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