use ARB extensions
This commit is contained in:
parent
f6dc07022c
commit
5142e912cc
|
@ -25,11 +25,11 @@
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
|
||||||
PFNGLGENFRAMEBUFFERSEXTPROC oglGenFramebuffersEXT = 0;
|
PFNGLGENFRAMEBUFFERSPROC oglGenFramebuffers = 0;
|
||||||
PFNGLBINDFRAMEBUFFEREXTPROC oglBindFramebufferEXT = 0;
|
PFNGLBINDFRAMEBUFFERPROC oglBindFramebuffer = 0;
|
||||||
PFNGLFRAMEBUFFERTEXTURE2DEXTPROC oglFramebufferTexture2DEXT = 0;
|
PFNGLFRAMEBUFFERTEXTURE2DPROC oglFramebufferTexture2D = 0;
|
||||||
PFNGLDELETEFRAMEBUFFERSEXTPROC oglDeleteFramebuffersEXT = 0;
|
PFNGLDELETEFRAMEBUFFERSPROC oglDeleteFramebuffers = 0;
|
||||||
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC oglCheckFramebufferStatusEXT = 0;
|
PFNGLCHECKFRAMEBUFFERSTATUSPROC oglCheckFramebufferStatus = 0;
|
||||||
|
|
||||||
FrameBuffer::FrameBuffer(int width, int height)
|
FrameBuffer::FrameBuffer(int width, int height)
|
||||||
{
|
{
|
||||||
|
@ -49,24 +49,24 @@ 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(Platform::isExtensionSupported("EXT_framebuffer_object")) {
|
if(g_graphics.isExtensionSupported("ARB_framebuffer_object")) {
|
||||||
m_fallbackOldImp = false;
|
m_fallbackOldImp = false;
|
||||||
if(!oglGenFramebuffersEXT) {
|
if(!oglGenFramebuffers) {
|
||||||
oglGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)Platform::getExtensionProcAddress("glGenFramebuffersEXT");
|
oglGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)Platform::getExtensionProcAddress("glGenFramebuffers");
|
||||||
oglBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)Platform::getExtensionProcAddress("glBindFramebufferEXT");
|
oglBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)Platform::getExtensionProcAddress("glBindFramebuffer");
|
||||||
oglFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)Platform::getExtensionProcAddress("glFramebufferTexture2DEXT");
|
oglFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)Platform::getExtensionProcAddress("glFramebufferTexture2D");
|
||||||
oglDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)Platform::getExtensionProcAddress("glDeleteFramebuffersEXT");
|
oglDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)Platform::getExtensionProcAddress("glDeleteFramebuffers");
|
||||||
oglCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)Platform::getExtensionProcAddress("glCheckFramebufferStatusEXT");
|
oglCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)Platform::getExtensionProcAddress("glCheckFramebufferStatus");
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate FBO
|
// generate FBO
|
||||||
oglGenFramebuffersEXT(1, &m_fbo);
|
oglGenFramebuffers(1, &m_fbo);
|
||||||
oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
|
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
|
||||||
|
|
||||||
// attach 2D texture to this FBO
|
// attach 2D texture to this FBO
|
||||||
oglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_fboTexture, 0);
|
oglFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_fboTexture, 0);
|
||||||
|
|
||||||
GLenum status = oglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
GLenum status = oglCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
||||||
//ok
|
//ok
|
||||||
|
@ -85,14 +85,14 @@ FrameBuffer::~FrameBuffer()
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &m_fboTexture);
|
glDeleteTextures(1, &m_fboTexture);
|
||||||
if(m_fbo)
|
if(m_fbo)
|
||||||
oglDeleteFramebuffersEXT(1, &m_fbo);
|
oglDeleteFramebuffers(1, &m_fbo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBuffer::bind()
|
void FrameBuffer::bind()
|
||||||
{
|
{
|
||||||
if(!m_fallbackOldImp) {
|
if(!m_fallbackOldImp) {
|
||||||
// bind framebuffer
|
// bind framebuffer
|
||||||
oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
|
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup framebuffer viewport
|
// setup framebuffer viewport
|
||||||
|
@ -114,7 +114,7 @@ void FrameBuffer::unbind()
|
||||||
{
|
{
|
||||||
if(!m_fallbackOldImp) {
|
if(!m_fallbackOldImp) {
|
||||||
// bind back buffer again
|
// bind back buffer again
|
||||||
oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
|
||||||
glDrawBuffer(GL_BACK);
|
glDrawBuffer(GL_BACK);
|
||||||
glReadBuffer(GL_BACK);
|
glReadBuffer(GL_BACK);
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,35 @@ void Graphics::terminate()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Graphics::isExtensionSupported(const char *extension)
|
||||||
|
{
|
||||||
|
const GLubyte *extensions = NULL;
|
||||||
|
const GLubyte *start;
|
||||||
|
GLubyte *where, *terminator;
|
||||||
|
where = (GLubyte *)strchr(extension, ' ');
|
||||||
|
|
||||||
|
if(where || *extension == '\0')
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
extensions = glGetString(GL_EXTENSIONS);
|
||||||
|
|
||||||
|
start = extensions;
|
||||||
|
while(true) {
|
||||||
|
where = (GLubyte *) strstr((const char *)start, extension);
|
||||||
|
if(!where)
|
||||||
|
break;
|
||||||
|
|
||||||
|
terminator = where + strlen(extension);
|
||||||
|
|
||||||
|
if(where == start || *(where - 1) == ' ')
|
||||||
|
if(*terminator == ' ' || *terminator == '\0')
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
start = terminator;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Graphics::resize(int width, int height)
|
void Graphics::resize(int width, int height)
|
||||||
{
|
{
|
||||||
m_screenSize.setWidth(width);
|
m_screenSize.setWidth(width);
|
||||||
|
|
|
@ -41,6 +41,8 @@ public:
|
||||||
void init();
|
void init();
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
|
bool isExtensionSupported(const char *extension);
|
||||||
|
|
||||||
/// Called after every window resize
|
/// Called after every window resize
|
||||||
void resize(int width, int height);
|
void resize(int width, int height);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue