| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the demonstration applications of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:BSD$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** BSD License Usage | 
| 18 | ** Alternatively, you may use this file under the terms of the BSD license | 
| 19 | ** as follows: | 
| 20 | ** | 
| 21 | ** "Redistribution and use in source and binary forms, with or without | 
| 22 | ** modification, are permitted provided that the following conditions are | 
| 23 | ** met: | 
| 24 | **   * Redistributions of source code must retain the above copyright | 
| 25 | **     notice, this list of conditions and the following disclaimer. | 
| 26 | **   * Redistributions in binary form must reproduce the above copyright | 
| 27 | **     notice, this list of conditions and the following disclaimer in | 
| 28 | **     the documentation and/or other materials provided with the | 
| 29 | **     distribution. | 
| 30 | **   * Neither the name of The Qt Company Ltd nor the names of its | 
| 31 | **     contributors may be used to endorse or promote products derived | 
| 32 | **     from this software without specific prior written permission. | 
| 33 | ** | 
| 34 | ** | 
| 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
| 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
| 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
| 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
| 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
| 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
| 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
| 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
| 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | 
| 46 | ** | 
| 47 | ** $QT_END_LICENSE$ | 
| 48 | ** | 
| 49 | ****************************************************************************/ | 
| 50 |  | 
| 51 | #ifndef GLEXTENSIONS_H | 
| 52 | #define GLEXTENSIONS_H | 
| 53 |  | 
| 54 | #include <QtOpenGL> | 
| 55 |  | 
| 56 | /* | 
| 57 | Functions resolved: | 
| 58 |  | 
| 59 | glGenFramebuffersEXT | 
| 60 | glGenRenderbuffersEXT | 
| 61 | glBindRenderbufferEXT | 
| 62 | glRenderbufferStorageEXT | 
| 63 | glDeleteFramebuffersEXT | 
| 64 | glDeleteRenderbuffersEXT | 
| 65 | glBindFramebufferEXT | 
| 66 | glFramebufferTexture2DEXT | 
| 67 | glFramebufferRenderbufferEXT | 
| 68 | glCheckFramebufferStatusEXT | 
| 69 |  | 
| 70 | glActiveTexture | 
| 71 | glTexImage3D | 
| 72 |  | 
| 73 | glGenBuffers | 
| 74 | glBindBuffer | 
| 75 | glBufferData | 
| 76 | glDeleteBuffers | 
| 77 | glMapBuffer | 
| 78 | glUnmapBuffer | 
| 79 | */ | 
| 80 |  | 
| 81 | #ifndef APIENTRY | 
| 82 | # define APIENTRY | 
| 83 | #endif | 
| 84 | #ifndef APIENTRYP | 
| 85 | # define APIENTRYP APIENTRY * | 
| 86 | #endif | 
| 87 |  | 
| 88 | #ifndef GL_VERSION_1_2 | 
| 89 | #define GL_TEXTURE_3D 0x806F | 
| 90 | #define GL_TEXTURE_WRAP_R 0x8072 | 
| 91 | #define GL_CLAMP_TO_EDGE 0x812F | 
| 92 | #define GL_BGRA 0x80E1 | 
| 93 | #endif | 
| 94 |  | 
| 95 | #ifndef GL_VERSION_1_3 | 
| 96 | #define GL_TEXTURE0 0x84C0 | 
| 97 | #define GL_TEXTURE1 0x84C1 | 
| 98 | #define GL_TEXTURE2 0x84C2 | 
| 99 | #define GL_TEXTURE_CUBE_MAP 0x8513 | 
| 100 | #define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 | 
| 101 | //#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 | 
| 102 | //#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 | 
| 103 | //#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 | 
| 104 | //#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 | 
| 105 | //#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A | 
| 106 | #endif | 
| 107 |  | 
| 108 | #ifndef GL_ARB_vertex_buffer_object | 
| 109 | typedef ptrdiff_t GLsizeiptrARB; | 
| 110 | #endif | 
| 111 |  | 
| 112 | #ifndef GL_VERSION_1_5 | 
| 113 | #define GL_ARRAY_BUFFER 0x8892 | 
| 114 | #define GL_ELEMENT_ARRAY_BUFFER 0x8893 | 
| 115 | #define GL_READ_WRITE 0x88BA | 
| 116 | #define GL_STATIC_DRAW 0x88E4 | 
| 117 | #endif | 
| 118 |  | 
| 119 | #ifndef GL_EXT_framebuffer_object | 
| 120 | #define GL_RENDERBUFFER_EXT 0x8D41 | 
| 121 | #define GL_FRAMEBUFFER_EXT 0x8D40 | 
| 122 | #define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 | 
| 123 | #define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 | 
| 124 | #define GL_DEPTH_ATTACHMENT_EXT 0x8D00 | 
| 125 | #endif | 
| 126 |  | 
| 127 | typedef void (APIENTRY *_glGenFramebuffersEXT) (GLsizei, GLuint *); | 
| 128 | typedef void (APIENTRY *_glGenRenderbuffersEXT) (GLsizei, GLuint *); | 
| 129 | typedef void (APIENTRY *_glBindRenderbufferEXT) (GLenum, GLuint); | 
| 130 | typedef void (APIENTRY *_glRenderbufferStorageEXT) (GLenum, GLenum, GLsizei, GLsizei); | 
| 131 | typedef void (APIENTRY *_glDeleteFramebuffersEXT) (GLsizei, const GLuint*); | 
| 132 | typedef void (APIENTRY *_glDeleteRenderbuffersEXT) (GLsizei, const GLuint*); | 
| 133 | typedef void (APIENTRY *_glBindFramebufferEXT) (GLenum, GLuint); | 
| 134 | typedef void (APIENTRY *_glFramebufferTexture2DEXT) (GLenum, GLenum, GLenum, GLuint, GLint); | 
| 135 | typedef void (APIENTRY *_glFramebufferRenderbufferEXT) (GLenum, GLenum, GLenum, GLuint); | 
| 136 | typedef GLenum (APIENTRY *_glCheckFramebufferStatusEXT) (GLenum); | 
| 137 |  | 
| 138 | typedef void (APIENTRY *_glActiveTexture) (GLenum); | 
| 139 | typedef void (APIENTRY *_glTexImage3D) (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); | 
| 140 |  | 
| 141 | typedef void (APIENTRY *_glGenBuffers) (GLsizei, GLuint *); | 
| 142 | typedef void (APIENTRY *_glBindBuffer) (GLenum, GLuint); | 
| 143 | typedef void (APIENTRY *_glBufferData) (GLenum, GLsizeiptrARB, const GLvoid *, GLenum); | 
| 144 | typedef void (APIENTRY *_glDeleteBuffers) (GLsizei, const GLuint *); | 
| 145 | typedef void *(APIENTRY *_glMapBuffer) (GLenum, GLenum); | 
| 146 | typedef GLboolean (APIENTRY *_glUnmapBuffer) (GLenum); | 
| 147 |  | 
| 148 | struct GLExtensionFunctions | 
| 149 | { | 
| 150 |     bool resolve(const QGLContext *context); | 
| 151 |  | 
| 152 |     bool fboSupported(); | 
| 153 |     bool openGL15Supported(); // the rest: multi-texture, 3D-texture, vertex buffer objects | 
| 154 |  | 
| 155 |     _glGenFramebuffersEXT GenFramebuffersEXT; | 
| 156 |     _glGenRenderbuffersEXT GenRenderbuffersEXT; | 
| 157 |     _glBindRenderbufferEXT BindRenderbufferEXT; | 
| 158 |     _glRenderbufferStorageEXT RenderbufferStorageEXT; | 
| 159 |     _glDeleteFramebuffersEXT DeleteFramebuffersEXT; | 
| 160 |     _glDeleteRenderbuffersEXT DeleteRenderbuffersEXT; | 
| 161 |     _glBindFramebufferEXT BindFramebufferEXT; | 
| 162 |     _glFramebufferTexture2DEXT FramebufferTexture2DEXT; | 
| 163 |     _glFramebufferRenderbufferEXT FramebufferRenderbufferEXT; | 
| 164 |     _glCheckFramebufferStatusEXT CheckFramebufferStatusEXT; | 
| 165 |  | 
| 166 |     _glActiveTexture ActiveTexture; | 
| 167 |     _glTexImage3D TexImage3D; | 
| 168 |  | 
| 169 |     _glGenBuffers GenBuffers; | 
| 170 |     _glBindBuffer BindBuffer; | 
| 171 |     _glBufferData BufferData; | 
| 172 |     _glDeleteBuffers DeleteBuffers; | 
| 173 |     _glMapBuffer MapBuffer; | 
| 174 |     _glUnmapBuffer UnmapBuffer; | 
| 175 | }; | 
| 176 |  | 
| 177 | inline GLExtensionFunctions &getGLExtensionFunctions() | 
| 178 | { | 
| 179 |     static GLExtensionFunctions funcs; | 
| 180 |     return funcs; | 
| 181 | } | 
| 182 |  | 
| 183 | #define glGenFramebuffersEXT getGLExtensionFunctions().GenFramebuffersEXT | 
| 184 | #define glGenRenderbuffersEXT getGLExtensionFunctions().GenRenderbuffersEXT | 
| 185 | #define glBindRenderbufferEXT getGLExtensionFunctions().BindRenderbufferEXT | 
| 186 | #define glRenderbufferStorageEXT getGLExtensionFunctions().RenderbufferStorageEXT | 
| 187 | #define glDeleteFramebuffersEXT getGLExtensionFunctions().DeleteFramebuffersEXT | 
| 188 | #define glDeleteRenderbuffersEXT getGLExtensionFunctions().DeleteRenderbuffersEXT | 
| 189 | #define glBindFramebufferEXT getGLExtensionFunctions().BindFramebufferEXT | 
| 190 | #define glFramebufferTexture2DEXT getGLExtensionFunctions().FramebufferTexture2DEXT | 
| 191 | #define glFramebufferRenderbufferEXT getGLExtensionFunctions().FramebufferRenderbufferEXT | 
| 192 | #define glCheckFramebufferStatusEXT getGLExtensionFunctions().CheckFramebufferStatusEXT | 
| 193 |  | 
| 194 | #define glActiveTexture getGLExtensionFunctions().ActiveTexture | 
| 195 | #define glTexImage3D getGLExtensionFunctions().TexImage3D | 
| 196 |  | 
| 197 | #define glGenBuffers getGLExtensionFunctions().GenBuffers | 
| 198 | #define glBindBuffer getGLExtensionFunctions().BindBuffer | 
| 199 | #define glBufferData getGLExtensionFunctions().BufferData | 
| 200 | #define glDeleteBuffers getGLExtensionFunctions().DeleteBuffers | 
| 201 | #define glMapBuffer getGLExtensionFunctions().MapBuffer | 
| 202 | #define glUnmapBuffer getGLExtensionFunctions().UnmapBuffer | 
| 203 |  | 
| 204 | #endif | 
| 205 |  |