3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
12 #include <msp/strings/formatter.h>
13 #include <msp/strings/utils.h>
14 #include "arb_shader_objects.h"
15 #include "arb_vertex_buffer_object.h"
16 #include "arb_vertex_shader.h"
17 #include "ext_framebuffer_object.h"
19 #include "extension.h"
21 #include "version_1_2.h"
22 #include "version_1_3.h"
29 bool is_supported(const string &ext)
31 static set<string> extensions;
32 static bool init_done=false;
36 if(const char *gl_ext=reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)))
38 vector<string> exts=split(gl_ext);
39 extensions.insert(exts.begin(), exts.end());
42 /* XXX Conceptually a bit weird place for this, but I couldn't really come up
43 with anything better that would still be transparent. */
44 if(extensions.count("GL_ARB_shader_objects"))
45 init_arb_shader_objects();
46 if(extensions.count("GL_ARB_vertex_shader"))
47 init_arb_vertex_shader();
48 if(extensions.count("GL_EXT_framebuffer_object"))
49 init_ext_framebuffer_object();
50 if(extensions.count("GL_ARB_vertex_buffer_object"))
51 init_arb_vertex_buffer_object();
56 return extensions.count(ext);
59 const Version &get_gl_version()
61 static Version version;
62 static bool init_done=false;
66 string gl_ver=reinterpret_cast<const char *>(glGetString(GL_VERSION));
67 vector<string> parts=split(gl_ver.substr(0, gl_ver.find(' ')), '.');
68 version.major=lexical_cast<unsigned>(parts[0]);
69 version.minor=lexical_cast<unsigned>(parts[1]);
71 unsigned combined=version.major*0x100+version.minor;
81 void require_extension(const string &ext)
83 if(!is_supported(ext))
84 throw UnsupportedExtension(ext);
87 void require_version(unsigned a, unsigned b)
89 const Version &ver=get_gl_version();
90 if(ver.major<a || (ver.major==a && ver.minor<b))
91 throw UnsupportedExtension(format("OpenGL %d.%d", a, b));
94 ExtFunc *get_proc_address(const string &name)
97 return glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(name.c_str()));
99 return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));