|
From: Lasse Kärkkäi. <tr...@us...> - 2011-01-31 23:57:41
|
Module: performous
Branch: opengl2
Commit: 8dd69283f43236a414fb4dd546ac95b25d23fc2b
Author: Lasse Karkkainen <tro...@tr...>
Date: Tue Feb 1 00:44:41 2011 +0100
Refactor where the rendering occurs (mainloop calls window to render using SM::drawScreen).
---
game/fbo.hh | 9 +++++----
game/main.cc | 5 +++--
game/screenmanager.cc | 7 ++-----
game/video_driver.cc | 16 ++++++++++++++++
game/video_driver.hh | 2 ++
5 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/game/fbo.hh b/game/fbo.hh
index ded4f84..c3668e1 100644
--- a/game/fbo.hh
+++ b/game/fbo.hh
@@ -1,6 +1,7 @@
#pragma once
#include <boost/noncopyable.hpp>
+#include "surface.hh"
#include "video_driver.hh"
/// Frame Buffer Object class
@@ -12,9 +13,9 @@ class FBO: public boost::noncopyable {
bind();
{
UseTexture tex(m_texture);
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, screenW(), screenH(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, screenW(), screenH(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// Bind texture as COLOR_ATTACHMENT0
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_texture.id(), 0);
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture.id(), 0);
}
unbind();
}
@@ -23,7 +24,7 @@ class FBO: public boost::noncopyable {
if (m_fbo) glDeleteFramebuffersEXT(1, &m_fbo);
}
/// Returns a reference to the attached texture
- OpenGLTexture<GL_TEXTURE_RECTANGLE_ARB>& getTexture() {
+ OpenGLTexture<GL_TEXTURE_2D>& getTexture() {
return m_texture;
}
/// Bind the FBO into use
@@ -37,7 +38,7 @@ class FBO: public boost::noncopyable {
private:
GLuint m_fbo;
- OpenGLTexture<GL_TEXTURE_RECTANGLE_ARB> m_texture;
+ OpenGLTexture<GL_TEXTURE_2D> m_texture;
};
/// RAII FBO binder
diff --git a/game/main.cc b/game/main.cc
index a7d7987..b69a936 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -21,6 +21,7 @@
#include "screen_paths.hh"
#include "screen_players.hh"
+#include <boost/bind.hpp>
#include <boost/format.hpp>
#include <boost/program_options.hpp>
#include <boost/thread.hpp>
@@ -65,7 +66,7 @@ static void checkEvents_SDL(ScreenManager& sm) {
sm.finished();
break;
case SDL_VIDEORESIZE:
- sm.window().resize(event.resize.w, event.resize.h);
+ //sm.window().resize(event.resize.w, event.resize.h);
break;
case SDL_KEYDOWN:
int keypressed = event.key.keysym.sym;
@@ -179,7 +180,7 @@ void mainLoop(std::string const& songlist) {
try {
// Draw
window.blank();
- sm.drawScreen();
+ window.render(boost::bind(&ScreenManager::drawScreen, &sm));
prof("draw");
// Display (and wait until next frame)
window.swap();
diff --git a/game/screenmanager.cc b/game/screenmanager.cc
index c47b9f9..847abcc 100644
--- a/game/screenmanager.cc
+++ b/game/screenmanager.cc
@@ -42,11 +42,8 @@ Screen* ScreenManager::getScreen(std::string const& name) {
}
void ScreenManager::drawScreen() {
- // Draw current frame for all the views
- for (unsigned i = 0; window().view(i); ++i) {
- getCurrentScreen()->draw();
- drawNotifications();
- }
+ getCurrentScreen()->draw();
+ drawNotifications();
}
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 336f179..08ce0ed 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -1,6 +1,7 @@
#include "video_driver.hh"
#include "config.hh"
+#include "fbo.hh"
#include "fs.hh"
#include "glmath.hh"
#include "image.hh"
@@ -79,6 +80,21 @@ void Window::blank() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
+void Window::render(boost::function<void (void)> drawFunc) {
+ // Draw current frame for all the views
+ FBO fbo[2];
+ for (unsigned i = 0; view(i); ++i) {
+ UseFBO user(fbo[i]);
+ drawFunc();
+ }
+ {
+ UseTexture use(fbo[0].getTexture());
+ glGenerateMipmap(GL_TEXTURE_2D);
+ }
+ //getCurrentScreen()->draw();
+ //fbo[0].getTexture().draw(Dimensions(1.0).center(0.0).middle(0.0), TexCoords());
+}
+
bool Window::view(unsigned num) {
// Setup the projection matrix for 2D translates
using namespace glmath;
diff --git a/game/video_driver.hh b/game/video_driver.hh
index 37f9f38..45ecf6b 100644
--- a/game/video_driver.hh
+++ b/game/video_driver.hh
@@ -2,6 +2,7 @@
#include "glshader.hh"
#include "glutil.hh"
+#include <boost/function.hpp>
#include <boost/scoped_ptr.hpp>
unsigned int screenW();
@@ -25,6 +26,7 @@ public:
Window(unsigned int windowW, unsigned int windowH, bool fullscreen);
/// destructor
~Window();
+ void render(boost::function<void (void)> drawFunc);
/// Setup everything for drawing a view.
/// @param num should be 0 the first time each frame then incremented for each additional view
/// @returns true if the view should be rendered, false if no more views are available
|