|
@@ -104,6 +104,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( ! capabilities.isWebGL2 ) return glFormat;
|
|
if ( ! capabilities.isWebGL2 ) return glFormat;
|
|
|
|
|
|
|
|
+ if ( glFormat === _gl.RED ) {
|
|
|
|
+
|
|
|
|
+ if ( glType === _gl.FLOAT ) return _gl.R32F;
|
|
|
|
+ if ( glType === _gl.HALF_FLOAT ) return _gl.R16F;
|
|
|
|
+ if ( glType === _gl.UNSIGNED_BYTE ) return _gl.R8;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
if ( glFormat === _gl.RGB ) {
|
|
if ( glFormat === _gl.RGB ) {
|
|
|
|
|
|
if ( glType === _gl.FLOAT ) return _gl.RGB32F;
|
|
if ( glType === _gl.FLOAT ) return _gl.RGB32F;
|
|
@@ -273,6 +281,23 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function setTexture3D( texture, slot ) {
|
|
|
|
+
|
|
|
|
+ var textureProperties = properties.get( texture );
|
|
|
|
+
|
|
|
|
+ if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
|
|
|
|
+
|
|
|
|
+ uploadTexture( textureProperties, texture, slot );
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ state.activeTexture( _gl.TEXTURE0 + slot );
|
|
|
|
+ state.bindTexture( _gl.TEXTURE_3D, textureProperties.__webglTexture );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
function setTextureCube( texture, slot ) {
|
|
function setTextureCube( texture, slot ) {
|
|
|
|
|
|
var textureProperties = properties.get( texture );
|
|
var textureProperties = properties.get( texture );
|
|
@@ -462,6 +487,19 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function uploadTexture( textureProperties, texture, slot ) {
|
|
function uploadTexture( textureProperties, texture, slot ) {
|
|
|
|
|
|
|
|
+ var textureType;
|
|
|
|
+
|
|
|
|
+ if ( texture.isTexture3D ) {
|
|
|
|
+
|
|
|
|
+ textureType = _gl.TEXTURE_3D;
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ textureType = _gl.TEXTURE_2D;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
if ( textureProperties.__webglInit === undefined ) {
|
|
if ( textureProperties.__webglInit === undefined ) {
|
|
|
|
|
|
textureProperties.__webglInit = true;
|
|
textureProperties.__webglInit = true;
|
|
@@ -473,9 +511,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
info.memory.textures ++;
|
|
info.memory.textures ++;
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
state.activeTexture( _gl.TEXTURE0 + slot );
|
|
state.activeTexture( _gl.TEXTURE0 + slot );
|
|
- state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ state.bindTexture( textureType, textureProperties.__webglTexture );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
_gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
|
|
_gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
|
|
_gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
|
|
_gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
|
|
@@ -494,7 +535,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
glType = utils.convert( texture.type ),
|
|
glType = utils.convert( texture.type ),
|
|
glInternalFormat = getInternalFormat( glFormat, glType );
|
|
glInternalFormat = getInternalFormat( glFormat, glType );
|
|
|
|
|
|
- setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
|
|
|
|
|
|
+ setTextureParameters( textureType, texture, isPowerOfTwoImage );
|
|
|
|
|
|
var mipmap, mipmaps = texture.mipmaps;
|
|
var mipmap, mipmaps = texture.mipmaps;
|
|
|
|
|
|
@@ -607,6 +648,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
textureProperties.__maxMipLevel = mipmaps.length - 1;
|
|
textureProperties.__maxMipLevel = mipmaps.length - 1;
|
|
|
|
|
|
|
|
+ } else if ( texture.isTexture3D ) {
|
|
|
|
+
|
|
|
|
+ state.texImage3D( _gl.TEXTURE_3D, 0, glInternalFormat, image.width, image.height, image.length, 0, glFormat, glType, image.data );
|
|
|
|
+ textureProperties.__maxMipLevel = 0;
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
|
|
|
|
// regular Texture (image, video, canvas)
|
|
// regular Texture (image, video, canvas)
|
|
@@ -890,6 +936,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
}
|
|
}
|
|
|
|
|
|
this.setTexture2D = setTexture2D;
|
|
this.setTexture2D = setTexture2D;
|
|
|
|
+ this.setTexture3D = setTexture3D;
|
|
this.setTextureCube = setTextureCube;
|
|
this.setTextureCube = setTextureCube;
|
|
this.setTextureCubeDynamic = setTextureCubeDynamic;
|
|
this.setTextureCubeDynamic = setTextureCubeDynamic;
|
|
this.setupRenderTarget = setupRenderTarget;
|
|
this.setupRenderTarget = setupRenderTarget;
|