Elevate Engine 1
Loading...
Searching...
No Matches
Elevate::Shader Class Referenceabstract

#include <Shader.h>

Inheritance diagram for Elevate::Shader:
Elevate::OpenGLShader

Public Member Functions

 ~Shader ()
 
virtual uint32_t GetID () const =0
 
virtual uint32_t GetHashCode () const =0
 
void UseLight (Light *newLightSetting, const std::string &lightName)
 
void UseDirLight (DirectionalLight *newDirLight)
 
void SetCameraPosition (const glm::vec3 cameraPosition) const
 
void SetModelMatrix (const glm::mat4 &modelMatrix)
 
void SetModelMatrix (const GameObject &object)
 
void SetProjectionViewMatrix (const glm::mat4 viewProjMatrix)
 
void SetProjectionViewMatrix (const Camera &cam)
 
virtual void SetUniform (const std::string &location, ShaderDataType type, void *value)
 UNIFORMS.
 
virtual void SetUniform1f (const std::string &location, float value) const =0
 
virtual void SetUniform2f (const std::string &location, float x, float y) const =0
 
virtual void SetUniform3f (const std::string &location, float x, float y, float z) const =0
 
virtual void SetUniform4f (const std::string &location, float x, float y, float z, float w) const =0
 
void SetUniform2f (const std::string &location, glm::vec2 value) const
 
void SetUniform3f (const std::string &location, glm::vec3 value) const
 
void SetUniform4f (const std::string &location, glm::vec4 value) const
 
virtual void SetUniform1i (const std::string &location, int value) const =0
 
virtual void SetUniform2i (const std::string &location, int x, int y) const =0
 
virtual void SetUniform3i (const std::string &location, int x, int y, int z) const =0
 
virtual void SetUniform4i (const std::string &location, int x, int y, int z, int w) const =0
 
virtual void SetUniform1fv (const std::string &location, int count, float *value) const =0
 
virtual void SetUniform2fv (const std::string &location, int count, float *value) const =0
 
virtual void SetUniform3fv (const std::string &location, int count, float *value) const =0
 
virtual void SetUniform4fv (const std::string &location, int count, float *value) const =0
 
virtual void SetUniform1iv (const std::string &location, int count, int *value) const =0
 
virtual void SetUniform2iv (const std::string &location, int count, int *value) const =0
 
virtual void SetUniform3iv (const std::string &location, int count, int *value) const =0
 
virtual void SetUniform4iv (const std::string &location, int count, int *value) const =0
 
virtual void SetUniformMatrix2fv (const std::string &location, float *data) const =0
 
void SetUniformMatrix2fv (const std::string &location, glm::mat2 data) const
 
virtual void SetUniformMatrix3fv (const std::string &location, float *data) const =0
 
void SetUniformMatrix3fv (const std::string &location, glm::mat3 data) const
 
virtual void SetUniformMatrix4fv (const std::string &location, float *data) const =0
 
void SetUniformMatrix4fv (const std::string &location, glm::mat4 data) const
 
virtual unsigned int GetRendererID () const =0
 
bool IsInitialized ()
 
const BufferLayoutGetLayout ()
 

Static Public Member Functions

static std::shared_ptr< ShaderCreateDefaultNative ()
 
static std::shared_ptr< ShaderCreateDefaultErrorNative ()
 
static std::shared_ptr< ShaderCreateDefault ()
 
static std::shared_ptr< ShaderCreateDefaultError ()
 
static std::shared_ptr< ShaderCreate (const std::string &vertexSource, const std::string &fragmentSouce)
 
static std::shared_ptr< ShaderCreateFromFiles (const std::string &vertexSrcPath, const std::string &fragSrcPath)
 
static std::shared_ptr< ShaderCreateFromFiles (const std::string &vertexSrcPath, const std::string &fragSrcPath, const std::string &customVertCode, const std::string &customFragCode)
 

Protected Member Functions

virtual BufferLayout ExtractReflectionData () const =0
 
