blob: 2c0fa51e20b0febbebbcf87f2cef5ac3b3381280 [file] [log] [blame]
José Fonseca93f0e3f2011-10-09 16:16:18 +01001/**************************************************************************
2 *
3 * Copyright 2011 Jose Fonseca
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 **************************************************************************/
25
26
José Fonsecad1c301f2012-10-18 15:22:41 +010027#include <assert.h>
28
José Fonseca3e899d72013-10-29 14:40:57 +000029#include <iostream>
30
José Fonsecad1c301f2012-10-18 15:22:41 +010031#include "glproc.hpp"
José Fonseca93f0e3f2011-10-09 16:16:18 +010032#include "glws.hpp"
33
34
35namespace glws {
36
37
José Fonseca984010a2013-10-30 11:45:47 +000038void
39getProfileVersion(Profile profile, unsigned &major, unsigned &minor, bool &core)
40{
41 major = (profile >> 4) & 0xf;
42 minor = profile & 0xf;
43 core = isCoreProfile(profile);
44}
45
46
José Fonseca93f0e3f2011-10-09 16:16:18 +010047bool
48checkExtension(const char *extName, const char *extString)
49{
José Fonsecad1c301f2012-10-18 15:22:41 +010050 assert(extName);
José Fonsecaa69cd192014-05-28 18:29:33 +010051
52 if (!extString) {
53 return false;
54 }
José Fonsecad1c301f2012-10-18 15:22:41 +010055
56 const char *p = extString;
57 const char *q = extName;
58 char c;
59 do {
60 c = *p++;
61 if (c == '\0' || c == ' ') {
62 if (q && *q == '\0') {
63 return true;
64 } else {
65 q = extName;
66 }
67 } else {
68 if (q && *q == c) {
69 ++q;
70 } else {
71 q = 0;
72 }
73 }
74 } while (c);
75 return false;
76}
77
78
José Fonseca3e899d72013-10-29 14:40:57 +000079void
80Drawable::copySubBuffer(int x, int y, int width, int height) {
81 std::cerr << "warning: copySubBuffer not yet implemented\n";
82}
83
84
José Fonsecad1c301f2012-10-18 15:22:41 +010085bool
86Context::hasExtension(const char *string) {
87 if (extensions.empty()) {
José Fonseca0cab2bf2014-03-07 09:28:35 +000088 unsigned major, minor;
89 bool core;
90 getProfileVersion(profile, major, minor, core);
91 if (major >= 3) {
José Fonsecad1c301f2012-10-18 15:22:41 +010092 // Use glGetStringi
93 GLint num_extensions = 0;
94 glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
José Fonseca0cab2bf2014-03-07 09:28:35 +000095 assert(num_extensions);
José Fonsecad1c301f2012-10-18 15:22:41 +010096 for (int i = 0; i < num_extensions; ++i) {
97 const char *extension = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i));
José Fonseca0cab2bf2014-03-07 09:28:35 +000098 assert(extension);
José Fonsecad1c301f2012-10-18 15:22:41 +010099 if (extension) {
100 extensions.insert(extension);
101 }
102 }
103 } else {
104 // Use glGetString
105 const char *begin = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
José Fonseca0cab2bf2014-03-07 09:28:35 +0000106 assert(begin);
José Fonsecad1c301f2012-10-18 15:22:41 +0100107 do {
108 const char *end = begin;
109 char c = *end;
110 while (c != '\0' && c != ' ') {
111 ++end;
112 c = *end;
113 }
114 if (end != begin) {
115 extensions.insert(std::string(begin, end));
116 }
117
118 if (c == '\0') {
119 break;
120 }
121 begin = end + 1;
122 } while(1);
123 }
124 }
125
126 return extensions.find(string) != extensions.end();
José Fonseca93f0e3f2011-10-09 16:16:18 +0100127}
128
129
130} /* namespace glws */