Fixed 8-bit texture decoding in legacy 3D engine. Contour mode/alpha still needs to be made consistent (as much as possible) with new engine.

This commit is contained in:
Bart Trzynadlowski 2016-04-15 04:26:42 +00:00
parent d6ce41f971
commit 34d4d8981d

View file

@ -276,33 +276,23 @@ void CLegacy3D::DecodeTexture(int format, int x, int y, int width, int height)
{
for (int xi = x; xi < (x+width); xi++)
{
/*
UINT16 texel = textureRAM[yi*2048+xi];
c = (GLfloat) (texel&0xFF) * (1.0f/255.0f);
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = 1.0;
*/
// Interpret as 8-bit grayscale
UINT16 texel = textureRAM[yi*2048+xi];
uint16_t texel = textureRAM[yi*2048+xi] & 0xFF;
GLfloat c = texel * (1.0f/255.0f);
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = 1.0f;
textureBuffer[i++] = (texel == 0xFF) ? 0. : 1.;
}
}
break;
case 4: // 8-bit, L4A4
case 4: // 8-bit L4A4 (high byte)
for (int yi = y; yi < (y+height); yi++)
{
for (int xi = x; xi < (x+width); xi++)
{
UINT16 texel = textureRAM[yi*2048+xi];
//GLfloat c = (~texel&0x0F) * (1.0f/15.0f);
//GLfloat a = ((texel>>4)&0xF) * (1.0f/15.0f);
GLfloat c = ((texel>>4)&0xF) * (1.0f/15.0f); // seems to work better in Lost World (raptor shadows)
uint16_t texel = textureRAM[yi*2048+xi] >> 8;
GLfloat c = (texel >> 4) * (1.0f/15.0f);
GLfloat a = (texel & 0xF) * (1.0f/15.0f);
textureBuffer[i++] = c;
textureBuffer[i++] = c;
@ -311,59 +301,41 @@ void CLegacy3D::DecodeTexture(int format, int x, int y, int width, int height)
}
}
break;
case 6: // 8-bit grayscale? (How does this differ from format 5? Alpha values?)
case 6: // 8-bit grayscale
for (int yi = y; yi < (y+height); yi++)
{
for (int xi = x; xi < (x+width); xi++)
{
/*
UINT16 texel = textureRAM[yi*2048+xi];
GLfloat c = ((texel>>4)&0xF) * (1.0f/15.0f);
uint16_t texel = textureRAM[yi*2048+xi] >> 8;
GLfloat c = texel * (1.0f/255.0f);
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = (texel == 0xFF) ? 0. : 1.;
}
}
break;
case 2: // 8-bit L4A4 (low byte)
for (int yi = y; yi < (y+height); yi++)
{
for (int xi = x; xi < (x+width); xi++)
{
uint16_t texel = textureRAM[yi*2048+xi] & 0xFF;
GLfloat c = (texel >> 4) * (1.0f/15.0f);
GLfloat a = (texel & 0xF) * (1.0f/15.0f);
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = a;
*/
UINT16 texel = textureRAM[yi*2048+xi]&0xFF;
GLfloat c = texel * (1.0f/255.0f);
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = 1.0f;
}
}
break;
case 2: // Unknown (all 16 bits appear present in Daytona 2, but only lower 8 bits in Le Mans 24)
case 3: // 8-bit A4L4 (high byte)
for (int yi = y; yi < (y+height); yi++)
{
for (int xi = x; xi < (x+width); xi++)
{
UINT16 texel = textureRAM[yi*2048+xi];
GLfloat a = ((texel>>4)&0xF) * (1.0f/15.0f);
GLfloat c = (texel&0xF) * (1.0f/15.0f);
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = a;
//printf("%04X\n", textureRAM[yi*2048+xi]);
/*
UINT16 texel = textureRAM[yi*2048+xi]&0xFF;
GLfloat c = texel * (1.0f/255.0f);
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = c;
textureBuffer[i++] = 1.0f;
*/
}
}
break;
case 3: // Interleaved A4L4 (high byte)
for (int yi = y; yi < (y+height); yi++)
{
for (int xi = x; xi < (x+width); xi++)
{
UINT16 texel = textureRAM[yi*2048+xi]>>8;
uint16_t texel = textureRAM[yi*2048+xi] >> 8;
GLfloat c = (texel & 0xF) * (1.0f/15.0f);
GLfloat a = (texel >> 4) * (1.0f/15.0f);
textureBuffer[i++] = c;
@ -373,13 +345,12 @@ void CLegacy3D::DecodeTexture(int format, int x, int y, int width, int height)
}
}
break;
case 1: // Interleaved A4L4 (low byte)
case 1: // 8-bit A4L4 (low byte)
for (int yi = y; yi < (y+height); yi++)
{
for (int xi = x; xi < (x+width); xi++)
{
// Interpret as A4L4
UINT16 texel = textureRAM[yi*2048+xi]&0xFF;
uint16_t texel = textureRAM[yi*2048+xi] & 0xFF;
GLfloat c = (texel & 0xF) * (1.0f/15.0f);
GLfloat a = (texel >> 4) * (1.0f/15.0f);
textureBuffer[i++] = c;
@ -685,6 +656,7 @@ void CLegacy3D::DescendCullingNode(UINT32 addr)
--stackDepth;
return;
}
//printf("%08x NODE %d\n", addr, stackDepth);
//for (int i = 0; i < 8; i++)
// printf(" %08x\n", node[i]);
@ -986,7 +958,6 @@ void CLegacy3D::RenderFrame(void)
{
// Begin frame
ClearErrors(); // must be cleared each frame
//printf("BEGIN FRAME\n");
// Z buffering (Z buffer is cleared by display list viewport nodes)
glDepthFunc(GL_LESS);
@ -1018,7 +989,7 @@ void CLegacy3D::RenderFrame(void)
if (fogIntensityLoc != -1) glEnableVertexAttribArray(fogIntensityLoc);
// Draw
//ClearModelCache(&VROMCache); // debug
//ClearModelCache(&VROMCache); // only enable this for debugging
ClearModelCache(&PolyCache);
for (int pri = 0; pri <= 3; pri++)
{