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:
@@ -78,7 +78,6 @@ void ActivityAnimation::draw(float timeScale)
|
|||||||
glColor4fv(RenderingState::instance().pathColor().data());
|
glColor4fv(RenderingState::instance().pathColor().data());
|
||||||
glVertexPointer(3, GL_FLOAT, 0, startingPos.data());
|
glVertexPointer(3, GL_FLOAT, 0, startingPos.data());
|
||||||
glDrawElements(GL_LINES, lineIndices.size(), GL_UNSIGNED_INT, lineIndices.data());
|
glDrawElements(GL_LINES, lineIndices.size(), GL_UNSIGNED_INT, lineIndices.data());
|
||||||
checkGLErrors();
|
|
||||||
}
|
}
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -481,8 +481,6 @@ void RenderingState::idleFunc()
|
|||||||
if (options.mouse_2_pressed) {
|
if (options.mouse_2_pressed) {
|
||||||
move('s', false);
|
move('s', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkGLErrors();
|
|
||||||
throttleIdleFunc();
|
throttleIdleFunc();
|
||||||
}
|
}
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
|
|||||||
@@ -7,19 +7,13 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include "glutils.hpp"
|
#include "glutils.hpp"
|
||||||
|
|
||||||
|
#ifdef FREEGLUT
|
||||||
|
#include <GL/freeglut.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace fmri;
|
using namespace fmri;
|
||||||
using namespace std;
|
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)
|
void fmri::changeWindowSize(int w, int h)
|
||||||
{
|
{
|
||||||
// Prevent a divide by zero, when window is too short
|
// 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()
|
void fmri::throttleIdleFunc()
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
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_VERTEX_ARRAY);
|
||||||
glDisableClientState(GL_TEXTURE_COORD_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
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,11 +29,6 @@ namespace fmri {
|
|||||||
*/
|
*/
|
||||||
void renderText(std::string_view text, int x = 0, int y = 0);
|
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.
|
* Slow down until the idle func is being called a reasonable amount of times.
|
||||||
*/
|
*/
|
||||||
@@ -55,4 +50,9 @@ namespace fmri {
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
drawImageTiles(int n, const float *vertexBuffer, const float *textureCoords, const Texture &texture, float alpha);
|
drawImageTiles(int n, const float *vertexBuffer, const float *textureCoords, const Texture &texture, float alpha);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempmt to register
|
||||||
|
*/
|
||||||
|
void registerErrorCallbacks();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <glog/logging.h>
|
#include <glog/logging.h>
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <cstdarg>
|
||||||
|
|
||||||
#include "LayerData.hpp"
|
#include "LayerData.hpp"
|
||||||
#include "Options.hpp"
|
#include "Options.hpp"
|
||||||
@@ -54,6 +55,8 @@ int main(int argc, char *argv[])
|
|||||||
google::InitGoogleLogging(argv[0]);
|
google::InitGoogleLogging(argv[0]);
|
||||||
google::InstallFailureSignalHandler();
|
google::InstallFailureSignalHandler();
|
||||||
|
|
||||||
|
registerErrorCallbacks();
|
||||||
|
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);
|
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);
|
||||||
glutCreateWindow(argv[0]);
|
glutCreateWindow(argv[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user