Claire's Game Engine
Full C++ Engine using OpenGL
Loading...
Searching...
No Matches
Shader Class Reference

Shader is a class representing a shader in OpenGL. It handles the creation, loading, and compilation of shaders from files, including vertex, fragment, tessellation control, tessellation evaluation, and geometry shaders. It provides functionality to retrieve the shader ID and its source code. More...

#include <Shader.h>

Public Member Functions

 Shader ()
 Default constructor for Shader. Initializes shader ID to 0, shader code to an empty string, and type to VERTEX.
 
 Shader (int pId, std::string pFile, ShaderType pShaderType)
 Constructor for Shader with provided ID, file name, and shader type.
 
 ~Shader ()
 Destructor for Shader. Cleans up any allocated resources.
 
int GetID () const
 Gets the shader ID.
 
ShaderType GetType () const
 Gets the shader type.
 
void Load (std::string pFileName, ShaderType pShaderType)
 Loads the shader code from the specified file and sets the shader type.
 
std::string & GetCode ()
 Gets the shader code. (contents of the text file)
 

Static Public Attributes

static const std::string SHADER_PATH = "Resources/Shaders/"
 The path to the shader files. Feel free to adjust if needed.
 

Protected Attributes

unsigned int mId
 The OpenGL shader ID.
 
std::string mCode
 The source code of the shader.
 
ShaderType mType
 The type of the shader (vertex, fragment, etc.).
 

Detailed Description

Shader is a class representing a shader in OpenGL. It handles the creation, loading, and compilation of shaders from files, including vertex, fragment, tessellation control, tessellation evaluation, and geometry shaders. It provides functionality to retrieve the shader ID and its source code.

Constructor & Destructor Documentation

◆ Shader() [1/2]

Shader::Shader ( )

Default constructor for Shader. Initializes shader ID to 0, shader code to an empty string, and type to VERTEX.

◆ Shader() [2/2]

Shader::Shader ( int pId,
std::string pFile,
ShaderType pShaderType )

Constructor for Shader with provided ID, file name, and shader type.

Parameters
pIdThe ID of the shader.
pFileThe source code of the shader in string format.
pShaderTypeThe type of the shader (e.g., vertex, fragment).

◆ ~Shader()

Shader::~Shader ( )
inline

Destructor for Shader. Cleans up any allocated resources.

Member Function Documentation

◆ GetCode()

std::string & Shader::GetCode ( )

Gets the shader code. (contents of the text file)

Returns
A reference to the shader source code.

◆ GetID()

int Shader::GetID ( ) const

Gets the shader ID.

Returns
The ID of the shader.

◆ GetType()

ShaderType Shader::GetType ( ) const

Gets the shader type.

Returns
The type of the shader.

◆ Load()

void Shader::Load ( std::string pFileName,
ShaderType pShaderType )

Loads the shader code from the specified file and sets the shader type.

Parameters
pFileNameThe name of the shader file to load.
pShaderTypeThe type of the shader (e.g., vertex, fragment).

Member Data Documentation

◆ mCode

std::string Shader::mCode
protected

The source code of the shader.

◆ mId

unsigned int Shader::mId
protected

The OpenGL shader ID.

◆ mType

ShaderType Shader::mType
protected

The type of the shader (vertex, fragment, etc.).

◆ SHADER_PATH

const std::string Shader::SHADER_PATH = "Resources/Shaders/"
static

The path to the shader files. Feel free to adjust if needed.


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