Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
640f046f
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,发现更多精彩内容 >>
未验证
提交
640f046f
编写于
3月 26, 2019
作者:
M
Mr.doob
提交者:
GitHub
3月 26, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16069 from mrdoob/webgluniforms
WebGLUniforms: Remove WebGLRenderer dependency.
上级
de338cfb
08ce26f2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
134 addition
and
175 deletion
+134
-175
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+4
-116
src/renderers/webgl/WebGLProgram.js
src/renderers/webgl/WebGLProgram.js
+1
-1
src/renderers/webgl/WebGLTextures.js
src/renderers/webgl/WebGLTextures.js
+90
-1
src/renderers/webgl/WebGLUniforms.d.ts
src/renderers/webgl/WebGLUniforms.d.ts
+3
-7
src/renderers/webgl/WebGLUniforms.js
src/renderers/webgl/WebGLUniforms.js
+36
-50
未找到文件。
src/renderers/WebGLRenderer.js
浏览文件 @
640f046f
...
...
@@ -145,10 +145,6 @@ function WebGLRenderer( parameters ) {
//
_usedTextureUnits
=
0
,
//
_width
=
_canvas
.
width
,
_height
=
_canvas
.
height
,
...
...
@@ -1635,7 +1631,7 @@ function WebGLRenderer( parameters ) {
function
setProgram
(
camera
,
fog
,
material
,
object
)
{
_usedTextureUnits
=
0
;
textures
.
resetTextureUnits
()
;
var
materialProperties
=
properties
.
get
(
material
);
var
lights
=
currentRenderState
.
state
.
lights
;
...
...
@@ -1822,7 +1818,7 @@ function WebGLRenderer( parameters ) {
}
p_uniforms
.
setValue
(
_gl
,
'
boneTexture
'
,
skeleton
.
boneTexture
);
p_uniforms
.
setValue
(
_gl
,
'
boneTexture
'
,
skeleton
.
boneTexture
,
textures
);
p_uniforms
.
setValue
(
_gl
,
'
boneTextureSize
'
,
skeleton
.
boneTextureSize
);
}
else
{
...
...
@@ -1952,13 +1948,13 @@ function WebGLRenderer( parameters ) {
if
(
m_uniforms
.
ltc_1
!==
undefined
)
m_uniforms
.
ltc_1
.
value
=
UniformsLib
.
LTC_1
;
if
(
m_uniforms
.
ltc_2
!==
undefined
)
m_uniforms
.
ltc_2
.
value
=
UniformsLib
.
LTC_2
;
WebGLUniforms
.
upload
(
_gl
,
materialProperties
.
uniformsList
,
m_uniforms
,
_this
,
textures
);
WebGLUniforms
.
upload
(
_gl
,
materialProperties
.
uniformsList
,
m_uniforms
,
textures
);
}
if
(
material
.
isShaderMaterial
&&
material
.
uniformsNeedUpdate
===
true
)
{
WebGLUniforms
.
upload
(
_gl
,
materialProperties
.
uniformsList
,
m_uniforms
,
_this
,
textures
);
WebGLUniforms
.
upload
(
_gl
,
materialProperties
.
uniformsList
,
m_uniforms
,
textures
);
material
.
uniformsNeedUpdate
=
false
;
}
...
...
@@ -2421,114 +2417,6 @@ function WebGLRenderer( parameters ) {
}
// Textures
function
allocTextureUnit
()
{
var
textureUnit
=
_usedTextureUnits
;
if
(
textureUnit
>=
capabilities
.
maxTextures
)
{
console
.
warn
(
'
THREE.WebGLRenderer: Trying to use
'
+
textureUnit
+
'
texture units while this GPU supports only
'
+
capabilities
.
maxTextures
);
}
_usedTextureUnits
+=
1
;
return
textureUnit
;
}
this
.
allocTextureUnit
=
allocTextureUnit
;
// this.setTexture2D = setTexture2D;
this
.
setTexture2D
=
(
function
()
{
var
warned
=
false
;
// backwards compatibility: peel texture.texture
return
function
setTexture2D
(
texture
,
slot
)
{
if
(
texture
&&
texture
.
isWebGLRenderTarget
)
{
if
(
!
warned
)
{
console
.
warn
(
"
THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead.
"
);
warned
=
true
;
}
texture
=
texture
.
texture
;
}
textures
.
setTexture2D
(
texture
,
slot
);
};
}()
);
this
.
setTexture
=
(
function
()
{
var
warned
=
false
;
return
function
setTexture
(
texture
,
slot
)
{
if
(
!
warned
)
{
console
.
warn
(
"
THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead.
"
);
warned
=
true
;
}
textures
.
setTexture2D
(
texture
,
slot
);
};
}()
);
this
.
setTextureCube
=
(
function
()
{
var
warned
=
false
;
return
function
setTextureCube
(
texture
,
slot
)
{
// backwards compatibility: peel texture.texture
if
(
texture
&&
texture
.
isWebGLRenderTargetCube
)
{
if
(
!
warned
)
{
console
.
warn
(
"
THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead.
"
);
warned
=
true
;
}
texture
=
texture
.
texture
;
}
// currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
// TODO: unify these code paths
if
(
(
texture
&&
texture
.
isCubeTexture
)
||
(
Array
.
isArray
(
texture
.
image
)
&&
texture
.
image
.
length
===
6
)
)
{
// CompressedTexture can have Array in image :/
// this function alone should take care of cube textures
textures
.
setTextureCube
(
texture
,
slot
);
}
else
{
// assumed: texture property of THREE.WebGLRenderTargetCube
textures
.
setTextureCubeDynamic
(
texture
,
slot
);
}
};
}()
);
//
this
.
setFramebuffer
=
function
(
value
)
{
...
...
src/renderers/webgl/WebGLProgram.js
浏览文件 @
640f046f
...
...
@@ -670,7 +670,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
if
(
cachedUniforms
===
undefined
)
{
cachedUniforms
=
new
WebGLUniforms
(
gl
,
program
,
renderer
,
textures
);
cachedUniforms
=
new
WebGLUniforms
(
gl
,
program
,
textures
);
}
...
...
src/renderers/webgl/WebGLTextures.js
浏览文件 @
640f046f
...
...
@@ -265,7 +265,31 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
//
var
textureUnits
=
0
;
function
resetTextureUnits
()
{
textureUnits
=
0
;
}
function
allocateTextureUnit
()
{
var
textureUnit
=
textureUnits
;
if
(
textureUnit
>=
capabilities
.
maxTextures
)
{
console
.
warn
(
'
THREE.WebGLTextures: Trying to use
'
+
textureUnit
+
'
texture units while this GPU supports only
'
+
capabilities
.
maxTextures
);
}
textureUnits
+=
1
;
return
textureUnit
;
}
//
function
setTexture2D
(
texture
,
slot
)
{
...
...
@@ -1077,6 +1101,69 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
// backwards compatibility
var
warnedTexture2D
=
false
;
var
warnedTextureCube
=
false
;
function
safeSetTexture2D
(
texture
,
slot
)
{
if
(
texture
&&
texture
.
isWebGLRenderTarget
)
{
if
(
warnedTexture2D
===
false
)
{
console
.
warn
(
"
THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead.
"
);
warnedTexture2D
=
true
;
}
texture
=
texture
.
texture
;
}
setTexture2D
(
texture
,
slot
);
}
function
safeSetTextureCube
(
texture
,
slot
)
{
if
(
texture
&&
texture
.
isWebGLRenderTargetCube
)
{
if
(
warnedTextureCube
===
false
)
{
console
.
warn
(
"
THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead.
"
);
warnedTextureCube
=
true
;
}
texture
=
texture
.
texture
;
}
// currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
// TODO: unify these code paths
if
(
(
texture
&&
texture
.
isCubeTexture
)
||
(
Array
.
isArray
(
texture
.
image
)
&&
texture
.
image
.
length
===
6
)
)
{
// CompressedTexture can have Array in image :/
// this function alone should take care of cube textures
setTextureCube
(
texture
,
slot
);
}
else
{
// assumed: texture property of THREE.WebGLRenderTargetCube
setTextureCubeDynamic
(
texture
,
slot
);
}
}
//
this
.
allocateTextureUnit
=
allocateTextureUnit
;
this
.
resetTextureUnits
=
resetTextureUnits
;
this
.
setTexture2D
=
setTexture2D
;
this
.
setTexture2DArray
=
setTexture2DArray
;
this
.
setTexture3D
=
setTexture3D
;
...
...
@@ -1086,7 +1173,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
this
.
updateRenderTargetMipmap
=
updateRenderTargetMipmap
;
this
.
updateMultisampleRenderTarget
=
updateMultisampleRenderTarget
;
}
this
.
safeSetTexture2D
=
safeSetTexture2D
;
this
.
safeSetTextureCube
=
safeSetTextureCube
;
}
export
{
WebGLTextures
};
src/renderers/webgl/WebGLUniforms.d.ts
浏览文件 @
640f046f
import
{
WebGLProgram
}
from
'
./WebGLProgram
'
;
import
{
WebGLRenderer
}
from
'
./../WebGLRenderer
'
;
import
{
WebGLTextures
}
from
'
./WebGLTextures
'
;
export
class
WebGLUniforms
{
constructor
(
gl
:
any
,
program
:
WebGLProgram
,
renderer
:
WebGLRenderer
,
textures
:
WebGLTextures
);
constructor
(
gl
:
any
,
program
:
WebGLProgram
);
renderer
:
WebGLRenderer
;
setValue
(
gl
:
any
,
name
:
string
,
value
:
any
):
void
;
set
(
gl
:
any
,
object
:
any
,
name
:
string
):
void
;
setValue
(
gl
:
any
,
name
:
string
,
value
:
any
,
textures
:
WebGLTextures
):
void
;
setOptional
(
gl
:
any
,
object
:
any
,
name
:
string
):
void
;
static
upload
(
gl
:
any
,
seq
:
any
,
values
:
any
[],
renderer
:
WebGLRenderer
,
textures
:
WebGLTextures
):
void
;
static
upload
(
gl
:
any
,
seq
:
any
,
values
:
any
[],
textures
:
WebGLTextures
):
void
;
static
seqWithValue
(
seq
:
any
,
values
:
any
[]):
any
[];
static
splitDynamic
(
seq
:
any
,
values
:
any
[]):
any
[];
static
evalDynamic
(
seq
:
any
,
values
:
any
[],
object
:
any
,
camera
:
any
):
any
[];
...
...
src/renderers/webgl/WebGLUniforms.js
浏览文件 @
640f046f
...
...
@@ -5,7 +5,7 @@
*
* Uniforms of a program.
* Those form a tree structure with a special top-level container for the root,
* which you get by calling 'new WebGLUniforms( gl, program
, renderer
)'.
* which you get by calling 'new WebGLUniforms( gl, program )'.
*
*
* Properties of inner nodes including the top-level container:
...
...
@@ -16,15 +16,15 @@
*
* Methods of all nodes except the top-level container:
*
* .setValue( gl, value, [
renderer
] )
* .setValue( gl, value, [
textures
] )
*
* uploads a uniform value(s)
* the '
renderer
' parameter is needed for sampler uniforms
* the '
textures
' parameter is needed for sampler uniforms
*
*
* Static methods of the top-level container (
renderer
factorizations):
* Static methods of the top-level container (
textures
factorizations):
*
* .upload( gl, seq, values,
renderer
)
* .upload( gl, seq, values,
textures
)
*
* sets uniforms in 'seq' to 'values[id].value'
*
...
...
@@ -33,16 +33,12 @@
* filters 'seq' entries with corresponding entry in values
*
*
* Methods of the top-level container (
renderer
factorizations):
* Methods of the top-level container (
textures
factorizations):
*
* .setValue( gl, name, value )
* .setValue( gl, name, value
, textures
)
*
* sets uniform with name 'name' to 'value'
*
* .set( gl, obj, prop )
*
* sets uniform from object and property with same name than uniform
*
* .setOptional( gl, obj, prop )
*
* like .set for an optional property of the object
...
...
@@ -59,15 +55,6 @@ var emptyTexture2dArray = new DataTexture2DArray();
var
emptyTexture3d
=
new
DataTexture3D
();
var
emptyCubeTexture
=
new
CubeTexture
();
// --- Base for inner nodes (including the root) ---
function
UniformContainer
()
{
this
.
seq
=
[];
this
.
map
=
{};
}
// --- Utilities ---
// Array Caches (provide typed arrays for temporary by size)
...
...
@@ -144,7 +131,7 @@ function copyArray( a, b ) {
// Texture unit allocation
function
allocTexUnits
(
renderer
,
n
)
{
function
allocTexUnits
(
textures
,
n
)
{
var
r
=
arrayCacheI32
[
n
];
...
...
@@ -156,7 +143,7 @@ function allocTexUnits( renderer, n ) {
}
for
(
var
i
=
0
;
i
!==
n
;
++
i
)
r
[
i
]
=
renderer
.
alloc
TextureUnit
();
r
[
i
]
=
textures
.
allocate
TextureUnit
();
return
r
;
...
...
@@ -376,10 +363,10 @@ function setValue4fm( gl, v ) {
// Single texture (2D / Cube)
function
setValueT1
(
gl
,
v
,
renderer
)
{
function
setValueT1
(
gl
,
v
,
textures
)
{
var
cache
=
this
.
cache
;
var
unit
=
renderer
.
alloc
TextureUnit
();
var
unit
=
textures
.
allocate
TextureUnit
();
if
(
cache
[
0
]
!==
unit
)
{
...
...
@@ -388,14 +375,14 @@ function setValueT1( gl, v, renderer ) {
}
renderer
.
s
etTexture2D
(
v
||
emptyTexture
,
unit
);
textures
.
safeS
etTexture2D
(
v
||
emptyTexture
,
unit
);
}
function
setValueT2DArray1
(
gl
,
v
,
renderer
,
textures
)
{
function
setValueT2DArray1
(
gl
,
v
,
textures
)
{
var
cache
=
this
.
cache
;
var
unit
=
renderer
.
alloc
TextureUnit
();
var
unit
=
textures
.
allocate
TextureUnit
();
if
(
cache
[
0
]
!==
unit
)
{
...
...
@@ -408,10 +395,10 @@ function setValueT2DArray1( gl, v, renderer, textures ) {
}
function
setValueT3D1
(
gl
,
v
,
renderer
,
textures
)
{
function
setValueT3D1
(
gl
,
v
,
textures
)
{
var
cache
=
this
.
cache
;
var
unit
=
renderer
.
alloc
TextureUnit
();
var
unit
=
textures
.
allocate
TextureUnit
();
if
(
cache
[
0
]
!==
unit
)
{
...
...
@@ -424,10 +411,10 @@ function setValueT3D1( gl, v, renderer, textures ) {
}
function
setValueT6
(
gl
,
v
,
renderer
)
{
function
setValueT6
(
gl
,
v
,
textures
)
{
var
cache
=
this
.
cache
;
var
unit
=
renderer
.
alloc
TextureUnit
();
var
unit
=
textures
.
allocate
TextureUnit
();
if
(
cache
[
0
]
!==
unit
)
{
...
...
@@ -436,7 +423,7 @@ function setValueT6( gl, v, renderer ) {
}
renderer
.
s
etTextureCube
(
v
||
emptyCubeTexture
,
unit
);
textures
.
safeS
etTextureCube
(
v
||
emptyCubeTexture
,
unit
);
}
...
...
@@ -616,12 +603,12 @@ function setValueM4a( gl, v ) {
// Array of textures (2D / Cube)
function
setValueT1a
(
gl
,
v
,
renderer
)
{
function
setValueT1a
(
gl
,
v
,
textures
)
{
var
cache
=
this
.
cache
;
var
n
=
v
.
length
;
var
units
=
allocTexUnits
(
renderer
,
n
);
var
units
=
allocTexUnits
(
textures
,
n
);
if
(
arraysEqual
(
cache
,
units
)
===
false
)
{
...
...
@@ -632,18 +619,18 @@ function setValueT1a( gl, v, renderer ) {
for
(
var
i
=
0
;
i
!==
n
;
++
i
)
{
renderer
.
s
etTexture2D
(
v
[
i
]
||
emptyTexture
,
units
[
i
]
);
textures
.
safeS
etTexture2D
(
v
[
i
]
||
emptyTexture
,
units
[
i
]
);
}
}
function
setValueT6a
(
gl
,
v
,
renderer
)
{
function
setValueT6a
(
gl
,
v
,
textures
)
{
var
cache
=
this
.
cache
;
var
n
=
v
.
length
;
var
units
=
allocTexUnits
(
renderer
,
n
);
var
units
=
allocTexUnits
(
textures
,
n
);
if
(
arraysEqual
(
cache
,
units
)
===
false
)
{
...
...
@@ -654,7 +641,7 @@ function setValueT6a( gl, v, renderer ) {
for
(
var
i
=
0
;
i
!==
n
;
++
i
)
{
renderer
.
s
etTextureCube
(
v
[
i
]
||
emptyCubeTexture
,
units
[
i
]
);
textures
.
safeS
etTextureCube
(
v
[
i
]
||
emptyCubeTexture
,
units
[
i
]
);
}
...
...
@@ -730,18 +717,19 @@ function StructuredUniform( id ) {
this
.
id
=
id
;
UniformContainer
.
call
(
this
);
// mix-in
this
.
seq
=
[];
this
.
map
=
{};
}
StructuredUniform
.
prototype
.
setValue
=
function
(
gl
,
value
,
renderer
)
{
StructuredUniform
.
prototype
.
setValue
=
function
(
gl
,
value
,
textures
)
{
var
seq
=
this
.
seq
;
for
(
var
i
=
0
,
n
=
seq
.
length
;
i
!==
n
;
++
i
)
{
var
u
=
seq
[
i
];
u
.
setValue
(
gl
,
value
[
u
.
id
],
renderer
);
u
.
setValue
(
gl
,
value
[
u
.
id
],
textures
);
}
...
...
@@ -821,12 +809,10 @@ function parseUniform( activeInfo, addr, container ) {
// Root Container
function
WebGLUniforms
(
gl
,
program
,
renderer
,
textures
)
{
function
WebGLUniforms
(
gl
,
program
)
{
UniformContainer
.
call
(
this
);
this
.
renderer
=
renderer
;
this
.
textures
=
textures
;
this
.
seq
=
[];
this
.
map
=
{};
var
n
=
gl
.
getProgramParameter
(
program
,
gl
.
ACTIVE_UNIFORMS
);
...
...
@@ -841,11 +827,11 @@ function WebGLUniforms( gl, program, renderer, textures ) {
}
WebGLUniforms
.
prototype
.
setValue
=
function
(
gl
,
name
,
value
)
{
WebGLUniforms
.
prototype
.
setValue
=
function
(
gl
,
name
,
value
,
textures
)
{
var
u
=
this
.
map
[
name
];
if
(
u
!==
undefined
)
u
.
setValue
(
gl
,
value
,
t
his
.
renderer
,
this
.
t
extures
);
if
(
u
!==
undefined
)
u
.
setValue
(
gl
,
value
,
textures
);
};
...
...
@@ -860,7 +846,7 @@ WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
// Static interface
WebGLUniforms
.
upload
=
function
(
gl
,
seq
,
values
,
renderer
,
textures
)
{
WebGLUniforms
.
upload
=
function
(
gl
,
seq
,
values
,
textures
)
{
for
(
var
i
=
0
,
n
=
seq
.
length
;
i
!==
n
;
++
i
)
{
...
...
@@ -870,7 +856,7 @@ WebGLUniforms.upload = function ( gl, seq, values, renderer, textures ) {
if
(
v
.
needsUpdate
!==
false
)
{
// note: always updating when .needsUpdate is undefined
u
.
setValue
(
gl
,
v
.
value
,
renderer
,
textures
);
u
.
setValue
(
gl
,
v
.
value
,
textures
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录