calculate texture coordinates
This commit is contained in:
parent
fb9dddc360
commit
f16d2aec61
37
GPU3D.cpp
37
GPU3D.cpp
|
@ -169,10 +169,14 @@ void UpdateClipMatrix();
|
||||||
u32 PolygonMode;
|
u32 PolygonMode;
|
||||||
s16 CurVertex[3];
|
s16 CurVertex[3];
|
||||||
u8 VertexColor[3];
|
u8 VertexColor[3];
|
||||||
|
s16 TexCoords[2];
|
||||||
|
|
||||||
u32 PolygonAttr;
|
u32 PolygonAttr;
|
||||||
u32 CurPolygonAttr;
|
u32 CurPolygonAttr;
|
||||||
|
|
||||||
|
u32 TexParam;
|
||||||
|
u32 TexPalette;
|
||||||
|
|
||||||
Vertex TempVertexBuffer[4];
|
Vertex TempVertexBuffer[4];
|
||||||
u32 VertexNum;
|
u32 VertexNum;
|
||||||
u32 VertexNumInPoly;
|
u32 VertexNumInPoly;
|
||||||
|
@ -410,6 +414,9 @@ void ClipSegment(Vertex* outbuf, Vertex* vout, Vertex* vin)
|
||||||
INTERPOLATE(Color[1]);
|
INTERPOLATE(Color[1]);
|
||||||
INTERPOLATE(Color[2]);
|
INTERPOLATE(Color[2]);
|
||||||
|
|
||||||
|
INTERPOLATE(TexCoords[0]);
|
||||||
|
INTERPOLATE(TexCoords[1]);
|
||||||
|
|
||||||
mid.Clipped = true;
|
mid.Clipped = true;
|
||||||
mid.ViewportTransformDone = false;
|
mid.ViewportTransformDone = false;
|
||||||
|
|
||||||
|
@ -798,6 +805,17 @@ void SubmitVertex()
|
||||||
vertextrans->Color[1] = (VertexColor[1] << 12) + 0xFFF;
|
vertextrans->Color[1] = (VertexColor[1] << 12) + 0xFFF;
|
||||||
vertextrans->Color[2] = (VertexColor[2] << 12) + 0xFFF;
|
vertextrans->Color[2] = (VertexColor[2] << 12) + 0xFFF;
|
||||||
|
|
||||||
|
if ((TexParam >> 30) == 3)
|
||||||
|
{
|
||||||
|
vertextrans->TexCoords[0] = (CurVertex[0]*TexMatrix[0] + CurVertex[1]*TexMatrix[4] + CurVertex[2]*TexMatrix[8] + 0x1000*TexCoords[0]) >> 12;
|
||||||
|
vertextrans->TexCoords[1] = (CurVertex[0]*TexMatrix[1] + CurVertex[1]*TexMatrix[5] + CurVertex[2]*TexMatrix[9] + 0x1000*TexCoords[1]) >> 12;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vertextrans->TexCoords[0] = TexCoords[0];
|
||||||
|
vertextrans->TexCoords[1] = TexCoords[1];
|
||||||
|
}
|
||||||
|
|
||||||
vertextrans->Clipped = false;
|
vertextrans->Clipped = false;
|
||||||
vertextrans->ViewportTransformDone = false;
|
vertextrans->ViewportTransformDone = false;
|
||||||
|
|
||||||
|
@ -1219,6 +1237,17 @@ void ExecuteCommand()
|
||||||
|
|
||||||
case 0x21:
|
case 0x21:
|
||||||
// TODO: more cycles if lights are enabled
|
// TODO: more cycles if lights are enabled
|
||||||
|
// TODO also texcoords if needed
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x22: // texcoord
|
||||||
|
TexCoords[0] = ExecParams[0] & 0xFFFF;
|
||||||
|
TexCoords[1] = ExecParams[1] >> 16;
|
||||||
|
if ((TexParam >> 30) == 1)
|
||||||
|
{
|
||||||
|
TexCoords[0] = (TexCoords[0]*TexMatrix[0] + TexCoords[1]*TexMatrix[4] + TexMatrix[8] + TexMatrix[12]) >> 12;
|
||||||
|
TexCoords[1] = (TexCoords[0]*TexMatrix[1] + TexCoords[1]*TexMatrix[5] + TexMatrix[9] + TexMatrix[13]) >> 12;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x23: // full vertex
|
case 0x23: // full vertex
|
||||||
|
@ -1264,6 +1293,14 @@ void ExecuteCommand()
|
||||||
PolygonAttr = ExecParams[0];
|
PolygonAttr = ExecParams[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0x2A: // texture param
|
||||||
|
TexParam = ExecParams[0];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x2B: // texture palette
|
||||||
|
TexPalette = ExecParams[0] & 0x1FFF;
|
||||||
|
break;
|
||||||
|
|
||||||
case 0x40:
|
case 0x40:
|
||||||
PolygonMode = ExecParams[0] & 0x3;
|
PolygonMode = ExecParams[0] & 0x3;
|
||||||
VertexNum = 0;
|
VertexNum = 0;
|
||||||
|
|
1
GPU3D.h
1
GPU3D.h
|
@ -26,6 +26,7 @@ typedef struct
|
||||||
{
|
{
|
||||||
s32 Position[4];
|
s32 Position[4];
|
||||||
s32 Color[3];
|
s32 Color[3];
|
||||||
|
s16 TexCoords[2];
|
||||||
|
|
||||||
bool Clipped;
|
bool Clipped;
|
||||||
|
|
||||||
|
|
|
@ -333,6 +333,8 @@ void RenderPolygon(Polygon* polygon)
|
||||||
perspfactor2 = 0;
|
perspfactor2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//z = 0x1000000 / (perspfactor1 + perspfactor2);
|
||||||
|
|
||||||
// possible optimization: only do color interpolation if the depth test passes
|
// possible optimization: only do color interpolation if the depth test passes
|
||||||
u32 vr = ((perspfactor1 * rl) + (perspfactor2 * rr)) / (perspfactor1 + perspfactor2);
|
u32 vr = ((perspfactor1 * rl) + (perspfactor2 * rr)) / (perspfactor1 + perspfactor2);
|
||||||
u32 vg = ((perspfactor1 * gl) + (perspfactor2 * gr)) / (perspfactor1 + perspfactor2);
|
u32 vg = ((perspfactor1 * gl) + (perspfactor2 * gr)) / (perspfactor1 + perspfactor2);
|
||||||
|
|
3
NDS.cpp
3
NDS.cpp
|
@ -776,6 +776,9 @@ void debug(u32 param)
|
||||||
{
|
{
|
||||||
printf("ARM9 PC=%08X LR=%08X %08X\n", ARM9->R[15], ARM9->R[14], ARM9->R_IRQ[1]);
|
printf("ARM9 PC=%08X LR=%08X %08X\n", ARM9->R[15], ARM9->R[14], ARM9->R_IRQ[1]);
|
||||||
printf("ARM7 PC=%08X LR=%08X %08X\n", ARM7->R[15], ARM7->R[14], ARM7->R_IRQ[1]);
|
printf("ARM7 PC=%08X LR=%08X %08X\n", ARM7->R[15], ARM7->R[14], ARM7->R_IRQ[1]);
|
||||||
|
|
||||||
|
for (int i = 0; i < 9; i++)
|
||||||
|
printf("VRAM %c: %02X\n", 'A'+i, GPU::VRAMCNT[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
1481161027 c:\documents\sources\melonds\types.h
|
1481161027 c:\documents\sources\melonds\types.h
|
||||||
|
|
||||||
1488227258 source:c:\documents\sources\melonds\nds.cpp
|
1488237361 source:c:\documents\sources\melonds\nds.cpp
|
||||||
<stdio.h>
|
<stdio.h>
|
||||||
<string.h>
|
<string.h>
|
||||||
"NDS.h"
|
"NDS.h"
|
||||||
|
@ -119,7 +119,7 @@
|
||||||
1487305393 c:\documents\sources\melonds\dma.h
|
1487305393 c:\documents\sources\melonds\dma.h
|
||||||
"types.h"
|
"types.h"
|
||||||
|
|
||||||
1488226688 source:c:\documents\sources\melonds\gpu.cpp
|
1488227337 source:c:\documents\sources\melonds\gpu.cpp
|
||||||
<stdio.h>
|
<stdio.h>
|
||||||
<string.h>
|
<string.h>
|
||||||
"NDS.h"
|
"NDS.h"
|
||||||
|
@ -146,16 +146,16 @@
|
||||||
"NDS.h"
|
"NDS.h"
|
||||||
"NDSCart.h"
|
"NDSCart.h"
|
||||||
|
|
||||||
1487610598 c:\documents\sources\melonds\gpu3d.h
|
1488238607 c:\documents\sources\melonds\gpu3d.h
|
||||||
|
|
||||||
1487681103 source:c:\documents\sources\melonds\gpu3d.cpp
|
1488239360 source:c:\documents\sources\melonds\gpu3d.cpp
|
||||||
<stdio.h>
|
<stdio.h>
|
||||||
<string.h>
|
<string.h>
|
||||||
"NDS.h"
|
"NDS.h"
|
||||||
"GPU.h"
|
"GPU.h"
|
||||||
"FIFO.h"
|
"FIFO.h"
|
||||||
|
|
||||||
1488214777 source:c:\documents\sources\melonds\gpu3d_soft.cpp
|
1488237540 source:c:\documents\sources\melonds\gpu3d_soft.cpp
|
||||||
<stdio.h>
|
<stdio.h>
|
||||||
<string.h>
|
<string.h>
|
||||||
"NDS.h"
|
"NDS.h"
|
||||||
|
|
Loading…
Reference in New Issue