]> git.tdb.fi Git - libs/gl.git/blobdiff - source/extension.h
Complete rewrite of extension handling
[libs/gl.git] / source / extension.h
index 4410cc3c316e244ec7ecd934e4668befffb6126d..e6c2aca045491e4a23005b87ac35d60c5cab3e64 100644 (file)
@@ -1,14 +1,7 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #ifndef MSP_GL_EXTENSION_H_
 #define MSP_GL_EXTENSION_H_
 
-#include <msp/core/except.h>
+#include <string>
 
 namespace Msp {
 namespace GL {
@@ -19,49 +12,52 @@ struct Version
        unsigned short minor;
 };
 
-typedef void ExtFunc();
 
-/**
-Indicates whether an extension is supported.  If this returns true, the
-functions of that extension are safe to use.
-*/
-bool is_supported(const std::string &);
+class Extension
+{
+public:
+       enum SupportLevel
+       {
+               UNSUPPORTED,
+               EXTENSION,
+               CORE
+       };
 
-/**
-Returns the OpenGL version number, as reported by the implementation.
-Functions up to the returned version are safe to use.
-*/
-const Version &get_gl_version();
+       typedef SupportLevel (*InitFunc)();
 
-/**
-Checks that an extension is supported and throws if it isn't.
-*/
-void require_extension(const std::string &);
+private:
+       const char *name;
+       InitFunc init_func;
+       mutable bool init_done;
+       mutable SupportLevel support;
 
-/**
-RAII version of require_extension.  Useful as a static local variable.
-*/
-struct RequireExtension
-{
-       RequireExtension(const std::string &e) { require_extension(e); }
+public:
+       Extension(const char *, InitFunc);
+
+       const char *get_name() const { return name; }
+       operator bool() const;
 };
 
-/**
-Checks that the OpenGL version is at least a.b and throws if it isn't.
-*/
-void require_version(unsigned a, unsigned b);
 
-/**
-RAII version of require_version.  Useful as a static local variable.
-*/
-struct RequireVersion
+struct Require
 {
-       RequireVersion(unsigned a, unsigned b) { require_version(a, b); }
+       Require(const Extension &);
 };
 
-/**
-Returns the address of an extension function.
-*/
+
+typedef void ExtFunc();
+
+/** Indicates whether an extension is supported. */
+bool is_supported(const std::string &);
+
+/** Returns the OpenGL version number, as reported by the implementation. */
+const Version &get_gl_version();
+
+/** Indicates whether the OpenGL version is at least a.b. */
+bool is_version_at_least(unsigned a, unsigned b);
+
+/** Returns the address of an extension function.  Only indended for internal
+use. */
 ExtFunc *get_proc_address(const std::string &);
 
 } // namespace GL