summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-01-05 23:09:45 +1100
committerquou <quou@disroot.org>2025-01-05 23:11:05 +1100
commit74a91b679e9be1381fe52cad5d7c63b8bc9fc534 (patch)
tree56c24dd7f44ddc9c1207a46a34ca420d86b0cbaf
parentbce070eba418c8a79f6affcd885564babbf8c9d3 (diff)
use rgba instead of rgb for HDR since nvidia gpu doesnt support it
-rw-r--r--convtexture.c29
-rw-r--r--video.cpp4
2 files changed, 17 insertions, 16 deletions
diff --git a/convtexture.c b/convtexture.c
index e5b603b..e5ec996 100644
--- a/convtexture.c
+++ b/convtexture.c
@@ -353,7 +353,7 @@ int proc_bitmap(FILE* infile, FILE* outfile, Texture_Format target) {
}
typedef struct {
- float r, g, b;
+ float r, g, b, a;
} Hdr_Pixel;
Hdr_Pixel hdr_pixel(uint8_t* bytes) {
@@ -362,6 +362,8 @@ Hdr_Pixel hdr_pixel(uint8_t* bytes) {
p.r = ((float)bytes[0] + 0.5f) * f;
p.g = ((float)bytes[1] + 0.5f) * f;
p.b = ((float)bytes[2] + 0.5f) * f;
+ p.a = 1.0f;
+ /* nvidia gpus dont support 3 component sfloat so we can't have nice things :( */
return p;
}
@@ -370,8 +372,7 @@ uint16_t f2h(uint32_t i) {
int s = (i >> 16) & 0x00008000;
int e = ((i >> 23) & 0x000000ff) - (127 - 15);
int m = i & 0x007fffff;
- if (e <= 0)
- {
+ if (e <= 0) {
if (e < -10)
return s;
m = m | 0x00800000;
@@ -381,21 +382,17 @@ uint16_t f2h(uint32_t i) {
m = (m + a + b) >> t;
return s | m;
}
- else if (e == 0xff - (127 - 15))
- {
+ else if (e == 0xff - (127 - 15)) {
if (m == 0)
return s | 0x7c00;
- else
- {
+ else {
m >>= 13;
return s | 0x7c00 | m | (m == 0);
}
}
- else
- {
+ else {
m = m + 0x00000fff + ((m >> 13) & 1);
- if (m & 0x00800000)
- {
+ if (m & 0x00800000) {
m = 0;
e += 1;
}
@@ -522,10 +519,10 @@ int proc_hdr(FILE* infile, FILE* outfile, int half) {
}
}
if (half) {
- write_header(outfile, w, h, texture_format_rgb16f);
- write_halves(outfile, w * h * 3, (float*)pixels);
+ write_header(outfile, w, h, texture_format_rgba16f);
+ write_halves(outfile, w * h * 4, (float*)pixels);
} else {
- write_header(outfile, w, h, texture_format_rgb32f);
+ write_header(outfile, w, h, texture_format_rgba32f);
fwrite(pixels, sizeof *pixels, w * h, outfile);
}
fclose(outfile);
@@ -560,8 +557,8 @@ int main(int argc, const char** argv) {
return proc_bitmap(infile, outfile, target);
}
if (string_equal(magic, "#?RADIANCE")) {
- int half = target == texture_format_rgb16f;
- if (!half && target != texture_format_rgb32f) {
+ int half = target == texture_format_rgba16f;
+ if (!half && target != texture_format_rgba32f) {
print_err("Unsupported target format.\n");
return 40;
}
diff --git a/video.cpp b/video.cpp
index f619643..47b7685 100644
--- a/video.cpp
+++ b/video.cpp
@@ -3696,6 +3696,10 @@ size_t Texture_Loader::calc_size(
return w * h * 6;
case texture_format_rgb32f:
return w * h * 12;
+ case texture_format_rgba16f:
+ return w * h * 8;
+ case texture_format_rgba32f:
+ return w * h * 16;
default:
print_err("Can't load this texture format.\n");
pbreak(45498);