ソースを参照

handle null-texture in calcTextureMeshColorSmoothing

Alexander Rose 2 年 前
コミット
07284e7e3d

+ 1 - 0
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
 

+ 6 - 4
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);

+ 14 - 4
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: () => {},