diff options
| author | NeoBrainX <NeoBrainX@gmail.com> | 2013-03-29 22:24:49 +0100 |
|---|---|---|
| committer | NeoBrainX <NeoBrainX@gmail.com> | 2013-03-29 22:24:49 +0100 |
| commit | 2afd892e466e656a2dc623bb5d6574d0d6c5533a (patch) | |
| tree | 1e52ce37458c4072bdbf043e539f0a1858b3fb57 /Source | |
| parent | e31c2aa6013d6a95358251610c15820a34e65a35 (diff) | |
ShaderGen: More interface cleanups. Less wtfs :)
Diffstat (limited to 'Source')
8 files changed, 23 insertions, 25 deletions
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index d9d45902fe..e534e2a6ca 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -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) 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); if (out.GetBuffer() != NULL) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index 4f9cba0c37..4881999206 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -190,8 +190,8 @@ struct pixel_shader_uid_data }; typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid; -typedef ShaderCode<pixel_shader_uid_data> PixelShaderCode; -typedef ShaderConstantProfile<pixel_shader_uid_data> PixelShaderConstantProfile; +typedef ShaderCode PixelShaderCode; // TODO: Obsolete +typedef ShaderConstantProfile PixelShaderConstantProfile; // TODO: Obsolete void GeneratePixelShaderCode(PixelShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components); diff --git a/Source/Core/VideoCommon/Src/ShaderGenCommon.h b/Source/Core/VideoCommon/Src/ShaderGenCommon.h index a2616e0a6c..a904a8e635 100644 --- a/Source/Core/VideoCommon/Src/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/Src/ShaderGenCommon.h @@ -25,7 +25,6 @@ #include <vector> -template<class uid_data> class ShaderGeneratorInterface { public: @@ -33,11 +32,13 @@ public: const char* GetBuffer() { return NULL; } void SetBuffer(char* buffer) { } 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> -class ShaderUid : public ShaderGeneratorInterface<uid_data> +class ShaderUid : public ShaderGeneratorInterface { public: ShaderUid() @@ -69,7 +70,8 @@ public: return false; } - inline uid_data& GetUidData() { return data; } + template<class T> + inline T& GetUidData() override { return data; } private: union @@ -79,9 +81,7 @@ private: }; }; -// Needs to be a template for hacks... -template<class uid_data> -class ShaderCode : public ShaderGeneratorInterface<uid_data> +class ShaderCode : public ShaderGeneratorInterface { public: ShaderCode() : buf(NULL), write_ptr(NULL) @@ -105,15 +105,11 @@ private: char* write_ptr; }; -template<class uid_data> -class ShaderConstantProfile : public ShaderGeneratorInterface<uid_data> +class ShaderConstantProfile : public ShaderGeneratorInterface { public: 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) { for (unsigned int i = first_index; i < last_index+1; ++i) diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 5ed1a73569..e27ced7b39 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -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) 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); if (out.GetBuffer() != NULL) @@ -535,7 +536,7 @@ void GenerateVertexShaderCode(VertexShaderCode& object, u32 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); } diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h index b6b176c806..33d27ecdf0 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.h +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h @@ -110,10 +110,10 @@ struct vertex_shader_uid_data }; 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 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 diff --git a/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp b/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp index f22ebef0df..5d6b8eb5b5 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp @@ -183,7 +183,7 @@ bool LineGeometryShader::SetShader(u32 components, float lineWidth, { // Generate new shader. Warning: not thread-safe. static char buffer[16384]; - ShaderCode<u32> code; + ShaderCode code; code.SetBuffer(buffer); GenerateVSOutputStructForGS(code, components, API_D3D11); code.Write("\n%s", LINE_GS_COMMON); diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp b/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp index 5976c09ab9..8f5300ff64 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp @@ -177,7 +177,7 @@ bool PointGeometryShader::SetShader(u32 components, float pointSize, { // Generate new shader. Warning: not thread-safe. static char buffer[16384]; - ShaderCode<u32> code; + ShaderCode code; code.SetBuffer(buffer); GenerateVSOutputStructForGS(code, components, API_D3D11); code.Write("\n%s", POINT_GS_COMMON); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index 188145ebcf..81621d2d38 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -360,9 +360,9 @@ template<class UidT> UidT GetPartialUid(const SHADERUID& uid); template<> PixelShaderUid GetPartialUid(const SHADERUID& uid) { return uid.puid; } template<> VertexShaderUid GetPartialUid(const SHADERUID& uid) { return uid.vuid; } -template<class CodeT> const std::string& GetShaderCode(const SHADER& shader); -template<> const std::string& GetShaderCode<PixelShaderCode>(const SHADER& shader) { return shader.strpprog; } -template<> const std::string& GetShaderCode<VertexShaderCode>(const SHADER& shader) { return shader.strvprog; } +template<class UidT> const std::string& GetShaderCode(const SHADER& shader); +template<> const std::string& GetShaderCode<PixelShaderUid>(const SHADER& shader) { return shader.strpprog; } +template<> const std::string& GetShaderCode<VertexShaderUid>(const SHADER& shader) { return shader.strvprog; } template<class UidT, class CodeT> void CheckForUidMismatch(const ProgramShaderCache::PCache& cache, CodeT& new_code, const UidT& new_uid) |
