3 #define GLX_GLXEXT_PROTOTYPES
6 #include <msp/strings/format.h>
7 #include <msp/strings/utils.h>
8 #include "arb_shader_objects.h"
9 #include "arb_uniform_buffer_object.h"
10 #include "arb_vertex_buffer_object.h"
11 #include "arb_vertex_program.h"
12 #include "arb_vertex_shader.h"
14 #include "ext_framebuffer_blit.h"
15 #include "ext_framebuffer_multisample.h"
16 #include "ext_framebuffer_object.h"
17 #include "extension.h"
19 #include "nv_primitive_restart.h"
20 #include "version_1_2.h"
21 #include "version_1_3.h"
28 bool is_supported(const string &ext)
30 static set<string> extensions;
31 static bool init_done = false;
35 if(const char *gl_ext = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)))
37 vector<string> exts = split(gl_ext);
38 extensions.insert(exts.begin(), exts.end());
41 /* XXX Conceptually a bit weird place for this, but I couldn't really come up
42 with anything better that would still be transparent. */
43 if(extensions.count("GL_ARB_shader_objects"))
44 init_arb_shader_objects();
45 if(extensions.count("GL_ARB_vertex_shader"))
46 init_arb_vertex_shader();
47 if(extensions.count("GL_ARB_vertex_program"))
48 init_arb_vertex_program();
49 if(extensions.count("GL_EXT_framebuffer_object"))
50 init_ext_framebuffer_object();
51 if(extensions.count("GL_EXT_framebuffer_blit"))
52 init_ext_framebuffer_blit();
53 if(extensions.count("GL_EXT_framebuffer_multisample"))
54 init_ext_framebuffer_multisample();
55 if(extensions.count("GL_ARB_vertex_buffer_object"))
56 init_arb_vertex_buffer_object();
57 if(extensions.count("GL_NV_primitive_restart"))
58 init_nv_primitive_restart();
59 if(extensions.count("GL_ARB_uniform_buffer_object"))
60 init_arb_uniform_buffer_object();
65 return extensions.count(ext);
68 void require_extension(const string &ext)
70 if(!is_supported(ext))
71 throw unsupported_extension(ext);
74 const Version &get_gl_version()
76 static Version version;
77 static bool init_done = false;
81 string gl_ver = reinterpret_cast<const char *>(glGetString(GL_VERSION));
82 vector<string> parts = split(gl_ver.substr(0, gl_ver.find(' ')), '.');
83 version.major = lexical_cast<unsigned>(parts[0]);
84 version.minor = lexical_cast<unsigned>(parts[1]);
86 unsigned combined = version.major*0x100+version.minor;
98 bool is_version_at_least(unsigned a, unsigned b)
100 const Version &ver = get_gl_version();
101 return (ver.major>a || (ver.major==a && ver.minor>=b));
104 void require_version(unsigned a, unsigned b)
106 if(!is_version_at_least(a, b))
107 throw unsupported_extension(format("OpenGL %d.%d", a, b));
110 ExtFunc *get_proc_address(const string &name)
113 return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));
115 return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));