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> |
| 28 | |
José Fonseca | 3e899d7 | 2013-10-29 14:40:57 +0000 | [diff] [blame] | 29 | #include <iostream> |
| 30 | |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 31 | #include "glproc.hpp" |
José Fonseca | 93f0e3f | 2011-10-09 16:16:18 +0100 | [diff] [blame] | 32 | #include "glws.hpp" |
| 33 | |
| 34 | |
| 35 | namespace glws { |
| 36 | |
| 37 | |
José Fonseca | 984010a | 2013-10-30 11:45:47 +0000 | [diff] [blame] | 38 | void |
| 39 | getProfileVersion(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é Fonseca | 93f0e3f | 2011-10-09 16:16:18 +0100 | [diff] [blame] | 47 | bool |
| 48 | checkExtension(const char *extName, const char *extString) |
| 49 | { |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 50 | assert(extName); |
José Fonseca | a69cd19 | 2014-05-28 18:29:33 +0100 | [diff] [blame^] | 51 | |
| 52 | if (!extString) { |
| 53 | return false; |
| 54 | } |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 55 | |
| 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é Fonseca | 3e899d7 | 2013-10-29 14:40:57 +0000 | [diff] [blame] | 79 | void |
| 80 | Drawable::copySubBuffer(int x, int y, int width, int height) { |
| 81 | std::cerr << "warning: copySubBuffer not yet implemented\n"; |
| 82 | } |
| 83 | |
| 84 | |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 85 | bool |
| 86 | Context::hasExtension(const char *string) { |
| 87 | if (extensions.empty()) { |
José Fonseca | 0cab2bf | 2014-03-07 09:28:35 +0000 | [diff] [blame] | 88 | unsigned major, minor; |
| 89 | bool core; |
| 90 | getProfileVersion(profile, major, minor, core); |
| 91 | if (major >= 3) { |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 92 | // Use glGetStringi |
| 93 | GLint num_extensions = 0; |
| 94 | glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions); |
José Fonseca | 0cab2bf | 2014-03-07 09:28:35 +0000 | [diff] [blame] | 95 | assert(num_extensions); |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 96 | for (int i = 0; i < num_extensions; ++i) { |
| 97 | const char *extension = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)); |
José Fonseca | 0cab2bf | 2014-03-07 09:28:35 +0000 | [diff] [blame] | 98 | assert(extension); |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 99 | 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é Fonseca | 0cab2bf | 2014-03-07 09:28:35 +0000 | [diff] [blame] | 106 | assert(begin); |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 107 | 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é Fonseca | 93f0e3f | 2011-10-09 16:16:18 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | |
| 130 | } /* namespace glws */ |