some im2d

This commit is contained in:
aap 2020-07-28 15:19:15 +02:00
parent b63c3ea3b4
commit aa627a8f2c
4 changed files with 38 additions and 9 deletions

View File

@ -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; }

View File

@ -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; }

View File

@ -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;

View File

@ -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]);