diff --git a/Source/Core/VideoCommon/Src/IndexGenerator.cpp b/Source/Core/VideoCommon/Src/IndexGenerator.cpp index 0c5c2fb91e..53a3e4a351 100644 --- a/Source/Core/VideoCommon/Src/IndexGenerator.cpp +++ b/Source/Core/VideoCommon/Src/IndexGenerator.cpp @@ -35,6 +35,30 @@ u32 IndexGenerator::index; static const u16 s_primitive_restart = -1; +static void (*primitive_table[8])(u32); + +void IndexGenerator::Init() +{ + if(g_Config.backend_info.bSupportsPrimitiveRestart) + { + primitive_table[0] = IndexGenerator::AddQuads; + primitive_table[2] = IndexGenerator::AddList; + primitive_table[3] = IndexGenerator::AddStrip; + primitive_table[4] = IndexGenerator::AddFan; + } + else + { + primitive_table[0] = IndexGenerator::AddQuads; + primitive_table[2] = IndexGenerator::AddList; + primitive_table[3] = IndexGenerator::AddStrip; + primitive_table[4] = IndexGenerator::AddFan; + } + primitive_table[1] = NULL; + primitive_table[5] = &IndexGenerator::AddLineList; + primitive_table[6] = &IndexGenerator::AddLineStrip; + primitive_table[7] = &IndexGenerator::AddPoints; +} + void IndexGenerator::Start(u16* Triangleptr, u16* Lineptr, u16* Pointptr) { Tptr = Triangleptr; @@ -51,57 +75,34 @@ void IndexGenerator::Start(u16* Triangleptr, u16* Lineptr, u16* Pointptr) void IndexGenerator::AddIndices(int primitive, u32 numVerts) { - //switch (primitive) - //{ - //case GX_DRAW_QUADS: IndexGenerator::AddQuads(numVerts); break; - //case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVerts); break; - //case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVerts); break; - //case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVerts); break; - //case GX_DRAW_LINES: IndexGenerator::AddLineList(numVerts); break; - //case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(numVerts); break; - //case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVerts); break; - //} - - static void (*const primitive_table[])(u32) = - { - IndexGenerator::AddQuads, - NULL, - IndexGenerator::AddList, - IndexGenerator::AddStrip, - IndexGenerator::AddFan, - IndexGenerator::AddLineList, - IndexGenerator::AddLineStrip, - IndexGenerator::AddPoints, - }; - primitive_table[primitive](numVerts); index += numVerts; } // Triangles -__forceinline void IndexGenerator::WriteTriangle(u32 index1, u32 index2, u32 index3) +template __forceinline void IndexGenerator::WriteTriangle(u32 index1, u32 index2, u32 index3) { *Tptr++ = index1; *Tptr++ = index2; *Tptr++ = index3; - if(g_Config.backend_info.bSupportsPrimitiveRestart) + if(pr) *Tptr++ = s_primitive_restart; ++numT; } -void IndexGenerator::AddList(u32 const numVerts) +template void IndexGenerator::AddList(u32 const numVerts) { auto const numTris = numVerts / 3; for (u32 i = 0; i != numTris; ++i) { - WriteTriangle(index + i * 3, index + i * 3 + 1, index + i * 3 + 2); + WriteTriangle(index + i * 3, index + i * 3 + 1, index + i * 3 + 2); } } -void IndexGenerator::AddStrip(u32 const numVerts) +template void IndexGenerator::AddStrip(u32 const numVerts) { - if(g_Config.backend_info.bSupportsPrimitiveRestart) { + if(pr) { for (u32 i = 0; i < numVerts; ++i) { *Tptr++ = index + i; @@ -113,7 +114,7 @@ void IndexGenerator::AddStrip(u32 const numVerts) bool wind = false; for (u32 i = 2; i < numVerts; ++i) { - WriteTriangle( + WriteTriangle( index + i - 2, index + i - !wind, index + i - wind); @@ -142,11 +143,11 @@ void IndexGenerator::AddStrip(u32 const numVerts) * so we use 6 indices for 3 triangles */ -void IndexGenerator::AddFan(u32 numVerts) +template void IndexGenerator::AddFan(u32 numVerts) { u32 i = 2; - if(g_Config.backend_info.bSupportsPrimitiveRestart) { + if(pr) { for(; i<=numVerts-3; i+=3) { *Tptr++ = index + i - 1; *Tptr++ = index + i + 0; @@ -169,7 +170,7 @@ void IndexGenerator::AddFan(u32 numVerts) for (; i < numVerts; ++i) { - WriteTriangle(index, index + i - 1, index + i); + WriteTriangle(index, index + i - 1, index + i); } } @@ -186,12 +187,12 @@ void IndexGenerator::AddFan(u32 numVerts) * or 120,302, 564,746 * or as strip: 1203, 5647 */ -void IndexGenerator::AddQuads(u32 numVerts) +template void IndexGenerator::AddQuads(u32 numVerts) { auto const numQuads = numVerts / 4; for (u32 i = 0; i != numQuads; ++i) { - if(g_Config.backend_info.bSupportsPrimitiveRestart) { + if(pr) { *Tptr++ = index + i * 4 + 1; *Tptr++ = index + i * 4 + 2; *Tptr++ = index + i * 4 + 0; @@ -199,8 +200,8 @@ void IndexGenerator::AddQuads(u32 numVerts) *Tptr++ = s_primitive_restart; numT += 2; } else { - WriteTriangle(index + i * 4, index + i * 4 + 1, index + i * 4 + 2); - WriteTriangle(index + i * 4, index + i * 4 + 2, index + i * 4 + 3); + WriteTriangle(index + i * 4, index + i * 4 + 1, index + i * 4 + 2); + WriteTriangle(index + i * 4, index + i * 4 + 2, index + i * 4 + 3); } } } diff --git a/Source/Core/VideoCommon/Src/IndexGenerator.h b/Source/Core/VideoCommon/Src/IndexGenerator.h index f14d3ae026..421c0aa4a8 100644 --- a/Source/Core/VideoCommon/Src/IndexGenerator.h +++ b/Source/Core/VideoCommon/Src/IndexGenerator.h @@ -26,6 +26,7 @@ class IndexGenerator { public: // Init + static void Init(); static void Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr); static void AddIndices(int primitive, u32 numVertices); @@ -54,10 +55,10 @@ public: */ private: // Triangles - static void AddList(u32 numVerts); - static void AddStrip(u32 numVerts); - static void AddFan(u32 numVerts); - static void AddQuads(u32 numVerts); + template static void AddList(u32 numVerts); + template static void AddStrip(u32 numVerts); + template static void AddFan(u32 numVerts); + template static void AddQuads(u32 numVerts); // Lines static void AddLineList(u32 numVerts); @@ -66,7 +67,7 @@ private: // Points static void AddPoints(u32 numVerts); - static void WriteTriangle(u32 index1, u32 index2, u32 index3); + template static void WriteTriangle(u32 index1, u32 index2, u32 index3); static u16 *Tptr; static u16 *BASETptr; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp index fcc5567016..0fe58e4277 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp @@ -35,6 +35,7 @@ #include "Debugger/DebuggerPanel.h" #include "DLCache.h" #include "EmuWindow.h" +#include "IndexGenerator.h" #include "FileUtil.h" #include "Globals.h" #include "IniFile.h" @@ -193,6 +194,7 @@ void VideoBackend::Video_Prepare() // VideoCommon BPInit(); Fifo_Init(); + IndexGenerator::Init(); VertexLoaderManager::Init(); OpcodeDecoder_Init(); VertexShaderManager::Init(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp index 71ce54c82b..4d21506b9c 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp @@ -51,6 +51,7 @@ #include "VideoState.h" #include "Render.h" #include "DLCache.h" +#include "IndexGenerator.h" #include "IniFile.h" #include "Core.h" #include "Host.h" @@ -184,6 +185,7 @@ void VideoBackend::Video_Prepare() // VideoCommon BPInit(); Fifo_Init(); + IndexGenerator::Init(); VertexLoaderManager::Init(); OpcodeDecoder_Init(); VertexShaderManager::Init(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 036444f8bd..ff5c3d1171 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -338,7 +338,7 @@ Renderer::Renderer() g_Config.backend_info.bSupportsDualSourceBlend = GLEW_ARB_blend_func_extended; g_Config.backend_info.bSupportsGLSLUBO = GLEW_ARB_uniform_buffer_object; - g_Config.backend_info.bSupportsPrimitiveRestart = false; //GLEW_VERSION_3_1; + g_Config.backend_info.bSupportsPrimitiveRestart = GLEW_VERSION_3_1; g_ogl_config.bSupportsGLSLCache = GLEW_ARB_get_program_binary; g_ogl_config.bSupportsGLPinnedMemory = GLEW_AMD_pinned_memory; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index e87238d4d4..9331956b67 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -96,6 +96,7 @@ Make AA apply instantly during gameplay if possible #include "PerfQuery.h" #include "VideoState.h" +#include "IndexGenerator.h" #include "VideoBackend.h" #include "ConfigManager.h" @@ -199,6 +200,7 @@ void VideoBackend::Video_Prepare() g_perf_query = new PerfQuery; Fifo_Init(); // must be done before OpcodeDecoder_Init() OpcodeDecoder_Init(); + IndexGenerator::Init(); VertexShaderManager::Init(); PixelShaderManager::Init(); ProgramShaderCache::Init();