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 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 | #ifndef __VBoxGLSupportInfo_h__
|
---|
23 | #define __VBoxGLSupportInfo_h__
|
---|
24 |
|
---|
25 | #include <iprt/types.h>
|
---|
26 |
|
---|
27 | typedef char GLchar;
|
---|
28 |
|
---|
29 | #ifndef GL_COMPILE_STATUS
|
---|
30 | # define GL_COMPILE_STATUS 0x8b81
|
---|
31 | #endif
|
---|
32 | #ifndef GL_LINK_STATUS
|
---|
33 | # define GL_LINK_STATUS 0x8b82
|
---|
34 | #endif
|
---|
35 | #ifndef GL_FRAGMENT_SHADER
|
---|
36 | # define GL_FRAGMENT_SHADER 0x8b30
|
---|
37 | #endif
|
---|
38 | #ifndef GL_VERTEX_SHADER
|
---|
39 | # define GL_VERTEX_SHADER 0x8b31
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | /* GL_ARB_multitexture */
|
---|
43 | #ifndef GL_TEXTURE0
|
---|
44 | # define GL_TEXTURE0 0x84c0
|
---|
45 | #endif
|
---|
46 | #ifndef GL_TEXTURE1
|
---|
47 | # define GL_TEXTURE1 0x84c1
|
---|
48 | #endif
|
---|
49 | #ifndef GL_MAX_TEXTURE_COORDS
|
---|
50 | # define GL_MAX_TEXTURE_COORDS 0x8871
|
---|
51 | #endif
|
---|
52 | #ifndef GL_MAX_TEXTURE_IMAGE_UNITS
|
---|
53 | # define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | #ifndef APIENTRY
|
---|
57 | # define APIENTRY
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_ACTIVE_TEXTURE) (GLenum texture);
|
---|
61 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_MULTI_TEX_COORD2I) (GLenum texture, GLint v0, GLint v1);
|
---|
62 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_MULTI_TEX_COORD2F) (GLenum texture, GLfloat v0, GLfloat v1);
|
---|
63 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_MULTI_TEX_COORD2D) (GLenum texture, GLdouble v0, GLdouble v1);
|
---|
64 |
|
---|
65 | /* GL_ARB_texture_rectangle */
|
---|
66 | #ifndef GL_TEXTURE_RECTANGLE
|
---|
67 | # define GL_TEXTURE_RECTANGLE 0x84F5
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | /* GL_ARB_shader_objects */
|
---|
71 | /* GL_ARB_fragment_shader */
|
---|
72 |
|
---|
73 | typedef GLuint (APIENTRY *PFNVBOXVHWA_CREATE_SHADER) (GLenum type);
|
---|
74 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_SHADER_SOURCE) (GLuint shader, GLsizei count, const GLchar **string, const GLint *length);
|
---|
75 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_COMPILE_SHADER) (GLuint shader);
|
---|
76 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_DELETE_SHADER) (GLuint shader);
|
---|
77 |
|
---|
78 | typedef GLuint (APIENTRY *PFNVBOXVHWA_CREATE_PROGRAM) ();
|
---|
79 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_ATTACH_SHADER) (GLuint program, GLuint shader);
|
---|
80 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_DETACH_SHADER) (GLuint program, GLuint shader);
|
---|
81 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_LINK_PROGRAM) (GLuint program);
|
---|
82 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_USE_PROGRAM) (GLuint program);
|
---|
83 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_DELETE_PROGRAM) (GLuint program);
|
---|
84 |
|
---|
85 | typedef GLboolean (APIENTRY *PFNVBOXVHWA_IS_SHADER) (GLuint shader);
|
---|
86 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_SHADERIV) (GLuint shader, GLenum pname, GLint *params);
|
---|
87 | typedef GLboolean (APIENTRY *PFNVBOXVHWA_IS_PROGRAM) (GLuint program);
|
---|
88 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_PROGRAMIV) (GLuint program, GLenum pname, GLint *params);
|
---|
89 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_ATTACHED_SHADERS) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders);
|
---|
90 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_SHADER_INFO_LOG) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
---|
91 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_GET_PROGRAM_INFO_LOG) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
---|
92 | typedef GLint (APIENTRY *PFNVBOXVHWA_GET_UNIFORM_LOCATION) (GLint programObj, const GLchar *name);
|
---|
93 |
|
---|
94 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM1F)(GLint location, GLfloat v0);
|
---|
95 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM2F)(GLint location, GLfloat v0, GLfloat v1);
|
---|
96 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM3F)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
|
---|
97 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM4F)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
|
---|
98 |
|
---|
99 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM1I)(GLint location, GLint v0);
|
---|
100 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM2I)(GLint location, GLint v0, GLint v1);
|
---|
101 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM3I)(GLint location, GLint v0, GLint v1, GLint v2);
|
---|
102 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_UNIFORM4I)(GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
|
---|
103 |
|
---|
104 | /* GL_ARB_pixel_buffer_object*/
|
---|
105 | #ifndef Q_WS_MAC
|
---|
106 | /* apears to be defined on mac */
|
---|
107 | typedef ptrdiff_t GLsizeiptr;
|
---|
108 | #endif
|
---|
109 |
|
---|
110 | #ifndef GL_READ_ONLY
|
---|
111 | # define GL_READ_ONLY 0x88B8
|
---|
112 | #endif
|
---|
113 | #ifndef GL_WRITE_ONLY
|
---|
114 | # define GL_WRITE_ONLY 0x88B9
|
---|
115 | #endif
|
---|
116 | #ifndef GL_READ_WRITE
|
---|
117 | # define GL_READ_WRITE 0x88BA
|
---|
118 | #endif
|
---|
119 | #ifndef GL_STREAM_DRAW
|
---|
120 | # define GL_STREAM_DRAW 0x88E0
|
---|
121 | #endif
|
---|
122 | #ifndef GL_STREAM_READ
|
---|
123 | # define GL_STREAM_READ 0x88E1
|
---|
124 | #endif
|
---|
125 | #ifndef GL_STREAM_COPY
|
---|
126 | # define GL_STREAM_COPY 0x88E2
|
---|
127 | #endif
|
---|
128 |
|
---|
129 | #ifndef GL_PIXEL_PACK_BUFFER
|
---|
130 | # define GL_PIXEL_PACK_BUFFER 0x88EB
|
---|
131 | #endif
|
---|
132 | #ifndef GL_PIXEL_UNPACK_BUFFER
|
---|
133 | # define GL_PIXEL_UNPACK_BUFFER 0x88EC
|
---|
134 | #endif
|
---|
135 | #ifndef GL_PIXEL_PACK_BUFFER_BINDING
|
---|
136 | # define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED
|
---|
137 | #endif
|
---|
138 | #ifndef GL_PIXEL_UNPACK_BUFFER_BINDING
|
---|
139 | # define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
|
---|
140 | #endif
|
---|
141 |
|
---|
142 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_GEN_BUFFERS)(GLsizei n, GLuint *buffers);
|
---|
143 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_DELETE_BUFFERS)(GLsizei n, const GLuint *buffers);
|
---|
144 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_BIND_BUFFER)(GLenum target, GLuint buffer);
|
---|
145 | typedef GLvoid (APIENTRY *PFNVBOXVHWA_BUFFER_DATA)(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
|
---|
146 | typedef GLvoid* (APIENTRY *PFNVBOXVHWA_MAP_BUFFER)(GLenum target, GLenum access);
|
---|
147 | typedef GLboolean (APIENTRY *PFNVBOXVHWA_UNMAP_BUFFER)(GLenum target);
|
---|
148 |
|
---|
149 |
|
---|
150 | /*****************/
|
---|
151 |
|
---|
152 | /* functions */
|
---|
153 |
|
---|
154 | /* @todo: move those to VBoxGLInfo class instance members ??? */
|
---|
155 | extern PFNVBOXVHWA_ACTIVE_TEXTURE vboxglActiveTexture;
|
---|
156 | extern PFNVBOXVHWA_MULTI_TEX_COORD2I vboxglMultiTexCoord2i;
|
---|
157 | extern PFNVBOXVHWA_MULTI_TEX_COORD2D vboxglMultiTexCoord2d;
|
---|
158 | extern PFNVBOXVHWA_MULTI_TEX_COORD2F vboxglMultiTexCoord2f;
|
---|
159 |
|
---|
160 |
|
---|
161 | extern PFNVBOXVHWA_CREATE_SHADER vboxglCreateShader;
|
---|
162 | extern PFNVBOXVHWA_SHADER_SOURCE vboxglShaderSource;
|
---|
163 | extern PFNVBOXVHWA_COMPILE_SHADER vboxglCompileShader;
|
---|
164 | extern PFNVBOXVHWA_DELETE_SHADER vboxglDeleteShader;
|
---|
165 |
|
---|
166 | extern PFNVBOXVHWA_CREATE_PROGRAM vboxglCreateProgram;
|
---|
167 | extern PFNVBOXVHWA_ATTACH_SHADER vboxglAttachShader;
|
---|
168 | extern PFNVBOXVHWA_DETACH_SHADER vboxglDetachShader;
|
---|
169 | extern PFNVBOXVHWA_LINK_PROGRAM vboxglLinkProgram;
|
---|
170 | extern PFNVBOXVHWA_USE_PROGRAM vboxglUseProgram;
|
---|
171 | extern PFNVBOXVHWA_DELETE_PROGRAM vboxglDeleteProgram;
|
---|
172 |
|
---|
173 | extern PFNVBOXVHWA_IS_SHADER vboxglIsShader;
|
---|
174 | extern PFNVBOXVHWA_GET_SHADERIV vboxglGetShaderiv;
|
---|
175 | extern PFNVBOXVHWA_IS_PROGRAM vboxglIsProgram;
|
---|
176 | extern PFNVBOXVHWA_GET_PROGRAMIV vboxglGetProgramiv;
|
---|
177 | extern PFNVBOXVHWA_GET_ATTACHED_SHADERS vboxglGetAttachedShaders;
|
---|
178 | extern PFNVBOXVHWA_GET_SHADER_INFO_LOG vboxglGetShaderInfoLog;
|
---|
179 | extern PFNVBOXVHWA_GET_PROGRAM_INFO_LOG vboxglGetProgramInfoLog;
|
---|
180 |
|
---|
181 | extern PFNVBOXVHWA_GET_UNIFORM_LOCATION vboxglGetUniformLocation;
|
---|
182 |
|
---|
183 | extern PFNVBOXVHWA_UNIFORM1F vboxglUniform1f;
|
---|
184 | extern PFNVBOXVHWA_UNIFORM2F vboxglUniform2f;
|
---|
185 | extern PFNVBOXVHWA_UNIFORM3F vboxglUniform3f;
|
---|
186 | extern PFNVBOXVHWA_UNIFORM4F vboxglUniform4f;
|
---|
187 |
|
---|
188 | extern PFNVBOXVHWA_UNIFORM1I vboxglUniform1i;
|
---|
189 | extern PFNVBOXVHWA_UNIFORM2I vboxglUniform2i;
|
---|
190 | extern PFNVBOXVHWA_UNIFORM3I vboxglUniform3i;
|
---|
191 | extern PFNVBOXVHWA_UNIFORM4I vboxglUniform4i;
|
---|
192 |
|
---|
193 | extern PFNVBOXVHWA_GEN_BUFFERS vboxglGenBuffers;
|
---|
194 | extern PFNVBOXVHWA_DELETE_BUFFERS vboxglDeleteBuffers;
|
---|
195 | extern PFNVBOXVHWA_BIND_BUFFER vboxglBindBuffer;
|
---|
196 | extern PFNVBOXVHWA_BUFFER_DATA vboxglBufferData;
|
---|
197 | extern PFNVBOXVHWA_MAP_BUFFER vboxglMapBuffer;
|
---|
198 | extern PFNVBOXVHWA_UNMAP_BUFFER vboxglUnmapBuffer;
|
---|
199 |
|
---|
200 | class VBoxGLInfo
|
---|
201 | {
|
---|
202 | public:
|
---|
203 | VBoxGLInfo() :
|
---|
204 | mGLVersion(0),
|
---|
205 | mFragmentShaderSupported(false),
|
---|
206 | mTextureRectangleSupported(false),
|
---|
207 | mTextureNP2Supported(false),
|
---|
208 | mPBOSupported(false),
|
---|
209 | mMultiTexNumSupported(1), /* 1 would mean it is not supported */
|
---|
210 | m_GL_ARB_multitexture(false),
|
---|
211 | m_GL_ARB_shader_objects(false),
|
---|
212 | m_GL_ARB_fragment_shader(false),
|
---|
213 | m_GL_ARB_pixel_buffer_object(false),
|
---|
214 | m_GL_ARB_texture_rectangle(false),
|
---|
215 | m_GL_EXT_texture_rectangle(false),
|
---|
216 | m_GL_NV_texture_rectangle(false),
|
---|
217 | m_GL_ARB_texture_non_power_of_two(false),
|
---|
218 | mInitialized(false)
|
---|
219 | {}
|
---|
220 |
|
---|
221 | void init(const class QGLContext * pContext);
|
---|
222 |
|
---|
223 | bool isInitialized() const { return mInitialized; }
|
---|
224 |
|
---|
225 | int getGLVersion() const { return mGLVersion; }
|
---|
226 | bool isFragmentShaderSupported() const { return mFragmentShaderSupported; }
|
---|
227 | bool isTextureRectangleSupported() const { return mTextureRectangleSupported; }
|
---|
228 | bool isTextureNP2Supported() const { return mTextureNP2Supported; }
|
---|
229 | bool isPBOSupported() const { return mPBOSupported; }
|
---|
230 | /* 1 would mean it is not supported */
|
---|
231 | int getMultiTexNumSupported() const { return mMultiTexNumSupported; }
|
---|
232 |
|
---|
233 | static int parseVersion(const GLubyte * ver);
|
---|
234 | private:
|
---|
235 | void initExtSupport(const class QGLContext & context);
|
---|
236 |
|
---|
237 | int mGLVersion;
|
---|
238 | bool mFragmentShaderSupported;
|
---|
239 | bool mTextureRectangleSupported;
|
---|
240 | bool mTextureNP2Supported;
|
---|
241 | bool mPBOSupported;
|
---|
242 | int mMultiTexNumSupported; /* 1 would mean it is not supported */
|
---|
243 |
|
---|
244 | bool m_GL_ARB_multitexture;
|
---|
245 | bool m_GL_ARB_shader_objects;
|
---|
246 | bool m_GL_ARB_fragment_shader;
|
---|
247 | bool m_GL_ARB_pixel_buffer_object;
|
---|
248 | bool m_GL_ARB_texture_rectangle;
|
---|
249 | bool m_GL_EXT_texture_rectangle;
|
---|
250 | bool m_GL_NV_texture_rectangle;
|
---|
251 | bool m_GL_ARB_texture_non_power_of_two;
|
---|
252 |
|
---|
253 | bool mInitialized;
|
---|
254 | };
|
---|
255 |
|
---|
256 | class VBoxGLTmpContext
|
---|
257 | {
|
---|
258 | public:
|
---|
259 | VBoxGLTmpContext();
|
---|
260 | ~VBoxGLTmpContext();
|
---|
261 |
|
---|
262 | const class QGLContext * makeCurrent();
|
---|
263 | private:
|
---|
264 | class QGLWidget * mWidget;
|
---|
265 | };
|
---|
266 |
|
---|
267 |
|
---|
268 | #define VBOXQGL_MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
---|
269 | ((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
---|
270 | ((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
---|
271 |
|
---|
272 | #define FOURCC_AYUV VBOXQGL_MAKEFOURCC('A', 'Y', 'U', 'V')
|
---|
273 | #define FOURCC_UYVY VBOXQGL_MAKEFOURCC('U', 'Y', 'V', 'Y')
|
---|
274 | #define FOURCC_YUY2 VBOXQGL_MAKEFOURCC('Y', 'U', 'Y', '2')
|
---|
275 | #define FOURCC_YV12 VBOXQGL_MAKEFOURCC('Y', 'V', '1', '2')
|
---|
276 | #define VBOXVHWA_NUMFOURCC 4
|
---|
277 |
|
---|
278 | class VBoxVHWAInfo
|
---|
279 | {
|
---|
280 | public:
|
---|
281 | VBoxVHWAInfo() :
|
---|
282 | mFourccSupportedCount(0),
|
---|
283 | mInitialized(false)
|
---|
284 | {}
|
---|
285 |
|
---|
286 | VBoxVHWAInfo(const VBoxGLInfo & glInfo) :
|
---|
287 | mglInfo(glInfo),
|
---|
288 | mFourccSupportedCount(0),
|
---|
289 | mInitialized(false)
|
---|
290 | {}
|
---|
291 |
|
---|
292 | void init(const class QGLContext * pContext);
|
---|
293 |
|
---|
294 | bool isInitialized() const { return mInitialized; }
|
---|
295 |
|
---|
296 | const VBoxGLInfo & getGlInfo() const { return mglInfo; }
|
---|
297 |
|
---|
298 | bool isVHWASupported() const;
|
---|
299 |
|
---|
300 | int getFourccSupportedCount() const { return mFourccSupportedCount; }
|
---|
301 | const uint32_t * getFourccSupportedList() const { return mFourccSupportedList; }
|
---|
302 |
|
---|
303 | static bool checkVHWASupport();
|
---|
304 | private:
|
---|
305 | VBoxGLInfo mglInfo;
|
---|
306 | uint32_t mFourccSupportedList[VBOXVHWA_NUMFOURCC];
|
---|
307 | int mFourccSupportedCount;
|
---|
308 |
|
---|
309 | bool mInitialized;
|
---|
310 | };
|
---|
311 |
|
---|
312 | #endif /* #ifndef __VBoxGLSupportInfo_h__ */
|
---|