MCPcopy Create free account
hub / github.com/gpujs/gpu.js / _setupSubOutputTextures

Method _setupSubOutputTextures

src/backend/web-gl2/kernel.js:313–355  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

311 }
312
313 _setupSubOutputTextures() {
314 const gl = this.context;
315 if (this.mappedTextures) {
316 // here we inherit from an already existing kernel, so go ahead and just bind textures to the framebuffer
317 for (let i = 0; i < this.subKernels.length; i++) {
318 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i + 1, gl.TEXTURE_2D, this.mappedTextures[i].texture, 0);
319 }
320 return;
321 }
322 const texSize = this.texSize;
323 this.drawBuffersMap = [gl.COLOR_ATTACHMENT0];
324 this.mappedTextures = [];
325 for (let i = 0; i < this.subKernels.length; i++) {
326 const texture = this.createTexture();
327 this.drawBuffersMap.push(gl.COLOR_ATTACHMENT0 + i + 1);
328 gl.activeTexture(gl.TEXTURE0 + this.constantTextureCount + this.argumentTextureCount + i);
329 gl.bindTexture(gl.TEXTURE_2D, texture);
330 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
331 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
332 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
333 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
334 // TODO: upgrade this
335 const format = this.getInternalFormat();
336 if (this.precision === 'single') {
337 gl.texStorage2D(gl.TEXTURE_2D, 1, format, texSize[0], texSize[1]);
338 // gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, texSize[0], texSize[1], 0, gl.RGBA, gl.FLOAT, null);
339 } else {
340 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, texSize[0], texSize[1], 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
341 }
342 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i + 1, gl.TEXTURE_2D, texture, 0);
343
344 this.mappedTextures.push(new this.TextureConstructor({
345 texture,
346 size: texSize,
347 dimensions: this.threadDim,
348 output: this.output,
349 context: this.context,
350 internalFormat: this.getInternalFormat(),
351 textureFormat: this.getTextureFormat(),
352 kernel: this,
353 }));
354 }
355 }
356
357 /**
358 *

Callers

nothing calls this directly

Calls 3

getInternalFormatMethod · 0.95
getTextureFormatMethod · 0.95
createTextureMethod · 0.80

Tested by

no test coverage detected