diff --git a/src/backend/web-gl/kernel-value/memory-optimized-number-texture.js b/src/backend/web-gl/kernel-value/memory-optimized-number-texture.js index d4963de1..3366bac0 100644 --- a/src/backend/web-gl/kernel-value/memory-optimized-number-texture.js +++ b/src/backend/web-gl/kernel-value/memory-optimized-number-texture.js @@ -47,7 +47,7 @@ class WebGLKernelValueMemoryOptimizedNumberTexture extends WebGLKernelArray { if (kernel.immutable) { kernel.updateTextureArgumentRefs(this, inputTexture); } else { - if (kernel.texture.texture === inputTexture.texture) { + if (kernel.texture && kernel.texture.texture === inputTexture.texture) { throw new Error(sameError); } else if (kernel.mappedTextures) { const { mappedTextures } = kernel; @@ -69,4 +69,4 @@ class WebGLKernelValueMemoryOptimizedNumberTexture extends WebGLKernelArray { module.exports = { WebGLKernelValueMemoryOptimizedNumberTexture, sameError -}; \ No newline at end of file +}; diff --git a/src/backend/web-gl/kernel-value/number-texture.js b/src/backend/web-gl/kernel-value/number-texture.js index 9a98e73c..1dad54a5 100644 --- a/src/backend/web-gl/kernel-value/number-texture.js +++ b/src/backend/web-gl/kernel-value/number-texture.js @@ -49,7 +49,7 @@ class WebGLKernelValueNumberTexture extends WebGLKernelArray { if (kernel.immutable) { kernel.updateTextureArgumentRefs(this, inputTexture); } else { - if (kernel.texture.texture === inputTexture.texture) { + if (kernel.texture && kernel.texture.texture === inputTexture.texture) { throw new Error(sameError); } else if (kernel.mappedTextures) { const { mappedTextures } = kernel; @@ -70,4 +70,4 @@ class WebGLKernelValueNumberTexture extends WebGLKernelArray { module.exports = { WebGLKernelValueNumberTexture -}; \ No newline at end of file +}; diff --git a/test/internal/backend/web-gl/kernel-value/memory-optimized-number-texture.js b/test/internal/backend/web-gl/kernel-value/memory-optimized-number-texture.js index cd53b2d3..f399dce3 100644 --- a/test/internal/backend/web-gl/kernel-value/memory-optimized-number-texture.js +++ b/test/internal/backend/web-gl/kernel-value/memory-optimized-number-texture.js @@ -76,3 +76,38 @@ test('.constructor() checks ok height & width', () => { }); assert.equal(v.constructor.name, 'WebGLKernelValueMemoryOptimizedNumberTexture'); }); + +test('.updateValue() should set uploadValue when a pipeline kernel has no texture', () => { + const mockKernel = { + constructor: { + features: { maxTextureSize: 2 }, + }, + validate: true, + pipeline: true, + setUniform3iv: () => {}, + setUniform2iv: () => {}, + setUniform1i: () => {}, + }; + const mockContext = { + activeTexture: () => {}, + bindTexture: () => {}, + texParameteri: () => {}, + pixelStorei: () => {}, + texImage2D: () => {}, + }; + const v = new webGLKernelValueMaps.unsigned.static.MemoryOptimizedNumberTexture({ size: [2,2], context: mockContext }, { + kernel: mockKernel, + name: 'test', + type: 'MemoryOptimizedNumberTexture', + origin: 'user', + tactic: 'speed', + context: mockContext, + onRequestContextHandle: () => 1, + onRequestTexture: () => null, + onRequestIndex: () => 1 + }); + + const newMockTexture = {} + v.updateValue({ size: [2,2], context: mockContext, texture: newMockTexture }) + assert.equal(v.uploadValue, newMockTexture) +}); diff --git a/test/internal/backend/web-gl/kernel-value/number-texture.js b/test/internal/backend/web-gl/kernel-value/number-texture.js index 3f2b416c..86902f06 100644 --- a/test/internal/backend/web-gl/kernel-value/number-texture.js +++ b/test/internal/backend/web-gl/kernel-value/number-texture.js @@ -76,3 +76,38 @@ test('.constructor() checks ok height & width', () => { }); assert.equal(v.constructor.name, 'WebGLKernelValueNumberTexture'); }); + +test('.updateValue() should set uploadValue when a pipeline kernel has no texture', () => { + const mockKernel = { + constructor: { + features: { maxTextureSize: 2 }, + }, + pipeline: true, + validate: true, + setUniform3iv: () => {}, + setUniform2iv: () => {}, + setUniform1i: () => {}, + }; + const mockContext = { + activeTexture: () => {}, + bindTexture: () => {}, + texParameteri: () => {}, + pixelStorei: () => {}, + texImage2D: () => {}, + }; + const v = new webGLKernelValueMaps.unsigned.static.NumberTexture({ size: [2,2], context: mockContext }, { + kernel: mockKernel, + name: 'test', + type: 'NumberTexture', + origin: 'user', + tactic: 'speed', + context: mockContext, + onRequestContextHandle: () => 1, + onRequestTexture: () => null, + onRequestIndex: () => 1 + }); + + const newMockTexture = {} + v.updateValue({ size: [2,2], context: mockContext, texture: newMockTexture }) + assert.equal(v.uploadValue, newMockTexture) +});