From 07284e7e3df7adf99e079337adf65a44e159e5e9 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sat, 4 Feb 2023 13:58:02 -0800 Subject: [PATCH] handle null-texture in calcTextureMeshColorSmoothing --- CHANGELOG.md | 1 + .../geometry/texture-mesh/color-smoothing.ts | 10 ++++++---- src/mol-gl/webgl/texture.ts | 18 ++++++++++++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e58412c88..5792f31a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Note that since we don't clearly distinguish between a public and private interf - Fix wrong offset when rendering text with orthographic projection - Update camera/handle helper when `devicePixelRatio` changes - Add various options to customize the axes camera-helper +- Fix issue with texture-mesh color smoothing when changing themes ## [v3.30.0] - 2023-01-29 diff --git a/src/mol-geo/geometry/texture-mesh/color-smoothing.ts b/src/mol-geo/geometry/texture-mesh/color-smoothing.ts index 8633a1a05..7cfc6b4e7 100644 --- a/src/mol-geo/geometry/texture-mesh/color-smoothing.ts +++ b/src/mol-geo/geometry/texture-mesh/color-smoothing.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2021-2023 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ @@ -7,7 +7,7 @@ import { ValueCell } from '../../../mol-util'; import { createComputeRenderable, ComputeRenderable } from '../../../mol-gl/renderable'; import { WebGLContext } from '../../../mol-gl/webgl/context'; -import { Texture } from '../../../mol-gl/webgl/texture'; +import { isNullTexture, Texture } from '../../../mol-gl/webgl/texture'; import { ShaderCode } from '../../../mol-gl/shader-code'; import { createComputeRenderItem } from '../../../mol-gl/webgl/render-item'; import { ValueSpec, AttributeSpec, UniformSpec, TextureSpec, Values, DefineSpec } from '../../../mol-gl/renderable/schema'; @@ -267,7 +267,7 @@ export function calcTextureMeshColorSmoothing(input: ColorSmoothingInput, resolu const [dx, dy, dz] = gridDim; const { texDimX: width, texDimY: height, texCols } = getTexture2dSize(gridDim); - // console.log({ width, height, texCols, dim, resolution }); + // console.log({ width, height, texCols, gridDim, resolution }); if (!webgl.namedFramebuffers[ColorAccumulateName]) { webgl.namedFramebuffers[ColorAccumulateName] = webgl.resources.framebuffer(); @@ -363,7 +363,9 @@ export function calcTextureMeshColorSmoothing(input: ColorSmoothingInput, resolu // normalize if (isTimingMode) webgl.timer.mark('ColorNormalize.render'); - if (!texture) texture = resources.texture('image-uint8', 'rgba', 'ubyte', 'linear'); + if (!texture || isNullTexture(texture)) { + texture = resources.texture('image-uint8', 'rgba', 'ubyte', 'linear'); + } texture.define(width, height); const normalizeRenderable = getNormalizeRenderable(webgl, accumulateTexture, countTexture); diff --git a/src/mol-gl/webgl/texture.ts b/src/mol-gl/webgl/texture.ts index d12c95d1c..c0f6298e2 100644 --- a/src/mol-gl/webgl/texture.ts +++ b/src/mol-gl/webgl/texture.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Gianluca Tomasello <giagitom@gmail.com> @@ -554,12 +554,18 @@ export function createCubeTexture(gl: GLRenderingContext, faces: CubeFaces, mipm // +const NullTextureFormat = -1; + +export function isNullTexture(texture: Texture) { + return texture.format === NullTextureFormat; +} + export function createNullTexture(gl?: GLRenderingContext): Texture { const target = gl?.TEXTURE_2D ?? 3553; return { id: getNextTextureId(), target, - format: 0, + format: NullTextureFormat, internalFormat: 0, type: 0, filter: 0, @@ -583,8 +589,12 @@ export function createNullTexture(gl?: GLRenderingContext): Texture { gl.bindTexture(target, null); } }, - attachFramebuffer: () => {}, - detachFramebuffer: () => {}, + attachFramebuffer: () => { + throw new Error('cannot attach null-texture to a framebuffer'); + }, + detachFramebuffer: () => { + throw new Error('cannot detach null-texture from a framebuffer'); + }, reset: () => {}, destroy: () => {}, -- GitLab