gpu.js/test/test-utils.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

46 lines
1.5 KiB
JavaScript

const testUtils = {
/**
* A visual debug utility
* @param {GPU} gpu
* @param rgba
* @param width
* @param height
* @return {Object[]}
*/
splitRGBAToCanvases: (gpu, rgba, width, height) => {
const visualKernelR = gpu.createKernel(function(v) {
const pixel = v[this.thread.y][this.thread.x];
this.color(pixel.r / 255, 0, 0, 255);
}, { output: [width, height], graphical: true, argumentTypes: { v: 'Array2D(4)' } });
visualKernelR(rgba);
const visualKernelG = gpu.createKernel(function(v) {
const pixel = v[this.thread.y][this.thread.x];
this.color(0, pixel.g / 255, 0, 255);
}, { output: [width, height], graphical: true, argumentTypes: { v: 'Array2D(4)' } });
visualKernelG(rgba);
const visualKernelB = gpu.createKernel(function(v) {
const pixel = v[this.thread.y][this.thread.x];
this.color(0, 0, pixel.b / 255, 255);
}, { output: [width, height], graphical: true, argumentTypes: { v: 'Array2D(4)' } });
visualKernelB(rgba);
const visualKernelA = gpu.createKernel(function(v) {
const pixel = v[this.thread.y][this.thread.x];
this.color(255, 255, 255, pixel.a / 255);
}, { output: [width, height], graphical: true, argumentTypes: { v: 'Array2D(4)' } });
visualKernelA(rgba);
return [
visualKernelR.getPixels(),
visualKernelG.getPixels(),
visualKernelB.getPixels(),
visualKernelA.getPixels(),
];
}
};
module.exports = testUtils;