Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
3b63de52
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,发现更多精彩内容 >>
提交
3b63de52
编写于
2月 07, 2013
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WebGLRenderer code clean up.
上级
2340b75d
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
938 addition
and
851 deletion
+938
-851
build/three.js
build/three.js
+459
-415
build/three.min.js
build/three.min.js
+20
-21
src/renderers/WebGLRendererOld.js
src/renderers/WebGLRendererOld.js
+1
-1
src/renderers/webgl/LowLevelRenderer.js
src/renderers/webgl/LowLevelRenderer.js
+216
-178
src/renderers/webgl/ShaderBuilder.js
src/renderers/webgl/ShaderBuilder.js
+241
-235
utils/build/includes/commonOld.json
utils/build/includes/commonOld.json
+1
-1
未找到文件。
build/three.js
浏览文件 @
3b63de52
此差异已折叠。
点击以展开。
build/three.min.js
浏览文件 @
3b63de52
此差异已折叠。
点击以展开。
src/renderers/WebGLRendererOld.js
浏览文件 @
3b63de52
...
...
@@ -5,7 +5,7 @@
* @author szimek / https://github.com/szimek/
*/
THREE
.
WebGLRenderer
Old
=
function
(
parameters
)
{
THREE
.
WebGLRenderer
=
function
(
parameters
)
{
console
.
log
(
'
THREE.WebGLRenderer
'
,
THREE
.
REVISION
);
...
...
src/renderers/webgl/LowLevelRenderer.js
浏览文件 @
3b63de52
/*global THREE:false */
THREE
.
WebGLRenderer
.
LowLevelRenderer
=
function
(
parameters
)
{
THREE
.
WebGLRenderer
.
LowLevelRenderer
=
function
(
parameters
)
{
parameters
=
parameters
||
{};
...
...
@@ -181,7 +181,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setDefaultGLState
()
{
...
...
@@ -202,7 +202,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
_gl
.
clearColor
(
_clearColor
.
r
,
_clearColor
.
g
,
_clearColor
.
b
,
_clearAlpha
);
}
;
}
// Fallback filters for non-power-of-2 textures
...
...
@@ -216,67 +216,67 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
return
_gl
.
LINEAR
;
}
;
}
function
getContext
()
{
return
_gl
;
}
;
}
function
getDomElement
(){
return
_canvas
;
}
;
}
function
getPrecision
()
{
return
_precision
;
}
;
}
function
getCurrentWidth
(){
return
_currentWidth
;
}
;
}
function
getCurrentHeight
(){
return
_currentHeight
;
}
;
}
function
supportsVertexTextures
()
{
return
_supportsVertexTextures
;
}
;
}
function
supportsFloatTextures
()
{
return
_glExtensionTextureFloat
;
}
;
}
function
supportsStandardDerivatives
()
{
return
_glExtensionStandardDerivatives
;
}
;
}
function
supportsCompressedTextureS3TC
()
{
return
_glExtensionCompressedTextureS3TC
;
}
;
}
function
getMaxAnisotropy
()
{
return
_maxAnisotropy
;
}
;
}
function
setSize
(
width
,
height
)
{
...
...
@@ -285,7 +285,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
setViewport
(
0
,
0
,
_canvas
.
width
,
_canvas
.
height
);
}
;
}
function
setViewport
(
x
,
y
,
width
,
height
)
{
...
...
@@ -297,19 +297,19 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
_gl
.
viewport
(
_viewportX
,
_viewportY
,
_viewportWidth
,
_viewportHeight
);
}
;
}
function
setScissor
(
x
,
y
,
width
,
height
)
{
_gl
.
scissor
(
x
,
y
,
width
,
height
);
}
;
}
function
enableScissorTest
(
enable
)
{
enable
?
_gl
.
enable
(
_gl
.
SCISSOR_TEST
)
:
_gl
.
disable
(
_gl
.
SCISSOR_TEST
);
}
;
}
// Clearing
...
...
@@ -320,7 +320,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
_gl
.
clearColor
(
_clearColor
.
r
,
_clearColor
.
g
,
_clearColor
.
b
,
_clearAlpha
);
}
;
}
function
setClearColor
(
color
,
alpha
)
{
...
...
@@ -329,19 +329,19 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
_gl
.
clearColor
(
_clearColor
.
r
,
_clearColor
.
g
,
_clearColor
.
b
,
_clearAlpha
);
}
;
}
function
getClearColor
()
{
return
_clearColor
;
}
;
}
function
getClearAlpha
()
{
return
_clearAlpha
;
}
;
}
function
clear
(
color
,
depth
,
stencil
)
{
...
...
@@ -353,115 +353,146 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
_gl
.
clear
(
bits
);
}
;
}
function
clearTarget
(
renderTarget
,
color
,
depth
,
stencil
)
{
setRenderTarget
(
renderTarget
);
clear
(
color
,
depth
,
stencil
);
}
;
}
function
deleteBuffer
(
buffer
){
_gl
.
deleteBuffer
(
buffer
);
};
}
function
deleteTexture
(
texture
){
_gl
.
deleteTexture
(
texture
);
};
}
function
deleteFramebuffer
(
Framebuffer
){
_gl
.
deleteFramebuffer
(
Framebuffer
);
};
}
function
deleteRenderbuffer
(
RenderBuffer
){
_gl
.
deleteRenderbuffer
(
RenderBuffer
);
};
}
function
deleteProgram
(
RenderBuffer
){
_gl
.
deleteProgram
(
RenderBuffer
);
};
}
function
createBuffer
(){
return
_gl
.
createBuffer
();
};
}
function
setStaticArrayBuffer
(
buffer
,
data
){
bindArrayBuffer
(
buffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
data
,
_gl
.
STATIC_DRAW
);
}
;
}
function
setStaticIndexBuffer
(
buffer
,
data
){
bindElementArrayBuffer
(
buffer
);
_gl
.
bufferData
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
data
,
_gl
.
STATIC_DRAW
);
}
;
}
function
setDynamicArrayBuffer
(
buffer
,
data
){
bindArrayBuffer
(
buffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
data
,
_gl
.
DYNAMIC_DRAW
);
}
;
}
function
setDynamicIndexBuffer
(
buffer
,
data
){
bindElementArrayBuffer
(
buffer
);
_gl
.
bufferData
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
data
,
_gl
.
DYNAMIC_DRAW
);
}
;
}
function
drawTriangles
(
count
){
_gl
.
drawArrays
(
_gl
.
TRIANGLES
,
0
,
count
);
};
}
function
drawTriangleStrip
(
count
){
_gl
.
drawArrays
(
_gl
.
TRIANGLE_STRIP
,
0
,
count
);
};
}
function
drawLines
(
count
){
_gl
.
drawArrays
(
_gl
.
LINES
,
0
,
count
);
};
}
function
drawLineStrip
(
count
){
_gl
.
drawArrays
(
_gl
.
LINE_STRIP
,
0
,
count
);
};
}
function
drawPoints
(
count
){
_gl
.
drawArrays
(
_gl
.
POINTS
,
0
,
count
);
};
}
function
drawTriangleElements
(
buffer
,
count
,
offset
){
bindElementArrayBuffer
(
buffer
);
_gl
.
drawElements
(
_gl
.
TRIANGLES
,
count
,
_gl
.
UNSIGNED_SHORT
,
offset
);
// 2 bytes per Uint16
};
}
function
drawLineElements
(
buffer
,
count
,
offset
){
bindElementArrayBuffer
(
buffer
);
_gl
.
drawElements
(
_gl
.
LINES
,
count
,
_gl
.
UNSIGNED_SHORT
,
offset
);
// 2 bytes per Uint16
};
}
var
_boundBuffer
;
function
bindArrayBuffer
(
buffer
){
if
(
_boundBuffer
!=
buffer
){
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
buffer
);
_boundBuffer
=
buffer
;
}
}
;
}
function
bindElementArrayBuffer
(
buffer
){
if
(
_boundBuffer
!=
buffer
){
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
buffer
);
_boundBuffer
=
buffer
;
}
}
;
}
function
enableAttribute
(
attribute
)
{
...
...
@@ -472,7 +503,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
disableAttributes
()
{
...
...
@@ -487,10 +518,12 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
getAttribLocation
(
program
,
id
){
return
_gl
.
getAttribLocation
(
program
,
id
);
}
function
setFloatAttribute
(
index
,
buffer
,
size
,
offset
){
...
...
@@ -499,7 +532,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
enableAttribute
(
index
);
_gl
.
vertexAttribPointer
(
index
,
size
,
_gl
.
FLOAT
,
false
,
0
,
offset
);
}
;
}
function
getUniformLocation
(
program
,
id
){
...
...
@@ -511,91 +544,91 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
_gl
.
uniform1i
(
uniform
,
value
);
}
;
}
function
uniform1f
(
uniform
,
value
){
_gl
.
uniform1f
(
uniform
,
value
);
}
;
}
function
uniform2f
(
uniform
,
value1
,
value2
){
_gl
.
uniform2f
(
uniform
,
value1
,
value2
);
}
;
}
function
uniform3f
(
uniform
,
value1
,
value2
,
value3
){
_gl
.
uniform3f
(
uniform
,
value1
,
value2
,
value3
);
}
;
}
function
uniform4f
(
uniform
,
value1
,
value2
,
value3
,
value4
){
_gl
.
uniform4f
(
uniform
,
value1
,
value2
,
value3
,
value4
);
}
;
}
function
uniform1iv
(
uniform
,
value
){
_gl
.
uniform1iv
(
uniform
,
value
);
}
;
}
function
uniform2iv
(
uniform
,
value
){
_gl
.
uniform2iv
(
uniform
,
value
);
}
;
}
function
uniform3iv
(
uniform
,
value
){
_gl
.
uniform3iv
(
uniform
,
value
);
}
;
}
function
uniform1fv
(
uniform
,
value
){
_gl
.
uniform1fv
(
uniform
,
value
);
}
;
}
function
uniform2fv
(
uniform
,
value
){
_gl
.
uniform2fv
(
uniform
,
value
);
}
;
}
function
uniform3fv
(
uniform
,
value
){
_gl
.
uniform3fv
(
uniform
,
value
);
}
;
}
function
uniform4fv
(
uniform
,
value
){
_gl
.
uniform3fv
(
uniform
,
value
);
}
;
}
function
uniformMatrix3fv
(
location
,
value
){
_gl
.
uniformMatrix3fv
(
location
,
false
,
value
);
}
;
}
function
uniformMatrix4fv
(
location
,
value
){
_gl
.
uniformMatrix4fv
(
location
,
false
,
value
);
}
;
}
function
useProgram
(
program
){
_gl
.
useProgram
(
program
);
}
;
}
function
setFaceCulling
(
cullFace
,
frontFaceDirection
)
{
...
...
@@ -633,7 +666,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setMaterialFaces
(
material
)
{
...
...
@@ -672,7 +705,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setPolygonOffset
(
polygonoffset
,
factor
,
units
)
{
...
...
@@ -701,7 +734,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setBlending
(
blending
,
blendEquation
,
blendSrc
,
blendDst
)
{
...
...
@@ -774,7 +807,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setDepthTest
(
depthTest
)
{
...
...
@@ -794,7 +827,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setDepthWrite
(
depthWrite
)
{
...
...
@@ -805,7 +838,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setTexture
(
texture
,
slot
)
{
...
...
@@ -912,7 +945,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setCubeTexture
(
texture
,
slot
)
{
...
...
@@ -997,7 +1030,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
// Textures
...
...
@@ -1005,7 +1038,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
return
(
value
&
(
value
-
1
)
)
===
0
;
}
;
}
function
setTextureParameters
(
textureType
,
texture
,
isImagePowerOfTwo
)
{
...
...
@@ -1038,14 +1071,14 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setupFrameBuffer
(
framebuffer
,
renderTarget
,
textureTarget
)
{
_gl
.
bindFramebuffer
(
_gl
.
FRAMEBUFFER
,
framebuffer
);
_gl
.
framebufferTexture2D
(
_gl
.
FRAMEBUFFER
,
_gl
.
COLOR_ATTACHMENT0
,
textureTarget
,
renderTarget
.
__webglTexture
,
0
);
}
;
}
function
setupRenderBuffer
(
renderbuffer
,
renderTarget
)
{
...
...
@@ -1073,7 +1106,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setRenderTarget
(
renderTarget
)
{
...
...
@@ -1222,7 +1255,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
_currentWidth
=
width
;
_currentHeight
=
height
;
}
;
}
function
clampToMaxSize
(
image
,
maxSize
)
{
...
...
@@ -1248,7 +1281,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
return
canvas
;
}
;
}
function
updateRenderTargetMipmap
(
renderTarget
)
{
...
...
@@ -1266,14 +1299,14 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
}
;
}
function
setCubeTextureDynamic
(
texture
,
slot
)
{
_gl
.
activeTexture
(
_gl
.
TEXTURE0
+
slot
);
_gl
.
bindTexture
(
_gl
.
TEXTURE_CUBE_MAP
,
texture
.
__webglTexture
);
}
;
}
// Map three.js constants to WebGL constants
function
paramThreeToGL
(
p
)
{
...
...
@@ -1336,7 +1369,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
return
0
;
}
;
}
function
compileShader
(
vertexShader
,
fragmentShader
){
...
...
@@ -1363,7 +1396,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
return
program
;
}
;
}
function
resetState
(){
...
...
@@ -1402,7 +1435,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
return
shader
;
}
;
}
function
addLineNumbers
(
string
)
{
...
...
@@ -1419,7 +1452,7 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
return
chunks
.
join
(
"
\n
"
);
}
;
}
function
setLineWidth
(
width
)
{
...
...
@@ -1431,102 +1464,107 @@ THREE.WebGLRenderer.LowLevelRenderer = function(parameters){
}
};
this
.
context
=
_gl
;
this
.
autoScaleCubemaps
=
_autoScaleCubemaps
;
this
.
supportsBoneTextures
=
_supportsBoneTextures
;
this
.
precision
=
_precision
;
this
.
maxVertexUniformVectors
=
_gl
.
getParameter
(
_gl
.
MAX_VERTEX_UNIFORM_VECTORS
);
// Methods
this
.
getContext
=
getContext
;
this
.
getDomElement
=
getDomElement
;
this
.
getPrecision
=
getPrecision
;
this
.
getCurrentWidth
=
getCurrentWidth
;
this
.
getCurrentHeight
=
getCurrentHeight
;
this
.
supportsVertexTextures
=
supportsVertexTextures
;
this
.
supportsFloatTextures
=
supportsFloatTextures
;
this
.
supportsStandardDerivatives
=
supportsStandardDerivatives
;
this
.
supportsCompressedTextureS3TC
=
supportsCompressedTextureS3TC
;
this
.
getMaxAnisotropy
=
getMaxAnisotropy
;
this
.
setRenderTarget
=
setRenderTarget
;
this
.
setSize
=
setSize
;
this
.
setViewport
=
setViewport
;
this
.
setScissor
=
setScissor
;
this
.
enableScissorTest
=
enableScissorTest
;
this
.
setClearColorHex
=
setClearColorHex
;
this
.
setClearColor
=
setClearColor
;
this
.
getClearColor
=
getClearColor
;
this
.
getClearAlpha
=
getClearAlpha
;
this
.
clear
=
clear
;
this
.
clearTarget
=
clearTarget
;
this
.
deleteBuffer
=
deleteBuffer
;
this
.
deleteTexture
=
deleteTexture
;
this
.
deleteFramebuffer
=
deleteFramebuffer
;
this
.
deleteRenderbuffer
=
deleteRenderbuffer
;
this
.
deleteProgram
=
deleteProgram
;
this
.
createBuffer
=
createBuffer
;
this
.
setStaticArrayBuffer
=
setStaticArrayBuffer
;
this
.
setStaticIndexBuffer
=
setStaticIndexBuffer
;
this
.
setDynamicArrayBuffer
=
setDynamicArrayBuffer
;
this
.
setDynamicIndexBuffer
=
setDynamicIndexBuffer
;
this
.
drawTriangles
=
drawTriangles
;
this
.
drawTriangleStrip
=
drawTriangleStrip
;
this
.
drawLines
=
drawLines
;
this
.
drawLineStrip
=
drawLineStrip
;
this
.
drawPoints
=
drawPoints
;
this
.
drawTriangleElements
=
drawTriangleElements
;
this
.
drawLineElements
=
drawLineElements
;
this
.
bindArrayBuffer
=
bindArrayBuffer
;
this
.
bindElementArrayBuffer
=
bindElementArrayBuffer
;
this
.
enableAttribute
=
enableAttribute
;
this
.
disableAttributes
=
disableAttributes
;
this
.
getAttribLocation
=
getAttribLocation
;
this
.
setFloatAttribute
=
setFloatAttribute
;
this
.
getUniformLocation
=
getUniformLocation
;
this
.
uniform1i
=
uniform1i
;
this
.
uniform1f
=
uniform1f
;
this
.
uniform2f
=
uniform2f
;
this
.
uniform3f
=
uniform3f
;
this
.
uniform4f
=
uniform4f
;
this
.
uniform1iv
=
uniform1iv
;
this
.
uniform2iv
=
uniform2iv
;
this
.
uniform3iv
=
uniform3iv
;
this
.
uniform1fv
=
uniform1fv
;
this
.
uniform2fv
=
uniform2fv
;
this
.
uniform3fv
=
uniform3fv
;
this
.
uniform4fv
=
uniform4fv
;
this
.
uniformMatrix3fv
=
uniformMatrix3fv
;
this
.
uniformMatrix4fv
=
uniformMatrix4fv
;
this
.
useProgram
=
useProgram
;
this
.
compileShader
=
compileShader
;
this
.
setFaceCulling
=
setFaceCulling
;
this
.
setMaterialFaces
=
setMaterialFaces
;
this
.
setPolygonOffset
=
setPolygonOffset
;
this
.
setBlending
=
setBlending
;
this
.
setDepthTest
=
setDepthTest
;
this
.
setDepthWrite
=
setDepthWrite
;
this
.
setTexture
=
setTexture
;
this
.
setCubeTexture
=
setCubeTexture
;
this
.
updateRenderTargetMipmap
=
updateRenderTargetMipmap
;
this
.
setCubeTextureDynamic
=
setCubeTextureDynamic
;
this
.
paramThreeToGL
=
paramThreeToGL
;
this
.
setLineWidth
=
setLineWidth
;
this
.
resetState
=
resetState
;
}
return
{
context
:
_gl
,
autoScaleCubemaps
:
_autoScaleCubemaps
,
supportsBoneTextures
:
_supportsBoneTextures
,
precision
:
_precision
,
maxVertexUniformVectors
:
_gl
.
getParameter
(
_gl
.
MAX_VERTEX_UNIFORM_VECTORS
),
// Methods
getContext
:
getContext
,
getDomElement
:
getDomElement
,
getPrecision
:
getPrecision
,
getCurrentWidth
:
getCurrentWidth
,
getCurrentHeight
:
getCurrentHeight
,
supportsVertexTextures
:
supportsVertexTextures
,
supportsFloatTextures
:
supportsFloatTextures
,
supportsStandardDerivatives
:
supportsStandardDerivatives
,
supportsCompressedTextureS3TC
:
supportsCompressedTextureS3TC
,
getMaxAnisotropy
:
getMaxAnisotropy
,
setRenderTarget
:
setRenderTarget
,
setSize
:
setSize
,
setViewport
:
setViewport
,
setScissor
:
setScissor
,
enableScissorTest
:
enableScissorTest
,
setClearColorHex
:
setClearColorHex
,
setClearColor
:
setClearColor
,
getClearColor
:
getClearColor
,
getClearAlpha
:
getClearAlpha
,
clear
:
clear
,
clearTarget
:
clearTarget
,
deleteBuffer
:
deleteBuffer
,
deleteTexture
:
deleteTexture
,
deleteFramebuffer
:
deleteFramebuffer
,
deleteRenderbuffer
:
deleteRenderbuffer
,
deleteProgram
:
deleteProgram
,
createBuffer
:
createBuffer
,
setStaticArrayBuffer
:
setStaticArrayBuffer
,
setStaticIndexBuffer
:
setStaticIndexBuffer
,
setDynamicArrayBuffer
:
setDynamicArrayBuffer
,
setDynamicIndexBuffer
:
setDynamicIndexBuffer
,
drawTriangles
:
drawTriangles
,
drawTriangleStrip
:
drawTriangleStrip
,
drawLines
:
drawLines
,
drawLineStrip
:
drawLineStrip
,
drawPoints
:
drawPoints
,
drawTriangleElements
:
drawTriangleElements
,
drawLineElements
:
drawLineElements
,
bindArrayBuffer
:
bindArrayBuffer
,
bindElementArrayBuffer
:
bindElementArrayBuffer
,
enableAttribute
:
enableAttribute
,
disableAttributes
:
disableAttributes
,
getAttribLocation
:
getAttribLocation
,
setFloatAttribute
:
setFloatAttribute
,
getUniformLocation
:
getUniformLocation
,
uniform1i
:
uniform1i
,
uniform1f
:
uniform1f
,
uniform2f
:
uniform2f
,
uniform3f
:
uniform3f
,
uniform4f
:
uniform4f
,
uniform1iv
:
uniform1iv
,
uniform2iv
:
uniform2iv
,
uniform3iv
:
uniform3iv
,
uniform1fv
:
uniform1fv
,
uniform2fv
:
uniform2fv
,
uniform3fv
:
uniform3fv
,
uniform4fv
:
uniform4fv
,
uniformMatrix3fv
:
uniformMatrix3fv
,
uniformMatrix4fv
:
uniformMatrix4fv
,
useProgram
:
useProgram
,
compileShader
:
compileShader
,
setFaceCulling
:
setFaceCulling
,
setMaterialFaces
:
setMaterialFaces
,
setPolygonOffset
:
setPolygonOffset
,
setBlending
:
setBlending
,
setDepthTest
:
setDepthTest
,
setDepthWrite
:
setDepthWrite
,
setTexture
:
setTexture
,
setCubeTexture
:
setCubeTexture
,
updateRenderTargetMipmap
:
updateRenderTargetMipmap
,
setCubeTextureDynamic
:
setCubeTextureDynamic
,
paramThreeToGL
:
paramThreeToGL
,
setLineWidth
:
setLineWidth
,
resetState
:
resetState
}
};
src/renderers/webgl/ShaderBuilder.js
浏览文件 @
3b63de52
THREE
.
WebGLRenderer
.
ShaderBuilder
=
function
(
renderer
,
info
){
THREE
.
WebGLRenderer
.
ShaderBuilder
=
function
(
renderer
,
info
)
{
this
.
renderer
=
renderer
;
this
.
info
=
info
;
this
.
programs
=
[],
this
.
programs_counter
=
0
;
}
THREE
.
WebGLRenderer
.
ShaderBuilder
.
prototype
.
buildProgram
=
function
(
shaderID
,
fragmentShader
,
vertexShader
,
uniforms
,
attributes
,
defines
,
parameters
)
{
};
var
renderer
=
this
.
renderer
;
var
p
,
pl
,
d
,
program
,
code
;
var
chunks
=
[];
THREE
.
extend
(
THREE
.
WebGLRenderer
.
ShaderBuilder
.
prototype
,
{
// Generate code
buildProgram
:
function
(
shaderID
,
fragmentShader
,
vertexShader
,
uniforms
,
attributes
,
defines
,
parameters
)
{
if
(
shaderID
)
{
var
renderer
=
this
.
renderer
;
var
p
,
pl
,
d
,
program
,
code
;
var
chunks
=
[];
chunks
.
push
(
shaderID
);
// Generate code
}
else
{
if
(
shaderID
)
{
chunks
.
push
(
fragmentShader
);
chunks
.
push
(
vertexShader
);
chunks
.
push
(
shaderID
);
}
}
else
{
for
(
d
in
defines
)
{
chunks
.
push
(
fragmentShader
);
chunks
.
push
(
vertexShader
);
chunks
.
push
(
d
);
chunks
.
push
(
defines
[
d
]
);
}
}
for
(
d
in
defines
)
{
chunks
.
push
(
d
);
chunks
.
push
(
defines
[
d
]
);
for
(
p
in
parameters
)
{
}
chunks
.
push
(
p
);
chunks
.
push
(
parameters
[
p
]
);
for
(
p
in
parameters
)
{
}
chunks
.
push
(
p
);
chunks
.
push
(
parameters
[
p
]
);
}
code
=
chunks
.
join
();
code
=
chunks
.
join
();
// Check if code has been already compiled
// Check if code has been already compiled
for
(
p
=
0
,
pl
=
this
.
programs
.
length
;
p
<
pl
;
p
++
)
{
for
(
p
=
0
,
pl
=
this
.
programs
.
length
;
p
<
pl
;
p
++
)
{
var
programInfo
=
this
.
programs
[
p
];
var
programInfo
=
this
.
programs
[
p
];
if
(
programInfo
.
code
===
code
)
{
if
(
programInfo
.
code
===
code
)
{
//console.log( "Code already compiled." /*: \n\n" + code*/ );
//console.log( "Code already compiled." /*: \n\n" + code*/ )
;
programInfo
.
usedTimes
++
;
programInfo
.
usedTimes
++
;
return
programInfo
.
program
;
return
programInfo
.
program
;
}
}
}
var
shadowMapTypeDefine
=
"
SHADOWMAP_TYPE_BASIC
"
;
var
shadowMapTypeDefine
=
"
SHADOWMAP_TYPE_BASIC
"
;
if
(
parameters
.
shadowMapType
===
THREE
.
PCFShadowMap
)
{
if
(
parameters
.
shadowMapType
===
THREE
.
PCFShadowMap
)
{
shadowMapTypeDefine
=
"
SHADOWMAP_TYPE_PCF
"
;
shadowMapTypeDefine
=
"
SHADOWMAP_TYPE_PCF
"
;
}
else
if
(
parameters
.
shadowMapType
===
THREE
.
PCFSoftShadowMap
)
{
}
else
if
(
parameters
.
shadowMapType
===
THREE
.
PCFSoftShadowMap
)
{
shadowMapTypeDefine
=
"
SHADOWMAP_TYPE_PCF_SOFT
"
;
shadowMapTypeDefine
=
"
SHADOWMAP_TYPE_PCF_SOFT
"
;
}
}
//console.log( "building new program " );
//console.log( "building new program " );
//
//
var
customDefines
=
this
.
generateDefines
(
defines
);
var
customDefines
=
this
.
generateDefines
(
defines
);
//
//
var
prefix_vertex
=
[
var
prefix_vertex
=
[
"
precision
"
+
renderer
.
precision
+
"
float;
"
,
"
precision
"
+
renderer
.
precision
+
"
float;
"
,
customDefines
,
customDefines
,
renderer
.
supportsVertexTextures
?
"
#define VERTEX_TEXTURES
"
:
""
,
renderer
.
supportsVertexTextures
?
"
#define VERTEX_TEXTURES
"
:
""
,
parameters
.
gammaInput
?
"
#define GAMMA_INPUT
"
:
""
,
parameters
.
gammaOutput
?
"
#define GAMMA_OUTPUT
"
:
""
,
parameters
.
physicallyBasedShading
?
"
#define PHYSICALLY_BASED_SHADING
"
:
""
,
parameters
.
gammaInput
?
"
#define GAMMA_INPUT
"
:
""
,
parameters
.
gammaOutput
?
"
#define GAMMA_OUTPUT
"
:
""
,
parameters
.
physicallyBasedShading
?
"
#define PHYSICALLY_BASED_SHADING
"
:
""
,
"
#define MAX_DIR_LIGHTS
"
+
parameters
.
maxDirLights
,
"
#define MAX_POINT_LIGHTS
"
+
parameters
.
maxPointLights
,
"
#define MAX_SPOT_LIGHTS
"
+
parameters
.
maxSpotLights
,
"
#define MAX_HEMI_LIGHTS
"
+
parameters
.
maxHemiLights
,
"
#define MAX_DIR_LIGHTS
"
+
parameters
.
maxDirLights
,
"
#define MAX_POINT_LIGHTS
"
+
parameters
.
maxPointLights
,
"
#define MAX_SPOT_LIGHTS
"
+
parameters
.
maxSpotLights
,
"
#define MAX_HEMI_LIGHTS
"
+
parameters
.
maxHemiLights
,
"
#define MAX_SHADOWS
"
+
parameters
.
maxShadows
,
"
#define MAX_SHADOWS
"
+
parameters
.
maxShadow
s
,
"
#define MAX_BONES
"
+
parameters
.
maxBone
s
,
"
#define MAX_BONES
"
+
parameters
.
maxBones
,
parameters
.
map
?
"
#define USE_MAP
"
:
""
,
parameters
.
envMap
?
"
#define USE_ENVMAP
"
:
""
,
parameters
.
lightMap
?
"
#define USE_LIGHTMAP
"
:
""
,
parameters
.
bumpMap
?
"
#define USE_BUMPMAP
"
:
""
,
parameters
.
normalMap
?
"
#define USE_NORMALMAP
"
:
""
,
parameters
.
specularMap
?
"
#define USE_SPECULARMAP
"
:
""
,
parameters
.
vertexColors
?
"
#define USE_COLOR
"
:
""
,
parameters
.
map
?
"
#define USE_MAP
"
:
""
,
parameters
.
envMap
?
"
#define USE_ENVMAP
"
:
""
,
parameters
.
lightMap
?
"
#define USE_LIGHTMAP
"
:
""
,
parameters
.
bumpMap
?
"
#define USE_BUMPMAP
"
:
""
,
parameters
.
normalMap
?
"
#define USE_NORMALMAP
"
:
""
,
parameters
.
specularMap
?
"
#define USE_SPECULARMAP
"
:
""
,
parameters
.
vertexColors
?
"
#define USE_COLOR
"
:
""
,
parameters
.
skinning
?
"
#define USE_SKINNING
"
:
""
,
parameters
.
useVertexTexture
?
"
#define BONE_TEXTURE
"
:
""
,
parameters
.
boneTextureWidth
?
"
#define N_BONE_PIXEL_X
"
+
parameters
.
boneTextureWidth
.
toFixed
(
1
)
:
""
,
parameters
.
boneTextureHeight
?
"
#define N_BONE_PIXEL_Y
"
+
parameters
.
boneTextureHeight
.
toFixed
(
1
)
:
""
,
parameters
.
skinning
?
"
#define USE_SKINNING
"
:
""
,
parameters
.
useVertexTexture
?
"
#define BONE_TEXTURE
"
:
""
,
parameters
.
boneTextureWidth
?
"
#define N_BONE_PIXEL_X
"
+
parameters
.
boneTextureWidth
.
toFixed
(
1
)
:
""
,
parameters
.
boneTextureHeight
?
"
#define N_BONE_PIXEL_Y
"
+
parameters
.
boneTextureHeight
.
toFixed
(
1
)
:
""
,
parameters
.
morphTargets
?
"
#define USE_MORPHTARGETS
"
:
""
,
parameters
.
morphNormals
?
"
#define USE_MORPHNORMALS
"
:
""
,
parameters
.
perPixel
?
"
#define PHONG_PER_PIXEL
"
:
""
,
parameters
.
wrapAround
?
"
#define WRAP_AROUND
"
:
""
,
parameters
.
doubleSided
?
"
#define DOUBLE_SIDED
"
:
""
,
parameters
.
flipSided
?
"
#define FLIP_SIDED
"
:
""
,
parameters
.
morphTargets
?
"
#define USE_MORPHTARGETS
"
:
""
,
parameters
.
morphNormals
?
"
#define USE_MORPHNORMALS
"
:
""
,
parameters
.
perPixel
?
"
#define PHONG_PER_PIXEL
"
:
""
,
parameters
.
wrapAround
?
"
#define WRAP_AROUND
"
:
""
,
parameters
.
doubleSided
?
"
#define DOUBLE_SIDED
"
:
""
,
parameters
.
flipSided
?
"
#define FLIP_SIDED
"
:
""
,
parameters
.
shadowMapEnabled
?
"
#define USE_SHADOWMAP
"
:
""
,
parameters
.
shadowMapEnabled
?
"
#define
"
+
shadowMapTypeDefine
:
""
,
parameters
.
shadowMapDebug
?
"
#define SHADOWMAP_DEBUG
"
:
""
,
parameters
.
shadowMapCascade
?
"
#define SHADOWMAP_CASCADE
"
:
""
,
parameters
.
shadowMapEnabled
?
"
#define USE_SHADOWMAP
"
:
""
,
parameters
.
shadowMapEnabled
?
"
#define
"
+
shadowMapTypeDefine
:
""
,
parameters
.
shadowMapDebug
?
"
#define SHADOWMAP_DEBUG
"
:
""
,
parameters
.
shadowMapCascade
?
"
#define SHADOWMAP_CASCADE
"
:
""
,
parameters
.
sizeAttenuation
?
"
#define USE_SIZEATTENUATION
"
:
""
,
parameters
.
sizeAttenuation
?
"
#define USE_SIZEATTENUATION
"
:
""
,
"
uniform mat4 modelMatrix;
"
,
"
uniform mat4 modelViewMatrix;
"
,
"
uniform mat4 projectionMatrix;
"
,
"
uniform mat4 viewMatrix;
"
,
"
uniform mat3 normalMatrix;
"
,
"
uniform vec3 cameraPosition;
"
,
"
uniform mat4 modelMatrix;
"
,
"
uniform mat4 modelViewMatrix;
"
,
"
uniform mat4 projectionMatrix;
"
,
"
uniform mat4 viewMatrix;
"
,
"
uniform mat3 normalMatrix;
"
,
"
uniform vec3 cameraPosition;
"
,
"
attribute vec3 position;
"
,
"
attribute vec3 normal;
"
,
"
attribute vec2 uv;
"
,
"
attribute vec2 uv2;
"
,
"
attribute vec3 position;
"
,
"
attribute vec3 normal;
"
,
"
attribute vec2 uv;
"
,
"
attribute vec2 uv2;
"
,
"
#ifdef USE_COLOR
"
,
"
#ifdef USE_COLOR
"
,
"
attribute vec3 color;
"
,
"
attribute vec3 color;
"
,
"
#endif
"
,
"
#endif
"
,
"
#ifdef USE_MORPHTARGETS
"
,
"
#ifdef USE_MORPHTARGETS
"
,
"
attribute vec3 morphTarget0;
"
,
"
attribute vec3 morphTarget1;
"
,
"
attribute vec3 morphTarget2;
"
,
"
attribute vec3 morphTarget3;
"
,
"
attribute vec3 morphTarget0;
"
,
"
attribute vec3 morphTarget1;
"
,
"
attribute vec3 morphTarget2;
"
,
"
attribute vec3 morphTarget3;
"
,
"
#ifdef USE_MORPHNORMALS
"
,
"
#ifdef USE_MORPHNORMALS
"
,
"
attribute vec3 morphNormal0;
"
,
"
attribute vec3 morphNormal1;
"
,
"
attribute vec3 morphNormal2;
"
,
"
attribute vec3 morphNormal3;
"
,
"
attribute vec3 morphNormal0;
"
,
"
attribute vec3 morphNormal1;
"
,
"
attribute vec3 morphNormal2;
"
,
"
attribute vec3 morphNormal3;
"
,
"
#else
"
,
"
#else
"
,
"
attribute vec3 morphTarget4;
"
,
"
attribute vec3 morphTarget5;
"
,
"
attribute vec3 morphTarget6;
"
,
"
attribute vec3 morphTarget7;
"
,
"
attribute vec3 morphTarget4;
"
,
"
attribute vec3 morphTarget5;
"
,
"
attribute vec3 morphTarget6;
"
,
"
attribute vec3 morphTarget7;
"
,
"
#endif
"
,
"
#endif
"
,
"
#endif
"
,
"
#ifdef USE_SKINNING
"
,
"
#ifdef USE_SKINNING
"
,
"
attribute vec4 skinIndex;
"
,
"
attribute vec4 skinWeight;
"
,
"
attribute vec4 skinIndex;
"
,
"
attribute vec4 skinWeight;
"
,
"
#endif
"
,
"
#endif
"
,
""
""
].
join
(
"
\n
"
);
].
join
(
"
\n
"
);
var
prefix_fragment
=
[
var
prefix_fragment
=
[
"
precision
"
+
renderer
.
precision
+
"
float;
"
,
"
precision
"
+
renderer
.
precision
+
"
float;
"
,
(
parameters
.
bumpMap
||
parameters
.
normalMap
)
?
"
#extension GL_OES_standard_derivatives : enable
"
:
"
"
,
(
parameters
.
bumpMap
||
parameters
.
normalMap
)
?
"
#extension GL_OES_standard_derivatives : enable
"
:
""
,
customDefines
,
customDefines
,
"
#define MAX_DIR_LIGHTS
"
+
parameters
.
maxDirLights
,
"
#define MAX_POINT_LIGHTS
"
+
parameters
.
maxPointLights
,
"
#define MAX_SPOT_LIGHTS
"
+
parameters
.
maxSpotLights
,
"
#define MAX_HEMI_LIGHTS
"
+
parameters
.
maxHemiLights
,
"
#define MAX_DIR_LIGHTS
"
+
parameters
.
maxDirLights
,
"
#define MAX_POINT_LIGHTS
"
+
parameters
.
maxPointLights
,
"
#define MAX_SPOT_LIGHTS
"
+
parameters
.
maxSpotLights
,
"
#define MAX_HEMI_LIGHTS
"
+
parameters
.
maxHemiLights
,
"
#define MAX_SHADOWS
"
+
parameters
.
maxShadows
,
"
#define MAX_SHADOWS
"
+
parameters
.
maxShadows
,
parameters
.
alphaTest
?
"
#define ALPHATEST
"
+
parameters
.
alphaTest
:
""
,
parameters
.
alphaTest
?
"
#define ALPHATEST
"
+
parameters
.
alphaTest
:
""
,
parameters
.
gammaInput
?
"
#define GAMMA_INPUT
"
:
""
,
parameters
.
gammaOutput
?
"
#define GAMMA_OUTPUT
"
:
""
,
parameters
.
gammaInput
?
"
#define GAMMA_INPUT
"
:
""
,
parameters
.
gammaOutput
?
"
#define GAMMA_OUTPUT
"
:
""
,
(
parameters
.
useFog
&&
parameters
.
fog
)
?
"
#define USE_FOG
"
:
""
,
(
parameters
.
useFog
&&
parameters
.
fogExp
)
?
"
#define FOG_EXP2
"
:
""
,
(
parameters
.
useFog
&&
parameters
.
fog
)
?
"
#define USE_FOG
"
:
""
,
(
parameters
.
useFog
&&
parameters
.
fogExp
)
?
"
#define FOG_EXP2
"
:
""
,
parameters
.
map
?
"
#define USE_MAP
"
:
""
,
parameters
.
envMap
?
"
#define USE_ENVMAP
"
:
""
,
parameters
.
lightMap
?
"
#define USE_LIGHTMAP
"
:
""
,
parameters
.
bumpMap
?
"
#define USE_BUMPMAP
"
:
""
,
parameters
.
normalMap
?
"
#define USE_NORMALMAP
"
:
""
,
parameters
.
specularMap
?
"
#define USE_SPECULARMAP
"
:
""
,
parameters
.
vertexColors
?
"
#define USE_COLOR
"
:
""
,
parameters
.
map
?
"
#define USE_MAP
"
:
""
,
parameters
.
envMap
?
"
#define USE_ENVMAP
"
:
""
,
parameters
.
lightMap
?
"
#define USE_LIGHTMAP
"
:
""
,
parameters
.
bumpMap
?
"
#define USE_BUMPMAP
"
:
""
,
parameters
.
normalMap
?
"
#define USE_NORMALMAP
"
:
""
,
parameters
.
specularMap
?
"
#define USE_SPECULARMAP
"
:
""
,
parameters
.
vertexColors
?
"
#define USE_COLOR
"
:
""
,
parameters
.
metal
?
"
#define METAL
"
:
""
,
parameters
.
perPixel
?
"
#define PHONG_PER_PIXEL
"
:
""
,
parameters
.
wrapAround
?
"
#define WRAP_AROUND
"
:
""
,
parameters
.
doubleSided
?
"
#define DOUBLE_SIDED
"
:
""
,
parameters
.
flipSided
?
"
#define FLIP_SIDED
"
:
""
,
parameters
.
metal
?
"
#define METAL
"
:
""
,
parameters
.
perPixel
?
"
#define PHONG_PER_PIXEL
"
:
""
,
parameters
.
wrapAround
?
"
#define WRAP_AROUND
"
:
""
,
parameters
.
doubleSided
?
"
#define DOUBLE_SIDED
"
:
""
,
parameters
.
flipSided
?
"
#define FLIP_SIDED
"
:
""
,
parameters
.
shadowMapEnabled
?
"
#define USE_SHADOWMAP
"
:
""
,
parameters
.
shadowMapEnabled
?
"
#define
"
+
shadowMapTypeDefine
:
""
,
parameters
.
shadowMapDebug
?
"
#define SHADOWMAP_DEBUG
"
:
""
,
parameters
.
shadowMapCascade
?
"
#define SHADOWMAP_CASCADE
"
:
""
,
parameters
.
shadowMapEnabled
?
"
#define USE_SHADOWMAP
"
:
""
,
parameters
.
shadowMapEnabled
?
"
#define
"
+
shadowMapTypeDefine
:
""
,
parameters
.
shadowMapDebug
?
"
#define SHADOWMAP_DEBUG
"
:
""
,
parameters
.
shadowMapCascade
?
"
#define SHADOWMAP_CASCADE
"
:
""
,
"
uniform mat4 viewMatrix;
"
,
"
uniform vec3 cameraPosition;
"
,
""
"
uniform mat4 viewMatrix;
"
,
"
uniform vec3 cameraPosition;
"
,
""
].
join
(
"
\n
"
);
].
join
(
"
\n
"
);
program
=
renderer
.
compileShader
(
prefix_vertex
+
vertexShader
,
prefix_fragment
+
fragmentShader
);
program
=
renderer
.
compileShader
(
prefix_vertex
+
vertexShader
,
prefix_fragment
+
fragmentShader
);
//console.log( prefix_fragment + fragmentShader );
//console.log( prefix_vertex + vertexShader );
//console.log( prefix_fragment + fragmentShader );
//console.log( prefix_vertex + vertexShader );
program
.
uniforms
=
{};
program
.
attributes
=
{};
program
.
uniforms
=
{};
program
.
attributes
=
{};
var
identifiers
,
u
,
a
,
i
;
var
identifiers
,
u
,
a
,
i
;
// cache uniform locations
// cache uniform locations
identifiers
=
[
identifiers
=
[
'
viewMatrix
'
,
'
modelViewMatrix
'
,
'
projectionMatrix
'
,
'
normalMatrix
'
,
'
modelMatrix
'
,
'
cameraPosition
'
,
'
morphTargetInfluences
'
'
viewMatrix
'
,
'
modelViewMatrix
'
,
'
projectionMatrix
'
,
'
normalMatrix
'
,
'
modelMatrix
'
,
'
cameraPosition
'
,
'
morphTargetInfluences
'
];
];
if
(
parameters
.
useVertexTexture
)
{
if
(
parameters
.
useVertexTexture
)
{
identifiers
.
push
(
'
boneTexture
'
);
identifiers
.
push
(
'
boneTexture
'
);
}
else
{
}
else
{
identifiers
.
push
(
'
boneGlobalMatrices
'
);
identifiers
.
push
(
'
boneGlobalMatrices
'
);
}
}
for
(
u
in
uniforms
)
{
for
(
u
in
uniforms
)
{
identifiers
.
push
(
u
);
identifiers
.
push
(
u
);
}
}
this
.
cacheUniformLocations
(
program
,
identifiers
);
this
.
cacheUniformLocations
(
program
,
identifiers
);
// cache attributes locations
// cache attributes locations
identifiers
=
[
identifiers
=
[
"
position
"
,
"
normal
"
,
"
uv
"
,
"
uv2
"
,
"
tangent
"
,
"
color
"
,
"
skinIndex
"
,
"
skinWeight
"
,
"
lineDistance
"
"
position
"
,
"
normal
"
,
"
uv
"
,
"
uv2
"
,
"
tangent
"
,
"
color
"
,
"
skinIndex
"
,
"
skinWeight
"
,
"
lineDistance
"
];
];
for
(
i
=
0
;
i
<
parameters
.
maxMorphTargets
;
i
++
)
{
for
(
i
=
0
;
i
<
parameters
.
maxMorphTargets
;
i
++
)
{
identifiers
.
push
(
"
morphTarget
"
+
i
);
identifiers
.
push
(
"
morphTarget
"
+
i
);
}
}
for
(
i
=
0
;
i
<
parameters
.
maxMorphNormals
;
i
++
)
{
for
(
i
=
0
;
i
<
parameters
.
maxMorphNormals
;
i
++
)
{
identifiers
.
push
(
"
morphNormal
"
+
i
);
identifiers
.
push
(
"
morphNormal
"
+
i
);
}
}
for
(
a
in
attributes
)
{
for
(
a
in
attributes
)
{
identifiers
.
push
(
a
);
identifiers
.
push
(
a
);
}
}
this
.
cacheAttributeLocations
(
program
,
identifiers
);
this
.
cacheAttributeLocations
(
program
,
identifiers
);
program
.
id
=
this
.
programs_counter
++
;
program
.
id
=
this
.
programs_counter
++
;
this
.
programs
.
push
(
{
program
:
program
,
code
:
code
,
usedTimes
:
1
}
);
this
.
programs
.
push
(
{
program
:
program
,
code
:
code
,
usedTimes
:
1
}
);
this
.
info
.
memory
.
programs
=
this
.
programs
.
length
;
this
.
info
.
memory
.
programs
=
this
.
programs
.
length
;
return
program
;
return
program
;
};
},
THREE
.
WebGLRenderer
.
ShaderBuilder
.
prototype
.
generateDefines
=
function
(
defines
)
{
generateDefines
:
function
(
defines
)
{
var
value
,
chunk
,
chunks
=
[];
var
value
,
chunk
,
chunks
=
[];
for
(
var
d
in
defines
)
{
for
(
var
d
in
defines
)
{
value
=
defines
[
d
];
if
(
value
===
false
)
continue
;
value
=
defines
[
d
];
if
(
value
===
false
)
continue
;
chunk
=
"
#define
"
+
d
+
"
"
+
value
;
chunks
.
push
(
chunk
);
chunk
=
"
#define
"
+
d
+
"
"
+
value
;
chunks
.
push
(
chunk
);
}
}
return
chunks
.
join
(
"
\n
"
);
return
chunks
.
join
(
"
\n
"
);
};
},
// Shader parameters cache
THREE
.
WebGLRenderer
.
ShaderBuilder
.
prototype
.
cacheUniformLocations
=
function
(
program
,
identifiers
)
{
cacheUniformLocations
:
function
(
program
,
identifiers
)
{
var
i
,
l
,
id
,
renderer
=
this
.
renderer
;
var
i
,
l
,
id
,
renderer
=
this
.
renderer
;
for
(
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
for
(
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
id
=
identifiers
[
i
];
program
.
uniforms
[
id
]
=
renderer
.
getUniformLocation
(
program
,
id
);
id
=
identifiers
[
i
];
program
.
uniforms
[
id
]
=
renderer
.
getUniformLocation
(
program
,
id
);
}
}
};
},
THREE
.
WebGLRenderer
.
ShaderBuilder
.
prototype
.
cacheAttributeLocations
=
function
(
program
,
identifiers
)
{
cacheAttributeLocations
:
function
(
program
,
identifiers
)
{
var
i
,
l
,
id
,
renderer
=
this
.
renderer
;
var
i
,
l
,
id
,
renderer
=
this
.
renderer
;
for
(
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
for
(
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
id
=
identifiers
[
i
];
program
.
attributes
[
id
]
=
renderer
.
getAttribLocation
(
program
,
id
);
id
=
identifiers
[
i
];
program
.
attributes
[
id
]
=
renderer
.
getAttribLocation
(
program
,
id
);
}
}
};
},
removeProgram
:
function
(
program
)
{
var
i
,
il
,
programInfo
;
var
deleteProgram
=
false
;
var
programs
=
this
.
programs
;
THREE
.
WebGLRenderer
.
ShaderBuilder
.
prototype
.
removeProgram
=
function
(
program
)
{
for
(
i
=
0
,
il
=
programs
.
length
;
i
<
il
;
i
++
)
{
var
i
,
il
,
programInfo
;
var
deleteProgram
=
false
;
var
programs
=
this
.
programs
;
programInfo
=
programs
[
i
];
for
(
i
=
0
,
il
=
programs
.
length
;
i
<
il
;
i
++
)
{
if
(
programInfo
.
program
===
program
)
{
programInfo
=
programs
[
i
]
;
programInfo
.
usedTimes
--
;
if
(
programInfo
.
program
===
program
)
{
if
(
programInfo
.
usedTimes
===
0
)
{
programInfo
.
usedTimes
--
;
deleteProgram
=
true
;
if
(
programInfo
.
usedTimes
===
0
)
{
}
deleteProgram
=
true
;
break
;
}
break
;
}
}
if
(
deleteProgram
===
true
)
{
if
(
deleteProgram
===
true
)
{
// avoid using array.splice, this is costlier than creating new array from scratch
// avoid using array.splice, this is costlier than creating new array from scratch
var
newPrograms
=
[];
var
newPrograms
=
[];
for
(
i
=
0
,
il
=
programs
.
length
;
i
<
il
;
i
++
)
{
for
(
i
=
0
,
il
=
programs
.
length
;
i
<
il
;
i
++
)
{
programInfo
=
programs
[
i
];
programInfo
=
programs
[
i
];
if
(
programInfo
.
program
!==
program
)
{
if
(
programInfo
.
program
!==
program
)
{
newPrograms
.
push
(
programInfo
);
newPrograms
.
push
(
programInfo
);
}
}
}
programs
=
newPrograms
;
programs
=
newPrograms
;
this
.
renderer
.
deleteProgram
(
program
)
;
this
.
renderer
.
deleteProgram
(
program
)
;
this
.
info
.
memory
.
programs
--
;
this
.
info
.
memory
.
programs
--
;
}
}
}
}
);
utils/build/includes/commonOld.json
浏览文件 @
3b63de52
...
...
@@ -74,7 +74,7 @@
"src/scenes/FogExp2.js"
,
"src/renderers/CanvasRenderer.js"
,
"src/renderers/WebGLShaders.js"
,
"src/renderers/WebGLRenderer.js"
,
"src/renderers/WebGLRenderer
Old
.js"
,
"src/renderers/WebGLRenderTarget.js"
,
"src/renderers/WebGLRenderTargetCube.js"
,
"src/renderers/renderables/RenderableVertex.js"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录