void SetInitializationStatus (bool initialized)
 

Friends

class Renderer
 

Detailed Description

Definition at line 22 of file Shader.h.

Constructor & Destructor Documentation

◆ ~Shader()

Elevate::Shader::~Shader ( )
inline

Definition at line 25 of file Shader.h.

25{}

Member Function Documentation

◆ Create()

ShaderPtr Elevate::Shader::Create ( const std::string &  vertexSource,
const std::string &  fragmentSouce 
)
static

Definition at line 48 of file Shader.cpp.

49 {
50 std::shared_ptr<Shader> shader = nullptr;
51
52 if (!vertexSource.empty() && !fragmentSouce.empty())
53 {
54 switch (Renderer::GetAPI())
55 {
56 case RendererAPI::GraphicAPI::None: EE_CORE_ASSERT(false, "Renderer none is not supported"); break;
57 case RendererAPI::GraphicAPI::OpenGL: shader = std::make_shared<OpenGLShader>(vertexSource, fragmentSouce);
58 }
59 }
60 else
61 {
62 EE_CORE_ERROR("Error : Tried to create a shader with an empty vertex or fragment source -> Vertex : {} And Fragment : {}", vertexSource, fragmentSouce);
64 }
65
66 if (!shader->IsInitialized())
67 {
68 shader.reset(); // Free the memory of that unused shader and reset to nullptr
69 EE_CORE_ERROR("Error : Could not create a valid shader. Fallback to default shader.");
71 }
72
73 shader->m_layout = shader->ExtractReflectionData();
74
75 EE_CORE_TRACE("Shader layout has {} elements.", shader->m_layout.GetElements().size());
76 return shader;
77 }
static RendererAPI::GraphicAPI GetAPI()
Definition Renderer.h:24
static std::shared_ptr< Shader > CreateDefaultErrorNative()
Definition Shader.cpp:28

◆ CreateDefault()

std::shared_ptr< Shader > Elevate::Shader::CreateDefault ( )
static

Definition at line 38 of file Shader.cpp.

39 {
41 }
#define EE_SHADER_HEADER
Definition Core.h:32
static constexpr std::string_view GetFragmentShader()
Definition Shader.h:147
static constexpr std::string_view GetVertexShader()
Definition Shader.h:133
static std::shared_ptr< Shader > Create(const std::string &vertexSource, const std::string &fragmentSouce)
Definition Shader.cpp:48

◆ CreateDefaultError()

std::shared_ptr< Shader > Elevate::Shader::CreateDefaultError ( )
static

Definition at line 43 of file Shader.cpp.

44 {
46 }
static constexpr std::string_view GetErrorShader()
Definition Shader.h:158

◆ CreateDefaultErrorNative()

std::shared_ptr< Shader > Elevate::Shader::CreateDefaultErrorNative ( )
static

Definition at line 28 of file Shader.cpp.

29 {
30 switch (Renderer::GetAPI())
31 {
32 case RendererAPI::GraphicAPI::None: EE_CORE_ASSERT(false, "Renderer none is not supported");
33 case RendererAPI::GraphicAPI::OpenGL: return std::make_shared<OpenGLShader>(EE_SHADER_HEADER + std::string(DefaultShader::GetVertexShader()), EE_SHADER_HEADER + std::string(DefaultShader::GetErrorShader()));
34 }
35 return nullptr;
36 }

◆ CreateDefaultNative()

std::shared_ptr< Shader > Elevate::Shader::CreateDefaultNative ( )
static

Definition at line 18 of file Shader.cpp.

19 {
20 switch (Renderer::GetAPI())
21 {
22 case RendererAPI::GraphicAPI::None: EE_CORE_ASSERT(false, "Renderer none is not supported");
23 case RendererAPI::GraphicAPI::OpenGL: return std::make_shared<OpenGLShader>(EE_SHADER_HEADER + std::string(DefaultShader::GetVertexShader()), EE_SHADER_HEADER + std::string(DefaultShader::GetFragmentShader()));
24 }
25 return nullptr;
26 }

