This commit is contained in:
2026-11-02 19:35:36 -05:00
parent a6103e453d
commit 7b32ad674e
52 changed files with 3285 additions and 1488 deletions
+27 -12
View File
@@ -6,6 +6,7 @@
#include<glm/glm.hpp>
#include<string>
#include<unordered_map>
#include<fstream>
#include <sstream>
#include <iostream>
@@ -19,35 +20,49 @@ public:
Shader(const char* vertexFile, const char* fragFile);
void Set1F(const char* uniform, float value) {
GLint location = glGetUniformLocation(Shader::ID, uniform);
glUniform1f(location, value);
glUniform1f(GetLocation(uniform), value);
};
void Set2F(const char* uniform, glm::vec2 value) {
GLint location = glGetUniformLocation(Shader::ID, uniform);
glUniform2f(location, value.x,value.y);
glUniform2f(GetLocation(uniform), value.x,value.y);
};
void Set3F(const char* uniform, glm::vec3 value) {
GLint location = glGetUniformLocation(Shader::ID, uniform);
glUniform3f(location, value.x,value.y,value.z);
glUniform3f(GetLocation(uniform), value.x,value.y,value.z);
};
void Set4F(const char* uniform, glm::vec4 value) {
GLint location = glGetUniformLocation(Shader::ID, uniform);
glUniform4f(location, value.x, value.y, value.z, value.w);
glUniform4f(GetLocation(uniform), value.x, value.y, value.z, value.w);
};
void SetMat4(const char* uniform, glm::mat4 value) {
GLint location = glGetUniformLocation(Shader::ID, uniform);
glUniformMatrix4fv(location,1,GL_FALSE,&value[0][0]);
glUniformMatrix4fv(GetLocation(uniform),1,GL_FALSE,&value[0][0]);
};
// Uploads a whole uniform array in one call
void SetMat4Array(const char* uniform, const glm::mat4* values, int count) {
glUniformMatrix4fv(GetLocation(uniform),count,GL_FALSE,&values[0][0][0]);
};
void SetInt(const char* uniform, GLuint value) {
GLint location = glGetUniformLocation(Shader::ID, uniform);
glUniform1i(location, value);
glUniform1i(GetLocation(uniform), value);
};
void Activate();
void Delete();
private:
// Asking the driver is slow and locations never change once linked.
// Uniforms the shader doesn't have cache as -1, which glUniform ignores.
GLint GetLocation(const char* uniform) {
auto existing = uniformLocations.find(uniform);
if (existing != uniformLocations.end())
return existing->second;
GLint location = glGetUniformLocation(ID, uniform);
uniformLocations.emplace(uniform, location);
return location;
}
std::unordered_map<std::string, GLint> uniformLocations;
};
#endif