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 | 93f0e3f | 2011-10-09 16:16:18 +0100 | [diff] [blame] | 38 | bool |
| 39 | checkExtension(const char *extName, const char *extString) |
| 40 | { |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 41 | assert(extName); |
| 42 | assert(extString); |
| 43 | |
| 44 | const char *p = extString; |
| 45 | const char *q = extName; |
| 46 | char c; |
| 47 | do { |
| 48 | c = *p++; |
| 49 | if (c == '\0' || c == ' ') { |
| 50 | if (q && *q == '\0') { |
| 51 | return true; |
| 52 | } else { |
| 53 | q = extName; |
| 54 | } |
| 55 | } else { |
| 56 | if (q && *q == c) { |
| 57 | ++q; |
| 58 | } else { |
| 59 | q = 0; |
| 60 | } |
| 61 | } |
| 62 | } while (c); |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | |
José Fonseca | 3e899d7 | 2013-10-29 14:40:57 +0000 | [diff] [blame^] | 67 | void |
| 68 | Drawable::copySubBuffer(int x, int y, int width, int height) { |
| 69 | std::cerr << "warning: copySubBuffer not yet implemented\n"; |
| 70 | } |
| 71 | |
| 72 | |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 73 | bool |
| 74 | Context::hasExtension(const char *string) { |
| 75 | if (extensions.empty()) { |
| 76 | if (profile == PROFILE_CORE) { |
| 77 | // Use glGetStringi |
| 78 | GLint num_extensions = 0; |
| 79 | glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions); |
| 80 | for (int i = 0; i < num_extensions; ++i) { |
| 81 | const char *extension = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)); |
| 82 | if (extension) { |
| 83 | extensions.insert(extension); |
| 84 | } |
| 85 | } |
| 86 | } else { |
| 87 | // Use glGetString |
| 88 | const char *begin = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)); |
| 89 | do { |
| 90 | const char *end = begin; |
| 91 | char c = *end; |
| 92 | while (c != '\0' && c != ' ') { |
| 93 | ++end; |
| 94 | c = *end; |
| 95 | } |
| 96 | if (end != begin) { |
| 97 | extensions.insert(std::string(begin, end)); |
| 98 | } |
| 99 | |
| 100 | if (c == '\0') { |
| 101 | break; |
| 102 | } |
| 103 | begin = end + 1; |
| 104 | } while(1); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return extensions.find(string) != extensions.end(); |
José Fonseca | 93f0e3f | 2011-10-09 16:16:18 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | |
| 112 | } /* namespace glws */ |