Sfoglia il codice sorgente

Some clean up.
Testing out texImage2D instead of texSubImage2D again.
@alteredq: which browsers/os didn't like this combo?

Mr.doob 14 anni fa
parent
commit
8bf95541b0
4 ha cambiato i file con 88 aggiunte e 88 eliminazioni
  1. 1 1
      build/Three.js
  2. 1 1
      build/custom/ThreeWebGL.js
  3. 36 35
      src/renderers/WebGLRenderer.js
  4. 50 51
      src/renderers/WebGLShaders.js

File diff suppressed because it is too large
+ 1 - 1
build/Three.js


File diff suppressed because it is too large
+ 1 - 1
build/custom/ThreeWebGL.js


+ 36 - 35
src/renderers/WebGLRenderer.js

@@ -102,20 +102,20 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		}
 
+		console.log(
+			navigator.userAgent + " | " +
+			_gl.getParameter( _gl.VERSION ) + " | " +
+			_gl.getParameter( _gl.VENDOR ) + " | " +
+			_gl.getParameter( _gl.RENDERER ) + " | " +
+			_gl.getParameter( _gl.SHADING_LANGUAGE_VERSION )
+		);
+
 	} catch ( error ) {
 
 		console.error( error );
 
 	}
 
-	console.log(
-		navigator.userAgent + " | " +
-		_gl.getParameter( _gl.VERSION ) + " | " +
-		_gl.getParameter( _gl.VENDOR ) + " | " +
-		_gl.getParameter( _gl.RENDERER ) + " | " +
-		_gl.getParameter( _gl.SHADING_LANGUAGE_VERSION )
-	);
-
 	_gl.clearColor( 0, 0, 0, 1 );
 	_gl.clearDepth( 1 );
 
@@ -132,8 +132,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	_gl.clearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
 
-	// _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, true );
-
 	_cullEnabled = true;
 
 	//
@@ -4523,29 +4521,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		program = _gl.createProgram();
 
-		var prefix_fragment = [
-
-			"#ifdef GL_ES",
-			"precision highp float;",
-			"#endif",
-
-			"#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
-			"#define MAX_POINT_LIGHTS " + parameters.maxPointLights,
-
-			parameters.fog ? "#define USE_FOG" : "",
-			parameters.fog instanceof THREE.FogExp2 ? "#define FOG_EXP2" : "",
-
-			parameters.map ? "#define USE_MAP" : "",
-			parameters.envMap ? "#define USE_ENVMAP" : "",
-			parameters.lightMap ? "#define USE_LIGHTMAP" : "",
-			parameters.vertexColors ? "#define USE_COLOR" : "",
-
-			"uniform mat4 viewMatrix;",
-			"uniform vec3 cameraPosition;",
-			""
-
-		].join("\n");
-
 		var prefix_vertex = [
 
 			_supportsVertexTextures ? "#define VERTEX_TEXTURES" : "",
@@ -4610,6 +4585,29 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		].join("\n");
 
+		var prefix_fragment = [
+
+			"#ifdef GL_ES",
+			"precision highp float;",
+			"#endif",
+
+			"#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
+			"#define MAX_POINT_LIGHTS " + parameters.maxPointLights,
+
+			parameters.fog ? "#define USE_FOG" : "",
+			parameters.fog instanceof THREE.FogExp2 ? "#define FOG_EXP2" : "",
+
+			parameters.map ? "#define USE_MAP" : "",
+			parameters.envMap ? "#define USE_ENVMAP" : "",
+			parameters.lightMap ? "#define USE_LIGHTMAP" : "",
+			parameters.vertexColors ? "#define USE_COLOR" : "",
+
+			"uniform mat4 viewMatrix;",
+			"uniform vec3 cameraPosition;",
+			""
+
+		].join("\n");
+
 		_gl.attachShader( program, getShader( "fragment", prefix_fragment + fragmentShader ) );
 		_gl.attachShader( program, getShader( "vertex", prefix_vertex + vertexShader ) );
 
@@ -4839,6 +4837,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 				texture.__webglTexture = _gl.createTexture();
 
 				_gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
+				// _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, true );
 				_gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image );
 
 				texture.__webglInit = true;
@@ -4846,12 +4845,14 @@ THREE.WebGLRenderer = function ( parameters ) {
 			} else {
 
 				_gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
-				// _gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image );
-				_gl.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image );
+				// _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, true );
+				_gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image );
+				// _gl.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image );
 
 			}
 
 			setTextureParameters( _gl.TEXTURE_2D, texture, texture.image );
+
 			_gl.bindTexture( _gl.TEXTURE_2D, null );
 
 			texture.needsUpdate = false;

+ 50 - 51
src/renderers/WebGLShaders.js

