diff --git a/src/dawnglfw/host/DawnGLFWHost.cpp b/src/dawnglfw/host/DawnGLFWHost.cpp index cc4e0774..7cdd517f 100644 --- a/src/dawnglfw/host/DawnGLFWHost.cpp +++ b/src/dawnglfw/host/DawnGLFWHost.cpp @@ -10,7 +10,6 @@ #include "dawnopengl.hpp" #include "display/BackBufferRenderTarget.hpp" - using namespace Dawn; // Static declaration of the host, needed due to GLFW events being C-like @@ -54,12 +53,14 @@ int32_t DawnHost::init(DawnGame *game) { glfwMakeContextCurrent(this->data->window); glfwSwapInterval(1); gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); + assertNoGLError(); // Override the defaults game->renderManager.backBuffer.setSize( DAWN_GLFW_WINDOW_WIDTH_DEFAULT, DAWN_GLFW_WINDOW_HEIGHT_DEFAULT ); + assertNoGLError(); // Default keybinds game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_ENTER); diff --git a/src/dawnliminal/game/LiminalGame.cpp b/src/dawnliminal/game/LiminalGame.cpp index 3d138f46..01b01942 100644 --- a/src/dawnliminal/game/LiminalGame.cpp +++ b/src/dawnliminal/game/LiminalGame.cpp @@ -10,6 +10,6 @@ using namespace Dawn; Scene * Dawn::dawnGameGetInitialScene(DawnGame *game) { - // return new SceneInitial(game); - return new HelloWorldScene(game); + return new SceneInitial(game); + // return new HelloWorldScene(game); } \ No newline at end of file diff --git a/src/dawnopengl/CMakeLists.txt b/src/dawnopengl/CMakeLists.txt index 90f8d807..3aacfc77 100644 --- a/src/dawnopengl/CMakeLists.txt +++ b/src/dawnopengl/CMakeLists.txt @@ -25,5 +25,6 @@ target_include_directories(${DAWN_TARGET_NAME} ) # Subdirs +add_subdirectory(assert) add_subdirectory(display) add_subdirectory(scene) \ No newline at end of file diff --git a/src/dawnopengl/assert/CMakeLists.txt b/src/dawnopengl/assert/CMakeLists.txt new file mode 100644 index 00000000..2310d7a3 --- /dev/null +++ b/src/dawnopengl/assert/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +target_sources(${DAWN_TARGET_NAME} + PRIVATE + assertgl.cpp +) \ No newline at end of file diff --git a/src/dawnopengl/assert/assertgl.cpp b/src/dawnopengl/assert/assertgl.cpp new file mode 100644 index 00000000..7a195600 --- /dev/null +++ b/src/dawnopengl/assert/assertgl.cpp @@ -0,0 +1,58 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "assertgl.hpp" +#include "dawnopengl.hpp" + +void assertNotGLErrorCheck(const char *file, int32_t line) { + GLenum errorCode; + std::string fileString = file; + std::string error = "GL Error"; + int32_t errorCount = 0; + + while((errorCode = glGetError()) != GL_NO_ERROR) { + errorCount++; + switch (errorCode) { + case GL_INVALID_ENUM: + error += "\nINVALID_ENUM"; + break; + + case GL_INVALID_VALUE: + error += "\nINVALID_VALUE"; + break; + + case GL_INVALID_OPERATION: + error += "\nINVALID_OPERATION"; + break; + + case GL_STACK_OVERFLOW: + error += "\nSTACK_OVERFLOW"; + break; + + case GL_STACK_UNDERFLOW: + error += "\nSTACK_UNDERFLOW"; + break; + + case GL_OUT_OF_MEMORY: + error += "\nOUT_OF_MEMORY"; + break; + + case GL_INVALID_FRAMEBUFFER_OPERATION: + error += "\nINVALID_FRAMEBUFFER_OPERATION"; + break; + + default: + error += "\nUNKNOWN GL ERROR ERROR"; + break; + } + + error += " (" + std::to_string(errorCode) + ")"; + } + + if(errorCount != 0) { + error += "\n" + std::string(file) + " (" + std::to_string(line) + ")"; + assertUnreachable(error); + } +} \ No newline at end of file diff --git a/src/dawnopengl/assert/assertgl.hpp b/src/dawnopengl/assert/assertgl.hpp new file mode 100644 index 00000000..d245eca5 --- /dev/null +++ b/src/dawnopengl/assert/assertgl.hpp @@ -0,0 +1,20 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "assert/assert.hpp" + +/** + * Asserts that there are no OpenGL errors. + * + * @param file The file the assertion is being made in. + * @param line The line the assertion is being made in. + */ +void assertNotGLErrorCheck(const char *file, int32_t line); + +/** + * Asserts that there are no OpenGL errors. + */ +#define assertNoGLError() assertNotGLErrorCheck(__FILE__, __LINE__) \ No newline at end of file diff --git a/src/dawnopengl/display/BackBufferRenderTarget.cpp b/src/dawnopengl/display/BackBufferRenderTarget.cpp index 68394c34..0f976b8c 100644 --- a/src/dawnopengl/display/BackBufferRenderTarget.cpp +++ b/src/dawnopengl/display/BackBufferRenderTarget.cpp @@ -38,10 +38,14 @@ void BackBufferRenderTarget::setClearColor(struct Color color) { void BackBufferRenderTarget::clear(flag8_t clearFlags) { glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); + assertNoGLError(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + assertNoGLError(); } void BackBufferRenderTarget::bind() { glBindFramebuffer(GL_FRAMEBUFFER, 0); + assertNoGLError(); glViewport(0, 0, (GLsizei)this->width, (GLsizei)this->height); + assertNoGLError(); } \ No newline at end of file diff --git a/src/dawnopengl/display/BackBufferRenderTarget.hpp b/src/dawnopengl/display/BackBufferRenderTarget.hpp index fe2dd237..151f3cb2 100644 --- a/src/dawnopengl/display/BackBufferRenderTarget.hpp +++ b/src/dawnopengl/display/BackBufferRenderTarget.hpp @@ -5,6 +5,7 @@ #pragma once #include "dawnopengl.hpp" +#include "assert/assertgl.hpp" #include "display/RenderTarget.hpp" namespace Dawn { diff --git a/src/dawnopengl/display/RenderManager.cpp b/src/dawnopengl/display/RenderManager.cpp index 6a18cf80..bd034c99 100644 --- a/src/dawnopengl/display/RenderManager.cpp +++ b/src/dawnopengl/display/RenderManager.cpp @@ -28,13 +28,17 @@ void RenderManager::init() { this->fontShader = this->shaderManager.getShader(this->lockFontShader); this->renderPipeline.init(); + assertNoGLError(); // Prepare the initial values - glEnable(GL_TEXTURE_2D); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + assertNoGLError(); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + assertNoGLError(); glDepthMask(GL_TRUE); + assertNoGLError(); glDepthFunc(GL_LESS); + assertNoGLError(); } RenderTarget * RenderManager::getBackBuffer() { @@ -57,12 +61,14 @@ void RenderManager::setRenderFlags(renderflag_t flags) { } else { glEnable(GL_DEPTH_TEST); } + assertNoGLError(); if((flags & RENDER_MANAGER_RENDER_FLAG_BLEND) == 0) { glDisable(GL_BLEND); } else { glEnable(GL_BLEND); } + assertNoGLError(); } void RenderManager::update() { diff --git a/src/dawnopengl/display/RenderManager.hpp b/src/dawnopengl/display/RenderManager.hpp index 436919fa..a548eff9 100644 --- a/src/dawnopengl/display/RenderManager.hpp +++ b/src/dawnopengl/display/RenderManager.hpp @@ -4,6 +4,7 @@ // https://opensource.org/licenses/MIT #pragma once +#include "assert/assertgl.hpp" #include "display/BackBufferRenderTarget.hpp" #include "display/shader/ShaderManager.hpp" #include "display/shader/shaders/SimpleTexturedShader.hpp" diff --git a/src/dawnopengl/display/Texture.cpp b/src/dawnopengl/display/Texture.cpp index d4f1124e..e7ae0ecb 100644 --- a/src/dawnopengl/display/Texture.cpp +++ b/src/dawnopengl/display/Texture.cpp @@ -20,7 +20,9 @@ Texture::Texture() : ITexture() { void Texture::bind(textureslot_t slot) { assertTrue(this->id != -1, "Texture::bind: Texture is not ready!"); glActiveTexture(GL_TEXTURE0 + slot); + assertNoGLError(); glBindTexture(GL_TEXTURE_2D, this->id); + assertNoGLError(); if(this->texturePropertiesNeedUpdating) { this->updateTextureProperties(); @@ -44,6 +46,7 @@ void Texture::setSize( ) { if(this->id != -1) { glDeleteTextures(1, &this->id); + assertNoGLError(); this->id = -1; } @@ -61,10 +64,12 @@ void Texture::setSize( this->dataFormat = dataFormat; glGenTextures(1, &this->id); + assertNoGLError(); if(this->id <= 0) throw "Texture generation failed!"; // Initialize the texture to blank glActiveTexture(GL_TEXTURE0); + assertNoGLError(); this->bufferRaw(NULL); } @@ -110,6 +115,7 @@ void Texture::updateTextureProperties() { default: assertUnreachable("Texture::updateTextureProperties: Unknown wrap mode!"); } + assertNoGLError(); }; setWrapMode(GL_TEXTURE_WRAP_S, this->wrapModeX); @@ -159,6 +165,7 @@ void Texture::updateTextureProperties() { assertUnreachable("Texture::updateTextureProperties: Unknown filter mode!"); } } + assertNoGLError(); }; setFilterMode(GL_TEXTURE_MIN_FILTER, this->filterModeMin, this->mipmapFilterModeMin); @@ -205,12 +212,15 @@ void Texture::bufferRaw(void *data) { } glBindTexture(GL_TEXTURE_2D, this->id); + assertNoGLError(); glTexImage2D( GL_TEXTURE_2D, 0, format, this->width, this->height, 0, format, dataFormat, data ); + assertNoGLError(); glGenerateMipmap(GL_TEXTURE_2D); + assertNoGLError(); this->texturePropertiesNeedUpdating = true; } @@ -231,5 +241,8 @@ void Texture::buffer(uint8_t pixels[]) { } Texture::~Texture() { - if(this->id != -1) glDeleteTextures(1, &this->id); + if(this->id != -1) { + glDeleteTextures(1, &this->id); + assertNoGLError(); + } } \ No newline at end of file diff --git a/src/dawnopengl/display/Texture.hpp b/src/dawnopengl/display/Texture.hpp index 7d74b5f2..a19628f3 100644 --- a/src/dawnopengl/display/Texture.hpp +++ b/src/dawnopengl/display/Texture.hpp @@ -5,7 +5,7 @@ #pragma once #include "dawnopengl.hpp" -#include "assert/assert.hpp" +#include "assert/assertgl.hpp" #include "display/_Texture.hpp" #include "util/memory.hpp" diff --git a/src/dawnopengl/display/TextureRenderTarget.cpp b/src/dawnopengl/display/TextureRenderTarget.cpp index 563130a3..1796d761 100644 --- a/src/dawnopengl/display/TextureRenderTarget.cpp +++ b/src/dawnopengl/display/TextureRenderTarget.cpp @@ -23,7 +23,9 @@ void TextureRenderTarget::setSize(float_t width, float_t height) { // Delete old buffers. if(this->rboId != -1) glDeleteRenderbuffers(1, &this->rboId); + assertNoGLError(); if(this->fboId != -1) glDeleteFramebuffers(1, &this->fboId); + assertNoGLError(); // Resize texture this->texture.setSize((int32_t)width, (int32_t)height, TEXTURE_FORMAT_RGBA, TEXTURE_DATA_FORMAT_FLOAT); @@ -31,22 +33,30 @@ void TextureRenderTarget::setSize(float_t width, float_t height) { // Create Frame Buffer glGenFramebuffers(1, &this->fboId); + assertNoGLError(); glBindFramebuffer(GL_FRAMEBUFFER, this->fboId); + assertNoGLError(); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->texture.id, 0 ); + assertNoGLError(); // Create Render Buffer glGenRenderbuffers(1, &this->rboId); + assertNoGLError(); glBindRenderbuffer(GL_RENDERBUFFER, this->rboId); + assertNoGLError(); glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, this->texture.width, this->texture.height ); + assertNoGLError(); glBindRenderbuffer(GL_RENDERBUFFER, 0); + assertNoGLError(); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, this->rboId ); + assertNoGLError(); // Validate things went correct. if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { diff --git a/src/dawnopengl/display/mesh/Mesh.cpp b/src/dawnopengl/display/mesh/Mesh.cpp index 6f1566b4..4c6e1b8a 100644 --- a/src/dawnopengl/display/mesh/Mesh.cpp +++ b/src/dawnopengl/display/mesh/Mesh.cpp @@ -23,9 +23,16 @@ void Mesh::createBuffers( auto sizeInds = sizeof(meshindice_t) * indiceCount; auto sizeCoords = sizeof(glm::vec2) * verticeCount; + // Generate vertex array, I don't think I need to do this tbh. + glGenVertexArrays(1, &this->vertexArray); + assertNoGLError(); + glBindVertexArray(this->vertexArray); + assertNoGLError(); + // Create some buffers, one for the vertex data, one for the indices GLuint buffer[2]; glGenBuffers(2, buffer); + assertNoGLError(); this->vertexBuffer = buffer[0]; if(this->vertexBuffer < 0) throw "Failed to create vertex buffer"; this->indexBuffer = buffer[1]; @@ -33,9 +40,13 @@ void Mesh::createBuffers( // Buffer an empty set of data then buffer each component glBindBuffer(GL_ARRAY_BUFFER, this->vertexBuffer); + assertNoGLError(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->indexBuffer); + assertNoGLError(); glBufferData(GL_ARRAY_BUFFER, sizePos+sizeCoords, 0, GL_DYNAMIC_DRAW); + assertNoGLError(); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeInds, 0, GL_DYNAMIC_DRAW); + assertNoGLError(); // Setup the attrib pointers size_t offset = 0; @@ -44,7 +55,9 @@ void Mesh::createBuffers( GL_FLOAT, GL_FALSE, 0, (void *)offset ); + assertNoGLError(); glEnableVertexAttribArray(0); + assertNoGLError(); offset += sizePos; glVertexAttribPointer( @@ -52,24 +65,36 @@ void Mesh::createBuffers( GL_FLOAT, GL_FALSE, 0, (void *)offset ); + assertNoGLError(); glEnableVertexAttribArray(1); + assertNoGLError(); } void Mesh::disposeBuffers() { glBindBuffer(GL_ARRAY_BUFFER, 0); + assertNoGLError(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + assertNoGLError(); if(this->vertexBuffer != -1) { glDeleteBuffers(1, &this->vertexBuffer); + assertNoGLError(); this->vertexBuffer = -1; this->verticeCount = -1; } if(this->indexBuffer != -1) { glDeleteBuffers(1, &this->indexBuffer); + assertNoGLError(); this->indexBuffer = -1; this->indiceCount = -1; } + + if(this->vertexArray) { + glDeleteVertexArrays(1, &this->vertexArray); + assertNoGLError(); + this->vertexArray = -1; + } } void Mesh::bufferPositions(int32_t pos, glm::vec3 *positions, int32_t len) { @@ -79,12 +104,14 @@ void Mesh::bufferPositions(int32_t pos, glm::vec3 *positions, int32_t len) { assertTrue(len > 0, "Mesh::bufferPositions: Length must be greater than zero"); glBindBuffer(GL_ARRAY_BUFFER, this->vertexBuffer); + assertNoGLError(); glBufferSubData( GL_ARRAY_BUFFER, sizeof(glm::vec3) * pos, sizeof(glm::vec3) * len, (void*)positions ); + assertNoGLError(); } void Mesh::bufferCoordinates(int32_t pos, glm::vec2 *coordinates, int32_t len) { @@ -99,12 +126,14 @@ void Mesh::bufferCoordinates(int32_t pos, glm::vec2 *coordinates, int32_t len) { ); glBindBuffer(GL_ARRAY_BUFFER, this->vertexBuffer); + assertNoGLError(); glBufferSubData( GL_ARRAY_BUFFER, offsetCoordinates, sizeof(glm::vec2) * len, (void*)coordinates ); + assertNoGLError(); } void Mesh::bufferIndices(int32_t pos, meshindice_t *indices, int32_t len) { @@ -114,12 +143,14 @@ void Mesh::bufferIndices(int32_t pos, meshindice_t *indices, int32_t len) { assertTrue(len > 0, "Mesh::bufferIndices: Length must be greater than zero"); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->indexBuffer); + assertNoGLError(); glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, sizeof(meshindice_t) * pos, sizeof(meshindice_t) * len, (void*)indices ); + assertNoGLError(); } void Mesh::draw(enum MeshDrawMode drawMode, int32_t start, int32_t count) { @@ -133,8 +164,12 @@ void Mesh::draw(enum MeshDrawMode drawMode, int32_t start, int32_t count) { // Re-Bind the buffers + glBindVertexArray(this->vertexArray); + assertNoGLError(); glBindBuffer(GL_ARRAY_BUFFER, this->vertexBuffer); + assertNoGLError(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->indexBuffer); + assertNoGLError(); // Re-Calculate the attrib pointers. size_t offset = 0; @@ -143,7 +178,9 @@ void Mesh::draw(enum MeshDrawMode drawMode, int32_t start, int32_t count) { GL_FLOAT, GL_FALSE, 0, (void *)offset ); + assertNoGLError(); glEnableVertexAttribArray(0); + assertNoGLError(); offset += sizeof(glm::vec3) * this->verticeCount; glVertexAttribPointer( @@ -151,12 +188,15 @@ void Mesh::draw(enum MeshDrawMode drawMode, int32_t start, int32_t count) { GL_FLOAT, GL_FALSE, 0, (void *)offset ); + assertNoGLError(); glEnableVertexAttribArray(1); + assertNoGLError(); // Render the elements. glDrawElements( drawMode, count, GL_UNSIGNED_INT, (void *)(sizeof(meshindice_t) * start) ); + assertNoGLError(); } Mesh::~Mesh() { diff --git a/src/dawnopengl/display/mesh/Mesh.hpp b/src/dawnopengl/display/mesh/Mesh.hpp index e32b3c8e..4655a82f 100644 --- a/src/dawnopengl/display/mesh/Mesh.hpp +++ b/src/dawnopengl/display/mesh/Mesh.hpp @@ -4,6 +4,7 @@ // https://opensource.org/licenses/MIT #pragma once +#include "assert/assertgl.hpp" #include "display/mesh/_Mesh.hpp" #include "dawnopengl.hpp" #include "assert/assert.hpp" @@ -25,6 +26,8 @@ namespace Dawn { GLuint vertexBuffer = -1; /** Pointer to the index buffer on the GPU */ GLuint indexBuffer = -1; + /** Pointer to the vertex buffer on the GPU */ + GLuint vertexArray = -1; /** How many vertices are in the mesh */ int32_t verticeCount = -1; diff --git a/src/dawnopengl/display/shader/Shader.cpp b/src/dawnopengl/display/shader/Shader.cpp index 581af531..b3eb3dff 100644 --- a/src/dawnopengl/display/shader/Shader.cpp +++ b/src/dawnopengl/display/shader/Shader.cpp @@ -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() { diff --git a/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp b/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp index 05a1aca2..e0ccb3d8 100644 --- a/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp +++ b/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp @@ -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; } } diff --git a/src/dawnopengl/display/shader/shaders/SimpleTexturedShader.cpp b/src/dawnopengl/display/shader/shaders/SimpleTexturedShader.cpp index f39dde53..f8c3f57d 100644 --- a/src/dawnopengl/display/shader/shaders/SimpleTexturedShader.cpp +++ b/src/dawnopengl/display/shader/shaders/SimpleTexturedShader.cpp @@ -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 diff --git a/src/dawnshared/assert/assert.cpp b/src/dawnshared/assert/assert.cpp index 36bce1e4..ea4fbc5d 100644 --- a/src/dawnshared/assert/assert.cpp +++ b/src/dawnshared/assert/assert.cpp @@ -7,64 +7,60 @@ #include "assert.hpp" -#if ASSERTS_ENABLED == 0 - -#elif ASSERTS_ENABLED == 1 - void assertTrue(bool_t x, const char message[]) { - if(x != true) { - std::cout << message << std::endl; - throw message; - free(0); - } - assert(x == true); +void assertTrue(bool_t x, const char message[]) { + if(x != true) { + std::cout << message << std::endl; + throw message; + free(0); } + assert(x == true); +} - void assertTrue(bool_t x, std::string message) { - assertTrue(x, message.c_str()); - } - - - void assertFalse(bool_t x, const char message[]) { - assertTrue(!x, message); - } - - void assertFalse(bool_t x, std::string message) { - assertFalse(x, message.c_str()); - } +void assertTrue(bool_t x, std::string message) { + assertTrue(x, message.c_str()); +} - void assertUnreachable(const char message[]) { - assertTrue(false, message); - } +void assertFalse(bool_t x, const char message[]) { + assertTrue(!x, message); +} - void assertUnreachable(std::string message) { - assertUnreachable(message.c_str()); - } +void assertFalse(bool_t x, std::string message) { + assertFalse(x, message.c_str()); +} - void assertNotNull(void *pointer, const char message[]) { - assertTrue(pointer != nullptr && pointer != NULL, message); - } +void assertUnreachable(const char message[]) { + assertTrue(false, message); +} - void assertNotNull(void *pointer, std::string message) { - assertNotNull(pointer, message.c_str()); - } +void assertUnreachable(std::string message) { + assertUnreachable(message.c_str()); +} - void assertNull(void *pointer, const char message[]) { - assertTrue(pointer == NULL || pointer == nullptr, message); - } +void assertNotNull(void *pointer, const char message[]) { + assertTrue(pointer != nullptr && pointer != NULL, message); +} - void assertNull(void *pointer, std::string message) { - assertNull(pointer, message.c_str()); - } +void assertNotNull(void *pointer, std::string message) { + assertNotNull(pointer, message.c_str()); +} - void assertDeprecated(const char message[]) { - assertUnreachable(message); - } +void assertNull(void *pointer, const char message[]) { + assertTrue(pointer == NULL || pointer == nullptr, message); +} - void assertDeprecated(std::string message) { - assertDeprecated(message.c_str()); - } -#endif \ No newline at end of file +void assertNull(void *pointer, std::string message) { + assertNull(pointer, message.c_str()); +} + + +void assertDeprecated(const char message[]) { + assertUnreachable(message); +} + +void assertDeprecated(std::string message) { + assertDeprecated(message.c_str()); +} \ No newline at end of file diff --git a/src/dawnshared/assert/assert.hpp b/src/dawnshared/assert/assert.hpp index 3ad381d0..3524d090 100644 --- a/src/dawnshared/assert/assert.hpp +++ b/src/dawnshared/assert/assert.hpp @@ -8,86 +8,73 @@ #pragma once #include "dawnsharedlibs.hpp" -#define ASSERTS_ENABLED 1 +/** + * Assert a given value to be true. + * @param x Value to assert as true. + * @param message Message to throw against assertion failure. + */ +void assertTrue(bool_t x, const char message[]); +void assertTrue(bool_t x, std::string message); -#if ASSERTS_ENABLED == 0 +/** + * Asserts a given statement to be false. + * @param x Value to assert as false. + * @param message Message to throw against assertion failure. + */ +void assertFalse(bool_t x, const char message[]); +void assertFalse(bool_t x, std::string message); -static inline void assertTrue(bool_t x) {} +/** + * Asserts that a given line of code is unreachable. Essentially a forced + * assertion failure, good for "edge cases" + * @param message Message to throw against assertion failure. + */ +void assertUnreachable(const char message[]); +void assertUnreachable(std::string message); -#elif ASSERTS_ENABLED == 1 +/** + * Assert a given pointer to not point to a null pointer. + * @param pointer Pointer to assert is not a null pointer. + * @param message Message to throw against assertion failure. + */ +void assertNotNull(void *pointer, const char message[]); +void assertNotNull(void *pointer, std::string message); - /** - * Assert a given value to be true. - * @param x Value to assert as true. - * @param message Message to throw against assertion failure. - */ - void assertTrue(bool_t x, const char message[]); - void assertTrue(bool_t x, std::string message); +/** + * Asserts a given pointer to be a nullptr. + * @param pointer Pointer to assert is nullptr. + * @param message Message to throw against assertion failure. + */ +void assertNull(void *pointer, const char message[]); +void assertNull(void *pointer, std::string message); - /** - * Asserts a given statement to be false. - * @param x Value to assert as false. - * @param message Message to throw against assertion failure. - */ - void assertFalse(bool_t x, const char message[]); - void assertFalse(bool_t x, std::string message); +/** + * Asserts a function as being deprecated. + * @param message Message to throw against assertion failure. + */ +void assertDeprecated(const char message[]); +void assertDeprecated(std::string message); - /** - * Asserts that a given line of code is unreachable. Essentially a forced - * assertion failure, good for "edge cases" - * @param message Message to throw against assertion failure. - */ - void assertUnreachable(const char message[]); - void assertUnreachable(std::string message); +/** + * Asserts that a given map has a key. + * + * @param map Map to check. + * @param key Key to try and assert exists. + * @param message Message to throw against assertion failure. + */ +template +void assertMapHasKey(std::map map, K key, const char message[]) { + assertTrue(map.find(key) != map.end(), message); +} - /** - * Assert a given pointer to not point to a null pointer. - * @param pointer Pointer to assert is not a null pointer. - * @param message Message to throw against assertion failure. - */ - void assertNotNull(void *pointer, const char message[]); - void assertNotNull(void *pointer, std::string message); - - /** - * Asserts a given pointer to be a nullptr. - * @param pointer Pointer to assert is nullptr. - * @param message Message to throw against assertion failure. - */ - void assertNull(void *pointer, const char message[]); - void assertNull(void *pointer, std::string message); - - /** - * Asserts a function as being deprecated. - * @param message Message to throw against assertion failure. - */ - void assertDeprecated(const char message[]); - void assertDeprecated(std::string message); - - /** - * Asserts that a given map has a key. - * - * @param map Map to check. - * @param key Key to try and assert exists. - * @param message Message to throw against assertion failure. - */ - template - void assertMapHasKey(std::map map, K key, const char message[]) { - assertTrue(map.find(key) != map.end(), message); - } - - /** - * Asserts that a given map has a key. - * - * @param map Map to check. - * @param key Key to try and assert exists. - * @param message Message to throw against assertion failure. - */ - template - void assertMapHasKey(std::map map, K key, std::string message) { - assertMapHasKey(map, key, message.c_str()); - } -#else - - #define assertTrue assert - -#endif \ No newline at end of file +/** + * Asserts that a given map has a key. + * + * @param map Map to check. + * @param key Key to try and assert exists. + * @param message Message to throw against assertion failure. + */ +template +void assertMapHasKey(std::map map, K key, std::string message) { + assertMapHasKey(map, key, message.c_str()); +} \ No newline at end of file