GeometryShaderGen: Re-emit the first vertex when wireframe mode is enabled.

This commit is contained in:
Jules Blok 2014-12-19 14:09:16 +01:00
parent 1b9fe70d7c
commit 531b3941ff
1 changed files with 29 additions and 11 deletions

View File

@ -26,7 +26,8 @@ static const char* primitives_d3d[] =
"triangle" "triangle"
}; };
template<class T> static inline void EmitVertex(T& out, const char* vertex, API_TYPE ApiType); template<class T> static inline void EmitVertex(T& out, const char* vertex, API_TYPE ApiType, bool first_vertex = false);
template<class T> static inline void EndPrimitive(T& out, API_TYPE ApiType);
template<class T> template<class T>
static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE ApiType) static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE ApiType)
@ -45,10 +46,13 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
uid_data->primitive_type = primitive_type; uid_data->primitive_type = primitive_type;
const unsigned int vertex_in = primitive_type + 1; 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->wireframe = g_ActiveConfig.bWireFrame;
if (g_ActiveConfig.bWireFrame)
vertex_out++;
uid_data->stereo = g_ActiveConfig.iStereoMode > 0; uid_data->stereo = g_ActiveConfig.iStereoMode > 0;
uid_data->wireframe = g_ActiveConfig.bWireFrame;
if (ApiType == API_OPENGL) if (ApiType == API_OPENGL)
{ {
// Insert layout parameters // Insert layout parameters
@ -178,6 +182,9 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
out.Write("\tfor (int eye = 0; eye < 2; ++eye) {\n"); 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); out.Write("\tfor (int i = 0; i < %d; ++i) {\n", vertex_in);
if (ApiType == API_OPENGL) if (ApiType == API_OPENGL)
@ -221,7 +228,7 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
} }
out.Write("\t}\n"); out.Write("\t}\n");
EmitVertex<T>(out, "l", ApiType); EmitVertex<T>(out, "l", ApiType, true);
EmitVertex<T>(out, "r", ApiType); EmitVertex<T>(out, "r", ApiType);
} }
else if (primitive_type == PRIMITIVE_POINTS) else if (primitive_type == PRIMITIVE_POINTS)
@ -249,22 +256,19 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
} }
out.Write("\t}\n"); out.Write("\t}\n");
EmitVertex<T>(out, "ll", ApiType); EmitVertex<T>(out, "ll", ApiType, true);
EmitVertex<T>(out, "lr", ApiType); EmitVertex<T>(out, "lr", ApiType);
EmitVertex<T>(out, "ul", ApiType); EmitVertex<T>(out, "ul", ApiType);
EmitVertex<T>(out, "ur", ApiType); EmitVertex<T>(out, "ur", ApiType);
} }
else else
{ {
EmitVertex<T>(out, "f", ApiType); EmitVertex<T>(out, "f", ApiType, true);
} }
out.Write("\t}\n"); out.Write("\t}\n");
if (ApiType == API_OPENGL) EndPrimitive<T>(out, ApiType);
out.Write("\tEndPrimitive();\n");
else
out.Write("\toutput.RestartStrip();\n");
if (g_ActiveConfig.iStereoMode > 0 && !g_ActiveConfig.backend_info.bSupportsGSInstancing) if (g_ActiveConfig.iStereoMode > 0 && !g_ActiveConfig.backend_info.bSupportsGSInstancing)
out.Write("\t}\n"); out.Write("\t}\n");
@ -279,8 +283,11 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
} }
template<class T> template<class T>
static inline void EmitVertex(T& out, const char* vertex, API_TYPE ApiType) static inline void EmitVertex(T& out, const char* vertex, API_TYPE ApiType, bool first_vertex)
{ {
if (g_ActiveConfig.bWireFrame && first_vertex)
out.Write("\tif (i == 0) first = %s;\n", vertex);
if (ApiType == API_OPENGL) if (ApiType == API_OPENGL)
out.Write("\tgl_Position = %s.pos;\n", vertex); out.Write("\tgl_Position = %s.pos;\n", vertex);
@ -291,6 +298,17 @@ static inline void EmitVertex(T& out, const char* vertex, API_TYPE ApiType)
else else
out.Write("\toutput.Append(ps);\n"); out.Write("\toutput.Append(ps);\n");
} }
template<class T>
static inline void EndPrimitive(T& out, API_TYPE ApiType)
{
if (g_ActiveConfig.bWireFrame)
EmitVertex<T>(out, "first", ApiType);
if (ApiType == API_OPENGL)
out.Write("\tEndPrimitive();\n");
else
out.Write("\toutput.RestartStrip();\n");
}
void GetGeometryShaderUid(GeometryShaderUid& object, u32 primitive_type, API_TYPE ApiType) void GetGeometryShaderUid(GeometryShaderUid& object, u32 primitive_type, API_TYPE ApiType)
{ {