summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authornodchip <nodchip@gmail.com>2010-02-28 08:41:02 +0000
committernodchip <nodchip@gmail.com>2010-02-28 08:41:02 +0000
commitd348c33bf2f094ac8c541ee459e4edb029da4fb4 (patch)
tree1afc0e06fffed611f49d855e1ad9dfe5337faf09 /Source/Core
parentff8ce634e38e960234281134d668631439b17ab2 (diff)
Refactored VertexLoader::CompileVertexTranslator(). Now the vertex position loader is selected from a function table. I will apply the same kind of refactoring to texture coordinates loader. This is a pre-preparation to optimize texture coordinates loaders.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5139 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/VideoCommon/Src/VertexLoader.cpp46
-rw-r--r--Source/Core/VideoCommon/Src/VertexLoader_Position.cpp66
-rw-r--r--Source/Core/VideoCommon/Src/VertexLoader_Position.h47
3 files changed, 82 insertions, 77 deletions
diff --git a/Source/Core/VideoCommon/Src/VertexLoader.cpp b/Source/Core/VideoCommon/Src/VertexLoader.cpp
index 35abfa8b3c..1f41662c62 100644
--- a/Source/Core/VideoCommon/Src/VertexLoader.cpp
+++ b/Source/Core/VideoCommon/Src/VertexLoader.cpp
@@ -263,44 +263,14 @@ void VertexLoader::CompileVertexTranslator()
if (m_VtxDesc.Tex6MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte); }
if (m_VtxDesc.Tex7MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX7; WriteCall(TexMtx_ReadDirect_UByte); }
- switch (m_VtxDesc.Position) {
- case NOT_PRESENT: {_assert_msg_(0, "Vertex descriptor without position!", "WTF?");} break;
- case DIRECT:
- switch (m_VtxAttr.PosFormat) {
- case FORMAT_UBYTE: m_VertexSize += m_VtxAttr.PosElements?3:2; WriteCall(m_VtxAttr.PosElements?Pos_ReadDirect_UByte3:Pos_ReadDirect_UByte2); break;
- case FORMAT_BYTE: m_VertexSize += m_VtxAttr.PosElements?3:2; WriteCall(m_VtxAttr.PosElements?Pos_ReadDirect_Byte3:Pos_ReadDirect_Byte2); break;
- case FORMAT_USHORT: m_VertexSize += m_VtxAttr.PosElements?6:4; WriteCall(m_VtxAttr.PosElements?Pos_ReadDirect_UShort3:Pos_ReadDirect_UShort2); break;
- case FORMAT_SHORT: m_VertexSize += m_VtxAttr.PosElements?6:4; WriteCall(m_VtxAttr.PosElements?Pos_ReadDirect_Short3:Pos_ReadDirect_Short2); break;
- case FORMAT_FLOAT: m_VertexSize += m_VtxAttr.PosElements?12:8; WriteCall(m_VtxAttr.PosElements?Pos_ReadDirect_Float3:Pos_ReadDirect_Float2); break;
- default: _assert_(0); break;
- }
- nat_offset += 12;
- break;
- case INDEX8:
- switch (m_VtxAttr.PosFormat) {
- case FORMAT_UBYTE: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex8_UByte3:Pos_ReadIndex8_UByte2); break; //WTF?
- case FORMAT_BYTE: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex8_Byte3:Pos_ReadIndex8_Byte2); break;
- case FORMAT_USHORT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex8_UShort3:Pos_ReadIndex8_UShort2); break;
- case FORMAT_SHORT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex8_Short3:Pos_ReadIndex8_Short2); break;
- case FORMAT_FLOAT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex8_Float3:Pos_ReadIndex8_Float2); break;
- default: _assert_(0); break;
- }
- m_VertexSize += 1;
- nat_offset += 12;
- break;
- case INDEX16:
- switch (m_VtxAttr.PosFormat) {
- case FORMAT_UBYTE: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex16_UByte3:Pos_ReadIndex16_UByte2); break;
- case FORMAT_BYTE: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex16_Byte3:Pos_ReadIndex16_Byte2); break;
- case FORMAT_USHORT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex16_UShort3:Pos_ReadIndex16_UShort2); break;
- case FORMAT_SHORT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex16_Short3:Pos_ReadIndex16_Short2); break;
- case FORMAT_FLOAT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex16_Float3:Pos_ReadIndex16_Float2); break;
- default: _assert_(0); break;
- }
- m_VertexSize += 2;
- nat_offset += 12;
- break;
- }
+ // Write vertex position loader
+ _assert_msg_(VIDEO, DIRECT <= m_VtxDesc.Position && m_VtxDesc.Position <= INDEX16, "Invalid vertex position!\n(m_VtxDesc.Position = %d)", m_VtxDesc.Position);
+ _assert_msg_(VIDEO, FORMAT_UBYTE <= m_VtxAttr.PosFormat && m_VtxAttr.PosFormat <= FORMAT_FLOAT, "Invalid vertex position format!\n(m_VtxAttr.PosFormat = %d)", m_VtxAttr.PosFormat);
+ _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]);
+ m_VertexSize += tableVertexSize[m_VtxDesc.Position][m_VtxAttr.PosFormat][m_VtxAttr.PosElements];
+ nat_offset += 12;
// OK, so we just got a point. Let's go back and read it for the bounding box.
diff --git a/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp b/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp
index 907a84cca9..b47567beed 100644
--- a/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp
+++ b/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp
@@ -15,9 +15,6 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
-#ifndef VERTEXLOADER_POSITION_H
-#define VERTEXLOADER_POSITION_H
-
#include "Common.h"
#include "VideoCommon.h"
#include "VertexLoader.h"
@@ -191,4 +188,65 @@ void LOADERDECL Pos_ReadIndex16_UShort2() {Pos_ReadIndex_Short<u16, false>(DataR
void LOADERDECL Pos_ReadIndex16_Short2() {Pos_ReadIndex_Short<s16, false>(DataReadU16());}
void LOADERDECL Pos_ReadIndex16_Float2() {Pos_ReadIndex_Float<false> (DataReadU16());}
-#endif
+ReadPosision tableReadPosition[4][8][2] = {
+ {
+ {NULL, NULL,},
+ {NULL, NULL,},
+ {NULL, NULL,},
+ {NULL, NULL,},
+ {NULL, NULL,},
+ },
+ {
+ {Pos_ReadDirect_UByte2, Pos_ReadDirect_UByte3,},
+ {Pos_ReadDirect_Byte2, Pos_ReadDirect_Byte3,},
+ {Pos_ReadDirect_UShort2, Pos_ReadDirect_UShort3,},
+ {Pos_ReadDirect_Short2, Pos_ReadDirect_Short3,},
+ {Pos_ReadDirect_Float2, Pos_ReadDirect_Float3,},
+ },
+ {
+ {Pos_ReadIndex8_UByte2, Pos_ReadIndex8_UByte3,},
+ {Pos_ReadIndex8_Byte2, Pos_ReadIndex8_Byte3,},
+ {Pos_ReadIndex8_UShort2, Pos_ReadIndex8_UShort3,},
+ {Pos_ReadIndex8_Short2, Pos_ReadIndex8_Short3,},
+ {Pos_ReadIndex8_Float2, Pos_ReadIndex8_Float3,},
+ },
+ {
+ {Pos_ReadIndex16_UByte2, Pos_ReadIndex16_UByte3,},
+ {Pos_ReadIndex16_Byte2, Pos_ReadIndex16_Byte3,},
+ {Pos_ReadIndex16_UShort2, Pos_ReadIndex16_UShort3,},
+ {Pos_ReadIndex16_Short2, Pos_ReadIndex16_Short3,},
+ {Pos_ReadIndex16_Float2, Pos_ReadIndex16_Float3,},
+ },
+};
+
+int tableVertexSize[4][8][2] = {
+ {
+ {0, 0,},
+ {0, 0,},
+ {0, 0,},
+ {0, 0,},
+ {0, 0,},
+ },
+ {
+ {2, 3,},
+ {2, 3,},
+ {4, 6,},
+ {4, 6,},
+ {8, 12,},
+ },
+ {
+ {1, 1,},
+ {1, 1,},
+ {1, 1,},
+ {1, 1,},
+ {1, 1,},
+ },
+ {
+ {2, 2,},
+ {2, 2,},
+ {2, 2,},
+ {2, 2,},
+ {2, 2,},
+ },
+};
+
diff --git a/Source/Core/VideoCommon/Src/VertexLoader_Position.h b/Source/Core/VideoCommon/Src/VertexLoader_Position.h
index 32da38e6be..f61dd9fd92 100644
--- a/Source/Core/VideoCommon/Src/VertexLoader_Position.h
+++ b/Source/Core/VideoCommon/Src/VertexLoader_Position.h
@@ -18,40 +18,17 @@
#ifndef VERTEXLOADER_POSITION_H
#define VERTEXLOADER_POSITION_H
-void LOADERDECL Pos_ReadDirect_UByte3();
-void LOADERDECL Pos_ReadDirect_Byte3();
-void LOADERDECL Pos_ReadDirect_UShort3();
-void LOADERDECL Pos_ReadDirect_Short3();
-void LOADERDECL Pos_ReadDirect_Float3();
-
-void LOADERDECL Pos_ReadIndex8_UByte3();
-void LOADERDECL Pos_ReadIndex8_Byte3();
-void LOADERDECL Pos_ReadIndex8_UShort3();
-void LOADERDECL Pos_ReadIndex8_Short3();
-void LOADERDECL Pos_ReadIndex8_Float3();
-
-void LOADERDECL Pos_ReadIndex16_UByte3();
-void LOADERDECL Pos_ReadIndex16_Byte3();
-void LOADERDECL Pos_ReadIndex16_UShort3();
-void LOADERDECL Pos_ReadIndex16_Short3();
-void LOADERDECL Pos_ReadIndex16_Float3();
-
-void LOADERDECL Pos_ReadDirect_UByte2();
-void LOADERDECL Pos_ReadDirect_Byte2();
-void LOADERDECL Pos_ReadDirect_UShort2();
-void LOADERDECL Pos_ReadDirect_Short2();
-void LOADERDECL Pos_ReadDirect_Float2();
-
-void LOADERDECL Pos_ReadIndex8_UByte2();
-void LOADERDECL Pos_ReadIndex8_Byte2();
-void LOADERDECL Pos_ReadIndex8_UShort2();
-void LOADERDECL Pos_ReadIndex8_Short2();
-void LOADERDECL Pos_ReadIndex8_Float2();
-
-void LOADERDECL Pos_ReadIndex16_UByte2();
-void LOADERDECL Pos_ReadIndex16_Byte2();
-void LOADERDECL Pos_ReadIndex16_UShort2();
-void LOADERDECL Pos_ReadIndex16_Short2();
-void LOADERDECL Pos_ReadIndex16_Float2();
+typedef void (LOADERDECL *ReadPosision)();
+
+// Hold function pointers of vertex loaders.
+// The first dimension corresponds to TVtxDesc.Position.
+// The second dimension corresponds to TVtxAttr.PosFormat.
+// The third dimension corresponds to TVtxAttr.PosElements.
+// The dimensions are aligned to 2^n for speed up.
+extern ReadPosision tableReadPosition[4][8][2];
+
+// Hold vertex size of each vertex format.
+// The dimensions are same as tableReadPosition.
+extern int tableVertexSize[4][8][2];
#endif