1 | /* $Id: DevVGA-SVGA3d-ogl.cpp 53756 2015-01-06 23:28:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DevVMWare - VMWare SVGA device
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2015 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 |
|
---|
19 | /*******************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *******************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_DEV_VMSVGA
|
---|
23 | #include <VBox/vmm/pdmdev.h>
|
---|
24 | #include <VBox/version.h>
|
---|
25 | #include <VBox/err.h>
|
---|
26 | #include <VBox/log.h>
|
---|
27 | #include <VBox/vmm/pgm.h>
|
---|
28 |
|
---|
29 | #include <iprt/assert.h>
|
---|
30 | #include <iprt/semaphore.h>
|
---|
31 | #include <iprt/uuid.h>
|
---|
32 | #include <iprt/mem.h>
|
---|
33 | #include <iprt/avl.h>
|
---|
34 |
|
---|
35 | #include <VBox/VMMDev.h>
|
---|
36 | #include <VBox/VBoxVideo.h>
|
---|
37 | #include <VBox/bioslogo.h>
|
---|
38 |
|
---|
39 | /* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
|
---|
40 | #include "DevVGA.h"
|
---|
41 |
|
---|
42 | #include "DevVGA-SVGA.h"
|
---|
43 | #include "DevVGA-SVGA3d.h"
|
---|
44 | #include "vmsvga/svga_reg.h"
|
---|
45 | #include "vmsvga/svga3d_reg.h"
|
---|
46 | #include "vmsvga/svga3d_shaderdefs.h"
|
---|
47 |
|
---|
48 | #ifdef RT_OS_WINDOWS
|
---|
49 | # include <GL/gl.h>
|
---|
50 | # include "vmsvga_glext/wglext.h"
|
---|
51 |
|
---|
52 | #elif defined(RT_OS_DARWIN)
|
---|
53 | # include <OpenGL/OpenGL.h>
|
---|
54 | # include <OpenGL/gl3.h>
|
---|
55 | # include <OpenGL/gl3ext.h>
|
---|
56 | # define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
|
---|
57 | # include <OpenGL/gl.h>
|
---|
58 | # include <OpenGL/glext.h>
|
---|
59 | # include "DevVGA-SVGA3d-cocoa.h"
|
---|
60 | /* work around conflicting definition of GLhandleARB in VMware's glext.h */
|
---|
61 | //#define GL_ARB_shader_objects
|
---|
62 | // HACK
|
---|
63 | typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer);
|
---|
64 | typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
|
---|
65 | typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params);
|
---|
66 | # define GL_RGBA_S3TC 0x83A2
|
---|
67 | # define GL_ALPHA8_EXT 0x803c
|
---|
68 | # define GL_LUMINANCE8_EXT 0x8040
|
---|
69 | # define GL_LUMINANCE16_EXT 0x8042
|
---|
70 | # define GL_LUMINANCE4_ALPHA4_EXT 0x8043
|
---|
71 | # define GL_LUMINANCE8_ALPHA8_EXT 0x8045
|
---|
72 | # define GL_INT_2_10_10_10_REV 0x8D9F
|
---|
73 | #else
|
---|
74 | # include <X11/Xlib.h>
|
---|
75 | # include <X11/Xatom.h>
|
---|
76 | # include <GL/gl.h>
|
---|
77 | # include <GL/glx.h>
|
---|
78 | # include <GL/glext.h>
|
---|
79 | //HACK FOR NOW
|
---|
80 | typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
|
---|
81 | #endif
|
---|
82 | #include "vmsvga_glext/glext.h"
|
---|
83 |
|
---|
84 | #include "shaderlib/shaderlib.h"
|
---|
85 |
|
---|
86 | #include <stdlib.h>
|
---|
87 | #include <math.h>
|
---|
88 | #include <float.h>
|
---|
89 |
|
---|
90 |
|
---|
91 | /* Generated by VBoxDef2LazyLoad from the VBoxSVGA3D.def and VBoxSVGA3DObjC.def files. */
|
---|
92 | extern "C" int ExplicitlyLoadVBoxSVGA3D(bool fResolveAllImports, PRTERRINFO pErrInfo);
|
---|
93 | #ifdef RT_OS_DARWIN
|
---|
94 | extern "C" int ExplicitlyLoadVBoxSVGA3DObjC(bool fResolveAllImports, PRTERRINFO pErrInfo);
|
---|
95 | #endif
|
---|
96 |
|
---|
97 |
|
---|
98 | /*******************************************************************************
|
---|
99 | * Defined Constants And Macros *
|
---|
100 | *******************************************************************************/
|
---|
101 | #ifndef VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE
|
---|
102 | # define VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE 1.0
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | #ifdef RT_OS_WINDOWS
|
---|
106 | # define OGLGETPROCADDRESS wglGetProcAddress
|
---|
107 |
|
---|
108 | #elif defined(RT_OS_DARWIN)
|
---|
109 | # include <dlfcn.h>
|
---|
110 | # define OGLGETPROCADDRESS MyNSGLGetProcAddress
|
---|
111 | /** Resolves an OpenGL symbol. */
|
---|
112 | static void *MyNSGLGetProcAddress(const char *pszSymbol)
|
---|
113 | {
|
---|
114 | /* Another copy in shaderapi.c. */
|
---|
115 | static void *s_pvImage = NULL;
|
---|
116 | if (s_pvImage == NULL)
|
---|
117 | s_pvImage = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
|
---|
118 | return s_pvImage ? dlsym(s_pvImage, pszSymbol) : NULL;
|
---|
119 | }
|
---|
120 |
|
---|
121 | #else
|
---|
122 | # define OGLGETPROCADDRESS(x) glXGetProcAddress((const GLubyte *)x)
|
---|
123 | #endif
|
---|
124 |
|
---|
125 | /* Invert y-coordinate for OpenGL's bottom left origin. */
|
---|
126 | #define D3D_TO_OGL_Y_COORD(ptrSurface, y_coordinate) (ptrSurface->pMipmapLevels[0].size.height - (y_coordinate))
|
---|
127 | #define D3D_TO_OGL_Y_COORD_MIPLEVEL(ptrMipLevel, y_coordinate) (ptrMipLevel->size.height - (y_coordinate))
|
---|
128 |
|
---|
129 | #define OPENGL_INVALID_ID 0
|
---|
130 |
|
---|
131 | //#define MANUAL_FLIP_SURFACE_DATA
|
---|
132 | /* Enable to render the result of DrawPrimitive in a seperate window. */
|
---|
133 | //#define DEBUG_GFX_WINDOW
|
---|
134 |
|
---|
135 | #define VMSVGA3D_CLEAR_CURRENT_CONTEXT(pState) \
|
---|
136 | do { (pState)->idActiveContext = OPENGL_INVALID_ID; } while (0)
|
---|
137 |
|
---|
138 | /** @def VMSVGA3D_SET_CURRENT_CONTEXT
|
---|
139 | * Makes sure the @a pContext is the active OpenGL context.
|
---|
140 | * @parm pState The VMSVGA3d state.
|
---|
141 | * @parm pContext The new context.
|
---|
142 | */
|
---|
143 | #ifdef RT_OS_WINDOWS
|
---|
144 | # define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
|
---|
145 | if ((pState)->idActiveContext != pContext->id) \
|
---|
146 | { \
|
---|
147 | BOOL fMakeCurrentRc = wglMakeCurrent((pContext)->hdc, (pContext)->hglrc); \
|
---|
148 | Assert(fMakeCurrentRc == TRUE); \
|
---|
149 | pState->idActiveContext = (pContext)->id; \
|
---|
150 | } else do { } while (0)
|
---|
151 |
|
---|
152 | #elif defined(RT_OS_DARWIN)
|
---|
153 | # define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
|
---|
154 | if ((pState)->idActiveContext != (pContext)->id) \
|
---|
155 | { \
|
---|
156 | vmsvga3dCocoaViewMakeCurrentContext((pContext)->cocoaView, (pContext)->cocoaContext); \
|
---|
157 | (pState)->idActiveContext = (pContext)->id; \
|
---|
158 | } else do { } while (0)
|
---|
159 | #else
|
---|
160 | # define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
|
---|
161 | if ((pState)->idActiveContext != (pContext)->id) \
|
---|
162 | { \
|
---|
163 | Bool fMakeCurrentRc = glXMakeCurrent((pState)->display, \
|
---|
164 | (pContext)->window, \
|
---|
165 | (pContext)->glxContext); \
|
---|
166 | Assert(fMakeCurrentRc == True); \
|
---|
167 | (pState)->idActiveContext = (pContext)->id; \
|
---|
168 | } else do { } while (0)
|
---|
169 | #endif
|
---|
170 |
|
---|
171 | /** @def VMSVGA3D_CHECK_LAST_ERROR
|
---|
172 | * Checks that the last OpenGL error code indicates success.
|
---|
173 | *
|
---|
174 | * Will assert and return VERR_INTERNAL_ERROR in strict builds, in other
|
---|
175 | * builds it will do nothing and is a NOOP.
|
---|
176 | *
|
---|
177 | * @parm pState The VMSVGA3d state.
|
---|
178 | * @parm pContext The new context.
|
---|
179 | *
|
---|
180 | * @todo Revamp this to include the OpenGL operation so we can see what went
|
---|
181 | * wrong. Maybe include a few of the first occurances in the release
|
---|
182 | * log of regular builds.
|
---|
183 | */
|
---|
184 | #ifdef VBOX_STRICT
|
---|
185 | # define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { \
|
---|
186 | Assert((pState)->idActiveContext == (pContext)->id); \
|
---|
187 | (pContext)->lastError = glGetError(); \
|
---|
188 | AssertMsgReturn((pContext)->lastError == GL_NO_ERROR, \
|
---|
189 | ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError), \
|
---|
190 | VERR_INTERNAL_ERROR); \
|
---|
191 | } while (0)
|
---|
192 | #else
|
---|
193 | # define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { } while (0)
|
---|
194 | #endif
|
---|
195 |
|
---|
196 | /** @def VMSVGA3D_CHECK_LAST_ERROR_WARN
|
---|
197 | * Checks that the last OpenGL error code indicates success.
|
---|
198 | *
|
---|
199 | * Will assert in strict builds, otherwise it's a NOOP.
|
---|
200 | *
|
---|
201 | * @parm pState The VMSVGA3d state.
|
---|
202 | * @parm pContext The new context.
|
---|
203 | */
|
---|
204 | #ifdef VBOX_STRICT
|
---|
205 | # define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { \
|
---|
206 | Assert((pState)->idActiveContext == (pContext)->id); \
|
---|
207 | (pContext)->lastError = glGetError(); \
|
---|
208 | AssertMsg((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError)); \
|
---|
209 | } while (0)
|
---|
210 | #else
|
---|
211 | # define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { } while (0)
|
---|
212 | #endif
|
---|
213 |
|
---|
214 |
|
---|
215 | /**
|
---|
216 | * Macro for doing something and then checking for errors during initialization.
|
---|
217 | * Uses AssertLogRelMsg.
|
---|
218 | */
|
---|
219 | #define VMSVGA3D_INIT_CHECKED(a_Expr) \
|
---|
220 | do \
|
---|
221 | { \
|
---|
222 | a_Expr; \
|
---|
223 | GLenum iGlError = glGetError(); \
|
---|
224 | AssertLogRelMsg(iGlError == GL_NO_ERROR, ("VMSVGA3d: %s -> %#x\n", #a_Expr, iGlError)); \
|
---|
225 | } while (0)
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Macro for doing something and then checking for errors during initialization,
|
---|
229 | * doing the same in the other context when enabled.
|
---|
230 | *
|
---|
231 | * This will try both profiles in dual profile builds. Caller must be in the
|
---|
232 | * default context.
|
---|
233 | *
|
---|
234 | * Uses AssertLogRelMsg to indicate trouble.
|
---|
235 | */
|
---|
236 | #ifdef VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE
|
---|
237 | # define VMSVGA3D_INIT_CHECKED_BOTH(a_pState, a_pContext, a_pOtherCtx, a_Expr) \
|
---|
238 | do \
|
---|
239 | { \
|
---|
240 | for (uint32_t i = 0; i < 64; i++) if (glGetError() == GL_NO_ERROR) break; Assert(glGetError() == GL_NO_ERROR); \
|
---|
241 | a_Expr; \
|
---|
242 | GLenum iGlError = glGetError(); \
|
---|
243 | if (iGlError != GL_NO_ERROR) \
|
---|
244 | { \
|
---|
245 | VMSVGA3D_SET_CURRENT_CONTEXT(a_pState, a_pOtherCtx); \
|
---|
246 | for (uint32_t i = 0; i < 64; i++) if (glGetError() == GL_NO_ERROR) break; Assert(glGetError() == GL_NO_ERROR); \
|
---|
247 | a_Expr; \
|
---|
248 | GLenum iGlError2 = glGetError(); \
|
---|
249 | AssertLogRelMsg(iGlError2 == GL_NO_ERROR, ("VMSVGA3d: %s -> %#x / %#x\n", #a_Expr, iGlError, iGlError2)); \
|
---|
250 | VMSVGA3D_SET_CURRENT_CONTEXT(a_pState, a_pContext); \
|
---|
251 | } \
|
---|
252 | } while (0)
|
---|
253 | #else
|
---|
254 | # define VMSVGA3D_INIT_CHECKED_BOTH(a_pState, a_pContext, a_pOtherCtx, a_Expr) VMSVGA3D_INIT_CHECKED(a_Expr)
|
---|
255 | #endif
|
---|
256 |
|
---|
257 |
|
---|
258 | /*******************************************************************************
|
---|
259 | * Structures, Typedefs and Globals. *
|
---|
260 | *******************************************************************************/
|
---|
261 | typedef struct
|
---|
262 | {
|
---|
263 | SVGA3dSize size;
|
---|
264 | uint32_t cbSurface;
|
---|
265 | uint32_t cbSurfacePitch;
|
---|
266 | void *pSurfaceData;
|
---|
267 | bool fDirty;
|
---|
268 | } VMSVGA3DMIPMAPLEVEL, *PVMSVGA3DMIPMAPLEVEL;
|
---|
269 |
|
---|
270 | /**
|
---|
271 | * SSM descriptor table for the VMSVGA3DMIPMAPLEVEL structure.
|
---|
272 | */
|
---|
273 | static SSMFIELD const g_aVMSVGA3DMIPMAPLEVELFields[] =
|
---|
274 | {
|
---|
275 | SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, size),
|
---|
276 | SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurface),
|
---|
277 | SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurfacePitch),
|
---|
278 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DMIPMAPLEVEL, pSurfaceData),
|
---|
279 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DMIPMAPLEVEL, fDirty),
|
---|
280 | SSMFIELD_ENTRY_TERM()
|
---|
281 | };
|
---|
282 |
|
---|
283 | typedef struct
|
---|
284 | {
|
---|
285 | uint32_t id;
|
---|
286 | uint32_t idAssociatedContext;
|
---|
287 | uint32_t flags;
|
---|
288 | SVGA3dSurfaceFormat format;
|
---|
289 | GLint internalFormatGL;
|
---|
290 | GLint formatGL;
|
---|
291 | GLint typeGL;
|
---|
292 | union
|
---|
293 | {
|
---|
294 | GLuint texture;
|
---|
295 | GLuint buffer;
|
---|
296 | GLuint renderbuffer;
|
---|
297 | } oglId;
|
---|
298 | SVGA3dSurfaceFace faces[SVGA3D_MAX_SURFACE_FACES];
|
---|
299 | uint32_t cFaces;
|
---|
300 | PVMSVGA3DMIPMAPLEVEL pMipmapLevels;
|
---|
301 | uint32_t multiSampleCount;
|
---|
302 | SVGA3dTextureFilter autogenFilter;
|
---|
303 | uint32_t cbBlock; /* block/pixel size in bytes */
|
---|
304 | /* Dirty state; surface was manually updated. */
|
---|
305 | bool fDirty;
|
---|
306 | } VMSVGA3DSURFACE, *PVMSVGA3DSURFACE;
|
---|
307 |
|
---|
308 | /**
|
---|
309 | * SSM descriptor table for the VMSVGA3DSURFACE structure.
|
---|
310 | */
|
---|
311 | static SSMFIELD const g_aVMSVGA3DSURFACEFields[] =
|
---|
312 | {
|
---|
313 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, id),
|
---|
314 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, idAssociatedContext),
|
---|
315 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, flags),
|
---|
316 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, format),
|
---|
317 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, internalFormatGL),
|
---|
318 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, formatGL),
|
---|
319 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, typeGL),
|
---|
320 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, id),
|
---|
321 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, faces),
|
---|
322 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, cFaces),
|
---|
323 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, pMipmapLevels),
|
---|
324 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, multiSampleCount),
|
---|
325 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, autogenFilter),
|
---|
326 | SSMFIELD_ENTRY( VMSVGA3DSURFACE, cbBlock),
|
---|
327 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fDirty),
|
---|
328 | SSMFIELD_ENTRY_TERM()
|
---|
329 | };
|
---|
330 |
|
---|
331 | typedef struct
|
---|
332 | {
|
---|
333 | uint32_t id;
|
---|
334 | uint32_t cid;
|
---|
335 | SVGA3dShaderType type;
|
---|
336 | uint32_t cbData;
|
---|
337 | void *pShaderProgram;
|
---|
338 | union
|
---|
339 | {
|
---|
340 | void *pVertexShader;
|
---|
341 | void *pPixelShader;
|
---|
342 | } u;
|
---|
343 | } VMSVGA3DSHADER, *PVMSVGA3DSHADER;
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * SSM descriptor table for the VMSVGA3DSHADER structure.
|
---|
347 | */
|
---|
348 | static SSMFIELD const g_aVMSVGA3DSHADERFields[] =
|
---|
349 | {
|
---|
350 | SSMFIELD_ENTRY( VMSVGA3DSHADER, id),
|
---|
351 | SSMFIELD_ENTRY( VMSVGA3DSHADER, cid),
|
---|
352 | SSMFIELD_ENTRY( VMSVGA3DSHADER, type),
|
---|
353 | SSMFIELD_ENTRY( VMSVGA3DSHADER, cbData),
|
---|
354 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, pShaderProgram),
|
---|
355 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, u.pVertexShader),
|
---|
356 | SSMFIELD_ENTRY_TERM()
|
---|
357 | };
|
---|
358 |
|
---|
359 | typedef struct
|
---|
360 | {
|
---|
361 | bool fValid;
|
---|
362 | float matrix[16];
|
---|
363 | } VMSVGATRANSFORMSTATE, *PVMSVGATRANSFORMSTATE;
|
---|
364 |
|
---|
365 | typedef struct
|
---|
366 | {
|
---|
367 | bool fValid;
|
---|
368 | SVGA3dMaterial material;
|
---|
369 | } VMSVGAMATERIALSTATE, *PVMSVGAMATERIALSTATE;
|
---|
370 |
|
---|
371 | typedef struct
|
---|
372 | {
|
---|
373 | bool fValid;
|
---|
374 | float plane[4];
|
---|
375 | } VMSVGACLIPPLANESTATE, *PVMSVGACLIPPLANESTATE;
|
---|
376 |
|
---|
377 | typedef struct
|
---|
378 | {
|
---|
379 | bool fEnabled;
|
---|
380 | bool fValidData;
|
---|
381 | SVGA3dLightData data;
|
---|
382 | } VMSVGALIGHTSTATE, *PVMSVGALIGHTSTATE;
|
---|
383 |
|
---|
384 | typedef struct
|
---|
385 | {
|
---|
386 | bool fValid;
|
---|
387 | SVGA3dShaderConstType ctype;
|
---|
388 | uint32_t value[4];
|
---|
389 | } VMSVGASHADERCONST, *PVMSVGASHADERCONST;
|
---|
390 |
|
---|
391 | /**
|
---|
392 | * SSM descriptor table for the VMSVGASHADERCONST structure.
|
---|
393 | */
|
---|
394 | static SSMFIELD const g_aVMSVGASHADERCONSTFields[] =
|
---|
395 | {
|
---|
396 | SSMFIELD_ENTRY( VMSVGASHADERCONST, fValid),
|
---|
397 | SSMFIELD_ENTRY( VMSVGASHADERCONST, ctype),
|
---|
398 | SSMFIELD_ENTRY( VMSVGASHADERCONST, value),
|
---|
399 | SSMFIELD_ENTRY_TERM()
|
---|
400 | };
|
---|
401 |
|
---|
402 | #define VMSVGA3D_UPDATE_SCISSORRECT RT_BIT(0)
|
---|
403 | #define VMSVGA3D_UPDATE_ZRANGE RT_BIT(1)
|
---|
404 | #define VMSVGA3D_UPDATE_VIEWPORT RT_BIT(2)
|
---|
405 | #define VMSVGA3D_UPDATE_VERTEXSHADER RT_BIT(3)
|
---|
406 | #define VMSVGA3D_UPDATE_PIXELSHADER RT_BIT(4)
|
---|
407 | #define VMSVGA3D_UPDATE_TRANSFORM RT_BIT(5)
|
---|
408 | #define VMSVGA3D_UPDATE_MATERIAL RT_BIT(6)
|
---|
409 |
|
---|
410 | typedef struct
|
---|
411 | {
|
---|
412 | uint32_t id;
|
---|
413 | #ifdef RT_OS_WINDOWS
|
---|
414 | /* Device context of the context window. */
|
---|
415 | HDC hdc;
|
---|
416 | /* OpenGL rendering context handle. */
|
---|
417 | HGLRC hglrc;
|
---|
418 | /* Device context window handle. */
|
---|
419 | HWND hwnd;
|
---|
420 | #elif defined(RT_OS_DARWIN)
|
---|
421 | /* OpenGL rendering context */
|
---|
422 | NativeNSOpenGLContextRef cocoaContext;
|
---|
423 | NativeNSViewRef cocoaView;
|
---|
424 | bool fOtherProfile;
|
---|
425 | #else
|
---|
426 | /** XGL rendering context handle */
|
---|
427 | GLXContext glxContext;
|
---|
428 | /** Device context window handle */
|
---|
429 | Window window;
|
---|
430 | /** flag whether the window is mapped (=visible) */
|
---|
431 | bool fMapped;
|
---|
432 | #endif
|
---|
433 | /* Framebuffer object associated with this context. */
|
---|
434 | GLuint idFramebuffer;
|
---|
435 | /* Read and draw framebuffer objects for various operations. */
|
---|
436 | GLuint idReadFramebuffer;
|
---|
437 | GLuint idDrawFramebuffer;
|
---|
438 | /* Last GL error recorded. */
|
---|
439 | GLenum lastError;
|
---|
440 |
|
---|
441 | /* Current active render target (if any) */
|
---|
442 | uint32_t sidRenderTarget;
|
---|
443 | /* Current selected texture surfaces (if any) */
|
---|
444 | uint32_t aSidActiveTexture[SVGA3D_MAX_TEXTURE_STAGE];
|
---|
445 | /* Per context pixel and vertex shaders. */
|
---|
446 | uint32_t cPixelShaders;
|
---|
447 | PVMSVGA3DSHADER paPixelShader;
|
---|
448 | uint32_t cVertexShaders;
|
---|
449 | PVMSVGA3DSHADER paVertexShader;
|
---|
450 | void *pShaderContext;
|
---|
451 | /* Keep track of the internal state to be able to recreate the context properly (save/restore, window resize). */
|
---|
452 | struct
|
---|
453 | {
|
---|
454 | uint32_t u32UpdateFlags;
|
---|
455 |
|
---|
456 | SVGA3dRenderState aRenderState[SVGA3D_RS_MAX];
|
---|
457 | SVGA3dTextureState aTextureState[SVGA3D_MAX_TEXTURE_STAGE][SVGA3D_TS_MAX];
|
---|
458 | VMSVGATRANSFORMSTATE aTransformState[SVGA3D_TRANSFORM_MAX];
|
---|
459 | VMSVGAMATERIALSTATE aMaterial[SVGA3D_FACE_MAX];
|
---|
460 | VMSVGACLIPPLANESTATE aClipPlane[SVGA3D_CLIPPLANE_MAX];
|
---|
461 | VMSVGALIGHTSTATE aLightData[SVGA3D_MAX_LIGHTS];
|
---|
462 |
|
---|
463 | uint32_t aRenderTargets[SVGA3D_RT_MAX];
|
---|
464 | SVGA3dRect RectScissor;
|
---|
465 | SVGA3dRect RectViewPort;
|
---|
466 | SVGA3dZRange zRange;
|
---|
467 | uint32_t shidPixel;
|
---|
468 | uint32_t shidVertex;
|
---|
469 |
|
---|
470 | uint32_t cPixelShaderConst;
|
---|
471 | PVMSVGASHADERCONST paPixelShaderConst;
|
---|
472 | uint32_t cVertexShaderConst;
|
---|
473 | PVMSVGASHADERCONST paVertexShaderConst;
|
---|
474 | } state;
|
---|
475 | } VMSVGA3DCONTEXT, *PVMSVGA3DCONTEXT;
|
---|
476 |
|
---|
477 | /**
|
---|
478 | * SSM descriptor table for the VMSVGA3DCONTEXT structure.
|
---|
479 | */
|
---|
480 | static SSMFIELD const g_aVMSVGA3DCONTEXTFields[] =
|
---|
481 | {
|
---|
482 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, id),
|
---|
483 | #ifdef RT_OS_WINDOWS
|
---|
484 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hdc),
|
---|
485 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hglrc),
|
---|
486 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hwnd),
|
---|
487 | #endif
|
---|
488 |
|
---|
489 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idFramebuffer),
|
---|
490 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idReadFramebuffer),
|
---|
491 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idDrawFramebuffer),
|
---|
492 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, lastError),
|
---|
493 |
|
---|
494 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, sidRenderTarget),
|
---|
495 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, aSidActiveTexture),
|
---|
496 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cPixelShaders),
|
---|
497 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paPixelShader),
|
---|
498 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cVertexShaders),
|
---|
499 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paVertexShader),
|
---|
500 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pShaderContext),
|
---|
501 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.u32UpdateFlags),
|
---|
502 |
|
---|
503 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderState),
|
---|
504 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTextureState),
|
---|
505 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTransformState),
|
---|
506 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aMaterial),
|
---|
507 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aClipPlane),
|
---|
508 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aLightData),
|
---|
509 |
|
---|
510 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderTargets),
|
---|
511 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectScissor),
|
---|
512 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectViewPort),
|
---|
513 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.zRange),
|
---|
514 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidPixel),
|
---|
515 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidVertex),
|
---|
516 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cPixelShaderConst),
|
---|
517 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paPixelShaderConst),
|
---|
518 | SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cVertexShaderConst),
|
---|
519 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paVertexShaderConst),
|
---|
520 | SSMFIELD_ENTRY_TERM()
|
---|
521 | };
|
---|
522 |
|
---|
523 | /**
|
---|
524 | * VMSVGA3d state data.
|
---|
525 | *
|
---|
526 | * Allocated on the heap and pointed to by VMSVGAState::p3dState.
|
---|
527 | */
|
---|
528 | typedef struct VMSVGA3DSTATE
|
---|
529 | {
|
---|
530 | #ifdef RT_OS_WINDOWS
|
---|
531 | /** Window Thread. */
|
---|
532 | R3PTRTYPE(RTTHREAD) pWindowThread;
|
---|
533 | DWORD idWindowThread;
|
---|
534 | HMODULE hInstance;
|
---|
535 | /** Window request semaphore. */
|
---|
536 | RTSEMEVENT WndRequestSem;
|
---|
537 | #elif defined(RT_OS_LINUX)
|
---|
538 | /* The X display */
|
---|
539 | Display *display;
|
---|
540 | R3PTRTYPE(RTTHREAD) pWindowThread;
|
---|
541 | bool bTerminate;
|
---|
542 | #endif
|
---|
543 |
|
---|
544 | float fGLVersion;
|
---|
545 | /* Current active context. */
|
---|
546 | uint32_t idActiveContext;
|
---|
547 |
|
---|
548 | struct
|
---|
549 | {
|
---|
550 | PFNGLISRENDERBUFFERPROC glIsRenderbuffer;
|
---|
551 | PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
|
---|
552 | PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
|
---|
553 | PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
|
---|
554 | PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
|
---|
555 | PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv;
|
---|
556 | PFNGLISFRAMEBUFFERPROC glIsFramebuffer;
|
---|
557 | PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
|
---|
558 | PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
|
---|
559 | PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
|
---|
560 | PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
|
---|
561 | PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;
|
---|
562 | PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
|
---|
563 | PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D;
|
---|
564 | PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
|
---|
565 | PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv;
|
---|
566 | PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
|
---|
567 | PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
|
---|
568 | PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample;
|
---|
569 | PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer;
|
---|
570 | PFNGLPOINTPARAMETERFPROC glPointParameterf;
|
---|
571 | PFNGLBLENDEQUATIONPROC glBlendEquation;
|
---|
572 | PFNGLBLENDEQUATIONSEPARATEPROC glBlendEquationSeparate;
|
---|
573 | PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;
|
---|
574 | PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate;
|
---|
575 | PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate;
|
---|
576 | PFNGLBLENDCOLORPROC glBlendColor;
|
---|
577 | PFNGLBINDBUFFERPROC glBindBuffer;
|
---|
578 | PFNGLDELETEBUFFERSPROC glDeleteBuffers;
|
---|
579 | PFNGLGENBUFFERSPROC glGenBuffers;
|
---|
580 | PFNGLBUFFERDATAPROC glBufferData;
|
---|
581 | PFNGLMAPBUFFERPROC glMapBuffer;
|
---|
582 | PFNGLUNMAPBUFFERPROC glUnmapBuffer;
|
---|
583 | PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
|
---|
584 | PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;
|
---|
585 | PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
|
---|
586 | PFNGLFOGCOORDPOINTERPROC glFogCoordPointer;
|
---|
587 | PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex;
|
---|
588 | PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex;
|
---|
589 | PFNGLACTIVETEXTUREPROC glActiveTexture;
|
---|
590 | PFNGLCLIENTACTIVETEXTUREPROC glClientActiveTexture;
|
---|
591 | PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
|
---|
592 | PFNGLPROVOKINGVERTEXPROC glProvokingVertex;
|
---|
593 | bool fEXT_stencil_two_side;
|
---|
594 | } ext;
|
---|
595 |
|
---|
596 | struct
|
---|
597 | {
|
---|
598 | GLint maxActiveLights;
|
---|
599 | GLint maxTextureBufferSize;
|
---|
600 | GLint maxTextures;
|
---|
601 | GLint maxClipDistances;
|
---|
602 | GLint maxColorAttachments;
|
---|
603 | GLint maxRectangleTextureSize;
|
---|
604 | GLint maxTextureAnisotropy;
|
---|
605 | GLint maxVertexShaderInstructions;
|
---|
606 | GLint maxFragmentShaderInstructions;
|
---|
607 | GLint maxVertexShaderTemps;
|
---|
608 | GLint maxFragmentShaderTemps;
|
---|
609 | GLfloat flPointSize[2];
|
---|
610 | SVGA3dPixelShaderVersion fragmentShaderVersion;
|
---|
611 | SVGA3dVertexShaderVersion vertexShaderVersion;
|
---|
612 | bool fS3TCSupported;
|
---|
613 | } caps;
|
---|
614 |
|
---|
615 | uint32_t cContexts;
|
---|
616 | PVMSVGA3DCONTEXT paContext;
|
---|
617 | uint32_t cSurfaces;
|
---|
618 | PVMSVGA3DSURFACE paSurface;
|
---|
619 | #ifdef DEBUG_GFX_WINDOW_TEST_CONTEXT
|
---|
620 | uint32_t idTestContext;
|
---|
621 | #endif
|
---|
622 | /** The GL_EXTENSIONS value (space padded) for the default OpenGL profile.
|
---|
623 | * Free with RTStrFree. */
|
---|
624 | R3PTRTYPE(char *) pszExtensions;
|
---|
625 |
|
---|
626 | /** The GL_EXTENSIONS value (space padded) for the other OpenGL profile.
|
---|
627 | * Free with RTStrFree.
|
---|
628 | *
|
---|
629 | * This is used to detect shader model version since some implementations
|
---|
630 | * (darwin) hides extensions that have made it into core and probably a
|
---|
631 | * bunch of others when using a OpenGL core profile instead of a legacy one */
|
---|
632 | R3PTRTYPE(char *) pszOtherExtensions;
|
---|
633 | /** The version of the other GL profile. */
|
---|
634 | float fOtherGLVersion;
|
---|
635 |
|
---|
636 | /** Shader talk back interface. */
|
---|
637 | VBOXVMSVGASHADERIF ShaderIf;
|
---|
638 | } VMSVGA3DSTATE;
|
---|
639 | /** Pointer to the VMSVGA3d state. */
|
---|
640 | typedef VMSVGA3DSTATE *PVMSVGA3DSTATE;
|
---|
641 |
|
---|
642 | /**
|
---|
643 | * SSM descriptor table for the VMSVGA3DSTATE structure.
|
---|
644 | */
|
---|
645 | static SSMFIELD const g_aVMSVGA3DSTATEFields[] =
|
---|
646 | {
|
---|
647 | #ifdef RT_OS_WINDOWS
|
---|
648 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, pWindowThread),
|
---|
649 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, idWindowThread),
|
---|
650 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, hInstance),
|
---|
651 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, WndRequestSem),
|
---|
652 | #elif defined(RT_OS_LINUX)
|
---|
653 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, display),
|
---|
654 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, pWindowThread),
|
---|
655 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, bTerminate),
|
---|
656 | #endif
|
---|
657 | SSMFIELD_ENTRY( VMSVGA3DSTATE, fGLVersion),
|
---|
658 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, idActiveContext),
|
---|
659 |
|
---|
660 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, ext),
|
---|
661 | SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, caps),
|
---|
662 |
|
---|
663 | SSMFIELD_ENTRY( VMSVGA3DSTATE, cContexts),
|
---|
664 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, paContext),
|
---|
665 | SSMFIELD_ENTRY( VMSVGA3DSTATE, cSurfaces),
|
---|
666 | SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, paSurface),
|
---|
667 | SSMFIELD_ENTRY_TERM()
|
---|
668 | };
|
---|
669 |
|
---|
670 |
|
---|
671 | /* Define the default light parameters as specified by MSDN. */
|
---|
672 | /* @todo move out; fetched from Wine */
|
---|
673 | const SVGA3dLightData vmsvga3d_default_light =
|
---|
674 | {
|
---|
675 | SVGA3D_LIGHTTYPE_DIRECTIONAL, /* type */
|
---|
676 | false, /* inWorldSpace */
|
---|
677 | { 1.0f, 1.0f, 1.0f, 0.0f }, /* diffuse r,g,b,a */
|
---|
678 | { 0.0f, 0.0f, 0.0f, 0.0f }, /* specular r,g,b,a */
|
---|
679 | { 0.0f, 0.0f, 0.0f, 0.0f }, /* ambient r,g,b,a, */
|
---|
680 | { 0.0f, 0.0f, 0.0f }, /* position x,y,z */
|
---|
681 | { 0.0f, 0.0f, 1.0f }, /* direction x,y,z */
|
---|
682 | 0.0f, /* range */
|
---|
683 | 0.0f, /* falloff */
|
---|
684 | 0.0f, 0.0f, 0.0f, /* attenuation 0,1,2 */
|
---|
685 | 0.0f, /* theta */
|
---|
686 | 0.0f /* phi */
|
---|
687 | };
|
---|
688 |
|
---|
689 | RT_C_DECLS_BEGIN
|
---|
690 | static int vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface);
|
---|
691 | static void vmsvgaColor2GLFloatArray(uint32_t color, GLfloat *pRed, GLfloat *pGreen, GLfloat *pBlue, GLfloat *pAlpha);
|
---|
692 | RT_C_DECLS_END
|
---|
693 |
|
---|
694 |
|
---|
695 | /**
|
---|
696 | * Checks if the given OpenGL extension is supported.
|
---|
697 | *
|
---|
698 | * @returns true if supported, false if not.
|
---|
699 | * @param pState The VMSVGA3d state.
|
---|
700 | * @param fActualGLVersion The actual OpenGL version we're working against.
|
---|
701 | * @param fMinGLVersion The OpenGL version that introduced this feature
|
---|
702 | * into the core.
|
---|
703 | * @param pszWantedExtension The name of the OpenGL extension we want padded
|
---|
704 | * with one space at each end.
|
---|
705 | * @remarks Init time only.
|
---|
706 | */
|
---|
707 | static bool vmsvga3dCheckGLExtension(PVMSVGA3DSTATE pState, float fMinGLVersion, const char *pszWantedExtension)
|
---|
708 | {
|
---|
709 | /* check padding. */
|
---|
710 | Assert(pszWantedExtension[0] == ' ');
|
---|
711 | Assert(pszWantedExtension[1] != ' ');
|
---|
712 | Assert(strchr(&pszWantedExtension[1], ' ') + 1 == strchr(pszWantedExtension, '\0'));
|
---|
713 |
|
---|
714 | /* Look it up. */
|
---|
715 | bool fRet = false;
|
---|
716 | if (strstr(pState->pszExtensions, pszWantedExtension))
|
---|
717 | fRet = true;
|
---|
718 |
|
---|
719 | /* Temporarily. Later start if (fMinGLVersion != 0.0 && fActualGLVersion >= fMinGLVersion) return true; */
|
---|
720 | AssertMsg( fMinGLVersion == 0.0
|
---|
721 | || fRet == (pState->fGLVersion >= fMinGLVersion)
|
---|
722 | #ifdef RT_OS_DARWIN
|
---|
723 | || VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE == 2.1
|
---|
724 | #endif
|
---|
725 | , ("%s actual:%d min:%d fRet=%d\n",
|
---|
726 | pszWantedExtension, (int)(pState->fGLVersion * 10), (int)(fMinGLVersion * 10), fRet));
|
---|
727 | return fRet;
|
---|
728 | }
|
---|
729 |
|
---|
730 |
|
---|
731 | /**
|
---|
732 | * Outputs GL_EXTENSIONS list to the release log.
|
---|
733 | */
|
---|
734 | static void vmsvga3dLogRelExtensions(const char *pszPrefix, const char *pszExtensions)
|
---|
735 | {
|
---|
736 | /* OpenGL 3.0 interface (glGetString(GL_EXTENSIONS) return NULL). */
|
---|
737 | bool fBuffered = RTLogRelSetBuffering(true);
|
---|
738 |
|
---|
739 | /*
|
---|
740 | * Determin the column widths first.
|
---|
741 | */
|
---|
742 | size_t acchWidths[4] = { 1, 1, 1, 1 };
|
---|
743 | uint32_t i;
|
---|
744 | const char *psz = pszExtensions;
|
---|
745 | for (i = 0; ; i++)
|
---|
746 | {
|
---|
747 | while (*psz == ' ')
|
---|
748 | psz++;
|
---|
749 | if (!*psz)
|
---|
750 | break;
|
---|
751 |
|
---|
752 | const char *pszEnd = strchr(psz, ' ');
|
---|
753 | AssertBreak(pszEnd);
|
---|
754 | size_t cch = pszEnd - psz;
|
---|
755 |
|
---|
756 | uint32_t iColumn = i % RT_ELEMENTS(acchWidths);
|
---|
757 | if (acchWidths[iColumn] < cch)
|
---|
758 | acchWidths[iColumn] = cch;
|
---|
759 |
|
---|
760 | psz = pszEnd;
|
---|
761 | }
|
---|
762 |
|
---|
763 | /*
|
---|
764 | * Output it.
|
---|
765 | */
|
---|
766 | LogRel(("VMSVGA3d: %sOpenGL extensions (%d):", pszPrefix, i));
|
---|
767 | psz = pszExtensions;
|
---|
768 | for (i = 0; ; i++)
|
---|
769 | {
|
---|
770 | while (*psz == ' ')
|
---|
771 | psz++;
|
---|
772 | if (!*psz)
|
---|
773 | break;
|
---|
774 |
|
---|
775 | const char *pszEnd = strchr(psz, ' ');
|
---|
776 | AssertBreak(pszEnd);
|
---|
777 | size_t cch = pszEnd - psz;
|
---|
778 |
|
---|
779 | uint32_t iColumn = i % RT_ELEMENTS(acchWidths);
|
---|
780 | if (iColumn == 0)
|
---|
781 | LogRel(("\nVMSVGA3d: %-*.*s", acchWidths[iColumn], cch, psz));
|
---|
782 | else if (iColumn != RT_ELEMENTS(acchWidths) - 1)
|
---|
783 | LogRel((" %-*.*s", acchWidths[iColumn], cch, psz));
|
---|
784 | else
|
---|
785 | LogRel((" %.*s", cch, psz));
|
---|
786 |
|
---|
787 | psz = pszEnd;
|
---|
788 | }
|
---|
789 |
|
---|
790 | RTLogRelSetBuffering(fBuffered);
|
---|
791 | LogRel(("\n"));
|
---|
792 | }
|
---|
793 |
|
---|
794 | /**
|
---|
795 | * Gathers the GL_EXTENSIONS list, storing it as a space padded list at
|
---|
796 | * @a ppszExtensions.
|
---|
797 | *
|
---|
798 | * @returns VINF_SUCCESS or VERR_NO_STR_MEMORY
|
---|
799 | * @param ppszExtensions Pointer to the string pointer. Free with RTStrFree.
|
---|
800 | * @param fGLProfileVersion The OpenGL profile version.
|
---|
801 | */
|
---|
802 | static int vmsvga3dGatherExtensions(char **ppszExtensions, float fGLProfileVersion)
|
---|
803 | {
|
---|
804 | int rc;
|
---|
805 | *ppszExtensions = NULL;
|
---|
806 |
|
---|
807 | /*
|
---|
808 | * Try the old glGetString interface first.
|
---|
809 | */
|
---|
810 | const char *pszExtensions = (const char *)glGetString(GL_EXTENSIONS);
|
---|
811 | if (pszExtensions)
|
---|
812 | {
|
---|
813 | rc = RTStrAAppendExN(ppszExtensions, 3, " ", (size_t)1, pszExtensions, RTSTR_MAX, " ", (size_t)1);
|
---|
814 | AssertLogRelRCReturn(rc, rc);
|
---|
815 | }
|
---|
816 | else
|
---|
817 | {
|
---|
818 | /*
|
---|
819 | * The new interface where each extension string is retrieved separately.
|
---|
820 | * Note! Cannot use VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE here because
|
---|
821 | * the above GL_EXTENSIONS error lingers on darwin. sucks.
|
---|
822 | */
|
---|
823 | #ifndef GL_NUM_EXTENSIONS
|
---|
824 | # define GL_NUM_EXTENSIONS 0x821D
|
---|
825 | #endif
|
---|
826 | GLint cExtensions = 1024;
|
---|
827 | glGetIntegerv(GL_NUM_EXTENSIONS, &cExtensions);
|
---|
828 | Assert(cExtensions != 1024);
|
---|
829 |
|
---|
830 | PFNGLGETSTRINGIPROC pfnGlGetStringi = (PFNGLGETSTRINGIPROC)OGLGETPROCADDRESS("glGetStringi");
|
---|
831 | AssertLogRelReturn(pfnGlGetStringi, VERR_NOT_SUPPORTED);
|
---|
832 |
|
---|
833 | rc = RTStrAAppend(ppszExtensions, " ");
|
---|
834 | for (GLint i = 0; RT_SUCCESS(rc) && i < cExtensions; i++)
|
---|
835 | {
|
---|
836 | const char *pszExt = (const char *)pfnGlGetStringi(GL_EXTENSIONS, i);
|
---|
837 | if (pszExt)
|
---|
838 | rc = RTStrAAppendExN(ppszExtensions, 2, pfnGlGetStringi(GL_EXTENSIONS, i), RTSTR_MAX, " ", (size_t)1);
|
---|
839 | }
|
---|
840 | AssertRCReturn(rc, rc);
|
---|
841 | }
|
---|
842 |
|
---|
843 | #if 1
|
---|
844 | /*
|
---|
845 | * Add extensions promoted into the core OpenGL profile.
|
---|
846 | */
|
---|
847 | static const struct
|
---|
848 | {
|
---|
849 | float fGLVersion;
|
---|
850 | const char *pszzExtensions;
|
---|
851 | } s_aPromotedExtensions[] =
|
---|
852 | {
|
---|
853 | {
|
---|
854 | 1.1,
|
---|
855 | " GL_EXT_vertex_array \0"
|
---|
856 | " GL_EXT_polygon_offset \0"
|
---|
857 | " GL_EXT_blend_logic_op \0"
|
---|
858 | " GL_EXT_texture \0"
|
---|
859 | " GL_EXT_copy_texture \0"
|
---|
860 | " GL_EXT_subtexture \0"
|
---|
861 | " GL_EXT_texture_object \0"
|
---|
862 | " GL_ARB_framebuffer_object \0"
|
---|
863 | " GL_ARB_map_buffer_range \0"
|
---|
864 | " GL_ARB_vertex_array_object \0"
|
---|
865 | "\0"
|
---|
866 | },
|
---|
867 | {
|
---|
868 | 1.2,
|
---|
869 | " EXT_texture3D \0"
|
---|
870 | " EXT_bgra \0"
|
---|
871 | " EXT_packed_pixels \0"
|
---|
872 | " EXT_rescale_normal \0"
|
---|
873 | " EXT_separate_specular_color \0"
|
---|
874 | " SGIS_texture_edge_clamp \0"
|
---|
875 | " SGIS_texture_lod \0"
|
---|
876 | " EXT_draw_range_elements \0"
|
---|
877 | "\0"
|
---|
878 | },
|
---|
879 | {
|
---|
880 | 1.3,
|
---|
881 | " GL_ARB_texture_compression \0"
|
---|
882 | " GL_ARB_texture_cube_map \0"
|
---|
883 | " GL_ARB_multisample \0"
|
---|
884 | " GL_ARB_multitexture \0"
|
---|
885 | " GL_ARB_texture_env_add \0"
|
---|
886 | " GL_ARB_texture_env_combine \0"
|
---|
887 | " GL_ARB_texture_env_dot3 \0"
|
---|
888 | " GL_ARB_texture_border_clamp \0"
|
---|
889 | " GL_ARB_transpose_matrix \0"
|
---|
890 | "\0"
|
---|
891 | },
|
---|
892 | {
|
---|
893 | 1.5,
|
---|
894 | " GL_SGIS_generate_mipmap \0"
|
---|
895 | /*" GL_NV_blend_equare \0"*/
|
---|
896 | " GL_ARB_depth_texture \0"
|
---|
897 | " GL_ARB_shadow \0"
|
---|
898 | " GL_EXT_fog_coord \0"
|
---|
899 | " GL_EXT_multi_draw_arrays \0"
|
---|
900 | " GL_ARB_point_parameters \0"
|
---|
901 | " GL_EXT_secondary_color \0"
|
---|
902 | " GL_EXT_blend_func_separate \0"
|
---|
903 | " GL_EXT_stencil_wrap \0"
|
---|
904 | " GL_ARB_texture_env_crossbar \0"
|
---|
905 | " GL_EXT_texture_lod_bias \0"
|
---|
906 | " GL_ARB_texture_mirrored_repeat \0"
|
---|
907 | " GL_ARB_window_pos \0"
|
---|
908 | "\0"
|
---|
909 | },
|
---|
910 | {
|
---|
911 | 1.6,
|
---|
912 | " GL_ARB_vertex_buffer_object \0"
|
---|
913 | " GL_ARB_occlusion_query \0"
|
---|
914 | " GL_EXT_shadow_funcs \0"
|
---|
915 | },
|
---|
916 | {
|
---|
917 | 2.0,
|
---|
918 | " GL_ARB_shader_objects \0" /*??*/
|
---|
919 | " GL_ARB_vertex_shader \0" /*??*/
|
---|
920 | " GL_ARB_fragment_shader \0" /*??*/
|
---|
921 | " GL_ARB_shading_language_100 \0" /*??*/
|
---|
922 | " GL_ARB_draw_buffers \0"
|
---|
923 | " GL_ARB_texture_non_power_of_two \0"
|
---|
924 | " GL_ARB_point_sprite \0"
|
---|
925 | " GL_ATI_separate_stencil \0"
|
---|
926 | " GL_EXT_stencil_two_side \0"
|
---|
927 | "\0"
|
---|
928 | },
|
---|
929 | {
|
---|
930 | 2.1,
|
---|
931 | " GL_ARB_pixel_buffer_object \0"
|
---|
932 | " GL_EXT_texture_sRGB \0"
|
---|
933 | "\0"
|
---|
934 | },
|
---|
935 | {
|
---|
936 | 3.0,
|
---|
937 | " GL_ARB_framebuffer_object \0"
|
---|
938 | " GL_ARB_map_buffer_range \0"
|
---|
939 | " GL_ARB_vertex_array_object \0"
|
---|
940 | "\0"
|
---|
941 | },
|
---|
942 | {
|
---|
943 | 3.1,
|
---|
944 | " GL_ARB_copy_buffer \0"
|
---|
945 | " GL_ARB_uniform_buffer_object \0"
|
---|
946 | "\0"
|
---|
947 | },
|
---|
948 | {
|
---|
949 | 3.2,
|
---|
950 | " GL_ARB_vertex_array_bgra \0"
|
---|
951 | " GL_ARB_draw_elements_base_vertex \0"
|
---|
952 | " GL_ARB_fragment_coord_conventions \0"
|
---|
953 | " GL_ARB_provoking_vertex \0"
|
---|
954 | " GL_ARB_seamless_cube_map \0"
|
---|
955 | " GL_ARB_texture_multisample \0"
|
---|
956 | " GL_ARB_depth_clamp \0"
|
---|
957 | " GL_ARB_sync \0"
|
---|
958 | " GL_ARB_geometry_shader4 \0" /*??*/
|
---|
959 | "\0"
|
---|
960 | },
|
---|
961 | {
|
---|
962 | 3.3,
|
---|
963 | " GL_ARB_blend_func_extended \0"
|
---|
964 | " GL_ARB_sampler_objects \0"
|
---|
965 | " GL_ARB_explicit_attrib_location \0"
|
---|
966 | " GL_ARB_occlusion_query2 \0"
|
---|
967 | " GL_ARB_shader_bit_encoding \0"
|
---|
968 | " GL_ARB_texture_rgb10_a2ui \0"
|
---|
969 | " GL_ARB_texture_swizzle \0"
|
---|
970 | " GL_ARB_timer_query \0"
|
---|
971 | " GL_ARB_vertex_type_2_10_10_10_rev \0"
|
---|
972 | "\0"
|
---|
973 | },
|
---|
974 | {
|
---|
975 | 4.0,
|
---|
976 | " GL_ARB_texture_query_lod \0"
|
---|
977 | " GL_ARB_draw_indirect \0"
|
---|
978 | " GL_ARB_gpu_shader5 \0"
|
---|
979 | " GL_ARB_gpu_shader_fp64 \0"
|
---|
980 | " GL_ARB_shader_subroutine \0"
|
---|
981 | " GL_ARB_tessellation_shader \0"
|
---|
982 | " GL_ARB_texture_buffer_object_rgb32 \0"
|
---|
983 | " GL_ARB_texture_cube_map_array \0"
|
---|
984 | " GL_ARB_texture_gather \0"
|
---|
985 | " GL_ARB_transform_feedback2 \0"
|
---|
986 | " GL_ARB_transform_feedback3 \0"
|
---|
987 | "\0"
|
---|
988 | },
|
---|
989 | {
|
---|
990 | 4.1,
|
---|
991 | " GL_ARB_ES2_compatibility \0"
|
---|
992 | " GL_ARB_get_program_binary \0"
|
---|
993 | " GL_ARB_separate_shader_objects \0"
|
---|
994 | " GL_ARB_shader_precision \0"
|
---|
995 | " GL_ARB_vertex_attrib_64bit \0"
|
---|
996 | " GL_ARB_viewport_array \0"
|
---|
997 | "\0"
|
---|
998 | }
|
---|
999 | };
|
---|
1000 |
|
---|
1001 | uint32_t cPromoted = 0;
|
---|
1002 | for (uint32_t i = 0; i < RT_ELEMENTS(s_aPromotedExtensions) && s_aPromotedExtensions[i].fGLVersion <= fGLProfileVersion; i++)
|
---|
1003 | {
|
---|
1004 | const char *pszExt = s_aPromotedExtensions[i].pszzExtensions;
|
---|
1005 | while (*pszExt)
|
---|
1006 | {
|
---|
1007 | size_t cchExt = strlen(pszExt);
|
---|
1008 | Assert(cchExt > 3);
|
---|
1009 | Assert(pszExt[0] == ' ');
|
---|
1010 | Assert(pszExt[1] != ' ');
|
---|
1011 | Assert(pszExt[cchExt - 2] != ' ');
|
---|
1012 | Assert(pszExt[cchExt - 1] == ' ');
|
---|
1013 |
|
---|
1014 | if (strstr(*ppszExtensions, pszExt) == NULL)
|
---|
1015 | {
|
---|
1016 | if (cPromoted++ == 0)
|
---|
1017 | {
|
---|
1018 | rc = RTStrAAppend(ppszExtensions, " <promoted-extensions:> <promoted-extensions:> <promoted-extensions:> ");
|
---|
1019 | AssertRCReturn(rc, rc);
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | rc = RTStrAAppend(ppszExtensions, pszExt);
|
---|
1023 | AssertRCReturn(rc, rc);
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | pszExt = strchr(pszExt, '\0') + 1;
|
---|
1027 | }
|
---|
1028 | }
|
---|
1029 | #endif
|
---|
1030 |
|
---|
1031 | return VINF_SUCCESS;
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | /**
|
---|
1035 | * @interface_method_impl{VBOXVMSVGASHADERIF, pfnSwitchInitProfile}
|
---|
1036 | */
|
---|
1037 | static DECLCALLBACK(void) vmsvga3dShaderIfSwitchInitProfile(PVBOXVMSVGASHADERIF pThis, bool fOtherProfile)
|
---|
1038 | {
|
---|
1039 | #ifdef VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE
|
---|
1040 | PVMSVGA3DSTATE pState = RT_FROM_MEMBER(pThis, VMSVGA3DSTATE, ShaderIf);
|
---|
1041 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, &pState->paContext[fOtherProfile ? 2 : 1]);
|
---|
1042 | #else
|
---|
1043 | NOREF(pThis);
|
---|
1044 | NOREF(fOtherProfile);
|
---|
1045 | #endif
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 |
|
---|
1049 | /**
|
---|
1050 | * @interface_method_impl{VBOXVMSVGASHADERIF, pfnGetNextExtension}
|
---|
1051 | */
|
---|
1052 | static DECLCALLBACK(bool) vmsvga3dShaderIfGetNextExtension(PVBOXVMSVGASHADERIF pThis, void **ppvEnumCtx,
|
---|
1053 | char *pszBuf, size_t cbBuf, bool fOtherProfile)
|
---|
1054 | {
|
---|
1055 | PVMSVGA3DSTATE pState = RT_FROM_MEMBER(pThis, VMSVGA3DSTATE, ShaderIf);
|
---|
1056 | const char *pszCur = *ppvEnumCtx ? (const char *)*ppvEnumCtx
|
---|
1057 | : fOtherProfile ? pState->pszOtherExtensions : pState->pszExtensions;
|
---|
1058 | while (*pszCur == ' ')
|
---|
1059 | pszCur++;
|
---|
1060 | if (!*pszCur)
|
---|
1061 | return false;
|
---|
1062 |
|
---|
1063 | const char *pszEnd = strchr(pszCur, ' ');
|
---|
1064 | AssertReturn(pszEnd, false);
|
---|
1065 | size_t cch = pszEnd - pszCur;
|
---|
1066 | if (cch < cbBuf)
|
---|
1067 | {
|
---|
1068 | memcpy(pszBuf, pszCur, cch);
|
---|
1069 | pszBuf[cch] = '\0';
|
---|
1070 | }
|
---|
1071 | else if (cbBuf > 0)
|
---|
1072 | {
|
---|
1073 | memcpy(pszBuf, "<overflow>", RT_MIN(sizeof("<overflow>"), cbBuf));
|
---|
1074 | pszBuf[cbBuf - 1] = '\0';
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 | *ppvEnumCtx = (void *)pszEnd;
|
---|
1078 | return true;
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 |
|
---|
1082 | /**
|
---|
1083 | * Initializes the VMSVGA3D state during VGA device construction.
|
---|
1084 | *
|
---|
1085 | * Failure are generally not fatal, 3D support will just be disabled.
|
---|
1086 | *
|
---|
1087 | * @returns VBox status code.
|
---|
1088 | * @param pThis The VGA device state where svga.p3dState will be modified.
|
---|
1089 | */
|
---|
1090 | int vmsvga3dInit(PVGASTATE pThis)
|
---|
1091 | {
|
---|
1092 | AssertCompile(GL_TRUE == 1);
|
---|
1093 | AssertCompile(GL_FALSE == 0);
|
---|
1094 |
|
---|
1095 | /*
|
---|
1096 | * Load and resolve imports from the external shared libraries.
|
---|
1097 | */
|
---|
1098 | RTERRINFOSTATIC ErrInfo;
|
---|
1099 | int rc = ExplicitlyLoadVBoxSVGA3D(true /*fResolveAllImports*/, RTErrInfoInitStatic(&ErrInfo));
|
---|
1100 | if (RT_FAILURE(rc))
|
---|
1101 | {
|
---|
1102 | LogRel(("VMSVGA3d: Error loading VBoxSVGA3D and resolving necessary functions: %Rrc - %s\n", rc, ErrInfo.Core.pszMsg));
|
---|
1103 | return rc;
|
---|
1104 | }
|
---|
1105 | #ifdef RT_OS_DARWIN
|
---|
1106 | rc = ExplicitlyLoadVBoxSVGA3DObjC(true /*fResolveAllImports*/, RTErrInfoInitStatic(&ErrInfo));
|
---|
1107 | if (RT_FAILURE(rc))
|
---|
1108 | {
|
---|
1109 | LogRel(("VMSVGA3d: Error loading VBoxSVGA3DObjC and resolving necessary functions: %Rrc - %s\n", rc, ErrInfo.Core.pszMsg));
|
---|
1110 | return rc;
|
---|
1111 | }
|
---|
1112 | #endif
|
---|
1113 |
|
---|
1114 | /*
|
---|
1115 | * Allocate the state.
|
---|
1116 | */
|
---|
1117 | pThis->svga.p3dState = RTMemAllocZ(sizeof(VMSVGA3DSTATE));
|
---|
1118 | AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
|
---|
1119 |
|
---|
1120 | #ifdef RT_OS_WINDOWS
|
---|
1121 | /* Create event semaphore and async IO thread. */
|
---|
1122 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
1123 | rc = RTSemEventCreate(&pState->WndRequestSem);
|
---|
1124 | if (RT_SUCCESS(rc))
|
---|
1125 | {
|
---|
1126 | rc = RTThreadCreate(&pState->pWindowThread, vmsvga3dWindowThread, pState->WndRequestSem, 0, RTTHREADTYPE_GUI, 0,
|
---|
1127 | "VMSVGA3DWND");
|
---|
1128 | if (RT_SUCCESS(rc))
|
---|
1129 | return VINF_SUCCESS;
|
---|
1130 |
|
---|
1131 | /* bail out. */
|
---|
1132 | LogRel(("VMSVGA3d: RTThreadCreate failed: %Rrc\n", rc));
|
---|
1133 | RTSemEventDestroy(&pState->WndRequestSem);
|
---|
1134 | }
|
---|
1135 | else
|
---|
1136 | LogRel(("VMSVGA3d: RTSemEventCreate failed: %Rrc\n", rc));
|
---|
1137 | RTMemFree(pThis->svga.p3dState);
|
---|
1138 | pThis->svga.p3dState = NULL;
|
---|
1139 | return rc;
|
---|
1140 | #else
|
---|
1141 | return VINF_SUCCESS;
|
---|
1142 | #endif
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | /* We must delay window creation until the PowerOn phase. Init is too early and will cause failures. */
|
---|
1146 | int vmsvga3dPowerOn(PVGASTATE pThis)
|
---|
1147 | {
|
---|
1148 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
1149 | AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
|
---|
1150 | PVMSVGA3DCONTEXT pContext;
|
---|
1151 | #ifdef VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE
|
---|
1152 | PVMSVGA3DCONTEXT pOtherCtx;
|
---|
1153 | #endif
|
---|
1154 | int rc;
|
---|
1155 |
|
---|
1156 | if (pState->fGLVersion != 0.0)
|
---|
1157 | return VINF_SUCCESS; /* already initialized (load state) */
|
---|
1158 |
|
---|
1159 | /*
|
---|
1160 | * OpenGL function calls aren't possible without a valid current context, so create a fake one here.
|
---|
1161 | */
|
---|
1162 | rc = vmsvga3dContextDefine(pThis, 1, false /*fOtherProfile*/);
|
---|
1163 | AssertRCReturn(rc, rc);
|
---|
1164 |
|
---|
1165 | pContext = &pState->paContext[1];
|
---|
1166 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
1167 |
|
---|
1168 | LogRel(("VMSVGA3d: OpenGL version: %s\n"
|
---|
1169 | "VMSVGA3d: OpenGL Vendor: %s\n"
|
---|
1170 | "VMSVGA3d: OpenGL Renderer: %s\n"
|
---|
1171 | "VMSVGA3d: OpenGL shader language version: %s\n",
|
---|
1172 | glGetString(GL_VERSION), glGetString(GL_VENDOR), glGetString(GL_RENDERER),
|
---|
1173 | glGetString(GL_SHADING_LANGUAGE_VERSION)));
|
---|
1174 |
|
---|
1175 | rc = vmsvga3dGatherExtensions(&pState->pszExtensions, VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE);
|
---|
1176 | AssertRCReturn(rc, rc);
|
---|
1177 | vmsvga3dLogRelExtensions("", pState->pszExtensions);
|
---|
1178 |
|
---|
1179 | pState->fGLVersion = atof((const char *)glGetString(GL_VERSION));
|
---|
1180 |
|
---|
1181 |
|
---|
1182 | #ifdef VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE
|
---|
1183 | /*
|
---|
1184 | * Get the extension list for the alternative profile so we can better
|
---|
1185 | * figure out the shader model and stuff.
|
---|
1186 | */
|
---|
1187 | rc = vmsvga3dContextDefine(pThis, 2, true /*fOtherProfile*/);
|
---|
1188 | AssertLogRelRCReturn(rc, rc);
|
---|
1189 | pContext = &pState->paContext[1]; /* Array may have been reallocated. */
|
---|
1190 |
|
---|
1191 | pOtherCtx = &pState->paContext[2];
|
---|
1192 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pOtherCtx);
|
---|
1193 |
|
---|
1194 | LogRel(("VMSVGA3d: Alternative OpenGL version: %s\n"
|
---|
1195 | "VMSVGA3d: Alternative OpenGL Vendor: %s\n"
|
---|
1196 | "VMSVGA3d: Alternative OpenGL Renderer: %s\n"
|
---|
1197 | "VMSVGA3d: Alternative OpenGL shader language version: %s\n",
|
---|
1198 | glGetString(GL_VERSION), glGetString(GL_VENDOR), glGetString(GL_RENDERER),
|
---|
1199 | glGetString(GL_SHADING_LANGUAGE_VERSION)));
|
---|
1200 |
|
---|
1201 | rc = vmsvga3dGatherExtensions(&pState->pszOtherExtensions, VBOX_VMSVGA3D_OTHER_OGL_PROFILE);
|
---|
1202 | AssertRCReturn(rc, rc);
|
---|
1203 | vmsvga3dLogRelExtensions("Alternative ", pState->pszOtherExtensions);
|
---|
1204 |
|
---|
1205 | pState->fOtherGLVersion = atof((const char *)glGetString(GL_VERSION));
|
---|
1206 |
|
---|
1207 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
1208 | #else
|
---|
1209 | pState->pszOtherExtensions = (char *)"";
|
---|
1210 | pState->fOtherGLVersion = pState->fGLVersion;
|
---|
1211 | #endif
|
---|
1212 |
|
---|
1213 |
|
---|
1214 | if (vmsvga3dCheckGLExtension(pState, 3.0, " GL_ARB_framebuffer_object "))
|
---|
1215 | {
|
---|
1216 | pState->ext.glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)OGLGETPROCADDRESS("glIsRenderbuffer");
|
---|
1217 | pState->ext.glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)OGLGETPROCADDRESS("glBindRenderbuffer");
|
---|
1218 | pState->ext.glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)OGLGETPROCADDRESS("glDeleteRenderbuffers");
|
---|
1219 | pState->ext.glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)OGLGETPROCADDRESS("glGenRenderbuffers");
|
---|
1220 | pState->ext.glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)OGLGETPROCADDRESS("glRenderbufferStorage");
|
---|
1221 | pState->ext.glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)OGLGETPROCADDRESS("glGetRenderbufferParameteriv");
|
---|
1222 | pState->ext.glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)OGLGETPROCADDRESS("glIsFramebuffer");
|
---|
1223 | pState->ext.glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)OGLGETPROCADDRESS("glBindFramebuffer");
|
---|
1224 | pState->ext.glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)OGLGETPROCADDRESS("glDeleteFramebuffers");
|
---|
1225 | pState->ext.glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)OGLGETPROCADDRESS("glGenFramebuffers");
|
---|
1226 | pState->ext.glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)OGLGETPROCADDRESS("glCheckFramebufferStatus");
|
---|
1227 | pState->ext.glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)OGLGETPROCADDRESS("glFramebufferTexture1D");
|
---|
1228 | pState->ext.glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)OGLGETPROCADDRESS("glFramebufferTexture2D");
|
---|
1229 | pState->ext.glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)OGLGETPROCADDRESS("glFramebufferTexture3D");
|
---|
1230 | pState->ext.glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)OGLGETPROCADDRESS("glFramebufferRenderbuffer");
|
---|
1231 | pState->ext.glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)OGLGETPROCADDRESS("glGetFramebufferAttachmentParameteriv");
|
---|
1232 | pState->ext.glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)OGLGETPROCADDRESS("glGenerateMipmap");
|
---|
1233 | pState->ext.glBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC)OGLGETPROCADDRESS("glBlitFramebuffer");
|
---|
1234 | pState->ext.glRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC)OGLGETPROCADDRESS("glRenderbufferStorageMultisample");
|
---|
1235 | pState->ext.glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC)OGLGETPROCADDRESS("glFramebufferTextureLayer");
|
---|
1236 | }
|
---|
1237 | pState->ext.glPointParameterf = (PFNGLPOINTPARAMETERFPROC)OGLGETPROCADDRESS("glPointParameterf");
|
---|
1238 | AssertMsgReturn(pState->ext.glPointParameterf, ("glPointParameterf missing"), VERR_NOT_IMPLEMENTED);
|
---|
1239 | pState->ext.glBlendEquation = (PFNGLBLENDEQUATIONPROC)OGLGETPROCADDRESS("glBlendEquation");
|
---|
1240 | AssertMsgReturn(pState->ext.glBlendEquation, ("glBlendEquation missing"), VERR_NOT_IMPLEMENTED);
|
---|
1241 | pState->ext.glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC)OGLGETPROCADDRESS("glBlendEquationSeparate");
|
---|
1242 | AssertMsgReturn(pState->ext.glBlendEquationSeparate, ("glBlendEquationSeparate missing"), VERR_NOT_IMPLEMENTED);
|
---|
1243 | pState->ext.glBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC)OGLGETPROCADDRESS("glBlendFuncSeparate");
|
---|
1244 | AssertMsgReturn(pState->ext.glBlendFuncSeparate, ("glBlendFuncSeparate missing"), VERR_NOT_IMPLEMENTED);
|
---|
1245 | pState->ext.glStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC)OGLGETPROCADDRESS("glStencilOpSeparate");
|
---|
1246 | AssertMsgReturn(pState->ext.glStencilOpSeparate, ("glStencilOpSeparate missing"), VERR_NOT_IMPLEMENTED);
|
---|
1247 | pState->ext.glStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC)OGLGETPROCADDRESS("glStencilFuncSeparate");
|
---|
1248 | AssertMsgReturn(pState->ext.glStencilFuncSeparate, ("glStencilFuncSeparate missing"), VERR_NOT_IMPLEMENTED);
|
---|
1249 | pState->ext.glBlendColor = (PFNGLBLENDCOLORPROC)OGLGETPROCADDRESS("glBlendColor");
|
---|
1250 | AssertMsgReturn(pState->ext.glBlendColor, ("glBlendColor missing"), VERR_NOT_IMPLEMENTED);
|
---|
1251 | pState->ext.glBindBuffer = (PFNGLBINDBUFFERPROC)OGLGETPROCADDRESS("glBindBuffer");
|
---|
1252 | AssertMsgReturn(pState->ext.glBindBuffer, ("glBindBuffer missing"), VERR_NOT_IMPLEMENTED);
|
---|
1253 | pState->ext.glDeleteBuffers = (PFNGLDELETEBUFFERSPROC)OGLGETPROCADDRESS("glDeleteBuffers");
|
---|
1254 | AssertMsgReturn(pState->ext.glDeleteBuffers, ("glDeleteBuffers missing"), VERR_NOT_IMPLEMENTED);
|
---|
1255 | pState->ext.glGenBuffers = (PFNGLGENBUFFERSPROC)OGLGETPROCADDRESS("glGenBuffers");
|
---|
1256 | AssertMsgReturn(pState->ext.glGenBuffers, ("glGenBuffers missing"), VERR_NOT_IMPLEMENTED);
|
---|
1257 | pState->ext.glBufferData = (PFNGLBUFFERDATAPROC)OGLGETPROCADDRESS("glBufferData");
|
---|
1258 | AssertMsgReturn(pState->ext.glBufferData, ("glBufferData missing"), VERR_NOT_IMPLEMENTED);
|
---|
1259 | pState->ext.glMapBuffer = (PFNGLMAPBUFFERPROC)OGLGETPROCADDRESS("glMapBuffer");
|
---|
1260 | AssertMsgReturn(pState->ext.glMapBuffer, ("glMapBuffer missing"), VERR_NOT_IMPLEMENTED);
|
---|
1261 | pState->ext.glUnmapBuffer = (PFNGLUNMAPBUFFERPROC)OGLGETPROCADDRESS("glUnmapBuffer");
|
---|
1262 | AssertMsgReturn(pState->ext.glUnmapBuffer, ("glUnmapBuffer missing"), VERR_NOT_IMPLEMENTED);
|
---|
1263 | pState->ext.glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)OGLGETPROCADDRESS("glEnableVertexAttribArray");
|
---|
1264 | AssertMsgReturn(pState->ext.glEnableVertexAttribArray, ("glEnableVertexAttribArray missing"), VERR_NOT_IMPLEMENTED);
|
---|
1265 | pState->ext.glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC)OGLGETPROCADDRESS("glDisableVertexAttribArray");
|
---|
1266 | AssertMsgReturn(pState->ext.glDisableVertexAttribArray, ("glDisableVertexAttribArray missing"), VERR_NOT_IMPLEMENTED);
|
---|
1267 | pState->ext.glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)OGLGETPROCADDRESS("glVertexAttribPointer");
|
---|
1268 | AssertMsgReturn(pState->ext.glVertexAttribPointer, ("glVertexAttribPointer missing"), VERR_NOT_IMPLEMENTED);
|
---|
1269 | pState->ext.glFogCoordPointer = (PFNGLFOGCOORDPOINTERPROC)OGLGETPROCADDRESS("glFogCoordPointer");
|
---|
1270 | AssertMsgReturn(pState->ext.glFogCoordPointer, ("glFogCoordPointer missing"), VERR_NOT_IMPLEMENTED);
|
---|
1271 | pState->ext.glActiveTexture = (PFNGLACTIVETEXTUREPROC)OGLGETPROCADDRESS("glActiveTexture");
|
---|
1272 | AssertMsgReturn(pState->ext.glActiveTexture, ("glActiveTexture missing"), VERR_NOT_IMPLEMENTED);
|
---|
1273 | pState->ext.glClientActiveTexture = (PFNGLCLIENTACTIVETEXTUREPROC)OGLGETPROCADDRESS("glClientActiveTexture");
|
---|
1274 | AssertMsgReturn(pState->ext.glClientActiveTexture, ("glClientActiveTexture missing"), VERR_NOT_IMPLEMENTED);
|
---|
1275 | pState->ext.glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC)OGLGETPROCADDRESS("glGetProgramivARB");
|
---|
1276 | AssertMsgReturn(pState->ext.glGetProgramivARB, ("glGetProgramivARB missing"), VERR_NOT_IMPLEMENTED);
|
---|
1277 |
|
---|
1278 | /* OpenGL 3.2 core */
|
---|
1279 | if (vmsvga3dCheckGLExtension(pState, 3.2, " GL_ARB_draw_elements_base_vertex "))
|
---|
1280 | {
|
---|
1281 | pState->ext.glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC)OGLGETPROCADDRESS("glDrawElementsBaseVertex");
|
---|
1282 | pState->ext.glDrawElementsInstancedBaseVertex = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC)OGLGETPROCADDRESS("glDrawElementsInstancedBaseVertex");
|
---|
1283 | }
|
---|
1284 | else
|
---|
1285 | LogRel(("VMSVGA3d: missing extension GL_ARB_draw_elements_base_vertex\n"));
|
---|
1286 |
|
---|
1287 | /* OpenGL 3.2 core */
|
---|
1288 | if (vmsvga3dCheckGLExtension(pState, 3.2, " GL_ARB_provoking_vertex "))
|
---|
1289 | {
|
---|
1290 | pState->ext.glProvokingVertex = (PFNGLPROVOKINGVERTEXPROC)OGLGETPROCADDRESS("glProvokingVertex");
|
---|
1291 | }
|
---|
1292 | else
|
---|
1293 | LogRel(("VMSVGA3d: missing extension GL_ARB_provoking_vertex\n"));
|
---|
1294 |
|
---|
1295 | /* Extension support */
|
---|
1296 | #if defined(RT_OS_DARWIN)
|
---|
1297 | /** @todo OpenGL version history suggest this, verify... */
|
---|
1298 | pState->ext.fEXT_stencil_two_side = vmsvga3dCheckGLExtension(pState, 2.0, " GL_EXT_stencil_two_side ");
|
---|
1299 | #else
|
---|
1300 | pState->ext.fEXT_stencil_two_side = vmsvga3dCheckGLExtension(pState, 0.0, " GL_EXT_stencil_two_side ");
|
---|
1301 | #endif
|
---|
1302 |
|
---|
1303 | /*
|
---|
1304 | * Initialize the capabilities with sensible defaults.
|
---|
1305 | */
|
---|
1306 | pState->caps.maxActiveLights = 1;
|
---|
1307 | pState->caps.maxTextureBufferSize = 65536;
|
---|
1308 | pState->caps.maxTextures = 1;
|
---|
1309 | pState->caps.maxClipDistances = 4;
|
---|
1310 | pState->caps.maxColorAttachments = 1;
|
---|
1311 | pState->caps.maxRectangleTextureSize = 2048;
|
---|
1312 | pState->caps.maxTextureAnisotropy = 2;
|
---|
1313 | pState->caps.maxVertexShaderInstructions = 1024;
|
---|
1314 | pState->caps.maxFragmentShaderInstructions = 1024;
|
---|
1315 | pState->caps.vertexShaderVersion = SVGA3DVSVERSION_NONE;
|
---|
1316 | pState->caps.fragmentShaderVersion = SVGA3DPSVERSION_NONE;
|
---|
1317 | pState->caps.flPointSize[0] = 1;
|
---|
1318 | pState->caps.flPointSize[1] = 1;
|
---|
1319 |
|
---|
1320 | /*
|
---|
1321 | * Query capabilities
|
---|
1322 | */
|
---|
1323 | VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx, glGetIntegerv(GL_MAX_LIGHTS, &pState->caps.maxActiveLights));
|
---|
1324 | VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx, glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &pState->caps.maxTextureBufferSize));
|
---|
1325 | VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx, glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &pState->caps.maxTextures));
|
---|
1326 | VMSVGA3D_INIT_CHECKED(glGetIntegerv(GL_MAX_CLIP_DISTANCES, &pState->caps.maxClipDistances));
|
---|
1327 | VMSVGA3D_INIT_CHECKED(glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &pState->caps.maxColorAttachments));
|
---|
1328 | VMSVGA3D_INIT_CHECKED(glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE, &pState->caps.maxRectangleTextureSize));
|
---|
1329 | VMSVGA3D_INIT_CHECKED(glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &pState->caps.maxTextureAnisotropy));
|
---|
1330 | VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx, glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pState->caps.flPointSize));
|
---|
1331 |
|
---|
1332 | if (pState->ext.glGetProgramivARB)
|
---|
1333 | {
|
---|
1334 | VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx,
|
---|
1335 | pState->ext.glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB,
|
---|
1336 | &pState->caps.maxFragmentShaderTemps));
|
---|
1337 | VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx,
|
---|
1338 | pState->ext.glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB,
|
---|
1339 | &pState->caps.maxFragmentShaderInstructions));
|
---|
1340 | VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx,
|
---|
1341 | pState->ext.glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB,
|
---|
1342 | &pState->caps.maxVertexShaderTemps));
|
---|
1343 | VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx,
|
---|
1344 | pState->ext.glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB,
|
---|
1345 | &pState->caps.maxVertexShaderInstructions));
|
---|
1346 | }
|
---|
1347 | pState->caps.fS3TCSupported = vmsvga3dCheckGLExtension(pState, 0.0, " GL_EXT_texture_compression_s3tc ");
|
---|
1348 |
|
---|
1349 | /* http://http://www.opengl.org/wiki/Detecting_the_Shader_Model
|
---|
1350 | * ARB Assembly Language
|
---|
1351 | * These are done through testing the presence of extensions. You should test them in this order:
|
---|
1352 | * GL_NV_gpu_program4: SM 4.0 or better.
|
---|
1353 | * GL_NV_vertex_program3: SM 3.0 or better.
|
---|
1354 | * GL_ARB_fragment_program: SM 2.0 or better.
|
---|
1355 | * ATI does not support higher than SM 2.0 functionality in assembly shaders.
|
---|
1356 | *
|
---|
1357 | */
|
---|
1358 | /** @todo: distinguish between vertex and pixel shaders??? */
|
---|
1359 | if ( vmsvga3dCheckGLExtension(pState, 0.0, " GL_NV_gpu_program4 ")
|
---|
1360 | || strstr(pState->pszOtherExtensions, " GL_NV_gpu_program4 "))
|
---|
1361 | {
|
---|
1362 | pState->caps.vertexShaderVersion = SVGA3DVSVERSION_40;
|
---|
1363 | pState->caps.fragmentShaderVersion = SVGA3DPSVERSION_40;
|
---|
1364 | }
|
---|
1365 | else
|
---|
1366 | if ( vmsvga3dCheckGLExtension(pState, 0.0, " GL_NV_vertex_program3 ")
|
---|
1367 | || strstr(pState->pszOtherExtensions, " GL_NV_vertex_program3 ")
|
---|
1368 | || vmsvga3dCheckGLExtension(pState, 0.0, " GL_ARB_shader_texture_lod ") /* Wine claims this suggests SM 3.0 support */
|
---|
1369 | || strstr(pState->pszOtherExtensions, " GL_ARB_shader_texture_lod ")
|
---|
1370 | )
|
---|
1371 | {
|
---|
1372 | pState->caps.vertexShaderVersion = SVGA3DVSVERSION_30;
|
---|
1373 | pState->caps.fragmentShaderVersion = SVGA3DPSVERSION_30;
|
---|
1374 | }
|
---|
1375 | else
|
---|
1376 | if ( vmsvga3dCheckGLExtension(pState, 0.0, " GL_ARB_fragment_program ")
|
---|
1377 | || strstr(pState->pszOtherExtensions, " GL_ARB_fragment_program "))
|
---|
1378 | {
|
---|
1379 | pState->caps.vertexShaderVersion = SVGA3DVSVERSION_20;
|
---|
1380 | pState->caps.fragmentShaderVersion = SVGA3DPSVERSION_20;
|
---|
1381 | }
|
---|
1382 | else
|
---|
1383 | {
|
---|
1384 | LogRel(("VMSVGA3D: WARNING: unknown support for assembly shaders!!\n"));
|
---|
1385 | pState->caps.vertexShaderVersion = SVGA3DVSVERSION_11;
|
---|
1386 | pState->caps.fragmentShaderVersion = SVGA3DPSVERSION_11;
|
---|
1387 | }
|
---|
1388 |
|
---|
1389 | if (!vmsvga3dCheckGLExtension(pState, 3.2, " GL_ARB_vertex_array_bgra "))
|
---|
1390 | {
|
---|
1391 | /** @todo Intel drivers don't support this extension! */
|
---|
1392 | LogRel(("VMSVGA3D: WARNING: Missing required extension GL_ARB_vertex_array_bgra (d3dcolor)!!!\n"));
|
---|
1393 | }
|
---|
1394 | #if 0
|
---|
1395 | SVGA3D_DEVCAP_MAX_FIXED_VERTEXBLEND = 11,
|
---|
1396 | SVGA3D_DEVCAP_QUERY_TYPES = 15,
|
---|
1397 | SVGA3D_DEVCAP_TEXTURE_GRADIENT_SAMPLING = 16,
|
---|
1398 | SVGA3D_DEVCAP_MAX_POINT_SIZE = 17,
|
---|
1399 | SVGA3D_DEVCAP_MAX_SHADER_TEXTURES = 18,
|
---|
1400 | SVGA3D_DEVCAP_MAX_VOLUME_EXTENT = 21,
|
---|
1401 | SVGA3D_DEVCAP_MAX_TEXTURE_REPEAT = 22,
|
---|
1402 | SVGA3D_DEVCAP_MAX_TEXTURE_ASPECT_RATIO = 23,
|
---|
1403 | SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY = 24,
|
---|
1404 | SVGA3D_DEVCAP_MAX_PRIMITIVE_COUNT = 25,
|
---|
1405 | SVGA3D_DEVCAP_MAX_VERTEX_INDEX = 26,
|
---|
1406 | SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS = 28,
|
---|
1407 | SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS = 29,
|
---|
1408 | SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS = 30,
|
---|
1409 | SVGA3D_DEVCAP_TEXTURE_OPS = 31,
|
---|
1410 | SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8 = 32,
|
---|
1411 | SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8 = 33,
|
---|
1412 | SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10 = 34,
|
---|
1413 | SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5 = 35,
|
---|
1414 | SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5 = 36,
|
---|
1415 | SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4 = 37,
|
---|
1416 | SVGA3D_DEVCAP_SURFACEFMT_R5G6B5 = 38,
|
---|
1417 | SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16 = 39,
|
---|
1418 | SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8 = 40,
|
---|
1419 | SVGA3D_DEVCAP_SURFACEFMT_ALPHA8 = 41,
|
---|
1420 | SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8 = 42,
|
---|
1421 | SVGA3D_DEVCAP_SURFACEFMT_Z_D16 = 43,
|
---|
1422 | SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8 = 44,
|
---|
1423 | SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8 = 45,
|
---|
1424 | SVGA3D_DEVCAP_SURFACEFMT_DXT1 = 46,
|
---|
1425 | SVGA3D_DEVCAP_SURFACEFMT_DXT2 = 47,
|
---|
1426 | SVGA3D_DEVCAP_SURFACEFMT_DXT3 = 48,
|
---|
1427 | SVGA3D_DEVCAP_SURFACEFMT_DXT4 = 49,
|
---|
1428 | SVGA3D_DEVCAP_SURFACEFMT_DXT5 = 50,
|
---|
1429 | SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8 = 51,
|
---|
1430 | SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10 = 52,
|
---|
1431 | SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8 = 53,
|
---|
1432 | SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8 = 54,
|
---|
1433 | SVGA3D_DEVCAP_SURFACEFMT_CxV8U8 = 55,
|
---|
1434 | SVGA3D_DEVCAP_SURFACEFMT_R_S10E5 = 56,
|
---|
1435 | SVGA3D_DEVCAP_SURFACEFMT_R_S23E8 = 57,
|
---|
1436 | SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5 = 58,
|
---|
1437 | SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8 = 59,
|
---|
1438 | SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5 = 60,
|
---|
1439 | SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8 = 61,
|
---|
1440 | SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEXTURES = 63,
|
---|
1441 | SVGA3D_DEVCAP_SURFACEFMT_V16U16 = 65,
|
---|
1442 | SVGA3D_DEVCAP_SURFACEFMT_G16R16 = 66,
|
---|
1443 | SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16 = 67,
|
---|
1444 | SVGA3D_DEVCAP_SURFACEFMT_UYVY = 68,
|
---|
1445 | SVGA3D_DEVCAP_SURFACEFMT_YUY2 = 69,
|
---|
1446 | SVGA3D_DEVCAP_MULTISAMPLE_NONMASKABLESAMPLES = 70,
|
---|
1447 | SVGA3D_DEVCAP_MULTISAMPLE_MASKABLESAMPLES = 71,
|
---|
1448 | SVGA3D_DEVCAP_ALPHATOCOVERAGE = 72,
|
---|
1449 | SVGA3D_DEVCAP_SUPERSAMPLE = 73,
|
---|
1450 | SVGA3D_DEVCAP_AUTOGENMIPMAPS = 74,
|
---|
1451 | SVGA3D_DEVCAP_SURFACEFMT_NV12 = 75,
|
---|
1452 | SVGA3D_DEVCAP_SURFACEFMT_AYUV = 76,
|
---|
1453 | SVGA3D_DEVCAP_SURFACEFMT_Z_DF16 = 79,
|
---|
1454 | SVGA3D_DEVCAP_SURFACEFMT_Z_DF24 = 80,
|
---|
1455 | SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT = 81,
|
---|
1456 | SVGA3D_DEVCAP_SURFACEFMT_BC4_UNORM = 82,
|
---|
1457 | SVGA3D_DEVCAP_SURFACEFMT_BC5_UNORM = 83,
|
---|
1458 | #endif
|
---|
1459 |
|
---|
1460 | LogRel(("VMSVGA3d: Capabilities:\n"));
|
---|
1461 | LogRel(("VMSVGA3d: maxActiveLights=%-2d maxTextures=%-2d maxTextureBufferSize=%d\n",
|
---|
1462 | pState->caps.maxActiveLights, pState->caps.maxTextures, pState->caps.maxTextureBufferSize));
|
---|
1463 | LogRel(("VMSVGA3d: maxClipDistances=%-2d maxColorAttachments=%-2d maxClipDistances=%d\n",
|
---|
1464 | pState->caps.maxClipDistances, pState->caps.maxColorAttachments, pState->caps.maxClipDistances));
|
---|
1465 | LogRel(("VMSVGA3d: maxColorAttachments=%-2d maxTextureAnisotropy=%-2d maxRectangleTextureSize=%d\n",
|
---|
1466 | pState->caps.maxColorAttachments, pState->caps.maxTextureAnisotropy, pState->caps.maxRectangleTextureSize));
|
---|
1467 | LogRel(("VMSVGA3d: maxVertexShaderTemps=%-2d maxVertexShaderInstructions=%d maxFragmentShaderInstructions=%d\n",
|
---|
1468 | pState->caps.maxVertexShaderTemps, pState->caps.maxVertexShaderInstructions, pState->caps.maxFragmentShaderInstructions));
|
---|
1469 | LogRel(("VMSVGA3d: maxFragmentShaderTemps=%d flPointSize={%d.%02u, %d.%02u}\n",
|
---|
1470 | pState->caps.maxFragmentShaderTemps,
|
---|
1471 | (int)pState->caps.flPointSize[0], (int)(pState->caps.flPointSize[0] * 100) % 100,
|
---|
1472 | (int)pState->caps.flPointSize[1], (int)(pState->caps.flPointSize[1] * 100) % 100));
|
---|
1473 | LogRel(("VMSVGA3d: fragmentShaderVersion=%-2d vertexShaderVersion=%-2d fS3TCSupported=%d\n",
|
---|
1474 | pState->caps.fragmentShaderVersion, pState->caps.vertexShaderVersion, pState->caps.fS3TCSupported));
|
---|
1475 |
|
---|
1476 |
|
---|
1477 | /* Initialize the shader library. */
|
---|
1478 | pState->ShaderIf.pfnSwitchInitProfile = vmsvga3dShaderIfSwitchInitProfile;
|
---|
1479 | pState->ShaderIf.pfnGetNextExtension = vmsvga3dShaderIfGetNextExtension;
|
---|
1480 | rc = ShaderInitLib(&pState->ShaderIf);
|
---|
1481 | AssertRC(rc);
|
---|
1482 |
|
---|
1483 | /* Cleanup */
|
---|
1484 | rc = vmsvga3dContextDestroy(pThis, 1);
|
---|
1485 | AssertRC(rc);
|
---|
1486 | #ifdef VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE
|
---|
1487 | rc = vmsvga3dContextDestroy(pThis, 2);
|
---|
1488 | AssertRC(rc);
|
---|
1489 | #endif
|
---|
1490 |
|
---|
1491 | if ( pState->fGLVersion < 3.0
|
---|
1492 | && pState->fOtherGLVersion < 3.0 /* darwin: legacy profile hack */)
|
---|
1493 | {
|
---|
1494 | LogRel(("VMSVGA3d: unsupported OpenGL version; minimum is 3.0\n"));
|
---|
1495 | return VERR_NOT_IMPLEMENTED;
|
---|
1496 | }
|
---|
1497 | if ( !pState->ext.glIsRenderbuffer
|
---|
1498 | || !pState->ext.glBindRenderbuffer
|
---|
1499 | || !pState->ext.glDeleteRenderbuffers
|
---|
1500 | || !pState->ext.glGenRenderbuffers
|
---|
1501 | || !pState->ext.glRenderbufferStorage
|
---|
1502 | || !pState->ext.glGetRenderbufferParameteriv
|
---|
1503 | || !pState->ext.glIsFramebuffer
|
---|
1504 | || !pState->ext.glBindFramebuffer
|
---|
1505 | || !pState->ext.glDeleteFramebuffers
|
---|
1506 | || !pState->ext.glGenFramebuffers
|
---|
1507 | || !pState->ext.glCheckFramebufferStatus
|
---|
1508 | || !pState->ext.glFramebufferTexture1D
|
---|
1509 | || !pState->ext.glFramebufferTexture2D
|
---|
1510 | || !pState->ext.glFramebufferTexture3D
|
---|
1511 | || !pState->ext.glFramebufferRenderbuffer
|
---|
1512 | || !pState->ext.glGetFramebufferAttachmentParameteriv
|
---|
1513 | || !pState->ext.glGenerateMipmap
|
---|
1514 | || !pState->ext.glBlitFramebuffer
|
---|
1515 | || !pState->ext.glRenderbufferStorageMultisample
|
---|
1516 | || !pState->ext.glFramebufferTextureLayer)
|
---|
1517 | {
|
---|
1518 | LogRel(("VMSVGA3d: missing required OpenGL extension; aborting\n"));
|
---|
1519 | return VERR_NOT_IMPLEMENTED;
|
---|
1520 | }
|
---|
1521 |
|
---|
1522 | #ifdef DEBUG_DEBUG_GFX_WINDOW_TEST_CONTEXT
|
---|
1523 | pState->idTestContext = SVGA_ID_INVALID;
|
---|
1524 | #endif
|
---|
1525 | return VINF_SUCCESS;
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 | int vmsvga3dReset(PVGASTATE pThis)
|
---|
1529 | {
|
---|
1530 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
1531 | AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
|
---|
1532 |
|
---|
1533 | /* Destroy all leftover surfaces. */
|
---|
1534 | for (uint32_t i = 0; i < pState->cSurfaces; i++)
|
---|
1535 | {
|
---|
1536 | if (pState->paSurface[i].id != SVGA3D_INVALID_ID)
|
---|
1537 | vmsvga3dSurfaceDestroy(pThis, pState->paSurface[i].id);
|
---|
1538 | }
|
---|
1539 |
|
---|
1540 | /* Destroy all leftover contexts. */
|
---|
1541 | for (uint32_t i = 0; i < pState->cContexts; i++)
|
---|
1542 | {
|
---|
1543 | if (pState->paContext[i].id != SVGA3D_INVALID_ID)
|
---|
1544 | vmsvga3dContextDestroy(pThis, pState->paContext[i].id);
|
---|
1545 | }
|
---|
1546 | return VINF_SUCCESS;
|
---|
1547 | }
|
---|
1548 |
|
---|
1549 | int vmsvga3dTerminate(PVGASTATE pThis)
|
---|
1550 | {
|
---|
1551 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
1552 | AssertReturn(pState, VERR_WRONG_ORDER);
|
---|
1553 | int rc;
|
---|
1554 |
|
---|
1555 | rc = vmsvga3dReset(pThis);
|
---|
1556 | AssertRCReturn(rc, rc);
|
---|
1557 |
|
---|
1558 | /* Terminate the shader library. */
|
---|
1559 | rc = ShaderDestroyLib();
|
---|
1560 | AssertRC(rc);
|
---|
1561 |
|
---|
1562 | #ifdef RT_OS_WINDOWS
|
---|
1563 | /* Terminate the window creation thread. */
|
---|
1564 | rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_EXIT, 0, 0);
|
---|
1565 | AssertRCReturn(rc, rc);
|
---|
1566 |
|
---|
1567 | RTSemEventDestroy(pState->WndRequestSem);
|
---|
1568 | #elif defined(RT_OS_DARWIN)
|
---|
1569 |
|
---|
1570 | #elif defined(RT_OS_LINUX)
|
---|
1571 | /* signal to the thread that it is supposed to exit */
|
---|
1572 | pState->bTerminate = true;
|
---|
1573 | /* wait for it to terminate */
|
---|
1574 | rc = RTThreadWait(pState->pWindowThread, 10000, NULL);
|
---|
1575 | AssertRC(rc);
|
---|
1576 | XCloseDisplay(pState->display);
|
---|
1577 | #endif
|
---|
1578 |
|
---|
1579 | RTStrFree(pState->pszExtensions);
|
---|
1580 | pState->pszExtensions = NULL;
|
---|
1581 | #ifdef VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE
|
---|
1582 | RTStrFree(pState->pszOtherExtensions);
|
---|
1583 | #endif
|
---|
1584 | pState->pszOtherExtensions = NULL;
|
---|
1585 |
|
---|
1586 | return VINF_SUCCESS;
|
---|
1587 | }
|
---|
1588 |
|
---|
1589 | /* Shared functions that depend on private structure definitions. */
|
---|
1590 | #define VMSVGA3D_OPENGL
|
---|
1591 | #include "DevVGA-SVGA3d-shared.h"
|
---|
1592 |
|
---|
1593 | static uint32_t vmsvga3dGetSurfaceFormatSupport(PVMSVGA3DSTATE pState3D, uint32_t idx3dCaps)
|
---|
1594 | {
|
---|
1595 | uint32_t result = 0;
|
---|
1596 |
|
---|
1597 | /* @todo missing:
|
---|
1598 | *
|
---|
1599 | * SVGA3DFORMAT_OP_PIXELSIZE
|
---|
1600 | */
|
---|
1601 |
|
---|
1602 | switch (idx3dCaps)
|
---|
1603 | {
|
---|
1604 | case SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8:
|
---|
1605 | case SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5:
|
---|
1606 | case SVGA3D_DEVCAP_SURFACEFMT_R5G6B5:
|
---|
1607 | result |= SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB
|
---|
1608 | | SVGA3DFORMAT_OP_CONVERT_TO_ARGB
|
---|
1609 | | SVGA3DFORMAT_OP_DISPLAYMODE /* Should not be set for alpha formats. */
|
---|
1610 | | SVGA3DFORMAT_OP_3DACCELERATION; /* implies OP_DISPLAYMODE */
|
---|
1611 | break;
|
---|
1612 |
|
---|
1613 | case SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8:
|
---|
1614 | case SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10:
|
---|
1615 | case SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5:
|
---|
1616 | case SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4:
|
---|
1617 | result |= SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB
|
---|
1618 | | SVGA3DFORMAT_OP_CONVERT_TO_ARGB
|
---|
1619 | | SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET;
|
---|
1620 | break;
|
---|
1621 | }
|
---|
1622 |
|
---|
1623 | /* @todo check hardware caps! */
|
---|
1624 | switch (idx3dCaps)
|
---|
1625 | {
|
---|
1626 | case SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8:
|
---|
1627 | case SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8:
|
---|
1628 | case SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10:
|
---|
1629 | case SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5:
|
---|
1630 | case SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5:
|
---|
1631 | case SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4:
|
---|
1632 | case SVGA3D_DEVCAP_SURFACEFMT_R5G6B5:
|
---|
1633 | case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16:
|
---|
1634 | case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8:
|
---|
1635 | case SVGA3D_DEVCAP_SURFACEFMT_ALPHA8:
|
---|
1636 | case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8:
|
---|
1637 | result |= SVGA3DFORMAT_OP_TEXTURE
|
---|
1638 | | SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET
|
---|
1639 | | SVGA3DFORMAT_OP_OFFSCREENPLAIN
|
---|
1640 | | SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET
|
---|
1641 | | SVGA3DFORMAT_OP_VOLUMETEXTURE
|
---|
1642 | | SVGA3DFORMAT_OP_CUBETEXTURE
|
---|
1643 | | SVGA3DFORMAT_OP_SRGBREAD
|
---|
1644 | | SVGA3DFORMAT_OP_SRGBWRITE;
|
---|
1645 | break;
|
---|
1646 |
|
---|
1647 | case SVGA3D_DEVCAP_SURFACEFMT_Z_D16:
|
---|
1648 | case SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8:
|
---|
1649 | case SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8:
|
---|
1650 | case SVGA3D_DEVCAP_SURFACEFMT_Z_DF16:
|
---|
1651 | case SVGA3D_DEVCAP_SURFACEFMT_Z_DF24:
|
---|
1652 | case SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT:
|
---|
1653 | result |= SVGA3DFORMAT_OP_ZSTENCIL
|
---|
1654 | | SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH
|
---|
1655 | | SVGA3DFORMAT_OP_TEXTURE /* Necessary for Ubuntu Unity */;
|
---|
1656 | break;
|
---|
1657 |
|
---|
1658 | case SVGA3D_DEVCAP_SURFACEFMT_DXT1:
|
---|
1659 | case SVGA3D_DEVCAP_SURFACEFMT_DXT3:
|
---|
1660 | case SVGA3D_DEVCAP_SURFACEFMT_DXT5:
|
---|
1661 | result |= SVGA3DFORMAT_OP_TEXTURE
|
---|
1662 | | SVGA3DFORMAT_OP_VOLUMETEXTURE
|
---|
1663 | | SVGA3DFORMAT_OP_CUBETEXTURE
|
---|
1664 | | SVGA3DFORMAT_OP_SRGBREAD;
|
---|
1665 | break;
|
---|
1666 |
|
---|
1667 | case SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8:
|
---|
1668 | case SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10:
|
---|
1669 | case SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8:
|
---|
1670 | case SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8:
|
---|
1671 | case SVGA3D_DEVCAP_SURFACEFMT_CxV8U8:
|
---|
1672 | break;
|
---|
1673 |
|
---|
1674 | case SVGA3D_DEVCAP_SURFACEFMT_R_S10E5:
|
---|
1675 | case SVGA3D_DEVCAP_SURFACEFMT_R_S23E8:
|
---|
1676 | case SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5:
|
---|
1677 | case SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8:
|
---|
1678 | case SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5:
|
---|
1679 | case SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8:
|
---|
1680 | break;
|
---|
1681 |
|
---|
1682 | case SVGA3D_DEVCAP_SURFACEFMT_V16U16:
|
---|
1683 | case SVGA3D_DEVCAP_SURFACEFMT_G16R16:
|
---|
1684 | case SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16:
|
---|
1685 |
|
---|
1686 | case SVGA3D_DEVCAP_SURFACEFMT_UYVY:
|
---|
1687 | case SVGA3D_DEVCAP_SURFACEFMT_YUY2:
|
---|
1688 | case SVGA3D_DEVCAP_SURFACEFMT_NV12:
|
---|
1689 | case SVGA3D_DEVCAP_SURFACEFMT_AYUV:
|
---|
1690 | break;
|
---|
1691 | }
|
---|
1692 | Log(("CAPS: %s =\n%s\n", vmsvga3dGetCapString(idx3dCaps), vmsvga3dGet3dFormatString(result)));
|
---|
1693 |
|
---|
1694 | return result;
|
---|
1695 | }
|
---|
1696 |
|
---|
1697 | static uint32_t vmsvga3dGetDepthFormatSupport(PVMSVGA3DSTATE pState3D, uint32_t idx3dCaps)
|
---|
1698 | {
|
---|
1699 | uint32_t result = 0;
|
---|
1700 |
|
---|
1701 | /* @todo test this somehow */
|
---|
1702 | result = SVGA3DFORMAT_OP_ZSTENCIL | SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH;
|
---|
1703 |
|
---|
1704 | Log(("CAPS: %s =\n%s\n", vmsvga3dGetCapString(idx3dCaps), vmsvga3dGet3dFormatString(result)));
|
---|
1705 | return result;
|
---|
1706 | }
|
---|
1707 |
|
---|
1708 |
|
---|
1709 | int vmsvga3dQueryCaps(PVGASTATE pThis, uint32_t idx3dCaps, uint32_t *pu32Val)
|
---|
1710 | {
|
---|
1711 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
1712 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
1713 | int rc = VINF_SUCCESS;
|
---|
1714 |
|
---|
1715 | *pu32Val = 0;
|
---|
1716 |
|
---|
1717 | switch (idx3dCaps)
|
---|
1718 | {
|
---|
1719 | case SVGA3D_DEVCAP_3D:
|
---|
1720 | *pu32Val = 1; /* boolean? */
|
---|
1721 | break;
|
---|
1722 |
|
---|
1723 | case SVGA3D_DEVCAP_MAX_LIGHTS:
|
---|
1724 | *pu32Val = pState->caps.maxActiveLights;
|
---|
1725 | break;
|
---|
1726 |
|
---|
1727 | case SVGA3D_DEVCAP_MAX_TEXTURES:
|
---|
1728 | *pu32Val = pState->caps.maxTextures;
|
---|
1729 | break;
|
---|
1730 |
|
---|
1731 | case SVGA3D_DEVCAP_MAX_CLIP_PLANES:
|
---|
1732 | *pu32Val = pState->caps.maxClipDistances;
|
---|
1733 | break;
|
---|
1734 |
|
---|
1735 | case SVGA3D_DEVCAP_VERTEX_SHADER_VERSION:
|
---|
1736 | *pu32Val = pState->caps.vertexShaderVersion;
|
---|
1737 | break;
|
---|
1738 |
|
---|
1739 | case SVGA3D_DEVCAP_VERTEX_SHADER:
|
---|
1740 | /* boolean? */
|
---|
1741 | *pu32Val = (pState->caps.vertexShaderVersion != SVGA3DVSVERSION_NONE);
|
---|
1742 | break;
|
---|
1743 |
|
---|
1744 | case SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION:
|
---|
1745 | *pu32Val = pState->caps.fragmentShaderVersion;
|
---|
1746 | break;
|
---|
1747 |
|
---|
1748 | case SVGA3D_DEVCAP_FRAGMENT_SHADER:
|
---|
1749 | /* boolean? */
|
---|
1750 | *pu32Val = (pState->caps.fragmentShaderVersion != SVGA3DPSVERSION_NONE);
|
---|
1751 | break;
|
---|
1752 |
|
---|
1753 | case SVGA3D_DEVCAP_S23E8_TEXTURES:
|
---|
1754 | case SVGA3D_DEVCAP_S10E5_TEXTURES:
|
---|
1755 | /* Must be obsolete by now; surface format caps specify the same thing. */
|
---|
1756 | rc = VERR_INVALID_PARAMETER;
|
---|
1757 | break;
|
---|
1758 |
|
---|
1759 | case SVGA3D_DEVCAP_MAX_FIXED_VERTEXBLEND:
|
---|
1760 | break;
|
---|
1761 |
|
---|
1762 | /*
|
---|
1763 | * 2. The BUFFER_FORMAT capabilities are deprecated, and they always
|
---|
1764 | * return TRUE. Even on physical hardware that does not support
|
---|
1765 | * these formats natively, the SVGA3D device will provide an emulation
|
---|
1766 | * which should be invisible to the guest OS.
|
---|
1767 | */
|
---|
1768 | case SVGA3D_DEVCAP_D16_BUFFER_FORMAT:
|
---|
1769 | case SVGA3D_DEVCAP_D24S8_BUFFER_FORMAT:
|
---|
1770 | case SVGA3D_DEVCAP_D24X8_BUFFER_FORMAT:
|
---|
1771 | *pu32Val = 1;
|
---|
1772 | break;
|
---|
1773 |
|
---|
1774 | case SVGA3D_DEVCAP_QUERY_TYPES:
|
---|
1775 | break;
|
---|
1776 |
|
---|
1777 | case SVGA3D_DEVCAP_TEXTURE_GRADIENT_SAMPLING:
|
---|
1778 | break;
|
---|
1779 |
|
---|
1780 | case SVGA3D_DEVCAP_MAX_POINT_SIZE:
|
---|
1781 | AssertCompile(sizeof(uint32_t) == sizeof(float));
|
---|
1782 | *(float *)pu32Val = pState->caps.flPointSize[1];
|
---|
1783 | break;
|
---|
1784 |
|
---|
1785 | case SVGA3D_DEVCAP_MAX_SHADER_TEXTURES:
|
---|
1786 | /* @todo ?? */
|
---|
1787 | rc = VERR_INVALID_PARAMETER;
|
---|
1788 | break;
|
---|
1789 |
|
---|
1790 | case SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH:
|
---|
1791 | case SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT:
|
---|
1792 | *pu32Val = pState->caps.maxRectangleTextureSize;
|
---|
1793 | break;
|
---|
1794 |
|
---|
1795 | case SVGA3D_DEVCAP_MAX_VOLUME_EXTENT:
|
---|
1796 | //*pu32Val = pCaps->MaxVolumeExtent;
|
---|
1797 | break;
|
---|
1798 |
|
---|
1799 | case SVGA3D_DEVCAP_MAX_TEXTURE_REPEAT:
|
---|
1800 | *pu32Val = 32768; /* hardcoded in Wine */
|
---|
1801 | break;
|
---|
1802 |
|
---|
1803 | case SVGA3D_DEVCAP_MAX_TEXTURE_ASPECT_RATIO:
|
---|
1804 | //*pu32Val = pCaps->MaxTextureAspectRatio;
|
---|
1805 | break;
|
---|
1806 |
|
---|
1807 | case SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY:
|
---|
1808 | *pu32Val = pState->caps.maxTextureAnisotropy;
|
---|
1809 | break;
|
---|
1810 |
|
---|
1811 | case SVGA3D_DEVCAP_MAX_PRIMITIVE_COUNT:
|
---|
1812 | case SVGA3D_DEVCAP_MAX_VERTEX_INDEX:
|
---|
1813 | *pu32Val = 0xFFFFF; /* hardcoded in Wine */
|
---|
1814 | break;
|
---|
1815 |
|
---|
1816 | case SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS:
|
---|
1817 | *pu32Val = pState->caps.maxVertexShaderInstructions;
|
---|
1818 | break;
|
---|
1819 |
|
---|
1820 | case SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS:
|
---|
1821 | *pu32Val = pState->caps.maxFragmentShaderInstructions;
|
---|
1822 | break;
|
---|
1823 |
|
---|
1824 | case SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS:
|
---|
1825 | *pu32Val = pState->caps.maxVertexShaderTemps;
|
---|
1826 | break;
|
---|
1827 |
|
---|
1828 | case SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS:
|
---|
1829 | *pu32Val = pState->caps.maxFragmentShaderTemps;
|
---|
1830 | break;
|
---|
1831 |
|
---|
1832 | case SVGA3D_DEVCAP_TEXTURE_OPS:
|
---|
1833 | break;
|
---|
1834 |
|
---|
1835 | case SVGA3D_DEVCAP_MULTISAMPLE_NONMASKABLESAMPLES:
|
---|
1836 | break;
|
---|
1837 |
|
---|
1838 | case SVGA3D_DEVCAP_MULTISAMPLE_MASKABLESAMPLES:
|
---|
1839 | break;
|
---|
1840 |
|
---|
1841 | case SVGA3D_DEVCAP_ALPHATOCOVERAGE:
|
---|
1842 | break;
|
---|
1843 |
|
---|
1844 | case SVGA3D_DEVCAP_SUPERSAMPLE:
|
---|
1845 | break;
|
---|
1846 |
|
---|
1847 | case SVGA3D_DEVCAP_AUTOGENMIPMAPS:
|
---|
1848 | //*pu32Val = !!(pCaps->Caps2 & D3DCAPS2_CANAUTOGENMIPMAP);
|
---|
1849 | break;
|
---|
1850 |
|
---|
1851 | case SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEXTURES:
|
---|
1852 | break;
|
---|
1853 |
|
---|
1854 | case SVGA3D_DEVCAP_MAX_RENDER_TARGETS: /* @todo same thing? */
|
---|
1855 | case SVGA3D_DEVCAP_MAX_SIMULTANEOUS_RENDER_TARGETS:
|
---|
1856 | *pu32Val = pState->caps.maxColorAttachments;
|
---|
1857 | break;
|
---|
1858 |
|
---|
1859 | /*
|
---|
1860 | * This is the maximum number of SVGA context IDs that the guest
|
---|
1861 | * can define using SVGA_3D_CMD_CONTEXT_DEFINE.
|
---|
1862 | */
|
---|
1863 | case SVGA3D_DEVCAP_MAX_CONTEXT_IDS:
|
---|
1864 | *pu32Val = SVGA3D_MAX_CONTEXT_IDS;
|
---|
1865 | break;
|
---|
1866 |
|
---|
1867 | /*
|
---|
1868 | * This is the maximum number of SVGA surface IDs that the guest
|
---|
1869 | * can define using SVGA_3D_CMD_SURFACE_DEFINE*.
|
---|
1870 | */
|
---|
1871 | case SVGA3D_DEVCAP_MAX_SURFACE_IDS:
|
---|
1872 | *pu32Val = SVGA3D_MAX_SURFACE_IDS;
|
---|
1873 | break;
|
---|
1874 |
|
---|
1875 | /* Supported surface formats. */
|
---|
1876 | case SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8:
|
---|
1877 | case SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8:
|
---|
1878 | case SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10:
|
---|
1879 | case SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5:
|
---|
1880 | case SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5:
|
---|
1881 | case SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4:
|
---|
1882 | case SVGA3D_DEVCAP_SURFACEFMT_R5G6B5:
|
---|
1883 | case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16:
|
---|
1884 | case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8:
|
---|
1885 | case SVGA3D_DEVCAP_SURFACEFMT_ALPHA8:
|
---|
1886 | case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8:
|
---|
1887 | case SVGA3D_DEVCAP_SURFACEFMT_Z_D16:
|
---|
1888 | case SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8:
|
---|
1889 | case SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8:
|
---|
1890 | case SVGA3D_DEVCAP_SURFACEFMT_Z_DF16:
|
---|
1891 | case SVGA3D_DEVCAP_SURFACEFMT_Z_DF24:
|
---|
1892 | case SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT:
|
---|
1893 | case SVGA3D_DEVCAP_SURFACEFMT_DXT1:
|
---|
1894 | *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps);
|
---|
1895 | break;
|
---|
1896 |
|
---|
1897 | case SVGA3D_DEVCAP_SURFACEFMT_DXT2:
|
---|
1898 | case SVGA3D_DEVCAP_SURFACEFMT_DXT4:
|
---|
1899 | *pu32Val = 0; /* apparently not supported in OpenGL */
|
---|
1900 | break;
|
---|
1901 |
|
---|
1902 | case SVGA3D_DEVCAP_SURFACEFMT_DXT3:
|
---|
1903 | case SVGA3D_DEVCAP_SURFACEFMT_DXT5:
|
---|
1904 | case SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8:
|
---|
1905 | case SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10:
|
---|
1906 | case SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8:
|
---|
1907 | case SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8:
|
---|
1908 | case SVGA3D_DEVCAP_SURFACEFMT_CxV8U8:
|
---|
1909 | case SVGA3D_DEVCAP_SURFACEFMT_R_S10E5:
|
---|
1910 | case SVGA3D_DEVCAP_SURFACEFMT_R_S23E8:
|
---|
1911 | case SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5:
|
---|
1912 | case SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8:
|
---|
1913 | case SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5:
|
---|
1914 | case SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8:
|
---|
1915 | case SVGA3D_DEVCAP_SURFACEFMT_V16U16:
|
---|
1916 | case SVGA3D_DEVCAP_SURFACEFMT_G16R16:
|
---|
1917 | case SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16:
|
---|
1918 | case SVGA3D_DEVCAP_SURFACEFMT_UYVY:
|
---|
1919 | case SVGA3D_DEVCAP_SURFACEFMT_YUY2:
|
---|
1920 | case SVGA3D_DEVCAP_SURFACEFMT_NV12:
|
---|
1921 | case SVGA3D_DEVCAP_SURFACEFMT_AYUV:
|
---|
1922 | *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps);
|
---|
1923 | break;
|
---|
1924 |
|
---|
1925 | case SVGA3D_DEVCAP_SURFACEFMT_BC4_UNORM:
|
---|
1926 | case SVGA3D_DEVCAP_SURFACEFMT_BC5_UNORM:
|
---|
1927 | Log(("CAPS: Unknown CAP %s\n", vmsvga3dGetCapString(idx3dCaps)));
|
---|
1928 | rc = VERR_INVALID_PARAMETER;
|
---|
1929 | *pu32Val = 0;
|
---|
1930 | break;
|
---|
1931 |
|
---|
1932 | default:
|
---|
1933 | Log(("CAPS: Unexpected CAP %d\n", idx3dCaps));
|
---|
1934 | rc = VERR_INVALID_PARAMETER;
|
---|
1935 | break;
|
---|
1936 | }
|
---|
1937 |
|
---|
1938 | Log(("CAPS: %s - %x\n", vmsvga3dGetCapString(idx3dCaps), *pu32Val));
|
---|
1939 | return rc;
|
---|
1940 | }
|
---|
1941 |
|
---|
1942 | /**
|
---|
1943 | * Convert SVGA format value to its OpenGL equivalent
|
---|
1944 | */
|
---|
1945 | static void vmsvga3dSurfaceFormat2OGL(PVMSVGA3DSURFACE pSurface, SVGA3dSurfaceFormat format)
|
---|
1946 | {
|
---|
1947 | switch (format)
|
---|
1948 | {
|
---|
1949 | case SVGA3D_X8R8G8B8:
|
---|
1950 | pSurface->internalFormatGL = GL_RGB8;
|
---|
1951 | pSurface->formatGL = GL_BGRA;
|
---|
1952 | pSurface->typeGL = GL_UNSIGNED_INT_8_8_8_8_REV;
|
---|
1953 | break;
|
---|
1954 | case SVGA3D_A8R8G8B8:
|
---|
1955 | pSurface->internalFormatGL = GL_RGBA8;
|
---|
1956 | pSurface->formatGL = GL_BGRA;
|
---|
1957 | pSurface->typeGL = GL_UNSIGNED_INT_8_8_8_8_REV;
|
---|
1958 | break;
|
---|
1959 | case SVGA3D_R5G6B5:
|
---|
1960 | pSurface->internalFormatGL = GL_RGB;
|
---|
1961 | pSurface->formatGL = GL_RGB;
|
---|
1962 | pSurface->typeGL = GL_UNSIGNED_SHORT_5_6_5;
|
---|
1963 | break;
|
---|
1964 | case SVGA3D_X1R5G5B5:
|
---|
1965 | pSurface->internalFormatGL = GL_RGB;
|
---|
1966 | pSurface->formatGL = GL_RGB;
|
---|
1967 | pSurface->typeGL = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
---|
1968 | break;
|
---|
1969 | case SVGA3D_A1R5G5B5:
|
---|
1970 | pSurface->internalFormatGL = GL_RGBA;
|
---|
1971 | pSurface->formatGL = GL_RGB;
|
---|
1972 | pSurface->typeGL = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
---|
1973 | break;
|
---|
1974 | case SVGA3D_A4R4G4B4:
|
---|
1975 | pSurface->internalFormatGL = GL_RGBA;
|
---|
1976 | pSurface->formatGL = GL_RGBA;
|
---|
1977 | pSurface->typeGL = GL_UNSIGNED_SHORT_4_4_4_4;
|
---|
1978 | break;
|
---|
1979 |
|
---|
1980 | case SVGA3D_Z_D32:
|
---|
1981 | pSurface->internalFormatGL = GL_DEPTH_COMPONENT32;
|
---|
1982 | pSurface->formatGL = GL_DEPTH_COMPONENT;
|
---|
1983 | pSurface->typeGL = GL_UNSIGNED_INT;
|
---|
1984 | break;
|
---|
1985 | case SVGA3D_Z_D16:
|
---|
1986 | pSurface->internalFormatGL = GL_DEPTH_COMPONENT16;
|
---|
1987 | pSurface->formatGL = GL_DEPTH_COMPONENT;
|
---|
1988 | pSurface->typeGL = GL_UNSIGNED_SHORT;
|
---|
1989 | break;
|
---|
1990 | case SVGA3D_Z_D24S8:
|
---|
1991 | pSurface->internalFormatGL = GL_DEPTH24_STENCIL8;
|
---|
1992 | pSurface->formatGL = GL_DEPTH_STENCIL;
|
---|
1993 | pSurface->typeGL = GL_UNSIGNED_INT;
|
---|
1994 | break;
|
---|
1995 | case SVGA3D_Z_D15S1:
|
---|
1996 | pSurface->internalFormatGL = GL_DEPTH_COMPONENT16; /* @todo ??? */
|
---|
1997 | pSurface->formatGL = GL_DEPTH_STENCIL;
|
---|
1998 | pSurface->typeGL = GL_UNSIGNED_SHORT;
|
---|
1999 | break;
|
---|
2000 | case SVGA3D_Z_D24X8:
|
---|
2001 | pSurface->internalFormatGL = GL_DEPTH_COMPONENT24;
|
---|
2002 | pSurface->formatGL = GL_DEPTH_COMPONENT;
|
---|
2003 | pSurface->typeGL = GL_UNSIGNED_INT;
|
---|
2004 | break;
|
---|
2005 |
|
---|
2006 | /* Advanced D3D9 depth formats. */
|
---|
2007 | case SVGA3D_Z_DF16:
|
---|
2008 | pSurface->internalFormatGL = GL_DEPTH_COMPONENT16;
|
---|
2009 | pSurface->formatGL = GL_DEPTH_COMPONENT;
|
---|
2010 | pSurface->typeGL = GL_FLOAT;
|
---|
2011 | break;
|
---|
2012 |
|
---|
2013 | case SVGA3D_Z_DF24:
|
---|
2014 | pSurface->internalFormatGL = GL_DEPTH_COMPONENT24;
|
---|
2015 | pSurface->formatGL = GL_DEPTH_COMPONENT;
|
---|
2016 | pSurface->typeGL = GL_FLOAT; /* ??? */
|
---|
2017 | break;
|
---|
2018 |
|
---|
2019 | case SVGA3D_Z_D24S8_INT:
|
---|
2020 | pSurface->internalFormatGL = GL_DEPTH24_STENCIL8;
|
---|
2021 | pSurface->formatGL = GL_DEPTH_STENCIL;
|
---|
2022 | pSurface->typeGL = GL_INT; /* ??? */
|
---|
2023 | break;
|
---|
2024 |
|
---|
2025 | case SVGA3D_DXT1:
|
---|
2026 | pSurface->internalFormatGL = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
---|
2027 | pSurface->formatGL = GL_RGBA_S3TC; /* ??? */
|
---|
2028 | pSurface->typeGL = GL_UNSIGNED_INT; /* ??? */
|
---|
2029 | break;
|
---|
2030 |
|
---|
2031 | case SVGA3D_DXT3:
|
---|
2032 | pSurface->internalFormatGL = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
---|
2033 | pSurface->formatGL = GL_RGBA_S3TC; /* ??? */
|
---|
2034 | pSurface->typeGL = GL_UNSIGNED_INT; /* ??? */
|
---|
2035 | break;
|
---|
2036 |
|
---|
2037 | case SVGA3D_DXT5:
|
---|
2038 | pSurface->internalFormatGL = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
---|
2039 | pSurface->formatGL = GL_RGBA_S3TC;
|
---|
2040 | pSurface->typeGL = GL_UNSIGNED_INT;
|
---|
2041 | break;
|
---|
2042 |
|
---|
2043 | case SVGA3D_LUMINANCE8:
|
---|
2044 | pSurface->internalFormatGL = GL_LUMINANCE8_EXT;
|
---|
2045 | pSurface->formatGL = GL_LUMINANCE;
|
---|
2046 | pSurface->typeGL = GL_UNSIGNED_BYTE;
|
---|
2047 | break;
|
---|
2048 |
|
---|
2049 | case SVGA3D_LUMINANCE16:
|
---|
2050 | pSurface->internalFormatGL = GL_LUMINANCE16_EXT;
|
---|
2051 | pSurface->formatGL = GL_LUMINANCE;
|
---|
2052 | pSurface->typeGL = GL_UNSIGNED_SHORT;
|
---|
2053 | break;
|
---|
2054 |
|
---|
2055 | case SVGA3D_LUMINANCE4_ALPHA4:
|
---|
2056 | pSurface->internalFormatGL = GL_LUMINANCE4_ALPHA4_EXT;
|
---|
2057 | pSurface->formatGL = GL_LUMINANCE_ALPHA;
|
---|
2058 | pSurface->typeGL = GL_UNSIGNED_BYTE;
|
---|
2059 | break;
|
---|
2060 |
|
---|
2061 | case SVGA3D_LUMINANCE8_ALPHA8:
|
---|
2062 | pSurface->internalFormatGL = GL_LUMINANCE8_ALPHA8_EXT;
|
---|
2063 | pSurface->formatGL = GL_LUMINANCE_ALPHA;
|
---|
2064 | pSurface->typeGL = GL_UNSIGNED_BYTE; /* unsigned_short causes issues even though this type should be 16-bit */
|
---|
2065 | break;
|
---|
2066 |
|
---|
2067 | case SVGA3D_ALPHA8:
|
---|
2068 | pSurface->internalFormatGL = GL_ALPHA8_EXT;
|
---|
2069 | pSurface->formatGL = GL_ALPHA;
|
---|
2070 | pSurface->typeGL = GL_UNSIGNED_BYTE;
|
---|
2071 | break;
|
---|
2072 |
|
---|
2073 | #if 0
|
---|
2074 |
|
---|
2075 | /* Bump-map formats */
|
---|
2076 | case SVGA3D_BUMPU8V8:
|
---|
2077 | return D3DFMT_V8U8;
|
---|
2078 | case SVGA3D_BUMPL6V5U5:
|
---|
2079 | return D3DFMT_L6V5U5;
|
---|
2080 | case SVGA3D_BUMPX8L8V8U8:
|
---|
2081 | return D3DFMT_X8L8V8U8;
|
---|
2082 | case SVGA3D_BUMPL8V8U8:
|
---|
2083 | /* No corresponding D3D9 equivalent. */
|
---|
2084 | AssertFailedReturn(D3DFMT_UNKNOWN);
|
---|
2085 | /* signed bump-map formats */
|
---|
2086 | case SVGA3D_V8U8:
|
---|
2087 | return D3DFMT_V8U8;
|
---|
2088 | case SVGA3D_Q8W8V8U8:
|
---|
2089 | return D3DFMT_Q8W8V8U8;
|
---|
2090 | case SVGA3D_CxV8U8:
|
---|
2091 | return D3DFMT_CxV8U8;
|
---|
2092 | /* mixed bump-map formats */
|
---|
2093 | case SVGA3D_X8L8V8U8:
|
---|
2094 | return D3DFMT_X8L8V8U8;
|
---|
2095 | case SVGA3D_A2W10V10U10:
|
---|
2096 | return D3DFMT_A2W10V10U10;
|
---|
2097 | #endif
|
---|
2098 |
|
---|
2099 | case SVGA3D_ARGB_S10E5: /* 16-bit floating-point ARGB */
|
---|
2100 | pSurface->internalFormatGL = GL_RGBA16F;
|
---|
2101 | pSurface->formatGL = GL_RGBA;
|
---|
2102 | pSurface->typeGL = GL_FLOAT;
|
---|
2103 | break;
|
---|
2104 |
|
---|
2105 | case SVGA3D_ARGB_S23E8: /* 32-bit floating-point ARGB */
|
---|
2106 | pSurface->internalFormatGL = GL_RGBA32F;
|
---|
2107 | pSurface->formatGL = GL_RGBA;
|
---|
2108 | pSurface->typeGL = GL_FLOAT; /* ?? */
|
---|
2109 | break;
|
---|
2110 |
|
---|
2111 | case SVGA3D_A2R10G10B10:
|
---|
2112 | pSurface->internalFormatGL = GL_RGB10_A2; /* ?? */
|
---|
2113 | pSurface->formatGL = GL_RGBA;
|
---|
2114 | pSurface->typeGL = GL_UNSIGNED_INT;
|
---|
2115 | break;
|
---|
2116 |
|
---|
2117 |
|
---|
2118 | /* Single- and dual-component floating point formats */
|
---|
2119 | case SVGA3D_R_S10E5:
|
---|
2120 | pSurface->internalFormatGL = GL_R16F;
|
---|
2121 | pSurface->formatGL = GL_RED;
|
---|
2122 | pSurface->typeGL = GL_FLOAT;
|
---|
2123 | break;
|
---|
2124 | case SVGA3D_R_S23E8:
|
---|
2125 | pSurface->internalFormatGL = GL_R32F;
|
---|
2126 | pSurface->formatGL = GL_RG;
|
---|
2127 | pSurface->typeGL = GL_FLOAT;
|
---|
2128 | break;
|
---|
2129 | case SVGA3D_RG_S10E5:
|
---|
2130 | pSurface->internalFormatGL = GL_RG16F;
|
---|
2131 | pSurface->formatGL = GL_RG;
|
---|
2132 | pSurface->typeGL = GL_FLOAT;
|
---|
2133 | break;
|
---|
2134 | case SVGA3D_RG_S23E8:
|
---|
2135 | pSurface->internalFormatGL = GL_RG32F;
|
---|
2136 | pSurface->formatGL = GL_RG;
|
---|
2137 | pSurface->typeGL = GL_FLOAT;
|
---|
2138 | break;
|
---|
2139 |
|
---|
2140 | /*
|
---|
2141 | * Any surface can be used as a buffer object, but SVGA3D_BUFFER is
|
---|
2142 | * the most efficient format to use when creating new surfaces
|
---|
2143 | * expressly for index or vertex data.
|
---|
2144 | */
|
---|
2145 | case SVGA3D_BUFFER:
|
---|
2146 | pSurface->internalFormatGL = -1;
|
---|
2147 | pSurface->formatGL = -1;
|
---|
2148 | pSurface->typeGL = -1;
|
---|
2149 | break;
|
---|
2150 |
|
---|
2151 | #if 0
|
---|
2152 | return D3DFMT_UNKNOWN;
|
---|
2153 |
|
---|
2154 | case SVGA3D_V16U16:
|
---|
2155 | return D3DFMT_V16U16;
|
---|
2156 | #endif
|
---|
2157 |
|
---|
2158 | case SVGA3D_G16R16:
|
---|
2159 | pSurface->internalFormatGL = GL_RG16;
|
---|
2160 | pSurface->formatGL = GL_RG;
|
---|
2161 | pSurface->typeGL = GL_UNSIGNED_INT;
|
---|
2162 | break;
|
---|
2163 |
|
---|
2164 | case SVGA3D_A16B16G16R16:
|
---|
2165 | pSurface->internalFormatGL = GL_RGBA16;
|
---|
2166 | pSurface->formatGL = GL_RG;
|
---|
2167 | pSurface->typeGL = GL_UNSIGNED_INT; /* ??? */
|
---|
2168 | break;
|
---|
2169 |
|
---|
2170 | #if 0
|
---|
2171 | /* Packed Video formats */
|
---|
2172 | case SVGA3D_UYVY:
|
---|
2173 | return D3DFMT_UYVY;
|
---|
2174 | case SVGA3D_YUY2:
|
---|
2175 | return D3DFMT_YUY2;
|
---|
2176 |
|
---|
2177 | /* Planar video formats */
|
---|
2178 | case SVGA3D_NV12:
|
---|
2179 | return (D3DFORMAT)MAKEFOURCC('N', 'V', '1', '2');
|
---|
2180 |
|
---|
2181 | /* Video format with alpha */
|
---|
2182 | case SVGA3D_AYUV:
|
---|
2183 | return (D3DFORMAT)MAKEFOURCC('A', 'Y', 'U', 'V');
|
---|
2184 |
|
---|
2185 | case SVGA3D_BC4_UNORM:
|
---|
2186 | case SVGA3D_BC5_UNORM:
|
---|
2187 | /* Unknown; only in DX10 & 11 */
|
---|
2188 | break;
|
---|
2189 | #endif
|
---|
2190 | default:
|
---|
2191 | AssertMsgFailed(("Unsupported format %d\n", format));
|
---|
2192 | break;
|
---|
2193 | }
|
---|
2194 | }
|
---|
2195 |
|
---|
2196 |
|
---|
2197 | #if 0
|
---|
2198 | /**
|
---|
2199 | * Convert SVGA multi sample count value to its D3D equivalent
|
---|
2200 | */
|
---|
2201 | D3DMULTISAMPLE_TYPE vmsvga3dMultipeSampleCount2D3D(uint32_t multisampleCount)
|
---|
2202 | {
|
---|
2203 | AssertCompile(D3DMULTISAMPLE_2_SAMPLES == 2);
|
---|
2204 | AssertCompile(D3DMULTISAMPLE_16_SAMPLES == 16);
|
---|
2205 |
|
---|
2206 | if (multisampleCount > 16)
|
---|
2207 | return D3DMULTISAMPLE_NONE;
|
---|
2208 |
|
---|
2209 | /* @todo exact same mapping as d3d? */
|
---|
2210 | return (D3DMULTISAMPLE_TYPE)multisampleCount;
|
---|
2211 | }
|
---|
2212 | #endif
|
---|
2213 |
|
---|
2214 | int vmsvga3dSurfaceDefine(PVGASTATE pThis, uint32_t sid, uint32_t surfaceFlags, SVGA3dSurfaceFormat format, SVGA3dSurfaceFace face[SVGA3D_MAX_SURFACE_FACES],
|
---|
2215 | uint32_t multisampleCount, SVGA3dTextureFilter autogenFilter, uint32_t cMipLevels, SVGA3dSize *pMipLevelSize)
|
---|
2216 | {
|
---|
2217 | PVMSVGA3DSURFACE pSurface;
|
---|
2218 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
2219 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
2220 |
|
---|
2221 | Log(("vmsvga3dSurfaceDefine: sid=%x surfaceFlags=%x format=%s (%x) multiSampleCount=%d autogenFilter=%d, cMipLevels=%d size=(%d,%d,%d)\n",
|
---|
2222 | sid, surfaceFlags, vmsvgaSurfaceType2String(format), format, multisampleCount, autogenFilter, cMipLevels, pMipLevelSize->width, pMipLevelSize->height, pMipLevelSize->depth));
|
---|
2223 |
|
---|
2224 | AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
2225 | AssertReturn(cMipLevels >= 1, VERR_INVALID_PARAMETER);
|
---|
2226 | /* Assuming all faces have the same nr of mipmaps. */
|
---|
2227 | AssertReturn(!(surfaceFlags & SVGA3D_SURFACE_CUBEMAP) || cMipLevels == face[0].numMipLevels * 6, VERR_INVALID_PARAMETER);
|
---|
2228 | AssertReturn((surfaceFlags & SVGA3D_SURFACE_CUBEMAP) || cMipLevels == face[0].numMipLevels, VERR_INVALID_PARAMETER);
|
---|
2229 |
|
---|
2230 | if (sid >= pState->cSurfaces)
|
---|
2231 | {
|
---|
2232 | pState->paSurface = (PVMSVGA3DSURFACE )RTMemRealloc(pState->paSurface, sizeof(VMSVGA3DSURFACE) * (sid + 1));
|
---|
2233 | AssertReturn(pState->paSurface, VERR_NO_MEMORY);
|
---|
2234 | memset(&pState->paSurface[pState->cSurfaces], 0, sizeof(VMSVGA3DSURFACE) * (sid + 1 - pState->cSurfaces));
|
---|
2235 | for (uint32_t i = pState->cSurfaces; i < sid + 1; i++)
|
---|
2236 | pState->paSurface[i].id = SVGA3D_INVALID_ID;
|
---|
2237 |
|
---|
2238 | pState->cSurfaces = sid + 1;
|
---|
2239 | }
|
---|
2240 | /* If one already exists with this id, then destroy it now. */
|
---|
2241 | if (pState->paSurface[sid].id != SVGA3D_INVALID_ID)
|
---|
2242 | vmsvga3dSurfaceDestroy(pThis, sid);
|
---|
2243 |
|
---|
2244 | pSurface = &pState->paSurface[sid];
|
---|
2245 | memset(pSurface, 0, sizeof(*pSurface));
|
---|
2246 | pSurface->id = sid;
|
---|
2247 | pSurface->idAssociatedContext = SVGA3D_INVALID_ID;
|
---|
2248 | vmsvga3dSurfaceFormat2OGL(pSurface, format);
|
---|
2249 |
|
---|
2250 | pSurface->oglId.buffer = OPENGL_INVALID_ID;
|
---|
2251 |
|
---|
2252 | /* The surface type is sort of undefined now, even though the hints and format can help to clear that up.
|
---|
2253 | * In some case we'll have to wait until the surface is used to create the D3D object.
|
---|
2254 | */
|
---|
2255 | switch (format)
|
---|
2256 | {
|
---|
2257 | case SVGA3D_Z_D32:
|
---|
2258 | case SVGA3D_Z_D16:
|
---|
2259 | case SVGA3D_Z_D24S8:
|
---|
2260 | case SVGA3D_Z_D15S1:
|
---|
2261 | case SVGA3D_Z_D24X8:
|
---|
2262 | case SVGA3D_Z_DF16:
|
---|
2263 | case SVGA3D_Z_DF24:
|
---|
2264 | case SVGA3D_Z_D24S8_INT:
|
---|
2265 | surfaceFlags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
|
---|
2266 | break;
|
---|
2267 |
|
---|
2268 | /* Texture compression formats */
|
---|
2269 | case SVGA3D_DXT1:
|
---|
2270 | case SVGA3D_DXT2:
|
---|
2271 | case SVGA3D_DXT3:
|
---|
2272 | case SVGA3D_DXT4:
|
---|
2273 | case SVGA3D_DXT5:
|
---|
2274 | /* Bump-map formats */
|
---|
2275 | case SVGA3D_BUMPU8V8:
|
---|
2276 | case SVGA3D_BUMPL6V5U5:
|
---|
2277 | case SVGA3D_BUMPX8L8V8U8:
|
---|
2278 | case SVGA3D_BUMPL8V8U8:
|
---|
2279 | case SVGA3D_V8U8:
|
---|
2280 | case SVGA3D_Q8W8V8U8:
|
---|
2281 | case SVGA3D_CxV8U8:
|
---|
2282 | case SVGA3D_X8L8V8U8:
|
---|
2283 | case SVGA3D_A2W10V10U10:
|
---|
2284 | case SVGA3D_V16U16:
|
---|
2285 | /* Typical render target formats; we should allow render target buffers to be used as textures. */
|
---|
2286 | case SVGA3D_X8R8G8B8:
|
---|
2287 | case SVGA3D_A8R8G8B8:
|
---|
2288 | case SVGA3D_R5G6B5:
|
---|
2289 | case SVGA3D_X1R5G5B5:
|
---|
2290 | case SVGA3D_A1R5G5B5:
|
---|
2291 | case SVGA3D_A4R4G4B4:
|
---|
2292 | surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE;
|
---|
2293 | break;
|
---|
2294 |
|
---|
2295 | case SVGA3D_LUMINANCE8:
|
---|
2296 | case SVGA3D_LUMINANCE4_ALPHA4:
|
---|
2297 | case SVGA3D_LUMINANCE16:
|
---|
2298 | case SVGA3D_LUMINANCE8_ALPHA8:
|
---|
2299 | case SVGA3D_ARGB_S10E5: /* 16-bit floating-point ARGB */
|
---|
2300 | case SVGA3D_ARGB_S23E8: /* 32-bit floating-point ARGB */
|
---|
2301 | case SVGA3D_A2R10G10B10:
|
---|
2302 | case SVGA3D_ALPHA8:
|
---|
2303 | case SVGA3D_R_S10E5:
|
---|
2304 | case SVGA3D_R_S23E8:
|
---|
2305 | case SVGA3D_RG_S10E5:
|
---|
2306 | case SVGA3D_RG_S23E8:
|
---|
2307 | case SVGA3D_G16R16:
|
---|
2308 | case SVGA3D_A16B16G16R16:
|
---|
2309 | case SVGA3D_UYVY:
|
---|
2310 | case SVGA3D_YUY2:
|
---|
2311 | case SVGA3D_NV12:
|
---|
2312 | case SVGA3D_AYUV:
|
---|
2313 | case SVGA3D_BC4_UNORM:
|
---|
2314 | case SVGA3D_BC5_UNORM:
|
---|
2315 | break;
|
---|
2316 |
|
---|
2317 | /*
|
---|
2318 | * Any surface can be used as a buffer object, but SVGA3D_BUFFER is
|
---|
2319 | * the most efficient format to use when creating new surfaces
|
---|
2320 | * expressly for index or vertex data.
|
---|
2321 | */
|
---|
2322 | case SVGA3D_BUFFER:
|
---|
2323 | break;
|
---|
2324 |
|
---|
2325 | default:
|
---|
2326 | break;
|
---|
2327 | }
|
---|
2328 |
|
---|
2329 | pSurface->flags = surfaceFlags;
|
---|
2330 | pSurface->format = format;
|
---|
2331 | memcpy(pSurface->faces, face, sizeof(face));
|
---|
2332 | pSurface->cFaces = 1; /* check for cube maps later */
|
---|
2333 | pSurface->multiSampleCount = multisampleCount;
|
---|
2334 | pSurface->autogenFilter = autogenFilter;
|
---|
2335 | Assert(autogenFilter != SVGA3D_TEX_FILTER_FLATCUBIC);
|
---|
2336 | Assert(autogenFilter != SVGA3D_TEX_FILTER_GAUSSIANCUBIC);
|
---|
2337 | pSurface->pMipmapLevels = (PVMSVGA3DMIPMAPLEVEL)RTMemAllocZ(cMipLevels * sizeof(VMSVGA3DMIPMAPLEVEL));
|
---|
2338 | AssertReturn(pSurface->pMipmapLevels, VERR_NO_MEMORY);
|
---|
2339 |
|
---|
2340 | for (uint32_t i=0; i < cMipLevels; i++)
|
---|
2341 | pSurface->pMipmapLevels[i].size = pMipLevelSize[i];
|
---|
2342 |
|
---|
2343 | pSurface->cbBlock = vmsvga3dSurfaceFormatSize(format);
|
---|
2344 |
|
---|
2345 | switch (surfaceFlags & (SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP))
|
---|
2346 | {
|
---|
2347 | case SVGA3D_SURFACE_CUBEMAP:
|
---|
2348 | Log(("SVGA3D_SURFACE_CUBEMAP\n"));
|
---|
2349 | pSurface->cFaces = 6;
|
---|
2350 | break;
|
---|
2351 |
|
---|
2352 | case SVGA3D_SURFACE_HINT_INDEXBUFFER:
|
---|
2353 | Log(("SVGA3D_SURFACE_HINT_INDEXBUFFER\n"));
|
---|
2354 | /* else type unknown at this time; postpone buffer creation */
|
---|
2355 | break;
|
---|
2356 |
|
---|
2357 | case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
|
---|
2358 | Log(("SVGA3D_SURFACE_HINT_VERTEXBUFFER\n"));
|
---|
2359 | /* Type unknown at this time; postpone buffer creation */
|
---|
2360 | break;
|
---|
2361 |
|
---|
2362 | case SVGA3D_SURFACE_HINT_TEXTURE:
|
---|
2363 | Log(("SVGA3D_SURFACE_HINT_TEXTURE\n"));
|
---|
2364 | break;
|
---|
2365 |
|
---|
2366 | case SVGA3D_SURFACE_HINT_RENDERTARGET:
|
---|
2367 | Log(("SVGA3D_SURFACE_HINT_RENDERTARGET\n"));
|
---|
2368 | break;
|
---|
2369 |
|
---|
2370 | case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:
|
---|
2371 | Log(("SVGA3D_SURFACE_HINT_DEPTHSTENCIL\n"));
|
---|
2372 | break;
|
---|
2373 |
|
---|
2374 | default:
|
---|
2375 | /* Unknown; decide later. */
|
---|
2376 | break;
|
---|
2377 | }
|
---|
2378 |
|
---|
2379 | /* Allocate buffer to hold the surface data until we can move it into a D3D object */
|
---|
2380 | for (uint32_t iFace=0; iFace < pSurface->cFaces; iFace++)
|
---|
2381 | {
|
---|
2382 | for (uint32_t i=0; i < pSurface->faces[iFace].numMipLevels; i++)
|
---|
2383 | {
|
---|
2384 | uint32_t idx = i + iFace * pSurface->faces[0].numMipLevels;
|
---|
2385 |
|
---|
2386 | Log(("vmsvga3dSurfaceDefine: face %d mip level %d (%d,%d,%d)\n", iFace, i, pSurface->pMipmapLevels[idx].size.width, pSurface->pMipmapLevels[idx].size.height, pSurface->pMipmapLevels[idx].size.depth));
|
---|
2387 | Log(("vmsvga3dSurfaceDefine: cbPitch=%x cbBlock=%x \n", pSurface->cbBlock * pSurface->pMipmapLevels[idx].size.width, pSurface->cbBlock));
|
---|
2388 |
|
---|
2389 | pSurface->pMipmapLevels[idx].cbSurfacePitch = pSurface->cbBlock * pSurface->pMipmapLevels[idx].size.width;
|
---|
2390 | pSurface->pMipmapLevels[idx].cbSurface = pSurface->pMipmapLevels[idx].cbSurfacePitch * pSurface->pMipmapLevels[idx].size.height * pSurface->pMipmapLevels[idx].size.depth;
|
---|
2391 | pSurface->pMipmapLevels[idx].pSurfaceData = RTMemAllocZ(pSurface->pMipmapLevels[idx].cbSurface);
|
---|
2392 | AssertReturn(pSurface->pMipmapLevels[idx].pSurfaceData, VERR_NO_MEMORY);
|
---|
2393 | }
|
---|
2394 | }
|
---|
2395 | return VINF_SUCCESS;
|
---|
2396 | }
|
---|
2397 |
|
---|
2398 | int vmsvga3dSurfaceDestroy(PVGASTATE pThis, uint32_t sid)
|
---|
2399 | {
|
---|
2400 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
2401 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
2402 |
|
---|
2403 | if ( sid < pState->cSurfaces
|
---|
2404 | && pState->paSurface[sid].id == sid)
|
---|
2405 | {
|
---|
2406 | PVMSVGA3DSURFACE pSurface = &pState->paSurface[sid];
|
---|
2407 | PVMSVGA3DCONTEXT pContext = NULL;
|
---|
2408 |
|
---|
2409 | Log(("vmsvga3dSurfaceDestroy id %x\n", sid));
|
---|
2410 |
|
---|
2411 | /* @todo stricter checks for associated context */
|
---|
2412 | uint32_t cid = pSurface->idAssociatedContext;
|
---|
2413 | if ( cid <= pState->cContexts
|
---|
2414 | && pState->paContext[cid].id == cid)
|
---|
2415 | {
|
---|
2416 | pContext = &pState->paContext[cid];
|
---|
2417 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
2418 | }
|
---|
2419 | else
|
---|
2420 | {
|
---|
2421 | /* Pick any active context; we need something here */
|
---|
2422 | for (cid = 0; cid < pState->cContexts; cid++)
|
---|
2423 | {
|
---|
2424 | if (pState->paContext[cid].id == cid)
|
---|
2425 | {
|
---|
2426 | pContext = &pState->paContext[cid];
|
---|
2427 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
2428 | break;
|
---|
2429 | }
|
---|
2430 | }
|
---|
2431 | AssertReturn(pContext, VERR_INTERNAL_ERROR); /* otherwise crashes/fails */
|
---|
2432 | }
|
---|
2433 |
|
---|
2434 | switch (pSurface->flags & (SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP))
|
---|
2435 | {
|
---|
2436 | case SVGA3D_SURFACE_CUBEMAP:
|
---|
2437 | AssertFailed(); /* @todo */
|
---|
2438 | break;
|
---|
2439 |
|
---|
2440 | case SVGA3D_SURFACE_HINT_INDEXBUFFER:
|
---|
2441 | case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
|
---|
2442 | if (pSurface->oglId.buffer != OPENGL_INVALID_ID)
|
---|
2443 | {
|
---|
2444 | pState->ext.glDeleteBuffers(1, &pSurface->oglId.buffer);
|
---|
2445 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2446 | }
|
---|
2447 | break;
|
---|
2448 |
|
---|
2449 | case SVGA3D_SURFACE_HINT_TEXTURE:
|
---|
2450 | case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
|
---|
2451 | if (pSurface->oglId.texture != OPENGL_INVALID_ID)
|
---|
2452 | {
|
---|
2453 | glDeleteTextures(1, &pSurface->oglId.texture);
|
---|
2454 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2455 | }
|
---|
2456 | break;
|
---|
2457 |
|
---|
2458 | case SVGA3D_SURFACE_HINT_RENDERTARGET:
|
---|
2459 | case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:
|
---|
2460 | case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE: /* @todo actual texture surface not supported */
|
---|
2461 | if (pSurface->oglId.renderbuffer != OPENGL_INVALID_ID)
|
---|
2462 | {
|
---|
2463 | pState->ext.glDeleteRenderbuffers(1, &pSurface->oglId.renderbuffer);
|
---|
2464 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2465 | }
|
---|
2466 | break;
|
---|
2467 |
|
---|
2468 | default:
|
---|
2469 | break;
|
---|
2470 | }
|
---|
2471 |
|
---|
2472 | if (pSurface->pMipmapLevels)
|
---|
2473 | {
|
---|
2474 | for (uint32_t face=0; face < pSurface->cFaces; face++)
|
---|
2475 | {
|
---|
2476 | for (uint32_t i=0; i < pSurface->faces[face].numMipLevels; i++)
|
---|
2477 | {
|
---|
2478 | uint32_t idx = i + face * pSurface->faces[0].numMipLevels;
|
---|
2479 | if (pSurface->pMipmapLevels[idx].pSurfaceData)
|
---|
2480 | RTMemFree(pSurface->pMipmapLevels[idx].pSurfaceData);
|
---|
2481 | }
|
---|
2482 | }
|
---|
2483 | RTMemFree(pSurface->pMipmapLevels);
|
---|
2484 | }
|
---|
2485 |
|
---|
2486 | memset(pSurface, 0, sizeof(*pSurface));
|
---|
2487 | pSurface->id = SVGA3D_INVALID_ID;
|
---|
2488 | }
|
---|
2489 | else
|
---|
2490 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
2491 |
|
---|
2492 | return VINF_SUCCESS;
|
---|
2493 | }
|
---|
2494 |
|
---|
2495 | int vmsvga3dSurfaceCopy(PVGASTATE pThis, SVGA3dSurfaceImageId dest, SVGA3dSurfaceImageId src, uint32_t cCopyBoxes, SVGA3dCopyBox *pBox)
|
---|
2496 | {
|
---|
2497 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
2498 | uint32_t sidSrc = src.sid;
|
---|
2499 | uint32_t sidDest = dest.sid;
|
---|
2500 | int rc = VINF_SUCCESS;
|
---|
2501 |
|
---|
2502 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
2503 | AssertReturn(sidSrc < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
2504 | AssertReturn(sidSrc < pState->cSurfaces && pState->paSurface[sidSrc].id == sidSrc, VERR_INVALID_PARAMETER);
|
---|
2505 | AssertReturn(sidDest < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
2506 | AssertReturn(sidDest < pState->cSurfaces && pState->paSurface[sidDest].id == sidDest, VERR_INVALID_PARAMETER);
|
---|
2507 |
|
---|
2508 | for (uint32_t i = 0; i < cCopyBoxes; i++)
|
---|
2509 | {
|
---|
2510 | SVGA3dBox destBox, srcBox;
|
---|
2511 |
|
---|
2512 | srcBox.x = pBox[i].srcx;
|
---|
2513 | srcBox.y = pBox[i].srcy;
|
---|
2514 | srcBox.z = pBox[i].srcz;
|
---|
2515 | srcBox.w = pBox[i].w;
|
---|
2516 | srcBox.h = pBox[i].h;
|
---|
2517 | srcBox.d = pBox[i].z;
|
---|
2518 |
|
---|
2519 | destBox.x = pBox[i].x;
|
---|
2520 | destBox.y = pBox[i].y;
|
---|
2521 | destBox.z = pBox[i].z;
|
---|
2522 | destBox.w = pBox[i].w;
|
---|
2523 | destBox.h = pBox[i].h;
|
---|
2524 | destBox.z = pBox[i].z;
|
---|
2525 |
|
---|
2526 | rc = vmsvga3dSurfaceStretchBlt(pThis, dest, destBox, src, srcBox, SVGA3D_STRETCH_BLT_LINEAR);
|
---|
2527 | AssertRCReturn(rc, rc);
|
---|
2528 | }
|
---|
2529 | return VINF_SUCCESS;
|
---|
2530 | }
|
---|
2531 |
|
---|
2532 | /* Create D3D texture object for the specified surface. */
|
---|
2533 | static int vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface)
|
---|
2534 | {
|
---|
2535 | GLint activeTexture = 0;
|
---|
2536 |
|
---|
2537 | glGenTextures(1, &pSurface->oglId.texture);
|
---|
2538 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2539 | /* @todo Set the mip map generation filter settings. */
|
---|
2540 |
|
---|
2541 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
|
---|
2542 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2543 |
|
---|
2544 | /* Must bind texture to the current context in order to change it. */
|
---|
2545 | glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
|
---|
2546 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2547 |
|
---|
2548 | if (pSurface->fDirty)
|
---|
2549 | {
|
---|
2550 | Log(("vmsvga3dCreateTexture: sync dirty texture\n"));
|
---|
2551 | for (uint32_t i = 0; i < pSurface->faces[0].numMipLevels; i++)
|
---|
2552 | {
|
---|
2553 | if (pSurface->pMipmapLevels[i].fDirty)
|
---|
2554 | {
|
---|
2555 | Log(("vmsvga3dCreateTexture: sync dirty texture mipmap level %d (pitch %x)\n", i, pSurface->pMipmapLevels[i].cbSurfacePitch));
|
---|
2556 |
|
---|
2557 | glTexImage2D(GL_TEXTURE_2D,
|
---|
2558 | i,
|
---|
2559 | pSurface->internalFormatGL,
|
---|
2560 | pSurface->pMipmapLevels[i].size.width,
|
---|
2561 | pSurface->pMipmapLevels[i].size.height,
|
---|
2562 | 0,
|
---|
2563 | pSurface->formatGL,
|
---|
2564 | pSurface->typeGL,
|
---|
2565 | pSurface->pMipmapLevels[i].pSurfaceData);
|
---|
2566 |
|
---|
2567 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2568 |
|
---|
2569 | pSurface->pMipmapLevels[i].fDirty = false;
|
---|
2570 | }
|
---|
2571 | }
|
---|
2572 | pSurface->fDirty = false;
|
---|
2573 | }
|
---|
2574 | else
|
---|
2575 | /* Reserve texture memory. */
|
---|
2576 | glTexImage2D(GL_TEXTURE_2D,
|
---|
2577 | 0,
|
---|
2578 | pSurface->internalFormatGL,
|
---|
2579 | pSurface->pMipmapLevels[0].size.width,
|
---|
2580 | pSurface->pMipmapLevels[0].size.height,
|
---|
2581 | 0,
|
---|
2582 | pSurface->formatGL,
|
---|
2583 | pSurface->typeGL,
|
---|
2584 | NULL);
|
---|
2585 |
|
---|
2586 | /* Restore the old active texture. */
|
---|
2587 | glBindTexture(GL_TEXTURE_2D, activeTexture);
|
---|
2588 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2589 |
|
---|
2590 | pSurface->flags |= SVGA3D_SURFACE_HINT_TEXTURE;
|
---|
2591 | pSurface->idAssociatedContext = idAssociatedContext;
|
---|
2592 | return VINF_SUCCESS;
|
---|
2593 | }
|
---|
2594 |
|
---|
2595 | int vmsvga3dSurfaceStretchBlt(PVGASTATE pThis, SVGA3dSurfaceImageId dest, SVGA3dBox destBox, SVGA3dSurfaceImageId src, SVGA3dBox srcBox, SVGA3dStretchBltMode mode)
|
---|
2596 | {
|
---|
2597 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
2598 | PVMSVGA3DSURFACE pSurfaceSrc;
|
---|
2599 | uint32_t sidSrc = src.sid;
|
---|
2600 | PVMSVGA3DSURFACE pSurfaceDest;
|
---|
2601 | uint32_t sidDest = dest.sid;
|
---|
2602 | int rc = VINF_SUCCESS;
|
---|
2603 | uint32_t cid;
|
---|
2604 | PVMSVGA3DCONTEXT pContext;
|
---|
2605 |
|
---|
2606 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
2607 | AssertReturn(sidSrc < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
2608 | AssertReturn(sidSrc < pState->cSurfaces && pState->paSurface[sidSrc].id == sidSrc, VERR_INVALID_PARAMETER);
|
---|
2609 | AssertReturn(sidDest < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
2610 | AssertReturn(sidDest < pState->cSurfaces && pState->paSurface[sidDest].id == sidDest, VERR_INVALID_PARAMETER);
|
---|
2611 |
|
---|
2612 | pSurfaceSrc = &pState->paSurface[sidSrc];
|
---|
2613 | pSurfaceDest = &pState->paSurface[sidDest];
|
---|
2614 | AssertReturn(pSurfaceSrc->faces[0].numMipLevels > src.mipmap, VERR_INVALID_PARAMETER);
|
---|
2615 | AssertReturn(pSurfaceDest->faces[0].numMipLevels > dest.mipmap, VERR_INVALID_PARAMETER);
|
---|
2616 |
|
---|
2617 | Log(("vmsvga3dSurfaceStretchBlt: src sid=%x (%d,%d)(%d,%d) dest sid=%x (%d,%d)(%d,%d) mode=%x\n", src.sid, srcBox.x, srcBox.y, srcBox.x + srcBox.w, srcBox.y + srcBox.h, dest.sid, destBox.x, destBox.y, destBox.x + destBox.w, destBox.y + destBox.h, mode));
|
---|
2618 |
|
---|
2619 | /* @todo stricter checks for associated context */
|
---|
2620 | cid = pSurfaceDest->idAssociatedContext;
|
---|
2621 | if (cid == SVGA3D_INVALID_ID)
|
---|
2622 | cid = pSurfaceSrc->idAssociatedContext;
|
---|
2623 |
|
---|
2624 | if ( cid >= pState->cContexts
|
---|
2625 | || pState->paContext[cid].id != cid)
|
---|
2626 | {
|
---|
2627 | Log(("vmsvga3dSurfaceStretchBlt invalid context id!\n"));
|
---|
2628 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
2629 | }
|
---|
2630 | pContext = &pState->paContext[cid];
|
---|
2631 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
2632 |
|
---|
2633 | if (pSurfaceSrc->oglId.texture == OPENGL_INVALID_ID)
|
---|
2634 | {
|
---|
2635 | /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
|
---|
2636 | Log(("vmsvga3dSurfaceStretchBlt: unknown src surface id=%x type=%d format=%d -> create texture\n", sidSrc, pSurfaceSrc->flags, pSurfaceSrc->format));
|
---|
2637 | rc = vmsvga3dCreateTexture(pState, pContext, cid, pSurfaceSrc);
|
---|
2638 | AssertRCReturn(rc, rc);
|
---|
2639 | }
|
---|
2640 |
|
---|
2641 | if (pSurfaceDest->oglId.texture == OPENGL_INVALID_ID)
|
---|
2642 | {
|
---|
2643 | /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
|
---|
2644 | Log(("vmsvga3dSurfaceStretchBlt: unknown dest surface id=%x type=%d format=%d -> create texture\n", sidDest, pSurfaceDest->flags, pSurfaceDest->format));
|
---|
2645 | rc = vmsvga3dCreateTexture(pState, pContext, cid, pSurfaceDest);
|
---|
2646 | AssertRCReturn(rc, rc);
|
---|
2647 | }
|
---|
2648 |
|
---|
2649 | /* Activate the read and draw framebuffer objects. */
|
---|
2650 | pState->ext.glBindFramebuffer(GL_READ_FRAMEBUFFER, pContext->idReadFramebuffer);
|
---|
2651 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2652 | pState->ext.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, pContext->idDrawFramebuffer);
|
---|
2653 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2654 |
|
---|
2655 | /* Bind the source and destination objects to the right place. */
|
---|
2656 | pState->ext.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pSurfaceSrc->oglId.texture, src.mipmap);
|
---|
2657 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2658 | pState->ext.glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pSurfaceDest->oglId.texture, dest.mipmap);
|
---|
2659 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2660 |
|
---|
2661 | Log(("src conv. (%d,%d)(%d,%d); dest conv (%d,%d)(%d,%d)\n", srcBox.x, D3D_TO_OGL_Y_COORD(pSurfaceSrc, srcBox.y + srcBox.h),
|
---|
2662 | srcBox.x + srcBox.w, D3D_TO_OGL_Y_COORD(pSurfaceSrc, srcBox.y), destBox.x, D3D_TO_OGL_Y_COORD(pSurfaceDest, destBox.y + destBox.h),
|
---|
2663 | destBox.x + destBox.w, D3D_TO_OGL_Y_COORD(pSurfaceDest, destBox.y)));
|
---|
2664 |
|
---|
2665 | pState->ext.glBlitFramebuffer(srcBox.x,
|
---|
2666 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
2667 | D3D_TO_OGL_Y_COORD(pSurfaceSrc, srcBox.y + srcBox.h), /* inclusive */
|
---|
2668 | #else
|
---|
2669 | srcBox.y,
|
---|
2670 | #endif
|
---|
2671 | srcBox.x + srcBox.w, /* exclusive. */
|
---|
2672 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
2673 | D3D_TO_OGL_Y_COORD(pSurfaceSrc, srcBox.y), /* exclusive */
|
---|
2674 | #else
|
---|
2675 | srcBox.y + srcBox.h,
|
---|
2676 | #endif
|
---|
2677 | destBox.x,
|
---|
2678 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
2679 | D3D_TO_OGL_Y_COORD(pSurfaceDest, destBox.y + destBox.h), /* inclusive. */
|
---|
2680 | #else
|
---|
2681 | destBox.y,
|
---|
2682 | #endif
|
---|
2683 | destBox.x + destBox.w, /* exclusive. */
|
---|
2684 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
2685 | D3D_TO_OGL_Y_COORD(pSurfaceDest, destBox.y), /* exclusive */
|
---|
2686 | #else
|
---|
2687 | destBox.y + destBox.h,
|
---|
2688 | #endif
|
---|
2689 | GL_COLOR_BUFFER_BIT,
|
---|
2690 | (mode == SVGA3D_STRETCH_BLT_POINT) ? GL_NEAREST : GL_LINEAR);
|
---|
2691 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2692 |
|
---|
2693 | /* Reset the frame buffer association */
|
---|
2694 | pState->ext.glBindFramebuffer(GL_FRAMEBUFFER, pContext->idFramebuffer);
|
---|
2695 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2696 |
|
---|
2697 | return VINF_SUCCESS;
|
---|
2698 | }
|
---|
2699 |
|
---|
2700 | int vmsvga3dSurfaceDMA(PVGASTATE pThis, SVGA3dGuestImage guest, SVGA3dSurfaceImageId host, SVGA3dTransferType transfer, uint32_t cCopyBoxes, SVGA3dCopyBox *pBoxes)
|
---|
2701 | {
|
---|
2702 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
2703 | PVMSVGA3DSURFACE pSurface;
|
---|
2704 | PVMSVGA3DMIPMAPLEVEL pMipLevel;
|
---|
2705 | uint32_t sid = host.sid;
|
---|
2706 | int rc = VINF_SUCCESS;
|
---|
2707 |
|
---|
2708 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
2709 | AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
2710 | AssertReturn(sid < pState->cSurfaces && pState->paSurface[sid].id == sid, VERR_INVALID_PARAMETER);
|
---|
2711 |
|
---|
2712 | pSurface = &pState->paSurface[sid];
|
---|
2713 | AssertReturn(pSurface->faces[0].numMipLevels > host.mipmap, VERR_INVALID_PARAMETER);
|
---|
2714 | pMipLevel = &pSurface->pMipmapLevels[host.mipmap];
|
---|
2715 |
|
---|
2716 | if (pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE)
|
---|
2717 | Log(("vmsvga3dSurfaceDMA TEXTURE guestptr gmr=%x offset=%x pitch=%x host sid=%x face=%d mipmap=%d transfer=%x cCopyBoxes=%d\n", guest.ptr.gmrId, guest.ptr.offset, guest.pitch, host.sid, host.face, host.mipmap, transfer, cCopyBoxes));
|
---|
2718 | else
|
---|
2719 | Log(("vmsvga3dSurfaceDMA guestptr gmr=%x offset=%x pitch=%x host sid=%x face=%d mipmap=%d transfer=%x cCopyBoxes=%d\n", guest.ptr.gmrId, guest.ptr.offset, guest.pitch, host.sid, host.face, host.mipmap, transfer, cCopyBoxes));
|
---|
2720 |
|
---|
2721 | if (pSurface->oglId.texture == OPENGL_INVALID_ID)
|
---|
2722 | {
|
---|
2723 | AssertReturn(pSurface->pMipmapLevels[host.mipmap].pSurfaceData, VERR_INTERNAL_ERROR);
|
---|
2724 |
|
---|
2725 | for (unsigned i = 0; i < cCopyBoxes; i++)
|
---|
2726 | {
|
---|
2727 | unsigned uDestOffset;
|
---|
2728 | unsigned cbSrcPitch;
|
---|
2729 | uint8_t *pBufferStart;
|
---|
2730 |
|
---|
2731 | Log(("Copy box %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n", i, pBoxes[i].srcx, pBoxes[i].srcy, pBoxes[i].srcz, pBoxes[i].w, pBoxes[i].h, pBoxes[i].d, pBoxes[i].x, pBoxes[i].y));
|
---|
2732 | /* Apparently we're supposed to clip it (gmr test sample) */
|
---|
2733 | if (pBoxes[i].x + pBoxes[i].w > pMipLevel->size.width)
|
---|
2734 | pBoxes[i].w = pMipLevel->size.width - pBoxes[i].x;
|
---|
2735 | if (pBoxes[i].y + pBoxes[i].h > pMipLevel->size.height)
|
---|
2736 | pBoxes[i].h = pMipLevel->size.height - pBoxes[i].y;
|
---|
2737 | if (pBoxes[i].z + pBoxes[i].d > pMipLevel->size.depth)
|
---|
2738 | pBoxes[i].d = pMipLevel->size.depth - pBoxes[i].z;
|
---|
2739 |
|
---|
2740 | if ( !pBoxes[i].w
|
---|
2741 | || !pBoxes[i].h
|
---|
2742 | || !pBoxes[i].d
|
---|
2743 | || pBoxes[i].x > pMipLevel->size.width
|
---|
2744 | || pBoxes[i].y > pMipLevel->size.height
|
---|
2745 | || pBoxes[i].z > pMipLevel->size.depth)
|
---|
2746 | {
|
---|
2747 | Log(("Empty box; skip\n"));
|
---|
2748 | continue;
|
---|
2749 | }
|
---|
2750 |
|
---|
2751 | uDestOffset = pBoxes[i].x * pSurface->cbBlock + pBoxes[i].y * pMipLevel->cbSurfacePitch + pBoxes[i].z * pMipLevel->size.height * pMipLevel->cbSurfacePitch;
|
---|
2752 | AssertReturn(uDestOffset + pBoxes[i].w * pSurface->cbBlock * pBoxes[i].h * pBoxes[i].d <= pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
|
---|
2753 |
|
---|
2754 | cbSrcPitch = (guest.pitch == 0) ? pBoxes[i].w * pSurface->cbBlock : guest.pitch;
|
---|
2755 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
2756 | pBufferStart = (uint8_t *)pMipLevel->pSurfaceData
|
---|
2757 | + pBoxes[i].x * pSurface->cbBlock
|
---|
2758 | + pMipLevel->cbSurface - pBoxes[i].y * pMipLevel->cbSurfacePitch
|
---|
2759 | - pMipLevel->cbSurfacePitch; /* flip image during copy */
|
---|
2760 | #else
|
---|
2761 | pBufferStart = (uint8_t *)pMipLevel->pSurfaceData + uDestOffset;
|
---|
2762 | #endif
|
---|
2763 | rc = vmsvgaGMRTransfer(pThis,
|
---|
2764 | transfer,
|
---|
2765 | pBufferStart,
|
---|
2766 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
2767 | -(int32_t)pMipLevel->cbSurfacePitch,
|
---|
2768 | #else
|
---|
2769 | (int32_t)pMipLevel->cbSurfacePitch,
|
---|
2770 | #endif
|
---|
2771 | guest.ptr,
|
---|
2772 | pBoxes[i].srcx * pSurface->cbBlock + (pBoxes[i].srcy + pBoxes[i].srcz * pBoxes[i].h) * cbSrcPitch,
|
---|
2773 | cbSrcPitch,
|
---|
2774 | pBoxes[i].w * pSurface->cbBlock,
|
---|
2775 | pBoxes[i].d * pBoxes[i].h);
|
---|
2776 |
|
---|
2777 | Log4(("first line:\n%.*Rhxd\n", pMipLevel->cbSurface, pMipLevel->pSurfaceData));
|
---|
2778 |
|
---|
2779 | AssertRC(rc);
|
---|
2780 | }
|
---|
2781 | pSurface->pMipmapLevels[host.mipmap].fDirty = true;
|
---|
2782 | pSurface->fDirty = true;
|
---|
2783 | }
|
---|
2784 | else
|
---|
2785 | {
|
---|
2786 | /* @todo stricter checks for associated context */
|
---|
2787 | uint32_t cid = pSurface->idAssociatedContext;
|
---|
2788 | if ( cid >= pState->cContexts
|
---|
2789 | || pState->paContext[cid].id != cid)
|
---|
2790 | {
|
---|
2791 | Log(("vmsvga3dSurfaceDMA invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->paContext[cid].id));
|
---|
2792 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
2793 | }
|
---|
2794 | PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
|
---|
2795 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
2796 |
|
---|
2797 | for (unsigned i = 0; i < cCopyBoxes; i++)
|
---|
2798 | {
|
---|
2799 | bool fVertex = false;
|
---|
2800 | unsigned cbSrcPitch;
|
---|
2801 |
|
---|
2802 | /* Apparently we're supposed to clip it (gmr test sample) */
|
---|
2803 | if (pBoxes[i].x + pBoxes[i].w > pMipLevel->size.width)
|
---|
2804 | pBoxes[i].w = pMipLevel->size.width - pBoxes[i].x;
|
---|
2805 | if (pBoxes[i].y + pBoxes[i].h > pMipLevel->size.height)
|
---|
2806 | pBoxes[i].h = pMipLevel->size.height - pBoxes[i].y;
|
---|
2807 | if (pBoxes[i].z + pBoxes[i].d > pMipLevel->size.depth)
|
---|
2808 | pBoxes[i].d = pMipLevel->size.depth - pBoxes[i].z;
|
---|
2809 |
|
---|
2810 | Assert((pBoxes[i].d == 1 || pBoxes[i].d == 0) && pBoxes[i].z == 0);
|
---|
2811 |
|
---|
2812 | if ( !pBoxes[i].w
|
---|
2813 | || !pBoxes[i].h
|
---|
2814 | || pBoxes[i].x > pMipLevel->size.width
|
---|
2815 | || pBoxes[i].y > pMipLevel->size.height)
|
---|
2816 | {
|
---|
2817 | Log(("Empty box; skip\n"));
|
---|
2818 | continue;
|
---|
2819 | }
|
---|
2820 |
|
---|
2821 | Log(("Copy box %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n", i, pBoxes[i].srcx, pBoxes[i].srcy, pBoxes[i].srcz, pBoxes[i].w, pBoxes[i].h, pBoxes[i].d, pBoxes[i].x, pBoxes[i].y));
|
---|
2822 |
|
---|
2823 | cbSrcPitch = (guest.pitch == 0) ? pBoxes[i].w * pSurface->cbBlock : guest.pitch;
|
---|
2824 |
|
---|
2825 | switch (pSurface->flags & (SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP))
|
---|
2826 | {
|
---|
2827 | case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
|
---|
2828 | case SVGA3D_SURFACE_HINT_TEXTURE:
|
---|
2829 | case SVGA3D_SURFACE_HINT_RENDERTARGET:
|
---|
2830 | {
|
---|
2831 | uint32_t cbSurfacePitch;
|
---|
2832 | uint8_t *pDoubleBuffer, *pBufferStart;
|
---|
2833 | unsigned uDestOffset = 0;
|
---|
2834 |
|
---|
2835 | pDoubleBuffer = (uint8_t *)RTMemAlloc(pMipLevel->cbSurface);
|
---|
2836 | AssertReturn(pDoubleBuffer, VERR_NO_MEMORY);
|
---|
2837 |
|
---|
2838 | if (transfer == SVGA3D_READ_HOST_VRAM)
|
---|
2839 | {
|
---|
2840 | GLint activeTexture;
|
---|
2841 |
|
---|
2842 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
|
---|
2843 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
2844 |
|
---|
2845 | glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
|
---|
2846 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
2847 |
|
---|
2848 | glGetTexImage(GL_TEXTURE_2D,
|
---|
2849 | host.mipmap,
|
---|
2850 | pSurface->formatGL,
|
---|
2851 | pSurface->typeGL,
|
---|
2852 | pDoubleBuffer);
|
---|
2853 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
2854 |
|
---|
2855 | /* Restore the old active texture. */
|
---|
2856 | glBindTexture(GL_TEXTURE_2D, activeTexture);
|
---|
2857 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
2858 |
|
---|
2859 | uDestOffset = pBoxes[i].x * pSurface->cbBlock + pBoxes[i].y * pMipLevel->cbSurfacePitch;
|
---|
2860 | AssertReturn(uDestOffset + pBoxes[i].w * pSurface->cbBlock + (pBoxes[i].h - 1) * pMipLevel->cbSurfacePitch <= pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
|
---|
2861 |
|
---|
2862 | cbSurfacePitch = pMipLevel->cbSurfacePitch;
|
---|
2863 |
|
---|
2864 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
2865 | pBufferStart = pDoubleBuffer
|
---|
2866 | + pBoxes[i].x * pSurface->cbBlock
|
---|
2867 | + pMipLevel->cbSurface - pBoxes[i].y * cbSurfacePitch
|
---|
2868 | - cbSurfacePitch; /* flip image during copy */
|
---|
2869 | #else
|
---|
2870 | pBufferStart = pDoubleBuffer + uDestOffset;
|
---|
2871 | #endif
|
---|
2872 | }
|
---|
2873 | else
|
---|
2874 | {
|
---|
2875 | cbSurfacePitch = pBoxes[i].w * pSurface->cbBlock;
|
---|
2876 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
2877 | pBufferStart = pDoubleBuffer + cbSurfacePitch * pBoxes[i].h - cbSurfacePitch; /* flip image during copy */
|
---|
2878 | #else
|
---|
2879 | pBufferStart = pDoubleBuffer;
|
---|
2880 | #endif
|
---|
2881 | }
|
---|
2882 |
|
---|
2883 | rc = vmsvgaGMRTransfer(pThis,
|
---|
2884 | transfer,
|
---|
2885 | pBufferStart,
|
---|
2886 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
2887 | -(int32_t)cbSurfacePitch,
|
---|
2888 | #else
|
---|
2889 | (int32_t)cbSurfacePitch,
|
---|
2890 | #endif
|
---|
2891 | guest.ptr,
|
---|
2892 | pBoxes[i].srcx * pSurface->cbBlock + pBoxes[i].srcy * cbSrcPitch,
|
---|
2893 | cbSrcPitch,
|
---|
2894 | pBoxes[i].w * pSurface->cbBlock,
|
---|
2895 | pBoxes[i].h);
|
---|
2896 | AssertRC(rc);
|
---|
2897 |
|
---|
2898 | /* Update the opengl surface data. */
|
---|
2899 | if (transfer == SVGA3D_WRITE_HOST_VRAM)
|
---|
2900 | {
|
---|
2901 | GLint activeTexture = 0;
|
---|
2902 | GLint alignment;
|
---|
2903 |
|
---|
2904 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
|
---|
2905 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
2906 |
|
---|
2907 | /* Must bind texture to the current context in order to change it. */
|
---|
2908 | glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
|
---|
2909 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
2910 |
|
---|
2911 | Log(("vmsvga3dSurfaceDMA: copy texture mipmap level %d (pitch %x)\n", host.mipmap, pMipLevel->cbSurfacePitch));
|
---|
2912 |
|
---|
2913 | /* Set row length and alignment of the input data. */
|
---|
2914 | glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
|
---|
2915 | glPixelStorei(GL_UNPACK_ROW_LENGTH, pBoxes[i].w);
|
---|
2916 | glPixelStorei(GL_UNPACK_ALIGNMENT, pSurface->cbBlock);
|
---|
2917 |
|
---|
2918 | glTexSubImage2D(GL_TEXTURE_2D,
|
---|
2919 | host.mipmap,
|
---|
2920 | pBoxes[i].x,
|
---|
2921 | pBoxes[i].y,
|
---|
2922 | pBoxes[i].w,
|
---|
2923 | pBoxes[i].h,
|
---|
2924 | pSurface->formatGL,
|
---|
2925 | pSurface->typeGL,
|
---|
2926 | pDoubleBuffer);
|
---|
2927 |
|
---|
2928 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
2929 |
|
---|
2930 | /* Restore old values. */
|
---|
2931 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
---|
2932 | glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
|
---|
2933 |
|
---|
2934 | /* Restore the old active texture. */
|
---|
2935 | glBindTexture(GL_TEXTURE_2D, activeTexture);
|
---|
2936 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
2937 | }
|
---|
2938 |
|
---|
2939 | Log4(("first line:\n%.*Rhxd\n", pBoxes[i].w * pSurface->cbBlock, pDoubleBuffer));
|
---|
2940 |
|
---|
2941 | /* Free the double buffer. */
|
---|
2942 | RTMemFree(pDoubleBuffer);
|
---|
2943 | break;
|
---|
2944 | }
|
---|
2945 |
|
---|
2946 | case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:
|
---|
2947 | AssertFailed(); /* @todo */
|
---|
2948 | break;
|
---|
2949 |
|
---|
2950 | case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
|
---|
2951 | case SVGA3D_SURFACE_HINT_INDEXBUFFER:
|
---|
2952 | {
|
---|
2953 | uint8_t *pData;
|
---|
2954 | unsigned uDestOffset;
|
---|
2955 |
|
---|
2956 | Assert(pBoxes[i].h == 1);
|
---|
2957 |
|
---|
2958 | pState->ext.glBindBuffer(GL_ARRAY_BUFFER, pSurface->oglId.buffer);
|
---|
2959 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2960 |
|
---|
2961 | pData = (uint8_t *)pState->ext.glMapBuffer(GL_ARRAY_BUFFER, (transfer == SVGA3D_READ_HOST_VRAM) ? GL_READ_ONLY : GL_WRITE_ONLY);
|
---|
2962 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2963 | Assert(pData);
|
---|
2964 |
|
---|
2965 | uDestOffset = pBoxes[i].x * pSurface->cbBlock + pBoxes[i].y * pMipLevel->cbSurfacePitch;
|
---|
2966 | AssertReturn(uDestOffset + pBoxes[i].w * pSurface->cbBlock + (pBoxes[i].h - 1) * pMipLevel->cbSurfacePitch <= pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
|
---|
2967 |
|
---|
2968 | Log(("Lock %s memory for rectangle (%d,%d)(%d,%d)\n", (fVertex) ? "vertex" : "index", pBoxes[i].x, pBoxes[i].y, pBoxes[i].x + pBoxes[i].w, pBoxes[i].y + pBoxes[i].h));
|
---|
2969 |
|
---|
2970 | rc = vmsvgaGMRTransfer(pThis,
|
---|
2971 | transfer,
|
---|
2972 | pData + uDestOffset,
|
---|
2973 | pMipLevel->cbSurfacePitch,
|
---|
2974 | guest.ptr,
|
---|
2975 | pBoxes[i].srcx * pSurface->cbBlock + pBoxes[i].srcy * cbSrcPitch,
|
---|
2976 | cbSrcPitch,
|
---|
2977 | pBoxes[i].w * pSurface->cbBlock,
|
---|
2978 | pBoxes[i].h);
|
---|
2979 | AssertRC(rc);
|
---|
2980 |
|
---|
2981 | Log4(("first line:\n%.*Rhxd\n", cbSrcPitch, pData));
|
---|
2982 |
|
---|
2983 | pState->ext.glUnmapBuffer(GL_ARRAY_BUFFER);
|
---|
2984 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2985 |
|
---|
2986 | pState->ext.glBindBuffer(GL_ARRAY_BUFFER, 0);
|
---|
2987 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
2988 | break;
|
---|
2989 | }
|
---|
2990 |
|
---|
2991 | default:
|
---|
2992 | AssertFailed();
|
---|
2993 | break;
|
---|
2994 | }
|
---|
2995 | }
|
---|
2996 | }
|
---|
2997 | return rc;
|
---|
2998 | }
|
---|
2999 |
|
---|
3000 | int vmsvga3dSurfaceBlitToScreen(PVGASTATE pThis, uint32_t dest, SVGASignedRect destRect, SVGA3dSurfaceImageId src, SVGASignedRect srcRect, uint32_t cRects, SVGASignedRect *pRect)
|
---|
3001 | {
|
---|
3002 | /* Requires SVGA_FIFO_CAP_SCREEN_OBJECT support */
|
---|
3003 | Log(("vmsvga3dSurfaceBlitToScreen: dest=%d (%d,%d)(%d,%d) surface=%x (face=%d, mipmap=%d) (%d,%d)(%d,%d) cRects=%d\n", dest, destRect.left, destRect.top, destRect.right, destRect.bottom, src.sid, src.face, src.mipmap, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom, cRects));
|
---|
3004 | for (uint32_t i = 0; i < cRects; i++)
|
---|
3005 | {
|
---|
3006 | Log(("vmsvga3dSurfaceBlitToScreen: clipping rect %d (%d,%d)(%d,%d)\n", i, pRect[i].left, pRect[i].top, pRect[i].right, pRect[i].bottom));
|
---|
3007 | }
|
---|
3008 |
|
---|
3009 | /* @todo Only screen 0 for now. */
|
---|
3010 | AssertReturn(dest == 0, VERR_INTERNAL_ERROR);
|
---|
3011 | AssertReturn(src.mipmap == 0 && src.face == 0, VERR_INVALID_PARAMETER);
|
---|
3012 | /* @todo scaling */
|
---|
3013 | AssertReturn(destRect.right - destRect.left == srcRect.right - srcRect.left && destRect.bottom - destRect.top == srcRect.bottom - srcRect.top, VERR_INVALID_PARAMETER);
|
---|
3014 |
|
---|
3015 | if (cRects == 0)
|
---|
3016 | {
|
---|
3017 | /* easy case; no clipping */
|
---|
3018 | SVGA3dCopyBox box;
|
---|
3019 | SVGA3dGuestImage dst;
|
---|
3020 |
|
---|
3021 | box.x = destRect.left;
|
---|
3022 | box.y = destRect.top;
|
---|
3023 | box.z = 0;
|
---|
3024 | box.w = destRect.right - destRect.left;
|
---|
3025 | box.h = destRect.bottom - destRect.top;
|
---|
3026 | box.d = 1;
|
---|
3027 | box.srcx = srcRect.left;
|
---|
3028 | box.srcy = srcRect.top;
|
---|
3029 | box.srcz = 0;
|
---|
3030 |
|
---|
3031 | dst.ptr.gmrId = SVGA_GMR_FRAMEBUFFER;
|
---|
3032 | dst.ptr.offset = 0;
|
---|
3033 | dst.pitch = pThis->svga.cbScanline;
|
---|
3034 |
|
---|
3035 | int rc = vmsvga3dSurfaceDMA(pThis, dst, src, SVGA3D_READ_HOST_VRAM, 1, &box);
|
---|
3036 | AssertRCReturn(rc, rc);
|
---|
3037 |
|
---|
3038 | vgaR3UpdateDisplay(pThis, box.x, box.y, box.w, box.h);
|
---|
3039 | return VINF_SUCCESS;
|
---|
3040 | }
|
---|
3041 | else
|
---|
3042 | {
|
---|
3043 | SVGA3dGuestImage dst;
|
---|
3044 | SVGA3dCopyBox box;
|
---|
3045 |
|
---|
3046 | box.srcz = 0;
|
---|
3047 | box.z = 0;
|
---|
3048 | box.d = 1;
|
---|
3049 |
|
---|
3050 | dst.ptr.gmrId = SVGA_GMR_FRAMEBUFFER;
|
---|
3051 | dst.ptr.offset = 0;
|
---|
3052 | dst.pitch = pThis->svga.cbScanline;
|
---|
3053 |
|
---|
3054 | /* @todo merge into one SurfaceDMA call */
|
---|
3055 | for (uint32_t i = 0; i < cRects; i++)
|
---|
3056 | {
|
---|
3057 | /* The clipping rectangle is relative to the top-left corner of srcRect & destRect. Adjust here. */
|
---|
3058 | box.srcx = srcRect.left + pRect[i].left;
|
---|
3059 | box.srcy = srcRect.top + pRect[i].top;
|
---|
3060 |
|
---|
3061 | box.x = pRect[i].left + destRect.left;
|
---|
3062 | box.y = pRect[i].top + destRect.top;
|
---|
3063 | box.z = 0;
|
---|
3064 | box.w = pRect[i].right - pRect[i].left;
|
---|
3065 | box.h = pRect[i].bottom - pRect[i].top;
|
---|
3066 |
|
---|
3067 | int rc = vmsvga3dSurfaceDMA(pThis, dst, src, SVGA3D_READ_HOST_VRAM, 1, &box);
|
---|
3068 | AssertRCReturn(rc, rc);
|
---|
3069 |
|
---|
3070 | vgaR3UpdateDisplay(pThis, box.x, box.y, box.w, box.h);
|
---|
3071 | }
|
---|
3072 |
|
---|
3073 | return VINF_SUCCESS;
|
---|
3074 | }
|
---|
3075 | }
|
---|
3076 |
|
---|
3077 | int vmsvga3dGenerateMipmaps(PVGASTATE pThis, uint32_t sid, SVGA3dTextureFilter filter)
|
---|
3078 | {
|
---|
3079 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
3080 | PVMSVGA3DSURFACE pSurface;
|
---|
3081 | int rc = VINF_SUCCESS;
|
---|
3082 | PVMSVGA3DCONTEXT pContext;
|
---|
3083 | uint32_t cid;
|
---|
3084 | GLint activeTexture = 0;
|
---|
3085 |
|
---|
3086 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
3087 | AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
3088 | AssertReturn(sid < pState->cSurfaces && pState->paSurface[sid].id == sid, VERR_INVALID_PARAMETER);
|
---|
3089 |
|
---|
3090 | pSurface = &pState->paSurface[sid];
|
---|
3091 | AssertReturn(pSurface->idAssociatedContext != SVGA3D_INVALID_ID, VERR_INTERNAL_ERROR);
|
---|
3092 |
|
---|
3093 | Assert(filter != SVGA3D_TEX_FILTER_FLATCUBIC);
|
---|
3094 | Assert(filter != SVGA3D_TEX_FILTER_GAUSSIANCUBIC);
|
---|
3095 | pSurface->autogenFilter = filter;
|
---|
3096 |
|
---|
3097 | Log(("vmsvga3dGenerateMipmaps: sid=%x filter=%d\n", sid, filter));
|
---|
3098 |
|
---|
3099 | /* @todo stricter checks for associated context */
|
---|
3100 | cid = pSurface->idAssociatedContext;
|
---|
3101 |
|
---|
3102 | if ( cid >= pState->cContexts
|
---|
3103 | || pState->paContext[cid].id != cid)
|
---|
3104 | {
|
---|
3105 | Log(("vmsvga3dGenerateMipmaps invalid context id!\n"));
|
---|
3106 | return VERR_INVALID_PARAMETER;
|
---|
3107 | }
|
---|
3108 | pContext = &pState->paContext[cid];
|
---|
3109 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
3110 |
|
---|
3111 | if (pSurface->oglId.texture == OPENGL_INVALID_ID)
|
---|
3112 | {
|
---|
3113 | /* Unknown surface type; turn it into a texture. */
|
---|
3114 | Log(("vmsvga3dGenerateMipmaps: unknown src surface id=%x type=%d format=%d -> create texture\n", sid, pSurface->flags, pSurface->format));
|
---|
3115 | rc = vmsvga3dCreateTexture(pState, pContext, cid, pSurface);
|
---|
3116 | AssertRCReturn(rc, rc);
|
---|
3117 | }
|
---|
3118 | else
|
---|
3119 | {
|
---|
3120 | /* @todo new filter */
|
---|
3121 | AssertFailed();
|
---|
3122 | }
|
---|
3123 |
|
---|
3124 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
|
---|
3125 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3126 |
|
---|
3127 | /* Must bind texture to the current context in order to change it. */
|
---|
3128 | glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
|
---|
3129 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3130 |
|
---|
3131 | /* Generate the mip maps. */
|
---|
3132 | pState->ext.glGenerateMipmap(GL_TEXTURE_2D);
|
---|
3133 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3134 |
|
---|
3135 | /* Restore the old texture. */
|
---|
3136 | glBindTexture(GL_TEXTURE_2D, activeTexture);
|
---|
3137 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3138 |
|
---|
3139 | return VINF_SUCCESS;
|
---|
3140 | }
|
---|
3141 |
|
---|
3142 | int vmsvga3dCommandPresent(PVGASTATE pThis, uint32_t sid, uint32_t cRects, SVGA3dCopyRect *pRect)
|
---|
3143 | {
|
---|
3144 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
3145 | PVMSVGA3DSURFACE pSurface;
|
---|
3146 | int rc = VINF_SUCCESS;
|
---|
3147 | PVMSVGA3DCONTEXT pContext;
|
---|
3148 | uint32_t cid;
|
---|
3149 | struct
|
---|
3150 | {
|
---|
3151 | uint32_t x;
|
---|
3152 | uint32_t y;
|
---|
3153 | uint32_t cx;
|
---|
3154 | uint32_t cy;
|
---|
3155 | } srcViewPort;
|
---|
3156 |
|
---|
3157 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
3158 | AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
3159 | AssertReturn(sid < pState->cSurfaces && pState->paSurface[sid].id == sid, VERR_INVALID_PARAMETER);
|
---|
3160 |
|
---|
3161 | pSurface = &pState->paSurface[sid];
|
---|
3162 | AssertReturn(pSurface->idAssociatedContext != SVGA3D_INVALID_ID, VERR_INTERNAL_ERROR);
|
---|
3163 |
|
---|
3164 | /* @todo stricter checks for associated context */
|
---|
3165 | cid = pSurface->idAssociatedContext;
|
---|
3166 | Log(("vmsvga3dCommandPresent: sid=%x cRects=%d cid=%x\n", sid, cRects, cid));
|
---|
3167 | for (uint32_t i=0; i < cRects; i++)
|
---|
3168 | {
|
---|
3169 | Log(("vmsvga3dCommandPresent: rectangle %d src=(%d,%d) (%d,%d)(%d,%d)\n", i, pRect[i].srcx, pRect[i].srcy, pRect[i].x, pRect[i].y, pRect[i].x + pRect[i].w, pRect[i].y + pRect[i].h));
|
---|
3170 | }
|
---|
3171 |
|
---|
3172 | if ( cid >= pState->cContexts
|
---|
3173 | || pState->paContext[cid].id != cid)
|
---|
3174 | {
|
---|
3175 | Log(("vmsvga3dCommandPresent invalid context id!\n"));
|
---|
3176 | return VERR_INVALID_PARAMETER;
|
---|
3177 | }
|
---|
3178 | pContext = &pState->paContext[cid];
|
---|
3179 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
3180 |
|
---|
3181 | /* Source surface different size? */
|
---|
3182 | if (pSurface->pMipmapLevels[0].size.width != pThis->svga.uWidth ||
|
---|
3183 | pSurface->pMipmapLevels[0].size.height != pThis->svga.uHeight)
|
---|
3184 | {
|
---|
3185 | float xMultiplier = (float)pSurface->pMipmapLevels[0].size.width / (float)pThis->svga.uWidth;
|
---|
3186 | float yMultiplier = (float)pSurface->pMipmapLevels[0].size.height / (float)pThis->svga.uHeight;
|
---|
3187 |
|
---|
3188 | LogFlow(("size (%d vs %d) (%d vs %d) multiplier %d\n", pSurface->pMipmapLevels[0].size.width, pThis->svga.uWidth, pSurface->pMipmapLevels[0].size.height, pThis->svga.uHeight, (int)(xMultiplier * 100.0), (int)(yMultiplier * 100.0)));
|
---|
3189 |
|
---|
3190 | srcViewPort.x = (uint32_t)((float)pThis->svga.viewport.x * xMultiplier);
|
---|
3191 | srcViewPort.y = (uint32_t)((float)pThis->svga.viewport.y * yMultiplier);
|
---|
3192 | srcViewPort.cx = (uint32_t)((float)pThis->svga.viewport.cx * xMultiplier);
|
---|
3193 | srcViewPort.cy = (uint32_t)((float)pThis->svga.viewport.cy * yMultiplier);
|
---|
3194 | }
|
---|
3195 | else
|
---|
3196 | {
|
---|
3197 | srcViewPort.x = pThis->svga.viewport.x;
|
---|
3198 | srcViewPort.y = pThis->svga.viewport.y;
|
---|
3199 | srcViewPort.cx = pThis->svga.viewport.cx;
|
---|
3200 | srcViewPort.cy = pThis->svga.viewport.cy;
|
---|
3201 | }
|
---|
3202 |
|
---|
3203 | #if 1
|
---|
3204 | /* @note this path is slightly faster than the glBlitFrameBuffer path below. */
|
---|
3205 | SVGA3dCopyRect rect;
|
---|
3206 | uint32_t oldVShader, oldPShader;
|
---|
3207 | GLint oldTextureId;
|
---|
3208 |
|
---|
3209 | if (cRects == 0)
|
---|
3210 | {
|
---|
3211 | rect.x = rect.y = rect.srcx = rect.srcy = 0;
|
---|
3212 | rect.w = pSurface->pMipmapLevels[0].size.width;
|
---|
3213 | rect.h = pSurface->pMipmapLevels[0].size.height;
|
---|
3214 | pRect = ▭
|
---|
3215 | cRects = 1;
|
---|
3216 | }
|
---|
3217 |
|
---|
3218 | //glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT);
|
---|
3219 |
|
---|
3220 | #if 0
|
---|
3221 | glDisable(GL_CULL_FACE);
|
---|
3222 | glDisable(GL_BLEND);
|
---|
3223 | glDisable(GL_ALPHA_TEST);
|
---|
3224 | glDisable(GL_SCISSOR_TEST);
|
---|
3225 | glDisable(GL_STENCIL_TEST);
|
---|
3226 | glEnable(GL_DEPTH_TEST);
|
---|
3227 | glDepthFunc(GL_ALWAYS);
|
---|
3228 | glDepthMask(GL_TRUE);
|
---|
3229 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
---|
3230 | glViewport(0, 0, pSurface->pMipmapLevels[0].size.width, pSurface->pMipmapLevels[0].size.height);
|
---|
3231 | #endif
|
---|
3232 |
|
---|
3233 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTextureId);
|
---|
3234 |
|
---|
3235 | oldVShader = pContext->state.shidVertex;
|
---|
3236 | oldPShader = pContext->state.shidPixel;
|
---|
3237 | vmsvga3dShaderSet(pThis, cid, SVGA3D_SHADERTYPE_VS, SVGA_ID_INVALID);
|
---|
3238 | vmsvga3dShaderSet(pThis, cid, SVGA3D_SHADERTYPE_PS, SVGA_ID_INVALID);
|
---|
3239 |
|
---|
3240 | /* Flush shader changes. */
|
---|
3241 | if (pContext->pShaderContext)
|
---|
3242 | ShaderUpdateState(pContext->pShaderContext, 0);
|
---|
3243 |
|
---|
3244 | /* Activate the read and draw framebuffer objects. */
|
---|
3245 | pState->ext.glBindFramebuffer(GL_READ_FRAMEBUFFER, pContext->idReadFramebuffer);
|
---|
3246 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3247 | pState->ext.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0 /* back buffer */);
|
---|
3248 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3249 |
|
---|
3250 | pState->ext.glActiveTexture(GL_TEXTURE0);
|
---|
3251 | glEnable(GL_TEXTURE_2D);
|
---|
3252 | glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
|
---|
3253 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3254 |
|
---|
3255 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
---|
3256 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
---|
3257 |
|
---|
3258 | // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
---|
3259 | // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
---|
3260 |
|
---|
3261 | /* Reset the transformation matrices. */
|
---|
3262 | glMatrixMode(GL_MODELVIEW);
|
---|
3263 | glPushMatrix();
|
---|
3264 | glLoadIdentity();
|
---|
3265 | glMatrixMode(GL_PROJECTION);
|
---|
3266 | glPushMatrix();
|
---|
3267 | glLoadIdentity();
|
---|
3268 | glScalef(1.0f, -1.0f, 1.0f);
|
---|
3269 | glOrtho(0, pThis->svga.uWidth, pThis->svga.uHeight, 0, 0.0, -1.0);
|
---|
3270 |
|
---|
3271 | for (uint32_t i = 0; i < cRects; i++)
|
---|
3272 | {
|
---|
3273 | float left, right, top, bottom; /* Texture coordinates */
|
---|
3274 | int vertexLeft, vertexRight, vertexTop, vertexBottom;
|
---|
3275 |
|
---|
3276 | pRect[i].srcx = RT_MAX(pRect[i].srcx, srcViewPort.x);
|
---|
3277 | pRect[i].srcy = RT_MAX(pRect[i].srcy, srcViewPort.y);
|
---|
3278 | pRect[i].x = RT_MAX(pRect[i].x, pThis->svga.viewport.x) - pThis->svga.viewport.x;
|
---|
3279 | pRect[i].y = RT_MAX(pRect[i].y, pThis->svga.viewport.y) - pThis->svga.viewport.y;
|
---|
3280 | pRect[i].w = pThis->svga.viewport.cx;
|
---|
3281 | pRect[i].h = pThis->svga.viewport.cy;
|
---|
3282 |
|
---|
3283 | if ( pRect[i].x + pRect[i].w <= pThis->svga.viewport.x
|
---|
3284 | || pThis->svga.viewport.x + pThis->svga.viewport.cx <= pRect[i].x
|
---|
3285 | || pRect[i].y + pRect[i].h <= pThis->svga.viewport.y
|
---|
3286 | || pThis->svga.viewport.y + pThis->svga.viewport.cy <= pRect[i].y)
|
---|
3287 | {
|
---|
3288 | /* Intersection is empty; skip */
|
---|
3289 | continue;
|
---|
3290 | }
|
---|
3291 |
|
---|
3292 | left = pRect[i].srcx;
|
---|
3293 | right = pRect[i].srcx + pRect[i].w;
|
---|
3294 | top = pRect[i].srcy + pRect[i].h;
|
---|
3295 | bottom = pRect[i].srcy;
|
---|
3296 |
|
---|
3297 | left /= pSurface->pMipmapLevels[0].size.width;
|
---|
3298 | right /= pSurface->pMipmapLevels[0].size.width;
|
---|
3299 | top /= pSurface->pMipmapLevels[0].size.height;
|
---|
3300 | bottom /= pSurface->pMipmapLevels[0].size.height;
|
---|
3301 |
|
---|
3302 | vertexLeft = pRect[i].x;
|
---|
3303 | vertexRight = pRect[i].x + pRect[i].w;
|
---|
3304 | vertexTop = ((uint32_t)pThis->svga.uHeight >= pRect[i].y + pRect[i].h) ? pThis->svga.uHeight - pRect[i].y - pRect[i].h : 0;
|
---|
3305 | vertexBottom = pThis->svga.uHeight - pRect[i].y;
|
---|
3306 |
|
---|
3307 | Log(("view port (%d,%d)(%d,%d)\n", srcViewPort.x, srcViewPort.y, srcViewPort.cx, srcViewPort.cy));
|
---|
3308 | Log(("vertex (%d,%d) (%d,%d) (%d,%d) (%d,%d)\n", vertexLeft, vertexBottom, vertexLeft, vertexTop, vertexRight, vertexTop, vertexRight, vertexBottom));
|
---|
3309 | Log(("texture (%d,%d) (%d,%d) (%d,%d) (%d,%d)\n", pRect[i].srcx, pSurface->pMipmapLevels[0].size.height - (pRect[i].srcy + pRect[i].h), pRect[i].srcx, pSurface->pMipmapLevels[0].size.height - pRect[i].srcy, pRect[i].srcx + pRect[i].w, pSurface->pMipmapLevels[0].size.height - pRect[i].srcy, pRect[i].srcx + pRect[i].w, pSurface->pMipmapLevels[0].size.height - (pRect[i].srcy + pRect[i].h)));
|
---|
3310 |
|
---|
3311 | glBegin(GL_QUADS);
|
---|
3312 | /* bottom left */
|
---|
3313 | glTexCoord2f(left, bottom);
|
---|
3314 | glVertex2i(vertexLeft, vertexBottom);
|
---|
3315 |
|
---|
3316 | /* top left */
|
---|
3317 | glTexCoord2f(left, top);
|
---|
3318 | glVertex2i(vertexLeft, vertexTop);
|
---|
3319 |
|
---|
3320 | /* top right */
|
---|
3321 | glTexCoord2f(right, top);
|
---|
3322 | glVertex2i(vertexRight, vertexTop);
|
---|
3323 |
|
---|
3324 | /* bottom right */
|
---|
3325 | glTexCoord2f(right, bottom);
|
---|
3326 | glVertex2i(vertexRight, vertexBottom);
|
---|
3327 |
|
---|
3328 | glEnd();
|
---|
3329 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3330 | }
|
---|
3331 |
|
---|
3332 | /* Restore old settings. */
|
---|
3333 | glMatrixMode(GL_PROJECTION);
|
---|
3334 | glPopMatrix();
|
---|
3335 | glMatrixMode(GL_MODELVIEW);
|
---|
3336 | glPopMatrix();
|
---|
3337 |
|
---|
3338 | //glPopAttrib();
|
---|
3339 |
|
---|
3340 | glBindTexture(GL_TEXTURE_2D, oldTextureId);
|
---|
3341 | vmsvga3dShaderSet(pThis, cid, SVGA3D_SHADERTYPE_VS, oldVShader);
|
---|
3342 | vmsvga3dShaderSet(pThis, cid, SVGA3D_SHADERTYPE_PS, oldPShader);
|
---|
3343 |
|
---|
3344 | /* Reset the frame buffer association */
|
---|
3345 | pState->ext.glBindFramebuffer(GL_FRAMEBUFFER, pContext->idFramebuffer);
|
---|
3346 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3347 |
|
---|
3348 | #else
|
---|
3349 | /* Activate the read and draw framebuffer objects. */
|
---|
3350 | pState->ext.glBindFramebuffer(GL_READ_FRAMEBUFFER, pContext->idReadFramebuffer);
|
---|
3351 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
3352 | pState->ext.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0 /* back buffer */);
|
---|
3353 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
3354 |
|
---|
3355 | /* Bind the source objects to the right place. */
|
---|
3356 | pState->ext.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pSurface->oglId.texture, 0 /* level 0 */);
|
---|
3357 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
3358 |
|
---|
3359 | /* Blit the surface rectangle(s) to the back buffer. */
|
---|
3360 | if (cRects == 0)
|
---|
3361 | {
|
---|
3362 | Log(("view port (%d,%d)(%d,%d)\n", srcViewPort.x, srcViewPort.y, srcViewPort.cx, srcViewPort.cy));
|
---|
3363 | pState->ext.glBlitFramebuffer(srcViewPort.x,
|
---|
3364 | srcViewPort.y,
|
---|
3365 | srcViewPort.x + srcViewPort.cx, /* exclusive. */
|
---|
3366 | srcViewPort.y + srcViewPort.cy, /* exclusive. (reverse to flip the image) */
|
---|
3367 | 0,
|
---|
3368 | pThis->svga.viewport.cy, /* exclusive. */
|
---|
3369 | pThis->svga.viewport.cx, /* exclusive. */
|
---|
3370 | 0,
|
---|
3371 | GL_COLOR_BUFFER_BIT,
|
---|
3372 | GL_LINEAR);
|
---|
3373 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
3374 | }
|
---|
3375 | else
|
---|
3376 | {
|
---|
3377 | for (uint32_t i = 0; i < cRects; i++)
|
---|
3378 | {
|
---|
3379 | if ( pRect[i].x + pRect[i].w <= pThis->svga.viewport.x
|
---|
3380 | || pThis->svga.viewport.x + pThis->svga.viewport.cx <= pRect[i].x
|
---|
3381 | || pRect[i].y + pRect[i].h <= pThis->svga.viewport.y
|
---|
3382 | || pThis->svga.viewport.y + pThis->svga.viewport.cy <= pRect[i].y)
|
---|
3383 | {
|
---|
3384 | /* Intersection is empty; skip */
|
---|
3385 | continue;
|
---|
3386 | }
|
---|
3387 |
|
---|
3388 | pState->ext.glBlitFramebuffer(RT_MAX(pRect[i].srcx, srcViewPort.x),
|
---|
3389 | pSurface->pMipmapLevels[0].size.width - RT_MAX(pRect[i].srcy, srcViewPort.y), /* exclusive. (reverse to flip the image) */
|
---|
3390 | RT_MIN(pRect[i].srcx + pRect[i].w, srcViewPort.x + srcViewPort.cx), /* exclusive. */
|
---|
3391 | pSurface->pMipmapLevels[0].size.width - RT_MIN(pRect[i].srcy + pRect[i].h, srcViewPort.y + srcViewPort.cy),
|
---|
3392 | RT_MAX(pRect[i].x, pThis->svga.viewport.x) - pThis->svga.viewport.x,
|
---|
3393 | pThis->svga.uHeight - (RT_MIN(pRect[i].y + pRect[i].h, pThis->svga.viewport.y + pThis->svga.viewport.cy) - pThis->svga.viewport.y), /* exclusive. */
|
---|
3394 | RT_MIN(pRect[i].x + pRect[i].w, pThis->svga.viewport.x + pThis->svga.viewport.cx) - pThis->svga.viewport.x, /* exclusive. */
|
---|
3395 | pThis->svga.uHeight - (RT_MAX(pRect[i].y, pThis->svga.viewport.y) - pThis->svga.viewport.y),
|
---|
3396 | GL_COLOR_BUFFER_BIT,
|
---|
3397 | GL_LINEAR);
|
---|
3398 | }
|
---|
3399 | }
|
---|
3400 | /* Reset the frame buffer association */
|
---|
3401 | pState->ext.glBindFramebuffer(GL_FRAMEBUFFER, pContext->idFramebuffer);
|
---|
3402 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
3403 | #endif
|
---|
3404 |
|
---|
3405 | /* Flip the front and back buffers. */
|
---|
3406 | #ifdef RT_OS_WINDOWS
|
---|
3407 | BOOL ret = SwapBuffers(pContext->hdc);
|
---|
3408 | AssertMsg(ret, ("SwapBuffers failed with %d\n", GetLastError()));
|
---|
3409 | #elif defined(RT_OS_DARWIN)
|
---|
3410 | vmsvga3dCocoaSwapBuffers(pContext->cocoaView, pContext->cocoaContext);
|
---|
3411 | #else
|
---|
3412 | /* show the window if not already done */
|
---|
3413 | if (!pContext->fMapped)
|
---|
3414 | {
|
---|
3415 | XMapWindow(pState->display, pContext->window);
|
---|
3416 | pContext->fMapped = true;
|
---|
3417 | }
|
---|
3418 | /* now swap the buffers, i.e. display the rendering result */
|
---|
3419 | glXSwapBuffers(pState->display, pContext->window);
|
---|
3420 | #endif
|
---|
3421 | return VINF_SUCCESS;
|
---|
3422 | }
|
---|
3423 |
|
---|
3424 | #ifdef RT_OS_LINUX
|
---|
3425 | /**
|
---|
3426 | * X11 event handling thread
|
---|
3427 | * @param ThreadSelf thread handle
|
---|
3428 | * @param pvUser pointer to pState structure
|
---|
3429 | * @returns VBox status code
|
---|
3430 | */
|
---|
3431 | DECLCALLBACK(int) vmsvga3dXEventThread(RTTHREAD ThreadSelf, void *pvUser)
|
---|
3432 | {
|
---|
3433 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pvUser;
|
---|
3434 | while (!pState->bTerminate)
|
---|
3435 | {
|
---|
3436 | while (XPending(pState->display) > 0)
|
---|
3437 | {
|
---|
3438 | XEvent event;
|
---|
3439 | XNextEvent(pState->display, &event);
|
---|
3440 |
|
---|
3441 | switch (event.type)
|
---|
3442 | {
|
---|
3443 | default:
|
---|
3444 | break;
|
---|
3445 | }
|
---|
3446 | }
|
---|
3447 | /* sleep for 16ms to not burn too many cycles */
|
---|
3448 | RTThreadSleep(16);
|
---|
3449 | }
|
---|
3450 | return VINF_SUCCESS;
|
---|
3451 | }
|
---|
3452 | #endif // RT_OS_LINUX
|
---|
3453 |
|
---|
3454 |
|
---|
3455 | /**
|
---|
3456 | * Create a new 3d context
|
---|
3457 | *
|
---|
3458 | * @returns VBox status code.
|
---|
3459 | * @param pThis VGA device instance data.
|
---|
3460 | * @param cid Context id
|
---|
3461 | * @param fOtherProfile When clear, the context is created using the default
|
---|
3462 | * OpenGL profile. When set, it's created using the
|
---|
3463 | * alternative profile. The latter is only allowed if
|
---|
3464 | * the VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE is set.
|
---|
3465 | */
|
---|
3466 | int vmsvga3dContextDefine(PVGASTATE pThis, uint32_t cid, bool fOtherProfile)
|
---|
3467 | {
|
---|
3468 | int rc;
|
---|
3469 | PVMSVGA3DCONTEXT pContext;
|
---|
3470 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
3471 |
|
---|
3472 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
3473 | AssertReturn(cid < SVGA3D_MAX_CONTEXT_IDS, VERR_INVALID_PARAMETER);
|
---|
3474 | #if !defined(VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE) || !(defined(RT_OS_DARWIN))
|
---|
3475 | AssertReturn(!fOtherProfile, VERR_INTERNAL_ERROR_3);
|
---|
3476 | #endif
|
---|
3477 |
|
---|
3478 | Log(("vmsvga3dContextDefine id %x\n", cid));
|
---|
3479 | #ifdef DEBUG_DEBUG_GFX_WINDOW_TEST_CONTEXT
|
---|
3480 | if (pState->idTestContext == SVGA_ID_INVALID)
|
---|
3481 | {
|
---|
3482 | pState->idTestContext = 207;
|
---|
3483 | rc = vmsvga3dContextDefine(pThis, pState->idTestContext, false /*fOtherProfile*/);
|
---|
3484 | AssertRCReturn(rc, rc);
|
---|
3485 | }
|
---|
3486 | #endif
|
---|
3487 |
|
---|
3488 | if (cid >= pState->cContexts)
|
---|
3489 | {
|
---|
3490 | pState->paContext = (PVMSVGA3DCONTEXT)RTMemRealloc(pState->paContext, sizeof(VMSVGA3DCONTEXT) * (cid + 1));
|
---|
3491 | AssertReturn(pState->paContext, VERR_NO_MEMORY);
|
---|
3492 | memset(&pState->paContext[pState->cContexts], 0, sizeof(VMSVGA3DCONTEXT) * (cid + 1 - pState->cContexts));
|
---|
3493 | for (uint32_t i = pState->cContexts; i < cid + 1; i++)
|
---|
3494 | pState->paContext[i].id = SVGA3D_INVALID_ID;
|
---|
3495 |
|
---|
3496 | pState->cContexts = cid + 1;
|
---|
3497 | }
|
---|
3498 | /* If one already exists with this id, then destroy it now. */
|
---|
3499 | if (pState->paContext[cid].id != SVGA3D_INVALID_ID)
|
---|
3500 | vmsvga3dContextDestroy(pThis, cid);
|
---|
3501 |
|
---|
3502 | pContext = &pState->paContext[cid];
|
---|
3503 | memset(pContext, 0, sizeof(*pContext));
|
---|
3504 | pContext->id = cid;
|
---|
3505 | for (uint32_t i = 0; i < RT_ELEMENTS(pContext->aSidActiveTexture); i++)
|
---|
3506 | pContext->aSidActiveTexture[i] = SVGA3D_INVALID_ID;
|
---|
3507 |
|
---|
3508 | pContext->sidRenderTarget = SVGA3D_INVALID_ID;
|
---|
3509 | pContext->state.shidVertex = SVGA3D_INVALID_ID;
|
---|
3510 | pContext->state.shidPixel = SVGA3D_INVALID_ID;
|
---|
3511 | pContext->idFramebuffer = OPENGL_INVALID_ID;
|
---|
3512 | pContext->idReadFramebuffer = OPENGL_INVALID_ID;
|
---|
3513 | pContext->idDrawFramebuffer = OPENGL_INVALID_ID;
|
---|
3514 |
|
---|
3515 | rc = ShaderContextCreate(&pContext->pShaderContext);
|
---|
3516 | AssertRCReturn(rc, rc);
|
---|
3517 |
|
---|
3518 | for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aRenderTargets); i++)
|
---|
3519 | pContext->state.aRenderTargets[i] = SVGA3D_INVALID_ID;
|
---|
3520 |
|
---|
3521 | AssertReturn(pThis->svga.u64HostWindowId, VERR_INTERNAL_ERROR);
|
---|
3522 |
|
---|
3523 | #ifdef RT_OS_WINDOWS
|
---|
3524 | /* Create a context window. */
|
---|
3525 | CREATESTRUCT cs;
|
---|
3526 | cs.lpCreateParams = NULL;
|
---|
3527 | cs.dwExStyle = WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY | WS_EX_TRANSPARENT;
|
---|
3528 | # ifdef DEBUG_GFX_WINDOW
|
---|
3529 | cs.lpszName = (char *)RTMemAllocZ(256);
|
---|
3530 | RTStrPrintf((char *)cs.lpszName, 256, "Context %d OpenGL Window", cid);
|
---|
3531 | # else
|
---|
3532 | cs.lpszName = NULL;
|
---|
3533 | # endif
|
---|
3534 | cs.lpszClass = 0;
|
---|
3535 | # ifdef DEBUG_GFX_WINDOW
|
---|
3536 | cs.style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | WS_CAPTION;
|
---|
3537 | # else
|
---|
3538 | cs.style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_DISABLED | WS_CHILD | WS_VISIBLE;
|
---|
3539 | # endif
|
---|
3540 | cs.x = 0;
|
---|
3541 | cs.y = 0;
|
---|
3542 | cs.cx = pThis->svga.uWidth;
|
---|
3543 | cs.cy = pThis->svga.uHeight;
|
---|
3544 | cs.hwndParent = (HWND)pThis->svga.u64HostWindowId;
|
---|
3545 | cs.hMenu = NULL;
|
---|
3546 | cs.hInstance = pState->hInstance;
|
---|
3547 |
|
---|
3548 | rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_CREATEWINDOW, (WPARAM)&pContext->hwnd, (LPARAM)&cs);
|
---|
3549 | AssertRCReturn(rc, rc);
|
---|
3550 |
|
---|
3551 | pContext->hdc = GetDC(pContext->hwnd);
|
---|
3552 | AssertMsgReturn(pContext->hdc, ("GetDC %x failed with %d\n", pContext->hwnd, GetLastError()), VERR_INTERNAL_ERROR);
|
---|
3553 |
|
---|
3554 | PIXELFORMATDESCRIPTOR pfd = {
|
---|
3555 | sizeof(PIXELFORMATDESCRIPTOR), /* size of this pfd */
|
---|
3556 | 1, /* version number */
|
---|
3557 | PFD_DRAW_TO_WINDOW | /* support window */
|
---|
3558 | PFD_DOUBLEBUFFER | /* support double buffering */
|
---|
3559 | PFD_SUPPORT_OPENGL, /* support OpenGL */
|
---|
3560 | PFD_TYPE_RGBA, /* RGBA type */
|
---|
3561 | 24, /* 24-bit color depth */
|
---|
3562 | 0, 0, 0, 0, 0, 0, /* color bits ignored */
|
---|
3563 | 8, /* alpha buffer */
|
---|
3564 | 0, /* shift bit ignored */
|
---|
3565 | 0, /* no accumulation buffer */
|
---|
3566 | 0, 0, 0, 0, /* accum bits ignored */
|
---|
3567 | 16, /* set depth buffer */
|
---|
3568 | 16, /* set stencil buffer */
|
---|
3569 | 0, /* no auxiliary buffer */
|
---|
3570 | PFD_MAIN_PLANE, /* main layer */
|
---|
3571 | 0, /* reserved */
|
---|
3572 | 0, 0, 0 /* layer masks ignored */
|
---|
3573 | };
|
---|
3574 | int pixelFormat;
|
---|
3575 | BOOL ret;
|
---|
3576 |
|
---|
3577 | pixelFormat = ChoosePixelFormat(pContext->hdc, &pfd);
|
---|
3578 | /* @todo is this really necessary?? */
|
---|
3579 | pixelFormat = ChoosePixelFormat(pContext->hdc, &pfd);
|
---|
3580 | AssertMsgReturn(pixelFormat != 0, ("ChoosePixelFormat failed with %d\n", GetLastError()), VERR_INTERNAL_ERROR);
|
---|
3581 |
|
---|
3582 | ret = SetPixelFormat(pContext->hdc, pixelFormat, &pfd);
|
---|
3583 | AssertMsgReturn(ret == TRUE, ("SetPixelFormat failed with %d\n", GetLastError()), VERR_INTERNAL_ERROR);
|
---|
3584 |
|
---|
3585 | pContext->hglrc = wglCreateContext(pContext->hdc);
|
---|
3586 | AssertMsgReturn(pContext->hglrc, ("wglCreateContext %x failed with %d\n", pContext->hdc, GetLastError()), VERR_INTERNAL_ERROR);
|
---|
3587 |
|
---|
3588 | // TODO isn't this default on Linux since OpenGL 1.1?
|
---|
3589 | /* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
|
---|
3590 | for (uint32_t i = 0; i < pState->cContexts; i++)
|
---|
3591 | {
|
---|
3592 | if ( pState->paContext[i].id != SVGA3D_INVALID_ID
|
---|
3593 | && i != pContext->id)
|
---|
3594 | {
|
---|
3595 | Log(("Sharing display lists between cid=%d and cid=%d\n", pContext->id, i));
|
---|
3596 | ret = wglShareLists(pState->paContext[i].hglrc, pContext->hglrc);
|
---|
3597 | Assert(ret == TRUE);
|
---|
3598 | break;
|
---|
3599 | }
|
---|
3600 | }
|
---|
3601 |
|
---|
3602 | #elif defined(RT_OS_DARWIN)
|
---|
3603 | pContext->fOtherProfile = fOtherProfile;
|
---|
3604 |
|
---|
3605 | /* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
|
---|
3606 | NativeNSOpenGLContextRef shareContext = NULL;
|
---|
3607 | for (uint32_t i = 0; i < pState->cContexts; i++)
|
---|
3608 | {
|
---|
3609 | if ( pState->paContext[i].id != SVGA3D_INVALID_ID
|
---|
3610 | && i != pContext->id
|
---|
3611 | && pState->paContext[i].fOtherProfile == fOtherProfile)
|
---|
3612 | {
|
---|
3613 | Log(("Sharing display lists between cid=%d and cid=%d\n", pContext->id, i));
|
---|
3614 | shareContext = pState->paContext[i].cocoaContext;
|
---|
3615 | break;
|
---|
3616 | }
|
---|
3617 | }
|
---|
3618 | vmsvga3dCocoaCreateContext(&pContext->cocoaContext, shareContext, fOtherProfile);
|
---|
3619 | NativeNSViewRef pHostView = (NativeNSViewRef)pThis->svga.u64HostWindowId;
|
---|
3620 | vmsvga3dCocoaCreateView(&pContext->cocoaView, pHostView);
|
---|
3621 |
|
---|
3622 | #else
|
---|
3623 | Window hostWindow = (Window)pThis->svga.u64HostWindowId;
|
---|
3624 |
|
---|
3625 | if (pState->display == NULL)
|
---|
3626 | {
|
---|
3627 | /* get an X display and make sure we have glX 1.3 */
|
---|
3628 | pState->display = XOpenDisplay(0);
|
---|
3629 | Assert(pState->display);
|
---|
3630 | int glxMajor, glxMinor;
|
---|
3631 | Bool ret = glXQueryVersion(pState->display, &glxMajor, &glxMinor);
|
---|
3632 | AssertMsgReturn(ret && glxMajor == 1 && glxMinor >= 3, ("glX >=1.3 not present"), VERR_INTERNAL_ERROR);
|
---|
3633 | /* start our X event handling thread */
|
---|
3634 | rc = RTThreadCreate(&pState->pWindowThread, vmsvga3dXEventThread, pState, 0, RTTHREADTYPE_GUI, RTTHREADFLAGS_WAITABLE, "VMSVGA3DXEVENT");
|
---|
3635 | if (RT_FAILURE(rc))
|
---|
3636 | {
|
---|
3637 | AssertMsgFailed(("%s: Async IO Thread creation for 3d window handling failed rc=%d\n", __FUNCTION__, rc));
|
---|
3638 | return rc;
|
---|
3639 | }
|
---|
3640 | }
|
---|
3641 | int attrib[] =
|
---|
3642 | {
|
---|
3643 | GLX_RGBA,
|
---|
3644 | GLX_RED_SIZE, 1,
|
---|
3645 | GLX_GREEN_SIZE, 1,
|
---|
3646 | GLX_BLUE_SIZE, 1,
|
---|
3647 | //GLX_ALPHA_SIZE, 1, this flips the bbos screen
|
---|
3648 | GLX_DOUBLEBUFFER,
|
---|
3649 | None
|
---|
3650 | };
|
---|
3651 | XVisualInfo *vi = glXChooseVisual(pState->display, DefaultScreen(pState->display), attrib);
|
---|
3652 | XSetWindowAttributes swa;
|
---|
3653 | swa.colormap = XCreateColormap(pState->display, XDefaultRootWindow(pState->display), vi->visual, AllocNone);
|
---|
3654 | swa.border_pixel = 0;
|
---|
3655 | swa.background_pixel = 0;
|
---|
3656 | swa.event_mask = StructureNotifyMask | ExposureMask;
|
---|
3657 | unsigned long flags = CWBorderPixel | CWBackPixel | CWColormap | CWEventMask;
|
---|
3658 | pContext->window = XCreateWindow(pState->display, hostWindow,//XDefaultRootWindow(pState->display),//hostWindow,
|
---|
3659 | 0, 0, pThis->svga.uWidth, pThis->svga.uHeight,
|
---|
3660 | 0, vi->depth, InputOutput,
|
---|
3661 | vi->visual, flags, &swa);
|
---|
3662 | AssertMsgReturn(pContext->window, ("XCreateWindow failed"), VERR_INTERNAL_ERROR);
|
---|
3663 | uint32_t cardinal_alpha = (uint32_t) (0.5 * (uint32_t)-1) ;
|
---|
3664 |
|
---|
3665 | /* the window is hidden by default and only mapped when CommandPresent is executed on it */
|
---|
3666 |
|
---|
3667 | /* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
|
---|
3668 | GLXContext shareContext = NULL;
|
---|
3669 | for (uint32_t i = 0; i < pState->cContexts; i++)
|
---|
3670 | {
|
---|
3671 | if ( pState->paContext[i].id != SVGA3D_INVALID_ID
|
---|
3672 | && i != pContext->id)
|
---|
3673 | {
|
---|
3674 | Log(("Sharing display lists between cid=%d and cid=%d\n", pContext->id, i));
|
---|
3675 | shareContext = pState->paContext[i].glxContext;
|
---|
3676 | break;
|
---|
3677 | }
|
---|
3678 | }
|
---|
3679 |
|
---|
3680 | pContext->glxContext = glXCreateContext(pState->display, vi, shareContext, GL_TRUE);
|
---|
3681 | AssertMsgReturn(pContext->glxContext, ("glXCreateContext failed"), VERR_INTERNAL_ERROR);
|
---|
3682 | #endif
|
---|
3683 |
|
---|
3684 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
3685 |
|
---|
3686 | /* NULL during the first PowerOn call. */
|
---|
3687 | if (pState->ext.glGenFramebuffers)
|
---|
3688 | {
|
---|
3689 | /* Create a framebuffer object for this context. */
|
---|
3690 | pState->ext.glGenFramebuffers(1, &pContext->idFramebuffer);
|
---|
3691 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3692 |
|
---|
3693 | /* Bind the object to the framebuffer target. */
|
---|
3694 | pState->ext.glBindFramebuffer(GL_FRAMEBUFFER, pContext->idFramebuffer);
|
---|
3695 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3696 |
|
---|
3697 | /* Create read and draw framebuffer objects for this context. */
|
---|
3698 | pState->ext.glGenFramebuffers(1, &pContext->idReadFramebuffer);
|
---|
3699 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3700 |
|
---|
3701 | pState->ext.glGenFramebuffers(1, &pContext->idDrawFramebuffer);
|
---|
3702 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3703 |
|
---|
3704 | }
|
---|
3705 | #if 0
|
---|
3706 | /* @todo move to shader lib!!! */
|
---|
3707 | /* Clear the screen */
|
---|
3708 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
3709 |
|
---|
3710 | glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
|
---|
3711 | glClearIndex(0);
|
---|
3712 | glClearDepth(1);
|
---|
3713 | glClearStencil(0xffff);
|
---|
3714 | glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
|
---|
3715 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
|
---|
3716 | glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
|
---|
3717 | if (pState->ext.glProvokingVertex)
|
---|
3718 | pState->ext.glProvokingVertex(GL_FIRST_VERTEX_CONVENTION);
|
---|
3719 | /* @todo move to shader lib!!! */
|
---|
3720 | #endif
|
---|
3721 | return VINF_SUCCESS;
|
---|
3722 | }
|
---|
3723 |
|
---|
3724 | /**
|
---|
3725 | * Destroy an existing 3d context
|
---|
3726 | *
|
---|
3727 | * @returns VBox status code.
|
---|
3728 | * @param pThis VGA device instance data.
|
---|
3729 | * @param cid Context id
|
---|
3730 | */
|
---|
3731 | int vmsvga3dContextDestroy(PVGASTATE pThis, uint32_t cid)
|
---|
3732 | {
|
---|
3733 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
3734 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
3735 |
|
---|
3736 | AssertReturn(cid < SVGA3D_MAX_CONTEXT_IDS, VERR_INVALID_PARAMETER);
|
---|
3737 |
|
---|
3738 | if ( cid < pState->cContexts
|
---|
3739 | && pState->paContext[cid].id == cid)
|
---|
3740 | {
|
---|
3741 | PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
|
---|
3742 |
|
---|
3743 | Log(("vmsvga3dContextDestroy id %x\n", cid));
|
---|
3744 |
|
---|
3745 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
3746 |
|
---|
3747 | /* Destroy all leftover pixel shaders. */
|
---|
3748 | for (uint32_t i = 0; i < pContext->cPixelShaders; i++)
|
---|
3749 | {
|
---|
3750 | if (pContext->paPixelShader[i].id != SVGA3D_INVALID_ID)
|
---|
3751 | vmsvga3dShaderDestroy(pThis, pContext->paPixelShader[i].cid, pContext->paPixelShader[i].id, pContext->paPixelShader[i].type);
|
---|
3752 | }
|
---|
3753 | if (pContext->paPixelShader)
|
---|
3754 | RTMemFree(pContext->paPixelShader);
|
---|
3755 |
|
---|
3756 | /* Destroy all leftover vertex shaders. */
|
---|
3757 | for (uint32_t i = 0; i < pContext->cVertexShaders; i++)
|
---|
3758 | {
|
---|
3759 | if (pContext->paVertexShader[i].id != SVGA3D_INVALID_ID)
|
---|
3760 | vmsvga3dShaderDestroy(pThis, pContext->paVertexShader[i].cid, pContext->paVertexShader[i].id, pContext->paVertexShader[i].type);
|
---|
3761 | }
|
---|
3762 | if (pContext->paVertexShader)
|
---|
3763 | RTMemFree(pContext->paVertexShader);
|
---|
3764 |
|
---|
3765 | if (pContext->state.paVertexShaderConst)
|
---|
3766 | RTMemFree(pContext->state.paVertexShaderConst);
|
---|
3767 | if (pContext->state.paPixelShaderConst)
|
---|
3768 | RTMemFree(pContext->state.paPixelShaderConst);
|
---|
3769 |
|
---|
3770 | if (pContext->pShaderContext)
|
---|
3771 | {
|
---|
3772 | int rc = ShaderContextDestroy(pContext->pShaderContext);
|
---|
3773 | AssertRC(rc);
|
---|
3774 | }
|
---|
3775 |
|
---|
3776 | if (pContext->idFramebuffer != OPENGL_INVALID_ID)
|
---|
3777 | {
|
---|
3778 | /* Unbind the object from the framebuffer target. */
|
---|
3779 | pState->ext.glBindFramebuffer(GL_FRAMEBUFFER, 0 /* back buffer */);
|
---|
3780 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3781 | pState->ext.glDeleteFramebuffers(1, &pContext->idFramebuffer);
|
---|
3782 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3783 |
|
---|
3784 | if (pContext->idReadFramebuffer != OPENGL_INVALID_ID)
|
---|
3785 | {
|
---|
3786 | pState->ext.glDeleteFramebuffers(1, &pContext->idReadFramebuffer);
|
---|
3787 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3788 | }
|
---|
3789 | if (pContext->idDrawFramebuffer != OPENGL_INVALID_ID)
|
---|
3790 | {
|
---|
3791 | pState->ext.glDeleteFramebuffers(1, &pContext->idDrawFramebuffer);
|
---|
3792 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3793 | }
|
---|
3794 | }
|
---|
3795 | #ifdef RT_OS_WINDOWS
|
---|
3796 | wglMakeCurrent(NULL, NULL);
|
---|
3797 | wglDeleteContext(pContext->hglrc);
|
---|
3798 | ReleaseDC(pContext->hwnd, pContext->hdc);
|
---|
3799 |
|
---|
3800 | /* Destroy the window we've created. */
|
---|
3801 | int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_DESTROYWINDOW, (WPARAM)pContext->hwnd, 0);
|
---|
3802 | AssertRC(rc);
|
---|
3803 | #elif defined(RT_OS_DARWIN)
|
---|
3804 | vmsvga3dCocoaDestroyView(pContext->cocoaView);
|
---|
3805 | vmsvga3dCocoaDestroyContext(pContext->cocoaContext);
|
---|
3806 | #elif defined(RT_OS_LINUX)
|
---|
3807 | glXMakeCurrent(pState->display, None, NULL);
|
---|
3808 | glXDestroyContext(pState->display, pContext->glxContext);
|
---|
3809 | XDestroyWindow(pState->display, pContext->window);
|
---|
3810 | #endif
|
---|
3811 |
|
---|
3812 | memset(pContext, 0, sizeof(*pContext));
|
---|
3813 | pContext->id = SVGA3D_INVALID_ID;
|
---|
3814 |
|
---|
3815 | VMSVGA3D_CLEAR_CURRENT_CONTEXT(pState);
|
---|
3816 | }
|
---|
3817 | else
|
---|
3818 | AssertFailed();
|
---|
3819 |
|
---|
3820 | return VINF_SUCCESS;
|
---|
3821 | }
|
---|
3822 |
|
---|
3823 | /* Handle resize */
|
---|
3824 | int vmsvga3dChangeMode(PVGASTATE pThis)
|
---|
3825 | {
|
---|
3826 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
3827 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
3828 |
|
---|
3829 | /* Resize all active contexts. */
|
---|
3830 | for (uint32_t i = 0; i < pState->cContexts; i++)
|
---|
3831 | {
|
---|
3832 | PVMSVGA3DCONTEXT pContext = &pState->paContext[i];
|
---|
3833 | uint32_t cid = pContext->id;
|
---|
3834 |
|
---|
3835 | if (cid != SVGA3D_INVALID_ID)
|
---|
3836 | {
|
---|
3837 | #ifdef RT_OS_WINDOWS
|
---|
3838 | CREATESTRUCT cs;
|
---|
3839 |
|
---|
3840 | memset(&cs, 0, sizeof(cs));
|
---|
3841 | cs.cx = pThis->svga.uWidth;
|
---|
3842 | cs.cy = pThis->svga.uHeight;
|
---|
3843 |
|
---|
3844 | /* Resize the window. */
|
---|
3845 | int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_RESIZEWINDOW, (WPARAM)pContext->hwnd, (LPARAM)&cs);
|
---|
3846 | AssertRC(rc);
|
---|
3847 | #elif defined(RT_OS_DARWIN)
|
---|
3848 | vmsvga3dCocoaViewSetSize(pContext->cocoaView, pThis->svga.uWidth, pThis->svga.uHeight);
|
---|
3849 | #elif defined(RT_OS_LINUX)
|
---|
3850 | XWindowChanges wc;
|
---|
3851 | wc.width = pThis->svga.uWidth;
|
---|
3852 | wc.height = pThis->svga.uHeight;
|
---|
3853 | XConfigureWindow(pState->display, pContext->window, CWWidth | CWHeight, &wc);
|
---|
3854 | #endif
|
---|
3855 | }
|
---|
3856 | }
|
---|
3857 | return VINF_SUCCESS;
|
---|
3858 | }
|
---|
3859 |
|
---|
3860 |
|
---|
3861 | int vmsvga3dSetTransform(PVGASTATE pThis, uint32_t cid, SVGA3dTransformType type, float matrix[16])
|
---|
3862 | {
|
---|
3863 | PVMSVGA3DCONTEXT pContext;
|
---|
3864 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
3865 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
3866 | bool fModelViewChanged = false;
|
---|
3867 |
|
---|
3868 | Log(("vmsvga3dSetTransform cid=%x %s\n", cid, vmsvgaTransformToString(type)));
|
---|
3869 |
|
---|
3870 | if ( cid >= pState->cContexts
|
---|
3871 | || pState->paContext[cid].id != cid)
|
---|
3872 | {
|
---|
3873 | Log(("vmsvga3dSetTransform invalid context id!\n"));
|
---|
3874 | return VERR_INVALID_PARAMETER;
|
---|
3875 | }
|
---|
3876 | pContext = &pState->paContext[cid];
|
---|
3877 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
3878 |
|
---|
3879 | /* Save this matrix for vm state save/restore. */
|
---|
3880 | pContext->state.aTransformState[type].fValid = true;
|
---|
3881 | memcpy(pContext->state.aTransformState[type].matrix, matrix, sizeof(pContext->state.aTransformState[type].matrix));
|
---|
3882 | pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_TRANSFORM;
|
---|
3883 |
|
---|
3884 | Log(("Matrix [%d %d %d %d]\n", (int)(matrix[0] * 10.0), (int)(matrix[1] * 10.0), (int)(matrix[2] * 10.0), (int)(matrix[3] * 10.0)));
|
---|
3885 | Log((" [%d %d %d %d]\n", (int)(matrix[4] * 10.0), (int)(matrix[5] * 10.0), (int)(matrix[6] * 10.0), (int)(matrix[7] * 10.0)));
|
---|
3886 | Log((" [%d %d %d %d]\n", (int)(matrix[8] * 10.0), (int)(matrix[9] * 10.0), (int)(matrix[10] * 10.0), (int)(matrix[11] * 10.0)));
|
---|
3887 | Log((" [%d %d %d %d]\n", (int)(matrix[12] * 10.0), (int)(matrix[13] * 10.0), (int)(matrix[14] * 10.0), (int)(matrix[15] * 10.0)));
|
---|
3888 |
|
---|
3889 | switch (type)
|
---|
3890 | {
|
---|
3891 | case SVGA3D_TRANSFORM_VIEW:
|
---|
3892 | /* View * World = Model View */
|
---|
3893 | glMatrixMode(GL_MODELVIEW);
|
---|
3894 | glLoadMatrixf(matrix);
|
---|
3895 | if (pContext->state.aTransformState[SVGA3D_TRANSFORM_WORLD].fValid)
|
---|
3896 | glMultMatrixf(pContext->state.aTransformState[SVGA3D_TRANSFORM_WORLD].matrix);
|
---|
3897 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3898 | fModelViewChanged = true;
|
---|
3899 | break;
|
---|
3900 |
|
---|
3901 | case SVGA3D_TRANSFORM_PROJECTION:
|
---|
3902 | {
|
---|
3903 | int rc = ShaderTransformProjection(pContext->state.RectViewPort.w, pContext->state.RectViewPort.h, matrix);
|
---|
3904 | AssertRCReturn(rc, rc);
|
---|
3905 | break;
|
---|
3906 | }
|
---|
3907 |
|
---|
3908 | case SVGA3D_TRANSFORM_TEXTURE0:
|
---|
3909 | glMatrixMode(GL_TEXTURE);
|
---|
3910 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3911 | glLoadMatrixf(matrix);
|
---|
3912 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3913 | break;
|
---|
3914 |
|
---|
3915 | case SVGA3D_TRANSFORM_TEXTURE1:
|
---|
3916 | case SVGA3D_TRANSFORM_TEXTURE2:
|
---|
3917 | case SVGA3D_TRANSFORM_TEXTURE3:
|
---|
3918 | case SVGA3D_TRANSFORM_TEXTURE4:
|
---|
3919 | case SVGA3D_TRANSFORM_TEXTURE5:
|
---|
3920 | case SVGA3D_TRANSFORM_TEXTURE6:
|
---|
3921 | case SVGA3D_TRANSFORM_TEXTURE7:
|
---|
3922 | Log(("vmsvga3dSetTransform: unsupported SVGA3D_TRANSFORM_TEXTUREx transform!!\n"));
|
---|
3923 | return VERR_INVALID_PARAMETER;
|
---|
3924 |
|
---|
3925 | case SVGA3D_TRANSFORM_WORLD:
|
---|
3926 | /* View * World = Model View */
|
---|
3927 | glMatrixMode(GL_MODELVIEW);
|
---|
3928 | if (pContext->state.aTransformState[SVGA3D_TRANSFORM_VIEW].fValid)
|
---|
3929 | glLoadMatrixf(pContext->state.aTransformState[SVGA3D_TRANSFORM_VIEW].matrix);
|
---|
3930 | else
|
---|
3931 | glLoadIdentity();
|
---|
3932 | glMultMatrixf(matrix);
|
---|
3933 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3934 | fModelViewChanged = true;
|
---|
3935 | break;
|
---|
3936 |
|
---|
3937 | case SVGA3D_TRANSFORM_WORLD1:
|
---|
3938 | case SVGA3D_TRANSFORM_WORLD2:
|
---|
3939 | case SVGA3D_TRANSFORM_WORLD3:
|
---|
3940 | Log(("vmsvga3dSetTransform: unsupported SVGA3D_TRANSFORM_WORLDx transform!!\n"));
|
---|
3941 | return VERR_INVALID_PARAMETER;
|
---|
3942 |
|
---|
3943 | default:
|
---|
3944 | Log(("vmsvga3dSetTransform: unknown type!!\n"));
|
---|
3945 | return VERR_INVALID_PARAMETER;
|
---|
3946 | }
|
---|
3947 |
|
---|
3948 | /* Apparently we need to reset the light and clip data after modifying the modelview matrix. */
|
---|
3949 | if (fModelViewChanged)
|
---|
3950 | {
|
---|
3951 | /* Reprogram the clip planes. */
|
---|
3952 | for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aClipPlane); j++)
|
---|
3953 | {
|
---|
3954 | if (pContext->state.aClipPlane[j].fValid == true)
|
---|
3955 | vmsvga3dSetClipPlane(pThis, cid, j, pContext->state.aClipPlane[j].plane);
|
---|
3956 | }
|
---|
3957 |
|
---|
3958 | /* Reprogram the light data. */
|
---|
3959 | for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aLightData); j++)
|
---|
3960 | {
|
---|
3961 | if (pContext->state.aLightData[j].fValidData == true)
|
---|
3962 | vmsvga3dSetLightData(pThis, cid, j, &pContext->state.aLightData[j].data);
|
---|
3963 | }
|
---|
3964 | }
|
---|
3965 |
|
---|
3966 | return VINF_SUCCESS;
|
---|
3967 | }
|
---|
3968 |
|
---|
3969 | int vmsvga3dSetZRange(PVGASTATE pThis, uint32_t cid, SVGA3dZRange zRange)
|
---|
3970 | {
|
---|
3971 | PVMSVGA3DCONTEXT pContext;
|
---|
3972 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
3973 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
3974 |
|
---|
3975 | Log(("vmsvga3dSetZRange cid=%x min=%d max=%d\n", cid, (uint32_t)(zRange.min * 100.0), (uint32_t)(zRange.max * 100.0)));
|
---|
3976 |
|
---|
3977 | if ( cid >= pState->cContexts
|
---|
3978 | || pState->paContext[cid].id != cid)
|
---|
3979 | {
|
---|
3980 | Log(("vmsvga3dSetZRange invalid context id!\n"));
|
---|
3981 | return VERR_INVALID_PARAMETER;
|
---|
3982 | }
|
---|
3983 | pContext = &pState->paContext[cid];
|
---|
3984 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
3985 |
|
---|
3986 | pContext->state.zRange = zRange;
|
---|
3987 | pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_ZRANGE;
|
---|
3988 |
|
---|
3989 | if (zRange.min < -1.0)
|
---|
3990 | zRange.min = -1.0;
|
---|
3991 | if (zRange.max > 1.0)
|
---|
3992 | zRange.max = 1.0;
|
---|
3993 |
|
---|
3994 | glDepthRange((GLdouble)zRange.min, (GLdouble)zRange.max);
|
---|
3995 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
3996 | return VINF_SUCCESS;
|
---|
3997 | }
|
---|
3998 |
|
---|
3999 | /**
|
---|
4000 | * Convert SVGA blend op value to its OpenGL equivalent
|
---|
4001 | */
|
---|
4002 | static GLenum vmsvga3dBlendOp2GL(uint32_t blendOp)
|
---|
4003 | {
|
---|
4004 | switch (blendOp)
|
---|
4005 | {
|
---|
4006 | case SVGA3D_BLENDOP_ZERO:
|
---|
4007 | return GL_ZERO;
|
---|
4008 | case SVGA3D_BLENDOP_ONE:
|
---|
4009 | return GL_ONE;
|
---|
4010 | case SVGA3D_BLENDOP_SRCCOLOR:
|
---|
4011 | return GL_SRC_COLOR;
|
---|
4012 | case SVGA3D_BLENDOP_INVSRCCOLOR:
|
---|
4013 | return GL_ONE_MINUS_SRC_COLOR;
|
---|
4014 | case SVGA3D_BLENDOP_SRCALPHA:
|
---|
4015 | return GL_SRC_ALPHA;
|
---|
4016 | case SVGA3D_BLENDOP_INVSRCALPHA:
|
---|
4017 | return GL_ONE_MINUS_SRC_ALPHA;
|
---|
4018 | case SVGA3D_BLENDOP_DESTALPHA:
|
---|
4019 | return GL_DST_ALPHA;
|
---|
4020 | case SVGA3D_BLENDOP_INVDESTALPHA:
|
---|
4021 | return GL_ONE_MINUS_DST_ALPHA;
|
---|
4022 | case SVGA3D_BLENDOP_DESTCOLOR:
|
---|
4023 | return GL_DST_COLOR;
|
---|
4024 | case SVGA3D_BLENDOP_INVDESTCOLOR:
|
---|
4025 | return GL_ONE_MINUS_DST_COLOR;
|
---|
4026 | case SVGA3D_BLENDOP_SRCALPHASAT:
|
---|
4027 | return GL_SRC_ALPHA_SATURATE;
|
---|
4028 | case SVGA3D_BLENDOP_BLENDFACTOR:
|
---|
4029 | return GL_CONSTANT_ALPHA; /* @todo correct?? */
|
---|
4030 | case SVGA3D_BLENDOP_INVBLENDFACTOR:
|
---|
4031 | return GL_ONE_MINUS_CONSTANT_ALPHA; /* @todo correct?? */
|
---|
4032 | default:
|
---|
4033 | AssertFailed();
|
---|
4034 | return GL_ONE;
|
---|
4035 | }
|
---|
4036 | }
|
---|
4037 |
|
---|
4038 | static GLenum vmsvga3dBlendEquation2GL(uint32_t blendEq)
|
---|
4039 | {
|
---|
4040 | switch (blendEq)
|
---|
4041 | {
|
---|
4042 | case SVGA3D_BLENDEQ_ADD:
|
---|
4043 | return GL_FUNC_ADD;
|
---|
4044 | case SVGA3D_BLENDEQ_SUBTRACT:
|
---|
4045 | return GL_FUNC_SUBTRACT;
|
---|
4046 | case SVGA3D_BLENDEQ_REVSUBTRACT:
|
---|
4047 | return GL_FUNC_REVERSE_SUBTRACT;
|
---|
4048 | case SVGA3D_BLENDEQ_MINIMUM:
|
---|
4049 | return GL_MIN;
|
---|
4050 | case SVGA3D_BLENDEQ_MAXIMUM:
|
---|
4051 | return GL_MAX;
|
---|
4052 | default:
|
---|
4053 | AssertFailed();
|
---|
4054 | return GL_FUNC_ADD;
|
---|
4055 | }
|
---|
4056 | }
|
---|
4057 |
|
---|
4058 | static GLenum vmsvgaCmpFunc2GL(uint32_t cmpFunc)
|
---|
4059 | {
|
---|
4060 | switch (cmpFunc)
|
---|
4061 | {
|
---|
4062 | case SVGA3D_CMP_NEVER:
|
---|
4063 | return GL_NEVER;
|
---|
4064 | case SVGA3D_CMP_LESS:
|
---|
4065 | return GL_LESS;
|
---|
4066 | case SVGA3D_CMP_EQUAL:
|
---|
4067 | return GL_EQUAL;
|
---|
4068 | case SVGA3D_CMP_LESSEQUAL:
|
---|
4069 | return GL_LEQUAL;
|
---|
4070 | case SVGA3D_CMP_GREATER:
|
---|
4071 | return GL_GREATER;
|
---|
4072 | case SVGA3D_CMP_NOTEQUAL:
|
---|
4073 | return GL_NOTEQUAL;
|
---|
4074 | case SVGA3D_CMP_GREATEREQUAL:
|
---|
4075 | return GL_GEQUAL;
|
---|
4076 | case SVGA3D_CMP_ALWAYS:
|
---|
4077 | return GL_ALWAYS;
|
---|
4078 | default:
|
---|
4079 | AssertFailed();
|
---|
4080 | return GL_LESS;
|
---|
4081 | }
|
---|
4082 | }
|
---|
4083 |
|
---|
4084 | static GLenum vmsvgaStencipOp2GL(uint32_t stencilOp)
|
---|
4085 | {
|
---|
4086 | switch (stencilOp)
|
---|
4087 | {
|
---|
4088 | case SVGA3D_STENCILOP_KEEP:
|
---|
4089 | return GL_KEEP;
|
---|
4090 | case SVGA3D_STENCILOP_ZERO:
|
---|
4091 | return GL_ZERO;
|
---|
4092 | case SVGA3D_STENCILOP_REPLACE:
|
---|
4093 | return GL_REPLACE;
|
---|
4094 | case SVGA3D_STENCILOP_INCRSAT:
|
---|
4095 | return GL_INCR_WRAP;
|
---|
4096 | case SVGA3D_STENCILOP_DECRSAT:
|
---|
4097 | return GL_DECR_WRAP;
|
---|
4098 | case SVGA3D_STENCILOP_INVERT:
|
---|
4099 | return GL_INVERT;
|
---|
4100 | case SVGA3D_STENCILOP_INCR:
|
---|
4101 | return GL_INCR;
|
---|
4102 | case SVGA3D_STENCILOP_DECR:
|
---|
4103 | return GL_DECR;
|
---|
4104 | default:
|
---|
4105 | AssertFailed();
|
---|
4106 | return GL_KEEP;
|
---|
4107 | }
|
---|
4108 | }
|
---|
4109 |
|
---|
4110 | int vmsvga3dSetRenderState(PVGASTATE pThis, uint32_t cid, uint32_t cRenderStates, SVGA3dRenderState *pRenderState)
|
---|
4111 | {
|
---|
4112 | uint32_t val;
|
---|
4113 | PVMSVGA3DCONTEXT pContext;
|
---|
4114 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
4115 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
4116 |
|
---|
4117 | Log(("vmsvga3dSetRenderState cid=%x cRenderStates=%d\n", cid, cRenderStates));
|
---|
4118 |
|
---|
4119 | if ( cid >= pState->cContexts
|
---|
4120 | || pState->paContext[cid].id != cid)
|
---|
4121 | {
|
---|
4122 | Log(("vmsvga3dSetRenderState invalid context id!\n"));
|
---|
4123 | return VERR_INVALID_PARAMETER;
|
---|
4124 | }
|
---|
4125 | pContext = &pState->paContext[cid];
|
---|
4126 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
4127 |
|
---|
4128 | for (unsigned i = 0; i < cRenderStates; i++)
|
---|
4129 | {
|
---|
4130 | GLenum enableCap = ~0U;
|
---|
4131 | Log(("vmsvga3dSetRenderState: cid=%d state=%s (%d) val=%x\n", cid, vmsvga3dGetRenderStateName(pRenderState[i].state), pRenderState[i].state, pRenderState[i].uintValue));
|
---|
4132 | /* Save the render state for vm state saving. */
|
---|
4133 | if (pRenderState[i].state < SVGA3D_RS_MAX)
|
---|
4134 | pContext->state.aRenderState[pRenderState[i].state] = pRenderState[i];
|
---|
4135 |
|
---|
4136 | switch (pRenderState[i].state)
|
---|
4137 | {
|
---|
4138 | case SVGA3D_RS_ZENABLE: /* SVGA3dBool */
|
---|
4139 | enableCap = GL_DEPTH_TEST;
|
---|
4140 | val = pRenderState[i].uintValue;
|
---|
4141 | break;
|
---|
4142 |
|
---|
4143 | case SVGA3D_RS_ZWRITEENABLE: /* SVGA3dBool */
|
---|
4144 | glDepthMask(!!pRenderState[i].uintValue);
|
---|
4145 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4146 | break;
|
---|
4147 |
|
---|
4148 | case SVGA3D_RS_ALPHATESTENABLE: /* SVGA3dBool */
|
---|
4149 | enableCap = GL_ALPHA_TEST;
|
---|
4150 | val = pRenderState[i].uintValue;
|
---|
4151 | break;
|
---|
4152 |
|
---|
4153 | case SVGA3D_RS_DITHERENABLE: /* SVGA3dBool */
|
---|
4154 | enableCap = GL_DITHER;
|
---|
4155 | val = pRenderState[i].uintValue;
|
---|
4156 | break;
|
---|
4157 |
|
---|
4158 | case SVGA3D_RS_FOGENABLE: /* SVGA3dBool */
|
---|
4159 | enableCap = GL_FOG;
|
---|
4160 | val = pRenderState[i].uintValue;
|
---|
4161 | break;
|
---|
4162 |
|
---|
4163 | case SVGA3D_RS_SPECULARENABLE: /* SVGA3dBool */
|
---|
4164 | Log(("vmsvga3dSetRenderState: WARNING: not applicable.\n"));
|
---|
4165 | break;
|
---|
4166 |
|
---|
4167 | case SVGA3D_RS_LIGHTINGENABLE: /* SVGA3dBool */
|
---|
4168 | enableCap = GL_LIGHTING;
|
---|
4169 | val = pRenderState[i].uintValue;
|
---|
4170 | break;
|
---|
4171 |
|
---|
4172 | case SVGA3D_RS_NORMALIZENORMALS: /* SVGA3dBool */
|
---|
4173 | /* not applicable */
|
---|
4174 | Log(("vmsvga3dSetRenderState: WARNING: not applicable.\n"));
|
---|
4175 | break;
|
---|
4176 |
|
---|
4177 | case SVGA3D_RS_POINTSPRITEENABLE: /* SVGA3dBool */
|
---|
4178 | enableCap = GL_POINT_SPRITE_ARB;
|
---|
4179 | val = pRenderState[i].uintValue;
|
---|
4180 | break;
|
---|
4181 |
|
---|
4182 | case SVGA3D_RS_POINTSIZE: /* float */
|
---|
4183 | /* @todo we need to apply scaling for point sizes below the min or above the max; see Wine) */
|
---|
4184 | if (pRenderState[i].floatValue < pState->caps.flPointSize[0])
|
---|
4185 | pRenderState[i].floatValue = pState->caps.flPointSize[0];
|
---|
4186 | if (pRenderState[i].floatValue > pState->caps.flPointSize[1])
|
---|
4187 | pRenderState[i].floatValue = pState->caps.flPointSize[1];
|
---|
4188 |
|
---|
4189 | glPointSize(pRenderState[i].floatValue);
|
---|
4190 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4191 | Log(("SVGA3D_RS_POINTSIZE: %d\n", (uint32_t) (pRenderState[i].floatValue * 100.0)));
|
---|
4192 | break;
|
---|
4193 |
|
---|
4194 | case SVGA3D_RS_POINTSIZEMIN: /* float */
|
---|
4195 | pState->ext.glPointParameterf(GL_POINT_SIZE_MIN, pRenderState[i].floatValue);
|
---|
4196 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4197 | Log(("SVGA3D_RS_POINTSIZEMIN: %d\n", (uint32_t) (pRenderState[i].floatValue * 100.0)));
|
---|
4198 | break;
|
---|
4199 |
|
---|
4200 | case SVGA3D_RS_POINTSIZEMAX: /* float */
|
---|
4201 | pState->ext.glPointParameterf(GL_POINT_SIZE_MAX, pRenderState[i].floatValue);
|
---|
4202 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4203 | Log(("SVGA3D_RS_POINTSIZEMAX: %d\n", (uint32_t) (pRenderState[i].floatValue * 100.0)));
|
---|
4204 | break;
|
---|
4205 |
|
---|
4206 | case SVGA3D_RS_POINTSCALEENABLE: /* SVGA3dBool */
|
---|
4207 | case SVGA3D_RS_POINTSCALE_A: /* float */
|
---|
4208 | case SVGA3D_RS_POINTSCALE_B: /* float */
|
---|
4209 | case SVGA3D_RS_POINTSCALE_C: /* float */
|
---|
4210 | Log(("vmsvga3dSetRenderState: WARNING: not applicable.\n"));
|
---|
4211 | break;
|
---|
4212 |
|
---|
4213 | case SVGA3D_RS_AMBIENT: /* SVGA3dColor */
|
---|
4214 | {
|
---|
4215 | GLfloat color[4]; /* red, green, blue, alpha */
|
---|
4216 |
|
---|
4217 | vmsvgaColor2GLFloatArray(pRenderState[i].uintValue, &color[0], &color[1], &color[2], &color[3]);
|
---|
4218 |
|
---|
4219 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color);
|
---|
4220 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4221 | break;
|
---|
4222 | }
|
---|
4223 |
|
---|
4224 | case SVGA3D_RS_CLIPPLANEENABLE: /* SVGA3dClipPlanes */
|
---|
4225 | {
|
---|
4226 | AssertCompile(SVGA3D_CLIPPLANE_MAX == (1 << 5));
|
---|
4227 | for (uint32_t j = 0; j <= 5; j++)
|
---|
4228 | {
|
---|
4229 | if (pRenderState[i].uintValue & RT_BIT(j))
|
---|
4230 | glEnable(GL_CLIP_PLANE0 + j);
|
---|
4231 | else
|
---|
4232 | glDisable(GL_CLIP_PLANE0 + j);
|
---|
4233 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4234 | }
|
---|
4235 | break;
|
---|
4236 | }
|
---|
4237 |
|
---|
4238 | case SVGA3D_RS_FOGCOLOR: /* SVGA3dColor */
|
---|
4239 | {
|
---|
4240 | GLfloat color[4]; /* red, green, blue, alpha */
|
---|
4241 |
|
---|
4242 | vmsvgaColor2GLFloatArray(pRenderState[i].uintValue, &color[0], &color[1], &color[2], &color[3]);
|
---|
4243 |
|
---|
4244 | glFogfv(GL_FOG_COLOR, color);
|
---|
4245 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4246 | break;
|
---|
4247 | }
|
---|
4248 |
|
---|
4249 | case SVGA3D_RS_FOGSTART: /* float */
|
---|
4250 | glFogf(GL_FOG_START, pRenderState[i].floatValue);
|
---|
4251 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4252 | break;
|
---|
4253 |
|
---|
4254 | case SVGA3D_RS_FOGEND: /* float */
|
---|
4255 | glFogf(GL_FOG_END, pRenderState[i].floatValue);
|
---|
4256 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4257 | break;
|
---|
4258 |
|
---|
4259 | case SVGA3D_RS_FOGDENSITY: /* float */
|
---|
4260 | glFogf(GL_FOG_DENSITY, pRenderState[i].floatValue);
|
---|
4261 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4262 | break;
|
---|
4263 |
|
---|
4264 | case SVGA3D_RS_RANGEFOGENABLE: /* SVGA3dBool */
|
---|
4265 | glFogi(GL_FOG_COORD_SRC, (pRenderState[i].uintValue) ? GL_FOG_COORD : GL_FRAGMENT_DEPTH);
|
---|
4266 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4267 | break;
|
---|
4268 |
|
---|
4269 | case SVGA3D_RS_FOGMODE: /* SVGA3dFogMode */
|
---|
4270 | {
|
---|
4271 | SVGA3dFogMode mode;
|
---|
4272 | mode.uintValue = pRenderState[i].uintValue;
|
---|
4273 |
|
---|
4274 | enableCap = GL_FOG_MODE;
|
---|
4275 | switch (mode.s.function)
|
---|
4276 | {
|
---|
4277 | case SVGA3D_FOGFUNC_EXP:
|
---|
4278 | val = GL_EXP;
|
---|
4279 | break;
|
---|
4280 | case SVGA3D_FOGFUNC_EXP2:
|
---|
4281 | val = GL_EXP2;
|
---|
4282 | break;
|
---|
4283 | case SVGA3D_FOGFUNC_LINEAR:
|
---|
4284 | val = GL_LINEAR;
|
---|
4285 | break;
|
---|
4286 | default:
|
---|
4287 | AssertMsgFailedReturn(("Unexpected fog function %d\n", mode.s.function), VERR_INTERNAL_ERROR);
|
---|
4288 | break;
|
---|
4289 | }
|
---|
4290 |
|
---|
4291 | /* @todo how to switch between vertex and pixel fog modes??? */
|
---|
4292 | Assert(mode.s.type == SVGA3D_FOGTYPE_PIXEL);
|
---|
4293 | #if 0
|
---|
4294 | /* The fog type determines the render state. */
|
---|
4295 | switch (mode.s.type)
|
---|
4296 | {
|
---|
4297 | case SVGA3D_FOGTYPE_VERTEX:
|
---|
4298 | renderState = D3DRS_FOGVERTEXMODE;
|
---|
4299 | break;
|
---|
4300 | case SVGA3D_FOGTYPE_PIXEL:
|
---|
4301 | renderState = D3DRS_FOGTABLEMODE;
|
---|
4302 | break;
|
---|
4303 | default:
|
---|
4304 | AssertMsgFailedReturn(("Unexpected fog type %d\n", mode.s.type), VERR_INTERNAL_ERROR);
|
---|
4305 | break;
|
---|
4306 | }
|
---|
4307 | #endif
|
---|
4308 |
|
---|
4309 | /* Set the fog base to depth or range. */
|
---|
4310 | switch (mode.s.base)
|
---|
4311 | {
|
---|
4312 | case SVGA3D_FOGBASE_DEPTHBASED:
|
---|
4313 | glFogi(GL_FOG_COORD_SRC, GL_FRAGMENT_DEPTH);
|
---|
4314 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4315 | break;
|
---|
4316 | case SVGA3D_FOGBASE_RANGEBASED:
|
---|
4317 | glFogi(GL_FOG_COORD_SRC, GL_FOG_COORD);
|
---|
4318 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4319 | break;
|
---|
4320 | default:
|
---|
4321 | /* ignore */
|
---|
4322 | AssertMsgFailed(("Unexpected fog base %d\n", mode.s.base));
|
---|
4323 | break;
|
---|
4324 | }
|
---|
4325 | break;
|
---|
4326 | }
|
---|
4327 |
|
---|
4328 | case SVGA3D_RS_FILLMODE: /* SVGA3dFillMode */
|
---|
4329 | {
|
---|
4330 | SVGA3dFillMode mode;
|
---|
4331 |
|
---|
4332 | mode.uintValue = pRenderState[i].uintValue;
|
---|
4333 |
|
---|
4334 | switch (mode.s.mode)
|
---|
4335 | {
|
---|
4336 | case SVGA3D_FILLMODE_POINT:
|
---|
4337 | val = GL_POINT;
|
---|
4338 | break;
|
---|
4339 | case SVGA3D_FILLMODE_LINE:
|
---|
4340 | val = GL_LINE;
|
---|
4341 | break;
|
---|
4342 | case SVGA3D_FILLMODE_FILL:
|
---|
4343 | val = GL_FILL;
|
---|
4344 | break;
|
---|
4345 | default:
|
---|
4346 | AssertMsgFailedReturn(("Unexpected fill mode %d\n", mode.s.mode), VERR_INTERNAL_ERROR);
|
---|
4347 | break;
|
---|
4348 | }
|
---|
4349 | /* @note only front and back faces */
|
---|
4350 | Assert(mode.s.face == SVGA3D_FACE_FRONT_BACK);
|
---|
4351 | glPolygonMode(GL_FRONT_AND_BACK, val);
|
---|
4352 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4353 | break;
|
---|
4354 | }
|
---|
4355 |
|
---|
4356 | case SVGA3D_RS_SHADEMODE: /* SVGA3dShadeMode */
|
---|
4357 | switch (pRenderState[i].uintValue)
|
---|
4358 | {
|
---|
4359 | case SVGA3D_SHADEMODE_FLAT:
|
---|
4360 | val = GL_FLAT;
|
---|
4361 | break;
|
---|
4362 |
|
---|
4363 | case SVGA3D_SHADEMODE_SMOOTH:
|
---|
4364 | val = GL_SMOOTH;
|
---|
4365 | break;
|
---|
4366 |
|
---|
4367 | default:
|
---|
4368 | AssertMsgFailedReturn(("Unexpected shade mode %d\n", pRenderState[i].uintValue), VERR_INTERNAL_ERROR);
|
---|
4369 | break;
|
---|
4370 | }
|
---|
4371 |
|
---|
4372 | glShadeModel(val);
|
---|
4373 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4374 | break;
|
---|
4375 |
|
---|
4376 | case SVGA3D_RS_LINEPATTERN: /* SVGA3dLinePattern */
|
---|
4377 | /* No longer supported by d3d; mesagl comments suggest not all backends support it */
|
---|
4378 | /* @todo */
|
---|
4379 | Log(("WARNING: SVGA3D_RS_LINEPATTERN %x not supported!!\n", pRenderState[i].uintValue));
|
---|
4380 | /*
|
---|
4381 | renderState = D3DRS_LINEPATTERN;
|
---|
4382 | val = pRenderState[i].uintValue;
|
---|
4383 | */
|
---|
4384 | break;
|
---|
4385 |
|
---|
4386 | case SVGA3D_RS_LINEAA: /* SVGA3dBool */
|
---|
4387 | enableCap = GL_LINE_SMOOTH;
|
---|
4388 | val = pRenderState[i].uintValue;
|
---|
4389 | break;
|
---|
4390 |
|
---|
4391 | case SVGA3D_RS_LINEWIDTH: /* float */
|
---|
4392 | glLineWidth(pRenderState[i].floatValue);
|
---|
4393 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4394 | break;
|
---|
4395 |
|
---|
4396 | case SVGA3D_RS_SEPARATEALPHABLENDENABLE: /* SVGA3dBool */
|
---|
4397 | {
|
---|
4398 | /* Refresh the blending state based on the new enable setting. */
|
---|
4399 | SVGA3dRenderState renderstate[2];
|
---|
4400 |
|
---|
4401 | renderstate[0].state = SVGA3D_RS_SRCBLEND;
|
---|
4402 | renderstate[0].uintValue = pContext->state.aRenderState[SVGA3D_RS_SRCBLEND].uintValue;
|
---|
4403 | renderstate[1].state = SVGA3D_RS_BLENDEQUATION;
|
---|
4404 | renderstate[1].uintValue = pContext->state.aRenderState[SVGA3D_RS_BLENDEQUATION].uintValue;
|
---|
4405 |
|
---|
4406 | int rc = vmsvga3dSetRenderState(pThis, cid, 2, renderstate);
|
---|
4407 | AssertRCReturn(rc, rc);
|
---|
4408 |
|
---|
4409 | if (pContext->state.aRenderState[SVGA3D_RS_BLENDENABLE].uintValue != 0)
|
---|
4410 | continue; /* ignore if blend is already enabled */
|
---|
4411 | /* no break */
|
---|
4412 | }
|
---|
4413 |
|
---|
4414 | case SVGA3D_RS_BLENDENABLE: /* SVGA3dBool */
|
---|
4415 | enableCap = GL_BLEND;
|
---|
4416 | val = pRenderState[i].uintValue;
|
---|
4417 | break;
|
---|
4418 |
|
---|
4419 | case SVGA3D_RS_SRCBLENDALPHA: /* SVGA3dBlendOp */
|
---|
4420 | case SVGA3D_RS_DSTBLENDALPHA: /* SVGA3dBlendOp */
|
---|
4421 | case SVGA3D_RS_SRCBLEND: /* SVGA3dBlendOp */
|
---|
4422 | case SVGA3D_RS_DSTBLEND: /* SVGA3dBlendOp */
|
---|
4423 | {
|
---|
4424 | GLint srcRGB, srcAlpha, dstRGB, dstAlpha;
|
---|
4425 | GLint blendop = vmsvga3dBlendOp2GL(pRenderState[i].uintValue);
|
---|
4426 |
|
---|
4427 | glGetIntegerv(GL_BLEND_SRC_RGB, &srcRGB);
|
---|
4428 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4429 | glGetIntegerv(GL_BLEND_DST_RGB, &dstRGB);
|
---|
4430 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4431 | glGetIntegerv(GL_BLEND_DST_ALPHA, &dstAlpha);
|
---|
4432 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4433 | glGetIntegerv(GL_BLEND_SRC_ALPHA, &srcAlpha);
|
---|
4434 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4435 |
|
---|
4436 | switch (pRenderState[i].state)
|
---|
4437 | {
|
---|
4438 | case SVGA3D_RS_SRCBLEND:
|
---|
4439 | srcRGB = blendop;
|
---|
4440 | break;
|
---|
4441 | case SVGA3D_RS_DSTBLEND:
|
---|
4442 | dstRGB = blendop;
|
---|
4443 | break;
|
---|
4444 | case SVGA3D_RS_SRCBLENDALPHA:
|
---|
4445 | srcAlpha = blendop;
|
---|
4446 | break;
|
---|
4447 | case SVGA3D_RS_DSTBLENDALPHA:
|
---|
4448 | dstAlpha = blendop;
|
---|
4449 | break;
|
---|
4450 | default:
|
---|
4451 | /* not possible; shut up gcc */
|
---|
4452 | AssertFailed();
|
---|
4453 | break;
|
---|
4454 | }
|
---|
4455 |
|
---|
4456 | if (pContext->state.aRenderState[SVGA3D_RS_SEPARATEALPHABLENDENABLE].uintValue != 0)
|
---|
4457 | pState->ext.glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
|
---|
4458 | else
|
---|
4459 | glBlendFunc(srcRGB, dstRGB);
|
---|
4460 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4461 | break;
|
---|
4462 | }
|
---|
4463 |
|
---|
4464 | case SVGA3D_RS_BLENDEQUATIONALPHA: /* SVGA3dBlendEquation */
|
---|
4465 | case SVGA3D_RS_BLENDEQUATION: /* SVGA3dBlendEquation */
|
---|
4466 | if (pContext->state.aRenderState[SVGA3D_RS_SEPARATEALPHABLENDENABLE].uintValue != 0)
|
---|
4467 | pState->ext.glBlendEquationSeparate(vmsvga3dBlendEquation2GL(pContext->state.aRenderState[SVGA3D_RS_BLENDEQUATION].uintValue),
|
---|
4468 | vmsvga3dBlendEquation2GL(pContext->state.aRenderState[SVGA3D_RS_BLENDEQUATIONALPHA].uintValue));
|
---|
4469 | else
|
---|
4470 | pState->ext.glBlendEquation(vmsvga3dBlendEquation2GL(pRenderState[i].uintValue));
|
---|
4471 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4472 | break;
|
---|
4473 |
|
---|
4474 | case SVGA3D_RS_BLENDCOLOR: /* SVGA3dColor */
|
---|
4475 | {
|
---|
4476 | GLfloat red, green, blue, alpha;
|
---|
4477 |
|
---|
4478 | vmsvgaColor2GLFloatArray(pRenderState[i].uintValue, &red, &green, &blue, &alpha);
|
---|
4479 |
|
---|
4480 | pState->ext.glBlendColor(red, green, blue, alpha);
|
---|
4481 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4482 | break;
|
---|
4483 | }
|
---|
4484 |
|
---|
4485 | case SVGA3D_RS_CULLMODE: /* SVGA3dFace */
|
---|
4486 | {
|
---|
4487 | GLenum mode = GL_BACK; /* default for OpenGL */
|
---|
4488 |
|
---|
4489 | switch (pRenderState[i].uintValue)
|
---|
4490 | {
|
---|
4491 | case SVGA3D_FACE_NONE:
|
---|
4492 | break;
|
---|
4493 | case SVGA3D_FACE_FRONT:
|
---|
4494 | mode = GL_FRONT;
|
---|
4495 | break;
|
---|
4496 | case SVGA3D_FACE_BACK:
|
---|
4497 | mode = GL_BACK;
|
---|
4498 | break;
|
---|
4499 | case SVGA3D_FACE_FRONT_BACK:
|
---|
4500 | mode = GL_FRONT_AND_BACK;
|
---|
4501 | break;
|
---|
4502 | default:
|
---|
4503 | AssertMsgFailedReturn(("Unexpected cull mode %d\n", pRenderState[i].uintValue), VERR_INTERNAL_ERROR);
|
---|
4504 | break;
|
---|
4505 | }
|
---|
4506 | enableCap = GL_CULL_FACE;
|
---|
4507 | if (pRenderState[i].uintValue != SVGA3D_FACE_NONE)
|
---|
4508 | {
|
---|
4509 | glCullFace(mode);
|
---|
4510 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4511 | val = 1;
|
---|
4512 | }
|
---|
4513 | else
|
---|
4514 | val = 0;
|
---|
4515 | break;
|
---|
4516 | }
|
---|
4517 |
|
---|
4518 | case SVGA3D_RS_ZFUNC: /* SVGA3dCmpFunc */
|
---|
4519 | glDepthFunc(vmsvgaCmpFunc2GL(pRenderState[i].uintValue));
|
---|
4520 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4521 | break;
|
---|
4522 |
|
---|
4523 | case SVGA3D_RS_ALPHAFUNC: /* SVGA3dCmpFunc */
|
---|
4524 | {
|
---|
4525 | GLclampf ref;
|
---|
4526 |
|
---|
4527 | glGetFloatv(GL_ALPHA_TEST_REF, &ref);
|
---|
4528 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4529 | glAlphaFunc(vmsvgaCmpFunc2GL(pRenderState[i].uintValue), ref);
|
---|
4530 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4531 | break;
|
---|
4532 | }
|
---|
4533 |
|
---|
4534 | case SVGA3D_RS_ALPHAREF: /* float (0.0 .. 1.0) */
|
---|
4535 | {
|
---|
4536 | GLint func;
|
---|
4537 |
|
---|
4538 | glGetIntegerv(GL_ALPHA_TEST_FUNC, &func);
|
---|
4539 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4540 | glAlphaFunc(func, pRenderState[i].floatValue);
|
---|
4541 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4542 | break;
|
---|
4543 | }
|
---|
4544 |
|
---|
4545 | case SVGA3D_RS_STENCILENABLE: /* SVGA3dBool */
|
---|
4546 | enableCap = GL_STENCIL_TEST;
|
---|
4547 | val = pRenderState[i].uintValue;
|
---|
4548 | break;
|
---|
4549 |
|
---|
4550 | case SVGA3D_RS_STENCILFUNC: /* SVGA3dCmpFunc */
|
---|
4551 | case SVGA3D_RS_STENCILREF: /* uint32_t */
|
---|
4552 | case SVGA3D_RS_STENCILMASK: /* uint32_t */
|
---|
4553 | {
|
---|
4554 | GLint func, ref;
|
---|
4555 | GLuint mask;
|
---|
4556 |
|
---|
4557 | glGetIntegerv(GL_STENCIL_FUNC, &func);
|
---|
4558 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4559 | glGetIntegerv(GL_STENCIL_VALUE_MASK, (GLint *)&mask);
|
---|
4560 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4561 | glGetIntegerv(GL_STENCIL_REF, &ref);
|
---|
4562 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4563 |
|
---|
4564 | switch (pRenderState[i].state)
|
---|
4565 | {
|
---|
4566 | case SVGA3D_RS_STENCILFUNC: /* SVGA3dCmpFunc */
|
---|
4567 | func = vmsvgaCmpFunc2GL(pRenderState[i].uintValue);
|
---|
4568 | break;
|
---|
4569 |
|
---|
4570 | case SVGA3D_RS_STENCILREF: /* uint32_t */
|
---|
4571 | ref = pRenderState[i].uintValue;
|
---|
4572 | break;
|
---|
4573 |
|
---|
4574 | case SVGA3D_RS_STENCILMASK: /* uint32_t */
|
---|
4575 | mask = pRenderState[i].uintValue;
|
---|
4576 | break;
|
---|
4577 |
|
---|
4578 | default:
|
---|
4579 | /* not possible; shut up gcc */
|
---|
4580 | AssertFailed();
|
---|
4581 | break;
|
---|
4582 | }
|
---|
4583 |
|
---|
4584 | glStencilFunc(func, ref, mask);
|
---|
4585 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4586 | break;
|
---|
4587 | }
|
---|
4588 |
|
---|
4589 | case SVGA3D_RS_STENCILWRITEMASK: /* uint32_t */
|
---|
4590 | glStencilMask(pRenderState[i].uintValue);
|
---|
4591 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4592 | break;
|
---|
4593 |
|
---|
4594 | case SVGA3D_RS_STENCILFAIL: /* SVGA3dStencilOp */
|
---|
4595 | case SVGA3D_RS_STENCILZFAIL: /* SVGA3dStencilOp */
|
---|
4596 | case SVGA3D_RS_STENCILPASS: /* SVGA3dStencilOp */
|
---|
4597 | {
|
---|
4598 | GLint sfail, dpfail, dppass;
|
---|
4599 | GLenum stencilop = vmsvgaStencipOp2GL(pRenderState[i].uintValue);
|
---|
4600 |
|
---|
4601 | glGetIntegerv(GL_STENCIL_FAIL, &sfail);
|
---|
4602 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4603 | glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, &dpfail);
|
---|
4604 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4605 | glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &dppass);
|
---|
4606 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4607 |
|
---|
4608 | switch (pRenderState[i].state)
|
---|
4609 | {
|
---|
4610 | case SVGA3D_RS_STENCILFAIL: /* SVGA3dStencilOp */
|
---|
4611 | sfail = stencilop;
|
---|
4612 | break;
|
---|
4613 | case SVGA3D_RS_STENCILZFAIL: /* SVGA3dStencilOp */
|
---|
4614 | dpfail = stencilop;
|
---|
4615 | break;
|
---|
4616 | case SVGA3D_RS_STENCILPASS: /* SVGA3dStencilOp */
|
---|
4617 | dppass = stencilop;
|
---|
4618 | break;
|
---|
4619 | default:
|
---|
4620 | /* not possible; shut up gcc */
|
---|
4621 | AssertFailed();
|
---|
4622 | break;
|
---|
4623 | }
|
---|
4624 | glStencilOp(sfail, dpfail, dppass);
|
---|
4625 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4626 | break;
|
---|
4627 | }
|
---|
4628 |
|
---|
4629 | case SVGA3D_RS_STENCILENABLE2SIDED: /* SVGA3dBool */
|
---|
4630 | /* @note GL_EXT_stencil_two_side required! */
|
---|
4631 | if (pState->ext.fEXT_stencil_two_side)
|
---|
4632 | {
|
---|
4633 | enableCap = GL_STENCIL_TEST_TWO_SIDE_EXT;
|
---|
4634 | val = pRenderState[i].uintValue;
|
---|
4635 | }
|
---|
4636 | else
|
---|
4637 | Log(("vmsvga3dSetRenderState: WARNING unsupported SVGA3D_RS_STENCILENABLE2SIDED\n"));
|
---|
4638 | break;
|
---|
4639 |
|
---|
4640 | case SVGA3D_RS_CCWSTENCILFUNC: /* SVGA3dCmpFunc */
|
---|
4641 | {
|
---|
4642 | /* @todo SVGA3D_RS_STENCILFAIL/ZFAIL/PASS for front & back faces
|
---|
4643 | * SVGA3D_RS_CCWSTENCILFAIL/ZFAIL/PASS for back faces ??
|
---|
4644 | */
|
---|
4645 | GLint ref;
|
---|
4646 | GLuint mask;
|
---|
4647 |
|
---|
4648 | glGetIntegerv(GL_STENCIL_BACK_VALUE_MASK, (GLint *)&mask);
|
---|
4649 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4650 | glGetIntegerv(GL_STENCIL_BACK_REF, &ref);
|
---|
4651 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4652 |
|
---|
4653 | pState->ext.glStencilFuncSeparate(GL_BACK, vmsvgaCmpFunc2GL(pRenderState[i].uintValue), ref, mask);
|
---|
4654 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4655 | break;
|
---|
4656 | }
|
---|
4657 |
|
---|
4658 | case SVGA3D_RS_CCWSTENCILFAIL: /* SVGA3dStencilOp */
|
---|
4659 | case SVGA3D_RS_CCWSTENCILZFAIL: /* SVGA3dStencilOp */
|
---|
4660 | case SVGA3D_RS_CCWSTENCILPASS: /* SVGA3dStencilOp */
|
---|
4661 | {
|
---|
4662 | /* @todo SVGA3D_RS_STENCILFAIL/ZFAIL/PASS for front & back faces
|
---|
4663 | * SVGA3D_RS_CCWSTENCILFAIL/ZFAIL/PASS for back faces ??
|
---|
4664 | */
|
---|
4665 | GLint sfail, dpfail, dppass;
|
---|
4666 | GLenum stencilop = vmsvgaStencipOp2GL(pRenderState[i].uintValue);
|
---|
4667 |
|
---|
4668 | glGetIntegerv(GL_STENCIL_BACK_FAIL, &sfail);
|
---|
4669 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4670 | glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_FAIL, &dpfail);
|
---|
4671 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4672 | glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_PASS, &dppass);
|
---|
4673 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4674 |
|
---|
4675 | switch (pRenderState[i].state)
|
---|
4676 | {
|
---|
4677 | case SVGA3D_RS_CCWSTENCILFAIL: /* SVGA3dStencilOp */
|
---|
4678 | sfail = stencilop;
|
---|
4679 | break;
|
---|
4680 | case SVGA3D_RS_CCWSTENCILZFAIL: /* SVGA3dStencilOp */
|
---|
4681 | dpfail = stencilop;
|
---|
4682 | break;
|
---|
4683 | case SVGA3D_RS_CCWSTENCILPASS: /* SVGA3dStencilOp */
|
---|
4684 | dppass = stencilop;
|
---|
4685 | break;
|
---|
4686 | default:
|
---|
4687 | /* not possible; shut up gcc */
|
---|
4688 | AssertFailed();
|
---|
4689 | break;
|
---|
4690 | }
|
---|
4691 | pState->ext.glStencilOpSeparate(GL_BACK, sfail, dpfail, dppass);
|
---|
4692 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4693 | break;
|
---|
4694 | }
|
---|
4695 |
|
---|
4696 | case SVGA3D_RS_ZBIAS: /* float */
|
---|
4697 | /* @todo unknown meaning; depth bias is not identical
|
---|
4698 | renderState = D3DRS_DEPTHBIAS;
|
---|
4699 | val = pRenderState[i].uintValue;
|
---|
4700 | */
|
---|
4701 | Log(("vmsvga3dSetRenderState: WARNING unsupported SVGA3D_RS_ZBIAS\n"));
|
---|
4702 | break;
|
---|
4703 |
|
---|
4704 | case SVGA3D_RS_DEPTHBIAS: /* float */
|
---|
4705 | {
|
---|
4706 | GLfloat factor;
|
---|
4707 |
|
---|
4708 | /* @todo not sure if the d3d & ogl definitions are identical. */
|
---|
4709 |
|
---|
4710 | /* Do not change the factor part. */
|
---|
4711 | glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &factor);
|
---|
4712 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4713 |
|
---|
4714 | glPolygonOffset(factor, pRenderState[i].floatValue);
|
---|
4715 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4716 | break;
|
---|
4717 | }
|
---|
4718 |
|
---|
4719 | case SVGA3D_RS_SLOPESCALEDEPTHBIAS: /* float */
|
---|
4720 | {
|
---|
4721 | GLfloat units;
|
---|
4722 |
|
---|
4723 | /* @todo not sure if the d3d & ogl definitions are identical. */
|
---|
4724 |
|
---|
4725 | /* Do not change the factor part. */
|
---|
4726 | glGetFloatv(GL_POLYGON_OFFSET_UNITS, &units);
|
---|
4727 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4728 |
|
---|
4729 | glPolygonOffset(pRenderState[i].floatValue, units);
|
---|
4730 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4731 | break;
|
---|
4732 | }
|
---|
4733 |
|
---|
4734 | case SVGA3D_RS_COLORWRITEENABLE: /* SVGA3dColorMask */
|
---|
4735 | {
|
---|
4736 | GLboolean red, green, blue, alpha;
|
---|
4737 | SVGA3dColorMask mask;
|
---|
4738 |
|
---|
4739 | mask.uintValue = pRenderState[i].uintValue;
|
---|
4740 |
|
---|
4741 | red = mask.s.red;
|
---|
4742 | green = mask.s.green;
|
---|
4743 | blue = mask.s.blue;
|
---|
4744 | alpha = mask.s.alpha;
|
---|
4745 |
|
---|
4746 | glColorMask(red, green, blue, alpha);
|
---|
4747 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4748 | break;
|
---|
4749 | }
|
---|
4750 |
|
---|
4751 | case SVGA3D_RS_COLORWRITEENABLE1: /* SVGA3dColorMask to D3DCOLORWRITEENABLE_* */
|
---|
4752 | case SVGA3D_RS_COLORWRITEENABLE2: /* SVGA3dColorMask to D3DCOLORWRITEENABLE_* */
|
---|
4753 | case SVGA3D_RS_COLORWRITEENABLE3: /* SVGA3dColorMask to D3DCOLORWRITEENABLE_* */
|
---|
4754 | Log(("vmsvga3dSetRenderState: WARNING SVGA3D_RS_COLORWRITEENABLEx not supported!!\n"));
|
---|
4755 | break;
|
---|
4756 |
|
---|
4757 | case SVGA3D_RS_SCISSORTESTENABLE: /* SVGA3dBool */
|
---|
4758 | enableCap = GL_SCISSOR_TEST;
|
---|
4759 | val = pRenderState[i].uintValue;
|
---|
4760 | break;
|
---|
4761 |
|
---|
4762 | #if 0
|
---|
4763 | case SVGA3D_RS_DIFFUSEMATERIALSOURCE: /* SVGA3dVertexMaterial */
|
---|
4764 | AssertCompile(D3DMCS_COLOR2 == SVGA3D_VERTEXMATERIAL_SPECULAR);
|
---|
4765 | renderState = D3DRS_DIFFUSEMATERIALSOURCE;
|
---|
4766 | val = pRenderState[i].uintValue;
|
---|
4767 | break;
|
---|
4768 |
|
---|
4769 | case SVGA3D_RS_SPECULARMATERIALSOURCE: /* SVGA3dVertexMaterial */
|
---|
4770 | renderState = D3DRS_SPECULARMATERIALSOURCE;
|
---|
4771 | val = pRenderState[i].uintValue;
|
---|
4772 | break;
|
---|
4773 |
|
---|
4774 | case SVGA3D_RS_AMBIENTMATERIALSOURCE: /* SVGA3dVertexMaterial */
|
---|
4775 | renderState = D3DRS_AMBIENTMATERIALSOURCE;
|
---|
4776 | val = pRenderState[i].uintValue;
|
---|
4777 | break;
|
---|
4778 |
|
---|
4779 | case SVGA3D_RS_EMISSIVEMATERIALSOURCE: /* SVGA3dVertexMaterial */
|
---|
4780 | renderState = D3DRS_EMISSIVEMATERIALSOURCE;
|
---|
4781 | val = pRenderState[i].uintValue;
|
---|
4782 | break;
|
---|
4783 | #endif
|
---|
4784 |
|
---|
4785 | case SVGA3D_RS_WRAP3: /* SVGA3dWrapFlags */
|
---|
4786 | case SVGA3D_RS_WRAP4: /* SVGA3dWrapFlags */
|
---|
4787 | case SVGA3D_RS_WRAP5: /* SVGA3dWrapFlags */
|
---|
4788 | case SVGA3D_RS_WRAP6: /* SVGA3dWrapFlags */
|
---|
4789 | case SVGA3D_RS_WRAP7: /* SVGA3dWrapFlags */
|
---|
4790 | case SVGA3D_RS_WRAP8: /* SVGA3dWrapFlags */
|
---|
4791 | case SVGA3D_RS_WRAP9: /* SVGA3dWrapFlags */
|
---|
4792 | case SVGA3D_RS_WRAP10: /* SVGA3dWrapFlags */
|
---|
4793 | case SVGA3D_RS_WRAP11: /* SVGA3dWrapFlags */
|
---|
4794 | case SVGA3D_RS_WRAP12: /* SVGA3dWrapFlags */
|
---|
4795 | case SVGA3D_RS_WRAP13: /* SVGA3dWrapFlags */
|
---|
4796 | case SVGA3D_RS_WRAP14: /* SVGA3dWrapFlags */
|
---|
4797 | case SVGA3D_RS_WRAP15: /* SVGA3dWrapFlags */
|
---|
4798 | Log(("vmsvga3dSetRenderState: WARNING unsupported SVGA3D_WRAPx (x >= 3)\n"));
|
---|
4799 | break;
|
---|
4800 |
|
---|
4801 | case SVGA3D_RS_LASTPIXEL: /* SVGA3dBool */
|
---|
4802 | case SVGA3D_RS_TWEENFACTOR: /* float */
|
---|
4803 | case SVGA3D_RS_INDEXEDVERTEXBLENDENABLE: /* SVGA3dBool */
|
---|
4804 | case SVGA3D_RS_VERTEXBLEND: /* SVGA3dVertexBlendFlags */
|
---|
4805 | Log(("vmsvga3dSetRenderState: WARNING not applicable!!\n"));
|
---|
4806 | break;
|
---|
4807 |
|
---|
4808 | case SVGA3D_RS_MULTISAMPLEANTIALIAS: /* SVGA3dBool */
|
---|
4809 | enableCap = GL_MULTISAMPLE;
|
---|
4810 | val = pRenderState[i].uintValue;
|
---|
4811 | break;
|
---|
4812 |
|
---|
4813 | case SVGA3D_RS_MULTISAMPLEMASK: /* uint32_t */
|
---|
4814 | case SVGA3D_RS_ANTIALIASEDLINEENABLE: /* SVGA3dBool */
|
---|
4815 | Log(("vmsvga3dSetRenderState: WARNING not applicable??!!\n"));
|
---|
4816 | break;
|
---|
4817 |
|
---|
4818 | case SVGA3D_RS_COORDINATETYPE: /* SVGA3dCoordinateType */
|
---|
4819 | Assert(pRenderState[i].uintValue == SVGA3D_COORDINATE_LEFTHANDED);
|
---|
4820 | /* @todo setup a view matrix to scale the world space by -1 in the z-direction for right handed coordinates. */
|
---|
4821 | /*
|
---|
4822 | renderState = D3DRS_COORDINATETYPE;
|
---|
4823 | val = pRenderState[i].uintValue;
|
---|
4824 | */
|
---|
4825 | break;
|
---|
4826 |
|
---|
4827 | case SVGA3D_RS_FRONTWINDING: /* SVGA3dFrontWinding */
|
---|
4828 | Assert(pRenderState[i].uintValue == SVGA3D_FRONTWINDING_CW);
|
---|
4829 | /* Invert the selected mode because of y-inversion (?) */
|
---|
4830 | glFrontFace((pRenderState[i].uintValue != SVGA3D_FRONTWINDING_CW) ? GL_CW : GL_CCW);
|
---|
4831 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4832 | break;
|
---|
4833 |
|
---|
4834 | case SVGA3D_RS_OUTPUTGAMMA: /* float */
|
---|
4835 | //AssertFailed();
|
---|
4836 | /*
|
---|
4837 | D3DRS_SRGBWRITEENABLE ??
|
---|
4838 | renderState = D3DRS_OUTPUTGAMMA;
|
---|
4839 | val = pRenderState[i].uintValue;
|
---|
4840 | */
|
---|
4841 | break;
|
---|
4842 |
|
---|
4843 | #if 0
|
---|
4844 |
|
---|
4845 | case SVGA3D_RS_VERTEXMATERIALENABLE: /* SVGA3dBool */
|
---|
4846 | //AssertFailed();
|
---|
4847 | renderState = D3DRS_INDEXEDVERTEXBLENDENABLE; /* correct?? */
|
---|
4848 | val = pRenderState[i].uintValue;
|
---|
4849 | break;
|
---|
4850 |
|
---|
4851 | case SVGA3D_RS_TEXTUREFACTOR: /* SVGA3dColor */
|
---|
4852 | renderState = D3DRS_TEXTUREFACTOR;
|
---|
4853 | val = pRenderState[i].uintValue;
|
---|
4854 | break;
|
---|
4855 |
|
---|
4856 | case SVGA3D_RS_LOCALVIEWER: /* SVGA3dBool */
|
---|
4857 | renderState = D3DRS_LOCALVIEWER;
|
---|
4858 | val = pRenderState[i].uintValue;
|
---|
4859 | break;
|
---|
4860 |
|
---|
4861 | case SVGA3D_RS_ZVISIBLE: /* SVGA3dBool */
|
---|
4862 | AssertFailed();
|
---|
4863 | /*
|
---|
4864 | renderState = D3DRS_ZVISIBLE;
|
---|
4865 | val = pRenderState[i].uintValue;
|
---|
4866 | */
|
---|
4867 | break;
|
---|
4868 |
|
---|
4869 | case SVGA3D_RS_CLIPPING: /* SVGA3dBool */
|
---|
4870 | renderState = D3DRS_CLIPPING;
|
---|
4871 | val = pRenderState[i].uintValue;
|
---|
4872 | break;
|
---|
4873 |
|
---|
4874 | case SVGA3D_RS_WRAP0: /* SVGA3dWrapFlags */
|
---|
4875 | glTexParameter GL_TEXTURE_WRAP_S
|
---|
4876 | Assert(SVGA3D_WRAPCOORD_3 == D3DWRAPCOORD_3);
|
---|
4877 | renderState = D3DRS_WRAP0;
|
---|
4878 | val = pRenderState[i].uintValue;
|
---|
4879 | break;
|
---|
4880 |
|
---|
4881 | case SVGA3D_RS_WRAP1: /* SVGA3dWrapFlags */
|
---|
4882 | glTexParameter GL_TEXTURE_WRAP_T
|
---|
4883 | renderState = D3DRS_WRAP1;
|
---|
4884 | val = pRenderState[i].uintValue;
|
---|
4885 | break;
|
---|
4886 |
|
---|
4887 | case SVGA3D_RS_WRAP2: /* SVGA3dWrapFlags */
|
---|
4888 | glTexParameter GL_TEXTURE_WRAP_R
|
---|
4889 | renderState = D3DRS_WRAP2;
|
---|
4890 | val = pRenderState[i].uintValue;
|
---|
4891 | break;
|
---|
4892 |
|
---|
4893 |
|
---|
4894 | case SVGA3D_RS_SEPARATEALPHABLENDENABLE: /* SVGA3dBool */
|
---|
4895 | renderState = D3DRS_SEPARATEALPHABLENDENABLE;
|
---|
4896 | val = pRenderState[i].uintValue;
|
---|
4897 | break;
|
---|
4898 |
|
---|
4899 |
|
---|
4900 | case SVGA3D_RS_BLENDEQUATIONALPHA: /* SVGA3dBlendEquation */
|
---|
4901 | renderState = D3DRS_BLENDOPALPHA;
|
---|
4902 | val = pRenderState[i].uintValue;
|
---|
4903 | break;
|
---|
4904 |
|
---|
4905 | case SVGA3D_RS_TRANSPARENCYANTIALIAS: /* SVGA3dTransparencyAntialiasType */
|
---|
4906 | AssertFailed();
|
---|
4907 | /*
|
---|
4908 | renderState = D3DRS_TRANSPARENCYANTIALIAS;
|
---|
4909 | val = pRenderState[i].uintValue;
|
---|
4910 | */
|
---|
4911 | break;
|
---|
4912 |
|
---|
4913 | #endif
|
---|
4914 | default:
|
---|
4915 | AssertFailed();
|
---|
4916 | break;
|
---|
4917 | }
|
---|
4918 |
|
---|
4919 | if (enableCap != ~0U)
|
---|
4920 | {
|
---|
4921 | if (val)
|
---|
4922 | glEnable(enableCap);
|
---|
4923 | else
|
---|
4924 | glDisable(enableCap);
|
---|
4925 | }
|
---|
4926 | }
|
---|
4927 |
|
---|
4928 | return VINF_SUCCESS;
|
---|
4929 | }
|
---|
4930 |
|
---|
4931 | int vmsvga3dSetRenderTarget(PVGASTATE pThis, uint32_t cid, SVGA3dRenderTargetType type, SVGA3dSurfaceImageId target)
|
---|
4932 | {
|
---|
4933 | PVMSVGA3DCONTEXT pContext;
|
---|
4934 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
4935 | PVMSVGA3DSURFACE pRenderTarget;
|
---|
4936 |
|
---|
4937 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
4938 | AssertReturn(type < SVGA3D_RT_MAX, VERR_INVALID_PARAMETER);
|
---|
4939 | AssertReturn(target.face == 0, VERR_INVALID_PARAMETER);
|
---|
4940 | AssertReturn(target.mipmap == 0, VERR_INVALID_PARAMETER);
|
---|
4941 |
|
---|
4942 | Log(("vmsvga3dSetRenderTarget cid=%x type=%x surface id=%x\n", cid, type, target.sid));
|
---|
4943 |
|
---|
4944 | if ( cid >= pState->cContexts
|
---|
4945 | || pState->paContext[cid].id != cid)
|
---|
4946 | {
|
---|
4947 | Log(("vmsvga3dSetRenderTarget invalid context id!\n"));
|
---|
4948 | return VERR_INVALID_PARAMETER;
|
---|
4949 | }
|
---|
4950 | pContext = &pState->paContext[cid];
|
---|
4951 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
4952 |
|
---|
4953 | /* Save for vm state save/restore. */
|
---|
4954 | pContext->state.aRenderTargets[type] = target.sid;
|
---|
4955 |
|
---|
4956 | if (target.sid == SVGA3D_INVALID_ID)
|
---|
4957 | {
|
---|
4958 | /* Disable render target. */
|
---|
4959 | switch (type)
|
---|
4960 | {
|
---|
4961 | case SVGA3D_RT_DEPTH:
|
---|
4962 | case SVGA3D_RT_STENCIL:
|
---|
4963 | pState->ext.glFramebufferRenderbuffer(GL_FRAMEBUFFER, (type == SVGA3D_RT_DEPTH) ? GL_DEPTH_ATTACHMENT : GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
|
---|
4964 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4965 | break;
|
---|
4966 |
|
---|
4967 | case SVGA3D_RT_COLOR0:
|
---|
4968 | case SVGA3D_RT_COLOR1:
|
---|
4969 | case SVGA3D_RT_COLOR2:
|
---|
4970 | case SVGA3D_RT_COLOR3:
|
---|
4971 | case SVGA3D_RT_COLOR4:
|
---|
4972 | case SVGA3D_RT_COLOR5:
|
---|
4973 | case SVGA3D_RT_COLOR6:
|
---|
4974 | case SVGA3D_RT_COLOR7:
|
---|
4975 | pContext->sidRenderTarget = SVGA3D_INVALID_ID;
|
---|
4976 | pState->ext.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + type - SVGA3D_RT_COLOR0, 0, 0, 0);
|
---|
4977 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4978 | break;
|
---|
4979 |
|
---|
4980 | default:
|
---|
4981 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
4982 | }
|
---|
4983 | return VINF_SUCCESS;
|
---|
4984 | }
|
---|
4985 |
|
---|
4986 | AssertReturn(target.sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
4987 | AssertReturn(target.sid < pState->cSurfaces && pState->paSurface[target.sid].id == target.sid, VERR_INVALID_PARAMETER);
|
---|
4988 | pRenderTarget = &pState->paSurface[target.sid];
|
---|
4989 |
|
---|
4990 | switch (type)
|
---|
4991 | {
|
---|
4992 | case SVGA3D_RT_DEPTH:
|
---|
4993 | case SVGA3D_RT_STENCIL:
|
---|
4994 | if (pRenderTarget->oglId.texture == OPENGL_INVALID_ID)
|
---|
4995 | {
|
---|
4996 | Log(("vmsvga3dSetRenderTarget: create renderbuffer to be used as render target; surface id=%x type=%d format=%d\n", target.sid, pRenderTarget->flags, pRenderTarget->internalFormatGL));
|
---|
4997 | pState->ext.glGenRenderbuffers(1, &pRenderTarget->oglId.renderbuffer);
|
---|
4998 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
4999 |
|
---|
5000 | pState->ext.glBindRenderbuffer(GL_RENDERBUFFER, pRenderTarget->oglId.renderbuffer);
|
---|
5001 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5002 |
|
---|
5003 | pState->ext.glRenderbufferStorage(GL_RENDERBUFFER,
|
---|
5004 | pRenderTarget->internalFormatGL,
|
---|
5005 | pRenderTarget->pMipmapLevels[0].size.width,
|
---|
5006 | pRenderTarget->pMipmapLevels[0].size.height);
|
---|
5007 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5008 |
|
---|
5009 | pRenderTarget->idAssociatedContext = cid;
|
---|
5010 | }
|
---|
5011 | else
|
---|
5012 | {
|
---|
5013 | pState->ext.glBindRenderbuffer(GL_RENDERBUFFER, pRenderTarget->oglId.renderbuffer);
|
---|
5014 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5015 | }
|
---|
5016 | Assert(pRenderTarget->idAssociatedContext == cid);
|
---|
5017 | Assert(!pRenderTarget->fDirty);
|
---|
5018 | AssertReturn(pRenderTarget->oglId.texture != OPENGL_INVALID_ID, VERR_INVALID_PARAMETER);
|
---|
5019 |
|
---|
5020 | pRenderTarget->flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
|
---|
5021 |
|
---|
5022 | pState->ext.glFramebufferRenderbuffer(GL_FRAMEBUFFER, (type == SVGA3D_RT_DEPTH) ? GL_DEPTH_ATTACHMENT : GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, pRenderTarget->oglId.renderbuffer);
|
---|
5023 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5024 | break;
|
---|
5025 |
|
---|
5026 | case SVGA3D_RT_COLOR0:
|
---|
5027 | case SVGA3D_RT_COLOR1:
|
---|
5028 | case SVGA3D_RT_COLOR2:
|
---|
5029 | case SVGA3D_RT_COLOR3:
|
---|
5030 | case SVGA3D_RT_COLOR4:
|
---|
5031 | case SVGA3D_RT_COLOR5:
|
---|
5032 | case SVGA3D_RT_COLOR6:
|
---|
5033 | case SVGA3D_RT_COLOR7:
|
---|
5034 | {
|
---|
5035 | /* A texture surface can be used as a render target to fill it and later on used as a texture. */
|
---|
5036 | if (pRenderTarget->oglId.texture == OPENGL_INVALID_ID)
|
---|
5037 | {
|
---|
5038 | Log(("vmsvga3dSetRenderTarget: create texture to be used as render target; surface id=%x type=%d format=%d -> create texture\n", target.sid, pRenderTarget->flags, pRenderTarget->format));
|
---|
5039 | int rc = vmsvga3dCreateTexture(pState, pContext, cid, pRenderTarget);
|
---|
5040 | AssertRCReturn(rc, rc);
|
---|
5041 | }
|
---|
5042 |
|
---|
5043 | AssertReturn(pRenderTarget->oglId.texture != OPENGL_INVALID_ID, VERR_INVALID_PARAMETER);
|
---|
5044 | Assert(!pRenderTarget->fDirty);
|
---|
5045 |
|
---|
5046 | pRenderTarget->flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
|
---|
5047 |
|
---|
5048 | pState->ext.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + type - SVGA3D_RT_COLOR0, GL_TEXTURE_2D, pRenderTarget->oglId.texture, target.mipmap);
|
---|
5049 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5050 |
|
---|
5051 | pContext->sidRenderTarget = target.sid;
|
---|
5052 |
|
---|
5053 | #ifdef DEBUG
|
---|
5054 | GLenum status = pState->ext.glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
---|
5055 | if (status != GL_FRAMEBUFFER_COMPLETE)
|
---|
5056 | Log(("vmsvga3dSetRenderTarget: WARNING: glCheckFramebufferStatus returned %x\n", status));
|
---|
5057 | #endif
|
---|
5058 | /* @todo use glDrawBuffers too? */
|
---|
5059 | break;
|
---|
5060 | }
|
---|
5061 |
|
---|
5062 | default:
|
---|
5063 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
5064 | }
|
---|
5065 |
|
---|
5066 | return VINF_SUCCESS;
|
---|
5067 | }
|
---|
5068 |
|
---|
5069 | #if 0
|
---|
5070 | /**
|
---|
5071 | * Convert SVGA texture combiner value to its D3D equivalent
|
---|
5072 | */
|
---|
5073 | static DWORD vmsvga3dTextureCombiner2D3D(uint32_t value)
|
---|
5074 | {
|
---|
5075 | switch (value)
|
---|
5076 | {
|
---|
5077 | case SVGA3D_TC_DISABLE:
|
---|
5078 | return D3DTOP_DISABLE;
|
---|
5079 | case SVGA3D_TC_SELECTARG1:
|
---|
5080 | return D3DTOP_SELECTARG1;
|
---|
5081 | case SVGA3D_TC_SELECTARG2:
|
---|
5082 | return D3DTOP_SELECTARG2;
|
---|
5083 | case SVGA3D_TC_MODULATE:
|
---|
5084 | return D3DTOP_MODULATE;
|
---|
5085 | case SVGA3D_TC_ADD:
|
---|
5086 | return D3DTOP_ADD;
|
---|
5087 | case SVGA3D_TC_ADDSIGNED:
|
---|
5088 | return D3DTOP_ADDSIGNED;
|
---|
5089 | case SVGA3D_TC_SUBTRACT:
|
---|
5090 | return D3DTOP_SUBTRACT;
|
---|
5091 | case SVGA3D_TC_BLENDTEXTUREALPHA:
|
---|
5092 | return D3DTOP_BLENDTEXTUREALPHA;
|
---|
5093 | case SVGA3D_TC_BLENDDIFFUSEALPHA:
|
---|
5094 | return D3DTOP_BLENDDIFFUSEALPHA;
|
---|
5095 | case SVGA3D_TC_BLENDCURRENTALPHA:
|
---|
5096 | return D3DTOP_BLENDCURRENTALPHA;
|
---|
5097 | case SVGA3D_TC_BLENDFACTORALPHA:
|
---|
5098 | return D3DTOP_BLENDFACTORALPHA;
|
---|
5099 | case SVGA3D_TC_MODULATE2X:
|
---|
5100 | return D3DTOP_MODULATE2X;
|
---|
5101 | case SVGA3D_TC_MODULATE4X:
|
---|
5102 | return D3DTOP_MODULATE4X;
|
---|
5103 | case SVGA3D_TC_DSDT:
|
---|
5104 | AssertFailed(); /* @todo ??? */
|
---|
5105 | return D3DTOP_DISABLE;
|
---|
5106 | case SVGA3D_TC_DOTPRODUCT3:
|
---|
5107 | return D3DTOP_DOTPRODUCT3;
|
---|
5108 | case SVGA3D_TC_BLENDTEXTUREALPHAPM:
|
---|
5109 | return D3DTOP_BLENDTEXTUREALPHAPM;
|
---|
5110 | case SVGA3D_TC_ADDSIGNED2X:
|
---|
5111 | return D3DTOP_ADDSIGNED2X;
|
---|
5112 | case SVGA3D_TC_ADDSMOOTH:
|
---|
5113 | return D3DTOP_ADDSMOOTH;
|
---|
5114 | case SVGA3D_TC_PREMODULATE:
|
---|
5115 | return D3DTOP_PREMODULATE;
|
---|
5116 | case SVGA3D_TC_MODULATEALPHA_ADDCOLOR:
|
---|
5117 | return D3DTOP_MODULATEALPHA_ADDCOLOR;
|
---|
5118 | case SVGA3D_TC_MODULATECOLOR_ADDALPHA:
|
---|
5119 | return D3DTOP_MODULATECOLOR_ADDALPHA;
|
---|
5120 | case SVGA3D_TC_MODULATEINVALPHA_ADDCOLOR:
|
---|
5121 | return D3DTOP_MODULATEINVALPHA_ADDCOLOR;
|
---|
5122 | case SVGA3D_TC_MODULATEINVCOLOR_ADDALPHA:
|
---|
5123 | return D3DTOP_MODULATEINVCOLOR_ADDALPHA;
|
---|
5124 | case SVGA3D_TC_BUMPENVMAPLUMINANCE:
|
---|
5125 | return D3DTOP_BUMPENVMAPLUMINANCE;
|
---|
5126 | case SVGA3D_TC_MULTIPLYADD:
|
---|
5127 | return D3DTOP_MULTIPLYADD;
|
---|
5128 | case SVGA3D_TC_LERP:
|
---|
5129 | return D3DTOP_LERP;
|
---|
5130 | default:
|
---|
5131 | AssertFailed();
|
---|
5132 | return D3DTOP_DISABLE;
|
---|
5133 | }
|
---|
5134 | }
|
---|
5135 |
|
---|
5136 | /**
|
---|
5137 | * Convert SVGA texture arg data value to its D3D equivalent
|
---|
5138 | */
|
---|
5139 | static DWORD vmsvga3dTextureArgData2D3D(uint32_t value)
|
---|
5140 | {
|
---|
5141 | switch (value)
|
---|
5142 | {
|
---|
5143 | case SVGA3D_TA_CONSTANT:
|
---|
5144 | return D3DTA_CONSTANT;
|
---|
5145 | case SVGA3D_TA_PREVIOUS:
|
---|
5146 | return D3DTA_CURRENT; /* current = previous */
|
---|
5147 | case SVGA3D_TA_DIFFUSE:
|
---|
5148 | return D3DTA_DIFFUSE;
|
---|
5149 | case SVGA3D_TA_TEXTURE:
|
---|
5150 | return D3DTA_TEXTURE;
|
---|
5151 | case SVGA3D_TA_SPECULAR:
|
---|
5152 | return D3DTA_SPECULAR;
|
---|
5153 | default:
|
---|
5154 | AssertFailed();
|
---|
5155 | return 0;
|
---|
5156 | }
|
---|
5157 | }
|
---|
5158 |
|
---|
5159 | /**
|
---|
5160 | * Convert SVGA texture transform flag value to its D3D equivalent
|
---|
5161 | */
|
---|
5162 | static DWORD vmsvga3dTextTransformFlags2D3D(uint32_t value)
|
---|
5163 | {
|
---|
5164 | switch (value)
|
---|
5165 | {
|
---|
5166 | case SVGA3D_TEX_TRANSFORM_OFF:
|
---|
5167 | return D3DTTFF_DISABLE;
|
---|
5168 | case SVGA3D_TEX_TRANSFORM_S:
|
---|
5169 | return D3DTTFF_COUNT1; /* @todo correct? */
|
---|
5170 | case SVGA3D_TEX_TRANSFORM_T:
|
---|
5171 | return D3DTTFF_COUNT2; /* @todo correct? */
|
---|
5172 | case SVGA3D_TEX_TRANSFORM_R:
|
---|
5173 | return D3DTTFF_COUNT3; /* @todo correct? */
|
---|
5174 | case SVGA3D_TEX_TRANSFORM_Q:
|
---|
5175 | return D3DTTFF_COUNT4; /* @todo correct? */
|
---|
5176 | case SVGA3D_TEX_PROJECTED:
|
---|
5177 | return D3DTTFF_PROJECTED;
|
---|
5178 | default:
|
---|
5179 | AssertFailed();
|
---|
5180 | return 0;
|
---|
5181 | }
|
---|
5182 | }
|
---|
5183 | #endif
|
---|
5184 |
|
---|
5185 | static GLenum vmsvga3dTextureAddress2OGL(SVGA3dTextureAddress value)
|
---|
5186 | {
|
---|
5187 | switch (value)
|
---|
5188 | {
|
---|
5189 | case SVGA3D_TEX_ADDRESS_WRAP:
|
---|
5190 | return GL_REPEAT;
|
---|
5191 | case SVGA3D_TEX_ADDRESS_MIRROR:
|
---|
5192 | return GL_MIRRORED_REPEAT;
|
---|
5193 | case SVGA3D_TEX_ADDRESS_CLAMP:
|
---|
5194 | return GL_CLAMP_TO_EDGE;
|
---|
5195 | case SVGA3D_TEX_ADDRESS_BORDER:
|
---|
5196 | return GL_CLAMP_TO_BORDER;
|
---|
5197 | case SVGA3D_TEX_ADDRESS_MIRRORONCE:
|
---|
5198 | AssertFailed();
|
---|
5199 | return GL_CLAMP_TO_EDGE_SGIS; /* @todo correct? */
|
---|
5200 |
|
---|
5201 | case SVGA3D_TEX_ADDRESS_EDGE:
|
---|
5202 | case SVGA3D_TEX_ADDRESS_INVALID:
|
---|
5203 | default:
|
---|
5204 | AssertFailed();
|
---|
5205 | return GL_REPEAT; /* default */
|
---|
5206 | }
|
---|
5207 | }
|
---|
5208 |
|
---|
5209 | static GLenum vmsvga3dTextureFilter2OGL(SVGA3dTextureFilter value)
|
---|
5210 | {
|
---|
5211 | switch (value)
|
---|
5212 | {
|
---|
5213 | case SVGA3D_TEX_FILTER_NONE:
|
---|
5214 | case SVGA3D_TEX_FILTER_LINEAR:
|
---|
5215 | return GL_LINEAR;
|
---|
5216 | case SVGA3D_TEX_FILTER_NEAREST:
|
---|
5217 | return GL_NEAREST;
|
---|
5218 | case SVGA3D_TEX_FILTER_ANISOTROPIC:
|
---|
5219 | /* @todo */
|
---|
5220 | case SVGA3D_TEX_FILTER_FLATCUBIC: // Deprecated, not implemented
|
---|
5221 | case SVGA3D_TEX_FILTER_GAUSSIANCUBIC: // Deprecated, not implemented
|
---|
5222 | case SVGA3D_TEX_FILTER_PYRAMIDALQUAD: // Not currently implemented
|
---|
5223 | case SVGA3D_TEX_FILTER_GAUSSIANQUAD: // Not currently implemented
|
---|
5224 | default:
|
---|
5225 | AssertFailed();
|
---|
5226 | return GL_LINEAR; /* default */
|
---|
5227 | }
|
---|
5228 | }
|
---|
5229 |
|
---|
5230 | uint32_t vmsvga3dSVGA3dColor2RGBA(SVGA3dColor value)
|
---|
5231 | {
|
---|
5232 | /* flip the red and blue bytes */
|
---|
5233 | uint8_t blue = value & 0xff;
|
---|
5234 | uint8_t red = (value >> 16) & 0xff;
|
---|
5235 | return (value & 0xff00ff00) | red | (blue << 16);
|
---|
5236 | }
|
---|
5237 |
|
---|
5238 | int vmsvga3dSetTextureState(PVGASTATE pThis, uint32_t cid, uint32_t cTextureStates, SVGA3dTextureState *pTextureState)
|
---|
5239 | {
|
---|
5240 | GLenum val;
|
---|
5241 | GLenum currentStage = ~0L;
|
---|
5242 | PVMSVGA3DCONTEXT pContext;
|
---|
5243 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
5244 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
5245 |
|
---|
5246 | Log(("vmsvga3dSetTextureState %x cTextureState=%d\n", cid, cTextureStates));
|
---|
5247 |
|
---|
5248 | if ( cid >= pState->cContexts
|
---|
5249 | || pState->paContext[cid].id != cid)
|
---|
5250 | {
|
---|
5251 | Log(("vmsvga3dSetTextureState invalid context id!\n"));
|
---|
5252 | return VERR_INVALID_PARAMETER;
|
---|
5253 | }
|
---|
5254 | pContext = &pState->paContext[cid];
|
---|
5255 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
5256 |
|
---|
5257 | for (unsigned i = 0; i < cTextureStates; i++)
|
---|
5258 | {
|
---|
5259 | GLenum textureType = ~0U;
|
---|
5260 | GLenum samplerType = ~0U;
|
---|
5261 |
|
---|
5262 | Log(("vmsvga3dSetTextureState: cid=%x stage=%d type=%s (%x) val=%x\n", cid, pTextureState[i].stage, vmsvga3dTextureStateToString(pTextureState[i].name), pTextureState[i].name, pTextureState[i].value));
|
---|
5263 | /* Record the texture state for vm state saving. */
|
---|
5264 | if ( pTextureState[i].stage < SVGA3D_MAX_TEXTURE_STAGE
|
---|
5265 | && pTextureState[i].name < SVGA3D_TS_MAX)
|
---|
5266 | {
|
---|
5267 | pContext->state.aTextureState[pTextureState[i].stage][pTextureState[i].name] = pTextureState[i];
|
---|
5268 | }
|
---|
5269 |
|
---|
5270 | /* Active the right texture unit for subsequent texture state changes. */
|
---|
5271 | if (pTextureState[i].stage != currentStage)
|
---|
5272 | {
|
---|
5273 | pState->ext.glActiveTexture(GL_TEXTURE0 + pTextureState[i].stage);
|
---|
5274 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5275 | currentStage = pTextureState[i].stage;
|
---|
5276 | }
|
---|
5277 |
|
---|
5278 | switch (pTextureState[i].name)
|
---|
5279 | {
|
---|
5280 | case SVGA3D_TS_BUMPENVMAT00: /* float */
|
---|
5281 | case SVGA3D_TS_BUMPENVMAT01: /* float */
|
---|
5282 | case SVGA3D_TS_BUMPENVMAT10: /* float */
|
---|
5283 | case SVGA3D_TS_BUMPENVMAT11: /* float */
|
---|
5284 | case SVGA3D_TS_BUMPENVLSCALE: /* float */
|
---|
5285 | case SVGA3D_TS_BUMPENVLOFFSET: /* float */
|
---|
5286 | Log(("vmsvga3dSetTextureState: bump mapping texture options not supported!!\n"));
|
---|
5287 | break;
|
---|
5288 |
|
---|
5289 | case SVGA3D_TS_COLOROP: /* SVGA3dTextureCombiner */
|
---|
5290 | case SVGA3D_TS_COLORARG0: /* SVGA3dTextureArgData */
|
---|
5291 | case SVGA3D_TS_COLORARG1: /* SVGA3dTextureArgData */
|
---|
5292 | case SVGA3D_TS_COLORARG2: /* SVGA3dTextureArgData */
|
---|
5293 | case SVGA3D_TS_ALPHAOP: /* SVGA3dTextureCombiner */
|
---|
5294 | case SVGA3D_TS_ALPHAARG0: /* SVGA3dTextureArgData */
|
---|
5295 | case SVGA3D_TS_ALPHAARG1: /* SVGA3dTextureArgData */
|
---|
5296 | case SVGA3D_TS_ALPHAARG2: /* SVGA3dTextureArgData */
|
---|
5297 | /* @todo; not used by MesaGL */
|
---|
5298 | Log(("vmsvga3dSetTextureState: colorop/alphaop not yet supported!!\n"));
|
---|
5299 | break;
|
---|
5300 | #if 0
|
---|
5301 |
|
---|
5302 | case SVGA3D_TS_TEXCOORDINDEX: /* uint32_t */
|
---|
5303 | textureType = D3DTSS_TEXCOORDINDEX;
|
---|
5304 | val = pTextureState[i].value;
|
---|
5305 | break;
|
---|
5306 |
|
---|
5307 | case SVGA3D_TS_TEXTURETRANSFORMFLAGS: /* SVGA3dTexTransformFlags */
|
---|
5308 | textureType = D3DTSS_TEXTURETRANSFORMFLAGS;
|
---|
5309 | val = vmsvga3dTextTransformFlags2D3D(pTextureState[i].value);
|
---|
5310 | break;
|
---|
5311 | #endif
|
---|
5312 |
|
---|
5313 | case SVGA3D_TS_BIND_TEXTURE: /* SVGA3dSurfaceId */
|
---|
5314 | if (pTextureState[i].value == SVGA3D_INVALID_ID)
|
---|
5315 | {
|
---|
5316 | Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture surface id=%x\n", pTextureState[i].stage, pTextureState[i].value));
|
---|
5317 |
|
---|
5318 | pContext->aSidActiveTexture[currentStage] = SVGA3D_INVALID_ID;
|
---|
5319 | /* Unselect the currently associated texture. */
|
---|
5320 | glBindTexture(GL_TEXTURE_2D, 0);
|
---|
5321 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5322 | /* Necessary for the fixed pipeline. */
|
---|
5323 | glDisable(GL_TEXTURE_2D);
|
---|
5324 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5325 | }
|
---|
5326 | else
|
---|
5327 | {
|
---|
5328 | uint32_t sid = pTextureState[i].value;
|
---|
5329 |
|
---|
5330 | AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
5331 | AssertReturn(sid < pState->cSurfaces && pState->paSurface[sid].id == sid, VERR_INVALID_PARAMETER);
|
---|
5332 |
|
---|
5333 | PVMSVGA3DSURFACE pSurface = &pState->paSurface[sid];
|
---|
5334 |
|
---|
5335 | Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture surface id=%x (%d,%d)\n", pTextureState[i].stage, pTextureState[i].value, pSurface->pMipmapLevels[0].size.width, pSurface->pMipmapLevels[0].size.height));
|
---|
5336 |
|
---|
5337 | if (pSurface->oglId.texture == OPENGL_INVALID_ID)
|
---|
5338 | {
|
---|
5339 | Assert(pSurface->idAssociatedContext == SVGA3D_INVALID_ID);
|
---|
5340 | Log(("CreateTexture (%d,%d) level=%d\n", pSurface->pMipmapLevels[0].size.width, pSurface->pMipmapLevels[0].size.height, pSurface->faces[0].numMipLevels));
|
---|
5341 | int rc = vmsvga3dCreateTexture(pState, pContext, cid, pSurface);
|
---|
5342 | AssertRCReturn(rc, rc);
|
---|
5343 | }
|
---|
5344 |
|
---|
5345 | glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
|
---|
5346 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5347 |
|
---|
5348 | /* Necessary for the fixed pipeline. */
|
---|
5349 | glEnable(GL_TEXTURE_2D);
|
---|
5350 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5351 |
|
---|
5352 | if (pContext->aSidActiveTexture[currentStage] != sid)
|
---|
5353 | {
|
---|
5354 | /* Recreate the texture state as glBindTexture resets them all (sigh). */
|
---|
5355 | for (uint32_t iStage = 0; iStage < SVGA3D_MAX_TEXTURE_STAGE; iStage++)
|
---|
5356 | {
|
---|
5357 | for (uint32_t j = 0; j < SVGA3D_TS_MAX; j++)
|
---|
5358 | {
|
---|
5359 | SVGA3dTextureState *pTextureStateIter = &pContext->state.aTextureState[iStage][j];
|
---|
5360 |
|
---|
5361 | if ( pTextureStateIter->name != SVGA3D_TS_INVALID
|
---|
5362 | && pTextureStateIter->name != SVGA3D_TS_BIND_TEXTURE)
|
---|
5363 | vmsvga3dSetTextureState(pThis, pContext->id, 1, pTextureStateIter);
|
---|
5364 | }
|
---|
5365 | }
|
---|
5366 | }
|
---|
5367 | pContext->aSidActiveTexture[currentStage] = sid;
|
---|
5368 | }
|
---|
5369 | /* Finished; continue with the next one. */
|
---|
5370 | continue;
|
---|
5371 |
|
---|
5372 | case SVGA3D_TS_ADDRESSW: /* SVGA3dTextureAddress */
|
---|
5373 | textureType = GL_TEXTURE_WRAP_R; /* R = W */
|
---|
5374 | val = vmsvga3dTextureAddress2OGL((SVGA3dTextureAddress)pTextureState[i].value);
|
---|
5375 | break;
|
---|
5376 |
|
---|
5377 | case SVGA3D_TS_ADDRESSU: /* SVGA3dTextureAddress */
|
---|
5378 | textureType = GL_TEXTURE_WRAP_S; /* S = U */
|
---|
5379 | val = vmsvga3dTextureAddress2OGL((SVGA3dTextureAddress)pTextureState[i].value);
|
---|
5380 | break;
|
---|
5381 |
|
---|
5382 | case SVGA3D_TS_ADDRESSV: /* SVGA3dTextureAddress */
|
---|
5383 | textureType = GL_TEXTURE_WRAP_T; /* T = V */
|
---|
5384 | val = vmsvga3dTextureAddress2OGL((SVGA3dTextureAddress)pTextureState[i].value);
|
---|
5385 | break;
|
---|
5386 |
|
---|
5387 | case SVGA3D_TS_MIPFILTER: /* SVGA3dTextureFilter */
|
---|
5388 | //AssertFailed(); /* @todo */
|
---|
5389 | //samplerType = D3DSAMP_MIPFILTER;
|
---|
5390 | val = vmsvga3dTextureFilter2OGL((SVGA3dTextureFilter)pTextureState[i].value);
|
---|
5391 | break;
|
---|
5392 |
|
---|
5393 | case SVGA3D_TS_MAGFILTER: /* SVGA3dTextureFilter */
|
---|
5394 | textureType = GL_TEXTURE_MAG_FILTER;
|
---|
5395 | val = vmsvga3dTextureFilter2OGL((SVGA3dTextureFilter)pTextureState[i].value);
|
---|
5396 | Assert(val == GL_NEAREST || val == GL_LINEAR);
|
---|
5397 | break;
|
---|
5398 |
|
---|
5399 | case SVGA3D_TS_MINFILTER: /* SVGA3dTextureFilter */
|
---|
5400 | textureType = GL_TEXTURE_MIN_FILTER;
|
---|
5401 | val = vmsvga3dTextureFilter2OGL((SVGA3dTextureFilter)pTextureState[i].value);
|
---|
5402 | break;
|
---|
5403 |
|
---|
5404 | case SVGA3D_TS_BORDERCOLOR: /* SVGA3dColor */
|
---|
5405 | {
|
---|
5406 | GLfloat color[4]; /* red, green, blue, alpha */
|
---|
5407 |
|
---|
5408 | vmsvgaColor2GLFloatArray(pTextureState[i].value, &color[0], &color[1], &color[2], &color[3]);
|
---|
5409 |
|
---|
5410 | glTexParameterfv(GL_TEXTURE_2D /* @todo flexible type */, GL_TEXTURE_BORDER_COLOR, color); /* Identical; default 0.0 identical too */
|
---|
5411 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5412 | break;
|
---|
5413 | }
|
---|
5414 |
|
---|
5415 | case SVGA3D_TS_TEXTURE_LOD_BIAS: /* float */
|
---|
5416 | glTexParameterf(GL_TEXTURE_2D /* @todo flexible type */, GL_TEXTURE_LOD_BIAS, pTextureState[i].value); /* Identical; default 0.0 identical too */
|
---|
5417 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5418 | break;
|
---|
5419 |
|
---|
5420 | case SVGA3D_TS_TEXTURE_MIPMAP_LEVEL: /* uint32_t */
|
---|
5421 | textureType = GL_TEXTURE_MAX_LEVEL;
|
---|
5422 | val = pTextureState[i].value; /* Identical?? */
|
---|
5423 | break;
|
---|
5424 |
|
---|
5425 | #if 0
|
---|
5426 | case SVGA3D_TS_TEXTURE_ANISOTROPIC_LEVEL: /* uint32_t */
|
---|
5427 | samplerType = D3DSAMP_MAXANISOTROPY;
|
---|
5428 | val = pTextureState[i].value; /* Identical?? */
|
---|
5429 | break;
|
---|
5430 |
|
---|
5431 | case SVGA3D_TS_GAMMA: /* float */
|
---|
5432 | samplerType = D3DSAMP_SRGBTEXTURE;
|
---|
5433 | /* Boolean in D3D */
|
---|
5434 | if (pTextureState[i].floatValue == 1.0f)
|
---|
5435 | val = FALSE;
|
---|
5436 | else
|
---|
5437 | val = TRUE;
|
---|
5438 | break;
|
---|
5439 | #endif
|
---|
5440 | /* Internal commands, that don't map directly to the SetTextureStageState API. */
|
---|
5441 | case SVGA3D_TS_TEXCOORDGEN: /* SVGA3dTextureCoordGen */
|
---|
5442 | AssertFailed();
|
---|
5443 | break;
|
---|
5444 |
|
---|
5445 | default:
|
---|
5446 | //AssertFailed();
|
---|
5447 | break;
|
---|
5448 | }
|
---|
5449 |
|
---|
5450 | if (textureType != ~0U)
|
---|
5451 | {
|
---|
5452 | glTexParameteri(GL_TEXTURE_2D /* @todo flexible type */, textureType, val);
|
---|
5453 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5454 | }
|
---|
5455 | }
|
---|
5456 |
|
---|
5457 | return VINF_SUCCESS;
|
---|
5458 | }
|
---|
5459 |
|
---|
5460 | int vmsvga3dSetMaterial(PVGASTATE pThis, uint32_t cid, SVGA3dFace face, SVGA3dMaterial *pMaterial)
|
---|
5461 | {
|
---|
5462 | PVMSVGA3DCONTEXT pContext;
|
---|
5463 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
5464 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
5465 | GLenum oglFace;
|
---|
5466 |
|
---|
5467 | Log(("vmsvga3dSetMaterial cid=%x face %d\n", cid, face));
|
---|
5468 |
|
---|
5469 | if ( cid >= pState->cContexts
|
---|
5470 | || pState->paContext[cid].id != cid)
|
---|
5471 | {
|
---|
5472 | Log(("vmsvga3dSetMaterial invalid context id!\n"));
|
---|
5473 | return VERR_INVALID_PARAMETER;
|
---|
5474 | }
|
---|
5475 | pContext = &pState->paContext[cid];
|
---|
5476 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
5477 |
|
---|
5478 | switch (face)
|
---|
5479 | {
|
---|
5480 | case SVGA3D_FACE_NONE:
|
---|
5481 | case SVGA3D_FACE_FRONT:
|
---|
5482 | oglFace = GL_FRONT;
|
---|
5483 | break;
|
---|
5484 |
|
---|
5485 | case SVGA3D_FACE_BACK:
|
---|
5486 | oglFace = GL_BACK;
|
---|
5487 | break;
|
---|
5488 |
|
---|
5489 | case SVGA3D_FACE_FRONT_BACK:
|
---|
5490 | oglFace = GL_FRONT_AND_BACK;
|
---|
5491 | break;
|
---|
5492 |
|
---|
5493 | default:
|
---|
5494 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
5495 | }
|
---|
5496 |
|
---|
5497 | /* Save for vm state save/restore. */
|
---|
5498 | pContext->state.aMaterial[face].fValid = true;
|
---|
5499 | pContext->state.aMaterial[face].material = *pMaterial;
|
---|
5500 | pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_MATERIAL;
|
---|
5501 |
|
---|
5502 | glMaterialfv(oglFace, GL_DIFFUSE, pMaterial->diffuse);
|
---|
5503 | glMaterialfv(oglFace, GL_AMBIENT, pMaterial->ambient);
|
---|
5504 | glMaterialfv(oglFace, GL_SPECULAR, pMaterial->specular);
|
---|
5505 | glMaterialfv(oglFace, GL_EMISSION, pMaterial->emissive);
|
---|
5506 | glMaterialfv(oglFace, GL_SHININESS, &pMaterial->shininess);
|
---|
5507 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5508 |
|
---|
5509 | return VINF_SUCCESS;
|
---|
5510 | }
|
---|
5511 |
|
---|
5512 | /* @todo Move into separate library as we are using logic from Wine here. */
|
---|
5513 | int vmsvga3dSetLightData(PVGASTATE pThis, uint32_t cid, uint32_t index, SVGA3dLightData *pData)
|
---|
5514 | {
|
---|
5515 | PVMSVGA3DCONTEXT pContext;
|
---|
5516 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
5517 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
5518 | float QuadAttenuation;
|
---|
5519 |
|
---|
5520 | Log(("vmsvga3dSetLightData cid=%x index=%d type=%d\n", cid, index, pData->type));
|
---|
5521 |
|
---|
5522 | if ( cid >= pState->cContexts
|
---|
5523 | || pState->paContext[cid].id != cid)
|
---|
5524 | {
|
---|
5525 | Log(("vmsvga3dSetLightData invalid context id!\n"));
|
---|
5526 | return VERR_INVALID_PARAMETER;
|
---|
5527 | }
|
---|
5528 | pContext = &pState->paContext[cid];
|
---|
5529 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
5530 |
|
---|
5531 | /* Store for vm state save/restore */
|
---|
5532 | if (index < SVGA3D_MAX_LIGHTS)
|
---|
5533 | {
|
---|
5534 | pContext->state.aLightData[index].fValidData = true;
|
---|
5535 | pContext->state.aLightData[index].data = *pData;
|
---|
5536 | }
|
---|
5537 | else
|
---|
5538 | AssertFailed();
|
---|
5539 |
|
---|
5540 | if ( pData->attenuation0 < 0.0f
|
---|
5541 | || pData->attenuation1 < 0.0f
|
---|
5542 | || pData->attenuation2 < 0.0f)
|
---|
5543 | {
|
---|
5544 | Log(("vmsvga3dSetLightData: invalid negative attenuation values!!\n"));
|
---|
5545 | return VINF_SUCCESS; /* ignore; could crash the GL driver */
|
---|
5546 | }
|
---|
5547 |
|
---|
5548 | /* Light settings are affected by the model view in OpenGL, the View transform in direct3d */
|
---|
5549 | glMatrixMode(GL_MODELVIEW);
|
---|
5550 | glPushMatrix();
|
---|
5551 | glLoadMatrixf(pContext->state.aTransformState[SVGA3D_TRANSFORM_VIEW].matrix);
|
---|
5552 |
|
---|
5553 | glLightfv(GL_LIGHT0 + index, GL_DIFFUSE, pData->diffuse);
|
---|
5554 | glLightfv(GL_LIGHT0 + index, GL_SPECULAR, pData->specular);
|
---|
5555 | glLightfv(GL_LIGHT0 + index, GL_AMBIENT, pData->ambient);
|
---|
5556 |
|
---|
5557 | if (pData->range * pData->range >= FLT_MIN)
|
---|
5558 | QuadAttenuation = 1.4f / (pData->range * pData->range);
|
---|
5559 | else
|
---|
5560 | QuadAttenuation = 0.0f;
|
---|
5561 |
|
---|
5562 | switch (pData->type)
|
---|
5563 | {
|
---|
5564 | case SVGA3D_LIGHTTYPE_POINT:
|
---|
5565 | {
|
---|
5566 | GLfloat position[4];
|
---|
5567 |
|
---|
5568 | position[0] = pData->position[0];
|
---|
5569 | position[1] = pData->position[1];
|
---|
5570 | position[2] = pData->position[2];
|
---|
5571 | position[3] = 1.0f;
|
---|
5572 |
|
---|
5573 | glLightfv(GL_LIGHT0 + index, GL_POSITION, position);
|
---|
5574 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5575 |
|
---|
5576 | glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, 180.0f);
|
---|
5577 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5578 |
|
---|
5579 | /* Attenuation - Are these right? guessing... */
|
---|
5580 | glLightf(GL_LIGHT0 + index, GL_CONSTANT_ATTENUATION, pData->attenuation0);
|
---|
5581 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5582 |
|
---|
5583 | glLightf(GL_LIGHT0 + index, GL_LINEAR_ATTENUATION, pData->attenuation1);
|
---|
5584 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5585 |
|
---|
5586 | glLightf(GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION, (QuadAttenuation < pData->attenuation2) ? pData->attenuation2 : QuadAttenuation);
|
---|
5587 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5588 |
|
---|
5589 | /* @todo range */
|
---|
5590 | break;
|
---|
5591 | }
|
---|
5592 |
|
---|
5593 | case SVGA3D_LIGHTTYPE_SPOT1:
|
---|
5594 | {
|
---|
5595 | GLfloat exponent;
|
---|
5596 | GLfloat position[4];
|
---|
5597 | const GLfloat pi = 4.0f * atanf(1.0f);
|
---|
5598 |
|
---|
5599 | position[0] = pData->position[0];
|
---|
5600 | position[1] = pData->position[1];
|
---|
5601 | position[2] = pData->position[2];
|
---|
5602 | position[3] = 1.0f;
|
---|
5603 |
|
---|
5604 | glLightfv(GL_LIGHT0 + index, GL_POSITION, position);
|
---|
5605 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5606 |
|
---|
5607 | position[0] = pData->direction[0];
|
---|
5608 | position[1] = pData->direction[1];
|
---|
5609 | position[2] = pData->direction[2];
|
---|
5610 | position[3] = 1.0f;
|
---|
5611 |
|
---|
5612 | glLightfv(GL_LIGHT0 + index, GL_SPOT_DIRECTION, position);
|
---|
5613 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5614 |
|
---|
5615 | /*
|
---|
5616 | * opengl-ish and d3d-ish spot lights use too different models for the
|
---|
5617 | * light "intensity" as a function of the angle towards the main light direction,
|
---|
5618 | * so we only can approximate very roughly.
|
---|
5619 | * however spot lights are rather rarely used in games (if ever used at all).
|
---|
5620 | * furthermore if still used, probably nobody pays attention to such details.
|
---|
5621 | */
|
---|
5622 | if (pData->falloff == 0)
|
---|
5623 | {
|
---|
5624 | /* Falloff = 0 is easy, because d3d's and opengl's spot light equations have the
|
---|
5625 | * falloff resp. exponent parameter as an exponent, so the spot light lighting
|
---|
5626 | * will always be 1.0 for both of them, and we don't have to care for the
|
---|
5627 | * rest of the rather complex calculation
|
---|
5628 | */
|
---|
5629 | exponent = 0.0f;
|
---|
5630 | }
|
---|
5631 | else
|
---|
5632 | {
|
---|
5633 | float rho = pData->theta + (pData->phi - pData->theta) / (2 * pData->falloff);
|
---|
5634 | if (rho < 0.0001f)
|
---|
5635 | rho = 0.0001f;
|
---|
5636 | exponent = -0.3f/log(cos(rho/2));
|
---|
5637 | }
|
---|
5638 | if (exponent > 128.0f)
|
---|
5639 | exponent = 128.0f;
|
---|
5640 |
|
---|
5641 | glLightf(GL_LIGHT0 + index, GL_SPOT_EXPONENT, exponent);
|
---|
5642 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5643 |
|
---|
5644 | glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, pData->phi * 90.0 / pi);
|
---|
5645 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5646 |
|
---|
5647 | /* Attenuation - Are these right? guessing... */
|
---|
5648 | glLightf(GL_LIGHT0 + index, GL_CONSTANT_ATTENUATION, pData->attenuation0);
|
---|
5649 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5650 |
|
---|
5651 | glLightf(GL_LIGHT0 + index, GL_LINEAR_ATTENUATION, pData->attenuation1);
|
---|
5652 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5653 |
|
---|
5654 | glLightf(GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION, (QuadAttenuation < pData->attenuation2) ? pData->attenuation2 : QuadAttenuation);
|
---|
5655 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5656 |
|
---|
5657 | /* @todo range */
|
---|
5658 | break;
|
---|
5659 | }
|
---|
5660 |
|
---|
5661 | case SVGA3D_LIGHTTYPE_DIRECTIONAL:
|
---|
5662 | {
|
---|
5663 | GLfloat position[4];
|
---|
5664 |
|
---|
5665 | position[0] = -pData->direction[0];
|
---|
5666 | position[1] = -pData->direction[1];
|
---|
5667 | position[2] = -pData->direction[2];
|
---|
5668 | position[3] = 0.0f;
|
---|
5669 |
|
---|
5670 | glLightfv(GL_LIGHT0 + index, GL_POSITION, position); /* Note gl uses w position of 0 for direction! */
|
---|
5671 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5672 |
|
---|
5673 | glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, 180.0f);
|
---|
5674 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5675 |
|
---|
5676 | glLightf(GL_LIGHT0 + index, GL_SPOT_EXPONENT, 0.0f);
|
---|
5677 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
5678 | break;
|
---|
5679 | }
|
---|
5680 |
|
---|
5681 | case SVGA3D_LIGHTTYPE_SPOT2:
|
---|
5682 | default:
|
---|
5683 | Log(("Unsupported light type!!\n"));
|
---|
5684 | return VERR_INVALID_PARAMETER;
|
---|
5685 | }
|
---|
5686 |
|
---|
5687 | /* Restore the modelview matrix */
|
---|
5688 | glPopMatrix();
|
---|
5689 |
|
---|
5690 | return VINF_SUCCESS;
|
---|
5691 | }
|
---|
5692 |
|
---|
5693 | int vmsvga3dSetLightEnabled(PVGASTATE pThis, uint32_t cid, uint32_t index, uint32_t enabled)
|
---|
5694 | {
|
---|
5695 | PVMSVGA3DCONTEXT pContext;
|
---|
5696 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
5697 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
5698 |
|
---|
5699 | Log(("vmsvga3dSetLightEnabled cid=%x %d -> %d\n", cid, index, enabled));
|
---|
5700 |
|
---|
5701 | if ( cid >= pState->cContexts
|
---|
5702 | || pState->paContext[cid].id != cid)
|
---|
5703 | {
|
---|
5704 | Log(("vmsvga3dSetLightEnabled invalid context id!\n"));
|
---|
5705 | return VERR_INVALID_PARAMETER;
|
---|
5706 | }
|
---|
5707 | pContext = &pState->paContext[cid];
|
---|
5708 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
5709 |
|
---|
5710 | /* Store for vm state save/restore */
|
---|
5711 | if (index < SVGA3D_MAX_LIGHTS)
|
---|
5712 | pContext->state.aLightData[index].fEnabled = !!enabled;
|
---|
5713 | else
|
---|
5714 | AssertFailed();
|
---|
5715 |
|
---|
5716 | if (enabled)
|
---|
5717 | {
|
---|
5718 | /* Load the default settings if none have been set yet. */
|
---|
5719 | if (!pContext->state.aLightData[index].fValidData)
|
---|
5720 | vmsvga3dSetLightData(pThis, cid, index, (SVGA3dLightData *)&vmsvga3d_default_light);
|
---|
5721 | glEnable(GL_LIGHT0 + index);
|
---|
5722 | }
|
---|
5723 | else
|
---|
5724 | glDisable(GL_LIGHT0 + index);
|
---|
5725 |
|
---|
5726 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5727 | return VINF_SUCCESS;
|
---|
5728 | }
|
---|
5729 |
|
---|
5730 | int vmsvga3dSetViewPort(PVGASTATE pThis, uint32_t cid, SVGA3dRect *pRect)
|
---|
5731 | {
|
---|
5732 | PVMSVGA3DCONTEXT pContext;
|
---|
5733 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
5734 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
5735 |
|
---|
5736 | Log(("vmsvga3dSetViewPort cid=%x (%d,%d)(%d,%d)\n", cid, pRect->x, pRect->y, pRect->w, pRect->h));
|
---|
5737 |
|
---|
5738 | if ( cid >= pState->cContexts
|
---|
5739 | || pState->paContext[cid].id != cid)
|
---|
5740 | {
|
---|
5741 | Log(("vmsvga3dSetViewPort invalid context id!\n"));
|
---|
5742 | return VERR_INVALID_PARAMETER;
|
---|
5743 | }
|
---|
5744 | pContext = &pState->paContext[cid];
|
---|
5745 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
5746 |
|
---|
5747 | /* Save for vm state save/restore. */
|
---|
5748 | pContext->state.RectViewPort = *pRect;
|
---|
5749 | pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_VIEWPORT;
|
---|
5750 |
|
---|
5751 | /* @todo y-inversion for partial viewport coordinates? */
|
---|
5752 | glViewport(pRect->x, pRect->y, pRect->w, pRect->h);
|
---|
5753 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5754 |
|
---|
5755 | /* Reset the projection matrix as that relies on the viewport setting. */
|
---|
5756 | if (pContext->state.aTransformState[SVGA3D_TRANSFORM_PROJECTION].fValid == true)
|
---|
5757 | {
|
---|
5758 | vmsvga3dSetTransform(pThis, cid, SVGA3D_TRANSFORM_PROJECTION, pContext->state.aTransformState[SVGA3D_TRANSFORM_PROJECTION].matrix);
|
---|
5759 | }
|
---|
5760 | else
|
---|
5761 | {
|
---|
5762 | float matrix[16];
|
---|
5763 |
|
---|
5764 | /* identity matrix if no matrix set. */
|
---|
5765 | memset(matrix, 0, sizeof(matrix));
|
---|
5766 | matrix[0] = 1.0;
|
---|
5767 | matrix[5] = 1.0;
|
---|
5768 | matrix[10] = 1.0;
|
---|
5769 | matrix[15] = 1.0;
|
---|
5770 | vmsvga3dSetTransform(pThis, cid, SVGA3D_TRANSFORM_PROJECTION, matrix);
|
---|
5771 | }
|
---|
5772 |
|
---|
5773 | return VINF_SUCCESS;
|
---|
5774 | }
|
---|
5775 |
|
---|
5776 | int vmsvga3dSetClipPlane(PVGASTATE pThis, uint32_t cid, uint32_t index, float plane[4])
|
---|
5777 | {
|
---|
5778 | PVMSVGA3DCONTEXT pContext;
|
---|
5779 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
5780 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
5781 | double oglPlane[4];
|
---|
5782 |
|
---|
5783 | Log(("vmsvga3dSetClipPlane cid=%x %d (%d,%d)(%d,%d)\n", cid, index, (unsigned)(plane[0] * 100.0), (unsigned)(plane[1] * 100.0), (unsigned)(plane[2] * 100.0), (unsigned)(plane[3] * 100.0)));
|
---|
5784 | AssertReturn(index < SVGA3D_CLIPPLANE_MAX, VERR_INVALID_PARAMETER);
|
---|
5785 |
|
---|
5786 | if ( cid >= pState->cContexts
|
---|
5787 | || pState->paContext[cid].id != cid)
|
---|
5788 | {
|
---|
5789 | Log(("vmsvga3dSetClipPlane invalid context id!\n"));
|
---|
5790 | return VERR_INVALID_PARAMETER;
|
---|
5791 | }
|
---|
5792 | pContext = &pState->paContext[cid];
|
---|
5793 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
5794 |
|
---|
5795 | /* Store for vm state save/restore. */
|
---|
5796 | pContext->state.aClipPlane[index].fValid = true;
|
---|
5797 | memcpy(pContext->state.aClipPlane[index].plane, plane, sizeof(plane));
|
---|
5798 |
|
---|
5799 | /* @todo clip plane affected by model view in OpenGL & view in D3D + vertex shader -> not transformed (see Wine; state.c clipplane) */
|
---|
5800 | oglPlane[0] = (double)plane[0];
|
---|
5801 | oglPlane[1] = (double)plane[1];
|
---|
5802 | oglPlane[2] = (double)plane[2];
|
---|
5803 | oglPlane[3] = (double)plane[3];
|
---|
5804 |
|
---|
5805 | glClipPlane(GL_CLIP_PLANE0 + index, oglPlane);
|
---|
5806 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5807 |
|
---|
5808 | return VINF_SUCCESS;
|
---|
5809 | }
|
---|
5810 |
|
---|
5811 | int vmsvga3dSetScissorRect(PVGASTATE pThis, uint32_t cid, SVGA3dRect *pRect)
|
---|
5812 | {
|
---|
5813 | PVMSVGA3DCONTEXT pContext;
|
---|
5814 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
5815 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
5816 |
|
---|
5817 | Log(("vmsvga3dSetScissorRect cid=%x (%d,%d)(%d,%d)\n", cid, pRect->x, pRect->y, pRect->w, pRect->h));
|
---|
5818 |
|
---|
5819 | if ( cid >= pState->cContexts
|
---|
5820 | || pState->paContext[cid].id != cid)
|
---|
5821 | {
|
---|
5822 | Log(("vmsvga3dSetScissorRect invalid context id!\n"));
|
---|
5823 | return VERR_INVALID_PARAMETER;
|
---|
5824 | }
|
---|
5825 | pContext = &pState->paContext[cid];
|
---|
5826 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
5827 |
|
---|
5828 | /* Store for vm state save/restore. */
|
---|
5829 | pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_SCISSORRECT;
|
---|
5830 | pContext->state.RectScissor = *pRect;
|
---|
5831 |
|
---|
5832 | glScissor(pRect->x, pRect->y, pRect->w, pRect->h);
|
---|
5833 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5834 |
|
---|
5835 | return VINF_SUCCESS;
|
---|
5836 | }
|
---|
5837 |
|
---|
5838 | static void vmsvgaColor2GLFloatArray(uint32_t color, GLfloat *pRed, GLfloat *pGreen, GLfloat *pBlue, GLfloat *pAlpha)
|
---|
5839 | {
|
---|
5840 | /* Convert byte color components to float (0-1.0) */
|
---|
5841 | *pAlpha = (GLfloat)(color >> 24) / 255.0;
|
---|
5842 | *pRed = (GLfloat)((color >> 16) & 0xff) / 255.0;
|
---|
5843 | *pGreen = (GLfloat)((color >> 8) & 0xff) / 255.0;
|
---|
5844 | *pBlue = (GLfloat)(color & 0xff) / 255.0;
|
---|
5845 | }
|
---|
5846 |
|
---|
5847 | int vmsvga3dCommandClear(PVGASTATE pThis, uint32_t cid, SVGA3dClearFlag clearFlag, uint32_t color, float depth, uint32_t stencil, uint32_t cRects, SVGA3dRect *pRect)
|
---|
5848 | {
|
---|
5849 | GLbitfield mask = 0;
|
---|
5850 | PVMSVGA3DCONTEXT pContext;
|
---|
5851 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
5852 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
5853 | GLboolean fDepthWriteEnabled = GL_FALSE;
|
---|
5854 |
|
---|
5855 | Log(("vmsvga3dCommandClear cid=%x clearFlag=%x color=%x depth=%d stencil=%x cRects=%d\n", cid, clearFlag, color, (uint32_t)(depth * 100.0), stencil, cRects));
|
---|
5856 |
|
---|
5857 | if ( cid >= pState->cContexts
|
---|
5858 | || pState->paContext[cid].id != cid)
|
---|
5859 | {
|
---|
5860 | Log(("vmsvga3dCommandClear invalid context id!\n"));
|
---|
5861 | return VERR_INVALID_PARAMETER;
|
---|
5862 | }
|
---|
5863 | pContext = &pState->paContext[cid];
|
---|
5864 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
5865 |
|
---|
5866 | if (clearFlag & SVGA3D_CLEAR_COLOR)
|
---|
5867 | {
|
---|
5868 | GLfloat red, green, blue, alpha;
|
---|
5869 |
|
---|
5870 | vmsvgaColor2GLFloatArray(color, &red, &green, &blue, &alpha);
|
---|
5871 |
|
---|
5872 | /* Set the color clear value. */
|
---|
5873 | glClearColor(red, green, blue, alpha);
|
---|
5874 |
|
---|
5875 | mask |= GL_COLOR_BUFFER_BIT;
|
---|
5876 | }
|
---|
5877 | if (clearFlag & SVGA3D_CLEAR_STENCIL)
|
---|
5878 | {
|
---|
5879 | /* @todo possibly the same problem as with glDepthMask */
|
---|
5880 | glClearStencil(stencil);
|
---|
5881 | mask |= GL_STENCIL_BUFFER_BIT;
|
---|
5882 | }
|
---|
5883 | if (clearFlag & SVGA3D_CLEAR_DEPTH)
|
---|
5884 | {
|
---|
5885 | glClearDepth((GLdouble)depth);
|
---|
5886 | mask |= GL_DEPTH_BUFFER_BIT;
|
---|
5887 |
|
---|
5888 | /* glClear will not clear the depth buffer if writing is disabled. */
|
---|
5889 | glGetBooleanv(GL_DEPTH_WRITEMASK, &fDepthWriteEnabled);
|
---|
5890 | if (fDepthWriteEnabled == GL_FALSE)
|
---|
5891 | glDepthMask(GL_TRUE);
|
---|
5892 | }
|
---|
5893 |
|
---|
5894 | if (cRects)
|
---|
5895 | {
|
---|
5896 | /* Save the current scissor test bit and scissor box. */
|
---|
5897 | glPushAttrib(GL_SCISSOR_BIT);
|
---|
5898 | glEnable(GL_SCISSOR_TEST);
|
---|
5899 | for (unsigned i=0; i < cRects; i++)
|
---|
5900 | {
|
---|
5901 | Log(("vmsvga3dCommandClear: rect %d (%d,%d)(%d,%d)\n", i, pRect[i].x, pRect[i].y, pRect[i].x + pRect[i].w, pRect[i].y + pRect[i].h));
|
---|
5902 | glScissor(pRect[i].x, pRect[i].y, pRect[i].w, pRect[i].h);
|
---|
5903 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5904 | glClear(mask);
|
---|
5905 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5906 | }
|
---|
5907 | /* Restore the old scissor test bit and box */
|
---|
5908 | glPopAttrib();
|
---|
5909 | }
|
---|
5910 | else
|
---|
5911 | {
|
---|
5912 | glClear(mask);
|
---|
5913 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
5914 | }
|
---|
5915 |
|
---|
5916 | /* Restore depth write state. */
|
---|
5917 | if ( (clearFlag & SVGA3D_CLEAR_DEPTH)
|
---|
5918 | && fDepthWriteEnabled == GL_FALSE)
|
---|
5919 | glDepthMask(GL_FALSE);
|
---|
5920 |
|
---|
5921 | return VINF_SUCCESS;
|
---|
5922 | }
|
---|
5923 |
|
---|
5924 | /* Convert VMWare vertex declaration to its OpenGL equivalent. */
|
---|
5925 | int vmsvga3dVertexDecl2OGL(SVGA3dVertexArrayIdentity &identity, GLint &size, GLenum &type, GLboolean &normalized)
|
---|
5926 | {
|
---|
5927 | normalized = GL_FALSE;
|
---|
5928 | switch (identity.type)
|
---|
5929 | {
|
---|
5930 | case SVGA3D_DECLTYPE_FLOAT1:
|
---|
5931 | size = 1;
|
---|
5932 | type = GL_FLOAT;
|
---|
5933 | break;
|
---|
5934 | case SVGA3D_DECLTYPE_FLOAT2:
|
---|
5935 | size = 2;
|
---|
5936 | type = GL_FLOAT;
|
---|
5937 | break;
|
---|
5938 | case SVGA3D_DECLTYPE_FLOAT3:
|
---|
5939 | size = 3;
|
---|
5940 | type = GL_FLOAT;
|
---|
5941 | break;
|
---|
5942 | case SVGA3D_DECLTYPE_FLOAT4:
|
---|
5943 | size = 4;
|
---|
5944 | type = GL_FLOAT;
|
---|
5945 | break;
|
---|
5946 |
|
---|
5947 | case SVGA3D_DECLTYPE_D3DCOLOR:
|
---|
5948 | size = GL_BGRA; /* @note requires GL_ARB_vertex_array_bgra */
|
---|
5949 | type = GL_UNSIGNED_BYTE;
|
---|
5950 | normalized = GL_TRUE; /* glVertexAttribPointer fails otherwise */
|
---|
5951 | break;
|
---|
5952 |
|
---|
5953 | case SVGA3D_DECLTYPE_UBYTE4N:
|
---|
5954 | normalized = GL_TRUE;
|
---|
5955 | /* no break */
|
---|
5956 | case SVGA3D_DECLTYPE_UBYTE4:
|
---|
5957 | size = 4;
|
---|
5958 | type = GL_UNSIGNED_BYTE;
|
---|
5959 | break;
|
---|
5960 |
|
---|
5961 | case SVGA3D_DECLTYPE_SHORT2N:
|
---|
5962 | normalized = GL_TRUE;
|
---|
5963 | /* no break */
|
---|
5964 | case SVGA3D_DECLTYPE_SHORT2:
|
---|
5965 | size = 2;
|
---|
5966 | type = GL_SHORT;
|
---|
5967 | break;
|
---|
5968 |
|
---|
5969 | case SVGA3D_DECLTYPE_SHORT4N:
|
---|
5970 | normalized = GL_TRUE;
|
---|
5971 | /* no break */
|
---|
5972 | case SVGA3D_DECLTYPE_SHORT4:
|
---|
5973 | size = 4;
|
---|
5974 | type = GL_SHORT;
|
---|
5975 | break;
|
---|
5976 |
|
---|
5977 | case SVGA3D_DECLTYPE_USHORT4N:
|
---|
5978 | normalized = GL_TRUE;
|
---|
5979 | size = 4;
|
---|
5980 | type = GL_UNSIGNED_SHORT;
|
---|
5981 | break;
|
---|
5982 |
|
---|
5983 | case SVGA3D_DECLTYPE_USHORT2N:
|
---|
5984 | normalized = GL_TRUE;
|
---|
5985 | size = 2;
|
---|
5986 | type = GL_UNSIGNED_SHORT;
|
---|
5987 | break;
|
---|
5988 |
|
---|
5989 | case SVGA3D_DECLTYPE_UDEC3:
|
---|
5990 | size = 3;
|
---|
5991 | type = GL_UNSIGNED_INT_2_10_10_10_REV; /* @todo correct? */
|
---|
5992 | break;
|
---|
5993 |
|
---|
5994 | case SVGA3D_DECLTYPE_DEC3N:
|
---|
5995 | normalized = true;
|
---|
5996 | size = 3;
|
---|
5997 | type = GL_INT_2_10_10_10_REV; /* @todo correct? */
|
---|
5998 | break;
|
---|
5999 |
|
---|
6000 | case SVGA3D_DECLTYPE_FLOAT16_2:
|
---|
6001 | size = 2;
|
---|
6002 | type = GL_HALF_FLOAT;
|
---|
6003 | break;
|
---|
6004 | case SVGA3D_DECLTYPE_FLOAT16_4:
|
---|
6005 | size = 4;
|
---|
6006 | type = GL_HALF_FLOAT;
|
---|
6007 | break;
|
---|
6008 | default:
|
---|
6009 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
6010 | }
|
---|
6011 |
|
---|
6012 | //pVertexElement->Method = identity.method;
|
---|
6013 | //pVertexElement->Usage = identity.usage;
|
---|
6014 |
|
---|
6015 | return VINF_SUCCESS;
|
---|
6016 | }
|
---|
6017 |
|
---|
6018 | /* Convert VMWare primitive type to its OpenGL equivalent. */
|
---|
6019 | /* Calculate the vertex count based on the primitive type and nr of primitives. */
|
---|
6020 | int vmsvga3dPrimitiveType2OGL(SVGA3dPrimitiveType PrimitiveType, GLenum *pMode, uint32_t cPrimitiveCount, uint32_t *pcVertices)
|
---|
6021 | {
|
---|
6022 | switch (PrimitiveType)
|
---|
6023 | {
|
---|
6024 | case SVGA3D_PRIMITIVE_TRIANGLELIST:
|
---|
6025 | *pMode = GL_TRIANGLES;
|
---|
6026 | *pcVertices = cPrimitiveCount * 3;
|
---|
6027 | break;
|
---|
6028 | case SVGA3D_PRIMITIVE_POINTLIST:
|
---|
6029 | *pMode = GL_POINTS;
|
---|
6030 | *pcVertices = cPrimitiveCount;
|
---|
6031 | break;
|
---|
6032 | case SVGA3D_PRIMITIVE_LINELIST:
|
---|
6033 | *pMode = GL_LINES;
|
---|
6034 | *pcVertices = cPrimitiveCount * 2;
|
---|
6035 | break;
|
---|
6036 | case SVGA3D_PRIMITIVE_LINESTRIP:
|
---|
6037 | *pMode = GL_LINE_STRIP;
|
---|
6038 | *pcVertices = cPrimitiveCount + 1;
|
---|
6039 | break;
|
---|
6040 | case SVGA3D_PRIMITIVE_TRIANGLESTRIP:
|
---|
6041 | *pMode = GL_TRIANGLE_STRIP;
|
---|
6042 | *pcVertices = cPrimitiveCount + 2;
|
---|
6043 | break;
|
---|
6044 | case SVGA3D_PRIMITIVE_TRIANGLEFAN:
|
---|
6045 | *pMode = GL_TRIANGLE_FAN;
|
---|
6046 | *pcVertices = cPrimitiveCount + 2;
|
---|
6047 | break;
|
---|
6048 | default:
|
---|
6049 | return VERR_INVALID_PARAMETER;
|
---|
6050 | }
|
---|
6051 | return VINF_SUCCESS;
|
---|
6052 | }
|
---|
6053 |
|
---|
6054 | int vmsvga3dDrawPrimitivesProcessVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl)
|
---|
6055 | {
|
---|
6056 | unsigned sidVertex = pVertexDecl[0].array.surfaceId;
|
---|
6057 | PVMSVGA3DSURFACE pVertexSurface;
|
---|
6058 |
|
---|
6059 | AssertReturn(sidVertex < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
6060 | AssertReturn(sidVertex < pState->cSurfaces && pState->paSurface[sidVertex].id == sidVertex, VERR_INVALID_PARAMETER);
|
---|
6061 |
|
---|
6062 | pVertexSurface = &pState->paSurface[sidVertex];
|
---|
6063 | Log(("vmsvga3dDrawPrimitives: vertex surface %x\n", sidVertex));
|
---|
6064 |
|
---|
6065 | /* Create and/or bind the vertex buffer. */
|
---|
6066 | if (pVertexSurface->oglId.buffer == OPENGL_INVALID_ID)
|
---|
6067 | {
|
---|
6068 | Log(("vmsvga3dDrawPrimitives: create vertex buffer fDirty=%d size=%x bytes\n", pVertexSurface->fDirty, pVertexSurface->pMipmapLevels[0].cbSurface));
|
---|
6069 | pState->ext.glGenBuffers(1, &pVertexSurface->oglId.buffer);
|
---|
6070 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6071 |
|
---|
6072 | pState->ext.glBindBuffer(GL_ARRAY_BUFFER, pVertexSurface->oglId.buffer);
|
---|
6073 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6074 |
|
---|
6075 | Assert(pVertexSurface->fDirty);
|
---|
6076 | /* @todo rethink usage dynamic/static */
|
---|
6077 | pState->ext.glBufferData(GL_ARRAY_BUFFER, pVertexSurface->pMipmapLevels[0].cbSurface, pVertexSurface->pMipmapLevels[0].pSurfaceData, GL_DYNAMIC_DRAW);
|
---|
6078 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6079 |
|
---|
6080 | pVertexSurface->pMipmapLevels[0].fDirty = false;
|
---|
6081 | pVertexSurface->fDirty = false;
|
---|
6082 |
|
---|
6083 | pVertexSurface->flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
|
---|
6084 | }
|
---|
6085 | else
|
---|
6086 | {
|
---|
6087 | Assert(pVertexSurface->fDirty == false);
|
---|
6088 | pState->ext.glBindBuffer(GL_ARRAY_BUFFER, pVertexSurface->oglId.buffer);
|
---|
6089 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6090 | }
|
---|
6091 | pVertexSurface->idAssociatedContext = pContext->id;
|
---|
6092 |
|
---|
6093 | /* Setup the vertex declarations. */
|
---|
6094 | for (unsigned iVertex = 0; iVertex < numVertexDecls; iVertex++)
|
---|
6095 | {
|
---|
6096 | GLint size;
|
---|
6097 | GLenum type;
|
---|
6098 | GLboolean normalized;
|
---|
6099 | GLuint index = iVertexDeclBase + iVertex;
|
---|
6100 |
|
---|
6101 | Log(("vmsvga3dDrawPrimitives: array index %d type=%s (%d) method=%s (%d) usage=%s (%d) usageIndex=%d stride=%d offset=%d\n", index, vmsvgaDeclType2String(pVertexDecl[iVertex].identity.type), pVertexDecl[iVertex].identity.type, vmsvgaDeclMethod2String(pVertexDecl[iVertex].identity.method), pVertexDecl[iVertex].identity.method, vmsvgaDeclUsage2String(pVertexDecl[iVertex].identity.usage), pVertexDecl[iVertex].identity.usage, pVertexDecl[iVertex].identity.usageIndex, pVertexDecl[iVertex].array.stride, pVertexDecl[iVertex].array.offset));
|
---|
6102 |
|
---|
6103 | int rc = vmsvga3dVertexDecl2OGL(pVertexDecl[iVertex].identity, size, type, normalized);
|
---|
6104 | AssertRCReturn(rc, rc);
|
---|
6105 |
|
---|
6106 | if (pContext->state.shidVertex != SVGA_ID_INVALID)
|
---|
6107 | {
|
---|
6108 | /* Use numbered vertex arrays when shaders are active. */
|
---|
6109 | pState->ext.glEnableVertexAttribArray(index);
|
---|
6110 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6111 | pState->ext.glVertexAttribPointer(index, size, type, normalized, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
|
---|
6112 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6113 | /* case SVGA3D_DECLUSAGE_COLOR: @todo color component order not identical!! test GL_BGRA!! */
|
---|
6114 | }
|
---|
6115 | else
|
---|
6116 | {
|
---|
6117 | /* Use the predefined selection of vertex streams for the fixed pipeline. */
|
---|
6118 | switch (pVertexDecl[iVertex].identity.usage)
|
---|
6119 | {
|
---|
6120 | case SVGA3D_DECLUSAGE_POSITION:
|
---|
6121 | glEnableClientState(GL_VERTEX_ARRAY);
|
---|
6122 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6123 | glVertexPointer(size, type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
|
---|
6124 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6125 | break;
|
---|
6126 | case SVGA3D_DECLUSAGE_BLENDWEIGHT:
|
---|
6127 | AssertFailed();
|
---|
6128 | break;
|
---|
6129 | case SVGA3D_DECLUSAGE_BLENDINDICES:
|
---|
6130 | AssertFailed();
|
---|
6131 | break;
|
---|
6132 | case SVGA3D_DECLUSAGE_NORMAL:
|
---|
6133 | glEnableClientState(GL_NORMAL_ARRAY);
|
---|
6134 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6135 | glNormalPointer(type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
|
---|
6136 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6137 | break;
|
---|
6138 | case SVGA3D_DECLUSAGE_PSIZE:
|
---|
6139 | AssertFailed();
|
---|
6140 | break;
|
---|
6141 | case SVGA3D_DECLUSAGE_TEXCOORD:
|
---|
6142 | /* Specify the affected texture unit. */
|
---|
6143 | pState->ext.glClientActiveTexture(GL_TEXTURE0 + pVertexDecl[iVertex].identity.usageIndex);
|
---|
6144 | glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
---|
6145 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6146 | glTexCoordPointer(size, type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
|
---|
6147 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6148 | break;
|
---|
6149 | case SVGA3D_DECLUSAGE_TANGENT:
|
---|
6150 | AssertFailed();
|
---|
6151 | break;
|
---|
6152 | case SVGA3D_DECLUSAGE_BINORMAL:
|
---|
6153 | AssertFailed();
|
---|
6154 | break;
|
---|
6155 | case SVGA3D_DECLUSAGE_TESSFACTOR:
|
---|
6156 | AssertFailed();
|
---|
6157 | break;
|
---|
6158 | case SVGA3D_DECLUSAGE_POSITIONT:
|
---|
6159 | AssertFailed(); /* see position_transformed in Wine */
|
---|
6160 | break;
|
---|
6161 | case SVGA3D_DECLUSAGE_COLOR: /* @todo color component order not identical!! test GL_BGRA!! */
|
---|
6162 | glEnableClientState(GL_COLOR_ARRAY);
|
---|
6163 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6164 | glColorPointer(size, type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
|
---|
6165 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6166 | break;
|
---|
6167 | case SVGA3D_DECLUSAGE_FOG:
|
---|
6168 | glEnableClientState(GL_FOG_COORD_ARRAY);
|
---|
6169 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6170 | pState->ext.glFogCoordPointer(type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
|
---|
6171 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6172 | break;
|
---|
6173 | case SVGA3D_DECLUSAGE_DEPTH:
|
---|
6174 | AssertFailed();
|
---|
6175 | break;
|
---|
6176 | case SVGA3D_DECLUSAGE_SAMPLE:
|
---|
6177 | AssertFailed();
|
---|
6178 | break;
|
---|
6179 | case SVGA3D_DECLUSAGE_MAX: AssertFailed(); break; /* shut up gcc */
|
---|
6180 | }
|
---|
6181 | }
|
---|
6182 |
|
---|
6183 | #ifdef LOG_ENABLED
|
---|
6184 | if (pVertexDecl[iVertex].array.stride == 0)
|
---|
6185 | Log(("vmsvga3dDrawPrimitives: stride == 0! Can be valid\n"));
|
---|
6186 | #endif
|
---|
6187 | }
|
---|
6188 |
|
---|
6189 | return VINF_SUCCESS;
|
---|
6190 | }
|
---|
6191 |
|
---|
6192 | int vmsvga3dDrawPrimitivesCleanupVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl)
|
---|
6193 | {
|
---|
6194 | /* Setup the vertex declarations. */
|
---|
6195 | for (unsigned iVertex = 0; iVertex < numVertexDecls; iVertex++)
|
---|
6196 | {
|
---|
6197 | if (pContext->state.shidVertex != SVGA_ID_INVALID)
|
---|
6198 | {
|
---|
6199 | /* Use numbered vertex arrays when shaders are active. */
|
---|
6200 | pState->ext.glDisableVertexAttribArray(iVertexDeclBase + iVertex);
|
---|
6201 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6202 | }
|
---|
6203 | else
|
---|
6204 | {
|
---|
6205 | /* Use the predefined selection of vertex streams for the fixed pipeline. */
|
---|
6206 | switch (pVertexDecl[iVertex].identity.usage)
|
---|
6207 | {
|
---|
6208 | case SVGA3D_DECLUSAGE_POSITION:
|
---|
6209 | glDisableClientState(GL_VERTEX_ARRAY);
|
---|
6210 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6211 | break;
|
---|
6212 | case SVGA3D_DECLUSAGE_BLENDWEIGHT:
|
---|
6213 | break;
|
---|
6214 | case SVGA3D_DECLUSAGE_BLENDINDICES:
|
---|
6215 | break;
|
---|
6216 | case SVGA3D_DECLUSAGE_NORMAL:
|
---|
6217 | glDisableClientState(GL_NORMAL_ARRAY);
|
---|
6218 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6219 | break;
|
---|
6220 | case SVGA3D_DECLUSAGE_PSIZE:
|
---|
6221 | break;
|
---|
6222 | case SVGA3D_DECLUSAGE_TEXCOORD:
|
---|
6223 | /* Specify the affected texture unit. */
|
---|
6224 | pState->ext.glClientActiveTexture(GL_TEXTURE0 + pVertexDecl[iVertex].identity.usageIndex);
|
---|
6225 | glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
---|
6226 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6227 | break;
|
---|
6228 | case SVGA3D_DECLUSAGE_TANGENT:
|
---|
6229 | break;
|
---|
6230 | case SVGA3D_DECLUSAGE_BINORMAL:
|
---|
6231 | break;
|
---|
6232 | case SVGA3D_DECLUSAGE_TESSFACTOR:
|
---|
6233 | break;
|
---|
6234 | case SVGA3D_DECLUSAGE_POSITIONT:
|
---|
6235 | break;
|
---|
6236 | case SVGA3D_DECLUSAGE_COLOR: /* @todo color component order not identical!! */
|
---|
6237 | glDisableClientState(GL_COLOR_ARRAY);
|
---|
6238 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6239 | break;
|
---|
6240 | case SVGA3D_DECLUSAGE_FOG:
|
---|
6241 | glDisableClientState(GL_FOG_COORD_ARRAY);
|
---|
6242 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6243 | break;
|
---|
6244 | case SVGA3D_DECLUSAGE_DEPTH:
|
---|
6245 | break;
|
---|
6246 | case SVGA3D_DECLUSAGE_SAMPLE:
|
---|
6247 | break;
|
---|
6248 | case SVGA3D_DECLUSAGE_MAX: AssertFailed(); break; /* shut up gcc */
|
---|
6249 | }
|
---|
6250 | }
|
---|
6251 | }
|
---|
6252 | /* Unbind the vertex buffer after usage. */
|
---|
6253 | pState->ext.glBindBuffer(GL_ARRAY_BUFFER, 0);
|
---|
6254 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6255 | return VINF_SUCCESS;
|
---|
6256 | }
|
---|
6257 |
|
---|
6258 | int vmsvga3dDrawPrimitives(PVGASTATE pThis, uint32_t cid, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl, uint32_t numRanges, SVGA3dPrimitiveRange *pRange, uint32_t cVertexDivisor, SVGA3dVertexDivisor *pVertexDivisor)
|
---|
6259 | {
|
---|
6260 | PVMSVGA3DCONTEXT pContext;
|
---|
6261 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
6262 | AssertReturn(pState, VERR_INTERNAL_ERROR);
|
---|
6263 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
6264 | uint32_t iCurrentVertex;
|
---|
6265 |
|
---|
6266 | Log(("vmsvga3dDrawPrimitives cid=%x numVertexDecls=%d numRanges=%d, cVertexDivisor=%d\n", cid, numVertexDecls, numRanges, cVertexDivisor));
|
---|
6267 |
|
---|
6268 | AssertReturn(numVertexDecls && numVertexDecls <= SVGA3D_MAX_VERTEX_ARRAYS, VERR_INVALID_PARAMETER);
|
---|
6269 | AssertReturn(numRanges && numRanges <= SVGA3D_MAX_DRAW_PRIMITIVE_RANGES, VERR_INVALID_PARAMETER);
|
---|
6270 | AssertReturn(!cVertexDivisor || cVertexDivisor == numVertexDecls, VERR_INVALID_PARAMETER);
|
---|
6271 | /* @todo */
|
---|
6272 | Assert(!cVertexDivisor);
|
---|
6273 |
|
---|
6274 | if ( cid >= pState->cContexts
|
---|
6275 | || pState->paContext[cid].id != cid)
|
---|
6276 | {
|
---|
6277 | Log(("vmsvga3dDrawPrimitives invalid context id!\n"));
|
---|
6278 | return VERR_INVALID_PARAMETER;
|
---|
6279 | }
|
---|
6280 | pContext = &pState->paContext[cid];
|
---|
6281 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
6282 |
|
---|
6283 | /* Flush any shader changes. */
|
---|
6284 | if (pContext->pShaderContext)
|
---|
6285 | {
|
---|
6286 | uint32_t rtHeight = 0;
|
---|
6287 |
|
---|
6288 | if (pContext->sidRenderTarget != SVGA_ID_INVALID)
|
---|
6289 | {
|
---|
6290 | PVMSVGA3DSURFACE pRenderTarget = &pState->paSurface[pContext->sidRenderTarget];
|
---|
6291 | rtHeight = pRenderTarget->pMipmapLevels[0].size.height;
|
---|
6292 | }
|
---|
6293 |
|
---|
6294 | ShaderUpdateState(pContext->pShaderContext, rtHeight);
|
---|
6295 | }
|
---|
6296 |
|
---|
6297 | /* Process all vertex declarations. Each vertex buffer is represented by one stream. */
|
---|
6298 | iCurrentVertex = 0;
|
---|
6299 | while (iCurrentVertex < numVertexDecls)
|
---|
6300 | {
|
---|
6301 | uint32_t sidVertex = SVGA_ID_INVALID;
|
---|
6302 | uint32_t iVertex;
|
---|
6303 |
|
---|
6304 | for (iVertex = iCurrentVertex; iVertex < numVertexDecls; iVertex++)
|
---|
6305 | {
|
---|
6306 | if ( sidVertex != SVGA_ID_INVALID
|
---|
6307 | && pVertexDecl[iVertex].array.surfaceId != sidVertex
|
---|
6308 | )
|
---|
6309 | break;
|
---|
6310 | sidVertex = pVertexDecl[iVertex].array.surfaceId;
|
---|
6311 | }
|
---|
6312 |
|
---|
6313 | rc = vmsvga3dDrawPrimitivesProcessVertexDecls(pState, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);
|
---|
6314 | AssertRCReturn(rc, rc);
|
---|
6315 |
|
---|
6316 | iCurrentVertex = iVertex;
|
---|
6317 | }
|
---|
6318 |
|
---|
6319 | /* Now draw the primitives. */
|
---|
6320 | for (unsigned iPrimitive = 0; iPrimitive < numRanges; iPrimitive++)
|
---|
6321 | {
|
---|
6322 | GLenum modeDraw;
|
---|
6323 | unsigned sidIndex = pRange[iPrimitive].indexArray.surfaceId;
|
---|
6324 | PVMSVGA3DSURFACE pIndexSurface = NULL;
|
---|
6325 | unsigned cVertices;
|
---|
6326 |
|
---|
6327 | Log(("Primitive %d: type %s\n", iPrimitive, vmsvga3dPrimitiveType2String(pRange[iPrimitive].primType)));
|
---|
6328 | rc = vmsvga3dPrimitiveType2OGL(pRange[iPrimitive].primType, &modeDraw, pRange[iPrimitive].primitiveCount, &cVertices);
|
---|
6329 | if (RT_FAILURE(rc))
|
---|
6330 | {
|
---|
6331 | AssertRC(rc);
|
---|
6332 | goto internal_error;
|
---|
6333 | }
|
---|
6334 |
|
---|
6335 | if (sidIndex != SVGA3D_INVALID_ID)
|
---|
6336 | {
|
---|
6337 | AssertMsg(pRange[iPrimitive].indexWidth == sizeof(uint32_t) || pRange[iPrimitive].indexWidth == sizeof(uint16_t), ("Unsupported primitive width %d\n", pRange[iPrimitive].indexWidth));
|
---|
6338 |
|
---|
6339 | if ( sidIndex >= SVGA3D_MAX_SURFACE_IDS
|
---|
6340 | || sidIndex >= pState->cSurfaces
|
---|
6341 | || pState->paSurface[sidIndex].id != sidIndex)
|
---|
6342 | {
|
---|
6343 | Assert(sidIndex < SVGA3D_MAX_SURFACE_IDS);
|
---|
6344 | Assert(sidIndex < pState->cSurfaces && pState->paSurface[sidIndex].id == sidIndex);
|
---|
6345 | rc = VERR_INVALID_PARAMETER;
|
---|
6346 | goto internal_error;
|
---|
6347 | }
|
---|
6348 | pIndexSurface = &pState->paSurface[sidIndex];
|
---|
6349 | Log(("vmsvga3dDrawPrimitives: index surface %x\n", sidIndex));
|
---|
6350 |
|
---|
6351 | if (pIndexSurface->oglId.buffer == OPENGL_INVALID_ID)
|
---|
6352 | {
|
---|
6353 | Log(("vmsvga3dDrawPrimitives: create index buffer fDirty=%d size=%x bytes\n", pIndexSurface->fDirty, pIndexSurface->pMipmapLevels[0].cbSurface));
|
---|
6354 |
|
---|
6355 | pState->ext.glGenBuffers(1, &pIndexSurface->oglId.buffer);
|
---|
6356 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6357 |
|
---|
6358 | pState->ext.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pIndexSurface->oglId.buffer);
|
---|
6359 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6360 |
|
---|
6361 | Assert(pIndexSurface->fDirty);
|
---|
6362 |
|
---|
6363 | /* @todo rethink usage dynamic/static */
|
---|
6364 | pState->ext.glBufferData(GL_ELEMENT_ARRAY_BUFFER, pIndexSurface->pMipmapLevels[0].cbSurface, pIndexSurface->pMipmapLevels[0].pSurfaceData, GL_DYNAMIC_DRAW);
|
---|
6365 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6366 |
|
---|
6367 | pIndexSurface->pMipmapLevels[0].fDirty = false;
|
---|
6368 | pIndexSurface->fDirty = false;
|
---|
6369 |
|
---|
6370 | pIndexSurface->flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
|
---|
6371 | }
|
---|
6372 | else
|
---|
6373 | {
|
---|
6374 | Assert(pIndexSurface->fDirty == false);
|
---|
6375 |
|
---|
6376 | pState->ext.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pIndexSurface->oglId.buffer);
|
---|
6377 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6378 | }
|
---|
6379 | pIndexSurface->idAssociatedContext = pContext->id;
|
---|
6380 | }
|
---|
6381 |
|
---|
6382 | if (!pIndexSurface)
|
---|
6383 | {
|
---|
6384 | /* Render without an index buffer */
|
---|
6385 | Log(("DrawPrimitive %x cPrimitives=%d cVertices=%d index index bias=%d\n", modeDraw, pRange[iPrimitive].primitiveCount, cVertices, pRange[iPrimitive].indexBias));
|
---|
6386 | glDrawArrays(modeDraw, pRange[iPrimitive].indexBias, cVertices);
|
---|
6387 | }
|
---|
6388 | else
|
---|
6389 | {
|
---|
6390 | Assert(pRange[iPrimitive].indexBias >= 0); /* @todo */
|
---|
6391 | Assert(pRange[iPrimitive].indexWidth == pRange[iPrimitive].indexArray.stride);
|
---|
6392 |
|
---|
6393 | /* Render with an index buffer */
|
---|
6394 | Log(("DrawIndexedPrimitive %x cPrimitives=%d cVertices=%d hint.first=%d hint.last=%d index offset=%d primitivecount=%d index width=%d index bias=%d\n", modeDraw, pRange[iPrimitive].primitiveCount, cVertices, pVertexDecl[0].rangeHint.first, pVertexDecl[0].rangeHint.last, pRange[iPrimitive].indexArray.offset, pRange[iPrimitive].primitiveCount, pRange[iPrimitive].indexWidth, pRange[iPrimitive].indexBias));
|
---|
6395 | if (pRange[iPrimitive].indexBias == 0)
|
---|
6396 | {
|
---|
6397 | glDrawElements(modeDraw,
|
---|
6398 | cVertices,
|
---|
6399 | (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
|
---|
6400 | (GLvoid *)(pRange[iPrimitive].indexArray.offset)); /* byte offset in indices buffer */
|
---|
6401 | }
|
---|
6402 | else
|
---|
6403 | pState->ext.glDrawElementsBaseVertex(modeDraw,
|
---|
6404 | cVertices,
|
---|
6405 | (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
|
---|
6406 | (GLvoid *)(pRange[iPrimitive].indexArray.offset), /* byte offset in indices buffer */
|
---|
6407 | pRange[iPrimitive].indexBias); /* basevertex */
|
---|
6408 |
|
---|
6409 | /* Unbind the index buffer after usage. */
|
---|
6410 | pState->ext.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
---|
6411 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6412 | }
|
---|
6413 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
6414 | }
|
---|
6415 |
|
---|
6416 | internal_error:
|
---|
6417 |
|
---|
6418 | /* Deactivate the vertex declarations. */
|
---|
6419 | iCurrentVertex = 0;
|
---|
6420 | while (iCurrentVertex < numVertexDecls)
|
---|
6421 | {
|
---|
6422 | uint32_t sidVertex = SVGA_ID_INVALID;
|
---|
6423 | uint32_t iVertex;
|
---|
6424 |
|
---|
6425 | for (iVertex = iCurrentVertex; iVertex < numVertexDecls; iVertex++)
|
---|
6426 | {
|
---|
6427 | if ( sidVertex != SVGA_ID_INVALID
|
---|
6428 | && pVertexDecl[iVertex].array.surfaceId != sidVertex
|
---|
6429 | )
|
---|
6430 | break;
|
---|
6431 | sidVertex = pVertexDecl[iVertex].array.surfaceId;
|
---|
6432 | }
|
---|
6433 |
|
---|
6434 | rc = vmsvga3dDrawPrimitivesCleanupVertexDecls(pState, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);
|
---|
6435 | AssertRCReturn(rc, rc);
|
---|
6436 |
|
---|
6437 | iCurrentVertex = iVertex;
|
---|
6438 | }
|
---|
6439 | #ifdef DEBUG
|
---|
6440 | for (uint32_t i = 0; i < RT_ELEMENTS(pContext->aSidActiveTexture); i++)
|
---|
6441 | {
|
---|
6442 | if (pContext->aSidActiveTexture[i] != SVGA3D_INVALID_ID)
|
---|
6443 | {
|
---|
6444 | GLint activeTexture = 0;
|
---|
6445 | GLint activeTextureUnit = 0;
|
---|
6446 |
|
---|
6447 | glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTextureUnit);
|
---|
6448 | pState->ext.glActiveTexture(GL_TEXTURE0 + i);
|
---|
6449 |
|
---|
6450 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
|
---|
6451 | pState->ext.glActiveTexture(activeTextureUnit);
|
---|
6452 |
|
---|
6453 | if (pContext->aSidActiveTexture[activeTextureUnit - GL_TEXTURE0] != SVGA3D_INVALID_ID)
|
---|
6454 | {
|
---|
6455 | PVMSVGA3DSURFACE pTexture;
|
---|
6456 | pTexture = &pState->paSurface[pContext->aSidActiveTexture[activeTextureUnit - GL_TEXTURE0]];
|
---|
6457 |
|
---|
6458 | AssertMsg(pTexture->oglId.texture == (GLuint)activeTexture, ("%x vs %x unit %d - %d\n", pTexture->oglId.texture, activeTexture, i, activeTextureUnit - GL_TEXTURE0));
|
---|
6459 | }
|
---|
6460 | }
|
---|
6461 | }
|
---|
6462 | #endif
|
---|
6463 |
|
---|
6464 | #ifdef DEBUG_GFX_WINDOW
|
---|
6465 | if (pContext->aSidActiveTexture[0])
|
---|
6466 | {
|
---|
6467 | SVGA3dCopyRect rect;
|
---|
6468 |
|
---|
6469 | rect.srcx = rect.srcy = rect.x = rect.y = 0;
|
---|
6470 | rect.w = 800;
|
---|
6471 | rect.h = 600;
|
---|
6472 | vmsvga3dCommandPresent(pThis, pContext->sidRenderTarget, 0, NULL);
|
---|
6473 | }
|
---|
6474 | #endif
|
---|
6475 | return rc;
|
---|
6476 | }
|
---|
6477 |
|
---|
6478 |
|
---|
6479 | int vmsvga3dShaderDefine(PVGASTATE pThis, uint32_t cid, uint32_t shid, SVGA3dShaderType type, uint32_t cbData, uint32_t *pShaderData)
|
---|
6480 | {
|
---|
6481 | PVMSVGA3DCONTEXT pContext;
|
---|
6482 | PVMSVGA3DSHADER pShader;
|
---|
6483 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
6484 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
6485 | int rc;
|
---|
6486 |
|
---|
6487 | Log(("vmsvga3dShaderDefine cid=%x shid=%x type=%s cbData=%x\n", cid, shid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", cbData));
|
---|
6488 | Log3(("shader code:\n%.*Rhxd\n", cbData, pShaderData));
|
---|
6489 |
|
---|
6490 | if ( cid >= pState->cContexts
|
---|
6491 | || pState->paContext[cid].id != cid)
|
---|
6492 | {
|
---|
6493 | Log(("vmsvga3dShaderDefine invalid context id!\n"));
|
---|
6494 | return VERR_INVALID_PARAMETER;
|
---|
6495 | }
|
---|
6496 | pContext = &pState->paContext[cid];
|
---|
6497 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
6498 |
|
---|
6499 | AssertReturn(shid < SVGA3D_MAX_SHADER_IDS, VERR_INVALID_PARAMETER);
|
---|
6500 | if (type == SVGA3D_SHADERTYPE_VS)
|
---|
6501 | {
|
---|
6502 | if (shid >= pContext->cVertexShaders)
|
---|
6503 | {
|
---|
6504 | pContext->paVertexShader = (PVMSVGA3DSHADER)RTMemRealloc(pContext->paVertexShader, sizeof(VMSVGA3DSHADER) * (shid + 1));
|
---|
6505 | AssertReturn(pContext->paVertexShader, VERR_NO_MEMORY);
|
---|
6506 | memset(&pContext->paVertexShader[pContext->cVertexShaders], 0, sizeof(VMSVGA3DSHADER) * (shid + 1 - pContext->cVertexShaders));
|
---|
6507 | for (uint32_t i = pContext->cVertexShaders; i < shid + 1; i++)
|
---|
6508 | pContext->paVertexShader[i].id = SVGA3D_INVALID_ID;
|
---|
6509 | pContext->cVertexShaders = shid + 1;
|
---|
6510 | }
|
---|
6511 | /* If one already exists with this id, then destroy it now. */
|
---|
6512 | if (pContext->paVertexShader[shid].id != SVGA3D_INVALID_ID)
|
---|
6513 | vmsvga3dShaderDestroy(pThis, cid, shid, pContext->paVertexShader[shid].type);
|
---|
6514 |
|
---|
6515 | pShader = &pContext->paVertexShader[shid];
|
---|
6516 | }
|
---|
6517 | else
|
---|
6518 | {
|
---|
6519 | Assert(type == SVGA3D_SHADERTYPE_PS);
|
---|
6520 | if (shid >= pContext->cPixelShaders)
|
---|
6521 | {
|
---|
6522 | pContext->paPixelShader = (PVMSVGA3DSHADER)RTMemRealloc(pContext->paPixelShader, sizeof(VMSVGA3DSHADER) * (shid + 1));
|
---|
6523 | AssertReturn(pContext->paPixelShader, VERR_NO_MEMORY);
|
---|
6524 | memset(&pContext->paPixelShader[pContext->cPixelShaders], 0, sizeof(VMSVGA3DSHADER) * (shid + 1 - pContext->cPixelShaders));
|
---|
6525 | for (uint32_t i = pContext->cPixelShaders; i < shid + 1; i++)
|
---|
6526 | pContext->paPixelShader[i].id = SVGA3D_INVALID_ID;
|
---|
6527 | pContext->cPixelShaders = shid + 1;
|
---|
6528 | }
|
---|
6529 | /* If one already exists with this id, then destroy it now. */
|
---|
6530 | if (pContext->paPixelShader[shid].id != SVGA3D_INVALID_ID)
|
---|
6531 | vmsvga3dShaderDestroy(pThis, cid, shid, pContext->paPixelShader[shid].type);
|
---|
6532 |
|
---|
6533 | pShader = &pContext->paPixelShader[shid];
|
---|
6534 | }
|
---|
6535 |
|
---|
6536 | memset(pShader, 0, sizeof(*pShader));
|
---|
6537 | pShader->id = shid;
|
---|
6538 | pShader->cid = cid;
|
---|
6539 | pShader->type = type;
|
---|
6540 | pShader->cbData = cbData;
|
---|
6541 | pShader->pShaderProgram = RTMemAllocZ(cbData);
|
---|
6542 | AssertReturn(pShader->pShaderProgram, VERR_NO_MEMORY);
|
---|
6543 | memcpy(pShader->pShaderProgram, pShaderData, cbData);
|
---|
6544 |
|
---|
6545 | switch (type)
|
---|
6546 | {
|
---|
6547 | case SVGA3D_SHADERTYPE_VS:
|
---|
6548 | rc = ShaderCreateVertexShader(pContext->pShaderContext, (const uint32_t *)pShaderData, &pShader->u.pVertexShader);
|
---|
6549 | break;
|
---|
6550 |
|
---|
6551 | case SVGA3D_SHADERTYPE_PS:
|
---|
6552 | rc = ShaderCreatePixelShader(pContext->pShaderContext, (const uint32_t *)pShaderData, &pShader->u.pPixelShader);
|
---|
6553 | break;
|
---|
6554 |
|
---|
6555 | default:
|
---|
6556 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
6557 | }
|
---|
6558 |
|
---|
6559 | return rc;
|
---|
6560 | }
|
---|
6561 |
|
---|
6562 | int vmsvga3dShaderDestroy(PVGASTATE pThis, uint32_t cid, uint32_t shid, SVGA3dShaderType type)
|
---|
6563 | {
|
---|
6564 | PVMSVGA3DCONTEXT pContext;
|
---|
6565 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
6566 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
6567 | PVMSVGA3DSHADER pShader = NULL;
|
---|
6568 | int rc;
|
---|
6569 |
|
---|
6570 | Log(("vmsvga3dShaderDestroy cid=%x shid=%x type=%s\n", cid, shid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL"));
|
---|
6571 |
|
---|
6572 | if ( cid >= pState->cContexts
|
---|
6573 | || pState->paContext[cid].id != cid)
|
---|
6574 | {
|
---|
6575 | Log(("vmsvga3dShaderDestroy invalid context id!\n"));
|
---|
6576 | return VERR_INVALID_PARAMETER;
|
---|
6577 | }
|
---|
6578 | pContext = &pState->paContext[cid];
|
---|
6579 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
6580 |
|
---|
6581 | if (type == SVGA3D_SHADERTYPE_VS)
|
---|
6582 | {
|
---|
6583 | if ( shid < pContext->cVertexShaders
|
---|
6584 | && pContext->paVertexShader[shid].id == shid)
|
---|
6585 | {
|
---|
6586 | pShader = &pContext->paVertexShader[shid];
|
---|
6587 | rc = ShaderDestroyVertexShader(pContext->pShaderContext, pShader->u.pVertexShader);
|
---|
6588 | AssertRC(rc);
|
---|
6589 | }
|
---|
6590 | }
|
---|
6591 | else
|
---|
6592 | {
|
---|
6593 | Assert(type == SVGA3D_SHADERTYPE_PS);
|
---|
6594 | if ( shid < pContext->cPixelShaders
|
---|
6595 | && pContext->paPixelShader[shid].id == shid)
|
---|
6596 | {
|
---|
6597 | pShader = &pContext->paPixelShader[shid];
|
---|
6598 | rc = ShaderDestroyPixelShader(pContext->pShaderContext, pShader->u.pPixelShader);
|
---|
6599 | AssertRC(rc);
|
---|
6600 | }
|
---|
6601 | }
|
---|
6602 |
|
---|
6603 | if (pShader)
|
---|
6604 | {
|
---|
6605 | if (pShader->pShaderProgram)
|
---|
6606 | RTMemFree(pShader->pShaderProgram);
|
---|
6607 | memset(pShader, 0, sizeof(*pShader));
|
---|
6608 | pShader->id = SVGA3D_INVALID_ID;
|
---|
6609 | }
|
---|
6610 | else
|
---|
6611 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
6612 |
|
---|
6613 | return VINF_SUCCESS;
|
---|
6614 | }
|
---|
6615 |
|
---|
6616 | int vmsvga3dShaderSet(PVGASTATE pThis, uint32_t cid, SVGA3dShaderType type, uint32_t shid)
|
---|
6617 | {
|
---|
6618 | PVMSVGA3DCONTEXT pContext;
|
---|
6619 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
6620 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
6621 | int rc;
|
---|
6622 |
|
---|
6623 | Log(("vmsvga3dShaderSet cid=%x type=%s shid=%d\n", cid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", shid));
|
---|
6624 |
|
---|
6625 | if ( cid >= pState->cContexts
|
---|
6626 | || pState->paContext[cid].id != cid)
|
---|
6627 | {
|
---|
6628 | Log(("vmsvga3dShaderSet invalid context id!\n"));
|
---|
6629 | return VERR_INVALID_PARAMETER;
|
---|
6630 | }
|
---|
6631 | pContext = &pState->paContext[cid];
|
---|
6632 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
6633 |
|
---|
6634 | if (type == SVGA3D_SHADERTYPE_VS)
|
---|
6635 | {
|
---|
6636 | /* Save for vm state save/restore. */
|
---|
6637 | pContext->state.shidVertex = shid;
|
---|
6638 | pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_VERTEXSHADER;
|
---|
6639 |
|
---|
6640 | if ( shid < pContext->cVertexShaders
|
---|
6641 | && pContext->paVertexShader[shid].id == shid)
|
---|
6642 | {
|
---|
6643 | PVMSVGA3DSHADER pShader = &pContext->paVertexShader[shid];
|
---|
6644 | Assert(type == pShader->type);
|
---|
6645 |
|
---|
6646 | rc = ShaderSetVertexShader(pContext->pShaderContext, pShader->u.pVertexShader);
|
---|
6647 | AssertRCReturn(rc, rc);
|
---|
6648 | }
|
---|
6649 | else
|
---|
6650 | if (shid == SVGA_ID_INVALID)
|
---|
6651 | {
|
---|
6652 | /* Unselect shader. */
|
---|
6653 | rc = ShaderSetVertexShader(pContext->pShaderContext, NULL);
|
---|
6654 | AssertRCReturn(rc, rc);
|
---|
6655 | }
|
---|
6656 | else
|
---|
6657 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
6658 | }
|
---|
6659 | else
|
---|
6660 | {
|
---|
6661 | /* Save for vm state save/restore. */
|
---|
6662 | pContext->state.shidPixel = shid;
|
---|
6663 | pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_PIXELSHADER;
|
---|
6664 |
|
---|
6665 | Assert(type == SVGA3D_SHADERTYPE_PS);
|
---|
6666 | if ( shid < pContext->cPixelShaders
|
---|
6667 | && pContext->paPixelShader[shid].id == shid)
|
---|
6668 | {
|
---|
6669 | PVMSVGA3DSHADER pShader = &pContext->paPixelShader[shid];
|
---|
6670 | Assert(type == pShader->type);
|
---|
6671 |
|
---|
6672 | rc = ShaderSetPixelShader(pContext->pShaderContext, pShader->u.pPixelShader);
|
---|
6673 | AssertRCReturn(rc, rc);
|
---|
6674 | }
|
---|
6675 | else
|
---|
6676 | if (shid == SVGA_ID_INVALID)
|
---|
6677 | {
|
---|
6678 | /* Unselect shader. */
|
---|
6679 | rc = ShaderSetPixelShader(pContext->pShaderContext, NULL);
|
---|
6680 | AssertRCReturn(rc, rc);
|
---|
6681 | }
|
---|
6682 | else
|
---|
6683 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
6684 | }
|
---|
6685 |
|
---|
6686 | return VINF_SUCCESS;
|
---|
6687 | }
|
---|
6688 |
|
---|
6689 | int vmsvga3dShaderSetConst(PVGASTATE pThis, uint32_t cid, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype, uint32_t cRegisters, uint32_t *pValues)
|
---|
6690 | {
|
---|
6691 | PVMSVGA3DCONTEXT pContext;
|
---|
6692 | PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
|
---|
6693 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
6694 | int rc;
|
---|
6695 |
|
---|
6696 | Log(("vmsvga3dShaderSetConst cid=%x reg=%x type=%s cregs=%d ctype=%x\n", cid, reg, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", cRegisters, ctype));
|
---|
6697 |
|
---|
6698 | if ( cid >= pState->cContexts
|
---|
6699 | || pState->paContext[cid].id != cid)
|
---|
6700 | {
|
---|
6701 | Log(("vmsvga3dShaderSetConst invalid context id!\n"));
|
---|
6702 | return VERR_INVALID_PARAMETER;
|
---|
6703 | }
|
---|
6704 | pContext = &pState->paContext[cid];
|
---|
6705 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
6706 |
|
---|
6707 | for (uint32_t i = 0; i < cRegisters; i++)
|
---|
6708 | {
|
---|
6709 | #ifdef LOG_ENABLED
|
---|
6710 | switch (ctype)
|
---|
6711 | {
|
---|
6712 | case SVGA3D_CONST_TYPE_FLOAT:
|
---|
6713 | {
|
---|
6714 | float *pValuesF = (float *)pValues;
|
---|
6715 | Log(("Constant %d: value=%d-%d-%d-%d\n", reg + i, (int)(pValuesF[i*4 + 0] * 100.0), (int)(pValuesF[i*4 + 1] * 100.0), (int)(pValuesF[i*4 + 2] * 100.0), (int)(pValuesF[i*4 + 3] * 100.0)));
|
---|
6716 | break;
|
---|
6717 | }
|
---|
6718 |
|
---|
6719 | case SVGA3D_CONST_TYPE_INT:
|
---|
6720 | Log(("Constant %d: value=%x-%x-%x-%x\n", reg + i, pValues[i*4 + 0], pValues[i*4 + 1], pValues[i*4 + 2], pValues[i*4 + 3]));
|
---|
6721 | break;
|
---|
6722 |
|
---|
6723 | case SVGA3D_CONST_TYPE_BOOL:
|
---|
6724 | Log(("Constant %d: value=%x-%x-%x-%x\n", reg + i, pValues[i*4 + 0], pValues[i*4 + 1], pValues[i*4 + 2], pValues[i*4 + 3]));
|
---|
6725 | break;
|
---|
6726 | }
|
---|
6727 | #endif
|
---|
6728 | vmsvga3dSaveShaderConst(pContext, reg + i, type, ctype, pValues[i*4 + 0], pValues[i*4 + 1], pValues[i*4 + 2], pValues[i*4 + 3]);
|
---|
6729 | }
|
---|
6730 |
|
---|
6731 | switch (type)
|
---|
6732 | {
|
---|
6733 | case SVGA3D_SHADERTYPE_VS:
|
---|
6734 | switch (ctype)
|
---|
6735 | {
|
---|
6736 | case SVGA3D_CONST_TYPE_FLOAT:
|
---|
6737 | rc = ShaderSetVertexShaderConstantF(pContext->pShaderContext, reg, (const float *)pValues, cRegisters);
|
---|
6738 | break;
|
---|
6739 |
|
---|
6740 | case SVGA3D_CONST_TYPE_INT:
|
---|
6741 | rc = ShaderSetVertexShaderConstantI(pContext->pShaderContext, reg, (const int32_t *)pValues, cRegisters);
|
---|
6742 | break;
|
---|
6743 |
|
---|
6744 | case SVGA3D_CONST_TYPE_BOOL:
|
---|
6745 | rc = ShaderSetVertexShaderConstantB(pContext->pShaderContext, reg, (const uint8_t *)pValues, cRegisters);
|
---|
6746 | break;
|
---|
6747 |
|
---|
6748 | default:
|
---|
6749 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
6750 | }
|
---|
6751 | AssertRCReturn(rc, rc);
|
---|
6752 | break;
|
---|
6753 |
|
---|
6754 | case SVGA3D_SHADERTYPE_PS:
|
---|
6755 | switch (ctype)
|
---|
6756 | {
|
---|
6757 | case SVGA3D_CONST_TYPE_FLOAT:
|
---|
6758 | rc = ShaderSetPixelShaderConstantF(pContext->pShaderContext, reg, (const float *)pValues, cRegisters);
|
---|
6759 | break;
|
---|
6760 |
|
---|
6761 | case SVGA3D_CONST_TYPE_INT:
|
---|
6762 | rc = ShaderSetPixelShaderConstantI(pContext->pShaderContext, reg, (const int32_t *)pValues, cRegisters);
|
---|
6763 | break;
|
---|
6764 |
|
---|
6765 | case SVGA3D_CONST_TYPE_BOOL:
|
---|
6766 | rc = ShaderSetPixelShaderConstantB(pContext->pShaderContext, reg, (const uint8_t *)pValues, cRegisters);
|
---|
6767 | break;
|
---|
6768 |
|
---|
6769 | default:
|
---|
6770 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
6771 | }
|
---|
6772 | AssertRCReturn(rc, rc);
|
---|
6773 | break;
|
---|
6774 |
|
---|
6775 | default:
|
---|
6776 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
6777 | }
|
---|
6778 |
|
---|
6779 | return VINF_SUCCESS;
|
---|
6780 | }
|
---|
6781 |
|
---|
6782 |
|
---|
6783 | int vmsvga3dQueryBegin(PVGASTATE pThis, uint32_t cid, SVGA3dQueryType type)
|
---|
6784 | {
|
---|
6785 | AssertFailed();
|
---|
6786 | return VERR_NOT_IMPLEMENTED;
|
---|
6787 | }
|
---|
6788 |
|
---|
6789 | int vmsvga3dQueryEnd(PVGASTATE pThis, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
|
---|
6790 | {
|
---|
6791 | AssertFailed();
|
---|
6792 | return VERR_NOT_IMPLEMENTED;
|
---|
6793 | }
|
---|
6794 |
|
---|
6795 | int vmsvga3dQueryWait(PVGASTATE pThis, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
|
---|
6796 | {
|
---|
6797 | AssertFailed();
|
---|
6798 | return VERR_NOT_IMPLEMENTED;
|
---|
6799 | }
|
---|
6800 |
|
---|