summaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
Diffstat (limited to 'render.c')
-rw-r--r--render.c59
1 files changed, 50 insertions, 9 deletions
diff --git a/render.c b/render.c
index 14aa6a1..233c084 100644
--- a/render.c
+++ b/render.c
@@ -311,16 +311,57 @@ int tri_winding(
(v1[0] - v0[0]) * (v2[1] - v1[1]);
}
+/*Colour sample_tex(
+ const Texture* t,
+ int u,
+ int v
+) {
+ vec3 start, end, col;
+ int i;
+ Colour r = { 0 };
+ const unsigned* data = (const unsigned*)&t[1];
+ int x = ((u * t->w) >> fbits) & (t->w - 1);
+ int y = ((v * t->h) >> fbits) & (t->h - 1);
+ unsigned palette = data[(x / 4 + y / 4 * (t->w / 4)) * 2];
+ unsigned indices = data[(x / 4 + y / 4 * (t->w / 4)) * 2 + 1];
+ start.r = (float)((palette & (31 << 27)) >> 27) / 32.0f;
+ start.g = (float)((palette & (63 << 21)) >> 21) / 64.0f;
+ start.b = (float)((palette & (31 << 16)) >> 16) / 32.0f;
+ end.r = (float)((palette & (31 << 11)) >> 11) / 32.0f;
+ end.g = (float)((palette & (63 << 5)) >> 5) / 64.0f;
+ end.b = (float)((palette & (31 )) ) / 32.0f;
+ i = x % 4 + (y % 4) * 4;
+ i = (indices & (3 << i * 2)) >> i * 2;
+ lerp(&col, &start, &end, (float)i / 3.0f);
+ r.r = (int)(col.r * 255.0f);
+ r.g = (int)(col.g * 255.0f);
+ r.b = (int)(col.b * 255.0f);
+ return r;
+}*/
Colour sample_tex(
- const Bitmap* t,
+ const Texture* t,
int u,
int v
) {
- int x = (u * t->w) >> fbits;
- int y = (v * t->h) >> fbits;
- x &= t->w - 1;
- y &= t->h - 1;
- return t->p[x + y * t->w];
+ int x = ((u * t->w) >> fbits) & (t->w - 1);
+ int y = ((v * t->h) >> fbits) & (t->h - 1);
+ Colour r;
+ int s[3];
+ int i;
+ int coord = ((x >> 2) + (y >> 2) * (t->w >> 2)) << 1;
+ const unsigned* data = (const unsigned*)&t[1];
+ unsigned pal = data[coord];
+ unsigned ind = data[coord + 1];
+ s[0] = (pal & (31 << 27)) >> 24;
+ s[1] = (pal & (63 << 21)) >> 19;
+ s[2] = (pal & (31 << 16)) >> 13;
+ i = ((x & 3) + ((y & 3) << 2)) << 1;
+ i = (ind & (3 << i)) >> i;
+ r.r = s[0] + (i * ((int)((pal & (31 << 11)) >> 8) - s[0]) / 3);
+ r.g = s[1] + (i * ((int)((pal & (63 << 5)) >> 3) - s[1]) / 3);
+ r.b = s[2] + (i * ((int)((pal & (31 )) << 3) - s[2]) / 3);
+ r.a = 0xff;
+ return r;
}
typedef struct {
@@ -380,7 +421,7 @@ void ren_tri(
const int* iv0,
const int* iv1,
const int* iv2,
- const Bitmap* tex
+ const Texture* tex
) {
#define ic 6
#define ec 8
@@ -509,7 +550,7 @@ void ren_tri3(
const int* iv0,
const int* iv1,
const int* iv2,
- const Bitmap* tex
+ const Texture* tex
) {
#define ec 8
#define ec2 (ec)
@@ -573,7 +614,7 @@ int point_os(
void ren_mesh(
Renderer* r,
const Mesh* m,
- const Bitmap* tex
+ const Texture* tex
) {
int vc = m->vc;
int tri[8 * 3];