blob: 4d036ca33f6ea79f18e28a9b4872300920e1e9c3 [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>
Jose Fonseca1ec161c2015-06-27 18:28:13 +010028#include <stdlib.h>
José Fonsecad1c301f2012-10-18 15:22:41 +010029
José Fonseca3e899d72013-10-29 14:40:57 +000030#include <iostream>
31
José Fonsecad1c301f2012-10-18 15:22:41 +010032#include "glproc.hpp"
José Fonseca93f0e3f2011-10-09 16:16:18 +010033#include "glws.hpp"
34
35
36namespace glws {
37
38
José Fonseca93f0e3f2011-10-09 16:16:18 +010039bool
40checkExtension(const char *extName, const char *extString)
41{
José Fonsecad1c301f2012-10-18 15:22:41 +010042 assert(extName);
José Fonsecaa69cd192014-05-28 18:29:33 +010043
44 if (!extString) {
45 return false;
46 }
José Fonsecad1c301f2012-10-18 15:22:41 +010047
48 const char *p = extString;
49 const char *q = extName;
50 char c;
51 do {
52 c = *p++;
53 if (c == '\0' || c == ' ') {
54 if (q && *q == '\0') {
55 return true;
56 } else {
57 q = extName;
58 }
59 } else {
60 if (q && *q == c) {
61 ++q;
62 } else {
63 q = 0;
64 }
65 }
66 } while (c);
67 return false;
68}
69
70
José Fonseca3e899d72013-10-29 14:40:57 +000071void
72Drawable::copySubBuffer(int x, int y, int width, int height) {
73 std::cerr << "warning: copySubBuffer not yet implemented\n";
74}
75
76
Jose Fonsecac87689f2015-06-27 12:49:02 +010077void
78Context::initialize(void)
79{
80 assert(!initialized);
José Fonsecad1c301f2012-10-18 15:22:41 +010081
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +010082 actualProfile = glprofile::getCurrentContextProfile();
83 actualExtensions.getCurrentContextExtensions(actualProfile);
Jose Fonsecac87689f2015-06-27 12:49:02 +010084
Jose Fonseca276d2252015-06-27 13:01:32 +010085 /* Ensure we got a matching profile.
86 *
87 * In particular on MacOSX, there is no way to specify specific versions, so this is all we can do.
88 *
89 * Also, see if OpenGL ES can be handled through ARB_ES*_compatibility.
90 */
91 glprofile::Profile expectedProfile = profile;
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +010092 if (!actualProfile.matches(expectedProfile)) {
Jose Fonseca276d2252015-06-27 13:01:32 +010093 if (expectedProfile.api == glprofile::API_GLES &&
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +010094 actualProfile.api == glprofile::API_GL &&
95 ((expectedProfile.major == 2 && actualExtensions.has("GL_ARB_ES2_compatibility")) ||
96 (expectedProfile.major == 3 && actualExtensions.has("GL_ARB_ES3_compatibility")))) {
Jose Fonseca276d2252015-06-27 13:01:32 +010097 std::cerr << "warning: context mismatch:"
98 << " expected " << expectedProfile << ","
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +010099 << " but got " << actualProfile << " with GL_ARB_ES" << expectedProfile.major << "_compatibility\n";
Jose Fonseca276d2252015-06-27 13:01:32 +0100100 } else {
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +0100101 std::cerr << "error: context mismatch: expected " << expectedProfile << ", but got " << actualProfile << "\n";
Jose Fonseca276d2252015-06-27 13:01:32 +0100102 exit(1);
103 }
104 }
105
Jose Fonsecac87689f2015-06-27 12:49:02 +0100106 initialized = true;
José Fonseca93f0e3f2011-10-09 16:16:18 +0100107}
108
109
110} /* namespace glws */