Refactored VertexLoader::CompileVertexTranslator(). Now texture coordinates loaders are also selected from a function table. I will add a hack to increase the speed in the next commit.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5140 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nodchip 2010-02-28 11:36:00 +00:00
parent d348c33bf2
commit 1c34052266
5 changed files with 90 additions and 74 deletions

View File

@ -269,7 +269,7 @@ void VertexLoader::CompileVertexTranslator()
_assert_msg_(VIDEO, 0 <= m_VtxAttr.PosElements && m_VtxAttr.PosElements <= 1, "Invalid number of vertex position elemnts!\n(m_VtxAttr.PosElements = %d)", m_VtxAttr.PosElements); _assert_msg_(VIDEO, 0 <= m_VtxAttr.PosElements && m_VtxAttr.PosElements <= 1, "Invalid number of vertex position elemnts!\n(m_VtxAttr.PosElements = %d)", m_VtxAttr.PosElements);
WriteCall(tableReadPosition[m_VtxDesc.Position][m_VtxAttr.PosFormat][m_VtxAttr.PosElements]); WriteCall(tableReadPosition[m_VtxDesc.Position][m_VtxAttr.PosFormat][m_VtxAttr.PosElements]);
m_VertexSize += tableVertexSize[m_VtxDesc.Position][m_VtxAttr.PosFormat][m_VtxAttr.PosElements]; m_VertexSize += tableReadPositionVertexSize[m_VtxDesc.Position][m_VtxAttr.PosFormat][m_VtxAttr.PosElements];
nat_offset += 12; nat_offset += 12;
// OK, so we just got a point. Let's go back and read it for the bounding box. // OK, so we just got a point. Let's go back and read it for the bounding box.
@ -412,48 +412,19 @@ void VertexLoader::CompileVertexTranslator()
// Texture matrix indices (remove if corresponding texture coordinate isn't enabled) // Texture matrix indices (remove if corresponding texture coordinate isn't enabled)
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
vtx_decl.texcoord_offset[i] = -1; vtx_decl.texcoord_offset[i] = -1;
m_NativeFmt->m_components |= VB_HAS_UV0 << i; const int format = m_VtxAttr.texCoord[i].Format;
int elements = m_VtxAttr.texCoord[i].Elements; const int elements = m_VtxAttr.texCoord[i].Elements;
switch (tc[i])
{ if (tc[i] == NOT_PRESENT) {
case NOT_PRESENT:
m_NativeFmt->m_components &= ~(VB_HAS_UV0 << i); m_NativeFmt->m_components &= ~(VB_HAS_UV0 << i);
break; } else {
case DIRECT: _assert_msg_(VIDEO, DIRECT <= tc[i] && tc[i] <= INDEX16, "Invalid texture coordinates!\n(tc[i] = %d)", tc[i]);
switch (m_VtxAttr.texCoord[i].Format) _assert_msg_(VIDEO, FORMAT_UBYTE <= format && format <= FORMAT_FLOAT, "Invalid texture coordinates format!\n(format = %d)", format);
{ _assert_msg_(VIDEO, 0 <= elements && elements <= 1, "Invalid number of texture coordinates elemnts!\n(elements = %d)", elements);
case FORMAT_UBYTE: m_VertexSize += elements?2:1; WriteCall(elements?TexCoord_ReadDirect_UByte2:TexCoord_ReadDirect_UByte1); break;
case FORMAT_BYTE: m_VertexSize += elements?2:1; WriteCall(elements?TexCoord_ReadDirect_Byte2:TexCoord_ReadDirect_Byte1); break; m_NativeFmt->m_components |= VB_HAS_UV0 << i;
case FORMAT_USHORT: m_VertexSize += elements?4:2; WriteCall(elements?TexCoord_ReadDirect_UShort2:TexCoord_ReadDirect_UShort1); break; WriteCall(tableReadTexCoord[tc[i]][format][elements]);
case FORMAT_SHORT: m_VertexSize += elements?4:2; WriteCall(elements?TexCoord_ReadDirect_Short2:TexCoord_ReadDirect_Short1); break; m_VertexSize += tableReadTexCoordVertexSize[tc[i]][format][elements];
case FORMAT_FLOAT: m_VertexSize += elements?8:4; WriteCall(elements?TexCoord_ReadDirect_Float2:TexCoord_ReadDirect_Float1); break;
default: _assert_(0); break;
}
break;
case INDEX8:
m_VertexSize += 1;
switch (m_VtxAttr.texCoord[i].Format)
{
case FORMAT_UBYTE: WriteCall(elements?TexCoord_ReadIndex8_UByte2:TexCoord_ReadIndex8_UByte1); break;
case FORMAT_BYTE: WriteCall(elements?TexCoord_ReadIndex8_Byte2:TexCoord_ReadIndex8_Byte1); break;
case FORMAT_USHORT: WriteCall(elements?TexCoord_ReadIndex8_UShort2:TexCoord_ReadIndex8_UShort1); break;
case FORMAT_SHORT: WriteCall(elements?TexCoord_ReadIndex8_Short2:TexCoord_ReadIndex8_Short1); break;
case FORMAT_FLOAT: WriteCall(elements?TexCoord_ReadIndex8_Float2:TexCoord_ReadIndex8_Float1); break;
default: _assert_(0); break;
}
break;
case INDEX16:
m_VertexSize += 2;
switch (m_VtxAttr.texCoord[i].Format)
{
case FORMAT_UBYTE: WriteCall(elements?TexCoord_ReadIndex16_UByte2:TexCoord_ReadIndex16_UByte1); break;
case FORMAT_BYTE: WriteCall(elements?TexCoord_ReadIndex16_Byte2:TexCoord_ReadIndex16_Byte1); break;
case FORMAT_USHORT: WriteCall(elements?TexCoord_ReadIndex16_UShort2:TexCoord_ReadIndex16_UShort1); break;
case FORMAT_SHORT: WriteCall(elements?TexCoord_ReadIndex16_Short2:TexCoord_ReadIndex16_Short1); break;
case FORMAT_FLOAT: WriteCall(elements?TexCoord_ReadIndex16_Float2:TexCoord_ReadIndex16_Float1); break;
default: _assert_(0);
}
break;
} }
if (m_NativeFmt->m_components & (VB_HAS_TEXMTXIDX0 << i)) { if (m_NativeFmt->m_components & (VB_HAS_TEXMTXIDX0 << i)) {

View File

@ -219,7 +219,7 @@ ReadPosision tableReadPosition[4][8][2] = {
}, },
}; };
int tableVertexSize[4][8][2] = { int tableReadPositionVertexSize[4][8][2] = {
{ {
{0, 0,}, {0, 0,},
{0, 0,}, {0, 0,},

View File

@ -29,6 +29,6 @@ extern ReadPosision tableReadPosition[4][8][2];
// Hold vertex size of each vertex format. // Hold vertex size of each vertex format.
// The dimensions are same as tableReadPosition. // The dimensions are same as tableReadPosition.
extern int tableVertexSize[4][8][2]; extern int tableReadPositionVertexSize[4][8][2];
#endif #endif

View File

@ -319,4 +319,66 @@ void LOADERDECL TexCoord_ReadIndex16_Float2()
tcIndex++; tcIndex++;
} }
ReadPosision tableReadTexCoord[4][8][2] = {
{
{NULL, NULL,},
{NULL, NULL,},
{NULL, NULL,},
{NULL, NULL,},
{NULL, NULL,},
},
{
{TexCoord_ReadDirect_UByte1, TexCoord_ReadDirect_UByte2,},
{TexCoord_ReadDirect_Byte1, TexCoord_ReadDirect_Byte2,},
{TexCoord_ReadDirect_UShort1, TexCoord_ReadDirect_UShort2,},
{TexCoord_ReadDirect_Short1, TexCoord_ReadDirect_Short2,},
{TexCoord_ReadDirect_Float1, TexCoord_ReadDirect_Float2,},
},
{
{TexCoord_ReadIndex8_UByte1, TexCoord_ReadIndex8_UByte2,},
{TexCoord_ReadIndex8_Byte1, TexCoord_ReadIndex8_Byte2,},
{TexCoord_ReadIndex8_UShort1, TexCoord_ReadIndex8_UShort2,},
{TexCoord_ReadIndex8_Short1, TexCoord_ReadIndex8_Short2,},
{TexCoord_ReadIndex8_Float1, TexCoord_ReadIndex8_Float2,},
},
{
{TexCoord_ReadIndex16_UByte1, TexCoord_ReadIndex16_UByte2,},
{TexCoord_ReadIndex16_Byte1, TexCoord_ReadIndex16_Byte2,},
{TexCoord_ReadIndex16_UShort1, TexCoord_ReadIndex16_UShort2,},
{TexCoord_ReadIndex16_Short1, TexCoord_ReadIndex16_Short2,},
{TexCoord_ReadIndex16_Float1, TexCoord_ReadIndex16_Float2,},
},
};
int tableReadTexCoordVertexSize[4][8][2] = {
{
{0, 0,},
{0, 0,},
{0, 0,},
{0, 0,},
{0, 0,},
},
{
{1, 2,},
{1, 2,},
{2, 4,},
{2, 4,},
{4, 8,},
},
{
{1, 1,},
{1, 1,},
{1, 1,},
{1, 1,},
{1, 1,},
},
{
{2, 2,},
{2, 2,},
{2, 2,},
{2, 2,},
{2, 2,},
},
};
#endif #endif

View File

@ -18,36 +18,19 @@
#ifndef VERTEXLOADER_TEXCOORD_H #ifndef VERTEXLOADER_TEXCOORD_H
#define VERTEXLOADER_TEXCOORD_H #define VERTEXLOADER_TEXCOORD_H
typedef void (LOADERDECL *ReadTexCoord)();
// Hold function pointers of texture coordinates loaders.
// The first dimension corresponds to TVtxDesc.Tex?Coord.
// The second dimension corresponds to TVtxAttr.texCoord[?].Format.
// The third dimension corresponds to TVtxAttr.texCoord[?].Elements.
// The dimensions are aligned to 2^n for speed up.
extern ReadTexCoord tableReadTexCoord[4][8][2];
// Hold vertex size of each vertex format.
// The dimensions are same as tableReadPosition.
extern int tableReadTexCoordVertexSize[4][8][2];
void LOADERDECL TexCoord_Read_Dummy(); void LOADERDECL TexCoord_Read_Dummy();
void LOADERDECL TexCoord_ReadDirect_UByte1();
void LOADERDECL TexCoord_ReadDirect_UByte2();
void LOADERDECL TexCoord_ReadDirect_Byte1();
void LOADERDECL TexCoord_ReadDirect_Byte2();
void LOADERDECL TexCoord_ReadDirect_UShort1();
void LOADERDECL TexCoord_ReadDirect_UShort2();
void LOADERDECL TexCoord_ReadDirect_Short1();
void LOADERDECL TexCoord_ReadDirect_Short2();
void LOADERDECL TexCoord_ReadDirect_Float1();
void LOADERDECL TexCoord_ReadDirect_Float2();
void LOADERDECL TexCoord_ReadIndex8_UByte1();
void LOADERDECL TexCoord_ReadIndex8_UByte2();
void LOADERDECL TexCoord_ReadIndex8_Byte1();
void LOADERDECL TexCoord_ReadIndex8_Byte2();
void LOADERDECL TexCoord_ReadIndex8_UShort1();
void LOADERDECL TexCoord_ReadIndex8_UShort2();
void LOADERDECL TexCoord_ReadIndex8_Short1();
void LOADERDECL TexCoord_ReadIndex8_Short2();
void LOADERDECL TexCoord_ReadIndex8_Float1();
void LOADERDECL TexCoord_ReadIndex8_Float2();
void LOADERDECL TexCoord_ReadIndex16_UByte1();
void LOADERDECL TexCoord_ReadIndex16_UByte2();
void LOADERDECL TexCoord_ReadIndex16_Byte1();
void LOADERDECL TexCoord_ReadIndex16_Byte2();
void LOADERDECL TexCoord_ReadIndex16_UShort1();
void LOADERDECL TexCoord_ReadIndex16_UShort2();
void LOADERDECL TexCoord_ReadIndex16_Short1();
void LOADERDECL TexCoord_ReadIndex16_Short2();
void LOADERDECL TexCoord_ReadIndex16_Float1();
void LOADERDECL TexCoord_ReadIndex16_Float2();
#endif #endif