* Creates an instance of GPU. * @param {IGPUSettings} [settings] - Settings to set mode, and other properties * @constructor
(settings)
| 111 | * @constructor |
| 112 | */ |
| 113 | constructor(settings) { |
| 114 | settings = settings || {}; |
| 115 | this.canvas = settings.canvas || null; |
| 116 | this.context = settings.context || null; |
| 117 | this.mode = settings.mode; |
| 118 | this.Kernel = null; |
| 119 | this.kernels = []; |
| 120 | this.functions = []; |
| 121 | this.nativeFunctions = []; |
| 122 | this.injectedNative = null; |
| 123 | if (this.mode === 'dev') return; |
| 124 | this.chooseKernel(); |
| 125 | // add functions from settings |
| 126 | if (settings.functions) { |
| 127 | for (let i = 0; i < settings.functions.length; i++) { |
| 128 | this.addFunction(settings.functions[i]); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // add native functions from settings |
| 133 | if (settings.nativeFunctions) { |
| 134 | for (const p in settings.nativeFunctions) { |
| 135 | if (!settings.nativeFunctions.hasOwnProperty(p)) continue; |
| 136 | const s = settings.nativeFunctions[p]; |
| 137 | const { name, source } = s; |
| 138 | this.addNativeFunction(name, source, s); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Choose kernel type and save on .Kernel property of GPU |
no test coverage detected