1 | /* $Id: VBoxGLSupportInfo.cpp 98281 2023-01-24 12:15:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - OpenGL support info used for 2D support detection.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.alldomusa.eu.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifdef RT_OS_WINDOWS
|
---|
29 | # include <iprt/win/windows.h> /* QGLWidget drags in Windows.h; -Wall forces us to use wrapper. */
|
---|
30 | # include <iprt/stdint.h> /* QGLWidget drags in stdint.h; -Wall forces us to use wrapper. */
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <QGuiApplication> /* For QT_VERSION */
|
---|
34 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
---|
35 | # include <QMainWindow>
|
---|
36 | # include <QOpenGLWidget>
|
---|
37 | # include <QOpenGLContext>
|
---|
38 | #else
|
---|
39 | # include <QGLWidget>
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/assert.h>
|
---|
43 | #include <iprt/log.h>
|
---|
44 | #include <iprt/env.h>
|
---|
45 | #include <iprt/param.h>
|
---|
46 | #include <iprt/path.h>
|
---|
47 | #include <iprt/process.h>
|
---|
48 | #include <iprt/string.h>
|
---|
49 | #include <iprt/time.h>
|
---|
50 | #include <iprt/thread.h>
|
---|
51 |
|
---|
52 | #include <VBox/VBoxGL2D.h>
|
---|
53 | #include "VBoxFBOverlayCommon.h"
|
---|
54 | #include <iprt/err.h>
|
---|
55 |
|
---|
56 |
|
---|
57 | /*****************/
|
---|
58 |
|
---|
59 | /* functions */
|
---|
60 |
|
---|
61 | PFNVBOXVHWA_ACTIVE_TEXTURE vboxglActiveTexture = NULL;
|
---|
62 | PFNVBOXVHWA_MULTI_TEX_COORD2I vboxglMultiTexCoord2i = NULL;
|
---|
63 | PFNVBOXVHWA_MULTI_TEX_COORD2D vboxglMultiTexCoord2d = NULL;
|
---|
64 | PFNVBOXVHWA_MULTI_TEX_COORD2F vboxglMultiTexCoord2f = NULL;
|
---|
65 |
|
---|
66 |
|
---|
67 | PFNVBOXVHWA_CREATE_SHADER vboxglCreateShader = NULL;
|
---|
68 | PFNVBOXVHWA_SHADER_SOURCE vboxglShaderSource = NULL;
|
---|
69 | PFNVBOXVHWA_COMPILE_SHADER vboxglCompileShader = NULL;
|
---|
70 | PFNVBOXVHWA_DELETE_SHADER vboxglDeleteShader = NULL;
|
---|
71 |
|
---|
72 | PFNVBOXVHWA_CREATE_PROGRAM vboxglCreateProgram = NULL;
|
---|
73 | PFNVBOXVHWA_ATTACH_SHADER vboxglAttachShader = NULL;
|
---|
74 | PFNVBOXVHWA_DETACH_SHADER vboxglDetachShader = NULL;
|
---|
75 | PFNVBOXVHWA_LINK_PROGRAM vboxglLinkProgram = NULL;
|
---|
76 | PFNVBOXVHWA_USE_PROGRAM vboxglUseProgram = NULL;
|
---|
77 | PFNVBOXVHWA_DELETE_PROGRAM vboxglDeleteProgram = NULL;
|
---|
78 |
|
---|
79 | PFNVBOXVHWA_IS_SHADER vboxglIsShader = NULL;
|
---|
80 | PFNVBOXVHWA_GET_SHADERIV vboxglGetShaderiv = NULL;
|
---|
81 | PFNVBOXVHWA_IS_PROGRAM vboxglIsProgram = NULL;
|
---|
82 | PFNVBOXVHWA_GET_PROGRAMIV vboxglGetProgramiv = NULL;
|
---|
83 | PFNVBOXVHWA_GET_ATTACHED_SHADERS vboxglGetAttachedShaders = NULL;
|
---|
84 | PFNVBOXVHWA_GET_SHADER_INFO_LOG vboxglGetShaderInfoLog = NULL;
|
---|
85 | PFNVBOXVHWA_GET_PROGRAM_INFO_LOG vboxglGetProgramInfoLog = NULL;
|
---|
86 |
|
---|
87 | PFNVBOXVHWA_GET_UNIFORM_LOCATION vboxglGetUniformLocation = NULL;
|
---|
88 |
|
---|
89 | PFNVBOXVHWA_UNIFORM1F vboxglUniform1f = NULL;
|
---|
90 | PFNVBOXVHWA_UNIFORM2F vboxglUniform2f = NULL;
|
---|
91 | PFNVBOXVHWA_UNIFORM3F vboxglUniform3f = NULL;
|
---|
92 | PFNVBOXVHWA_UNIFORM4F vboxglUniform4f = NULL;
|
---|
93 |
|
---|
94 | PFNVBOXVHWA_UNIFORM1I vboxglUniform1i = NULL;
|
---|
95 | PFNVBOXVHWA_UNIFORM2I vboxglUniform2i = NULL;
|
---|
96 | PFNVBOXVHWA_UNIFORM3I vboxglUniform3i = NULL;
|
---|
97 | PFNVBOXVHWA_UNIFORM4I vboxglUniform4i = NULL;
|
---|
98 |
|
---|
99 | PFNVBOXVHWA_GEN_BUFFERS vboxglGenBuffers = NULL;
|
---|
100 | PFNVBOXVHWA_DELETE_BUFFERS vboxglDeleteBuffers = NULL;
|
---|
101 | PFNVBOXVHWA_BIND_BUFFER vboxglBindBuffer = NULL;
|
---|
102 | PFNVBOXVHWA_BUFFER_DATA vboxglBufferData = NULL;
|
---|
103 | PFNVBOXVHWA_MAP_BUFFER vboxglMapBuffer = NULL;
|
---|
104 | PFNVBOXVHWA_UNMAP_BUFFER vboxglUnmapBuffer = NULL;
|
---|
105 |
|
---|
106 | PFNVBOXVHWA_IS_FRAMEBUFFER vboxglIsFramebuffer = NULL;
|
---|
107 | PFNVBOXVHWA_BIND_FRAMEBUFFER vboxglBindFramebuffer = NULL;
|
---|
108 | PFNVBOXVHWA_DELETE_FRAMEBUFFERS vboxglDeleteFramebuffers = NULL;
|
---|
109 | PFNVBOXVHWA_GEN_FRAMEBUFFERS vboxglGenFramebuffers = NULL;
|
---|
110 | PFNVBOXVHWA_CHECK_FRAMEBUFFER_STATUS vboxglCheckFramebufferStatus = NULL;
|
---|
111 | PFNVBOXVHWA_FRAMEBUFFER_TEXTURE1D vboxglFramebufferTexture1D = NULL;
|
---|
112 | PFNVBOXVHWA_FRAMEBUFFER_TEXTURE2D vboxglFramebufferTexture2D = NULL;
|
---|
113 | PFNVBOXVHWA_FRAMEBUFFER_TEXTURE3D vboxglFramebufferTexture3D = NULL;
|
---|
114 | PFNVBOXVHWA_GET_FRAMEBUFFER_ATTACHMENT_PARAMETRIV vboxglGetFramebufferAttachmentParameteriv = NULL;
|
---|
115 |
|
---|
116 | #define VBOXVHWA_GETPROCADDRESS(_c, _t, _n) ((_t)(uintptr_t)(_c).getProcAddress(_n))
|
---|
117 |
|
---|
118 | #define VBOXVHWA_PFNINIT_SAME(_c, _t, _v, _rc) \
|
---|
119 | do { \
|
---|
120 | if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v)) == NULL) \
|
---|
121 | { \
|
---|
122 | VBOXQGLLOGREL(("ERROR: '%s' function not found\n", "gl"#_v));\
|
---|
123 | AssertBreakpoint(); \
|
---|
124 | if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v"ARB")) == NULL) \
|
---|
125 | { \
|
---|
126 | VBOXQGLLOGREL(("ERROR: '%s' function not found\n", "gl"#_v"ARB"));\
|
---|
127 | AssertBreakpoint(); \
|
---|
128 | if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v"EXT")) == NULL) \
|
---|
129 | { \
|
---|
130 | VBOXQGLLOGREL(("ERROR: '%s' function not found\n", "gl"#_v"EXT"));\
|
---|
131 | AssertBreakpoint(); \
|
---|
132 | (_rc)++; \
|
---|
133 | } \
|
---|
134 | } \
|
---|
135 | } \
|
---|
136 | }while(0)
|
---|
137 |
|
---|
138 | #define VBOXVHWA_PFNINIT(_c, _t, _v, _f,_rc) \
|
---|
139 | do { \
|
---|
140 | if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_f)) == NULL) \
|
---|
141 | { \
|
---|
142 | VBOXQGLLOGREL(("ERROR: '%s' function is not found\n", "gl"#_f));\
|
---|
143 | AssertBreakpoint(); \
|
---|
144 | (_rc)++; \
|
---|
145 | } \
|
---|
146 | }while(0)
|
---|
147 |
|
---|
148 | #define VBOXVHWA_PFNINIT_OBJECT_ARB(_c, _t, _v, _rc) \
|
---|
149 | do { \
|
---|
150 | if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v"ObjectARB")) == NULL) \
|
---|
151 | { \
|
---|
152 | VBOXQGLLOGREL(("ERROR: '%s' function is not found\n", "gl"#_v"ObjectARB"));\
|
---|
153 | AssertBreakpoint(); \
|
---|
154 | (_rc)++; \
|
---|
155 | } \
|
---|
156 | }while(0)
|
---|
157 |
|
---|
158 | #define VBOXVHWA_PFNINIT_ARB(_c, _t, _v, _rc) \
|
---|
159 | do { \
|
---|
160 | if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v"ARB")) == NULL) \
|
---|
161 | { \
|
---|
162 | VBOXQGLLOGREL(("ERROR: '%s' function is not found\n", "gl"#_v"ARB"));\
|
---|
163 | AssertBreakpoint(); \
|
---|
164 | (_rc)++; \
|
---|
165 | } \
|
---|
166 | }while(0)
|
---|
167 |
|
---|
168 | #define VBOXVHWA_PFNINIT_EXT(_c, _t, _v, _rc) \
|
---|
169 | do { \
|
---|
170 | if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v"EXT")) == NULL) \
|
---|
171 | { \
|
---|
172 | VBOXQGLLOGREL(("ERROR: '%s' function is not found\n", "gl"#_v"EXT"));\
|
---|
173 | AssertBreakpoint(); \
|
---|
174 | (_rc)++; \
|
---|
175 | } \
|
---|
176 | }while(0)
|
---|
177 |
|
---|
178 | static int vboxVHWAGlParseSubver(const GLubyte * ver, const GLubyte ** pNext, bool bSpacePrefixAllowed)
|
---|
179 | {
|
---|
180 | int val = 0;
|
---|
181 |
|
---|
182 | for(;;++ver)
|
---|
183 | {
|
---|
184 | if(*ver >= '0' && *ver <= '9')
|
---|
185 | {
|
---|
186 | if(!val)
|
---|
187 | {
|
---|
188 | if(*ver == '0')
|
---|
189 | continue;
|
---|
190 | }
|
---|
191 | else
|
---|
192 | {
|
---|
193 | val *= 10;
|
---|
194 | }
|
---|
195 | val += *ver - '0';
|
---|
196 | }
|
---|
197 | else if(*ver == '.')
|
---|
198 | {
|
---|
199 | *pNext = ver+1;
|
---|
200 | break;
|
---|
201 | }
|
---|
202 | else if(*ver == '\0')
|
---|
203 | {
|
---|
204 | *pNext = NULL;
|
---|
205 | break;
|
---|
206 | }
|
---|
207 | else if(*ver == ' ' || *ver == '\t' || *ver == 0x0d || *ver == 0x0a)
|
---|
208 | {
|
---|
209 | if(bSpacePrefixAllowed)
|
---|
210 | {
|
---|
211 | if(!val)
|
---|
212 | {
|
---|
213 | continue;
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | /* treat this as the end ov version string */
|
---|
218 | *pNext = NULL;
|
---|
219 | break;
|
---|
220 | }
|
---|
221 | else
|
---|
222 | {
|
---|
223 | Assert(0);
|
---|
224 | val = -1;
|
---|
225 | break;
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | return val;
|
---|
230 | }
|
---|
231 |
|
---|
232 | /* static */
|
---|
233 | int VBoxGLInfo::parseVersion(const GLubyte * ver)
|
---|
234 | {
|
---|
235 | int iVer = vboxVHWAGlParseSubver(ver, &ver, true);
|
---|
236 | if(iVer)
|
---|
237 | {
|
---|
238 | iVer <<= 16;
|
---|
239 | if(ver)
|
---|
240 | {
|
---|
241 | int tmp = vboxVHWAGlParseSubver(ver, &ver, false);
|
---|
242 | if(tmp >= 0)
|
---|
243 | {
|
---|
244 | iVer |= tmp << 8;
|
---|
245 | if(ver)
|
---|
246 | {
|
---|
247 | tmp = vboxVHWAGlParseSubver(ver, &ver, false);
|
---|
248 | if(tmp >= 0)
|
---|
249 | {
|
---|
250 | iVer |= tmp;
|
---|
251 | }
|
---|
252 | else
|
---|
253 | {
|
---|
254 | Assert(0);
|
---|
255 | iVer = -1;
|
---|
256 | }
|
---|
257 | }
|
---|
258 | }
|
---|
259 | else
|
---|
260 | {
|
---|
261 | Assert(0);
|
---|
262 | iVer = -1;
|
---|
263 | }
|
---|
264 | }
|
---|
265 | }
|
---|
266 | return iVer;
|
---|
267 | }
|
---|
268 |
|
---|
269 | void VBoxGLInfo::init(const MY_QOpenGLContext *pContext)
|
---|
270 | {
|
---|
271 | if (mInitialized)
|
---|
272 | return;
|
---|
273 |
|
---|
274 | mInitialized = true;
|
---|
275 |
|
---|
276 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
---|
277 | if (!QGLFormat::hasOpenGL())
|
---|
278 | {
|
---|
279 | VBOXQGLLOGREL (("no gl support available\n"));
|
---|
280 | return;
|
---|
281 | }
|
---|
282 | #endif
|
---|
283 |
|
---|
284 | // pContext->makeCurrent();
|
---|
285 |
|
---|
286 | const GLubyte * str;
|
---|
287 | VBOXQGL_CHECKERR(
|
---|
288 | str = glGetString(GL_VERSION);
|
---|
289 | );
|
---|
290 |
|
---|
291 | if (str)
|
---|
292 | {
|
---|
293 | VBOXQGLLOGREL (("gl version string: 0%s\n", str));
|
---|
294 |
|
---|
295 | mGLVersion = parseVersion (str);
|
---|
296 | Assert(mGLVersion > 0);
|
---|
297 | if(mGLVersion < 0)
|
---|
298 | {
|
---|
299 | mGLVersion = 0;
|
---|
300 | }
|
---|
301 | else
|
---|
302 | {
|
---|
303 | VBOXQGLLOGREL (("gl version: 0x%x\n", mGLVersion));
|
---|
304 | VBOXQGL_CHECKERR(
|
---|
305 | str = glGetString (GL_EXTENSIONS);
|
---|
306 | );
|
---|
307 |
|
---|
308 | VBOXQGLLOGREL (("gl extensions: %s\n", str));
|
---|
309 |
|
---|
310 | const char * pos = strstr((const char *)str, "GL_ARB_multitexture");
|
---|
311 | m_GL_ARB_multitexture = pos != NULL;
|
---|
312 | VBOXQGLLOGREL (("GL_ARB_multitexture: %d\n", m_GL_ARB_multitexture));
|
---|
313 |
|
---|
314 | pos = strstr((const char *)str, "GL_ARB_shader_objects");
|
---|
315 | m_GL_ARB_shader_objects = pos != NULL;
|
---|
316 | VBOXQGLLOGREL (("GL_ARB_shader_objects: %d\n", m_GL_ARB_shader_objects));
|
---|
317 |
|
---|
318 | pos = strstr((const char *)str, "GL_ARB_fragment_shader");
|
---|
319 | m_GL_ARB_fragment_shader = pos != NULL;
|
---|
320 | VBOXQGLLOGREL (("GL_ARB_fragment_shader: %d\n", m_GL_ARB_fragment_shader));
|
---|
321 |
|
---|
322 | pos = strstr((const char *)str, "GL_ARB_pixel_buffer_object");
|
---|
323 | m_GL_ARB_pixel_buffer_object = pos != NULL;
|
---|
324 | VBOXQGLLOGREL (("GL_ARB_pixel_buffer_object: %d\n", m_GL_ARB_pixel_buffer_object));
|
---|
325 |
|
---|
326 | pos = strstr((const char *)str, "GL_ARB_texture_rectangle");
|
---|
327 | m_GL_ARB_texture_rectangle = pos != NULL;
|
---|
328 | VBOXQGLLOGREL (("GL_ARB_texture_rectangle: %d\n", m_GL_ARB_texture_rectangle));
|
---|
329 |
|
---|
330 | pos = strstr((const char *)str, "GL_EXT_texture_rectangle");
|
---|
331 | m_GL_EXT_texture_rectangle = pos != NULL;
|
---|
332 | VBOXQGLLOGREL (("GL_EXT_texture_rectangle: %d\n", m_GL_EXT_texture_rectangle));
|
---|
333 |
|
---|
334 | pos = strstr((const char *)str, "GL_NV_texture_rectangle");
|
---|
335 | m_GL_NV_texture_rectangle = pos != NULL;
|
---|
336 | VBOXQGLLOGREL (("GL_NV_texture_rectangle: %d\n", m_GL_NV_texture_rectangle));
|
---|
337 |
|
---|
338 | pos = strstr((const char *)str, "GL_ARB_texture_non_power_of_two");
|
---|
339 | m_GL_ARB_texture_non_power_of_two = pos != NULL;
|
---|
340 | VBOXQGLLOGREL (("GL_ARB_texture_non_power_of_two: %d\n", m_GL_ARB_texture_non_power_of_two));
|
---|
341 |
|
---|
342 | pos = strstr((const char *)str, "GL_EXT_framebuffer_object");
|
---|
343 | m_GL_EXT_framebuffer_object = pos != NULL;
|
---|
344 | VBOXQGLLOGREL (("GL_EXT_framebuffer_object: %d\n", m_GL_EXT_framebuffer_object));
|
---|
345 |
|
---|
346 |
|
---|
347 | initExtSupport(*pContext);
|
---|
348 | }
|
---|
349 | }
|
---|
350 | else
|
---|
351 | {
|
---|
352 | VBOXQGLLOGREL (("failed to make the context current, treating as unsupported\n"));
|
---|
353 | }
|
---|
354 | }
|
---|
355 |
|
---|
356 | void VBoxGLInfo::initExtSupport(const MY_QOpenGLContext &context)
|
---|
357 | {
|
---|
358 | int vrc = VINF_SUCCESS;
|
---|
359 | do
|
---|
360 | {
|
---|
361 | mMultiTexNumSupported = 1; /* default, 1 means not supported */
|
---|
362 | if(mGLVersion >= 0x010201) /* ogl >= 1.2.1 */
|
---|
363 | {
|
---|
364 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_ACTIVE_TEXTURE, ActiveTexture, vrc);
|
---|
365 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_MULTI_TEX_COORD2I, MultiTexCoord2i, vrc);
|
---|
366 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_MULTI_TEX_COORD2D, MultiTexCoord2d, vrc);
|
---|
367 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_MULTI_TEX_COORD2F, MultiTexCoord2f, vrc);
|
---|
368 | }
|
---|
369 | else if(m_GL_ARB_multitexture)
|
---|
370 | {
|
---|
371 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_ACTIVE_TEXTURE, ActiveTexture, vrc);
|
---|
372 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MULTI_TEX_COORD2I, MultiTexCoord2i, vrc);
|
---|
373 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MULTI_TEX_COORD2D, MultiTexCoord2d, vrc);
|
---|
374 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MULTI_TEX_COORD2F, MultiTexCoord2f, vrc);
|
---|
375 | }
|
---|
376 | else
|
---|
377 | {
|
---|
378 | break;
|
---|
379 | }
|
---|
380 |
|
---|
381 | if(RT_FAILURE(vrc))
|
---|
382 | break;
|
---|
383 |
|
---|
384 | GLint maxCoords, maxUnits;
|
---|
385 | glGetIntegerv(GL_MAX_TEXTURE_COORDS, &maxCoords);
|
---|
386 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxUnits);
|
---|
387 |
|
---|
388 | VBOXQGLLOGREL(("Max Tex Coords (%d), Img Units (%d)\n", maxCoords, maxUnits));
|
---|
389 | /* take the minimum of those */
|
---|
390 | if(maxUnits < maxCoords)
|
---|
391 | maxCoords = maxUnits;
|
---|
392 | if(maxUnits < 2)
|
---|
393 | {
|
---|
394 | VBOXQGLLOGREL(("Max Tex Coord or Img Units < 2 disabling MultiTex support\n"));
|
---|
395 | break;
|
---|
396 | }
|
---|
397 |
|
---|
398 | mMultiTexNumSupported = maxUnits;
|
---|
399 | }while(0);
|
---|
400 |
|
---|
401 |
|
---|
402 | do
|
---|
403 | {
|
---|
404 | vrc = 0;
|
---|
405 | mPBOSupported = false;
|
---|
406 |
|
---|
407 | if(m_GL_ARB_pixel_buffer_object)
|
---|
408 | {
|
---|
409 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_GEN_BUFFERS, GenBuffers, vrc);
|
---|
410 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_DELETE_BUFFERS, DeleteBuffers, vrc);
|
---|
411 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_BIND_BUFFER, BindBuffer, vrc);
|
---|
412 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_BUFFER_DATA, BufferData, vrc);
|
---|
413 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MAP_BUFFER, MapBuffer, vrc);
|
---|
414 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNMAP_BUFFER, UnmapBuffer, vrc);
|
---|
415 | }
|
---|
416 | else
|
---|
417 | {
|
---|
418 | break;
|
---|
419 | }
|
---|
420 |
|
---|
421 | if(RT_FAILURE(vrc))
|
---|
422 | break;
|
---|
423 |
|
---|
424 | mPBOSupported = true;
|
---|
425 | } while(0);
|
---|
426 |
|
---|
427 | do
|
---|
428 | {
|
---|
429 | vrc = 0;
|
---|
430 | mFragmentShaderSupported = false;
|
---|
431 |
|
---|
432 | if(mGLVersion >= 0x020000) /* if ogl >= 2.0*/
|
---|
433 | {
|
---|
434 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_CREATE_SHADER, CreateShader, vrc);
|
---|
435 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_SHADER_SOURCE, ShaderSource, vrc);
|
---|
436 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_COMPILE_SHADER, CompileShader, vrc);
|
---|
437 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_DELETE_SHADER, DeleteShader, vrc);
|
---|
438 |
|
---|
439 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_CREATE_PROGRAM, CreateProgram, vrc);
|
---|
440 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_ATTACH_SHADER, AttachShader, vrc);
|
---|
441 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_DETACH_SHADER, DetachShader, vrc);
|
---|
442 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_LINK_PROGRAM, LinkProgram, vrc);
|
---|
443 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_USE_PROGRAM, UseProgram, vrc);
|
---|
444 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_DELETE_PROGRAM, DeleteProgram, vrc);
|
---|
445 |
|
---|
446 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_IS_SHADER, IsShader, vrc);
|
---|
447 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_SHADERIV, GetShaderiv, vrc);
|
---|
448 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_IS_PROGRAM, IsProgram, vrc);
|
---|
449 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_PROGRAMIV, GetProgramiv, vrc);
|
---|
450 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_ATTACHED_SHADERS, GetAttachedShaders, vrc);
|
---|
451 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_SHADER_INFO_LOG, GetShaderInfoLog, vrc);
|
---|
452 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_PROGRAM_INFO_LOG, GetProgramInfoLog, vrc);
|
---|
453 |
|
---|
454 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_UNIFORM_LOCATION, GetUniformLocation, vrc);
|
---|
455 |
|
---|
456 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM1F, Uniform1f, vrc);
|
---|
457 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM2F, Uniform2f, vrc);
|
---|
458 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM3F, Uniform3f, vrc);
|
---|
459 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM4F, Uniform4f, vrc);
|
---|
460 |
|
---|
461 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM1I, Uniform1i, vrc);
|
---|
462 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM2I, Uniform2i, vrc);
|
---|
463 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM3I, Uniform3i, vrc);
|
---|
464 | VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM4I, Uniform4i, vrc);
|
---|
465 | }
|
---|
466 | else if(m_GL_ARB_shader_objects && m_GL_ARB_fragment_shader)
|
---|
467 | {
|
---|
468 | VBOXVHWA_PFNINIT_OBJECT_ARB(context, PFNVBOXVHWA_CREATE_SHADER, CreateShader, vrc);
|
---|
469 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_SHADER_SOURCE, ShaderSource, vrc);
|
---|
470 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_COMPILE_SHADER, CompileShader, vrc);
|
---|
471 | VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_DELETE_SHADER, DeleteShader, DeleteObjectARB, vrc);
|
---|
472 |
|
---|
473 | VBOXVHWA_PFNINIT_OBJECT_ARB(context, PFNVBOXVHWA_CREATE_PROGRAM, CreateProgram, vrc);
|
---|
474 | VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_ATTACH_SHADER, AttachShader, AttachObjectARB, vrc);
|
---|
475 | VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_DETACH_SHADER, DetachShader, DetachObjectARB, vrc);
|
---|
476 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_LINK_PROGRAM, LinkProgram, vrc);
|
---|
477 | VBOXVHWA_PFNINIT_OBJECT_ARB(context, PFNVBOXVHWA_USE_PROGRAM, UseProgram, vrc);
|
---|
478 | VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_DELETE_PROGRAM, DeleteProgram, DeleteObjectARB, vrc);
|
---|
479 |
|
---|
480 | /// @todo VBOXVHWA_PFNINIT(PFNVBOXVHWA_IS_SHADER, IsShader, vrc);
|
---|
481 | VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_SHADERIV, GetShaderiv, GetObjectParameterivARB, vrc);
|
---|
482 | /// @todo VBOXVHWA_PFNINIT(PFNVBOXVHWA_IS_PROGRAM, IsProgram, vrc);
|
---|
483 | VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_PROGRAMIV, GetProgramiv, GetObjectParameterivARB, vrc);
|
---|
484 | VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_ATTACHED_SHADERS, GetAttachedShaders, GetAttachedObjectsARB, vrc);
|
---|
485 | VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_SHADER_INFO_LOG, GetShaderInfoLog, GetInfoLogARB, vrc);
|
---|
486 | VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_PROGRAM_INFO_LOG, GetProgramInfoLog, GetInfoLogARB, vrc);
|
---|
487 |
|
---|
488 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_GET_UNIFORM_LOCATION, GetUniformLocation, vrc);
|
---|
489 |
|
---|
490 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM1F, Uniform1f, vrc);
|
---|
491 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM2F, Uniform2f, vrc);
|
---|
492 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM3F, Uniform3f, vrc);
|
---|
493 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM4F, Uniform4f, vrc);
|
---|
494 |
|
---|
495 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM1I, Uniform1i, vrc);
|
---|
496 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM2I, Uniform2i, vrc);
|
---|
497 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM3I, Uniform3i, vrc);
|
---|
498 | VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM4I, Uniform4i, vrc);
|
---|
499 | }
|
---|
500 | else
|
---|
501 | {
|
---|
502 | break;
|
---|
503 | }
|
---|
504 |
|
---|
505 | if(RT_FAILURE(vrc))
|
---|
506 | break;
|
---|
507 |
|
---|
508 | mFragmentShaderSupported = true;
|
---|
509 | } while(0);
|
---|
510 |
|
---|
511 | do
|
---|
512 | {
|
---|
513 | vrc = 0;
|
---|
514 | mFBOSupported = false;
|
---|
515 |
|
---|
516 | if(m_GL_EXT_framebuffer_object)
|
---|
517 | {
|
---|
518 | VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_IS_FRAMEBUFFER, IsFramebuffer, vrc);
|
---|
519 | VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_BIND_FRAMEBUFFER, BindFramebuffer, vrc);
|
---|
520 | VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_DELETE_FRAMEBUFFERS, DeleteFramebuffers, vrc);
|
---|
521 | VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_GEN_FRAMEBUFFERS, GenFramebuffers, vrc);
|
---|
522 | VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_CHECK_FRAMEBUFFER_STATUS, CheckFramebufferStatus, vrc);
|
---|
523 | VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_FRAMEBUFFER_TEXTURE1D, FramebufferTexture1D, vrc);
|
---|
524 | VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_FRAMEBUFFER_TEXTURE2D, FramebufferTexture2D, vrc);
|
---|
525 | VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_FRAMEBUFFER_TEXTURE3D, FramebufferTexture3D, vrc);
|
---|
526 | VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_GET_FRAMEBUFFER_ATTACHMENT_PARAMETRIV, GetFramebufferAttachmentParameteriv, vrc);
|
---|
527 | }
|
---|
528 | else
|
---|
529 | {
|
---|
530 | break;
|
---|
531 | }
|
---|
532 |
|
---|
533 | if(RT_FAILURE(vrc))
|
---|
534 | break;
|
---|
535 |
|
---|
536 | mFBOSupported = true;
|
---|
537 | } while(0);
|
---|
538 |
|
---|
539 | if(m_GL_ARB_texture_rectangle || m_GL_EXT_texture_rectangle || m_GL_NV_texture_rectangle)
|
---|
540 | {
|
---|
541 | mTextureRectangleSupported = true;
|
---|
542 | }
|
---|
543 | else
|
---|
544 | {
|
---|
545 | mTextureRectangleSupported = false;
|
---|
546 | }
|
---|
547 |
|
---|
548 | mTextureNP2Supported = m_GL_ARB_texture_non_power_of_two;
|
---|
549 | }
|
---|
550 |
|
---|
551 | void VBoxVHWAInfo::init(const MY_QOpenGLContext *pContext)
|
---|
552 | {
|
---|
553 | if(mInitialized)
|
---|
554 | return;
|
---|
555 |
|
---|
556 | mInitialized = true;
|
---|
557 |
|
---|
558 | mglInfo.init(pContext);
|
---|
559 |
|
---|
560 | if(mglInfo.isFragmentShaderSupported() && mglInfo.isTextureRectangleSupported())
|
---|
561 | {
|
---|
562 | uint32_t num = 0;
|
---|
563 | mFourccSupportedList[num++] = FOURCC_AYUV;
|
---|
564 | mFourccSupportedList[num++] = FOURCC_UYVY;
|
---|
565 | mFourccSupportedList[num++] = FOURCC_YUY2;
|
---|
566 | if(mglInfo.getMultiTexNumSupported() >= 4)
|
---|
567 | {
|
---|
568 | /* YV12 currently requires 3 units (for each color component)
|
---|
569 | * + 1 unit for dst texture for color-keying + 3 units for each color component
|
---|
570 | * TODO: we could store YV12 data in one texture to eliminate this requirement*/
|
---|
571 | mFourccSupportedList[num++] = FOURCC_YV12;
|
---|
572 | }
|
---|
573 |
|
---|
574 | Assert(num <= VBOXVHWA_NUMFOURCC);
|
---|
575 | mFourccSupportedCount = num;
|
---|
576 | }
|
---|
577 | else
|
---|
578 | {
|
---|
579 | mFourccSupportedCount = 0;
|
---|
580 | }
|
---|
581 | }
|
---|
582 |
|
---|
583 | bool VBoxVHWAInfo::isVHWASupported() const
|
---|
584 | {
|
---|
585 | if(mglInfo.getGLVersion() <= 0)
|
---|
586 | {
|
---|
587 | /* error occurred while gl info initialization */
|
---|
588 | VBOXQGLLOGREL(("2D not supported: gl version info not initialized properly\n"));
|
---|
589 | return false;
|
---|
590 | }
|
---|
591 |
|
---|
592 | #ifndef DEBUGVHWASTRICT
|
---|
593 | /* in case we do not support shaders & multitexturing we can not support dst colorkey,
|
---|
594 | * no sense to report Video Acceleration supported */
|
---|
595 | if(!mglInfo.isFragmentShaderSupported())
|
---|
596 | {
|
---|
597 | VBOXQGLLOGREL(("2D not supported: fragment shader unsupported\n"));
|
---|
598 | return false;
|
---|
599 | }
|
---|
600 | #endif
|
---|
601 | if(mglInfo.getMultiTexNumSupported() < 2)
|
---|
602 | {
|
---|
603 | VBOXQGLLOGREL(("2D not supported: multitexture unsupported\n"));
|
---|
604 | return false;
|
---|
605 | }
|
---|
606 |
|
---|
607 | /* color conversion now supported only GL_TEXTURE_RECTANGLE
|
---|
608 | * in this case only stretching is accelerated
|
---|
609 | * report as unsupported, TODO: probably should report as supported for stretch acceleration */
|
---|
610 | if(!mglInfo.isTextureRectangleSupported())
|
---|
611 | {
|
---|
612 | VBOXQGLLOGREL(("2D not supported: texture rectangle unsupported\n"));
|
---|
613 | return false;
|
---|
614 | }
|
---|
615 |
|
---|
616 | VBOXQGLLOGREL(("2D is supported!\n"));
|
---|
617 | return true;
|
---|
618 | }
|
---|
619 |
|
---|
620 | /* static */
|
---|
621 | bool VBoxVHWAInfo::checkVHWASupport()
|
---|
622 | {
|
---|
623 | #if defined(RT_OS_WINDOWS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
|
---|
624 | static char pszVBoxPath[RTPATH_MAX];
|
---|
625 | const char *papszArgs[] = { NULL, "-test", "2D", NULL};
|
---|
626 |
|
---|
627 | int vrc = RTPathExecDir(pszVBoxPath, RTPATH_MAX); AssertRCReturn(vrc, false);
|
---|
628 | # if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
|
---|
629 | vrc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL.exe");
|
---|
630 | # else
|
---|
631 | vrc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL");
|
---|
632 | # endif
|
---|
633 | papszArgs[0] = pszVBoxPath; /* argv[0] */
|
---|
634 | AssertRCReturn(vrc, false);
|
---|
635 |
|
---|
636 | RTPROCESS Process;
|
---|
637 | vrc = RTProcCreate(pszVBoxPath, papszArgs, RTENV_DEFAULT, 0, &Process);
|
---|
638 | if (RT_FAILURE(vrc))
|
---|
639 | {
|
---|
640 | VBOXQGLLOGREL(("2D support test failed: failed to create a test process\n"));
|
---|
641 | return false;
|
---|
642 | }
|
---|
643 |
|
---|
644 | uint64_t const StartTS = RTTimeMilliTS();
|
---|
645 |
|
---|
646 | RTPROCSTATUS ProcStatus = {0};
|
---|
647 | while (1)
|
---|
648 | {
|
---|
649 | vrc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
|
---|
650 | if (vrc != VERR_PROCESS_RUNNING)
|
---|
651 | break;
|
---|
652 |
|
---|
653 | if (RTTimeMilliTS() - StartTS > 30*1000 /* 30 sec */)
|
---|
654 | {
|
---|
655 | RTProcTerminate(Process);
|
---|
656 | RTThreadSleep(100);
|
---|
657 | RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
|
---|
658 | VBOXQGLLOGREL(("2D support test failed: the test did not complete within 30 sec\n"));
|
---|
659 | return false;
|
---|
660 | }
|
---|
661 | RTThreadSleep(100);
|
---|
662 | }
|
---|
663 |
|
---|
664 | if (RT_SUCCESS(vrc))
|
---|
665 | {
|
---|
666 | if ((ProcStatus.enmReason==RTPROCEXITREASON_NORMAL) && (ProcStatus.iStatus==0))
|
---|
667 | {
|
---|
668 | VBOXQGLLOGREL(("2D support test succeeded\n"));
|
---|
669 | return true;
|
---|
670 | }
|
---|
671 | }
|
---|
672 |
|
---|
673 | VBOXQGLLOGREL(("2D support test failed: err code (%Rra)\n", vrc));
|
---|
674 |
|
---|
675 | return false;
|
---|
676 | #else
|
---|
677 | /** @todo test & enable external app approach*/
|
---|
678 | VBoxGLTmpContext ctx;
|
---|
679 | const MY_QOpenGLContext *pContext = ctx.makeCurrent();
|
---|
680 | Assert(pContext);
|
---|
681 | if (pContext)
|
---|
682 | {
|
---|
683 | VBoxVHWAInfo info;
|
---|
684 | info.init(pContext);
|
---|
685 | return info.isVHWASupported();
|
---|
686 | }
|
---|
687 | return false;
|
---|
688 | #endif
|
---|
689 | }
|
---|
690 |
|
---|
691 | VBoxGLTmpContext::VBoxGLTmpContext()
|
---|
692 | {
|
---|
693 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
---|
694 | mWidget = new MY_QOpenGLWidget(/*new QMainWindow()*/);
|
---|
695 | #else
|
---|
696 | if (QGLFormat::hasOpenGL())
|
---|
697 | mWidget = new MY_QOpenGLWidget();
|
---|
698 | else
|
---|
699 | mWidget = NULL;
|
---|
700 | #endif
|
---|
701 | }
|
---|
702 |
|
---|
703 | VBoxGLTmpContext::~VBoxGLTmpContext()
|
---|
704 | {
|
---|
705 | if (mWidget)
|
---|
706 | {
|
---|
707 | delete mWidget;
|
---|
708 | mWidget = NULL;
|
---|
709 | }
|
---|
710 | }
|
---|
711 |
|
---|
712 | const MY_QOpenGLContext *VBoxGLTmpContext::makeCurrent()
|
---|
713 | {
|
---|
714 | if (mWidget)
|
---|
715 | {
|
---|
716 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
---|
717 | mWidget->grabFramebuffer(); /* This is a hack to trigger GL initialization or context() will return NULL. */
|
---|
718 | #endif
|
---|
719 | mWidget->makeCurrent();
|
---|
720 | return mWidget->context();
|
---|
721 | }
|
---|
722 | return NULL;
|
---|
723 | }
|
---|
724 |
|
---|