summaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2015-01-23 15:32:23 +0000
committerJosé Fonseca <jfonseca@vmware.com>2015-01-23 15:32:23 +0000
commit440d8aa290701a2f3014ad7da3423026afe930a3 (patch)
treebe2bb97c3dbf7a95779f9b02a614a199f101d87a /helpers
parent88c8971cc39f872de42654612a13a6137e4ab7bb (diff)
glhelpers,glws: Move extension management to helper module.
Diffstat (limited to 'helpers')
-rw-r--r--helpers/glprofile.cpp48
-rw-r--r--helpers/glprofile.hpp20
2 files changed, 65 insertions, 3 deletions
diff --git a/helpers/glprofile.cpp b/helpers/glprofile.cpp
index 0cfcaa45..6207094e 100644
--- a/helpers/glprofile.cpp
+++ b/helpers/glprofile.cpp
@@ -208,4 +208,52 @@ getCurrentContextProfile(void)
}
+void
+Extensions::getCurrentContextExtensions(const Profile & profile)
+{
+ assert(strings.empty());
+ if (profile.major >= 3) {
+ // Use glGetStringi
+ GLint num_strings = 0;
+ _glGetIntegerv(GL_NUM_EXTENSIONS, &num_strings);
+ assert(num_strings);
+ for (int i = 0; i < num_strings; ++i) {
+ const char *extension = reinterpret_cast<const char *>(_glGetStringi(GL_EXTENSIONS, i));
+ assert(extension);
+ if (extension) {
+ strings.insert(extension);
+ }
+ }
+ } else {
+ // Use glGetString
+ const char *begin = reinterpret_cast<const char *>(_glGetString(GL_EXTENSIONS));
+ assert(begin);
+ if (begin) {
+ do {
+ const char *end = begin;
+ char c = *end;
+ while (c != '\0' && c != ' ') {
+ ++end;
+ c = *end;
+ }
+ if (end != begin) {
+ strings.insert(std::string(begin, end));
+ }
+ if (c == '\0') {
+ break;
+ }
+ begin = end + 1;
+ } while(true);
+ }
+ }
+}
+
+
+bool
+Extensions::has(const char *string) const
+{
+ return strings.find(string) != strings.end();
+}
+
+
} /* namespace glprofile */
diff --git a/helpers/glprofile.hpp b/helpers/glprofile.hpp
index 5915e897..25f0a2d4 100644
--- a/helpers/glprofile.hpp
+++ b/helpers/glprofile.hpp
@@ -29,13 +29,14 @@
*/
-#include <ostream>
-
-
#ifndef GLPROFILE_HPP
#define GLPROFILE_HPP
+#include <ostream>
+#include <set>
+
+
namespace glprofile {
@@ -122,6 +123,19 @@ Profile
getCurrentContextProfile(void);
+struct Extensions
+{
+ std::set<std::string> strings;
+
+ void
+ getCurrentContextExtensions(const Profile & profile);
+
+ bool
+ has(const char *string) const;
+};
+
+
+
} /* namespace glprofile */