Skip to content

Commit

Permalink
GeometryShaderGen: Re-emit the first vertex when wireframe mode is en…
Browse files Browse the repository at this point in the history
…abled.
  • Loading branch information
CrossVR committed Dec 19, 2014
1 parent 1b9fe70 commit 410e333
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions Source/Core/VideoCommon/GeometryShaderGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "VideoCommon/VideoConfig.h"

static char text[16384];
static bool s_first_vertex = true;

static const char* primitives_ogl[] =
{
Expand All @@ -27,6 +28,7 @@ static const char* primitives_d3d[] =
};

template<class T> static inline void EmitVertex(T& out, const char* vertex, API_TYPE ApiType);
template<class T> static inline void EndPrimitive(T& out, API_TYPE ApiType);

template<class T>
static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE ApiType)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<T>(out, ApiType);

if (g_ActiveConfig.iStereoMode > 0 && !g_ActiveConfig.backend_info.bSupportsGSInstancing)
out.Write("\t}\n");
Expand All @@ -281,6 +286,11 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
template<class T>
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);

Expand All @@ -291,6 +301,19 @@ static inline void EmitVertex(T& out, const char* vertex, API_TYPE ApiType)
else
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);

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)
{
Expand Down

0 comments on commit 410e333

Please sign in to comment.