]> git.tdb.fi Git - libs/gl.git/blob - source/extension.cpp
Make Material::apply const
[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 "except.h"
17 #include "extension.h"
18
19 using namespace std;
20
21 namespace Msp {
22 namespace GL {
23
24 bool is_supported(const string &ext)
25 {
26         static set<string> extensions;
27         static bool init_done=false;
28
29         if(!init_done)
30         {
31                 if(const char *gl_ext=reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)))
32                 {
33                         vector<string> exts=split(gl_ext);
34                         extensions.insert(exts.begin(), exts.end());
35                 }
36
37                 /* XXX Conceptually a bit weird place for this, but I couldn't really come up
38                    with anything better that would still be transparent. */
39                 if(extensions.count("GL_ARB_shader_objects"))
40                         init_arb_shader_objects();
41                 if(extensions.count("GL_ARB_vertex_shader"))
42                         init_arb_vertex_shader();
43
44                 init_done=true;
45         }
46
47         return extensions.count(ext);
48 }
49
50 void require_extension(const string &ext)
51 {
52         if(!is_supported(ext))
53                 throw UnsupportedExtension(ext+" is not supported");
54 }
55
56 ExtFunc *get_proc_address(const string &name)
57 {
58 #ifndef WIN32
59         return glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(name.c_str()));
60 #endif
61 }
62
63 } // namespace GL
64 } // namespace Msp