summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorJoJoX <jonas.lhoste@gmail.com>2023-02-08 20:41:44 +0100
committerJoJoX <jonas.lhoste@gmail.com>2023-02-08 20:41:44 +0100
commita7f3b4459a0a3c5578e0adc1f71cbb9537071008 (patch)
treeedee32f7ccd2ed8b964e862894bc9e6da10bd5ed /drivers
parent8843d9ad347e5c3be5130153aeecdf48e4fe5a14 (diff)
Handle 0 exponent in float/half conversion for OpenGl
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles3/shaders/stdlib_inc.glsl18
1 files changed, 14 insertions, 4 deletions
diff --git a/drivers/gles3/shaders/stdlib_inc.glsl b/drivers/gles3/shaders/stdlib_inc.glsl
index 8d4a24cc1f..0b76c4334a 100644
--- a/drivers/gles3/shaders/stdlib_inc.glsl
+++ b/drivers/gles3/shaders/stdlib_inc.glsl
@@ -2,13 +2,23 @@
#ifdef USE_GLES_OVER_GL
// Floating point pack/unpack functions are part of the GLSL ES 300 specification used by web and mobile.
uint float2half(uint f) {
- return ((f >> uint(16)) & uint(0x8000)) |
- ((((f & uint(0x7f800000)) - uint(0x38000000)) >> uint(13)) & uint(0x7c00)) |
- ((f >> uint(13)) & uint(0x03ff));
+ uint e = f & uint(0x7f800000);
+ if (e <= uint(0x38000000)) {
+ return uint(0);
+ } else {
+ return ((f >> uint(16)) & uint(0x8000)) |
+ (((e - uint(0x38000000)) >> uint(13)) & uint(0x7c00)) |
+ ((f >> uint(13)) & uint(0x03ff));
+ }
}
uint half2float(uint h) {
- return ((h & uint(0x8000)) << uint(16)) | (((h & uint(0x7c00)) + uint(0x1c000)) << uint(13)) | ((h & uint(0x03ff)) << uint(13));
+ uint h_e = h & uint(0x7c00);
+ if (h_e == uint(0x0000)) {
+ return uint(0);
+ } else {
+ return ((h & uint(0x8000)) << uint(16)) | ((h_e + uint(0x1c000)) << uint(13)) | ((h & uint(0x03ff)) << uint(13));
+ }
}
uint packHalf2x16(vec2 v) {