|
From: Tapio V. <aa...@us...> - 2010-05-11 11:03:09
|
Module: performous
Branch: master
Commit: c0e27ca4d9869a7e01549231420f8d7b001e641d
Author: Tapio Vierros <tap...@gm...>
Date: Tue May 11 14:02:11 2010 +0300
Add some OpenGL error checking to video_driver and surface.
---
game/glutil.hh | 25 +++++++++++++++++++++++--
game/main.cc | 11 +++--------
game/surface.cc | 4 ++++
game/video_driver.cc | 3 ++-
4 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/game/glutil.hh b/game/glutil.hh
index ad7f309..fe5441d 100644
--- a/game/glutil.hh
+++ b/game/glutil.hh
@@ -1,5 +1,8 @@
#pragma once
+#include <string>
+#include <iostream>
+
#include <GL/glew.h>
namespace glutil {
@@ -38,10 +41,10 @@ namespace glutil {
if (doit) {
glClear(GL_DEPTH_BUFFER_BIT);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
-
+
GLfloat light_position[] = { -50.0, 15.0, -5.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
-
+
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
@@ -69,5 +72,23 @@ namespace glutil {
/// overload float const cast
operator float const*() const { return reinterpret_cast<float const*>(this); }
};
+
+ /// 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;
+ }
+ }
+ }
+ };
}
diff --git a/game/main.cc b/game/main.cc
index fea8426..a0f4a91 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -9,6 +9,7 @@
#include "xtime.hh"
#include "video_driver.hh"
#include "i18n.hh"
+#include "glutil.hh"
// Screens
#include "screen_intro.hh"
@@ -99,14 +100,8 @@ 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);
- switch(glGetError()) {
- case GL_INVALID_ENUM: std::cerr << "OpenGL error: invalid enum" << std::endl; break;
- case GL_INVALID_VALUE: std::cerr << "OpenGL error: invalid value" << std::endl; break;
- case GL_INVALID_OPERATION: std::cerr << "OpenGL error: invalid operation" << std::endl; break;
- case GL_STACK_OVERFLOW: std::cerr << "OpenGL error: stack overflow" << std::endl; break;
- case GL_STACK_UNDERFLOW: std::cerr << "OpenGL error: stack underflow" << std::endl; break;
- case GL_OUT_OF_MEMORY: std::cerr << "OpenGL error: out of memory" << std::endl; break;
- }
+ // Check for OpenGL errors
+ glutil::GLErrorChecker glerror;
}
if( config["graphic/fullscreen"].b() != sm.window().getFullscreen() )
sm.window().setFullscreen(config["graphic/fullscreen"].b());
diff --git a/game/surface.cc b/game/surface.cc
index be71e13..1de1480 100644
--- a/game/surface.cc
+++ b/game/surface.cc
@@ -101,6 +101,8 @@ 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 glerror("Texture::load");
}
void Surface::load(unsigned int width, unsigned int height, pix::Format format, unsigned char const* buffer, float ar) {
@@ -113,6 +115,8 @@ 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 56c774a..508db0e 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -138,6 +138,7 @@ 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");
}
|