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

Clean up.

上级 71008527
......@@ -6,6 +6,7 @@
THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
var _gl = _renderer.context,
_state = _renderer.state,
_frustum = new THREE.Frustum(),
_projScreenMatrix = new THREE.Matrix4(),
......@@ -99,7 +100,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
}
_renderer.state.setDepthTest( true );
_state.setDepthTest( true );
// preprocess lights
// - skip lights that are not casting shadows
......
......@@ -160,66 +160,67 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
this.setDepthFunc = function ( depthFunc ) {
if ( currentDepthFunc !== depthFunc ) {
if ( currentDepthFunc !== depthFunc ) {
if ( depthFunc ) {
if ( depthFunc ) {
switch ( depthFunc ) {
switch ( depthFunc ) {
case THREE.NeverDepth:
case THREE.NeverDepth:
gl.depthFunc( gl.NEVER );
break;
gl.depthFunc( gl.NEVER );
break;
case THREE.AlwaysDepth:
case THREE.AlwaysDepth:
gl.depthFunc( gl.ALWAYS );
break;
gl.depthFunc( gl.ALWAYS );
break;
case THREE.LessDepth:
case THREE.LessDepth:
gl.depthFunc( gl.LESS );
break;
gl.depthFunc( gl.LESS );
break;
case THREE.LessEqualDepth:
case THREE.LessEqualDepth:
gl.depthFunc( gl.LEQUAL );
break;
gl.depthFunc( gl.LEQUAL );
break;
case THREE.EqualDepth:
case THREE.EqualDepth:
gl.depthFunc( gl.EQUAL );
break;
gl.depthFunc( gl.EQUAL );
break;
case THREE.GreaterEqualDepth:
case THREE.GreaterEqualDepth:
gl.depthFunc( gl.GEQUAL );
break;
gl.depthFunc( gl.GEQUAL );
break;
case THREE.GreaterDepth:
case THREE.GreaterDepth:
gl.depthFunc( gl.GREATER );
break;
gl.depthFunc( gl.GREATER );
break;
case THREE.NotEqualDepth:
case THREE.NotEqualDepth:
gl.depthFunc( gl.NOTEQUAL );
break;
gl.depthFunc( gl.NOTEQUAL );
break;
default:
default:
gl.depthFunc( gl.LEQUAL );
}
gl.depthFunc( gl.LEQUAL );
} else {
}
gl.depthFunc( gl.LEQUAL );
} else {
gl.depthFunc( gl.LEQUAL );
}
}
currentDepthFunc = depthFunc;
currentDepthFunc = depthFunc;
}
}
};
......
......@@ -6,6 +6,7 @@
THREE.LensFlarePlugin = function ( renderer, flares ) {
var gl = renderer.context;
var state = renderer.state;
var vertexBuffer, elementBuffer;
var program, attributes, uniforms;
......@@ -43,14 +44,14 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
tempTexture = gl.createTexture();
occlusionTexture = gl.createTexture();
renderer.state.bindTexture( gl.TEXTURE_2D, tempTexture );
state.bindTexture( gl.TEXTURE_2D, tempTexture );
gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
renderer.state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
......@@ -295,10 +296,10 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
gl.useProgram( program );
renderer.state.initAttributes();
renderer.state.enableAttribute( attributes.vertex );
renderer.state.enableAttribute( attributes.uv );
renderer.state.disableUnusedAttributes();
state.initAttributes();
state.enableAttribute( attributes.vertex );
state.enableAttribute( attributes.uv );
state.disableUnusedAttributes();
// loop through all lens flares to update their occlusion and positions
// setup gl and common used attribs/unforms
......@@ -346,10 +347,10 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
// save current RGB to temp texture
renderer.state.activeTexture( gl.TEXTURE0 );
renderer.state.bindTexture( gl.TEXTURE_2D, null );
renderer.state.activeTexture( gl.TEXTURE1 );
renderer.state.bindTexture( gl.TEXTURE_2D, tempTexture );
state.activeTexture( gl.TEXTURE0 );
state.bindTexture( gl.TEXTURE_2D, null );
state.activeTexture( gl.TEXTURE1 );
state.bindTexture( gl.TEXTURE_2D, tempTexture );
gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
......@@ -367,8 +368,8 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
// copy result to occlusionMap
renderer.state.activeTexture( gl.TEXTURE0 );
renderer.state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
state.activeTexture( gl.TEXTURE0 );
state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
......@@ -377,8 +378,8 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
gl.uniform1i( uniforms.renderType, 1 );
gl.disable( gl.DEPTH_TEST );
renderer.state.activeTexture( gl.TEXTURE1 );
renderer.state.bindTexture( gl.TEXTURE_2D, tempTexture );
state.activeTexture( gl.TEXTURE1 );
state.bindTexture( gl.TEXTURE_2D, tempTexture );
gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
......@@ -423,7 +424,7 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
gl.uniform1f( uniforms.opacity, sprite.opacity );
gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
renderer.state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
renderer.setTexture( sprite.texture, 1 );
gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
......
......@@ -6,6 +6,7 @@
THREE.SpritePlugin = function ( renderer, sprites ) {
var gl = renderer.context;
var state = renderer.state;
var vertexBuffer, elementBuffer;
var program, attributes, uniforms;
......@@ -98,10 +99,10 @@ THREE.SpritePlugin = function ( renderer, sprites ) {
gl.useProgram( program );
renderer.state.initAttributes();
renderer.state.enableAttribute( attributes.position );
renderer.state.enableAttribute( attributes.uv );
renderer.state.disableUnusedAttributes();
state.initAttributes();
state.enableAttribute( attributes.position );
state.enableAttribute( attributes.uv );
state.disableUnusedAttributes();
gl.disable( gl.CULL_FACE );
gl.enable( gl.BLEND );
......@@ -114,7 +115,7 @@ THREE.SpritePlugin = function ( renderer, sprites ) {
gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
renderer.state.activeTexture( gl.TEXTURE0 );
state.activeTexture( gl.TEXTURE0 );
gl.uniform1i( uniforms.map, 0 );
var oldFogType = 0;
......@@ -216,9 +217,9 @@ THREE.SpritePlugin = function ( renderer, sprites ) {
gl.uniform1f( uniforms.rotation, material.rotation );
gl.uniform2fv( uniforms.scale, scale );
renderer.state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
renderer.state.setDepthTest( material.depthTest );
renderer.state.setDepthWrite( material.depthWrite );
state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
state.setDepthTest( material.depthTest );
state.setDepthWrite( material.depthWrite );
if ( material.map && material.map.image && material.map.image.width ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册