blob: d791ff958f5206f2751f653d7ea60c0b42bfc7b4 [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é Fonseca93f0e3f2011-10-09 16:16:18 +010038bool
39checkExtension(const char *extName, const char *extString)
40{
José Fonsecad1c301f2012-10-18 15:22:41 +010041 assert(extName);
José Fonsecaa69cd192014-05-28 18:29:33 +010042
43 if (!extString) {
44 return false;
45 }
José Fonsecad1c301f2012-10-18 15:22:41 +010046
47 const char *p = extString;
48 const char *q = extName;
49 char c;
50 do {
51 c = *p++;
52 if (c == '\0' || c == ' ') {
53 if (q && *q == '\0') {
54 return true;
55 } else {
56 q = extName;
57 }
58 } else {
59 if (q && *q == c) {
60 ++q;
61 } else {
62 q = 0;
63 }
64 }
65 } while (c);
66 return false;
67}
68
69
José Fonseca3e899d72013-10-29 14:40:57 +000070void
71Drawable::copySubBuffer(int x, int y, int width, int height) {
72 std::cerr << "warning: copySubBuffer not yet implemented\n";
73}
74
75
Jose Fonsecac87689f2015-06-27 12:49:02 +010076void
77Context::initialize(void)
78{
79 assert(!initialized);
José Fonsecad1c301f2012-10-18 15:22:41 +010080
Jose Fonsecac87689f2015-06-27 12:49:02 +010081 extensions.getCurrentContextExtensions(profile);
82
Jose Fonseca276d2252015-06-27 13:01:32 +010083 /* Ensure we got a matching profile.
84 *
85 * In particular on MacOSX, there is no way to specify specific versions, so this is all we can do.
86 *
87 * Also, see if OpenGL ES can be handled through ARB_ES*_compatibility.
88 */
89 glprofile::Profile expectedProfile = profile;
90 glprofile::Profile currentProfile = glprofile::getCurrentContextProfile();
91 if (!currentProfile.matches(expectedProfile)) {
92 if (expectedProfile.api == glprofile::API_GLES &&
93 currentProfile.api == glprofile::API_GL &&
94 ((expectedProfile.major == 2 && extensions.has("GL_ARB_ES2_compatibility")) ||
95 (expectedProfile.major == 3 && extensions.has("GL_ARB_ES3_compatibility")))) {
96 std::cerr << "warning: context mismatch:"
97 << " expected " << expectedProfile << ","
98 << " but got " << currentProfile << " with GL_ARB_ES" << expectedProfile.major << "_compatibility\n";
99 } else {
100 std::cerr << "error: context mismatch: expected " << expectedProfile << ", but got " << currentProfile << "\n";
101 exit(1);
102 }
103 }
104
Jose Fonsecac87689f2015-06-27 12:49:02 +0100105 initialized = true;
José Fonseca93f0e3f2011-10-09 16:16:18 +0100106}
107
108
109} /* namespace glws */