Initial work on texture and colour matrix support

This commit is contained in:
UnknownShadow200 2025-02-22 09:33:08 +11:00
parent ebdb454a75
commit e3f61f3c78
3 changed files with 78 additions and 13 deletions

View File

@ -130,8 +130,20 @@ static void UpdateNormalMatrix() {
}
static void OnMatrixChanged() {
if(MATRIX_MODE == GL_MODELVIEW) NORMAL_DIRTY = true;
if(MATRIX_MODE == GL_PROJECTION) PROJECTION_DIRTY = true;
switch (MATRIX_MODE) {
case GL_MODELVIEW:
NORMAL_DIRTY = true;
return;
case GL_PROJECTION:
PROJECTION_DIRTY = true;
return;
case GL_TEXTURE:
_glTnlUpdateTextureMatrix();
return;
case GL_COLOR:
_glTnlUpdateColorMatrix();
return;
}
}

View File

@ -492,6 +492,8 @@ void _glTnlLoadMatrix(void);
void _glTnlApplyEffects(SubmissionTarget* target);
void _glTnlUpdateLighting(void);
void _glTnlUpdateTextureMatrix(void);
void _glTnlUpdateColorMatrix(void);
/* This is from KOS pvr_buffers.c */
#define PVR_MIN_Z 0.0001f

View File

@ -8,10 +8,7 @@
#include "private.h"
#include "platform.h"
#define TNL_FX_LIGHTING 0x01
#define TNL_FX_TEXTURE 0x02
#define TNL_FX_COLOR 0x04
static int TNL_EFFECTS;
static int TNL_EFFECTS, TNL_LIGHTING, TNL_TEXTURE, TNL_COLOR;
#define ITERATE(count) \
GLuint i = count; \
@ -25,13 +22,17 @@ void _glTnlLoadMatrix(void) {
* If we're not doing lighting though we can optimise by taking
* vertices straight to clip-space */
if(TNL_EFFECTS & TNL_FX_LIGHTING) {
if(TNL_LIGHTING) {
_glMatrixLoadModelView();
} else {
_glMatrixLoadModelViewProjection();
}
}
static void updateEffects(void) {
TNL_EFFECTS = TNL_LIGHTING | TNL_TEXTURE | TNL_COLOR;
}
static void transformVertices(SubmissionTarget* target) {
TRACE();
@ -66,20 +67,70 @@ static void lightingEffect(SubmissionTarget* target) {
}
void _glTnlUpdateLighting(void) {
if (_glIsLightingEnabled()) {
TNL_EFFECTS |= TNL_FX_LIGHTING;
} else {
TNL_EFFECTS &= ~TNL_FX_LIGHTING;
TNL_LIGHTING = _glIsLightingEnabled();
updateEffects();
}
static void textureEffect(SubmissionTarget* target) {
Matrix4x4* m = _glGetTextureMatrix();
UploadMatrix4x4(m);
float coords[4];
Vertex* it = _glSubmissionTargetStart(target);
uint32_t count = target->count;
ITERATE(count) {
TransformVertex(it->uv[0], it->uv[1], 0.0f, 1.0f, coords, &coords[3]);
it->uv[0] = coords[0];
it->uv[1] = coords[1];
it++;
}
}
void _glTnlUpdateTextureMatrix(void) {
Matrix4x4* m = _glGetTextureMatrix();
TNL_TEXTURE = _glIsIdentity(m);
updateEffects();
}
static void colorEffect(SubmissionTarget* target) {
Matrix4x4* m = _glGetColorMatrix();
UploadMatrix4x4(m);
float coords[4];
Vertex* it = _glSubmissionTargetStart(target);
uint32_t count = target->count;
ITERATE(count) {
TransformVertex(it->bgra[2], it->bgra[1], it->bgra[0], it->bgra[3], coords, &coords[3]);
it->bgra[2] = clamp(coords[0], 0, 255);
it->bgra[1] = clamp(coords[1], 0, 255);
it->bgra[0] = clamp(coords[2], 0, 255);
it->bgra[3] = clamp(coords[3], 0, 255);
it++;
}
}
void _glTnlUpdateColorMatrix(void) {
Matrix4x4* m = _glGetColorMatrix();
TNL_COLOR = _glIsIdentity(m);
updateEffects();
}
void _glTnlApplyEffects(SubmissionTarget* target) {
if (!TNL_EFFECTS) return;
if (TNL_EFFECTS & TNL_FX_LIGHTING)
if (TNL_LIGHTING)
lightingEffect(target);
if (TNL_TEXTURE)
textureEffect(target);
if (TNL_COLOR)
colorEffect(target);
if (TNL_EFFECTS & TNL_FX_LIGHTING) {
if (TNL_LIGHTING) {
/* OK eye-space work done, now move into clip space */
_glMatrixLoadProjection();
transformVertices(target);