Skip to content

Commit 425554e

Browse files
committed
renderer: rewrite unpackUnorm4x8 with explicit uint casting
1 parent 86ff74d commit 425554e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,19 @@ static std::string GenCompatHeader() {
529529
str += "float smoothstep(float edge0, float edge1, float x) { float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); return t * t * (3.0 - 2.0 * t); }\n";
530530
}
531531

532-
if ( !glConfig2.gpuShader5Available ) {
533-
str += "#define unpackUnorm4x8( value ) ( ( vec4( value, value >> 8, value >> 16, value >> 24 ) & 0xFF ) / 255.0f )\n";
532+
if ( !glConfig2.gpuShader5Available && glConfig2.gpuShader4Available )
533+
{
534+
str +=
535+
R"(vec4 unpackUnorm4x8( uint value )
536+
{
537+
uint x = value & 0xFFu;
538+
uint y = ( value >> 8u ) & 0xFFu;
539+
uint z = ( value >> 16u ) & 0xFFu;
540+
uint w = ( value >> 24u ) & 0xFFu;
541+
542+
return vec4( x, y, z, w ) / 255.0f;
543+
}
544+
)";
534545
}
535546

536547
/* Driver bug: Adrenaline/OGLP drivers fail to recognise the ARB function versions when they return a 4.6 context

0 commit comments

Comments
 (0)