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

fix texture warnings (#319)

- bind real texture to tDepth in renderer
- ensure textures are not empty; init as 1x1(x1)
parent c3203860
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ Note that since we don't clearly distinguish between a public and private interf ...@@ -8,6 +8,7 @@ Note that since we don't clearly distinguish between a public and private interf
- Fix parsing contour-level from emdb v3 header files - Fix parsing contour-level from emdb v3 header files
- Fix invalid CSS (#376) - Fix invalid CSS (#376)
- Fix "texture not renderable" & "texture not bound" warnings (#319)
## [v3.2.0] - 2022-02-17 ## [v3.2.0] - 2022-02-17
......
...@@ -16,7 +16,7 @@ import { GlobalUniformValues } from './renderable/schema'; ...@@ -16,7 +16,7 @@ import { GlobalUniformValues } from './renderable/schema';
import { GraphicsRenderVariant } from './webgl/render-item'; import { GraphicsRenderVariant } from './webgl/render-item';
import { ParamDefinition as PD } from '../mol-util/param-definition'; import { ParamDefinition as PD } from '../mol-util/param-definition';
import { degToRad } from '../mol-math/misc'; import { degToRad } from '../mol-math/misc';
import { createNullTexture, Texture, Textures } from './webgl/texture'; import { Texture, Textures } from './webgl/texture';
import { arrayMapUpsert } from '../mol-util/array'; import { arrayMapUpsert } from '../mol-util/array';
import { clamp } from '../mol-math/interpolate'; import { clamp } from '../mol-math/interpolate';
...@@ -146,9 +146,9 @@ namespace Renderer { ...@@ -146,9 +146,9 @@ namespace Renderer {
let transparentBackground = false; let transparentBackground = false;
const nullDepthTexture = createNullTexture(gl); const emptyDepthTexture = ctx.resources.texture('image-depth', 'depth', 'ushort', 'nearest');
const sharedTexturesList: Textures = [ const sharedTexturesList: Textures = [
['tDepth', nullDepthTexture] ['tDepth', emptyDepthTexture]
]; ];
const view = Mat4(); const view = Mat4();
...@@ -309,7 +309,7 @@ namespace Renderer { ...@@ -309,7 +309,7 @@ namespace Renderer {
}; };
const updateInternal = (group: Scene.Group, camera: ICamera, depthTexture: Texture | null, renderWboit: boolean, markingDepthTest: boolean) => { const updateInternal = (group: Scene.Group, camera: ICamera, depthTexture: Texture | null, renderWboit: boolean, markingDepthTest: boolean) => {
arrayMapUpsert(sharedTexturesList, 'tDepth', depthTexture || nullDepthTexture); arrayMapUpsert(sharedTexturesList, 'tDepth', depthTexture || emptyDepthTexture);
ValueCell.update(globalUniforms.uModel, group.view); ValueCell.update(globalUniforms.uModel, group.view);
ValueCell.update(globalUniforms.uModelView, Mat4.mul(modelView, group.view, camera.view)); ValueCell.update(globalUniforms.uModelView, Mat4.mul(modelView, group.view, camera.view));
......
/** /**
* Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
* *
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
...@@ -176,7 +176,7 @@ function isTexture2d(x: TextureImage<any> | TextureVolume<any>, target: number, ...@@ -176,7 +176,7 @@ function isTexture2d(x: TextureImage<any> | TextureVolume<any>, target: number,
return target === gl.TEXTURE_2D; return target === gl.TEXTURE_2D;
} }
function isTexture3d(x: TextureImage<any> | TextureVolume<any>, target: number, gl: WebGL2RenderingContext): x is TextureImage<any> { function isTexture3d(x: TextureImage<any> | TextureVolume<any>, target: number, gl: WebGL2RenderingContext): x is TextureVolume<any> {
return target === gl.TEXTURE_3D; return target === gl.TEXTURE_3D;
} }
...@@ -260,6 +260,10 @@ export function createTexture(gl: GLRenderingContext, extensions: WebGLExtension ...@@ -260,6 +260,10 @@ export function createTexture(gl: GLRenderingContext, extensions: WebGLExtension
let destroyed = false; let destroyed = false;
function define(_width: number, _height: number, _depth?: number) { function define(_width: number, _height: number, _depth?: number) {
if (_width === 0 || _height === 0 || (isWebGL2(gl) && target === gl.TEXTURE_3D && _depth === 0)) {
throw new Error('empty textures are not allowed');
}
if (width === _width && height === _height && depth === (_depth || 0)) return; if (width === _width && height === _height && depth === (_depth || 0)) return;
width = _width, height = _height, depth = _depth || 0; width = _width, height = _height, depth = _depth || 0;
...@@ -272,14 +276,20 @@ export function createTexture(gl: GLRenderingContext, extensions: WebGLExtension ...@@ -272,14 +276,20 @@ export function createTexture(gl: GLRenderingContext, extensions: WebGLExtension
throw new Error('unknown texture target'); throw new Error('unknown texture target');
} }
} }
define(1, 1, isWebGL2(gl) && target === gl.TEXTURE_3D ? 1 : 0);
function load(data: TextureImage<any> | TextureVolume<any> | HTMLImageElement, sub = false) { function load(data: TextureImage<any> | TextureVolume<any> | HTMLImageElement, sub = false) {
if (data.width === 0 || data.height === 0 || (!isImage(data) && isWebGL2(gl) && isTexture3d(data, target, gl) && data.depth === 0)) {
throw new Error('empty textures are not allowed');
}
gl.bindTexture(target, texture); gl.bindTexture(target, texture);
// unpack alignment of 1 since we use textures only for data // unpack alignment of 1 since we use textures only for data
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1); gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE); gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0); gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
if (isImage(data)) { if (isImage(data)) {
width = data.width, height = data.height;
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
gl.bindTexture(gl.TEXTURE_2D, texture); gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, format, type, data); gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, format, type, data);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment