Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
154826d4
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,发现更多精彩内容 >>
提交
154826d4
编写于
2月 19, 2015
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WebGLRenderer: Moved initAttributes/enableAttribute/disableUnusedAttributes to WebGLState.
上级
3ab982bc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
114 addition
and
75 deletion
+114
-75
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+67
-75
src/renderers/webgl/WebGLState.js
src/renderers/webgl/WebGLState.js
+47
-0
未找到文件。
src/renderers/WebGLRenderer.js
浏览文件 @
154826d4
...
...
@@ -125,9 +125,6 @@ THREE.WebGLRenderer = function ( parameters ) {
_currentWidth
=
0
,
_currentHeight
=
0
,
_newAttributes
=
new
Uint8Array
(
16
),
_enabledAttributes
=
new
Uint8Array
(
16
),
// frustum
_frustum
=
new
THREE
.
Frustum
(),
...
...
@@ -280,12 +277,6 @@ THREE.WebGLRenderer = function ( parameters ) {
_lightsNeedUpdate
=
true
;
for
(
var
i
=
0
;
i
<
_enabledAttributes
.
length
;
i
++
)
{
_enabledAttributes
[
i
]
=
0
;
}
state
.
reset
();
};
...
...
@@ -2330,7 +2321,7 @@ THREE.WebGLRenderer = function ( parameters ) {
this
.
renderBufferImmediate
=
function
(
object
,
program
,
material
)
{
initAttributes
();
state
.
initAttributes
();
if
(
object
.
hasPositions
&&
!
object
.
__webglVertexBuffer
)
object
.
__webglVertexBuffer
=
_gl
.
createBuffer
();
if
(
object
.
hasNormals
&&
!
object
.
__webglNormalBuffer
)
object
.
__webglNormalBuffer
=
_gl
.
createBuffer
();
...
...
@@ -2341,7 +2332,9 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webglVertexBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
object
.
positionArray
,
_gl
.
DYNAMIC_DRAW
);
enableAttribute
(
program
.
attributes
.
position
);
state
.
enableAttribute
(
program
.
attributes
.
position
);
_gl
.
vertexAttribPointer
(
program
.
attributes
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -2394,7 +2387,9 @@ THREE.WebGLRenderer = function ( parameters ) {
}
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
object
.
normalArray
,
_gl
.
DYNAMIC_DRAW
);
enableAttribute
(
program
.
attributes
.
normal
);
state
.
enableAttribute
(
program
.
attributes
.
normal
);
_gl
.
vertexAttribPointer
(
program
.
attributes
.
normal
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -2403,7 +2398,9 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webglUvBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
object
.
uvArray
,
_gl
.
DYNAMIC_DRAW
);
enableAttribute
(
program
.
attributes
.
uv
);
state
.
enableAttribute
(
program
.
attributes
.
uv
);
_gl
.
vertexAttribPointer
(
program
.
attributes
.
uv
,
2
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -2412,12 +2409,14 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webglColorBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
object
.
colorArray
,
_gl
.
DYNAMIC_DRAW
);
enableAttribute
(
program
.
attributes
.
color
);
state
.
enableAttribute
(
program
.
attributes
.
color
);
_gl
.
vertexAttribPointer
(
program
.
attributes
.
color
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
disableUnusedAttributes
();
state
.
disableUnusedAttributes
();
_gl
.
drawArrays
(
_gl
.
TRIANGLES
,
0
,
object
.
count
);
...
...
@@ -2447,7 +2446,7 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryAttribute
.
buffer
);
enableAttribute
(
programAttribute
);
state
.
enableAttribute
(
programAttribute
);
_gl
.
vertexAttribPointer
(
programAttribute
,
size
,
_gl
.
FLOAT
,
false
,
0
,
startIndex
*
size
*
4
);
// 4 bytes per Float32
...
...
@@ -2469,7 +2468,7 @@ THREE.WebGLRenderer = function ( parameters ) {
}
disableUnusedAttributes
();
state
.
disableUnusedAttributes
();
}
...
...
@@ -2494,7 +2493,7 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
updateBuffers
)
{
initAttributes
();
state
.
initAttributes
();
}
...
...
@@ -2835,7 +2834,7 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
updateBuffers
)
{
initAttributes
();
state
.
initAttributes
();
}
...
...
@@ -2846,7 +2845,9 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
updateBuffers
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglVertexBuffer
);
enableAttribute
(
attributes
.
position
);
state
.
enableAttribute
(
attributes
.
position
);
_gl
.
vertexAttribPointer
(
attributes
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -2877,7 +2878,9 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
attributes
[
attribute
.
buffer
.
belongsToAttribute
]
>=
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
attribute
.
buffer
);
enableAttribute
(
attributes
[
attribute
.
buffer
.
belongsToAttribute
]
);
state
.
enableAttribute
(
attributes
[
attribute
.
buffer
.
belongsToAttribute
]
);
_gl
.
vertexAttribPointer
(
attributes
[
attribute
.
buffer
.
belongsToAttribute
],
attribute
.
size
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -2894,7 +2897,9 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
object
.
geometry
.
colors
.
length
>
0
||
object
.
geometry
.
faces
.
length
>
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglColorBuffer
);
enableAttribute
(
attributes
.
color
);
state
.
enableAttribute
(
attributes
.
color
);
_gl
.
vertexAttribPointer
(
attributes
.
color
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
else
if
(
material
.
defaultAttributeValues
!==
undefined
)
{
...
...
@@ -2911,7 +2916,9 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
attributes
.
normal
>=
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglNormalBuffer
);
enableAttribute
(
attributes
.
normal
);
state
.
enableAttribute
(
attributes
.
normal
);
_gl
.
vertexAttribPointer
(
attributes
.
normal
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -2921,7 +2928,9 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
attributes
.
tangent
>=
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglTangentBuffer
);
enableAttribute
(
attributes
.
tangent
);
state
.
enableAttribute
(
attributes
.
tangent
);
_gl
.
vertexAttribPointer
(
attributes
.
tangent
,
4
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -2933,7 +2942,9 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
object
.
geometry
.
faceVertexUvs
[
0
]
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglUVBuffer
);
enableAttribute
(
attributes
.
uv
);
state
.
enableAttribute
(
attributes
.
uv
);
_gl
.
vertexAttribPointer
(
attributes
.
uv
,
2
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
else
if
(
material
.
defaultAttributeValues
!==
undefined
)
{
...
...
@@ -2950,7 +2961,9 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
object
.
geometry
.
faceVertexUvs
[
1
]
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglUV2Buffer
);
enableAttribute
(
attributes
.
uv2
);
state
.
enableAttribute
(
attributes
.
uv2
);
_gl
.
vertexAttribPointer
(
attributes
.
uv2
,
2
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
else
if
(
material
.
defaultAttributeValues
!==
undefined
)
{
...
...
@@ -2966,11 +2979,15 @@ THREE.WebGLRenderer = function ( parameters ) {
attributes
.
skinIndex
>=
0
&&
attributes
.
skinWeight
>=
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglSkinIndicesBuffer
);
enableAttribute
(
attributes
.
skinIndex
);
state
.
enableAttribute
(
attributes
.
skinIndex
);
_gl
.
vertexAttribPointer
(
attributes
.
skinIndex
,
4
,
_gl
.
FLOAT
,
false
,
0
,
0
);
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglSkinWeightsBuffer
);
enableAttribute
(
attributes
.
skinWeight
);
state
.
enableAttribute
(
attributes
.
skinWeight
);
_gl
.
vertexAttribPointer
(
attributes
.
skinWeight
,
4
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -2980,14 +2997,16 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
attributes
.
lineDistance
>=
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglLineDistanceBuffer
);
enableAttribute
(
attributes
.
lineDistance
);
state
.
enableAttribute
(
attributes
.
lineDistance
);
_gl
.
vertexAttribPointer
(
attributes
.
lineDistance
,
1
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
}
disableUnusedAttributes
();
state
.
disableUnusedAttributes
();
// render mesh
...
...
@@ -3042,44 +3061,6 @@ THREE.WebGLRenderer = function ( parameters ) {
};
function
initAttributes
()
{
for
(
var
i
=
0
,
l
=
_newAttributes
.
length
;
i
<
l
;
i
++
)
{
_newAttributes
[
i
]
=
0
;
}
}
function
enableAttribute
(
attribute
)
{
_newAttributes
[
attribute
]
=
1
;
if
(
_enabledAttributes
[
attribute
]
===
0
)
{
_gl
.
enableVertexAttribArray
(
attribute
);
_enabledAttributes
[
attribute
]
=
1
;
}
}
function
disableUnusedAttributes
()
{
for
(
var
i
=
0
,
l
=
_enabledAttributes
.
length
;
i
<
l
;
i
++
)
{
if
(
_enabledAttributes
[
i
]
!==
_newAttributes
[
i
]
)
{
_gl
.
disableVertexAttribArray
(
i
);
_enabledAttributes
[
i
]
=
0
;
}
}
}
function
setupMorphTargets
(
material
,
geometryGroup
,
object
)
{
// set base
...
...
@@ -3089,13 +3070,17 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
object
.
morphTargetBase
!==
-
1
&&
attributes
.
position
>=
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglMorphTargetsBuffers
[
object
.
morphTargetBase
]
);
enableAttribute
(
attributes
.
position
);
state
.
enableAttribute
(
attributes
.
position
);
_gl
.
vertexAttribPointer
(
attributes
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
else
if
(
attributes
.
position
>=
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglVertexBuffer
);
enableAttribute
(
attributes
.
position
);
state
.
enableAttribute
(
attributes
.
position
);
_gl
.
vertexAttribPointer
(
attributes
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -3117,7 +3102,9 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
attribute
>=
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglMorphTargetsBuffers
[
order
[
m
]
]
);
enableAttribute
(
attribute
);
state
.
enableAttribute
(
attribute
);
_gl
.
vertexAttribPointer
(
attribute
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -3127,7 +3114,9 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
attribute
>=
0
&&
material
.
morphNormals
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglMorphNormalsBuffers
[
order
[
m
]
]
);
enableAttribute
(
attribute
);
state
.
enableAttribute
(
attribute
);
_gl
.
vertexAttribPointer
(
attribute
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -3189,7 +3178,9 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
attribute
>=
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglMorphTargetsBuffers
[
influenceIndex
]
);
enableAttribute
(
attribute
);
state
.
enableAttribute
(
attribute
);
_gl
.
vertexAttribPointer
(
attribute
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -3199,9 +3190,10 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
attribute
>=
0
&&
material
.
morphNormals
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webglMorphNormalsBuffers
[
influenceIndex
]
);
enableAttribute
(
attribute
);
_gl
.
vertexAttribPointer
(
attribute
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
state
.
enableAttribute
(
attribute
);
_gl
.
vertexAttribPointer
(
attribute
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
src/renderers/webgl/WebGLState.js
浏览文件 @
154826d4
...
...
@@ -4,6 +4,9 @@
THREE
.
WebGLState
=
function
(
gl
,
paramThreeToGL
)
{
var
newAttributes
=
new
Uint8Array
(
16
);
var
enabledAttributes
=
new
Uint8Array
(
16
);
var
currentBlending
=
-
1
;
var
currentBlendEquation
=
-
1
;
var
currentBlendSrc
=
-
1
;
...
...
@@ -24,6 +27,44 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
var
currentPolygonOffsetFactor
=
null
;
var
currentPolygonOffsetUnits
=
null
;
this
.
initAttributes
=
function
()
{
for
(
var
i
=
0
,
l
=
newAttributes
.
length
;
i
<
l
;
i
++
)
{
newAttributes
[
i
]
=
0
;
}
};
this
.
enableAttribute
=
function
(
attribute
)
{
newAttributes
[
attribute
]
=
1
;
if
(
enabledAttributes
[
attribute
]
===
0
)
{
gl
.
enableVertexAttribArray
(
attribute
);
enabledAttributes
[
attribute
]
=
1
;
}
};
this
.
disableUnusedAttributes
=
function
()
{
for
(
var
i
=
0
,
l
=
enabledAttributes
.
length
;
i
<
l
;
i
++
)
{
if
(
enabledAttributes
[
i
]
!==
newAttributes
[
i
]
)
{
gl
.
disableVertexAttribArray
(
i
);
enabledAttributes
[
i
]
=
0
;
}
}
};
this
.
setBlending
=
function
(
blending
,
blendEquation
,
blendSrc
,
blendDst
,
blendEquationAlpha
,
blendSrcAlpha
,
blendDstAlpha
)
{
if
(
blending
!==
currentBlending
)
{
...
...
@@ -221,6 +262,12 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
this
.
reset
=
function
()
{
for
(
var
i
=
0
;
i
<
enabledAttributes
.
length
;
i
++
)
{
enabledAttributes
[
i
]
=
0
;
}
currentBlending
=
-
1
;
currentDepthTest
=
-
1
;
currentDepthWrite
=
-
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录