提交 c1cb8e90 编写于 作者: A alteredq

Added handling of 2d textures in MeshShaderMaterial.

上级 0f918488
此差异已折叠。
此差异已折叠。
此差异已折叠。
...@@ -445,26 +445,9 @@ THREE.WebGLRenderer = function ( scene ) { ...@@ -445,26 +445,9 @@ THREE.WebGLRenderer = function ( scene ) {
if ( mMap ) { if ( mMap ) {
if ( !material.map.__webGLTexture && material.map.image.loaded ) { setTexture( mMap, 0 );
material.map.__webGLTexture = _gl.createTexture();
_gl.bindTexture( _gl.TEXTURE_2D, material.map.__webGLTexture );
_gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, _gl.RGBA, _gl.UNSIGNED_BYTE, material.map.image );
_gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, paramThreeToGL( material.map.wrap_s ) );
_gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, paramThreeToGL( material.map.wrap_t ) );
_gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MAG_FILTER, _gl.LINEAR );
_gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, _gl.LINEAR_MIPMAP_LINEAR );
_gl.generateMipmap( _gl.TEXTURE_2D );
_gl.bindTexture( _gl.TEXTURE_2D, null );
}
_gl.activeTexture( _gl.TEXTURE0 );
_gl.bindTexture( _gl.TEXTURE_2D, material.map.__webGLTexture );
_gl.uniform1i( program.uniforms.tMap, 0 ); _gl.uniform1i( program.uniforms.tMap, 0 );
_gl.uniform1i( program.uniforms.enableMap, 1 ); _gl.uniform1i( program.uniforms.enableMap, 1 );
} else { } else {
...@@ -475,14 +458,9 @@ THREE.WebGLRenderer = function ( scene ) { ...@@ -475,14 +458,9 @@ THREE.WebGLRenderer = function ( scene ) {
if ( envMap ) { if ( envMap ) {
if ( material.env_map ) { setCubeTexture( envMap, 1 );
setCubeTexture( material.env_map, 1 ); _gl.uniform1i( program.uniforms.tCube, 1 );
_gl.uniform1i( program.uniforms.tCube, 1 );
}
_gl.uniform1i( program.uniforms.enableCubeMap, 1 ); _gl.uniform1i( program.uniforms.enableCubeMap, 1 );
} else { } else {
...@@ -1212,7 +1190,16 @@ THREE.WebGLRenderer = function ( scene ) { ...@@ -1212,7 +1190,16 @@ THREE.WebGLRenderer = function ( scene ) {
_gl.uniform1i( location, value ); _gl.uniform1i( location, value );
texture = uniforms[u].texture; texture = uniforms[u].texture;
setCubeTexture( texture, value );
if ( texture instanceof THREE.TextureCube ) {
setCubeTexture( texture, value );
} else if ( texture instanceof THREE.Texture ) {
setTexture( texture, value );
}
} }
...@@ -1259,6 +1246,29 @@ THREE.WebGLRenderer = function ( scene ) { ...@@ -1259,6 +1246,29 @@ THREE.WebGLRenderer = function ( scene ) {
}; };
function setTexture( texture, slot ) {
if ( !texture.__webGLTexture && texture.image.loaded ) {
texture.__webGLTexture = _gl.createTexture();
_gl.bindTexture( _gl.TEXTURE_2D, texture.__webGLTexture );
_gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image );
_gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrap_s ) );
_gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrap_t ) );
_gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MAG_FILTER, _gl.LINEAR );
_gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, _gl.LINEAR_MIPMAP_LINEAR );
_gl.generateMipmap( _gl.TEXTURE_2D );
_gl.bindTexture( _gl.TEXTURE_2D, null );
}
_gl.activeTexture( _gl.TEXTURE0 + slot );
_gl.bindTexture( _gl.TEXTURE_2D, texture.__webGLTexture );
};
function cacheUniformLocations( program, identifiers ) { function cacheUniformLocations( program, identifiers ) {
var i, l, id; var i, l, id;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册