oceanGermanique
oceanGermanique

Reputation: 409

copy a float texture with webgl2

I can no longer find any trace of copyTexImage2D in the specification of webgl2 : https://www.khronos.org/registry/webgl/specs/latest/2.0/

A few months ago I had asked the question of how to make a float-texture copy. With webgl version 1.0 this was not possible with copyTexImage2D (float type is not supported) So I made a texture copy by building a simple shader.

I imagined that the restriction on the float32 type was lifted with webgl2. But I do not find any occurrence of the word "copyTexImage2D" in the specification of webgl 2.

How does it work? The specification of webgl2 gives only the novelties or new polymorphism functions since webgl1 ?

In short, with webgl2, is a more efficient method to copy a texture ?

(In my slow, very slow, understanding of webgl2 I have not yet addressed the interesting novelty of feedback)

Upvotes: 0

Views: 897

Answers (3)

Jeff Gilbert
Jeff Gilbert

Reputation: 396

copyTex[Sub]Image2D works with floats in WebGL2 with the EXT_color_buffer_float extension.

I'll note that this also works in WebGL1 with the extensions:

  • OES_texture_half_float and EXT_color_buffer_half_float[1] for float16s
  • OES_texture_float and WEBGL_color_buffer_float[1] for float32s

Note the sometimes-confusing differences:

  • WEBGL_color_buffer_float is for WebGL1, and enables only RGBA32F (RGBA/FLOAT for textures)
  • EXT_color_buffer_half_float is for WebGL1, and enables only RGBA16F (RGBA/HALF_FLOAT_OES for textures)
  • EXT_color_buffer_float is for WebGL2, and enables R/RG/RGBA 16F and 32F, as well as R11F_G11F_B10F

(see the WebGL Extension Registry for more info on extensions)

blitFramebuffer also does work on WebGL2, though you'll need EXT_color_buffer_float to allow float framebuffers to be complete.

[1]: EXT_color_buffer_half_float and WEBGL_color_buffer_float are not yet offered in Chrome, though enabling OES_texture_[half_]float might be enough. On Chrome, verify on each machine that checkFramebufferStatus returns FRAMEBUFFER_COMPLETE.

Upvotes: 1

user128511
user128511

Reputation:

WebGL2s spec just adds to WebGL1. From the WebGL2 spec right near the beginning

This document should be read as an extension to the WebGL 1.0 specification. It will only describe the differences from 1.0.

Similarly it also says

The remaining sections of this document are intended to be read in conjunction with the OpenGL ES 3.0 specification (3.0.4 at the time of this writing, available from the Khronos OpenGL ES API Registry). Unless otherwise specified, the behavior of each method is defined by the OpenGL ES 3.0 specification.

So, copyTexImage2D is still there.

Your blitFramebuffer solution works though

Upvotes: 2

oceanGermanique
oceanGermanique

Reputation: 409

Ok i find a solution: blitFramebuffer :

let texture1 be the texture which we want to copy in texture2. We have already two framebuffer copieFB and FBorig. copieFB have a color attachment to texture2, FBorig have a color attachment to texture1.

gl.bindFramebuffer ( gl.DRAW_FRAMEBUFFER, copieFB );
gl.bindFramebuffer ( gl.READ_FRAMEBUFFER, FBorig );
gl.readBuffer ( gl.COLOR_ATTACHMENT0 );
gl.blitFramebuffer(0, 0, PVS, PVS,0, 0, PVS, PVS,gl.COLOR_BUFFER_BIT, gl.NEAREST);

old solution :

gl.bindFramebuffer( gl.FRAMEBUFFER , copieFB);
gl.viewport(0, 0, PVS, PVS);
gl.useProgram(copieShader);
gl.uniform1i(copieShader.FBorig,TEXTURE1);
gl.drawArrays(gl.POINTS , 0 , NBRE);

the gain is some FPS.

Upvotes: 1

Related Questions