Inserted OpenGL Error checking
This commit is contained in:
9
src/dawnopengl/assert/CMakeLists.txt
Normal file
9
src/dawnopengl/assert/CMakeLists.txt
Normal file
@ -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
|
||||
)
|
58
src/dawnopengl/assert/assertgl.cpp
Normal file
58
src/dawnopengl/assert/assertgl.cpp
Normal file
@ -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);
|
||||
}
|
||||
}
|
20
src/dawnopengl/assert/assertgl.hpp
Normal file
20
src/dawnopengl/assert/assertgl.hpp
Normal file
@ -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__)
|
Reference in New Issue
Block a user