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

@@ -78,7 +78,6 @@ void ActivityAnimation::draw(float timeScale)
glColor4fv(RenderingState::instance().pathColor().data());
glVertexPointer(3, GL_FLOAT, 0, startingPos.data());
glDrawElements(GL_LINES, lineIndices.size(), GL_UNSIGNED_INT, lineIndices.data());
checkGLErrors();
}
glDisableClientState(GL_VERTEX_ARRAY);
}

View File

@@ -481,8 +481,6 @@ void RenderingState::idleFunc()
if (options.mouse_2_pressed) {
move('s', false);
}
checkGLErrors();
throttleIdleFunc();
}
glutPostRedisplay();

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
}

View File

@@ -29,11 +29,6 @@ namespace fmri {
*/
void renderText(std::string_view text, int x = 0, int y = 0);
/**
* Check if there are OpenGL errors and report them.
*/
void checkGLErrors();
/**
* Slow down until the idle func is being called a reasonable amount of times.
*/
@@ -55,4 +50,9 @@ namespace fmri {
*/
void
drawImageTiles(int n, const float *vertexBuffer, const float *textureCoords, const Texture &texture, float alpha);
/**
* Attempmt to register
*/
void registerErrorCallbacks();
}

View File

@@ -3,6 +3,7 @@
#include <glog/logging.h>
#include <GL/glut.h>
#include <map>
#include <cstdarg>
#include "LayerData.hpp"
#include "Options.hpp"
@@ -54,6 +55,8 @@ int main(int argc, char *argv[])
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();
registerErrorCallbacks();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);
glutCreateWindow(argv[0]);