@@ -140,43 +140,43 @@ THREE.ShaderChunk = {
 
 	// COLOR MAP (triangles)
 
-	map_pars_fragment: [
+	map_pars_vertex: [
 
 	"#ifdef USE_MAP",
 
 		"varying vec2 vUv;",
-		"uniform sampler2D map;",
+		"uniform vec4 offsetRepeat;",
 
 	"#endif"
 
 	].join("\n"),
 
-	map_pars_vertex: [
+	map_pars_fragment: [
 
 	"#ifdef USE_MAP",
 
 		"varying vec2 vUv;",
-		"uniform vec4 offsetRepeat;",
+		"uniform sampler2D map;",
 
 	"#endif"
 
 	].join("\n"),
 
-	map_fragment: [
+	map_vertex: [
 
 	"#ifdef USE_MAP",
 
-		"gl_FragColor = gl_FragColor * texture2D( map, vUv );",
+		"vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
 
 	"#endif"
 
 	].join("\n"),
 
-	map_vertex: [
+	map_fragment: [
 
 	"#ifdef USE_MAP",
 
-		"vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
+		"gl_FragColor = gl_FragColor * texture2D( map, vUv );",
 
 	"#endif"
 
@@ -632,17 +632,17 @@ THREE.ShaderLib = {
 
 		vertexShader: [
 
-			"uniform 	vec3 	screenPosition;",
-			"uniform	vec2	scale;",
-			"uniform	float	rotation;",
-			"uniform    int     renderType;",
+			"uniform vec3 screenPosition;",
+			"uniform vec2 scale;",
+			"uniform float rotation;",
+			"uniform int renderType;",
 
-			"uniform	sampler2D	occlusionMap;",
+			"uniform sampler2D occlusionMap;",
 
-			"attribute 	vec2 	position;",
-			"attribute  vec2	UV;",
-			"varying	vec2	vUV;",
-			"varying	float	vVisibility;",
+			"attribute vec2 position;",
+			"attribute vec2 UV;",
+			"varying vec2 vUV;",
+			"varying float vVisibility;",
 
 			"void main() {",
 
@@ -684,12 +684,12 @@ THREE.ShaderLib = {
 				"precision highp float;",
 			"#endif",
 
-			"uniform	sampler2D	map;",
-			"uniform	float		opacity;",
-			"uniform    int         renderType;",
+			"uniform sampler2D map;",
+			"uniform float opacity;",
+			"uniform int renderType;",
 
-			"varying	vec2		vUV;",
-			"varying	float		vVisibility;",
+			"varying vec2 vUV;",
+			"varying float vVisibility;",
 
 			"void main() {",
 
@@ -725,15 +725,15 @@ THREE.ShaderLib = {
 
 		vertexShader: [
 
-			"uniform 	vec3 	screenPosition;",
-			"uniform	vec2	scale;",
-			"uniform	float	rotation;",
-			"uniform    int     renderType;",
+			"uniform vec3 screenPosition;",
+			"uniform vec2 scale;",
+			"uniform float rotation;",
+			"uniform int renderType;",
 
-			"attribute 	vec2 	position;",
-			"attribute  vec2	UV;",
+			"attribute vec2 position;",
+			"attribute vec2 UV;",
 
-			"varying	vec2	vUV;",
+			"varying vec2 vUV;",
 
 			"void main() {",
 
@@ -760,12 +760,12 @@ THREE.ShaderLib = {
 				"precision highp float;",
 			"#endif",
 
-			"uniform	sampler2D	map;",
-			"uniform	sampler2D	occlusionMap;",
-			"uniform	float		opacity;",
-			"uniform    int         renderType;",
+			"uniform sampler2D map;",
+			"uniform sampler2D occlusionMap;",
+			"uniform float opacity;",
+			"uniform int renderType;",
 
-			"varying	vec2		vUV;",
+			"varying vec2 vUV;",
 
 			"void main() {",
 
@@ -808,25 +808,24 @@ THREE.ShaderLib = {
 
 		vertexShader: [
 
-			"uniform	int		useScreenCoordinates;",
-			"uniform    int     affectedByDistance;",
-			"uniform	vec3	screenPosition;",
-			"uniform 	mat4 	modelViewMatrix;",
-			"uniform 	mat4 	projectionMatrix;",
-			"uniform    float   rotation;",
-			"uniform    vec2    scale;",
-			"uniform    vec2    alignment;",
-			"uniform    vec2    uvOffset;",
-			"uniform	vec2    uvScale;",
+			"uniform int useScreenCoordinates;",
+			"uniform int affectedByDistance;",
+			"uniform vec3 screenPosition;",
+			"uniform mat4 modelViewMatrix;",
+			"uniform mat4 projectionMatrix;",
+			"uniform float rotation;",
+			"uniform vec2 scale;",
+			"uniform vec2 alignment;",
+			"uniform vec2 uvOffset;",
+			"uniform vec2 uvScale;",
 
-			"attribute 	vec2 	position;",
-			"attribute  vec2	uv;",
+			"attribute vec2 position;",
+			"attribute vec2 uv;",
 
-			"varying	vec2	vUV;",
+			"varying vec2 vUV;",
 
 			"void main() {",
 
-				//"vUV = uvOffset + vec2( uv.x, 1.0 - uv.y ) * uvScale;",
 				"vUV = uvOffset + uv * uvScale;",
 
 				"vec2 alignedPosition = position + alignment;",
@@ -860,10 +859,10 @@ THREE.ShaderLib = {
 				"precision highp float;",
 			"#endif",
 
-			"uniform	sampler2D	map;",
-			"uniform	float		opacity;",
+			"uniform sampler2D map;",
+			"uniform float opacity;",
 
-			"varying	vec2		vUV;",
+			"varying vec2 vUV;",
 
 			"void main() {",
 

Some files were not shown because too many files changed in this diff