20 explicit ShaderProgram(std::vector<ShaderSource> shaderList = {});
61 std::vector<ShaderSource> shaderSources;
63 GLuint current2DTextureUnit = 0;
64 GLuint currentCubeTextureUnit = 0;
76 glUseProgram(programId);
78 current2DTextureUnit = 0;
79 currentCubeTextureUnit = 0;
83 glActiveTexture(GL_TEXTURE0 + current2DTextureUnit);
84 glBindTexture(GL_TEXTURE_2D, textureHandle);
85 glUniform1i(glGetUniformLocation(programId, uniformName), current2DTextureUnit);
86 current2DTextureUnit++;
90 glActiveTexture(GL_TEXTURE0 + currentCubeTextureUnit);
91 glBindTexture(GL_TEXTURE_CUBE_MAP, textureHandle);
92 glUniform1i(glGetUniformLocation(programId, uniformName), currentCubeTextureUnit);
93 currentCubeTextureUnit++;
97 for (GLuint i = 0; i < current2DTextureUnit; i++) {
98 glActiveTexture(GL_TEXTURE0 + i);
99 glBindTexture(GL_TEXTURE_2D, 0);
100 current2DTextureUnit--;
102 for (GLuint i = 0; i < currentCubeTextureUnit; i++) {
103 glActiveTexture(GL_TEXTURE0 + i);
104 glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
105 currentCubeTextureUnit--;
110 for (GLuint i = 0; i < numTextures; i++) {
111 glActiveTexture(GL_TEXTURE0 + current2DTextureUnit - 1);
112 glBindTexture(GL_TEXTURE_2D, 0);
113 current2DTextureUnit--;
118 for (GLuint i = 0; i < numTextures; i++) {
119 glActiveTexture(GL_TEXTURE0 + currentCubeTextureUnit - 1);
120 glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
121 currentCubeTextureUnit--;
A linked OpenGL program.
Definition shaderProgram.h:16
~ShaderProgram()
Destroy the program.
Definition shaderProgram.cpp:102
void setCubeTextureUniform(const char *uniformName, const GLuint textureHandle)
Definition shaderProgram.h:89
void set2DTextureUniform(const char *uniformName, const GLuint textureHandle)
Definition shaderProgram.h:82
void unbindCubeTextures(int numTextures)
Definition shaderProgram.h:117
GLuint getProgramId() const
Definition shaderProgram.h:71
void unbindAllTextures()
Unbind all textures currently bound to the program.
Definition shaderProgram.h:96
void useProgram()
Set as the current program to use.
Definition shaderProgram.h:75
void reloadShaders()
Reload the shaders in the program. Can be used to reload shaders during execution.
Definition shaderProgram.cpp:49
void unbind2DTextures(int numTextures)
Definition shaderProgram.h:109
ShaderProgram(std::vector< ShaderSource > shaderList={})
Definition shaderProgram.cpp:39
Struct to store the path to a shader source file.
Definition shaderProgram.h:10
std::string sourcePath
The path to the shader source.
Definition shaderProgram.h:12
GLenum type
The shader type (vertex, fragment, etc)
Definition shaderProgram.h:11