1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox Windows NT/2000/XP guest OpenGL ICD
|
---|
4 | *
|
---|
5 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
6 | *
|
---|
7 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | * available from http://www.virtualbox.org. This file is free software;
|
---|
9 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | * General Public License (GPL) as published by the Free Software
|
---|
11 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
12 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
13 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | *
|
---|
15 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
16 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
17 | * additional information or have any questions.
|
---|
18 | */
|
---|
19 | #ifndef __VBOXOGL_H__
|
---|
20 | #define __VBOXOGL_H__
|
---|
21 |
|
---|
22 | #include <windows.h>
|
---|
23 | /* get rid of the inconsistent dll linkage warnings */
|
---|
24 | #undef WINGDIAPI
|
---|
25 | #define WINGDIAPI
|
---|
26 | #include "GL/gl.h"
|
---|
27 | #define WGL_WGLEXT_PROTOTYPES
|
---|
28 | #include <VBox/HostServices/wglext.h>
|
---|
29 |
|
---|
30 | #include <iprt/cdefs.h>
|
---|
31 | #include <iprt/assert.h>
|
---|
32 |
|
---|
33 | #include <VBox/HostServices/VBoxOpenGLSvc.h>
|
---|
34 | #include <VBox/HostServices/VBoxOGLOp.h>
|
---|
35 |
|
---|
36 | typedef struct _icdTable
|
---|
37 | {
|
---|
38 | DWORD size;
|
---|
39 | PROC table[336];
|
---|
40 | } ICDTABLE, *PICDTABLE;
|
---|
41 |
|
---|
42 |
|
---|
43 | typedef struct
|
---|
44 | {
|
---|
45 | HANDLE hGuestDrv;
|
---|
46 |
|
---|
47 | } VBOX_OGL_CTX, *PVBOX_OGL_CTX;
|
---|
48 |
|
---|
49 | /* HGCM macro */
|
---|
50 | #define VBOX_INIT_CALL(a, b, c) \
|
---|
51 | (a)->result = VINF_SUCCESS; \
|
---|
52 | (a)->u32ClientID = (c)->u32ClientID; \
|
---|
53 | (a)->u32Function = VBOXOGL_FN_##b; \
|
---|
54 | (a)->cParms = VBOXOGL_CPARMS_##b
|
---|
55 |
|
---|
56 | /* glDrawElement internal state */
|
---|
57 | #define VBOX_OGL_DRAWELEMENT_VERTEX 0
|
---|
58 | #define VBOX_OGL_DRAWELEMENT_TEXCOORD 1
|
---|
59 | #define VBOX_OGL_DRAWELEMENT_COLOR 2
|
---|
60 | #define VBOX_OGL_DRAWELEMENT_EDGEFLAG 3
|
---|
61 | #define VBOX_OGL_DRAWELEMENT_INDEX 4
|
---|
62 | #define VBOX_OGL_DRAWELEMENT_NORMAL 5
|
---|
63 | #define VBOX_OGL_DRAWELEMENT_MAX 6
|
---|
64 |
|
---|
65 | typedef struct
|
---|
66 | {
|
---|
67 | GLint size;
|
---|
68 | GLenum type;
|
---|
69 | GLsizei stride;
|
---|
70 | uint32_t cbDataType;
|
---|
71 | const GLvoid *pointer;
|
---|
72 | bool fValid;
|
---|
73 | } VBOX_OGL_DRAWELEMENT;
|
---|
74 |
|
---|
75 | typedef struct
|
---|
76 | {
|
---|
77 | uint32_t u32ClientID;
|
---|
78 |
|
---|
79 | GLenum glLastError;
|
---|
80 | uint32_t cCommands;
|
---|
81 | uint8_t *pCmdBuffer;
|
---|
82 | uint8_t *pCmdBufferEnd;
|
---|
83 | uint8_t *pCurrentCmd;
|
---|
84 |
|
---|
85 | /* Internal OpenGL state variables */
|
---|
86 | VBOX_OGL_DRAWELEMENT Pointer[VBOX_OGL_DRAWELEMENT_MAX];
|
---|
87 |
|
---|
88 | } VBOX_OGL_THREAD_CTX, *PVBOX_OGL_THREAD_CTX;
|
---|
89 |
|
---|
90 |
|
---|
91 | extern HINSTANCE hDllVBoxOGL;
|
---|
92 | extern char szOpenGLVersion[256];
|
---|
93 | extern char szOpenGLExtensions[8192];
|
---|
94 |
|
---|
95 | void APIENTRY glSetError(GLenum glNewError);
|
---|
96 |
|
---|
97 | #ifdef DEBUG
|
---|
98 | #define glLogError(a) \
|
---|
99 | { \
|
---|
100 | /** @todo log error */ \
|
---|
101 | glSetError(a); \
|
---|
102 | }
|
---|
103 | #define DbgPrintf(a) VBoxDbgLog a
|
---|
104 |
|
---|
105 | #ifdef VBOX_DEBUG_LVL2
|
---|
106 | #define DbgPrintf2(a) VBoxDbgLog a
|
---|
107 | #else
|
---|
108 | #define DbgPrintf2(a)
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | #else
|
---|
112 | #define glLogError(a) glSetError(a)
|
---|
113 | #define DbgPrintf(a)
|
---|
114 | #define DbgPrintf2(a)
|
---|
115 | #endif
|
---|
116 |
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Initialize the OpenGL guest-host communication channel
|
---|
120 | *
|
---|
121 | * @return success or failure (boolean)
|
---|
122 | * @param hDllInst Dll instance handle
|
---|
123 | */
|
---|
124 | BOOL VBoxOGLInit(HINSTANCE hDllInst);
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Destroy the OpenGL guest-host communication channel
|
---|
128 | *
|
---|
129 | * @return success or failure (boolean)
|
---|
130 | */
|
---|
131 | BOOL VBoxOGLExit();
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Initialize new thread
|
---|
135 | *
|
---|
136 | * @return success or failure (boolean)
|
---|
137 | */
|
---|
138 | BOOL VBoxOGLThreadAttach();
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Clean up for terminating thread
|
---|
142 | *
|
---|
143 | * @return success or failure (boolean)
|
---|
144 | */
|
---|
145 | BOOL VBoxOGLThreadDetach();
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * Set the thread local OpenGL context
|
---|
149 | *
|
---|
150 | * @param pCtx thread local OpenGL context ptr
|
---|
151 | */
|
---|
152 | void VBoxOGLSetThreadCtx(PVBOX_OGL_THREAD_CTX pCtx);
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * Return the thread local OpenGL context
|
---|
156 | *
|
---|
157 | * @return thread local OpenGL context ptr or NULL if failure
|
---|
158 | */
|
---|
159 | PVBOX_OGL_THREAD_CTX VBoxOGLGetThreadCtx();
|
---|
160 |
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Queue a new OpenGL command
|
---|
164 | *
|
---|
165 | * @param enmOp OpenGL command op
|
---|
166 | * @param cParam Number of parameters
|
---|
167 | * @param cbParams Memory needed for parameters
|
---|
168 | */
|
---|
169 | void VBoxCmdStart(uint32_t enmOp, uint32_t cParam, uint32_t cbParams);
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * Add a parameter to the currently queued OpenGL command
|
---|
173 | *
|
---|
174 | * @param pParam Parameter ptr
|
---|
175 | * @param cbParam Parameter value size
|
---|
176 | */
|
---|
177 | void VBoxCmdSaveParameter(uint8_t *pParam, uint32_t cbParam);
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * Add a parameter (variable size) to the currently queued OpenGL command
|
---|
181 | *
|
---|
182 | * @param pParam Parameter ptr
|
---|
183 | * @param cbParam Parameter value size
|
---|
184 | */
|
---|
185 | void VBoxCmdSaveMemParameter(uint8_t *pParam, uint32_t cbParam);
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Finish the queued command
|
---|
189 | *
|
---|
190 | * @param enmOp OpenGL command op
|
---|
191 | */
|
---|
192 | void VBoxCmdStop(uint32_t enmOp);
|
---|
193 |
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Send an HGCM request
|
---|
197 | *
|
---|
198 | * @return VBox status code
|
---|
199 | * @param pvData Data pointer
|
---|
200 | * @param cbData Data size
|
---|
201 | */
|
---|
202 | int vboxHGCMCall(void *pvData, unsigned cbData);
|
---|
203 |
|
---|
204 | #ifdef DEBUG
|
---|
205 | /**
|
---|
206 | * Log to the debug output device
|
---|
207 | *
|
---|
208 | * @param pszFormat Format string
|
---|
209 | * @param ... Variable parameters
|
---|
210 | */
|
---|
211 | void VBoxDbgLog(char *pszFormat, ...);
|
---|
212 | #endif
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Flush the OpenGL command queue and return the return val of the last command
|
---|
216 | *
|
---|
217 | * @returns return val of last command
|
---|
218 | */
|
---|
219 | uint64_t VBoxOGLFlush();
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Flush the OpenGL command queue and return the return val of the last command
|
---|
223 | * The last command's final parameter is a pointer where its result is stored
|
---|
224 | *
|
---|
225 | * @returns return val of last command
|
---|
226 | * @param pLastParam Last parameter's address
|
---|
227 | * @param cbParam Last parameter's size
|
---|
228 | */
|
---|
229 | uint64_t VBoxOGLFlushPtr(void *pLastParam, uint32_t cbParam);
|
---|
230 |
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * Initialize OpenGL extensions
|
---|
234 | *
|
---|
235 | * @returns VBox status code
|
---|
236 | * @param pCtx OpenGL thread context
|
---|
237 | */
|
---|
238 | int vboxInitOpenGLExtensions(PVBOX_OGL_THREAD_CTX pCtx);
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Check if an OpenGL extension is available on the host
|
---|
242 | *
|
---|
243 | * @returns available or not
|
---|
244 | * @param pszExtFunctionName
|
---|
245 | */
|
---|
246 | bool VBoxIsExtensionAvailable(const char *pszExtFunctionName);
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Query the specified cached parameter
|
---|
250 | *
|
---|
251 | * @returns requested cached value
|
---|
252 | * @param type Parameter type (Note: minimal checks only!)
|
---|
253 | */
|
---|
254 | GLint glInternalGetIntegerv(GLenum type);
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Query the specified cached texture level parameter
|
---|
258 | *
|
---|
259 | * @returns requested cached value
|
---|
260 | * @param type Parameter type (Note: minimal checks only!)
|
---|
261 | */
|
---|
262 | GLint glInternalGetTexLevelParameteriv(GLenum type);
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Query the number of bytes required for a pixel in the specified format
|
---|
266 | *
|
---|
267 | * @returns requested pixel size
|
---|
268 | * @param type Parameter type
|
---|
269 | */
|
---|
270 | GLint glInternalGetPixelFormatElements(GLenum format);
|
---|
271 |
|
---|
272 | /**
|
---|
273 | * Query the size of the specified data type
|
---|
274 | *
|
---|
275 | * @returns type size or 0 if unknown type
|
---|
276 | * @param type data type
|
---|
277 | */
|
---|
278 | GLint glVBoxGetDataTypeSize(GLenum type);
|
---|
279 |
|
---|
280 | uint32_t glInternalLightvElem(GLenum pname);
|
---|
281 | uint32_t glInternalMaterialvElem(GLenum pname);
|
---|
282 | uint32_t glInternalTexEnvvElem(GLenum pname);
|
---|
283 | uint32_t glInternalTexGenvElem(GLenum pname);
|
---|
284 | uint32_t glInternalTexParametervElem(GLenum pname);
|
---|
285 |
|
---|
286 |
|
---|
287 | #endif /* __VBOXOGL_H__ */
|
---|
288 |
|
---|