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_program.h"
17 #include "arb_vertex_shader.h"
18 #include "ext_framebuffer_object.h"
20 #include "extension.h"
22 #include "version_1_2.h"
23 #include "version_1_3.h"
30 bool is_supported(const string &ext)
32 static set<string> extensions;
33 static bool init_done=false;
37 if(const char *gl_ext=reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)))
39 vector<string> exts=split(gl_ext);
40 extensions.insert(exts.begin(), exts.end());
43 /* XXX Conceptually a bit weird place for this, but I couldn't really come up
44 with anything better that would still be transparent. */
45 if(extensions.count("GL_ARB_shader_objects"))
46 init_arb_shader_objects();
47 if(extensions.count("GL_ARB_vertex_shader"))
48 init_arb_vertex_shader();
49 if(extensions.count("GL_ARB_vertex_program"))
50 init_arb_vertex_program();
51 if(extensions.count("GL_EXT_framebuffer_object"))
52 init_ext_framebuffer_object();
53 if(extensions.count("GL_ARB_vertex_buffer_object"))
54 init_arb_vertex_buffer_object();
59 return extensions.count(ext);
62 const Version &get_gl_version()
64 static Version version;
65 static bool init_done=false;
69 string gl_ver=reinterpret_cast<const char *>(glGetString(GL_VERSION));
70 vector<string> parts=split(gl_ver.substr(0, gl_ver.find(' ')), '.');
71 version.major=lexical_cast<unsigned>(parts[0]);
72 version.minor=lexical_cast<unsigned>(parts[1]);
74 unsigned combined=version.major*0x100+version.minor;
84 void require_extension(const string &ext)
86 if(!is_supported(ext))
87 throw UnsupportedExtension(ext);
90 void require_version(unsigned a, unsigned b)
92 const Version &ver=get_gl_version();
93 if(ver.major<a || (ver.major==a && ver.minor<b))
94 throw UnsupportedExtension(format("OpenGL %d.%d", a, b));
97 ExtFunc *get_proc_address(const string &name)
100 return glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(name.c_str()));
102 return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));