From fc1239892f3781eacb730bdfb8c5627a4896bcc2 Mon Sep 17 00:00:00 2001 From: Christopher Cameron Date: Thu, 3 Oct 2019 23:40:22 -0400 Subject: [PATCH] Show floating-point texture upload --- webgl-hdr.html | 57 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/webgl-hdr.html b/webgl-hdr.html index 3382046..4d9778c 100644 --- a/webgl-hdr.html +++ b/webgl-hdr.html @@ -4,31 +4,27 @@ WebGL HDR/WCG Test @@ -70,6 +66,37 @@ gl.vertexAttribPointer(shaderProgram.a_position, 2, gl.FLOAT, false, 0, 0); } + // Upload a floating-point texture. + var texture = gl.createTexture(); + { + const data = new Float32Array([ + // The left side is P3(1,0,0) + 1.093034, -0.226670, -0.150102, 1.0, + // Then sRGB(1,0,0) + 1.0, 0.0, 0.0, 1.0, + // Then sRGB(1,1,1) + 1.0, 1.0, 1.0, 1.0, + // Then twice the physical luminance of sRGB(1,1,1). + 1.353256, 1.353256, 1.353256, 1.0, + ]); + gl.bindTexture(gl.TEXTURE_2D, texture); + const alignment = 1; + gl.pixelStorei(gl.UNPACK_ALIGNMENT, alignment); + gl.texImage2D(gl.TEXTURE_2D, + 0 /*level */, + gl.RGBA16F /* internalFormat */, + 4 /* width */, + 1 /* height */, + 0 /* border */, + gl.RGBA /* format */, + gl.FLOAT /* type */, data); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + 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.uniform1i(gl.getUniformLocation(shaderProgram, 'u_sampler'), 0); + } + // Draw the quad to the screen. gl.bindFramebuffer(gl.FRAMEBUFFER, null); gl.viewport(0, 0, 256, 32);