ShaderGen: More interface cleanups. Less wtfs :)

This commit is contained in:
NeoBrainX 2013-03-29 22:24:49 +01:00
parent e31c2aa601
commit 2afd892e46
8 changed files with 23 additions and 25 deletions

View File

@ -274,7 +274,8 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
// Non-uid template parameters will write to the dummy data (=> gets optimized out) // Non-uid template parameters will write to the dummy data (=> gets optimized out)
pixel_shader_uid_data dummy_data; pixel_shader_uid_data dummy_data;
pixel_shader_uid_data& uid_data = (&out.GetUidData() != NULL) ? out.GetUidData() : dummy_data; pixel_shader_uid_data& uid_data = (&out.template GetUidData<pixel_shader_uid_data>() != NULL)
? out.template GetUidData<pixel_shader_uid_data>() : dummy_data;
out.SetBuffer(text); out.SetBuffer(text);
if (out.GetBuffer() != NULL) if (out.GetBuffer() != NULL)

View File

@ -190,8 +190,8 @@ struct pixel_shader_uid_data
}; };
typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid; typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid;
typedef ShaderCode<pixel_shader_uid_data> PixelShaderCode; typedef ShaderCode PixelShaderCode; // TODO: Obsolete
typedef ShaderConstantProfile<pixel_shader_uid_data> PixelShaderConstantProfile; typedef ShaderConstantProfile PixelShaderConstantProfile; // TODO: Obsolete
void GeneratePixelShaderCode(PixelShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components); void GeneratePixelShaderCode(PixelShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components);

View File

