Browse Source

use ARB extensions

Eduardo Bart 10 years ago
parent
commit
5142e912cc
3 changed files with 50 additions and 19 deletions
  1. 19
    19
      src/framework/framebuffer.cpp
  2. 29
    0
      src/framework/graphics.cpp
  3. 2
    0
      src/framework/graphics.h

+ 19
- 19
src/framework/framebuffer.cpp View File

@@ -25,11 +25,11 @@
25 25
 #include "platform.h"
26 26
 #include "graphics.h"
27 27
 
28
-PFNGLGENFRAMEBUFFERSEXTPROC         oglGenFramebuffersEXT = 0;
29
-PFNGLBINDFRAMEBUFFEREXTPROC         oglBindFramebufferEXT = 0;
30
-PFNGLFRAMEBUFFERTEXTURE2DEXTPROC    oglFramebufferTexture2DEXT = 0;
31
-PFNGLDELETEFRAMEBUFFERSEXTPROC      oglDeleteFramebuffersEXT = 0;
32
-PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC  oglCheckFramebufferStatusEXT = 0;
28
+PFNGLGENFRAMEBUFFERSPROC         oglGenFramebuffers = 0;
29
+PFNGLBINDFRAMEBUFFERPROC         oglBindFramebuffer = 0;
30
+PFNGLFRAMEBUFFERTEXTURE2DPROC    oglFramebufferTexture2D = 0;
31
+PFNGLDELETEFRAMEBUFFERSPROC      oglDeleteFramebuffers = 0;
32
+PFNGLCHECKFRAMEBUFFERSTATUSPROC  oglCheckFramebufferStatus = 0;
33 33
 
34 34
 FrameBuffer::FrameBuffer(int width, int height)
35 35
 {
@@ -49,24 +49,24 @@ FrameBuffer::FrameBuffer(int width, int height)
49 49
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
50 50
 
51 51
     // use FBO ext only if supported
52
-    if(Platform::isExtensionSupported("EXT_framebuffer_object")) {
52
+    if(g_graphics.isExtensionSupported("ARB_framebuffer_object")) {
53 53
         m_fallbackOldImp = false;
54
-        if(!oglGenFramebuffersEXT) {
55
-            oglGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)Platform::getExtensionProcAddress("glGenFramebuffersEXT");
56
-            oglBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)Platform::getExtensionProcAddress("glBindFramebufferEXT");
57
-            oglFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)Platform::getExtensionProcAddress("glFramebufferTexture2DEXT");
58
-            oglDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)Platform::getExtensionProcAddress("glDeleteFramebuffersEXT");
59
-            oglCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)Platform::getExtensionProcAddress("glCheckFramebufferStatusEXT");
54
+        if(!oglGenFramebuffers) {
55
+            oglGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)Platform::getExtensionProcAddress("glGenFramebuffers");
56
+            oglBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)Platform::getExtensionProcAddress("glBindFramebuffer");
57
+            oglFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)Platform::getExtensionProcAddress("glFramebufferTexture2D");
58
+            oglDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)Platform::getExtensionProcAddress("glDeleteFramebuffers");
59
+            oglCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)Platform::getExtensionProcAddress("glCheckFramebufferStatus");
60 60
         }
61 61
         
62 62
         // generate FBO
63
-        oglGenFramebuffersEXT(1, &m_fbo);
64
-        oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
63
+        oglGenFramebuffers(1, &m_fbo);
64
+        oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
65 65
 
66 66
         // attach 2D texture to this FBO
67
-        oglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_fboTexture, 0);
67
+        oglFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_fboTexture, 0);
68 68
 
69
-        GLenum status = oglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
69
+        GLenum status = oglCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
70 70
         switch(status) {
71 71
             case GL_FRAMEBUFFER_COMPLETE_EXT:
72 72
                 //ok
@@ -85,14 +85,14 @@ FrameBuffer::~FrameBuffer()
85 85
 {
86 86
     glDeleteTextures(1, &m_fboTexture);
87 87
     if(m_fbo)
88
-        oglDeleteFramebuffersEXT(1, &m_fbo);
88
+        oglDeleteFramebuffers(1, &m_fbo);
89 89
 }
90 90
 
91 91
 void FrameBuffer::bind()
92 92
 {
93 93
     if(!m_fallbackOldImp) {
94 94
         // bind framebuffer
95
-        oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
95
+        oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
96 96
     }
97 97
 
98 98
     // setup framebuffer viewport
@@ -114,7 +114,7 @@ void FrameBuffer::unbind()
114 114
 {
115 115
     if(!m_fallbackOldImp) {
116 116
         // bind back buffer again
117
-        oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
117
+        oglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
118 118
         glDrawBuffer(GL_BACK);
119 119
         glReadBuffer(GL_BACK);
120 120
 

+ 29
- 0
src/framework/graphics.cpp View File

@@ -58,6 +58,35 @@ void Graphics::terminate()
58 58
 
59 59
 }
60 60
 
61
+bool Graphics::isExtensionSupported(const char *extension)
62
+{
63
+    const GLubyte *extensions = NULL;
64
+    const GLubyte *start;
65
+    GLubyte *where, *terminator;
66
+    where = (GLubyte *)strchr(extension, ' ');
67
+
68
+    if(where || *extension == '\0')
69
+        return 0;
70
+
71
+    extensions = glGetString(GL_EXTENSIONS);
72
+
73
+    start = extensions;
74
+    while(true) {
75
+        where = (GLubyte *) strstr((const char *)start, extension);
76
+        if(!where)
77
+            break;
78
+
79
+        terminator = where + strlen(extension);
80
+
81
+        if(where == start || *(where - 1) == ' ')
82
+            if(*terminator == ' ' || *terminator == '\0')
83
+                return 1;
84
+
85
+        start = terminator;
86
+    }
87
+    return 0;
88
+}
89
+
61 90
 void Graphics::resize(int width, int height)
62 91
 {
63 92
     m_screenSize.setWidth(width);

+ 2
- 0
src/framework/graphics.h View File

@@ -41,6 +41,8 @@ public:
41 41
     void init();
42 42
     void terminate();
43 43
 
44
+    bool isExtensionSupported(const char *extension);
45
+
44 46
     /// Called after every window resize
45 47
     void resize(int width, int height);
46 48
 

Loading…
Cancel
Save