|
From: Yoda-JM <yo...@us...> - 2011-02-24 10:34:07
|
Author: Vincent Le Ligeour <yo...@us...>
Date: Thu Feb 24 11:33:14 2011 +0100
RAII GLErrorChecker and better diagnostics.
Conflicts:
game/glshader.cc
game/glutil.hh
game/guitargraph.cc
game/video_driver.cc
---
game/glutil.hh | 31 +++++++++++++++++++------------
game/guitargraph.cc | 3 ++-
game/main.cc | 4 ++--
game/surface.cc | 10 ++++------
game/video_driver.cc | 5 ++---
5 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/game/glutil.hh b/game/glutil.hh
index c7f81a8..5df2080 100644
--- a/game/glutil.hh
+++ b/game/glutil.hh
@@ -106,18 +106,25 @@ namespace glutil {
/// Checks for OpenGL error and displays it with given location info
struct GLErrorChecker {
- GLErrorChecker(std::string info = "") {
- GLenum err;
- if ((err = glGetError()) != GL_NO_ERROR) {
- if (!info.empty()) info = " (" + info +")";
- switch(err) {
- case GL_INVALID_ENUM: std::cerr << "OpenGL error: invalid enum" << info << std::endl; break;
- case GL_INVALID_VALUE: std::cerr << "OpenGL error: invalid value" << info << std::endl; break;
- case GL_INVALID_OPERATION: std::cerr << "OpenGL error: invalid operation" << info << std::endl; break;
- case GL_STACK_OVERFLOW: std::cerr << "OpenGL error: stack overflow" << info << std::endl; break;
- case GL_STACK_UNDERFLOW: std::cerr << "OpenGL error: stack underflow" << info << std::endl; break;
- case GL_OUT_OF_MEMORY: std::cerr << "OpenGL error: out of memory" << info << std::endl; break;
- }
+ std::string info;
+ GLErrorChecker(std::string const& info): info(info) { check("precondition"); }
+ ~GLErrorChecker() { check("postcondition"); }
+ void check(std::string const& what = "check()") {
+ GLenum err = glGetError();
+ if (err == GL_NO_ERROR) return;
+ std::clog << "opengl/error: " << msg(err) << " in " << info << " " << what << std::endl;
+ }
+ static void reset() { glGetError(); }
+ static std::string msg(GLenum err) {
+ switch(err) {
+ case GL_NO_ERROR: return std::string();
+ case GL_INVALID_ENUM: return "Invalid enum";
+ case GL_INVALID_VALUE: return "Invalid value";
+ case GL_INVALID_OPERATION: return "Invalid operation";
+ case GL_STACK_OVERFLOW: return "Stack overflow";
+ case GL_STACK_UNDERFLOW: return "Stack underflow";
+ case GL_OUT_OF_MEMORY: return "Out of memory";
+ default: return "Unknown error";
}
}
};
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 51cd3d2..ea4010a 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -787,6 +787,7 @@ namespace {
/// Main drawing function (projection, neck, cursor...)
void GuitarGraph::draw(double time) {
+ // FIXME: There are errors here... glutil::GLErrorChecker ec("GuitarGraph::draw");
Dimensions dimensions(1.0); // FIXME: bogus aspect ratio (is this fixable?)
dimensions.screenBottom().middle(m_cx.get()).fixedWidth(std::min(m_width.get(),0.5));
double offsetX = 0.5 * (dimensions.x1() + dimensions.x2());
@@ -940,7 +941,7 @@ void GuitarGraph::draw(double time) {
}
}
}
- } //< disable lighting
+ } //< disable depth test
// Draw flames
for (int fret = 0; fret < m_pads; ++fret) { // Loop through the frets
if (m_drums && fret == input::KICK_BUTTON) { // Skip bass drum
diff --git a/game/main.cc b/game/main.cc
index 51596f0..a5fba08 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -105,8 +105,6 @@ static void checkEvents_SDL(ScreenManager& sm) {
// This is needed to allow navigation (quiting the song) to function even then
input::SDL::pushEvent(event);
sm.getCurrentScreen()->manageEvent(event);
- // Check for OpenGL errors
- glutil::GLErrorChecker glerror;
}
if (config["graphic/fullscreen"].b() != sm.window().getFullscreen()) {
sm.window().setFullscreen(config["graphic/fullscreen"].b());
@@ -162,6 +160,7 @@ void mainLoop(std::string const& songlist) {
// Main loop
boost::xtime time = now();
unsigned frames = 0;
+ glutil::GLErrorChecker glerror("mainloop");
while (!sm.isFinished()) {
Profiler prof("mainloop");
if( g_take_screenshot ) {
@@ -207,6 +206,7 @@ void mainLoop(std::string const& songlist) {
std::cerr << "ERROR: " << e.what() << std::endl;
sm.flashMessage(std::string("ERROR: ") + e.what());
}
+ glerror.check("frame");
}
} catch (std::exception& e) {
// This should use ScreenManager fatalError, but it cannot
diff --git a/game/surface.cc b/game/surface.cc
index d95e0e9..ec2004e 100644
--- a/game/surface.cc
+++ b/game/surface.cc
@@ -77,6 +77,7 @@ namespace {
}
void Texture::load(unsigned int width, unsigned int height, pix::Format format, unsigned char const* buffer, float ar) {
+ glutil::GLErrorChecker glerror("Texture::load");
m_ar = ar ? ar : double(width) / height;
UseTexture texture(*this);
// When texture area is small, bilinear filter the closest mipmap
@@ -87,12 +88,12 @@ void Texture::load(unsigned int width, unsigned int height, pix::Format format,
glTexParameterf(type(), GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(type(), GL_TEXTURE_WRAP_T, GL_REPEAT);
//glTexParameterf(type(), GL_TEXTURE_MAX_LEVEL, 1);
- glutil::GLErrorChecker glerror1("Texture::load - glTexParameterf");
+ glerror.check("glTexParameterf");
// Anisotropy is potential trouble maker
if (GLEW_EXT_texture_filter_anisotropic)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f);
- glutil::GLErrorChecker glerror2("Texture::load - MAX_ANISOTROPY_EXT");
+ glerror.check("MAX_ANISOTROPY_EXT");
glTexParameteri(type(), GL_GENERATE_MIPMAP, GL_TRUE);
PixFmt const& f = getPixFmt(format);
@@ -112,11 +113,10 @@ void Texture::load(unsigned int width, unsigned int height, pix::Format format,
// Just don't do it in Surface class, thanks. -Tronic
glTexImage2D(type(), 0, GL_RGBA, newWidth, newHeight, 0, f.format, f.type, &outBuf[0]);
}
- // Check for OpenGL errors
- glutil::GLErrorChecker glerror3("Texture::load");
}
void Surface::load(unsigned int width, unsigned int height, pix::Format format, unsigned char const* buffer, float ar) {
+ glutil::GLErrorChecker glerror("Surface::load");
using namespace pix;
// Initialize dimensions
m_width = width; m_height = height;
@@ -126,8 +126,6 @@ void Surface::load(unsigned int width, unsigned int height, pix::Format format,
PixFmt const& f = getPixFmt(format);
glPixelStorei(GL_UNPACK_SWAP_BYTES, f.swap);
glTexImage2D(m_texture.type(), 0, GL_RGBA, width, height, 0, f.format, f.type, buffer);
- // Check for OpenGL errors
- glutil::GLErrorChecker glerror("Surface::load");
}
void Surface::draw() const {
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 4ad9d69..26d16af 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -91,6 +91,7 @@ void Window::screenshot() {
void Window::resize() {
+ glutil::GLErrorChecker glerror("Window::resize");
unsigned width = m_fullscreen ? m_fsW : m_windowW;
unsigned height = m_fullscreen ? m_fsH : m_windowH;
{ // Setup GL attributes for context creation
@@ -109,7 +110,7 @@ void Window::resize() {
screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL | SDL_RESIZABLE | (m_fullscreen ? SDL_FULLSCREEN : 0));
if (!screen) throw std::runtime_error(std::string("SDL_SetVideoMode failed: ") + SDL_GetError());
}
-
+ glerror.check("SetVideoMode");
s_width = screen->w;
s_height = screen->h;
if (!m_fullscreen) {
@@ -140,7 +141,5 @@ void Window::resize() {
const float f = 0.9f; // Avoid texture surface being exactly at the near plane (MacOSX fix)
glFrustum(-0.5f * f, 0.5f * f, 0.5f * h * f, -0.5f * h * f, f * near_, far_);
glTranslatef(0.0f, 0.0f, -near_); // So that z = 0.0f is still on monitor surface
- // Check for OpenGL errors
- glutil::GLErrorChecker glerror("Window::resize");
}
|