Class Shader

Inheritance Relationships

Derived Types

Class Documentation

class Shader

Base class for handling OpenGL shader objects.

This class encapsulates the creation, management, and destruction of an OpenGL shader. It is intended to be used as a base class for specific shader types (e.g., vertex, fragment).

Note

Copy construction and assignment are disabled to prevent multiple ownership of the shader resource.

Param type:

The type of the shader (e.g., GL_VERTEX_SHADER, GL_FRAGMENT_SHADER).

Param path:

The file path to the shader source code.

Subclassed by FragmentShader, VertexShader

Public Functions

inline Shader(GLenum type)

Constructs a Shader object by loading and compiling a shader from a file.

This constructor reads the shader source code from the specified file path, creates an OpenGL shader object of the given type, sets the shader source, and compiles it. If the file cannot be opened or the shader fails to compile, a std::runtime_error is thrown with an appropriate error message.

Parameters:
  • type – The type of shader to create (e.g., GL_VERTEX_SHADER, GL_FRAGMENT_SHADER).

  • path – The file path to the shader source code.

Throws:

std::runtime_error – If the shader file cannot be opened or compilation fails.

Shader(const Shader&) = delete
Shader &operator=(const Shader&) = delete
~Shader()
bool Init(const std::string &path)
inline virtual GLuint Get() const

Protected Attributes

GLenum _type = 0
GLuint _shader = 0