Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
da7b874d
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
da7b874d
编写于
6月 29, 2017
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WebGLRenderer: Basic support for webgl context lost. See #11435
上级
35d14fc8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
70 addition
and
64 deletion
+70
-64
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+58
-49
src/renderers/webgl/WebGLState.js
src/renderers/webgl/WebGLState.js
+12
-15
未找到文件。
src/renderers/WebGLRenderer.js
浏览文件 @
da7b874d
...
@@ -110,6 +110,8 @@ function WebGLRenderer( parameters ) {
...
@@ -110,6 +110,8 @@ function WebGLRenderer( parameters ) {
var
_this
=
this
,
var
_this
=
this
,
_isContextLost
=
false
,
// internal state cache
// internal state cache
_currentRenderTarget
=
null
,
_currentRenderTarget
=
null
,
...
@@ -252,6 +254,7 @@ function WebGLRenderer( parameters ) {
...
@@ -252,6 +254,7 @@ function WebGLRenderer( parameters ) {
}
}
_canvas
.
addEventListener
(
'
webglcontextlost
'
,
onContextLost
,
false
);
_canvas
.
addEventListener
(
'
webglcontextlost
'
,
onContextLost
,
false
);
_canvas
.
addEventListener
(
'
webglcontextrestored
'
,
onContextRestore
,
false
);
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -259,73 +262,65 @@ function WebGLRenderer( parameters ) {
...
@@ -259,73 +262,65 @@ function WebGLRenderer( parameters ) {
}
}
var
extensions
=
new
WebGLExtensions
(
_gl
);
var
extensions
,
capabilities
,
state
;
var
properties
,
textures
,
attributes
,
geometries
,
objects
;
extensions
.
get
(
'
WEBGL_depth_texture
'
);
var
programCache
,
lightCache
,
renderLists
;
extensions
.
get
(
'
OES_texture_float
'
);
extensions
.
get
(
'
OES_texture_float_linear
'
);
extensions
.
get
(
'
OES_texture_half_float
'
);
extensions
.
get
(
'
OES_texture_half_float_linear
'
);
extensions
.
get
(
'
OES_standard_derivatives
'
);
extensions
.
get
(
'
ANGLE_instanced_arrays
'
);
if
(
extensions
.
get
(
'
OES_element_index_uint
'
)
)
{
var
background
,
bufferRenderer
,
indexedBufferRenderer
;
BufferGeometry
.
MaxIndex
=
4294967296
;
function
initGLContext
()
{
}
extensions
=
new
WebGLExtensions
(
_gl
);
extensions
.
get
(
'
WEBGL_depth_texture
'
);
extensions
.
get
(
'
OES_texture_float
'
);
extensions
.
get
(
'
OES_texture_float_linear
'
);
extensions
.
get
(
'
OES_texture_half_float
'
);
extensions
.
get
(
'
OES_texture_half_float_linear
'
);
extensions
.
get
(
'
OES_standard_derivatives
'
);
extensions
.
get
(
'
ANGLE_instanced_arrays
'
);
var
capabilities
=
new
WebGLCapabilities
(
_gl
,
extensions
,
parameters
);
if
(
extensions
.
get
(
'
OES_element_index_uint
'
)
)
{
var
state
=
new
WebGLState
(
_gl
,
extensions
,
paramThreeToGL
)
;
BufferGeometry
.
MaxIndex
=
4294967296
;
var
properties
=
new
WebGLProperties
();
}
var
textures
=
new
WebGLTextures
(
_gl
,
extensions
,
state
,
properties
,
capabilities
,
paramThreeToGL
,
_infoMemory
);
var
attributes
=
new
WebGLAttributes
(
_gl
);
var
geometries
=
new
WebGLGeometries
(
_gl
,
attributes
,
_infoMemory
);
var
objects
=
new
WebGLObjects
(
_gl
,
geometries
,
_infoRender
);
var
programCache
=
new
WebGLPrograms
(
this
,
capabilities
);
var
lightCache
=
new
WebGLLights
();
var
renderLists
=
new
WebGLRenderLists
();
var
background
=
new
WebGLBackground
(
this
,
state
,
objects
,
_premultipliedAlpha
);
capabilities
=
new
WebGLCapabilities
(
_gl
,
extensions
,
parameters
);
var
vr
=
new
WebVRManager
(
this
);
this
.
info
.
programs
=
programCache
.
programs
;
state
=
new
WebGLState
(
_gl
,
extensions
,
paramThreeToGL
);
state
.
scissor
(
_currentScissor
.
copy
(
_scissor
).
multiplyScalar
(
_pixelRatio
)
);
state
.
viewport
(
_currentViewport
.
copy
(
_viewport
).
multiplyScalar
(
_pixelRatio
)
);
var
bufferRenderer
=
new
WebGLBufferRenderer
(
_gl
,
extensions
,
_infoRender
);
properties
=
new
WebGLProperties
();
var
indexedBufferRenderer
=
new
WebGLIndexedBufferRenderer
(
_gl
,
extensions
,
_infoRender
);
textures
=
new
WebGLTextures
(
_gl
,
extensions
,
state
,
properties
,
capabilities
,
paramThreeToGL
,
_infoMemory
);
attributes
=
new
WebGLAttributes
(
_gl
);
geometries
=
new
WebGLGeometries
(
_gl
,
attributes
,
_infoMemory
);
objects
=
new
WebGLObjects
(
_gl
,
geometries
,
_infoRender
);
programCache
=
new
WebGLPrograms
(
_this
,
capabilities
);
lightCache
=
new
WebGLLights
();
renderLists
=
new
WebGLRenderLists
();
//
background
=
new
WebGLBackground
(
_this
,
state
,
objects
,
_premultipliedAlpha
);
function
getTargetPixelRatio
()
{
bufferRenderer
=
new
WebGLBufferRenderer
(
_gl
,
extensions
,
_infoRender
);
indexedBufferRenderer
=
new
WebGLIndexedBufferRenderer
(
_gl
,
extensions
,
_infoRender
);
return
_currentRenderTarget
===
null
?
_pixelRatio
:
1
;
_this
.
info
.
programs
=
programCache
.
programs
;
}
}
function
setDefaultGLState
()
{
initGLContext
();
state
.
init
();
state
.
scissor
(
_currentScissor
.
copy
(
_scissor
).
multiplyScalar
(
_pixelRatio
)
);
state
.
viewport
(
_currentViewport
.
copy
(
_viewport
).
multiplyScalar
(
_pixelRatio
)
);
}
function
resetGLState
()
{
var
vr
=
new
WebVRManager
(
_this
);
_currentCamera
=
null
;
//
_currentGeometryProgram
=
''
;
function
getTargetPixelRatio
()
{
_currentMaterialId
=
-
1
;
state
.
reset
()
;
return
_currentRenderTarget
===
null
?
_pixelRatio
:
1
;
}
}
setDefaultGLState
();
this
.
context
=
_gl
;
this
.
context
=
_gl
;
this
.
capabilities
=
capabilities
;
this
.
capabilities
=
capabilities
;
this
.
extensions
=
extensions
;
this
.
extensions
=
extensions
;
...
@@ -367,6 +362,13 @@ function WebGLRenderer( parameters ) {
...
@@ -367,6 +362,13 @@ function WebGLRenderer( parameters ) {
};
};
this
.
forceContextRestore
=
function
()
{
var
extension
=
extensions
.
get
(
'
WEBGL_lose_context
'
);
if
(
extension
)
extension
.
restoreContext
();
};
this
.
getMaxAnisotropy
=
function
()
{
this
.
getMaxAnisotropy
=
function
()
{
return
capabilities
.
getMaxAnisotropy
();
return
capabilities
.
getMaxAnisotropy
();
...
@@ -524,6 +526,7 @@ function WebGLRenderer( parameters ) {
...
@@ -524,6 +526,7 @@ function WebGLRenderer( parameters ) {
this
.
dispose
=
function
()
{
this
.
dispose
=
function
()
{
_canvas
.
removeEventListener
(
'
webglcontextlost
'
,
onContextLost
,
false
);
_canvas
.
removeEventListener
(
'
webglcontextlost
'
,
onContextLost
,
false
);
_canvas
.
removeEventListener
(
'
webglcontextrestored
'
,
onContextRestore
,
false
);
renderLists
.
dispose
();
renderLists
.
dispose
();
...
@@ -535,11 +538,15 @@ function WebGLRenderer( parameters ) {
...
@@ -535,11 +538,15 @@ function WebGLRenderer( parameters ) {
event
.
preventDefault
();
event
.
preventDefault
();
resetGLState
();
_isContextLost
=
true
;
setDefaultGLState
();
}
function
onContextRestore
(
event
)
{
properties
.
clear
();
initGLContext
();
objects
.
clear
();
_isContextLost
=
false
;
}
}
...
@@ -1098,6 +1105,8 @@ function WebGLRenderer( parameters ) {
...
@@ -1098,6 +1105,8 @@ function WebGLRenderer( parameters ) {
}
}
if
(
_isContextLost
)
return
;
// reset caching for this frame
// reset caching for this frame
_currentGeometryProgram
=
''
;
_currentGeometryProgram
=
''
;
...
...
src/renderers/webgl/WebGLState.js
浏览文件 @
da7b874d
...
@@ -376,25 +376,23 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
...
@@ -376,25 +376,23 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
emptyTextures
[
gl
.
TEXTURE_2D
]
=
createTexture
(
gl
.
TEXTURE_2D
,
gl
.
TEXTURE_2D
,
1
);
emptyTextures
[
gl
.
TEXTURE_2D
]
=
createTexture
(
gl
.
TEXTURE_2D
,
gl
.
TEXTURE_2D
,
1
);
emptyTextures
[
gl
.
TEXTURE_CUBE_MAP
]
=
createTexture
(
gl
.
TEXTURE_CUBE_MAP
,
gl
.
TEXTURE_CUBE_MAP_POSITIVE_X
,
6
);
emptyTextures
[
gl
.
TEXTURE_CUBE_MAP
]
=
createTexture
(
gl
.
TEXTURE_CUBE_MAP
,
gl
.
TEXTURE_CUBE_MAP_POSITIVE_X
,
6
);
//
// init
function
init
()
{
colorBuffer
.
setClear
(
0
,
0
,
0
,
1
);
colorBuffer
.
setClear
(
0
,
0
,
0
,
1
);
depthBuffer
.
setClear
(
1
);
depthBuffer
.
setClear
(
1
);
stencilBuffer
.
setClear
(
0
);
stencilBuffer
.
setClear
(
0
);
enable
(
gl
.
DEPTH_TEST
);
enable
(
gl
.
DEPTH_TEST
);
depthBuffer
.
setFunc
(
LessEqualDepth
);
depthBuffer
.
setFunc
(
LessEqualDepth
);
setFlipSided
(
false
);
setFlipSided
(
false
);
setCullFace
(
CullFaceBack
);
setCullFace
(
CullFaceBack
);
enable
(
gl
.
CULL_FACE
);
enable
(
gl
.
CULL_FACE
);
enable
(
gl
.
BLEND
);
enable
(
gl
.
BLEND
);
setBlending
(
NormalBlending
);
setBlending
(
NormalBlending
);
}
//
function
initAttributes
()
{
function
initAttributes
()
{
...
@@ -917,7 +915,6 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
...
@@ -917,7 +915,6 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
stencil
:
stencilBuffer
stencil
:
stencilBuffer
},
},
init
:
init
,
initAttributes
:
initAttributes
,
initAttributes
:
initAttributes
,
enableAttribute
:
enableAttribute
,
enableAttribute
:
enableAttribute
,
enableAttributeAndDivisor
:
enableAttributeAndDivisor
,
enableAttributeAndDivisor
:
enableAttributeAndDivisor
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录