ShaderGen: More interface cleanups. Less wtfs :)
This commit is contained in:
parent
e31c2aa601
commit
2afd892e46
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue