twgl.js icon indicating copy to clipboard operation
twgl.js copied to clipboard

Example with 'OES_texture_float' and 'WEBGL_color_buffer_float' extensions

Open munrocket opened this issue 5 years ago • 5 comments

We need WebGL1 example with float extensions because WebGL2 will never supported by Apple.

munrocket avatar Apr 05 '19 11:04 munrocket

Here working example with 'WEBGL_color_buffer_float' in WebGL1 https://jsfiddle.net/mp6onju8/

munrocket avatar Apr 05 '19 11:04 munrocket

And here 'OES_texture_float' in WebGL1 https://jsfiddle.net/7vqehuds/6/

munrocket avatar Apr 05 '19 15:04 munrocket

It is right and all of them float32? Do we need to use Float32Array type or something else?

munrocket avatar Apr 05 '19 15:04 munrocket

Looks right to me. You can use Float32Array if you want

let texbuffer = new Float32Array(width * height * 4);
let off = 0;
for(let i = 0; i < width; i++) {
  for(let j = 0; j < height; j++) {
    texbuffer[off++] = (Math.cos(3.14*i/width));
    texbuffer[off++] = (Math.sin(3.14*j/width));
    texbuffer[off++] = (Math.cos(3.14*j/width));
    texbuffer[off++] = (1.0);
  }
}
const textures = twgl.createTextures(gl, {
  texture: {
  format:gl.RGBA,
  minMag: gl.NEAREST,
  wrap: gl.CLAMP_TO_EDGE,
  src: texbuffer,
}});

you should probably check for float support and show warning if no support. 1 out 4 devices don't support it.

greggman avatar Apr 06 '19 00:04 greggman

Yep

munrocket avatar Apr 06 '19 00:04 munrocket