blob: fb9f2e412cd4bc4b28e8be654bbbf745f945f34f [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"
Brian Paul6cd0c802017-05-26 20:22:28 -060034#include "retrace.hpp"
José Fonseca93f0e3f2011-10-09 16:16:18 +010035
36
37namespace glws {
38
39
José Fonseca93f0e3f2011-10-09 16:16:18 +010040bool
41checkExtension(const char *extName, const char *extString)
42{
José Fonsecad1c301f2012-10-18 15:22:41 +010043 assert(extName);
José Fonsecaa69cd192014-05-28 18:29:33 +010044
45 if (!extString) {
46 return false;
47 }
José Fonsecad1c301f2012-10-18 15:22:41 +010048
49 const char *p = extString;
50 const char *q = extName;
51 char c;
52 do {
53 c = *p++;
54 if (c == '\0' || c == ' ') {
55 if (q && *q == '\0') {
56 return true;
57 } else {
58 q = extName;
59 }
60 } else {
61 if (q && *q == c) {
62 ++q;
63 } else {
64 q = 0;
65 }
66 }
67 } while (c);
68 return false;
69}
70
71
José Fonseca3e899d72013-10-29 14:40:57 +000072void
73Drawable::copySubBuffer(int x, int y, int width, int height) {
74 std::cerr << "warning: copySubBuffer not yet implemented\n";
75}
76
77
Jose Fonsecac87689f2015-06-27 12:49:02 +010078void
79Context::initialize(void)
80{
81 assert(!initialized);
José Fonsecad1c301f2012-10-18 15:22:41 +010082
Jose Fonseca9ed64622016-04-04 13:36:12 +010083 actualProfile = glfeatures::getCurrentContextProfile();
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +010084 actualExtensions.getCurrentContextExtensions(actualProfile);
Jose Fonseca8d6653a2016-04-04 15:42:25 +010085 actualFeatures.load(actualProfile, actualExtensions);
Jose Fonsecac87689f2015-06-27 12:49:02 +010086
Jose Fonseca276d2252015-06-27 13:01:32 +010087 /* Ensure we got a matching profile.
88 *
89 * In particular on MacOSX, there is no way to specify specific versions, so this is all we can do.
90 *
91 * Also, see if OpenGL ES can be handled through ARB_ES*_compatibility.
92 */
Jose Fonseca9ed64622016-04-04 13:36:12 +010093 glfeatures::Profile expectedProfile = profile;
Brian Paul6cd0c802017-05-26 20:22:28 -060094 if (retrace::contextCheck && !actualProfile.matches(expectedProfile)) {
Jose Fonseca9ed64622016-04-04 13:36:12 +010095 if (expectedProfile.api == glfeatures::API_GLES &&
96 actualProfile.api == glfeatures::API_GL &&
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +010097 ((expectedProfile.major == 2 && actualExtensions.has("GL_ARB_ES2_compatibility")) ||
98 (expectedProfile.major == 3 && actualExtensions.has("GL_ARB_ES3_compatibility")))) {
Jose Fonseca276d2252015-06-27 13:01:32 +010099 std::cerr << "warning: context mismatch:"
100 << " expected " << expectedProfile << ","
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +0100101 << " but got " << actualProfile << " with GL_ARB_ES" << expectedProfile.major << "_compatibility\n";
Jose Fonseca276d2252015-06-27 13:01:32 +0100102 } else {
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +0100103 std::cerr << "error: context mismatch: expected " << expectedProfile << ", but got " << actualProfile << "\n";
Jose Fonseca276d2252015-06-27 13:01:32 +0100104 exit(1);
105 }
106 }
107
Jose Fonsecac87689f2015-06-27 12:49:02 +0100108 initialized = true;
José Fonseca93f0e3f2011-10-09 16:16:18 +0100109}
110
111
112} /* namespace glws */