Inserted OpenGL Error checking

This commit is contained in:
2023-07-23 13:57:25 -07:00
parent 5b01eb904d
commit a94b16e23f
20 changed files with 305 additions and 132 deletions

View File

@ -3,6 +3,7 @@
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "assert/assertgl.hpp"
#include "Shader.hpp"
using namespace Dawn;
@ -20,7 +21,9 @@ void Shader::compileShader(
this->shaderVertex = glCreateShader(GL_VERTEX_SHADER);
auto vertShaderC = vertexShader.c_str();
glShaderSource(this->shaderVertex, 1, &vertShaderC, 0);
assertNoGLError();
glCompileShader(this->shaderVertex);
assertNoGLError();
// Validate
glGetShaderiv(this->shaderVertex, GL_COMPILE_STATUS, &isSuccess);
@ -31,6 +34,7 @@ void Shader::compileShader(
debugMessage(error);
throw error;
}
assertNoGLError();
// Now load the Frag shader
this->shaderFrag = glCreateShader(GL_FRAGMENT_SHADER);
@ -46,11 +50,13 @@ void Shader::compileShader(
debugMessage(error);
throw error;
}
assertNoGLError();
// Now create the shader program.
this->shaderProgram = glCreateProgram();
glAttachShader(this->shaderProgram, this->shaderVertex);
glAttachShader(this->shaderProgram, this->shaderFrag);
assertNoGLError();
// Now parse out the variables.
#if DAWN_OPENGL_HLSL
@ -73,15 +79,18 @@ void Shader::compileShader(
debugMessage(error);
throw error;
}
assertNoGLError();
}
void Shader::bindAttributeLocation(std::string name, int32_t location) {
if(this->shaderProgram == -1) throw "Shader has not yet been compiled";
glBindAttribLocation(this->shaderProgram, location, name.c_str());
assertNoGLError();
}
void Shader::setTexture(shaderparameter_t param, textureslot_t slot) {
glUniform1i(param, slot);
assertNoGLError();
}
shaderparameter_t Shader::getParameterByName(std::string name) {
@ -94,31 +103,38 @@ shaderbufferlocation_t Shader::getBufferLocationByName(std::string name) {
void Shader::setParameterBuffer(shaderbufferlocation_t location, shaderbufferslot_t slot) {
glUniformBlockBinding(this->shaderProgram, location, slot);
assertNoGLError();
}
void Shader::setMatrix(shaderparameter_t uniform, glm::mat4 matrix) {
glUniformMatrix4fv(uniform, 1, GL_FALSE, glm::value_ptr(matrix));
assertNoGLError();
}
void Shader::setBoolean(shaderparameter_t uni, bool value) {
glUniform1i(uni, value);
assertNoGLError();
}
void Shader::setColor(shaderparameter_t uniform, struct Color color) {
glUniform4f(uniform, color.r, color.g, color.b, color.a);
assertNoGLError();
}
void Shader::setVector3(shaderparameter_t uniform, glm::vec3 vector) {
glUniform3f(uniform, vector.x, vector.y, vector.z);
assertNoGLError();
}
void Shader::setFloat(shaderparameter_t param, float_t value) {
glUniform1f(param, value);
assertNoGLError();
}
void Shader::bind() {
if(this->shaderProgram == -1) throw "Shader has not yet been compiled";
assertTrue(this->shaderProgram != -1, "Shader::bind: Cannot bind a program that is not ready");
glUseProgram(this->shaderProgram);
assertNoGLError();
}
Shader::~Shader() {

View File

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "assert/assert.hpp"
#include "assert/assertgl.hpp"
#include "dawnopengl.hpp"
#include "display/shader/_ShaderParameterBuffer.hpp"
@ -30,9 +30,12 @@ namespace Dawn {
assertTrue(this->id == -1, "ShaderParameterBuffer::init: ShaderParameterBuffer is already initialized!");
this->size = sizeof(T);
glGenBuffers(1, &this->id);
assertNoGLError();
glBindBuffer(GL_UNIFORM_BUFFER, this->id);
assertNoGLError();
glBufferData(GL_UNIFORM_BUFFER, this->size, NULL, GL_DYNAMIC_DRAW);
assertNoGLError();
}
bool_t isReady() {
@ -52,7 +55,9 @@ namespace Dawn {
void bind(shaderbufferslot_t location) override {
assertTrue(this->isReady(), "ShaderParameterBuffer::bind: ShaderParameterBuffer is not ready!");
glBindBuffer(GL_UNIFORM_BUFFER, this->id);
assertNoGLError();
glBindBufferBase(GL_UNIFORM_BUFFER, location, this->id);
assertNoGLError();
}
/**
@ -75,7 +80,9 @@ namespace Dawn {
void bufferRaw(void *data, size_t start, size_t length) {
assertTrue(this->isReady(), "ShaderParameterBuffer::bufferRaw: ShaderParameterBuffer is not ready!");
glBindBuffer(GL_UNIFORM_BUFFER, this->id);
assertNoGLError();
glBufferSubData(GL_UNIFORM_BUFFER, start, length, (void*)((size_t)data + start));
assertNoGLError();
}
/**
@ -112,6 +119,7 @@ namespace Dawn {
~ShaderParameterBuffer() {
if(this->id != -1) {
glDeleteBuffers(1, &this->id);
assertNoGLError();
this->id = -1;
}
}

View File

@ -44,7 +44,6 @@ void SimpleTexturedShader::compile() {
"} else {\n"
"o_Color = u_Color;"
"}\n"
"o_Color = vec4(1, 0, 0, 1);\n"
"}\n"
);
#elif DAWN_OPENGL_HLSL