From aa627a8f2cf5970e5c5cf35dee6a0e0833a42b86 Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 28 Jul 2020 15:19:15 +0200 Subject: [PATCH] some im2d --- src/d3d/rwd3d.h | 7 ++++--- src/gl/rwgl3.h | 1 + src/ps2/rwps2.h | 27 +++++++++++++++++++++++++++ tools/playground/ras_test.cpp | 12 ++++++------ 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/d3d/rwd3d.h b/src/d3d/rwd3d.h index 9ee270d..178a644 100644 --- a/src/d3d/rwd3d.h +++ b/src/d3d/rwd3d.h @@ -64,7 +64,7 @@ struct Im3DVertex struct Im2DVertex { float32 x, y, z; - float32 w; + float32 q; uint32 color; float32 u, v; @@ -72,7 +72,7 @@ struct Im2DVertex void setScreenY(float32 y) { this->y = y; } void setScreenZ(float32 z) { this->z = z; } void setCameraZ(float32 z) { } - void setRecipCameraZ(float32 recipz) { this->w = recipz; } + void setRecipCameraZ(float32 recipz) { this->q = recipz; } void setColor(uint8 r, uint8 g, uint8 b, uint8 a) { this->color = COLOR_ARGB(a, r, g, b); } void setU(float32 u, float recipZ) { this->u = u; } void setV(float32 v, float recipZ) { this->v = v; } @@ -80,7 +80,8 @@ struct Im2DVertex float getScreenX(void) { return this->x; } float getScreenY(void) { return this->y; } float getScreenZ(void) { return this->z; } - float getCameraZ(void) { return this->w; } + float getCameraZ(void) { return 1.0f/this->q; } + float getRecipCameraZ(void) { return this->q; } RGBA getColor(void) { return makeRGBA(this->color>>16 & 0xFF, this->color>>8 & 0xFF, this->color & 0xFF, this->color>>24 & 0xFF); } float getU(void) { return this->u; } diff --git a/src/gl/rwgl3.h b/src/gl/rwgl3.h index 863da2e..53fd763 100644 --- a/src/gl/rwgl3.h +++ b/src/gl/rwgl3.h @@ -143,6 +143,7 @@ struct Im2DVertex float getScreenY(void) { return this->y; } float getScreenZ(void) { return this->z; } float getCameraZ(void) { return this->w; } + float getRecipCameraZ(void) { return 1.0f/this->w; } RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); } float getU(void) { return this->u; } float getV(void) { return this->v; } diff --git a/src/ps2/rwps2.h b/src/ps2/rwps2.h index 6376c5e..01a60b7 100644 --- a/src/ps2/rwps2.h +++ b/src/ps2/rwps2.h @@ -12,6 +12,33 @@ void registerPlatformPlugins(void); extern Device renderdevice; +struct Im2DVertex +{ + float32 x, y, z, w; + uint32 r, g, b, a; + float32 u, v, q, PAD; + + void setScreenX(float32 x) { this->x = x; } + void setScreenY(float32 y) { this->y = y; } + void setScreenZ(float32 z) { this->z = z; } + void setCameraZ(float32 z) { this->w = z; } + void setRecipCameraZ(float32 recipz) { this->q = recipz; } + void setColor(uint8 r, uint8 g, uint8 b, uint8 a) { + this->r = r; this->g = g; this->b = b; this->a = a; } + void setU(float32 u, float recipz) { this->u = u; } + void setV(float32 v, float recipz) { this->v = v; } + + float getScreenX(void) { return this->x; } + float getScreenY(void) { return this->y; } + float getScreenZ(void) { return this->z; } + float getCameraZ(void) { return this->w; } + float getRecipCameraZ(void) { return this->q; } + RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); } + float getU(void) { return this->u; } + float getV(void) { return this->v; } +}; + + struct InstanceData { uint32 dataSize; diff --git a/tools/playground/ras_test.cpp b/tools/playground/ras_test.cpp index 1544c1c..185fdec 100644 --- a/tools/playground/ras_test.cpp +++ b/tools/playground/ras_test.cpp @@ -798,18 +798,18 @@ rastest_renderTriangles(RWDEVICE::Im2DVertex *scrverts, int32 numVerts, uint16 * while(numTris--){ for(i = 0; i < 3; i++){ iv = &scrverts[indices[i]]; - v[i].x = iv->x * 16.0f; - v[i].y = iv->y * 16.0f; - v[i].z = 16777216*(1.0f-iv->z); - v[i].q = iv->w; + v[i].x = iv->getScreenX() * 16.0f; + v[i].y = iv->getScreenY() * 16.0f; + v[i].z = 16777216*(1.0f-iv->getScreenZ()); + v[i].q = iv->getRecipCameraZ(); col = iv->getColor(); v[i].r = col.red; v[i].g = col.green; v[i].b = col.blue; v[i].a = col.alpha; v[i].f = 0; - v[i].s = iv->u*iv->w; - v[i].t = iv->v*iv->w; + v[i].s = iv->u*iv->getRecipCameraZ(); + v[i].t = iv->v*iv->getRecipCameraZ(); } drawTriangle(rs::canvas, v[0], v[1], v[2]);