* @desc Builds the Kernel, by generating the kernel * string using thread dimensions, and arguments * supplied to the kernel. * * If the graphical flag is enabled, canvas is used.
()
| 136 | * <p>If the graphical flag is enabled, canvas is used.</p> |
| 137 | */ |
| 138 | build() { |
| 139 | if (this.built) return; |
| 140 | this.setupConstants(); |
| 141 | this.setupArguments(arguments); |
| 142 | this.validateSettings(arguments); |
| 143 | this.translateSource(); |
| 144 | |
| 145 | if (this.graphical) { |
| 146 | const { |
| 147 | canvas, |
| 148 | output |
| 149 | } = this; |
| 150 | if (!canvas) { |
| 151 | throw new Error('no canvas available for using graphical output'); |
| 152 | } |
| 153 | const width = output[0]; |
| 154 | const height = output[1] || 1; |
| 155 | canvas.width = width; |
| 156 | canvas.height = height; |
| 157 | this._imageData = this.context.createImageData(width, height); |
| 158 | this._colorData = new Uint8ClampedArray(width * height * 4); |
| 159 | } |
| 160 | |
| 161 | const kernelString = this.getKernelString(); |
| 162 | this.kernelString = kernelString; |
| 163 | |
| 164 | if (this.debug) { |
| 165 | console.log('Function output:'); |
| 166 | console.log(kernelString); |
| 167 | } |
| 168 | |
| 169 | try { |
| 170 | this.run = new Function([], kernelString).bind(this)(); |
| 171 | } catch (e) { |
| 172 | console.error('An error occurred compiling the javascript: ', e); |
| 173 | } |
| 174 | this.buildSignature(arguments); |
| 175 | this.built = true; |
| 176 | } |
| 177 | |
| 178 | color(r, g, b, a) { |
| 179 | if (typeof a === 'undefined') { |
no test coverage detected