diff --git a/src/mol-gl/renderable/util.ts b/src/mol-gl/renderable/util.ts index 8a4781c01ad3ba248b5ee5cbc8eaaab0f134b02c..4431e6f6913554c4729b7ac3d3846c0a7f0bacac 100644 --- a/src/mol-gl/renderable/util.ts +++ b/src/mol-gl/renderable/util.ts @@ -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> { diff --git a/src/mol-gl/webgl/texture.ts b/src/mol-gl/webgl/texture.ts index 4702362ed02e5a0b0a3a17c7727ca9962212512a..3552738dd0278ea54f9550d53954a6b9d4937f78 100644 --- a/src/mol-gl/webgl/texture.ts +++ b/src/mol-gl/webgl/texture.ts @@ -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'); }