use get proc address for opengl extension functions

This commit is contained in:
Eduardo Bart 2011-03-18 20:49:30 -03:00
parent 3164d7e691
commit f6dc07022c
3 changed files with 25 additions and 11 deletions

View File

@ -48,16 +48,18 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-D_DEBUG) ADD_DEFINITIONS(-D_DEBUG)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
# find sources
SET(SOURCES SET(SOURCES
# game sources
src/main.cpp
src/menustate.cpp src/menustate.cpp
# framework sources
src/framework/framebuffer.cpp src/framework/framebuffer.cpp
src/framework/textureloader.cpp src/framework/textureloader.cpp
src/framework/texture.cpp src/framework/texture.cpp
src/framework/texturemanager.cpp src/framework/texturemanager.cpp
src/framework/configmanager.cpp src/framework/configmanager.cpp
src/framework/resourcemanager.cpp src/framework/resourcemanager.cpp
src/main.cpp
src/framework/engine.cpp src/framework/engine.cpp
src/framework/graphics.cpp src/framework/graphics.cpp
src/framework/logger.cpp src/framework/logger.cpp

View File

@ -25,6 +25,12 @@
#include "platform.h" #include "platform.h"
#include "graphics.h" #include "graphics.h"
PFNGLGENFRAMEBUFFERSEXTPROC oglGenFramebuffersEXT = 0;
PFNGLBINDFRAMEBUFFEREXTPROC oglBindFramebufferEXT = 0;
PFNGLFRAMEBUFFERTEXTURE2DEXTPROC oglFramebufferTexture2DEXT = 0;
PFNGLDELETEFRAMEBUFFERSEXTPROC oglDeleteFramebuffersEXT = 0;
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC oglCheckFramebufferStatusEXT = 0;
FrameBuffer::FrameBuffer(int width, int height) FrameBuffer::FrameBuffer(int width, int height)
{ {
m_fbo = 0; m_fbo = 0;
@ -45,15 +51,22 @@ FrameBuffer::FrameBuffer(int width, int height)
// use FBO ext only if supported // use FBO ext only if supported
if(Platform::isExtensionSupported("EXT_framebuffer_object")) { if(Platform::isExtensionSupported("EXT_framebuffer_object")) {
m_fallbackOldImp = false; m_fallbackOldImp = false;
if(!oglGenFramebuffersEXT) {
oglGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)Platform::getExtensionProcAddress("glGenFramebuffersEXT");
oglBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)Platform::getExtensionProcAddress("glBindFramebufferEXT");
oglFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)Platform::getExtensionProcAddress("glFramebufferTexture2DEXT");
oglDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)Platform::getExtensionProcAddress("glDeleteFramebuffersEXT");
oglCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)Platform::getExtensionProcAddress("glCheckFramebufferStatusEXT");
}
// generate FBO // generate FBO
glGenFramebuffersEXT(1, &m_fbo); oglGenFramebuffersEXT(1, &m_fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
// attach 2D texture to this FBO // attach 2D texture to this FBO
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_fboTexture, 0); oglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_fboTexture, 0);
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); GLenum status = oglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
switch(status) { switch(status) {
case GL_FRAMEBUFFER_COMPLETE_EXT: case GL_FRAMEBUFFER_COMPLETE_EXT:
//ok //ok
@ -72,14 +85,14 @@ FrameBuffer::~FrameBuffer()
{ {
glDeleteTextures(1, &m_fboTexture); glDeleteTextures(1, &m_fboTexture);
if(m_fbo) if(m_fbo)
glDeleteFramebuffersEXT(1, &m_fbo); oglDeleteFramebuffersEXT(1, &m_fbo);
} }
void FrameBuffer::bind() void FrameBuffer::bind()
{ {
if(!m_fallbackOldImp) { if(!m_fallbackOldImp) {
// bind framebuffer // bind framebuffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
} }
// setup framebuffer viewport // setup framebuffer viewport
@ -101,7 +114,7 @@ void FrameBuffer::unbind()
{ {
if(!m_fallbackOldImp) { if(!m_fallbackOldImp) {
// bind back buffer again // bind back buffer again
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDrawBuffer(GL_BACK); glDrawBuffer(GL_BACK);
glReadBuffer(GL_BACK); glReadBuffer(GL_BACK);

View File

@ -81,7 +81,6 @@ typedef int8_t int8;
#define foreach BOOST_FOREACH #define foreach BOOST_FOREACH
// GL stuff // GL stuff
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
#include <GL/glext.h> #include <GL/glext.h>