VirtualBox

source: vbox/trunk/src/VBox/Main/src-helper-apps/OpenGLTest/VBoxGLSupportInfo.cpp@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.1 KB
Line 
1/* $Id: VBoxGLSupportInfo.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - OpenGL support info used for 2D support detection.
4 */
5
6/*
7 * Copyright (C) 2009-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.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
61PFNVBOXVHWA_ACTIVE_TEXTURE vboxglActiveTexture = NULL;
62PFNVBOXVHWA_MULTI_TEX_COORD2I vboxglMultiTexCoord2i = NULL;
63PFNVBOXVHWA_MULTI_TEX_COORD2D vboxglMultiTexCoord2d = NULL;
64PFNVBOXVHWA_MULTI_TEX_COORD2F vboxglMultiTexCoord2f = NULL;
65
66
67PFNVBOXVHWA_CREATE_SHADER vboxglCreateShader = NULL;
68PFNVBOXVHWA_SHADER_SOURCE vboxglShaderSource = NULL;
69PFNVBOXVHWA_COMPILE_SHADER vboxglCompileShader = NULL;
70PFNVBOXVHWA_DELETE_SHADER vboxglDeleteShader = NULL;
71
72PFNVBOXVHWA_CREATE_PROGRAM vboxglCreateProgram = NULL;
73PFNVBOXVHWA_ATTACH_SHADER vboxglAttachShader = NULL;
74PFNVBOXVHWA_DETACH_SHADER vboxglDetachShader = NULL;
75PFNVBOXVHWA_LINK_PROGRAM vboxglLinkProgram = NULL;
76PFNVBOXVHWA_USE_PROGRAM vboxglUseProgram = NULL;
77PFNVBOXVHWA_DELETE_PROGRAM vboxglDeleteProgram = NULL;
78
79PFNVBOXVHWA_IS_SHADER vboxglIsShader = NULL;
80PFNVBOXVHWA_GET_SHADERIV vboxglGetShaderiv = NULL;
81PFNVBOXVHWA_IS_PROGRAM vboxglIsProgram = NULL;
82PFNVBOXVHWA_GET_PROGRAMIV vboxglGetProgramiv = NULL;
83PFNVBOXVHWA_GET_ATTACHED_SHADERS vboxglGetAttachedShaders = NULL;
84PFNVBOXVHWA_GET_SHADER_INFO_LOG vboxglGetShaderInfoLog = NULL;
85PFNVBOXVHWA_GET_PROGRAM_INFO_LOG vboxglGetProgramInfoLog = NULL;
86
87PFNVBOXVHWA_GET_UNIFORM_LOCATION vboxglGetUniformLocation = NULL;
88
89PFNVBOXVHWA_UNIFORM1F vboxglUniform1f = NULL;
90PFNVBOXVHWA_UNIFORM2F vboxglUniform2f = NULL;
91PFNVBOXVHWA_UNIFORM3F vboxglUniform3f = NULL;
92PFNVBOXVHWA_UNIFORM4F vboxglUniform4f = NULL;
93
94PFNVBOXVHWA_UNIFORM1I vboxglUniform1i = NULL;
95PFNVBOXVHWA_UNIFORM2I vboxglUniform2i = NULL;
96PFNVBOXVHWA_UNIFORM3I vboxglUniform3i = NULL;
97PFNVBOXVHWA_UNIFORM4I vboxglUniform4i = NULL;
98
99PFNVBOXVHWA_GEN_BUFFERS vboxglGenBuffers = NULL;
100PFNVBOXVHWA_DELETE_BUFFERS vboxglDeleteBuffers = NULL;
101PFNVBOXVHWA_BIND_BUFFER vboxglBindBuffer = NULL;
102PFNVBOXVHWA_BUFFER_DATA vboxglBufferData = NULL;
103PFNVBOXVHWA_MAP_BUFFER vboxglMapBuffer = NULL;
104PFNVBOXVHWA_UNMAP_BUFFER vboxglUnmapBuffer = NULL;
105
106PFNVBOXVHWA_IS_FRAMEBUFFER vboxglIsFramebuffer = NULL;
107PFNVBOXVHWA_BIND_FRAMEBUFFER vboxglBindFramebuffer = NULL;
108PFNVBOXVHWA_DELETE_FRAMEBUFFERS vboxglDeleteFramebuffers = NULL;
109PFNVBOXVHWA_GEN_FRAMEBUFFERS vboxglGenFramebuffers = NULL;
110PFNVBOXVHWA_CHECK_FRAMEBUFFER_STATUS vboxglCheckFramebufferStatus = NULL;
111PFNVBOXVHWA_FRAMEBUFFER_TEXTURE1D vboxglFramebufferTexture1D = NULL;
112PFNVBOXVHWA_FRAMEBUFFER_TEXTURE2D vboxglFramebufferTexture2D = NULL;
113PFNVBOXVHWA_FRAMEBUFFER_TEXTURE3D vboxglFramebufferTexture3D = NULL;
114PFNVBOXVHWA_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
178static 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 */
233int 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
269void 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
356void VBoxGLInfo::initExtSupport(const MY_QOpenGLContext &context)
357{
358 int rc = 0;
359 do
360 {
361 rc = 0;
362 mMultiTexNumSupported = 1; /* default, 1 means not supported */
363 if(mGLVersion >= 0x010201) /* ogl >= 1.2.1 */
364 {
365 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_ACTIVE_TEXTURE, ActiveTexture, rc);
366 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_MULTI_TEX_COORD2I, MultiTexCoord2i, rc);
367 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_MULTI_TEX_COORD2D, MultiTexCoord2d, rc);
368 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_MULTI_TEX_COORD2F, MultiTexCoord2f, rc);
369 }
370 else if(m_GL_ARB_multitexture)
371 {
372 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_ACTIVE_TEXTURE, ActiveTexture, rc);
373 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MULTI_TEX_COORD2I, MultiTexCoord2i, rc);
374 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MULTI_TEX_COORD2D, MultiTexCoord2d, rc);
375 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MULTI_TEX_COORD2F, MultiTexCoord2f, rc);
376 }
377 else
378 {
379 break;
380 }
381
382 if(RT_FAILURE(rc))
383 break;
384
385 GLint maxCoords, maxUnits;
386 glGetIntegerv(GL_MAX_TEXTURE_COORDS, &maxCoords);
387 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxUnits);
388
389 VBOXQGLLOGREL(("Max Tex Coords (%d), Img Units (%d)\n", maxCoords, maxUnits));
390 /* take the minimum of those */
391 if(maxUnits < maxCoords)
392 maxCoords = maxUnits;
393 if(maxUnits < 2)
394 {
395 VBOXQGLLOGREL(("Max Tex Coord or Img Units < 2 disabling MultiTex support\n"));
396 break;
397 }
398
399 mMultiTexNumSupported = maxUnits;
400 }while(0);
401
402
403 do
404 {
405 rc = 0;
406 mPBOSupported = false;
407
408 if(m_GL_ARB_pixel_buffer_object)
409 {
410 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_GEN_BUFFERS, GenBuffers, rc);
411 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_DELETE_BUFFERS, DeleteBuffers, rc);
412 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_BIND_BUFFER, BindBuffer, rc);
413 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_BUFFER_DATA, BufferData, rc);
414 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MAP_BUFFER, MapBuffer, rc);
415 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNMAP_BUFFER, UnmapBuffer, rc);
416 }
417 else
418 {
419 break;
420 }
421
422 if(RT_FAILURE(rc))
423 break;
424
425 mPBOSupported = true;
426 } while(0);
427
428 do
429 {
430 rc = 0;
431 mFragmentShaderSupported = false;
432
433 if(mGLVersion >= 0x020000) /* if ogl >= 2.0*/
434 {
435 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_CREATE_SHADER, CreateShader, rc);
436 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_SHADER_SOURCE, ShaderSource, rc);
437 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_COMPILE_SHADER, CompileShader, rc);
438 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_DELETE_SHADER, DeleteShader, rc);
439
440 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_CREATE_PROGRAM, CreateProgram, rc);
441 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_ATTACH_SHADER, AttachShader, rc);
442 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_DETACH_SHADER, DetachShader, rc);
443 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_LINK_PROGRAM, LinkProgram, rc);
444 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_USE_PROGRAM, UseProgram, rc);
445 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_DELETE_PROGRAM, DeleteProgram, rc);
446
447 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_IS_SHADER, IsShader, rc);
448 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_SHADERIV, GetShaderiv, rc);
449 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_IS_PROGRAM, IsProgram, rc);
450 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_PROGRAMIV, GetProgramiv, rc);
451 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_ATTACHED_SHADERS, GetAttachedShaders, rc);
452 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_SHADER_INFO_LOG, GetShaderInfoLog, rc);
453 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_PROGRAM_INFO_LOG, GetProgramInfoLog, rc);
454
455 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_UNIFORM_LOCATION, GetUniformLocation, rc);
456
457 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM1F, Uniform1f, rc);
458 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM2F, Uniform2f, rc);
459 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM3F, Uniform3f, rc);
460 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM4F, Uniform4f, rc);
461
462 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM1I, Uniform1i, rc);
463 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM2I, Uniform2i, rc);
464 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM3I, Uniform3i, rc);
465 VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM4I, Uniform4i, rc);
466 }
467 else if(m_GL_ARB_shader_objects && m_GL_ARB_fragment_shader)
468 {
469 VBOXVHWA_PFNINIT_OBJECT_ARB(context, PFNVBOXVHWA_CREATE_SHADER, CreateShader, rc);
470 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_SHADER_SOURCE, ShaderSource, rc);
471 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_COMPILE_SHADER, CompileShader, rc);
472 VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_DELETE_SHADER, DeleteShader, DeleteObjectARB, rc);
473
474 VBOXVHWA_PFNINIT_OBJECT_ARB(context, PFNVBOXVHWA_CREATE_PROGRAM, CreateProgram, rc);
475 VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_ATTACH_SHADER, AttachShader, AttachObjectARB, rc);
476 VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_DETACH_SHADER, DetachShader, DetachObjectARB, rc);
477 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_LINK_PROGRAM, LinkProgram, rc);
478 VBOXVHWA_PFNINIT_OBJECT_ARB(context, PFNVBOXVHWA_USE_PROGRAM, UseProgram, rc);
479 VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_DELETE_PROGRAM, DeleteProgram, DeleteObjectARB, rc);
480
481 /// @todo VBOXVHWA_PFNINIT(PFNVBOXVHWA_IS_SHADER, IsShader, rc);
482 VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_SHADERIV, GetShaderiv, GetObjectParameterivARB, rc);
483 /// @todo VBOXVHWA_PFNINIT(PFNVBOXVHWA_IS_PROGRAM, IsProgram, rc);
484 VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_PROGRAMIV, GetProgramiv, GetObjectParameterivARB, rc);
485 VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_ATTACHED_SHADERS, GetAttachedShaders, GetAttachedObjectsARB, rc);
486 VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_SHADER_INFO_LOG, GetShaderInfoLog, GetInfoLogARB, rc);
487 VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_PROGRAM_INFO_LOG, GetProgramInfoLog, GetInfoLogARB, rc);
488
489 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_GET_UNIFORM_LOCATION, GetUniformLocation, rc);
490
491 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM1F, Uniform1f, rc);
492 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM2F, Uniform2f, rc);
493 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM3F, Uniform3f, rc);
494 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM4F, Uniform4f, rc);
495
496 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM1I, Uniform1i, rc);
497 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM2I, Uniform2i, rc);
498 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM3I, Uniform3i, rc);
499 VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM4I, Uniform4i, rc);
500 }
501 else
502 {
503 break;
504 }
505
506 if(RT_FAILURE(rc))
507 break;
508
509 mFragmentShaderSupported = true;
510 } while(0);
511
512 do
513 {
514 rc = 0;
515 mFBOSupported = false;
516
517 if(m_GL_EXT_framebuffer_object)
518 {
519 VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_IS_FRAMEBUFFER, IsFramebuffer, rc);
520 VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_BIND_FRAMEBUFFER, BindFramebuffer, rc);
521 VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_DELETE_FRAMEBUFFERS, DeleteFramebuffers, rc);
522 VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_GEN_FRAMEBUFFERS, GenFramebuffers, rc);
523 VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_CHECK_FRAMEBUFFER_STATUS, CheckFramebufferStatus, rc);
524 VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_FRAMEBUFFER_TEXTURE1D, FramebufferTexture1D, rc);
525 VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_FRAMEBUFFER_TEXTURE2D, FramebufferTexture2D, rc);
526 VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_FRAMEBUFFER_TEXTURE3D, FramebufferTexture3D, rc);
527 VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_GET_FRAMEBUFFER_ATTACHMENT_PARAMETRIV, GetFramebufferAttachmentParameteriv, rc);
528 }
529 else
530 {
531 break;
532 }
533
534 if(RT_FAILURE(rc))
535 break;
536
537 mFBOSupported = true;
538 } while(0);
539
540 if(m_GL_ARB_texture_rectangle || m_GL_EXT_texture_rectangle || m_GL_NV_texture_rectangle)
541 {
542 mTextureRectangleSupported = true;
543 }
544 else
545 {
546 mTextureRectangleSupported = false;
547 }
548
549 mTextureNP2Supported = m_GL_ARB_texture_non_power_of_two;
550}
551
552void VBoxVHWAInfo::init(const MY_QOpenGLContext *pContext)
553{
554 if(mInitialized)
555 return;
556
557 mInitialized = true;
558
559 mglInfo.init(pContext);
560
561 if(mglInfo.isFragmentShaderSupported() && mglInfo.isTextureRectangleSupported())
562 {
563 uint32_t num = 0;
564 mFourccSupportedList[num++] = FOURCC_AYUV;
565 mFourccSupportedList[num++] = FOURCC_UYVY;
566 mFourccSupportedList[num++] = FOURCC_YUY2;
567 if(mglInfo.getMultiTexNumSupported() >= 4)
568 {
569 /* YV12 currently requires 3 units (for each color component)
570 * + 1 unit for dst texture for color-keying + 3 units for each color component
571 * TODO: we could store YV12 data in one texture to eliminate this requirement*/
572 mFourccSupportedList[num++] = FOURCC_YV12;
573 }
574
575 Assert(num <= VBOXVHWA_NUMFOURCC);
576 mFourccSupportedCount = num;
577 }
578 else
579 {
580 mFourccSupportedCount = 0;
581 }
582}
583
584bool VBoxVHWAInfo::isVHWASupported() const
585{
586 if(mglInfo.getGLVersion() <= 0)
587 {
588 /* error occurred while gl info initialization */
589 VBOXQGLLOGREL(("2D not supported: gl version info not initialized properly\n"));
590 return false;
591 }
592
593#ifndef DEBUGVHWASTRICT
594 /* in case we do not support shaders & multitexturing we can not support dst colorkey,
595 * no sense to report Video Acceleration supported */
596 if(!mglInfo.isFragmentShaderSupported())
597 {
598 VBOXQGLLOGREL(("2D not supported: fragment shader unsupported\n"));
599 return false;
600 }
601#endif
602 if(mglInfo.getMultiTexNumSupported() < 2)
603 {
604 VBOXQGLLOGREL(("2D not supported: multitexture unsupported\n"));
605 return false;
606 }
607
608 /* color conversion now supported only GL_TEXTURE_RECTANGLE
609 * in this case only stretching is accelerated
610 * report as unsupported, TODO: probably should report as supported for stretch acceleration */
611 if(!mglInfo.isTextureRectangleSupported())
612 {
613 VBOXQGLLOGREL(("2D not supported: texture rectangle unsupported\n"));
614 return false;
615 }
616
617 VBOXQGLLOGREL(("2D is supported!\n"));
618 return true;
619}
620
621/* static */
622bool VBoxVHWAInfo::checkVHWASupport()
623{
624#if defined(RT_OS_WINDOWS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
625 static char pszVBoxPath[RTPATH_MAX];
626 const char *papszArgs[] = { NULL, "-test", "2D", NULL};
627 int rc;
628 RTPROCESS Process;
629 RTPROCSTATUS ProcStatus;
630 uint64_t StartTS;
631
632 rc = RTPathExecDir(pszVBoxPath, RTPATH_MAX); AssertRCReturn(rc, false);
633#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
634 rc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL.exe");
635#else
636 rc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL");
637#endif
638 papszArgs[0] = pszVBoxPath; /* argv[0] */
639 AssertRCReturn(rc, false);
640
641 rc = RTProcCreate(pszVBoxPath, papszArgs, RTENV_DEFAULT, 0, &Process);
642 if (RT_FAILURE(rc))
643 {
644 VBOXQGLLOGREL(("2D support test failed: failed to create a test process\n"));
645 return false;
646 }
647
648 StartTS = RTTimeMilliTS();
649
650 while (1)
651 {
652 rc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
653 if (rc != VERR_PROCESS_RUNNING)
654 break;
655
656 if (RTTimeMilliTS() - StartTS > 30*1000 /* 30 sec */)
657 {
658 RTProcTerminate(Process);
659 RTThreadSleep(100);
660 RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
661 VBOXQGLLOGREL(("2D support test failed: the test did not complete within 30 sec\n"));
662 return false;
663 }
664 RTThreadSleep(100);
665 }
666
667 if (RT_SUCCESS(rc))
668 {
669 if ((ProcStatus.enmReason==RTPROCEXITREASON_NORMAL) && (ProcStatus.iStatus==0))
670 {
671 VBOXQGLLOGREL(("2D support test succeeded\n"));
672 return true;
673 }
674 }
675
676 VBOXQGLLOGREL(("2D support test failed: err code (%Rra)\n", rc));
677
678 return false;
679#else
680 /** @todo test & enable external app approach*/
681 VBoxGLTmpContext ctx;
682 const MY_QOpenGLContext *pContext = ctx.makeCurrent();
683 Assert(pContext);
684 if (pContext)
685 {
686 VBoxVHWAInfo info;
687 info.init(pContext);
688 return info.isVHWASupported();
689 }
690 return false;
691#endif
692}
693
694VBoxGLTmpContext::VBoxGLTmpContext()
695{
696#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
697 mWidget = new MY_QOpenGLWidget(/*new QMainWindow()*/);
698#else
699 if (QGLFormat::hasOpenGL())
700 mWidget = new MY_QOpenGLWidget();
701 else
702 mWidget = NULL;
703#endif
704}
705
706VBoxGLTmpContext::~VBoxGLTmpContext()
707{
708 if (mWidget)
709 {
710 delete mWidget;
711 mWidget = NULL;
712 }
713}
714
715const MY_QOpenGLContext *VBoxGLTmpContext::makeCurrent()
716{
717 if (mWidget)
718 {
719#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
720 mWidget->grabFramebuffer(); /* This is a hack to trigger GL initialization or context() will return NULL. */
721#endif
722 mWidget->makeCurrent();
723 return mWidget->context();
724 }
725 return NULL;
726}
727
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette