提交 01bebe5c 编写于 作者: A alteredq

Added DataTexture, for creating textures out of raw data.

DataTexture can be used in the same places like image / video based Texture (WebGLRenderer-only).

To be used like this:

var width = 64, height = 64, bytes = 3;
var data = new Uint8Array( width * height * bytes );

// fill data array with values 0 .. 255

var texture = DataTexture( data, width, height, THREE.RGBFormat );
texture.needsUpdate = true;

For the moment only UNSIGNED_BYTE type is supported.
上级 dc042582
此差异已折叠。
此差异已折叠。
/**
* @author alteredq / http://alteredqualia.com/
*/
THREE.DataTexture = function ( data, width, height, format, mapping, wrapS, wrapT, magFilter, minFilter ) {
THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter );
this.image = { data: data, width: width, height: height };
this.format = format !== undefined ? format : THREE.RGBAFormat;
};
THREE.DataTexture.prototype = new THREE.Texture();
THREE.DataTexture.prototype.constructor = THREE.DataTexture;
THREE.DataTexture.prototype = {
clone: function () {
var clonedTexture = new THREE.DataTexture( this.data.slice( 0 ), this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter );
clonedTexture.offset.copy( this.offset );
clonedTexture.repeat.copy( this.repeat );
return clonedTexture;
}
};
......@@ -5436,22 +5436,22 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( texture.needsUpdate ) {
if ( !texture.__webglInit ) {
if ( ! texture.__webglInit ) {
texture.__webglTexture = _gl.createTexture();
texture.__webglInit = true;
_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;
_gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
if ( texture.image.data ) {
_gl.texImage2D( _gl.TEXTURE_2D, 0, paramThreeToGL( texture.format ), texture.image.width, texture.image.height, 0, paramThreeToGL( texture.format ), _gl.UNSIGNED_BYTE, texture.image.data );
} else {
_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 );
// _gl.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image );
}
......@@ -5466,16 +5466,21 @@ THREE.WebGLRenderer = function ( parameters ) {
/*
if ( texture.needsUpdate ) {
if ( texture.__webglTexture ) {
if ( !texture.__webglInit ) {
texture.__webglTexture = _gl.createTexture();
texture.__webglTexture = _gl.deleteTexture( texture.__webglTexture );
_gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
_gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image );
}
texture.__webglInit = true;
texture.__webglTexture = _gl.createTexture();
} else {
_gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
_gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image );
_gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
_gl.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image );
}
setTextureParameters( _gl.TEXTURE_2D, texture, texture.image );
......
......@@ -52,6 +52,7 @@ COMMON_FILES = [
'materials/ParticleCanvasMaterial.js',
'materials/ParticleDOMMaterial.js',
'materials/Texture.js',
'materials/DataTexture.js',
'objects/Particle.js',
'objects/ParticleSystem.js',
'objects/Line.js',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册