Use GLUT for detecting errors.

Rather than polling for errors, let GLUT do it. Can be enabled with the
"-gldebug" CLI flag.
This commit is contained in:
2018-04-13 13:21:30 +02:00
parent 018148efef
commit d20f568836
5 changed files with 32 additions and 25 deletions

View File

@@ -7,19 +7,13 @@
#include <thread>
#include "glutils.hpp"
#ifdef FREEGLUT
#include <GL/freeglut.h>
#endif
using namespace fmri;
using namespace std;
static void handleGLError(GLenum error) {
switch (error) {
case GL_NO_ERROR:
return;
default:
cerr << "OpenGL error: " << (const char*) gluGetString(error) << endl;
}
}
void fmri::changeWindowSize(int w, int h)
{
// Prevent a divide by zero, when window is too short
@@ -59,13 +53,6 @@ void fmri::renderText(std::string_view text, int x, int y)
}
}
void fmri::checkGLErrors()
{
while (auto error = glGetError()) {
handleGLError(error);
}
}
void fmri::throttleIdleFunc()
{
using namespace std::chrono;
@@ -129,3 +116,23 @@ void fmri::drawImageTiles(int n, const float *vertexBuffer, const float *texture
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
void fmri::registerErrorCallbacks()
{
#ifdef FREEGLUT
glutInitErrorFunc([](const char* format, va_list args) {
char buffer[1024];
std::vsnprintf(buffer, sizeof(buffer), format, args);
LOG(ERROR) << "freeglut: " << buffer;
});
glutInitWarningFunc([](const char* format, va_list args) {
char buffer[1024];
std::vsnprintf(buffer, sizeof(buffer), format, args);
LOG(WARNING) << "freeglut: " << buffer;
});
LOG(INFO) << "Freeglut error handlers installed successfully";
#else
LOG(INFO) << "Compiled without freeglut, error handlers not available.";
#endif
}