◆ CreateFromFiles() [1/2]

ShaderPtr Elevate::Shader::CreateFromFiles ( const std::string &  vertexSrcPath,
const std::string &  fragSrcPath 
)
static

Definition at line 79 of file Shader.cpp.

80 {
81 std::string vertexSource = File::GetFileContent(vertexSrcPath);
82 std::string fragmentSource = File::GetFileContent(fragSrcPath);
83 return Create(vertexSource, fragmentSource);
84 }
std::string GetFileContent(std::string path)

◆ CreateFromFiles() [2/2]

ShaderPtr Elevate::Shader::CreateFromFiles ( const std::string &  vertexSrcPath,
const std::string &  fragSrcPath,
const std::string &  customVertCode,
const std::string &  customFragCode 
)
static

Definition at line 86 of file Shader.cpp.

87 {
88 std::string vertexContent = File::GetFileContent(vertexSrcPath);
89 std::string fragmentContent = File::GetFileContent(fragSrcPath);
90
91 if (!vertexContent.empty() && !fragmentContent.empty())
92 {
93 std::string vertexSource = customVertCode + "\n" + vertexContent;
94 std::string fragmentSource = customFragCode + "\n" + fragmentContent;
95 return Create(vertexSource, fragmentSource);
96 }
97 else
98 {
99 EE_CORE_ERROR("Error : Tried to create a shader with an empty vertex or fragment source -> Vertex : {} And Fragment : {}", vertexContent, fragmentContent);
100 return CreateDefaultError();
101 }
102 }
static std::shared_ptr< Shader > CreateDefaultError()
Definition Shader.cpp:43

◆ ExtractReflectionData()

virtual BufferLayout Elevate::Shader::ExtractReflectionData ( ) const
protectedpure virtual

Implemented in Elevate::OpenGLShader.

◆ GetHashCode()

virtual uint32_t Elevate::Shader::GetHashCode ( ) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ GetID()

virtual uint32_t Elevate::Shader::GetID ( ) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ GetLayout()

const BufferLayout & Elevate::Shader::GetLayout ( )
inline

Definition at line 111 of file Shader.h.

111{ return m_layout; }

◆ GetRendererID()

virtual unsigned int Elevate::Shader::GetRendererID ( ) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ IsInitialized()

bool Elevate::Shader::IsInitialized ( )
inline

Definition at line 109 of file Shader.h.

109{ return m_isInitialized; }

◆ SetCameraPosition()

void Elevate::Shader::SetCameraPosition ( const glm::vec3  cameraPosition) const

Definition at line 118 of file Shader.cpp.

119 {
120 SetUniform3f(EE_SHADER_CAMPOS, cameraPosition);
121 }
#define EE_SHADER_CAMPOS
Definition Shader.h:13
virtual void SetUniform3f(const std::string &location, float x, float y, float z) const =0

◆ SetInitializationStatus()

void Elevate::Shader::SetInitializationStatus ( bool  initialized)
inlineprotected

Definition at line 115 of file Shader.h.

115{ m_isInitialized = initialized; }

◆ SetModelMatrix() [1/2]

void Elevate::Shader::SetModelMatrix ( const GameObject object)

Definition at line 128 of file Shader.cpp.

129 {
130 SetUniformMatrix4fv(EE_SHADER_MODEL, object.GetModelMatrix()); // set the model matrix
131 }
#define EE_SHADER_MODEL
Definition Shader.h:11
virtual void SetUniformMatrix4fv(const std::string &location, float *data) const =0

◆ SetModelMatrix() [2/2]

void Elevate::Shader::SetModelMatrix ( const glm::mat4 &  modelMatrix)

Definition at line 123 of file Shader.cpp.

124 {
125 SetUniformMatrix4fv(EE_SHADER_MODEL, modelMatrix); // set the model matrix
126 }

