Skip to content
Snippets Groups Projects
Commit 7cba9cda authored by Alexander Rose's avatar Alexander Rose
Browse files

support flipY for textures

parent 04c690e8
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ export interface TextureImage<T extends Uint8Array | Float32Array> {
readonly array: T
readonly width: number
readonly height: number
readonly flipY?: boolean
}
export interface TextureVolume<T extends Uint8Array | Float32Array> {
......
......@@ -118,6 +118,14 @@ export function getAttachment(gl: GLRenderingContext, extensions: WebGLExtension
throw new Error('unknown texture attachment');
}
function isTexture2d(x: TextureImage<any> | TextureVolume<any>, target: number, gl: GLRenderingContext): x is TextureImage<any> {
return target === gl.TEXTURE_2D;
}
function isTexture3d(x: TextureImage<any> | TextureVolume<any>, target: number, gl: WebGL2RenderingContext): x is TextureImage<any> {
return target === gl.TEXTURE_3D;
}
export interface Texture {
readonly id: number
readonly target: number
......@@ -214,14 +222,13 @@ export function createTexture(gl: GLRenderingContext, extensions: WebGLExtension
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
if (target === gl.TEXTURE_2D) {
const { array, width: _width, height: _height } = data as TextureImage<any>;
width = _width, height = _height;
gl.texImage2D(target, 0, internalFormat, width, height, 0, format, type, array);
} else if (isWebGL2(gl) && target === gl.TEXTURE_3D) {
const { array, width: _width, height: _height, depth: _depth } = data as TextureVolume<any>;
width = _width, height = _height, depth = _depth;
gl.texImage3D(target, 0, internalFormat, width, height, depth, 0, format, type, array);
if (isTexture2d(data, target, gl)) {
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, !!data.flipY);
width = data.width, height = data.height;
gl.texImage2D(target, 0, internalFormat, width, height, 0, format, type, data.array);
} else if (isWebGL2(gl) && isTexture3d(data, target, gl)) {
width = data.width, height = data.height, depth = data.depth;
gl.texImage3D(target, 0, internalFormat, width, height, depth, 0, format, type, data.array);
} else {
throw new Error('unknown texture target');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment