提交 ac7a4dc8 编写于 作者: M Mr.doob

WebGLRenderer: Moved currentProgram to WebGLState.

上级 bdd1d907
...@@ -112,7 +112,6 @@ function WebGLRenderer( parameters ) { ...@@ -112,7 +112,6 @@ function WebGLRenderer( parameters ) {
// internal state cache // internal state cache
_currentProgram = null,
_currentRenderTarget = null, _currentRenderTarget = null,
_currentFramebuffer = null, _currentFramebuffer = null,
_currentMaterialId = - 1, _currentMaterialId = - 1,
...@@ -316,7 +315,6 @@ function WebGLRenderer( parameters ) { ...@@ -316,7 +315,6 @@ function WebGLRenderer( parameters ) {
function resetGLState() { function resetGLState() {
_currentProgram = null;
_currentCamera = null; _currentCamera = null;
_currentGeometryProgram = ''; _currentGeometryProgram = '';
...@@ -1676,10 +1674,7 @@ function WebGLRenderer( parameters ) { ...@@ -1676,10 +1674,7 @@ function WebGLRenderer( parameters ) {
p_uniforms = program.getUniforms(), p_uniforms = program.getUniforms(),
m_uniforms = materialProperties.shader.uniforms; m_uniforms = materialProperties.shader.uniforms;
if ( program.id !== _currentProgram ) { if ( state.useProgram( program.program ) ) {
_gl.useProgram( program.program );
_currentProgram = program.id;
refreshProgram = true; refreshProgram = true;
refreshMaterial = true; refreshMaterial = true;
......
...@@ -321,6 +321,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) { ...@@ -321,6 +321,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
var compressedTextureFormats = null; var compressedTextureFormats = null;
var currentProgram = null;
var currentBlending = null; var currentBlending = null;
var currentBlendEquation = null; var currentBlendEquation = null;
var currentBlendSrc = null; var currentBlendSrc = null;
...@@ -511,6 +513,22 @@ function WebGLState( gl, extensions, paramThreeToGL ) { ...@@ -511,6 +513,22 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
} }
function useProgram( program ) {
if ( currentProgram !== program ) {
gl.useProgram( program );
currentProgram = program;
return true;
}
return false;
}
function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) { function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
if ( blending !== NoBlending ) { if ( blending !== NoBlending ) {
...@@ -878,6 +896,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) { ...@@ -878,6 +896,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
currentTextureSlot = null; currentTextureSlot = null;
currentBoundTextures = {}; currentBoundTextures = {};
currentProgram = null;
currentBlending = null; currentBlending = null;
currentFlipSided = null; currentFlipSided = null;
...@@ -906,6 +926,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) { ...@@ -906,6 +926,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
disable: disable, disable: disable,
getCompressedTextureFormats: getCompressedTextureFormats, getCompressedTextureFormats: getCompressedTextureFormats,
useProgram: useProgram,
setBlending: setBlending, setBlending: setBlending,
setMaterial: setMaterial, setMaterial: setMaterial,
......
...@@ -208,7 +208,7 @@ function LensFlarePlugin( renderer, flares ) { ...@@ -208,7 +208,7 @@ function LensFlarePlugin( renderer, flares ) {
} }
gl.useProgram( program ); state.useProgram( program );
state.initAttributes(); state.initAttributes();
state.enableAttribute( attributes.vertex ); state.enableAttribute( attributes.vertex );
......
...@@ -100,7 +100,7 @@ function SpritePlugin( renderer, sprites ) { ...@@ -100,7 +100,7 @@ function SpritePlugin( renderer, sprites ) {
} }
gl.useProgram( program ); state.useProgram( program );
state.initAttributes(); state.initAttributes();
state.enableAttribute( attributes.position ); state.enableAttribute( attributes.position );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册