◆ SetProjectionViewMatrix() [1/2]

void Elevate::Shader::SetProjectionViewMatrix ( const Camera cam)

Definition at line 138 of file Shader.cpp.

139 {
140 SetUniformMatrix4fv(EE_SHADER_VIEWPROJ, cam.GenViewProjectionMatrix());
141 }
#define EE_SHADER_VIEWPROJ
Definition Shader.h:12

◆ SetProjectionViewMatrix() [2/2]

void Elevate::Shader::SetProjectionViewMatrix ( const glm::mat4  viewProjMatrix)

Definition at line 133 of file Shader.cpp.

134 {
136 }

◆ SetUniform()

void Elevate::Shader::SetUniform ( const std::string &  location,
ShaderDataType  type,
void *  value 
)
virtual

UNIFORMS.

Sets any uniform of any type. Dispatchs the uniform using the right setter function.

Parameters
locationThe name of the uniform.
valueThe pointer to the data.

Definition at line 158 of file Shader.cpp.

159 {
160 switch (type)
161 {
162 // todo impl all of the types here based on the functions we have in the shader part
163 // todo remove the need to cast to float* and directly use the SetUniform2fv functions (create them if necessary)
164 case ShaderDataType::Float: SetUniform1f(location, *(float*)value); break;
166 {
167 float* data = (float*)value;
168 SetUniform2f(location, data[0], data[1]);
169 break;
170 }
172 {
173 float* data = (float*)value;
174 SetUniform3f(location, data[0], data[1], data[2]);
175 break;
176 }
178 {
179 float* data = (float*)value;
180 SetUniform4f(location, data[0], data[1], data[2], data[3]);
181 break;
182 }
184 SetUniform1i(location, *(int*)value);
185 break;
187 SetUniformMatrix4fv(location, (float*) value);
188 break;
189 default:
190 EE_CORE_ASSERT(false, "(Shader::SetUniform()) : Unsupported datatype provided.");
191 break;
192 }
193 }
virtual void SetUniform4f(const std::string &location, float x, float y, float z, float w) const =0
virtual void SetUniform1i(const std::string &location, int value) const =0
virtual void SetUniform1f(const std::string &location, float value) const =0
virtual void SetUniform2f(const std::string &location, float x, float y) const =0

◆ SetUniform1f()

