José Fonseca | 93f0e3f | 2011-10-09 16:16:18 +0100 | [diff] [blame] | 1 | /************************************************************************** |
| 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é Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 27 | #include <assert.h> |
Jose Fonseca | 1ec161c | 2015-06-27 18:28:13 +0100 | [diff] [blame] | 28 | #include <stdlib.h> |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 29 | |
José Fonseca | 3e899d7 | 2013-10-29 14:40:57 +0000 | [diff] [blame] | 30 | #include <iostream> |
| 31 | |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 32 | #include "glproc.hpp" |
José Fonseca | 93f0e3f | 2011-10-09 16:16:18 +0100 | [diff] [blame] | 33 | #include "glws.hpp" |
Brian Paul | 6cd0c80 | 2017-05-26 20:22:28 -0600 | [diff] [blame] | 34 | #include "retrace.hpp" |
José Fonseca | 93f0e3f | 2011-10-09 16:16:18 +0100 | [diff] [blame] | 35 | |
| 36 | |
| 37 | namespace glws { |
| 38 | |
| 39 | |
José Fonseca | 93f0e3f | 2011-10-09 16:16:18 +0100 | [diff] [blame] | 40 | bool |
| 41 | checkExtension(const char *extName, const char *extString) |
| 42 | { |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 43 | assert(extName); |
José Fonseca | a69cd19 | 2014-05-28 18:29:33 +0100 | [diff] [blame] | 44 | |
| 45 | if (!extString) { |
| 46 | return false; |
| 47 | } |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 48 | |
| 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é Fonseca | 3e899d7 | 2013-10-29 14:40:57 +0000 | [diff] [blame] | 72 | void |
| 73 | Drawable::copySubBuffer(int x, int y, int width, int height) { |
| 74 | std::cerr << "warning: copySubBuffer not yet implemented\n"; |
| 75 | } |
| 76 | |
| 77 | |
Jose Fonseca | c87689f | 2015-06-27 12:49:02 +0100 | [diff] [blame] | 78 | void |
| 79 | Context::initialize(void) |
| 80 | { |
| 81 | assert(!initialized); |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 82 | |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 83 | actualProfile = glfeatures::getCurrentContextProfile(); |
Jose Fonseca | 6d7ddcc | 2015-08-25 22:05:36 +0100 | [diff] [blame] | 84 | actualExtensions.getCurrentContextExtensions(actualProfile); |
Jose Fonseca | 8d6653a | 2016-04-04 15:42:25 +0100 | [diff] [blame] | 85 | actualFeatures.load(actualProfile, actualExtensions); |
Jose Fonseca | c87689f | 2015-06-27 12:49:02 +0100 | [diff] [blame] | 86 | |
Jose Fonseca | 276d225 | 2015-06-27 13:01:32 +0100 | [diff] [blame] | 87 | /* 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 Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 93 | glfeatures::Profile expectedProfile = profile; |
Brian Paul | 6cd0c80 | 2017-05-26 20:22:28 -0600 | [diff] [blame] | 94 | if (retrace::contextCheck && !actualProfile.matches(expectedProfile)) { |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 95 | if (expectedProfile.api == glfeatures::API_GLES && |
| 96 | actualProfile.api == glfeatures::API_GL && |
Jose Fonseca | 6d7ddcc | 2015-08-25 22:05:36 +0100 | [diff] [blame] | 97 | ((expectedProfile.major == 2 && actualExtensions.has("GL_ARB_ES2_compatibility")) || |
| 98 | (expectedProfile.major == 3 && actualExtensions.has("GL_ARB_ES3_compatibility")))) { |
Jose Fonseca | 276d225 | 2015-06-27 13:01:32 +0100 | [diff] [blame] | 99 | std::cerr << "warning: context mismatch:" |
| 100 | << " expected " << expectedProfile << "," |
Jose Fonseca | 6d7ddcc | 2015-08-25 22:05:36 +0100 | [diff] [blame] | 101 | << " but got " << actualProfile << " with GL_ARB_ES" << expectedProfile.major << "_compatibility\n"; |
Jose Fonseca | 276d225 | 2015-06-27 13:01:32 +0100 | [diff] [blame] | 102 | } else { |
Jose Fonseca | 6d7ddcc | 2015-08-25 22:05:36 +0100 | [diff] [blame] | 103 | std::cerr << "error: context mismatch: expected " << expectedProfile << ", but got " << actualProfile << "\n"; |
Jose Fonseca | 276d225 | 2015-06-27 13:01:32 +0100 | [diff] [blame] | 104 | exit(1); |
| 105 | } |
| 106 | } |
| 107 | |
Jose Fonseca | c87689f | 2015-06-27 12:49:02 +0100 | [diff] [blame] | 108 | initialized = true; |
José Fonseca | 93f0e3f | 2011-10-09 16:16:18 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | |
| 112 | } /* namespace glws */ |