|
@@ -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 );
|