virtual void Elevate::Shader::SetUniform1f ( const std::string &  location,
float  value 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform1fv()

virtual void Elevate::Shader::SetUniform1fv ( const std::string &  location,
int  count,
float *  value 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform1i()

virtual void Elevate::Shader::SetUniform1i ( const std::string &  location,
int  value 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform1iv()

virtual void Elevate::Shader::SetUniform1iv ( const std::string &  location,
int  count,
int *  value 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform2f() [1/2]

virtual void Elevate::Shader::SetUniform2f ( const std::string &  location,
float  x,
float  y 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform2f() [2/2]

void Elevate::Shader::SetUniform2f ( const std::string &  location,
glm::vec2  value 
) const
inline

Definition at line 67 of file Shader.h.

68 {
69 SetUniform2f(location, value.x, value.y);
70 }

◆ SetUniform2fv()

virtual void Elevate::Shader::SetUniform2fv ( const std::string &  location,
int  count,
float *  value 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform2i()

virtual void Elevate::Shader::SetUniform2i ( const std::string &  location,
int  x,
int  y 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform2iv()

virtual void Elevate::Shader::SetUniform2iv ( const std::string &  location,
int  count,
int *  value 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform3f() [1/2]

virtual void Elevate::Shader::SetUniform3f ( const std::string &  location,
float  x,
float  y,
float  z 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform3f() [2/2]

void Elevate::Shader::SetUniform3f ( const std::string &  location,
glm::vec3  value 
) const
inline

Definition at line 71 of file Shader.h.

72 {
73 SetUniform3f(location, value.x, value.y, value.z);
74 }

◆ SetUniform3fv()

virtual void Elevate::Shader::SetUniform3fv ( const std::string &  location,
int  count,
float *  value 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform3i()

virtual void Elevate::Shader::SetUniform3i ( const std::string &  location,
int  x,
int  y,
int  z 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform3iv()

virtual void Elevate::Shader::SetUniform3iv ( const std::string &  location,
int  count,
int *  value 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform4f() [1/2]

virtual void Elevate::Shader::SetUniform4f ( const std::string &  location,
float  x,
float  y,
float  z,
float  w 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform4f() [2/2]

void Elevate::Shader::SetUniform4f ( const std::string &  location,
glm::vec4  value 
) const
inline

Definition at line 75 of file Shader.h.

76 {
77 SetUniform4f(location, value.x, value.y, value.z, value.w);
78 }

◆ SetUniform4fv()

virtual void Elevate::Shader::SetUniform4fv ( const std::string &  location,
int  count,
float *  value 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform4i()

virtual void Elevate::Shader::SetUniform4i ( const std::string &  location,
int  x,
int  y,
int  z,
int  w 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniform4iv()

virtual void Elevate::Shader::SetUniform4iv ( const std::string &  location,
int  count,
int *  value 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniformMatrix2fv() [1/2]

virtual void Elevate::Shader::SetUniformMatrix2fv ( const std::string &  location,
float *  data 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniformMatrix2fv() [2/2]

void Elevate::Shader::SetUniformMatrix2fv ( const std::string &  location,
glm::mat2  data 
) const

Definition at line 143 of file Shader.cpp.

144 {
145 SetUniformMatrix2fv(location, glm::value_ptr(data));
146 }
virtual void SetUniformMatrix2fv(const std::string &location, float *data) const =0

◆ SetUniformMatrix3fv() [1/2]

virtual void Elevate::Shader::SetUniformMatrix3fv ( const std::string &  location,
float *  data 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniformMatrix3fv() [2/2]

void Elevate::Shader::SetUniformMatrix3fv ( const std::string &  location,
glm::mat3  data 
) const

Definition at line 148 of file Shader.cpp.

149 {
150 SetUniformMatrix3fv(location, glm::value_ptr(data));
151 }
virtual void SetUniformMatrix3fv(const std::string &location, float *data) const =0

◆ SetUniformMatrix4fv() [1/2]

virtual void Elevate::Shader::SetUniformMatrix4fv ( const std::string &  location,
float *  data 
) const
pure virtual

Implemented in Elevate::OpenGLShader.

◆ SetUniformMatrix4fv() [2/2]

void Elevate::Shader::SetUniformMatrix4fv ( const std::string &  location,
glm::mat4  data 
) const

Definition at line 153 of file Shader.cpp.

154 {
155 SetUniformMatrix4fv(location, glm::value_ptr(data));
156 }

◆ UseDirLight()

void Elevate::Shader::UseDirLight ( DirectionalLight newDirLight)

Definition at line 112 of file Shader.cpp.

113 {
114 UseLight(newDirLight, "dirLight");
115 SetUniform3f("dirLight.direction", newDirLight->CalculateDirection());
116 }
void UseLight(Light *newLightSetting, const std::string &lightName)
Definition Shader.cpp:104

◆ UseLight()

void Elevate::Shader::UseLight ( Light newLightSetting,
const std::string &  lightName 
)

Definition at line 104 of file Shader.cpp.

105 {
106 SetUniform3f(lightName + ".ambient", newLightSetting->GetAmbientColor());
107 SetUniform3f(lightName + ".diffuse", newLightSetting->GetDiffuseColor());
108 SetUniform3f(lightName + ".specular", newLightSetting->GetSpecularColor());
109 SetUniform1f(lightName + ".intensity", newLightSetting->GetIntensity());
110 }

Friends And Related Symbol Documentation

◆ Renderer

friend class Renderer
friend

Definition at line 125 of file Shader.h.


The documentation for this class was generated from the following files: