VirtualBox

source: vbox/trunk/include/VBox/VBoxGL2D.h@ 99760

Last change on this file since 99760 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 14.5 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * OpenGL support info used for 2D support detection
5 */
6
7/*
8 * Copyright (C) 2009-2023 Oracle and/or its affiliates.
9 *
10 * This file is part of VirtualBox base platform packages, as
11 * available from https://www.virtualbox.org.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation, in version 3 of the
16 * License.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <https://www.gnu.org/licenses>.
25 *
26 * The contents of this file may alternatively be used under the terms
27 * of the Common Development and Distribution License Version 1.0
28 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
29 * in the VirtualBox distribution, in which case the provisions of the
30 * CDDL are applicable instead of those of the GPL.
31 *
32 * You may elect to license modified versions of this file under the
33 * terms and conditions of either the GPL or the CDDL or both.
34 *
35 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36 */
37
38#ifndef VBOX_INCLUDED_VBoxGL2D_h
39#define VBOX_INCLUDED_VBoxGL2D_h
40#ifndef RT_WITHOUT_PRAGMA_ONCE
41# pragma once
42#endif
43
44#include <iprt/types.h>
45
46typedef char GLchar;
47
48#ifndef GL_COMPILE_STATUS
49# define GL_COMPILE_STATUS 0x8b81
50#endif
51#ifndef GL_LINK_STATUS
52# define GL_LINK_STATUS 0x8b82
53#endif
54#ifndef GL_FRAGMENT_SHADER
55# define GL_FRAGMENT_SHADER 0x8b30
56#endif
57#ifndef GL_VERTEX_SHADER
58# define GL_VERTEX_SHADER 0x8b31
59#endif
60
61/* GL_ARB_multitexture */
62#ifndef GL_TEXTURE0
63# define GL_TEXTURE0 0x84c0
64#endif
65#ifndef GL_TEXTURE1
66# define GL_TEXTURE1 0x84c1
67#endif
68#ifndef GL_MAX_TEXTURE_COORDS
69# define GL_MAX_TEXTURE_COORDS 0x8871
70#endif
71#ifndef GL_MAX_TEXTURE_IMAGE_UNITS
72# define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
73#endif
74
75#ifndef APIENTRY
76# define APIENTRY
77#endif
78
79typedef GLvoid (APIENTRY *PFNVBOXVHWA_ACTIVE_TEXTURE) (GLenum texture);
80typedef GLvoid (APIENTRY *PFNVBOXVHWA_MULTI_TEX_COORD2I) (GLenum texture, GLint v0, GLint v1);
81typedef GLvoid (APIENTRY *PFNVBOXVHWA_MULTI_TEX_COORD2F) (GLenum texture, GLfloat v0, GLfloat v1);
82typedef GLvoid (APIENTRY *PFNVBOXVHWA_MULTI_TEX_COORD2D) (GLenum texture, GLdouble v0, GLdouble v1);
83
84/* GL_ARB_texture_rectangle */
85#ifndef GL_TEXTURE_RECTANGLE
86# define GL_TEXTURE_RECTANGLE 0x84F5
87#endif
88
89/* GL_ARB_shader_objects */
90/* GL_ARB_fragment_shader */
91
92typedef GLuint (APIENTRY *PFNVBOXVHWA_CREATE_SHADER) (GLenum type);
93typedef GLvoid (APIENTRY *PFNVBOXVHWA_SHADER_SOURCE) (GLuint shader, GLsizei count, const GLchar **string, const GLint *length);
94typedef GLvoid (APIENTRY *PFNVBOXVHWA_COMPILE_SHADER) (GLuint shader);
95typedef GLvoid (APIENTRY *PFNVBOXVHWA_DELETE_SHADER) (GLuint shader);
96
97typedef GLuint (APIENTRY *PFNVBOXVHWA_CREATE_PROGRAM) ();
98typedef GLvoid (APIENTRY *PFNVBOXVHWA_ATTACH_SHADER) (GLuint program, GLuint shader);
99typedef GLvoid (APIENTRY *PFNVBOXVHWA_DETACH_SHADER) (GLuint program, GLuint shader);
100typedef GLvoid (APIENTRY *PFNVBOXVHWA_LINK_PROGRAM) (GLuint program);
101typedef GLvoid (APIENTRY *PFNVBOXVHWA_USE_PROGRAM) (GLuint program);
102typedef GLvoid (APIENTRY *PFNVBOXVHWA_DELETE_PROGRAM) (GLuint program);
103
104typedef GLboolean (APIENTRY *PFNVBOXVHWA_IS_SHADER) (GLuint shader);
105typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_SHADERIV) (GLuint shader, GLenum pname, GLint *params);
106typedef GLboolean (APIENTRY *PFNVBOXVHWA_IS_PROGRAM) (GLuint program);
107typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_PROGRAMIV) (GLuint program, GLenum pname, GLint *params);
108typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_ATTACHED_SHADERS) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders);
109typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_SHADER_INFO_LOG) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
110typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_PROGRAM_INFO_LOG) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
111typedef GLint (APIENTRY *PFNVBOXVHWA_GET_UNIFORM_LOCATION) (GLint programObj, const GLchar *name);
112
113typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM1F)(GLint location, GLfloat v0);
114typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM2F)(GLint location, GLfloat v0, GLfloat v1);
115typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM3F)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
116typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM4F)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
117
118typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM1I)(GLint location, GLint v0);
119typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM2I)(GLint location, GLint v0, GLint v1);
120typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM3I)(GLint location, GLint v0, GLint v1, GLint v2);
121typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM4I)(GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
122
123/* GL_ARB_pixel_buffer_object*/
124#ifndef Q_WS_MAC
125/* apears to be defined on mac */
126typedef ptrdiff_t GLsizeiptr;
127#endif
128
129#ifndef GL_READ_ONLY
130# define GL_READ_ONLY 0x88B8
131#endif
132#ifndef GL_WRITE_ONLY
133# define GL_WRITE_ONLY 0x88B9
134#endif
135#ifndef GL_READ_WRITE
136# define GL_READ_WRITE 0x88BA
137#endif
138#ifndef GL_STREAM_DRAW
139# define GL_STREAM_DRAW 0x88E0
140#endif
141#ifndef GL_STREAM_READ
142# define GL_STREAM_READ 0x88E1
143#endif
144#ifndef GL_STREAM_COPY
145# define GL_STREAM_COPY 0x88E2
146#endif
147#ifndef GL_DYNAMIC_DRAW
148# define GL_DYNAMIC_DRAW 0x88E8
149#endif
150
151#ifndef GL_PIXEL_PACK_BUFFER
152# define GL_PIXEL_PACK_BUFFER 0x88EB
153#endif
154#ifndef GL_PIXEL_UNPACK_BUFFER
155# define GL_PIXEL_UNPACK_BUFFER 0x88EC
156#endif
157#ifndef GL_PIXEL_PACK_BUFFER_BINDING
158# define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED
159#endif
160#ifndef GL_PIXEL_UNPACK_BUFFER_BINDING
161# define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
162#endif
163
164typedef GLvoid (APIENTRY *PFNVBOXVHWA_GEN_BUFFERS)(GLsizei n, GLuint *buffers);
165typedef GLvoid (APIENTRY *PFNVBOXVHWA_DELETE_BUFFERS)(GLsizei n, const GLuint *buffers);
166typedef GLvoid (APIENTRY *PFNVBOXVHWA_BIND_BUFFER)(GLenum target, GLuint buffer);
167typedef GLvoid (APIENTRY *PFNVBOXVHWA_BUFFER_DATA)(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
168typedef GLvoid* (APIENTRY *PFNVBOXVHWA_MAP_BUFFER)(GLenum target, GLenum access);
169typedef GLboolean (APIENTRY *PFNVBOXVHWA_UNMAP_BUFFER)(GLenum target);
170
171/* GL_EXT_framebuffer_object */
172#ifndef GL_FRAMEBUFFER
173# define GL_FRAMEBUFFER 0x8D40
174#endif
175#ifndef GL_COLOR_ATTACHMENT0
176# define GL_COLOR_ATTACHMENT0 0x8CE0
177#endif
178
179typedef GLboolean (APIENTRY *PFNVBOXVHWA_IS_FRAMEBUFFER)(GLuint framebuffer);
180typedef GLvoid (APIENTRY *PFNVBOXVHWA_BIND_FRAMEBUFFER)(GLenum target, GLuint framebuffer);
181typedef GLvoid (APIENTRY *PFNVBOXVHWA_DELETE_FRAMEBUFFERS)(GLsizei n, const GLuint *framebuffers);
182typedef GLvoid (APIENTRY *PFNVBOXVHWA_GEN_FRAMEBUFFERS)(GLsizei n, GLuint *framebuffers);
183typedef GLenum (APIENTRY *PFNVBOXVHWA_CHECK_FRAMEBUFFER_STATUS)(GLenum target);
184typedef GLvoid (APIENTRY *PFNVBOXVHWA_FRAMEBUFFER_TEXTURE1D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
185typedef GLvoid (APIENTRY *PFNVBOXVHWA_FRAMEBUFFER_TEXTURE2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
186typedef GLvoid (APIENTRY *PFNVBOXVHWA_FRAMEBUFFER_TEXTURE3D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
187typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_FRAMEBUFFER_ATTACHMENT_PARAMETRIV)(GLenum target, GLenum attachment, GLenum pname, GLint *params);
188
189
190/*****************/
191
192/* functions */
193
194/* @todo: move those to VBoxGLInfo class instance members ??? */
195extern PFNVBOXVHWA_ACTIVE_TEXTURE vboxglActiveTexture;
196extern PFNVBOXVHWA_MULTI_TEX_COORD2I vboxglMultiTexCoord2i;
197extern PFNVBOXVHWA_MULTI_TEX_COORD2D vboxglMultiTexCoord2d;
198extern PFNVBOXVHWA_MULTI_TEX_COORD2F vboxglMultiTexCoord2f;
199
200
201extern PFNVBOXVHWA_CREATE_SHADER vboxglCreateShader;
202extern PFNVBOXVHWA_SHADER_SOURCE vboxglShaderSource;
203extern PFNVBOXVHWA_COMPILE_SHADER vboxglCompileShader;
204extern PFNVBOXVHWA_DELETE_SHADER vboxglDeleteShader;
205
206extern PFNVBOXVHWA_CREATE_PROGRAM vboxglCreateProgram;
207extern PFNVBOXVHWA_ATTACH_SHADER vboxglAttachShader;
208extern PFNVBOXVHWA_DETACH_SHADER vboxglDetachShader;
209extern PFNVBOXVHWA_LINK_PROGRAM vboxglLinkProgram;
210extern PFNVBOXVHWA_USE_PROGRAM vboxglUseProgram;
211extern PFNVBOXVHWA_DELETE_PROGRAM vboxglDeleteProgram;
212
213extern PFNVBOXVHWA_IS_SHADER vboxglIsShader;
214extern PFNVBOXVHWA_GET_SHADERIV vboxglGetShaderiv;
215extern PFNVBOXVHWA_IS_PROGRAM vboxglIsProgram;
216extern PFNVBOXVHWA_GET_PROGRAMIV vboxglGetProgramiv;
217extern PFNVBOXVHWA_GET_ATTACHED_SHADERS vboxglGetAttachedShaders;
218extern PFNVBOXVHWA_GET_SHADER_INFO_LOG vboxglGetShaderInfoLog;
219extern PFNVBOXVHWA_GET_PROGRAM_INFO_LOG vboxglGetProgramInfoLog;
220
221extern PFNVBOXVHWA_GET_UNIFORM_LOCATION vboxglGetUniformLocation;
222
223extern PFNVBOXVHWA_UNIFORM1F vboxglUniform1f;
224extern PFNVBOXVHWA_UNIFORM2F vboxglUniform2f;
225extern PFNVBOXVHWA_UNIFORM3F vboxglUniform3f;
226extern PFNVBOXVHWA_UNIFORM4F vboxglUniform4f;
227
228extern PFNVBOXVHWA_UNIFORM1I vboxglUniform1i;
229extern PFNVBOXVHWA_UNIFORM2I vboxglUniform2i;
230extern PFNVBOXVHWA_UNIFORM3I vboxglUniform3i;
231extern PFNVBOXVHWA_UNIFORM4I vboxglUniform4i;
232
233extern PFNVBOXVHWA_GEN_BUFFERS vboxglGenBuffers;
234extern PFNVBOXVHWA_DELETE_BUFFERS vboxglDeleteBuffers;
235extern PFNVBOXVHWA_BIND_BUFFER vboxglBindBuffer;
236extern PFNVBOXVHWA_BUFFER_DATA vboxglBufferData;
237extern PFNVBOXVHWA_MAP_BUFFER vboxglMapBuffer;
238extern PFNVBOXVHWA_UNMAP_BUFFER vboxglUnmapBuffer;
239
240extern PFNVBOXVHWA_IS_FRAMEBUFFER vboxglIsFramebuffer;
241extern PFNVBOXVHWA_BIND_FRAMEBUFFER vboxglBindFramebuffer;
242extern PFNVBOXVHWA_DELETE_FRAMEBUFFERS vboxglDeleteFramebuffers;
243extern PFNVBOXVHWA_GEN_FRAMEBUFFERS vboxglGenFramebuffers;
244extern PFNVBOXVHWA_CHECK_FRAMEBUFFER_STATUS vboxglCheckFramebufferStatus;
245extern PFNVBOXVHWA_FRAMEBUFFER_TEXTURE1D vboxglFramebufferTexture1D;
246extern PFNVBOXVHWA_FRAMEBUFFER_TEXTURE2D vboxglFramebufferTexture2D;
247extern PFNVBOXVHWA_FRAMEBUFFER_TEXTURE3D vboxglFramebufferTexture3D;
248extern PFNVBOXVHWA_GET_FRAMEBUFFER_ATTACHMENT_PARAMETRIV vboxglGetFramebufferAttachmentParameteriv;
249
250
251/*
252 * Glossing over qt 5 vs 6 differences.
253 *
254 * Note! We could use the qt6 classes in 5, but we probably don't have the
255 * necessary modules in our current qt builds.
256 */
257#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
258class QOpenGLWidget;
259class QOpenGLContext;
260# define MY_QOpenGLWidget QOpenGLWidget
261# define MY_QOpenGLContext QOpenGLContext
262#else
263class QGLWidget;
264class QGLContext;
265# define MY_QOpenGLWidget QGLWidget
266# define MY_QOpenGLContext QGLContext
267#endif
268
269
270class VBoxGLInfo
271{
272public:
273 VBoxGLInfo() :
274 mGLVersion(0),
275 mFragmentShaderSupported(false),
276 mTextureRectangleSupported(false),
277 mTextureNP2Supported(false),
278 mPBOSupported(false),
279 mFBOSupported(false),
280 mMultiTexNumSupported(1), /* 1 would mean it is not supported */
281 m_GL_ARB_multitexture(false),
282 m_GL_ARB_shader_objects(false),
283 m_GL_ARB_fragment_shader(false),
284 m_GL_ARB_pixel_buffer_object(false),
285 m_GL_ARB_texture_rectangle(false),
286 m_GL_EXT_texture_rectangle(false),
287 m_GL_NV_texture_rectangle(false),
288 m_GL_ARB_texture_non_power_of_two(false),
289 m_GL_EXT_framebuffer_object(false),
290 mInitialized(false)
291 {}
292
293 void init(const MY_QOpenGLContext *pContext);
294
295 bool isInitialized() const { return mInitialized; }
296
297 int getGLVersion() const { return mGLVersion; }
298 bool isFragmentShaderSupported() const { return mFragmentShaderSupported; }
299 bool isTextureRectangleSupported() const { return mTextureRectangleSupported; }
300 bool isTextureNP2Supported() const { return mTextureNP2Supported; }
301 bool isPBOSupported() const { return mPBOSupported; }
302 /* some ATI drivers do not seem to support non-zero offsets when dealing with PBOs
303 * @todo: add a check for that, always unsupported currently */
304 bool isPBOOffsetSupported() const { return false; }
305 bool isFBOSupported() const { return mFBOSupported; }
306 /* 1 would mean it is not supported */
307 int getMultiTexNumSupported() const { return mMultiTexNumSupported; }
308
309 static int parseVersion(const GLubyte * ver);
310private:
311 void initExtSupport(const MY_QOpenGLContext &context);
312
313 int mGLVersion;
314 bool mFragmentShaderSupported;
315 bool mTextureRectangleSupported;
316 bool mTextureNP2Supported;
317 bool mPBOSupported;
318 bool mFBOSupported;
319 int mMultiTexNumSupported; /* 1 would mean it is not supported */
320
321 bool m_GL_ARB_multitexture;
322 bool m_GL_ARB_shader_objects;
323 bool m_GL_ARB_fragment_shader;
324 bool m_GL_ARB_pixel_buffer_object;
325 bool m_GL_ARB_texture_rectangle;
326 bool m_GL_EXT_texture_rectangle;
327 bool m_GL_NV_texture_rectangle;
328 bool m_GL_ARB_texture_non_power_of_two;
329 bool m_GL_EXT_framebuffer_object;
330
331 bool mInitialized;
332};
333
334class VBoxGLTmpContext
335{
336public:
337 VBoxGLTmpContext();
338 ~VBoxGLTmpContext();
339
340 const MY_QOpenGLContext *makeCurrent();
341private:
342 MY_QOpenGLWidget *mWidget;
343};
344
345
346#define VBOXQGL_MAKEFOURCC(ch0, ch1, ch2, ch3) \
347 ((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
348 ((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
349
350#define FOURCC_AYUV VBOXQGL_MAKEFOURCC('A', 'Y', 'U', 'V')
351#define FOURCC_UYVY VBOXQGL_MAKEFOURCC('U', 'Y', 'V', 'Y')
352#define FOURCC_YUY2 VBOXQGL_MAKEFOURCC('Y', 'U', 'Y', '2')
353#define FOURCC_YV12 VBOXQGL_MAKEFOURCC('Y', 'V', '1', '2')
354#define VBOXVHWA_NUMFOURCC 4
355
356class VBoxVHWAInfo
357{
358public:
359 VBoxVHWAInfo() :
360 mFourccSupportedCount(0),
361 mInitialized(false)
362 {}
363
364 VBoxVHWAInfo(const VBoxGLInfo & glInfo) :
365 mglInfo(glInfo),
366 mFourccSupportedCount(0),
367 mInitialized(false)
368 {}
369
370 void init(const MY_QOpenGLContext *pContext);
371
372 bool isInitialized() const { return mInitialized; }
373
374 const VBoxGLInfo & getGlInfo() const { return mglInfo; }
375
376 bool isVHWASupported() const;
377
378 int getFourccSupportedCount() const { return mFourccSupportedCount; }
379 const uint32_t * getFourccSupportedList() const { return mFourccSupportedList; }
380
381 static bool checkVHWASupport();
382private:
383 VBoxGLInfo mglInfo;
384 uint32_t mFourccSupportedList[VBOXVHWA_NUMFOURCC];
385 int mFourccSupportedCount;
386
387 bool mInitialized;
388};
389
390#endif /* !VBOX_INCLUDED_VBoxGL2D_h */
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