Skip to content

Instantly share code, notes, and snippets.

@nkreeger
Created January 31, 2019 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkreeger/ca10dc4dcfe69ca3c9bfe6117d584002 to your computer and use it in GitHub Desktop.
Save nkreeger/ca10dc4dcfe69ca3c9bfe6117d584002 to your computer and use it in GitHub Desktop.
const gles = require('node-gles');
const gl = gles.binding.createWebGLRenderingContext();
const ext = gl.getExtension('OES_texture_half_float');
gl.getExtension('EXT_color_buffer_half_float');
console.log('VERSION: ' + gl.getParameter(gl.VERSION));
gl.disable(gl.DEPTH_TEST);
gl.disable(gl.STENCIL_TEST);
gl.disable(gl.BLEND);
gl.disable(gl.DITHER);
gl.disable(gl.POLYGON_OFFSET_FILL);
gl.disable(gl.SAMPLE_COVERAGE);
gl.enable(gl.SCISSOR_TEST);
gl.enable(gl.CULL_FACE);
gl.cullFace(gl.BACK);
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, ext.HALF_FLOAT_OES, null);
gl.bindTexture(gl.TEXTURE_2D, 0);
gl.bindTexture(gl.TEXTURE_2D, texture);
const values = new Float32Array([0.5, 1.25, 4.5, 3.15]);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, gl.RGBA, gl.FLOAT, values);
const framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.framebufferTexture2D(
gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
const buffer = new Float32Array(4);
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.FLOAT, buffer);
console.log('buffer: ', buffer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment