gpu.js/test/internal/backend/web-gl/kernel-value/dynamic-memory-optimized-number-texture.js
Robert Plummer ed1cd94448 feat: Added features and fixes for the following issues:
...it kind of snowballed from some needs
Fixes #521 - If `tactic` is not set, check precision allowed from WebGL, and automatically change based off needs, otherwise use value from `tactic`.
Fixes #535 - Internally check if texture from argument is the same as output, if so, clone this texture, and then clean it up after the kernel runs.
Fixes #536 - Normalize all declarations to non-destructured, and then parse
Fixes #537 - Change logic
Fixes #538 - Found the GL script that would work, and reduced the methods to use it
Fixes #539 - Found a better way of testing random, and this gives me an error for 1 in 10 runs, acceptable

Some refactoring for less duplicate code and documentation
2019-11-26 10:55:28 -05:00

91 lines
2.5 KiB
JavaScript

const { assert, skip, test, module: describe, only } = require('qunit');
const { webGLKernelValueMaps } = require('../../../../../src');
describe('internal: WebGLKernelValueDynamicMemoryOptimizedNumberTexture');
test('.updateValue() checks too large height', () => {
const mockKernel = {
constructor: {
features: { maxTextureSize: 1 },
},
validate: true,
};
const v = new webGLKernelValueMaps.unsigned.dynamic.MemoryOptimizedNumberTexture({ size: [1, 1] }, {
kernel: mockKernel,
name: 'test',
type: 'MemoryOptimizedNumberTexture',
origin: 'user',
tactic: 'speed',
onRequestContextHandle: () => 1,
onRequestTexture: () => null,
onRequestIndex: () => 1
});
assert.throws(() => {
v.updateValue({ size: [1, 2] });
}, new Error('Argument height of 2 larger than maximum size of 1 for your GPU'));
});
test('.updateValue() checks too large width', () => {
const mockKernel = {
constructor: {
features: { maxTextureSize: 1 },
},
validate: true,
};
const v = new webGLKernelValueMaps.unsigned.dynamic.MemoryOptimizedNumberTexture({ size: [1, 1] }, {
kernel: mockKernel,
name: 'test',
type: 'MemoryOptimizedNumberTexture',
origin: 'user',
tactic: 'speed',
onRequestContextHandle: () => 1,
onRequestTexture: () => null,
onRequestIndex: () => 1
});
assert.throws(() => {
v.updateValue({
size: [2,1]
})
}, new Error('Argument width of 2 larger than maximum size of 1 for your GPU'));
});
test('.updateValue() checks ok height & width', () => {
const mockKernel = {
constructor: {
features: { maxTextureSize: 2 },
},
validate: true,
setUniform3iv: () => {},
setUniform2iv: () => {},
setUniform1i: () => {},
outputTexture: {}
};
const mockContext = {
activeTexture: () => {},
bindTexture: () => {},
texParameteri: () => {},
pixelStorei: () => {},
texImage2D: () => {},
};
const v = new webGLKernelValueMaps.unsigned.dynamic.MemoryOptimizedNumberTexture({ size: [2,2], context: mockContext }, {
kernel: mockKernel,
name: 'test',
type: 'MemoryOptimizedNumberTexture',
origin: 'user',
tactic: 'speed',
context: mockContext,
onRequestContextHandle: () => 1,
onRequestTexture: () => null,
onRequestIndex: () => 1
});
v.updateValue({
size: [1,1],
context: mockContext,
texture: {}
});
assert.equal(v.constructor.name, 'WebGLKernelValueDynamicMemoryOptimizedNumberTexture');
});