Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
70b4a686
T
three.js
项目概览
Ablesons
/
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,体验更适合开发者的 AI 搜索 >>
提交
70b4a686
编写于
5月 31, 2015
作者:
T
tschw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed caching of vertex attributes / uniforms (changing WebGLProgram API).
上级
9d3ac1aa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
94 deletion
+67
-94
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+16
-13
src/renderers/webgl/WebGLProgram.js
src/renderers/webgl/WebGLProgram.js
+51
-81
未找到文件。
src/renderers/WebGLRenderer.js
浏览文件 @
70b4a686
...
...
@@ -779,14 +779,15 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
object
.
hasUvs
&&
!
object
.
__webglUvBuffer
)
object
.
__webglUvBuffer
=
_gl
.
createBuffer
();
if
(
object
.
hasColors
&&
!
object
.
__webglColorBuffer
)
object
.
__webglColorBuffer
=
_gl
.
createBuffer
();
var
attributes
=
program
.
attributes
();
if
(
object
.
hasPositions
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webglVertexBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
object
.
positionArray
,
_gl
.
DYNAMIC_DRAW
);
state
.
enableAttribute
(
program
.
attributes
.
position
);
_gl
.
vertexAttribPointer
(
program
.
attributes
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
state
.
enableAttribute
(
attributes
.
position
);
_gl
.
vertexAttribPointer
(
attributes
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -839,9 +840,9 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
object
.
normalArray
,
_gl
.
DYNAMIC_DRAW
);
state
.
enableAttribute
(
program
.
attributes
.
normal
);
state
.
enableAttribute
(
attributes
.
normal
);
_gl
.
vertexAttribPointer
(
program
.
attributes
.
normal
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
_gl
.
vertexAttribPointer
(
attributes
.
normal
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -850,9 +851,9 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webglUvBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
object
.
uvArray
,
_gl
.
DYNAMIC_DRAW
);
state
.
enableAttribute
(
program
.
attributes
.
uv
);
state
.
enableAttribute
(
attributes
.
uv
);
_gl
.
vertexAttribPointer
(
program
.
attributes
.
uv
,
2
,
_gl
.
FLOAT
,
false
,
0
,
0
);
_gl
.
vertexAttribPointer
(
attributes
.
uv
,
2
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -861,9 +862,9 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webglColorBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
object
.
colorArray
,
_gl
.
DYNAMIC_DRAW
);
state
.
enableAttribute
(
program
.
attributes
.
color
);
state
.
enableAttribute
(
attributes
.
color
);
_gl
.
vertexAttribPointer
(
program
.
attributes
.
color
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
_gl
.
vertexAttribPointer
(
attributes
.
color
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
...
...
@@ -893,7 +894,8 @@ THREE.WebGLRenderer = function ( parameters ) {
}
var
geometryAttributes
=
geometry
.
attributes
;
var
programAttributes
=
program
.
attributes
;
var
programAttributes
=
program
.
attributes
();
var
materialDefaultAttributeValues
=
material
.
defaultAttributeValues
;
...
...
@@ -1995,7 +1997,7 @@ THREE.WebGLRenderer = function ( parameters ) {
material
.
program
=
program
;
var
attributes
=
program
.
attributes
;
var
attributes
=
program
.
attributes
()
;
if
(
material
.
morphTargets
)
{
...
...
@@ -2031,9 +2033,10 @@ THREE.WebGLRenderer = function ( parameters ) {
material
.
uniformsList
=
[];
var
uniformLocations
=
material
.
program
.
uniforms
();
for
(
var
u
in
material
.
__webglShader
.
uniforms
)
{
var
location
=
material
.
program
.
uniform
s
[
u
];
var
location
=
uniformLocation
s
[
u
];
if
(
location
)
{
material
.
uniformsList
.
push
(
[
material
.
__webglShader
.
uniforms
[
u
],
location
]
);
...
...
@@ -2079,7 +2082,7 @@ THREE.WebGLRenderer = function ( parameters ) {
var
refreshLights
=
false
;
var
program
=
material
.
program
,
p_uniforms
=
program
.
uniforms
,
p_uniforms
=
program
.
uniforms
()
,
m_uniforms
=
material
.
__webglShader
.
uniforms
;
if
(
program
.
id
!==
_currentProgram
)
{
...
...
src/renderers/webgl/WebGLProgram.js
浏览文件 @
70b4a686
...
...
@@ -20,14 +20,28 @@ THREE.WebGLProgram = ( function () {
}
function
cacheUniformLocations
(
gl
,
program
,
identifiers
)
{
function
fetchUniformLocations
(
gl
,
program
,
identifiers
)
{
var
uniforms
=
{};
for
(
var
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
var
n
=
gl
.
getProgramParameter
(
program
,
gl
.
ACTIVE_UNIFORMS
);
for
(
var
i
=
0
;
i
<
n
;
i
++
)
{
var
info
=
gl
.
getActiveUniform
(
program
,
i
);
var
name
=
info
.
name
;
var
location
=
gl
.
getUniformLocation
(
program
,
name
);
//console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
var
id
=
identifiers
[
i
];
uniforms
[
id
]
=
gl
.
getUniformLocation
(
program
,
id
);
var
suffixPos
=
name
.
lastIndexOf
(
'
[0]
'
);
if
(
suffixPos
!==
-
1
&&
suffixPos
===
name
.
length
-
3
)
{
uniforms
[
name
.
substr
(
0
,
suffixPos
)
]
=
location
;
}
uniforms
[
name
]
=
location
;
}
...
...
@@ -35,14 +49,19 @@ THREE.WebGLProgram = ( function () {
}
function
cache
AttributeLocations
(
gl
,
program
,
identifiers
)
{
function
fetch
AttributeLocations
(
gl
,
program
,
identifiers
)
{
var
attributes
=
{};
for
(
var
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
var
n
=
gl
.
getProgramParameter
(
program
,
gl
.
ACTIVE_ATTRIBUTES
);
for
(
var
i
=
0
;
i
<
n
;
i
++
)
{
var
info
=
gl
.
getActiveAttrib
(
program
,
i
);
var
name
=
info
.
name
;
//console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name);
var
id
=
identifiers
[
i
];
attributes
[
id
]
=
gl
.
getAttribLocation
(
program
,
id
);
attributes
[
name
]
=
gl
.
getAttribLocation
(
program
,
name
);
}
...
...
@@ -373,91 +392,42 @@ THREE.WebGLProgram = ( function () {
gl
.
deleteShader
(
glVertexShader
);
gl
.
deleteShader
(
glFragmentShader
);
//
cache
uniform locations
//
set up caching for
uniform locations
var
identifiers
=
[
var
getUniforms
=
function
()
{
return
this
.
_cachedUniforms
;
};
'
viewMatrix
'
,
'
modelViewMatrix
'
,
'
projectionMatrix
'
,
'
normalMatrix
'
,
'
modelMatrix
'
,
'
cameraPosition
'
,
'
morphTargetInfluences
'
,
'
bindMatrix
'
,
'
bindMatrixInverse
'
this
.
uniforms
=
function
()
{
];
// fetch, cache, and next time just use a dumb accessor
var
uniforms
=
fetchUniformLocations
(
gl
,
program
);
this
.
_cachedUniforms
=
uniforms
;
this
.
uniforms
=
getUniforms
;
return
uniforms
;
if
(
parameters
.
useVertexTexture
)
{
};
identifiers
.
push
(
'
boneTexture
'
,
'
boneTextureWidth
'
,
'
boneTextureHeight
'
);
// set up caching for attribute keys and locations
}
else
{
var
getAttributes
=
function
()
{
return
this
.
_cachedAttributes
;
};
var
getAttribKeys
=
function
()
{
return
this
.
_cachedAttribKeys
;
};
identifiers
.
push
(
'
boneGlobalMatrices
'
);
this
.
attributes
=
function
()
{
}
var
attributes
=
fetchAttributeLocations
(
gl
,
program
);
this
.
_cachedAttributes
=
attributes
;
this
.
_cachedAttribKeys
=
Object
.
keys
(
attributes
);
this
.
attributes
=
getAttributes
;
this
.
attributesKeys
=
getAttribKeys
;
return
attributes
;
if
(
parameters
.
logarithmicDepthBuffer
)
{
};
identifiers
.
push
(
'
logDepthBufFC
'
);
}
for
(
var
u
in
uniforms
)
{
identifiers
.
push
(
u
);
}
this
.
uniforms
=
cacheUniformLocations
(
gl
,
program
,
identifiers
);
// cache attributes locations
if
(
material
instanceof
THREE
.
RawShaderMaterial
)
{
this
.
attributesKeys
=
function
()
{
identifiers
=
attributes
;
}
else
{
identifiers
=
[
'
position
'
,
'
normal
'
,
'
uv
'
,
'
uv2
'
,
'
tangent
'
,
'
color
'
,
'
skinIndex
'
,
'
skinWeight
'
,
'
lineDistance
'
];
for
(
var
i
=
0
;
i
<
parameters
.
maxMorphTargets
;
i
++
)
{
identifiers
.
push
(
'
morphTarget
'
+
i
);
}
for
(
var
i
=
0
;
i
<
parameters
.
maxMorphNormals
;
i
++
)
{
identifiers
.
push
(
'
morphNormal
'
+
i
);
}
// ShaderMaterial attributes
if
(
Array
.
isArray
(
attributes
)
)
{
identifiers
=
identifiers
.
concat
(
attributes
);
}
}
this
.
attributes
();
return
this
.
_cachedAttribKeys
;
this
.
attributes
=
cacheAttributeLocations
(
gl
,
program
,
identifiers
)
;
}
;
//
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录