]> git.tdb.fi Git - libs/gl.git/blob - source/extension.cpp
e250bb249c9f04fd9fce24ebd3a42762ded9657d
[libs/gl.git] / source / extension.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <set>
9 #include <GL/gl.h>
10 #ifndef WIN32
11 #include <GL/glx.h>
12 #endif
13 #include <msp/strings/utils.h>
14 #include "arb_shader_objects.h"
15 #include "arb_vertex_shader.h"
16 #include "ext_framebuffer_object.h"
17 #include "except.h"
18 #include "extension.h"
19
20 using namespace std;
21
22 namespace Msp {
23 namespace GL {
24
25 bool is_supported(const string &ext)
26 {
27         static set<string> extensions;
28         static bool init_done=false;
29
30         if(!init_done)
31         {
32                 if(const char *gl_ext=reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)))
33                 {
34                         vector<string> exts=split(gl_ext);
35                         extensions.insert(exts.begin(), exts.end());
36                 }
37
38                 /* XXX Conceptually a bit weird place for this, but I couldn't really come up
39                    with anything better that would still be transparent. */
40                 if(extensions.count("GL_ARB_shader_objects"))
41                         init_arb_shader_objects();
42                 if(extensions.count("GL_ARB_vertex_shader"))
43                         init_arb_vertex_shader();
44                 if(extensions.count("GL_EXT_framebuffer_object"))
45                         init_ext_framebuffer_object();
46
47                 init_done=true;
48         }
49
50         return extensions.count(ext);
51 }
52
53 void require_extension(const string &ext)
54 {
55         if(!is_supported(ext))
56                 throw UnsupportedExtension(ext+" is not supported");
57 }
58
59 ExtFunc *get_proc_address(const string &name)
60 {
61 #ifndef WIN32
62         return glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(name.c_str()));
63 #endif
64 }
65
66 } // namespace GL
67 } // namespace Msp