framebuffer

This commit is contained in:
Eduardo Bart 2011-08-11 22:38:54 -03:00
parent 651315d4cd
commit 1a81d1520f
4 changed files with 25 additions and 1 deletions

View File

@ -34,6 +34,8 @@ PFNGLCHECKFRAMEBUFFERSTATUSPROC oglCheckFramebufferStatus = 0;
FrameBuffer::FrameBuffer(int width, int height) FrameBuffer::FrameBuffer(int width, int height)
{ {
g_graphics.disableDrawing();
m_fbo = 0; m_fbo = 0;
m_width = width; m_width = width;
m_height = height; m_height = height;
@ -50,7 +52,7 @@ FrameBuffer::FrameBuffer(int width, int height)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// use FBO ext only if supported // use FBO ext only if supported
if(g_graphics.isExtensionSupported("ARB_framebuffer_object")) { if(g_graphics.isExtensionSupported("GL_ARB_framebuffer_object")) {
m_fallbackOldImp = false; m_fallbackOldImp = false;
if(!oglGenFramebuffers) { if(!oglGenFramebuffers) {
oglGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)Platform::getExtensionProcAddress("glGenFramebuffers"); oglGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)Platform::getExtensionProcAddress("glGenFramebuffers");
@ -84,6 +86,8 @@ FrameBuffer::FrameBuffer(int width, int height)
FrameBuffer::~FrameBuffer() FrameBuffer::~FrameBuffer()
{ {
g_graphics.disableDrawing();
glDeleteTextures(1, &m_fboTexture); glDeleteTextures(1, &m_fboTexture);
if(m_fbo) if(m_fbo)
oglDeleteFramebuffers(1, &m_fbo); oglDeleteFramebuffers(1, &m_fbo);
@ -91,6 +95,8 @@ FrameBuffer::~FrameBuffer()
void FrameBuffer::bind() void FrameBuffer::bind()
{ {
g_graphics.disableDrawing();
if(!m_fallbackOldImp) { if(!m_fallbackOldImp) {
// bind framebuffer // bind framebuffer
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo); oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
@ -113,6 +119,8 @@ void FrameBuffer::bind()
void FrameBuffer::unbind() void FrameBuffer::unbind()
{ {
g_graphics.disableDrawing();
if(!m_fallbackOldImp) { if(!m_fallbackOldImp) {
// bind back buffer again // bind back buffer again
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); oglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
@ -137,6 +145,8 @@ void FrameBuffer::unbind()
void FrameBuffer::draw(int x, int y, int width, int height) void FrameBuffer::draw(int x, int y, int width, int height)
{ {
g_graphics.disableDrawing();
glBindTexture(GL_TEXTURE_2D, m_fboTexture); glBindTexture(GL_TEXTURE_2D, m_fboTexture);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex2i(x, y); glTexCoord2i(0, 0); glVertex2i(x, y);

View File

@ -27,6 +27,9 @@
#include <global.h> #include <global.h>
class FrameBuffer;
typedef std::shared_ptr<FrameBuffer> FrameBufferPtr;
class FrameBuffer class FrameBuffer
{ {
public: public:

View File

@ -3,6 +3,11 @@
void Map::draw(int x, int y, int width, int heigth) void Map::draw(int x, int y, int width, int heigth)
{ {
if(!m_framebuffer)
m_framebuffer = FrameBufferPtr(new FrameBuffer(19*32, 15*32));
m_framebuffer->bind();
Position playerPos = g_game.getPlayer()->getPosition(); Position playerPos = g_game.getPlayer()->getPosition();
for(int ix = 0; ix < 19; ++ix) { for(int ix = 0; ix < 19; ++ix) {
for(int iy = 0; iy < 15; ++iy) { for(int iy = 0; iy < 15; ++iy) {
@ -13,6 +18,9 @@ void Map::draw(int x, int y, int width, int heigth)
} }
} }
} }
m_framebuffer->unbind();
m_framebuffer->draw(0, 0, width, heigth);
} }
void Map::addThing(Thing *thing, const Position& pos) void Map::addThing(Thing *thing, const Position& pos)

View File

@ -3,6 +3,7 @@
#include "position.h" #include "position.h"
#include "tile.h" #include "tile.h"
#include <graphics/framebuffer.h>
class Map class Map
{ {
@ -14,6 +15,8 @@ public:
private: private:
// Visible tiles are 15x11, but we have a +3 value. We have 15 floors. // Visible tiles are 15x11, but we have a +3 value. We have 15 floors.
Tile m_map[19][15][15]; Tile m_map[19][15][15];
FrameBufferPtr m_framebuffer;
}; };
#endif // MAP_H #endif // MAP_H