Added the ability to use renderdoc and warn when uniforms unavailable

This commit is contained in:
Warwick 2022-07-20 16:26:40 +01:00
parent 1e5544ce1f
commit 40f12dd510
5 changed files with 40 additions and 17 deletions

View file

@ -122,6 +122,7 @@ void main()
color = pow(color, vec3(1.0/2.2));
//FragColor = texture(texture_diffuse1, ourTexCoord);
//FragColor = texture(texture_metalness1, ourTexCoord);
FragColor = texture(texture_diffuse1, ourTexCoord) * vec4(color, 0.0);
FragColor = texture(texture_metalness1, ourTexCoord);
//FragColor = texture(texture_diffuse1, ourTexCoord) * vec4(color, 0.0);
//FragColor = vec4(CameraPos,1.0);
}

View file

@ -1,18 +1,18 @@
#include "Error.h"
Error::Error(std::string location) { object = location; }
void Error::crash(std::string msg) {
const void Error::crash(std::string msg) const {
log("Error: " + msg);
throw std::string(object + ": \n" + msg);
}
void Error::crash(std::string reason, std::string msg) {
const void Error::crash(std::string reason, std::string msg) const {
log("Error: " + reason + ": \n" + msg);
throw std::string(object + ": \n" + reason + ": \n" + msg);
}
void Error::warn(std::string msg) {
const void Error::warn(std::string msg) const {
log("Warining: " + msg);
// throw object + ": " + msg;
}
void Error::log(std::string msg) {
const void Error::log(std::string msg) const {
std::cout << object << ": \n" << msg << std::endl;
}

View file

@ -11,9 +11,9 @@ public:
Error(std::string location);
// TODO: make the crash break game loop
void crash(std::string msg);
void crash(std::string reason, std::string msg);
void warn(std::string msg);
const void crash(std::string msg) const;
const void crash(std::string reason, std::string msg) const;
const void warn(std::string msg) const;
// TODO: write log issues to a file rather than throw
void log(std::string msg);
const void log(std::string msg) const;
};

View file

@ -80,19 +80,37 @@ ShaderLoader::ShaderLoader(const char *vertexPath, const char *fragmentPath) {
void ShaderLoader::use() { glUseProgram(ID); }
void ShaderLoader::setBool(const std::string &name, bool value) const {
glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value);
int uniformLocation = glGetUniformLocation(ID, name.c_str());
glUniform1i(uniformLocation, (int)value);
if (uniformLocation == -1)
error.warn("Uniform location " + name + " not found");
}
void ShaderLoader::setInt(const std::string &name, int value) const {
glUniform1i(glGetUniformLocation(ID, name.c_str()), value);
int uniformLocation = glGetUniformLocation(ID, name.c_str());
glUniform1i(uniformLocation, value);
if (uniformLocation == -1)
error.warn("Uniform location " + name + " not found");
}
void ShaderLoader::setFloat(const std::string &name, float value) const {
glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
int uniformLocation = glGetUniformLocation(ID, name.c_str());
glUniform1f(uniformLocation, value);
if (uniformLocation == -1)
error.warn("Uniform location " + name + " not found");
}
void ShaderLoader::setMat4(const std::string &name, glm::mat4 value) const {
glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE,
&value[0][0]);
int uniformLocation = glGetUniformLocation(ID, name.c_str());
glUniformMatrix4fv(uniformLocation, 1, GL_FALSE, &value[0][0]);
if (uniformLocation == -1)
error.warn("Uniform location " + name + " not found");
}
void ShaderLoader::setVec3(const std::string &name, glm::vec3 value) const {
glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1,
glm::value_ptr(value));
int uniformLocation = glGetUniformLocation(ID, name.c_str());
glUniform3fv(uniformLocation, 1, glm::value_ptr(value));
if (uniformLocation == -1)
error.warn("Uniform location " + name + " not found");
}

View file

@ -46,6 +46,10 @@ int main(int argc, char **argv) {
return 1;
}
// Set openGL version so RenderDoc works
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
// Create glContext
SDL_GLContext glContext = SDL_GL_CreateContext(window);
if (!glContext) {