1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtOpenGL module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qgl_p.h"
|
---|
43 |
|
---|
44 | QT_BEGIN_NAMESPACE
|
---|
45 |
|
---|
46 | static void *qt_gl_getProcAddress_search
|
---|
47 | (QGLContext *ctx, const char *name1, const char *name2,
|
---|
48 | const char *name3, const char *name4)
|
---|
49 | {
|
---|
50 | void *addr;
|
---|
51 |
|
---|
52 | addr = ctx->getProcAddress(QLatin1String(name1));
|
---|
53 | if (addr)
|
---|
54 | return addr;
|
---|
55 |
|
---|
56 | addr = ctx->getProcAddress(QLatin1String(name2));
|
---|
57 | if (addr)
|
---|
58 | return addr;
|
---|
59 |
|
---|
60 | addr = ctx->getProcAddress(QLatin1String(name3));
|
---|
61 | if (addr)
|
---|
62 | return addr;
|
---|
63 |
|
---|
64 | if (name4)
|
---|
65 | return ctx->getProcAddress(QLatin1String(name4));
|
---|
66 |
|
---|
67 | return 0;
|
---|
68 | }
|
---|
69 |
|
---|
70 | // Search for an extension function starting with the most likely
|
---|
71 | // function suffix first, and then trying the other variations.
|
---|
72 | #if defined(QT_OPENGL_ES)
|
---|
73 | #define qt_gl_getProcAddress(ctx,name) \
|
---|
74 | qt_gl_getProcAddress_search((ctx), name, name "OES", name "EXT", name "ARB")
|
---|
75 | #define qt_gl_getProcAddressEXT(ctx,name) \
|
---|
76 | qt_gl_getProcAddress_search((ctx), name "OES", name, name "EXT", name "ARB")
|
---|
77 | #define qt_gl_getProcAddressARB(ctx,name) \
|
---|
78 | qt_gl_getProcAddress_search((ctx), name "OES", name, name "ARB", name "EXT")
|
---|
79 | #define qt_gl_getProcAddressOES(ctx,name) \
|
---|
80 | qt_gl_getProcAddress_search((ctx), name "OES", name, name "EXT", name "ARB")
|
---|
81 | #else
|
---|
82 | #define qt_gl_getProcAddress(ctx,name) \
|
---|
83 | qt_gl_getProcAddress_search((ctx), name, name "ARB", name "EXT", 0)
|
---|
84 | #define qt_gl_getProcAddressEXT(ctx,name) \
|
---|
85 | qt_gl_getProcAddress_search((ctx), name "EXT", name, name "ARB", 0)
|
---|
86 | #define qt_gl_getProcAddressARB(ctx,name) \
|
---|
87 | qt_gl_getProcAddress_search((ctx), name "ARB", name, name "EXT", 0)
|
---|
88 | #define qt_gl_getProcAddressOES(ctx,name) \
|
---|
89 | qt_gl_getProcAddress_search((ctx), name "OES", name, name "EXT", name "ARB")
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | bool qt_resolve_framebufferobject_extensions(QGLContext *ctx)
|
---|
93 | {
|
---|
94 | #if defined(QT_OPENGL_ES_2)
|
---|
95 | static bool have_resolved = false;
|
---|
96 | if (have_resolved)
|
---|
97 | return true;
|
---|
98 | have_resolved = true;
|
---|
99 | #else
|
---|
100 | if (glIsRenderbuffer != 0)
|
---|
101 | return true;
|
---|
102 | #endif
|
---|
103 |
|
---|
104 | if (ctx == 0) {
|
---|
105 | qWarning("QGLFramebufferObject: Unable to resolve framebuffer object extensions -"
|
---|
106 | " make sure there is a current context when creating the framebuffer object.");
|
---|
107 | return false;
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | glBlitFramebufferEXT = (_glBlitFramebufferEXT) qt_gl_getProcAddressEXT(ctx, "glBlitFramebuffer");
|
---|
112 | glRenderbufferStorageMultisampleEXT =
|
---|
113 | (_glRenderbufferStorageMultisampleEXT) qt_gl_getProcAddressEXT(ctx, "glRenderbufferStorageMultisample");
|
---|
114 |
|
---|
115 | #if !defined(QT_OPENGL_ES_2)
|
---|
116 | glIsRenderbuffer = (_glIsRenderbuffer) qt_gl_getProcAddressEXT(ctx, "glIsRenderbuffer");
|
---|
117 | if (!glIsRenderbuffer)
|
---|
118 | return false; // Not much point searching for anything else.
|
---|
119 | glBindRenderbuffer = (_glBindRenderbuffer) qt_gl_getProcAddressEXT(ctx, "glBindRenderbuffer");
|
---|
120 | glDeleteRenderbuffers = (_glDeleteRenderbuffers) qt_gl_getProcAddressEXT(ctx, "glDeleteRenderbuffers");
|
---|
121 | glGenRenderbuffers = (_glGenRenderbuffers) qt_gl_getProcAddressEXT(ctx, "glGenRenderbuffers");
|
---|
122 | glRenderbufferStorage = (_glRenderbufferStorage) qt_gl_getProcAddressEXT(ctx, "glRenderbufferStorage");
|
---|
123 | glGetRenderbufferParameteriv =
|
---|
124 | (_glGetRenderbufferParameteriv) qt_gl_getProcAddressEXT(ctx, "glGetRenderbufferParameteriv");
|
---|
125 | glIsFramebuffer = (_glIsFramebuffer) qt_gl_getProcAddressEXT(ctx, "glIsFramebuffer");
|
---|
126 | glBindFramebuffer = (_glBindFramebuffer) qt_gl_getProcAddressEXT(ctx, "glBindFramebuffer");
|
---|
127 | glDeleteFramebuffers = (_glDeleteFramebuffers) qt_gl_getProcAddressEXT(ctx, "glDeleteFramebuffers");
|
---|
128 | glGenFramebuffers = (_glGenFramebuffers) qt_gl_getProcAddressEXT(ctx, "glGenFramebuffers");
|
---|
129 | glCheckFramebufferStatus = (_glCheckFramebufferStatus) qt_gl_getProcAddressEXT(ctx, "glCheckFramebufferStatus");
|
---|
130 | glFramebufferTexture2D = (_glFramebufferTexture2D) qt_gl_getProcAddressEXT(ctx, "glFramebufferTexture2D");
|
---|
131 | glFramebufferRenderbuffer = (_glFramebufferRenderbuffer) qt_gl_getProcAddressEXT(ctx, "glFramebufferRenderbuffer");
|
---|
132 | glGetFramebufferAttachmentParameteriv =
|
---|
133 | (_glGetFramebufferAttachmentParameteriv) qt_gl_getProcAddressEXT(ctx, "glGetFramebufferAttachmentParameteriv");
|
---|
134 | glGenerateMipmap = (_glGenerateMipmap) qt_gl_getProcAddressEXT(ctx, "glGenerateMipmap");
|
---|
135 |
|
---|
136 | return glIsRenderbuffer != 0;
|
---|
137 | #else
|
---|
138 | return true;
|
---|
139 | #endif
|
---|
140 | }
|
---|
141 |
|
---|
142 | #if !defined(QT_OPENGL_ES_2)
|
---|
143 | bool qt_resolve_version_1_3_functions(QGLContext *ctx)
|
---|
144 | {
|
---|
145 | if (glMultiTexCoord4f != 0)
|
---|
146 | return true;
|
---|
147 |
|
---|
148 | QGLContext cx(QGLFormat::defaultFormat());
|
---|
149 | glMultiTexCoord4f = (_glMultiTexCoord4f) ctx->getProcAddress(QLatin1String("glMultiTexCoord4f"));
|
---|
150 |
|
---|
151 | glActiveTexture = (_glActiveTexture) ctx->getProcAddress(QLatin1String("glActiveTexture"));
|
---|
152 | return glMultiTexCoord4f && glActiveTexture;
|
---|
153 | }
|
---|
154 | #endif
|
---|
155 |
|
---|
156 | #if !defined(QT_OPENGL_ES_2)
|
---|
157 | bool qt_resolve_stencil_face_extension(QGLContext *ctx)
|
---|
158 | {
|
---|
159 | if (glActiveStencilFaceEXT != 0)
|
---|
160 | return true;
|
---|
161 |
|
---|
162 | QGLContext cx(QGLFormat::defaultFormat());
|
---|
163 | glActiveStencilFaceEXT = (_glActiveStencilFaceEXT) ctx->getProcAddress(QLatin1String("glActiveStencilFaceEXT"));
|
---|
164 |
|
---|
165 | return glActiveStencilFaceEXT;
|
---|
166 | }
|
---|
167 | #endif
|
---|
168 |
|
---|
169 |
|
---|
170 | #if !defined(QT_OPENGL_ES_2)
|
---|
171 | bool qt_resolve_frag_program_extensions(QGLContext *ctx)
|
---|
172 | {
|
---|
173 | if (glProgramStringARB != 0)
|
---|
174 | return true;
|
---|
175 |
|
---|
176 | // ARB_fragment_program
|
---|
177 | glProgramStringARB = (_glProgramStringARB) ctx->getProcAddress(QLatin1String("glProgramStringARB"));
|
---|
178 | glBindProgramARB = (_glBindProgramARB) ctx->getProcAddress(QLatin1String("glBindProgramARB"));
|
---|
179 | glDeleteProgramsARB = (_glDeleteProgramsARB) ctx->getProcAddress(QLatin1String("glDeleteProgramsARB"));
|
---|
180 | glGenProgramsARB = (_glGenProgramsARB) ctx->getProcAddress(QLatin1String("glGenProgramsARB"));
|
---|
|
---|