提交 2752ab4c 编写于 作者: T Takahiro

Add DataTexture2DArray

上级 a9e6a124
......@@ -117,6 +117,7 @@ function glconstants() {
ACTIVE_ATTRIBUTES: 35721,
IMPLEMENTATION_COLOR_READ_TYPE: 35738,
IMPLEMENTATION_COLOR_READ_FORMAT: 35739,
TEXTURE_2D_ARRAY: 35866,
DEPTH_COMPONENT32F: 36012,
COLOR_ATTACHMENT0: 36064,
FRAMEBUFFER_COMPLETE: 36053,
......
......@@ -24,6 +24,7 @@ export { Points } from './objects/Points.js';
export { Group } from './objects/Group.js';
export { VideoTexture } from './textures/VideoTexture.js';
export { DataTexture } from './textures/DataTexture.js';
export { DataTexture2DArray } from './textures/DataTexture2DArray.js';
export { DataTexture3D } from './textures/DataTexture3D.js';
export { CompressedTexture } from './textures/CompressedTexture.js';
export { CubeTexture } from './textures/CubeTexture.js';
......
......@@ -2462,6 +2462,12 @@ function WebGLRenderer( parameters ) {
}() );
this.setTexture2DArray = function ( texture, slot ) {
textures.setTexture2DArray( texture, slot );
};
this.setTexture3D = ( function () {
// backwards compatibility: peel texture.texture
......
......@@ -297,6 +297,22 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
function setTexture2DArray( 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_2D_ARRAY, textureProperties.__webglTexture );
}
function setTexture3D( texture, slot ) {
var textureProperties = properties.get( texture );
......@@ -449,7 +465,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
if ( textureType === _gl.TEXTURE_3D ) {
if ( textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY ) {
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, utils.convert( texture.wrapR ) );
......@@ -463,7 +479,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
if ( textureType === _gl.TEXTURE_3D ) {
if ( textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY ) {
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, _gl.CLAMP_TO_EDGE );
......@@ -522,7 +538,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function uploadTexture( textureProperties, texture, slot ) {
var textureType = ( texture.isDataTexture3D ) ? _gl.TEXTURE_3D : _gl.TEXTURE_2D;
var textureType = _gl.TEXTURE_2D;
if ( texture.isDataTexture2DArray ) textureType = _gl.TEXTURE_2D_ARRAY;
if ( texture.isDataTexture3D ) textureType = _gl.TEXTURE_3D;
initTexture( textureProperties, texture );
......@@ -654,6 +673,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
textureProperties.__maxMipLevel = mipmaps.length - 1;
} else if ( texture.isDataTexture2DArray ) {
state.texImage3D( _gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
textureProperties.__maxMipLevel = 0;
} else if ( texture.isDataTexture3D ) {
state.texImage3D( _gl.TEXTURE_3D, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
......@@ -1052,6 +1076,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
this.setTexture2D = setTexture2D;
this.setTexture2DArray = setTexture2DArray;
this.setTexture3D = setTexture3D;
this.setTextureCube = setTextureCube;
this.setTextureCubeDynamic = setTextureCubeDynamic;
......
......@@ -390,6 +390,22 @@ function setValueT1( gl, v, renderer ) {
}
function setValueT2DArray1( gl, v, renderer ) {
var cache = this.cache;
var unit = renderer.allocTextureUnit();
if ( cache[ 0 ] !== unit ) {
gl.uniform1i( this.addr, unit );
cache[ 0 ] = unit;
}
renderer.setTexture2DArray( v || emptyTexture2dArray, unit );
}
function setValueT3D1( gl, v, renderer ) {
var cache = this.cache;
......@@ -478,6 +494,7 @@ function getSingularSetter( type ) {
case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
case 0x8B5F: return setValueT3D1; // SAMPLER_3D
case 0x8b60: return setValueT6; // SAMPLER_CUBE
case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
......
import { Texture } from './Texture';
import { NearestFilter } from '../constants';
import { TypedArray } from '../polyfills';
export class DataTexture2DArray extends Texture {
constructor(
data: ArrayBuffer | TypedArray,
width: number,
height: number,
depth: number
);
}
/**
* @author Takahiro https://github.com/takahirox
*/
import { Texture } from './Texture.js';
import { ClampToEdgeWrapping, NearestFilter } from '../constants.js';
function DataTexture2DArray( data, width, height, depth ) {
Texture.call( this, null );
this.image = { data: data, width: width, height: height, depth: depth };
this.magFilter = NearestFilter;
this.minFilter = NearestFilter;
this.wrapR = ClampToEdgeWrapping;
this.generateMipmaps = false;
this.flipY = false;
}
DataTexture2DArray.prototype = Object.create( Texture.prototype );
DataTexture2DArray.prototype.constructor = DataTexture2DArray;
DataTexture2DArray.prototype.isDataTexture2DArray = true;
export { DataTexture2DArray };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册