From 410e3337504c5d837475fb52c7803ddeb15b0de3 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Fri, 19 Dec 2014 14:09:16 +0100 Subject: [PATCH] GeometryShaderGen: Re-emit the first vertex when wireframe mode is enabled. --- Source/Core/VideoCommon/GeometryShaderGen.cpp | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp index eaba7652d655..af6217aa571a 100644 --- a/Source/Core/VideoCommon/GeometryShaderGen.cpp +++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp @@ -11,6 +11,7 @@ #include "VideoCommon/VideoConfig.h" static char text[16384]; +static bool s_first_vertex = true; static const char* primitives_ogl[] = { @@ -27,6 +28,7 @@ static const char* primitives_d3d[] = }; template static inline void EmitVertex(T& out, const char* vertex, API_TYPE ApiType); +template static inline void EndPrimitive(T& out, API_TYPE ApiType); template static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE ApiType) @@ -45,10 +47,13 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A uid_data->primitive_type = primitive_type; const unsigned int vertex_in = primitive_type + 1; - const unsigned int vertex_out = primitive_type == PRIMITIVE_TRIANGLES ? 3 : 4; + unsigned int vertex_out = primitive_type == PRIMITIVE_TRIANGLES ? 3 : 4; - uid_data->stereo = g_ActiveConfig.iStereoMode > 0; uid_data->wireframe = g_ActiveConfig.bWireFrame; + if (g_ActiveConfig.bWireFrame) + vertex_out++; + + uid_data->stereo = g_ActiveConfig.iStereoMode > 0; if (ApiType == API_OPENGL) { // Insert layout parameters @@ -178,6 +183,9 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A out.Write("\tfor (int eye = 0; eye < 2; ++eye) {\n"); } + if (g_ActiveConfig.bWireFrame) + out.Write("\tVS_OUTPUT first;\n"); + out.Write("\tfor (int i = 0; i < %d; ++i) {\n", vertex_in); if (ApiType == API_OPENGL) @@ -261,10 +269,7 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A out.Write("\t}\n"); - if (ApiType == API_OPENGL) - out.Write("\tEndPrimitive();\n"); - else - out.Write("\toutput.RestartStrip();\n"); + EndPrimitive(out, ApiType); if (g_ActiveConfig.iStereoMode > 0 && !g_ActiveConfig.backend_info.bSupportsGSInstancing) out.Write("\t}\n"); @@ -281,6 +286,11 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A template static inline void EmitVertex(T& out, const char* vertex, API_TYPE ApiType) { + if (g_ActiveConfig.bWireFrame && s_first_vertex) + out.Write("\tif (i == 0) first = %s;\n", vertex); + + s_first_vertex = false; + if (ApiType == API_OPENGL) out.Write("\tgl_Position = %s.pos;\n", vertex); @@ -291,6 +301,19 @@ static inline void EmitVertex(T& out, const char* vertex, API_TYPE ApiType) else out.Write("\toutput.Append(ps);\n"); } +template +static inline void EndPrimitive(T& out, API_TYPE ApiType) +{ + if (g_ActiveConfig.bWireFrame) + EmitVertex(out, "first", ApiType); + + s_first_vertex = true; + + if (ApiType == API_OPENGL) + out.Write("\tEndPrimitive();\n"); + else + out.Write("\toutput.RestartStrip();\n"); +} void GetGeometryShaderUid(GeometryShaderUid& object, u32 primitive_type, API_TYPE ApiType) {