@ -25,7 +25,6 @@
#include <vector> #include <vector>
template<class uid_data>
class ShaderGeneratorInterface class ShaderGeneratorInterface
{ {
public: public:
@ -33,11 +32,13 @@ public:
const char* GetBuffer() { return NULL; } const char* GetBuffer() { return NULL; }
void SetBuffer(char* buffer) { } void SetBuffer(char* buffer) { }
inline void SetConstantsUsed(unsigned int first_index, unsigned int last_index) {} inline void SetConstantsUsed(unsigned int first_index, unsigned int last_index) {}
uid_data& GetUidData() { return *(uid_data*)NULL; } // TODO: can be moved out, just make this GetUidData<T> instead
template<class uid_data>
uid_data& GetUidData() { return *(uid_data*)NULL; }
}; };
template<class uid_data> template<class uid_data>
class ShaderUid : public ShaderGeneratorInterface<uid_data> class ShaderUid : public ShaderGeneratorInterface
{ {
public: public:
ShaderUid() ShaderUid()
@ -69,7 +70,8 @@ public:
return false; return false;
} }
inline uid_data& GetUidData() { return data; } template<class T>
inline T& GetUidData() override { return data; }
private: private:
union union
@ -79,9 +81,7 @@ private:
}; };
}; };
// Needs to be a template for hacks... class ShaderCode : public ShaderGeneratorInterface
template<class uid_data>
class ShaderCode : public ShaderGeneratorInterface<uid_data>
{ {
public: public:
ShaderCode() : buf(NULL), write_ptr(NULL) ShaderCode() : buf(NULL), write_ptr(NULL)
@ -105,15 +105,11 @@ private:
char* write_ptr; char* write_ptr;
}; };
template<class uid_data> class ShaderConstantProfile : public ShaderGeneratorInterface
class ShaderConstantProfile : public ShaderGeneratorInterface<uid_data>
{ {
public: public:
ShaderConstantProfile(int num_constants) { constant_usage.resize(num_constants); } ShaderConstantProfile(int num_constants) { constant_usage.resize(num_constants); }
// has room for optimization (if it matters at all...)
void NumConstants() { return constant_usage.size(); }
inline void SetConstantsUsed(unsigned int first_index, unsigned int last_index) inline void SetConstantsUsed(unsigned int first_index, unsigned int last_index)
{ {
for (unsigned int i = first_index; i < last_index+1; ++i) for (unsigned int i = first_index; i < last_index+1; ++i)

View File

@ -85,7 +85,8 @@ void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
{ {
// Non-uid template parameters will write to the dummy data (=> gets optimized out) // Non-uid template parameters will write to the dummy data (=> gets optimized out)
vertex_shader_uid_data dummy_data; vertex_shader_uid_data dummy_data;
vertex_shader_uid_data& uid_data = (&out.GetUidData() != NULL) ? out.GetUidData() : dummy_data; vertex_shader_uid_data& uid_data = (&out.template GetUidData<vertex_shader_uid_data>() != NULL)
? out.template GetUidData<vertex_shader_uid_data>() : dummy_data;
out.SetBuffer(text); out.SetBuffer(text);
if (out.GetBuffer() != NULL) if (out.GetBuffer() != NULL)
@ -535,7 +536,7 @@ void GenerateVertexShaderCode(VertexShaderCode& object, u32 components, API_TYPE
GenerateVertexShader<VertexShaderCode>(object, components, api_type); GenerateVertexShader<VertexShaderCode>(object, components, api_type);
} }
void GenerateVSOutputStructForGS(ShaderCode<u32>& object, u32 components, API_TYPE api_type) void GenerateVSOutputStructForGS(ShaderCode& object, u32 components, API_TYPE api_type)
{ {
GenerateVSOutputStruct<ShaderCode<u32> >(object, components, api_type); GenerateVSOutputStruct<ShaderCode>(object, components, api_type);
} }

View File

@ -110,10 +110,10 @@ struct vertex_shader_uid_data
}; };
typedef ShaderUid<vertex_shader_uid_data> VertexShaderUid; typedef ShaderUid<vertex_shader_uid_data> VertexShaderUid;
typedef ShaderCode<vertex_shader_uid_data> VertexShaderCode; typedef ShaderCode VertexShaderCode; // TODO: Obsolete..
void GetVertexShaderUid(VertexShaderUid& object, u32 components, API_TYPE api_type); void GetVertexShaderUid(VertexShaderUid& object, u32 components, API_TYPE api_type);
void GenerateVertexShaderCode(VertexShaderCode& object, u32 components, API_TYPE api_type); void GenerateVertexShaderCode(VertexShaderCode& object, u32 components, API_TYPE api_type);
void GenerateVSOutputStructForGS(ShaderCode<u32>& object, u32 components, API_TYPE api_type); void GenerateVSOutputStructForGS(ShaderCode& object, u32 components, API_TYPE api_type);
#endif // GCOGL_VERTEXSHADER_H #endif // GCOGL_VERTEXSHADER_H

View File

@ -183,7 +183,7 @@ bool LineGeometryShader::SetShader(u32 components, float lineWidth,
{ {
// Generate new shader. Warning: not thread-safe. // Generate new shader. Warning: not thread-safe.
static char buffer[16384]; static char buffer[16384];
ShaderCode<u32> code; ShaderCode code;
code.SetBuffer(buffer); code.SetBuffer(buffer);
GenerateVSOutputStructForGS(code, components, API_D3D11); GenerateVSOutputStructForGS(code, components, API_D3D11);
code.Write("\n%s", LINE_GS_COMMON); code.Write("\n%s", LINE_GS_COMMON);

View File

@ -177,7 +177,7 @@ bool PointGeometryShader::SetShader(u32 components, float pointSize,
{ {
// Generate new shader. Warning: not thread-safe. // Generate new shader. Warning: not thread-safe.
static char buffer[16384]; static char buffer[16384];
ShaderCode<u32> code; ShaderCode code;
code.SetBuffer(buffer); code.SetBuffer(buffer);
GenerateVSOutputStructForGS(code, components, API_D3D11); GenerateVSOutputStructForGS(code, components, API_D3D11);
code.Write("\n%s", POINT_GS_COMMON); code.Write("\n%s", POINT_GS_COMMON);

View File

@ -360,9 +360,9 @@ template<class UidT> UidT GetPartialUid(const SHADERUID& uid);
template<> PixelShaderUid GetPartialUid(const SHADERUID& uid) { return uid.puid; } template<> PixelShaderUid GetPartialUid(const SHADERUID& uid) { return uid.puid; }
template<> VertexShaderUid GetPartialUid(const SHADERUID& uid) { return uid.vuid; } template<> VertexShaderUid GetPartialUid(const SHADERUID& uid) { return uid.vuid; }
template<class CodeT> const std::string& GetShaderCode(const SHADER& shader); template<class UidT> const std::string& GetShaderCode(const SHADER& shader);
template<> const std::string& GetShaderCode<PixelShaderCode>(const SHADER& shader) { return shader.strpprog; } template<> const std::string& GetShaderCode<PixelShaderUid>(const SHADER& shader) { return shader.strpprog; }
template<> const std::string& GetShaderCode<VertexShaderCode>(const SHADER& shader) { return shader.strvprog; } template<> const std::string& GetShaderCode<VertexShaderUid>(const SHADER& shader) { return shader.strvprog; }
template<class UidT, class CodeT> template<class UidT, class CodeT>
void CheckForUidMismatch(const ProgramShaderCache::PCache& cache, CodeT& new_code, const UidT& new_uid) void CheckForUidMismatch(const ProgramShaderCache::PCache& cache, CodeT& new_code, const UidT& new_uid)