@awayjs/stage
Version:
Stage for AwayJS
50 lines (49 loc) • 2.54 kB
JavaScript
import { __extends } from "tslib";
import { TextureBaseWebGL } from './TextureBaseWebGL';
var CubeTextureWebGL = /** @class */ (function (_super) {
__extends(CubeTextureWebGL, _super);
function CubeTextureWebGL(context, size) {
var _this = _super.call(this, context) || this;
_this._textureSelectorDictionary = new Array(6);
_this.textureType = 'textureCube';
var gl = _this._gl;
_this._size = size;
_this._glTexture = _this._gl.createTexture();
_this._textureSelectorDictionary[0] = gl.TEXTURE_CUBE_MAP_POSITIVE_X;
_this._textureSelectorDictionary[1] = gl.TEXTURE_CUBE_MAP_NEGATIVE_X;
_this._textureSelectorDictionary[2] = gl.TEXTURE_CUBE_MAP_POSITIVE_Y;
_this._textureSelectorDictionary[3] = gl.TEXTURE_CUBE_MAP_NEGATIVE_Y;
_this._textureSelectorDictionary[4] = gl.TEXTURE_CUBE_MAP_POSITIVE_Z;
_this._textureSelectorDictionary[5] = gl.TEXTURE_CUBE_MAP_NEGATIVE_Z;
return _this;
}
CubeTextureWebGL.prototype.uploadFromArray = function (array, side, miplevel, premultiplied) {
if (miplevel === void 0) { miplevel = 0; }
if (premultiplied === void 0) { premultiplied = false; }
if (array.length != this._size * this._size * 4)
throw new Error('Array is not the correct length for texture dimensions');
if (array instanceof Array)
array = new Uint8Array(array);
this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, this._glTexture);
this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiplied);
this._gl.texImage2D(this._textureSelectorDictionary[side], miplevel, this._gl.RGBA, this._size, this._size, 0, this._gl.RGBA, this._gl.UNSIGNED_BYTE, array);
this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
};
CubeTextureWebGL.prototype.uploadCompressedTextureFromArray = function (array, offset /*uint*/, async) {
if (async === void 0) { async = false; }
};
Object.defineProperty(CubeTextureWebGL.prototype, "size", {
get: function () {
return this._size;
},
enumerable: false,
configurable: true
});
CubeTextureWebGL.prototype.generateMipmaps = function () {
this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, this._glTexture);
this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP);
//this._gl.bindTexture( this._gl.TEXTURE_CUBE_MAP, null );
};
return CubeTextureWebGL;
}(TextureBaseWebGL));
export { CubeTextureWebGL };