Browse Source

WebGLRenderer: Moved getCompressedTextureFormats to WebGLState.

Mr.doob 10 years ago
parent
commit
4448405337
2 changed files with 36 additions and 37 deletions
  1. 6 36
      src/renderers/WebGLRenderer.js
  2. 30 1
      src/renderers/webgl/WebGLState.js

+ 6 - 36
src/renderers/WebGLRenderer.js

@@ -191,10 +191,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	}
 
-	var state = new THREE.WebGLState( _gl, paramThreeToGL );
-	var properties = new THREE.WebGLProperties();
-	var objects = new THREE.WebGLObjects( _gl, properties, this.info );
-
 	var extensions = new THREE.WebGLExtensions( _gl );
 
 	extensions.get( 'OES_texture_float' );
@@ -216,6 +212,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	}
 
+	var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
+	var properties = new THREE.WebGLProperties();
+	var objects = new THREE.WebGLObjects( _gl, properties, this.info );
+
 	//
 
 	function glClearColor( r, g, b, a ) {
@@ -279,37 +279,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	//
 
-	var getCompressedTextureFormats = ( function () {
-
-		var array;
-
-		return function getCompressedTextureFormats() {
-
-			if ( array !== undefined ) {
-
-				return array;
-
-			}
-
-			array = [];
 
-			if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) || extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
-
-				var formats = _gl.getParameter( _gl.COMPRESSED_TEXTURE_FORMATS );
-
-				for ( var i = 0; i < formats.length; i ++ ) {
-
-					array.push( formats[ i ] );
-
-				}
-
-			}
-
-			return array;
-
-		};
-
-	} )();
 
 	//
 
@@ -3348,7 +3318,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
 
-					if ( getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
+					if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
 
 						state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
 
@@ -3532,7 +3502,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 							if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
 
-								if ( getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
+								if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
 
 									state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
 

+ 30 - 1
src/renderers/webgl/WebGLState.js

@@ -2,7 +2,7 @@
 * @author mrdoob / http://mrdoob.com/
 */
 
-THREE.WebGLState = function ( gl, paramThreeToGL ) {
+THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 
 	var _this = this;
 
@@ -11,6 +11,8 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
 
 	var capabilities = {};
 
+	var compressedTextureFormats = null;
+
 	var currentBlending = null;
 	var currentBlendEquation = null;
 	var currentBlendSrc = null;
@@ -115,6 +117,31 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
 
 	};
 
+	this.getCompressedTextureFormats = function () {
+
+		if ( compressedTextureFormats === null ) {
+
+			compressedTextureFormats = [];
+
+			if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
+			     extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
+
+				var formats = gl.getParameter( _gl.COMPRESSED_TEXTURE_FORMATS );
+
+				for ( var i = 0; i < formats.length; i ++ ) {
+
+					compressedTextureFormats.push( formats[ i ] );
+
+				}
+
+			}
+
+		}
+
+		return compressedTextureFormats;
+
+	};
+
 	this.getMaxPrecision = function ( precision ) {
 
 		if ( precision === 'highp' ) {
@@ -489,6 +516,8 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
 
 		capabilities = {};
 
+		compressedTextureFormats = null;
+
 		currentBlending = null;
 
 		currentDepthWrite = null;