Skip to content

Commit

Permalink
texture fallback if no half_float extension is available
Browse files Browse the repository at this point in the history
  • Loading branch information
pandrr committed May 6, 2024
1 parent 932c11f commit 818c256
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions src/core/cgl/cgl_texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,43 @@ Texture.setUpGlPixelFormat = function (cgl, pixelFormatStr)

o.pixelFormatBase = pixelFormatStr;


o.pixelFormat = pixelFormatStr;
o.glDataType = cgl.gl.UNSIGNED_BYTE;
o.glInternalFormat = cgl.gl.RGBA8;
o.glDataFormat = cgl.gl.RGBA;

let floatDatatype = cgl.gl.FLOAT;

if (cgl.glUseHalfFloatTex)
{
if (pixelFormatStr == Texture.PFORMATSTR_RGBA32F) pixelFormatStr = Texture.PFORMATSTR_RGBA16F;
if (pixelFormatStr == Texture.PFORMATSTR_RG32F) pixelFormatStr = Texture.PFORMATSTR_RG16F;
if (pixelFormatStr == Texture.PFORMATSTR_R32F) pixelFormatStr = Texture.PFORMATSTR_R16F;
}

o.pixelFormat = pixelFormatStr;
o.glDataType = cgl.gl.UNSIGNED_BYTE;
o.glInternalFormat = cgl.gl.RGBA8;
o.glDataFormat = cgl.gl.RGBA;
if (pixelFormatStr.contains("16bit"))
{
if (cgl.glVersion == 2)
{
// cgl.enableExtension("OES_texture_half_float");
const hasExt = cgl.enableExtension("EXT_color_buffer_half_float");

let floatDatatype = cgl.gl.FLOAT;
if (!hasExt)
{
console.warn("no 16bit extension, fallback to 32bit");
// fallback to 32 bit?
if (pixelFormatStr == Texture.PFORMATSTR_RGBA16F) pixelFormatStr = Texture.PFORMATSTR_RGBA32F;
if (pixelFormatStr == Texture.PFORMATSTR_RGB16F) pixelFormatStr = Texture.PFORMATSTR_RGB32F;
if (pixelFormatStr == Texture.PFORMATSTR_RG16F) pixelFormatStr = Texture.PFORMATSTR_RG32F;
if (pixelFormatStr == Texture.PFORMATSTR_R16F) pixelFormatStr = Texture.PFORMATSTR_R32F;
}
else
{
floatDatatype = cgl.gl.HALF_FLOAT;
}
}
}

if (cgl.glVersion == 1)
{
Expand All @@ -222,6 +246,10 @@ Texture.setUpGlPixelFormat = function (cgl, pixelFormatStr)
}
}





if (pixelFormatStr == Texture.PFORMATSTR_RGBA8UB)
{
}
Expand Down Expand Up @@ -316,11 +344,6 @@ Texture.setUpGlPixelFormat = function (cgl, pixelFormatStr)
cgl.enableExtension("OES_texture_float_linear"); // yes, i am sure, this is a webgl 1 and 2 ext
}

if (pixelFormatStr.contains("16bit"))
{
cgl.enableExtension("EXT_color_buffer_half_float");
cgl.enableExtension("OES_texture_float_linear");
}

o.numColorChannels = 1;
if (pixelFormatStr.startsWith("R"))o.numColorChannels = 1;
Expand Down

0 comments on commit 818c256

Please sign in to comment.