Changeset 57149 in vbox for trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
- Timestamp:
- Aug 1, 2015 8:18:07 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 101895
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
r57139 r57149 38 38 #include <iprt/uuid.h> 39 39 #include <iprt/mem.h> 40 #include <iprt/avl.h> 41 42 #include <VBox/VMMDev.h> 43 #include <VBox/VBoxVideo.h> 44 #include <VBox/bioslogo.h> 40 41 #include <VBox/VBoxVideo.h> /* required by DevVGA.h */ 45 42 46 43 /* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */ … … 49 46 #include "DevVGA-SVGA.h" 50 47 #include "DevVGA-SVGA3d.h" 51 #include "vmsvga/svga_reg.h" 52 #include "vmsvga/svga3d_reg.h" 53 #include "vmsvga/svga3d_shaderdefs.h" 54 55 #ifdef RT_OS_WINDOWS 56 # include <GL/gl.h> 57 # include "vmsvga_glext/wglext.h" 58 59 #elif defined(RT_OS_DARWIN) 60 # include <OpenGL/OpenGL.h> 61 # include <OpenGL/gl3.h> 62 # include <OpenGL/gl3ext.h> 63 # define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED 64 # include <OpenGL/gl.h> 65 # include <OpenGL/glext.h> 66 # include "DevVGA-SVGA3d-cocoa.h" 67 /* work around conflicting definition of GLhandleARB in VMware's glext.h */ 68 //#define GL_ARB_shader_objects 69 // HACK 70 typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); 71 typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); 72 typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params); 73 # define GL_RGBA_S3TC 0x83A2 74 # define GL_ALPHA8_EXT 0x803c 75 # define GL_LUMINANCE8_EXT 0x8040 76 # define GL_LUMINANCE16_EXT 0x8042 77 # define GL_LUMINANCE4_ALPHA4_EXT 0x8043 78 # define GL_LUMINANCE8_ALPHA8_EXT 0x8045 79 # define GL_INT_2_10_10_10_REV 0x8D9F 80 #else 81 # include <X11/Xlib.h> 82 # include <X11/Xatom.h> 83 # include <GL/gl.h> 84 # include <GL/glx.h> 85 # include <GL/glext.h> 86 # define VBOX_VMSVGA3D_GL_HACK_LEVEL 0x103 87 #endif 48 #include "DevVGA-SVGA3d-internal.h" 49 88 50 #ifdef DUMP_SHADER_DISASSEMBLY 89 51 # include <d3dx9shader.h> 90 52 #endif 91 #include "vmsvga_glext/glext.h"92 93 #include "shaderlib/shaderlib.h"94 53 95 54 #include <stdlib.h> 96 55 #include <math.h> 97 #include <float.h> 56 #include <float.h> /* FLT_MIN */ 98 57 99 58 … … 101 60 * Defined Constants And Macros * 102 61 *******************************************************************************/ 103 /** Experimental: Create a dedicated context for handling surfaces in, thus104 * avoiding orphaned surfaces after context destruction.105 *106 * This cures, for instance, an assertion on fedora 21 that happens in107 * vmsvga3dSurfaceStretchBlt if the login screen and the desktop has different108 * sizes. The context of the login screen seems to have just been destroyed109 * earlier and I believe the driver/X/whoever is attemting to strech the old110 * screen content onto the new sized screen.111 *112 * @remarks This probably comes at a slight preformance expense, as we currently113 * switches context when setting up the surface the first time. Not sure114 * if we really need to, but as this is an experiment, I'm playing it safe.115 */116 #define VMSVGA3D_OGL_WITH_SHARED_CTX117 #ifdef VMSVGA3D_OGL_WITH_SHARED_CTX118 /** Fake surface ID for the shared context. */119 # define VMSVGA3D_SHARED_CTX_ID UINT32_C(0xffffeeee)120 #endif121 122 /** @def VBOX_VMSVGA3D_GL_HACK_LEVEL123 * Turns out that on Linux gl.h may often define the first 2-4 OpenGL versions124 * worth of extensions, but missing out on a function pointer of fifteen. This125 * causes headache for us when we use the function pointers below. This hack126 * changes the code to call the known problematic functions directly.127 * The value is ((x)<<16 | (y)) where x and y are taken from the GL_VERSION_x_y.128 */129 #ifndef VBOX_VMSVGA3D_GL_HACK_LEVEL130 # define VBOX_VMSVGA3D_GL_HACK_LEVEL 0131 #endif132 133 62 #ifndef VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE 134 63 # define VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE 1.0 … … 159 88 #define D3D_TO_OGL_Y_COORD_MIPLEVEL(ptrMipLevel, y_coordinate) (ptrMipLevel->size.height - (y_coordinate)) 160 89 161 #define OPENGL_INVALID_ID 0162 163 90 //#define MANUAL_FLIP_SURFACE_DATA 164 91 /* Enable to render the result of DrawPrimitive in a seperate window. */ 165 92 //#define DEBUG_GFX_WINDOW 166 167 168 /** @name VMSVGA3D_DEF_CTX_F_XXX - vmsvga3dContextDefineOgl flags.169 * @{ */170 /** When clear, the context is created using the default OpenGL profile.171 * When set, it's created using the alternative profile. The latter is only172 * allowed if the VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE is set. */173 #define VMSVGA3D_DEF_CTX_F_OTHER_PROFILE RT_BIT_32(0)174 /** Defining the shared context. */175 #define VMSVGA3D_DEF_CTX_F_SHARED_CTX RT_BIT_32(1)176 /** Defining the init time context (EMT). */177 #define VMSVGA3D_DEF_CTX_F_INIT RT_BIT_32(2)178 /** @} */179 180 181 #define VMSVGA3D_CLEAR_CURRENT_CONTEXT(pState) \182 do { (pState)->idActiveContext = OPENGL_INVALID_ID; } while (0)183 184 /** @def VMSVGA3D_SET_CURRENT_CONTEXT185 * Makes sure the @a pContext is the active OpenGL context.186 * @parm pState The VMSVGA3d state.187 * @parm pContext The new context.188 */189 #ifdef RT_OS_WINDOWS190 # define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \191 do { \192 if ((pState)->idActiveContext != (pContext)->id) \193 { \194 BOOL fMakeCurrentRc = wglMakeCurrent((pContext)->hdc, (pContext)->hglrc); \195 Assert(fMakeCurrentRc == TRUE); \196 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \197 (pState)->idActiveContext = (pContext)->id; \198 } \199 } while (0)200 201 #elif defined(RT_OS_DARWIN)202 # define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \203 do { \204 if ((pState)->idActiveContext != (pContext)->id) \205 { \206 vmsvga3dCocoaViewMakeCurrentContext((pContext)->cocoaView, (pContext)->cocoaContext); \207 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \208 (pState)->idActiveContext = (pContext)->id; \209 } \210 } while (0)211 #else212 # define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \213 do { \214 if ((pState)->idActiveContext != (pContext)->id) \215 { \216 Bool fMakeCurrentRc = glXMakeCurrent((pState)->display, \217 (pContext)->window, \218 (pContext)->glxContext); \219 Assert(fMakeCurrentRc == True); \220 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \221 (pState)->idActiveContext = (pContext)->id; \222 } \223 } while (0)224 #endif225 226 /** @def VMSVGA3D_CLEAR_GL_ERRORS227 * Clears all pending OpenGL errors.228 *229 * If I understood this correctly, OpenGL maintains a bitmask internally and230 * glGetError gets the next bit (clearing it) from the bitmap and translates it231 * into a GL_XXX constant value which it then returns. A single OpenGL call can232 * set more than one bit, and they stick around across calls, from what I233 * understand.234 *235 * So in order to be able to use glGetError to check whether a function236 * succeeded, we need to call glGetError until all error bits have been cleared.237 * This macro does that (in all types of builds).238 *239 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS240 */241 #define VMSVGA3D_CLEAR_GL_ERRORS() \242 do { \243 if (RT_UNLIKELY(glGetError() != GL_NO_ERROR)) /* predict no errors pending */ \244 { \245 uint32_t iErrorClearingLoopsLeft = 64; \246 while (glGetError() != GL_NO_ERROR && iErrorClearingLoopsLeft > 0) \247 iErrorClearingLoopsLeft--; \248 } \249 } while (0)250 251 /** @def VMSVGA3D_GET_LAST_GL_ERROR252 * Gets the last OpenGL error, stores it in a_pContext->lastError and returns253 * it.254 *255 * @returns Same as glGetError.256 * @param a_pContext The context to store the error in.257 *258 * @sa VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN259 */260 #define VMSVGA3D_GET_GL_ERROR(a_pContext) ((a_pContext)->lastError = glGetError())261 262 /** @def VMSVGA3D_GL_SUCCESS263 * Checks whether VMSVGA3D_GET_LAST_GL_ERROR() return GL_NO_ERROR.264 *265 * Will call glGetError() and store the result in a_pContext->lastError.266 * Will predict GL_NO_ERROR outcome.267 *268 * @returns True on success, false on error.269 * @parm a_pContext The context to store the error in.270 *271 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_COMPLAIN272 */273 #define VMSVGA3D_GL_IS_SUCCESS(a_pContext) RT_LIKELY((((a_pContext)->lastError = glGetError()) == GL_NO_ERROR))274 275 /** @def VMSVGA3D_GL_COMPLAIN276 * Complains about one or more OpenGL errors (first in a_pContext->lastError).277 *278 * Strict builds will trigger an assertion, while other builds will put the279 * first few occurences in the release log.280 *281 * All GL errors will be cleared after invocation. Assumes lastError282 * is an error, will not check for GL_NO_ERROR.283 *284 * @param a_pState The 3D state structure.285 * @param a_pContext The context that holds the first error.286 * @param a_LogRelDetails Argument list for LogRel or similar that describes287 * the operation in greater detail.288 *289 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS290 */291 #ifdef VBOX_STRICT292 # define VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \293 do { \294 AssertMsg((a_pState)->idActiveContext == (a_pContext)->id, \295 ("idActiveContext=%#x id=%x\n", (a_pState)->idActiveContext, (a_pContext)->id)); \296 RTAssertMsg2Weak a_LogRelDetails; \297 GLenum iNextError; \298 while ((iNextError = glGetError()) != GL_NO_ERROR) \299 RTAssertMsg2Weak("next error: %#x\n", iNextError); \300 AssertMsgFailed(("first error: %#x (idActiveContext=%#x)\n", (a_pContext)->lastError, (a_pContext)->id)); \301 } while (0)302 #else303 # define VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \304 do { \305 LogRelMax(32, ("VMSVGA3d: OpenGL error %#x (idActiveContext=%#x) on line %u ", (a_pContext)->lastError, (a_pContext)->id)); \306 GLenum iNextError; \307 while ((iNextError = glGetError()) != GL_NO_ERROR) \308 LogRelMax(32, (" - also error %#x ", iNextError)); \309 LogRelMax(32, a_LogRelDetails); \310 } while (0)311 #endif312 313 /** @def VMSVGA3D_GL_GET_AND_COMPLAIN314 * Combination of VMSVGA3D_GET_GL_ERROR and VMSVGA3D_GL_COMPLAIN, assuming that315 * there is a pending error.316 *317 * @param a_pState The 3D state structure.318 * @param a_pContext The context that holds the first error.319 * @param a_LogRelDetails Argument list for LogRel or similar that describes320 * the operation in greater detail.321 *322 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN323 */324 #define VMSVGA3D_GL_GET_AND_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \325 do { \326 VMSVGA3D_GET_GL_ERROR(a_pContext); \327 VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails); \328 } while (0)329 330 /** @def VMSVGA3D_GL_ASSERT_SUCCESS331 * Asserts that VMSVGA3D_GL_IS_SUCCESS is true, complains if not.332 *333 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release334 * logging in non-strict builds.335 *336 * @param a_pState The 3D state structure.337 * @param a_pContext The context that holds the first error.338 * @param a_LogRelDetails Argument list for LogRel or similar that describes339 * the operation in greater detail.340 *341 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN342 */343 #define VMSVGA3D_GL_ASSERT_SUCCESS(a_pState, a_pContext, a_LogRelDetails) \344 if (VMSVGA3D_GL_IS_SUCCESS(a_pContext)) \345 { /* likely */ } \346 else do { \347 VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails); \348 } while (0)349 350 /** @def VMSVGA3D_ASSERT_GL_CALL_EX351 * Executes the specified OpenGL API call and asserts that it succeeded, variant352 * with extra logging flexibility.353 *354 * ASSUMES no GL errors pending prior to invocation - caller should use355 * VMSVGA3D_CLEAR_GL_ERRORS if uncertain.356 *357 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release358 * logging in non-strict builds.359 *360 * @param a_GlCall Expression making an OpenGL call.361 * @param a_pState The 3D state structure.362 * @param a_pContext The context that holds the first error.363 * @param a_LogRelDetails Argument list for LogRel or similar that describes364 * the operation in greater detail.365 *366 * @sa VMSVGA3D_ASSERT_GL_CALL, VMSVGA3D_GL_ASSERT_SUCCESS,367 * VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN368 */369 #define VMSVGA3D_ASSERT_GL_CALL_EX(a_GlCall, a_pState, a_pContext, a_LogRelDetails) \370 do { \371 (a_GlCall); \372 VMSVGA3D_GL_ASSERT_SUCCESS(a_pState, a_pContext, a_LogRelDetails); \373 } while (0)374 375 /** @def VMSVGA3D_ASSERT_GL_CALL376 * Executes the specified OpenGL API call and asserts that it succeeded.377 *378 * ASSUMES no GL errors pending prior to invocation - caller should use379 * VMSVGA3D_CLEAR_GL_ERRORS if uncertain.380 *381 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release382 * logging in non-strict builds.383 *384 * @param a_GlCall Expression making an OpenGL call.385 * @param a_pState The 3D state structure.386 * @param a_pContext The context that holds the first error.387 *388 * @sa VMSVGA3D_ASSERT_GL_CALL_EX, VMSVGA3D_GL_ASSERT_SUCCESS,389 * VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN390 */391 #define VMSVGA3D_ASSERT_GL_CALL(a_GlCall, a_pState, a_pContext) \392 VMSVGA3D_ASSERT_GL_CALL_EX(a_GlCall, a_pState, a_pContext, ("%s\n", #a_GlCall))393 394 395 /** @def VMSVGA3D_CHECK_LAST_ERROR396 * Checks that the last OpenGL error code indicates success.397 *398 * Will assert and return VERR_INTERNAL_ERROR in strict builds, in other399 * builds it will do nothing and is a NOOP.400 *401 * @parm pState The VMSVGA3d state.402 * @parm pContext The context.403 *404 * @todo Replace with proper error handling, it's crazy to return405 * VERR_INTERNAL_ERROR in strict builds and just barge on ahead in406 * release builds.407 */408 #ifdef VBOX_STRICT409 # define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { \410 Assert((pState)->idActiveContext == (pContext)->id); \411 (pContext)->lastError = glGetError(); \412 AssertMsgReturn((pContext)->lastError == GL_NO_ERROR, \413 ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError), \414 VERR_INTERNAL_ERROR); \415 } while (0)416 #else417 # define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { } while (0)418 #endif419 420 /** @def VMSVGA3D_CHECK_LAST_ERROR_WARN421 * Checks that the last OpenGL error code indicates success.422 *423 * Will assert in strict builds, otherwise it's a NOOP.424 *425 * @parm pState The VMSVGA3d state.426 * @parm pContext The new context.427 */428 #ifdef VBOX_STRICT429 # define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { \430 Assert((pState)->idActiveContext == (pContext)->id); \431 (pContext)->lastError = glGetError(); \432 AssertMsg((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError)); \433 } while (0)434 #else435 # define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { } while (0)436 #endif437 93 438 94 … … 481 137 482 138 /******************************************************************************* 483 * Structures, Typedefs and Globals. *484 *******************************************************************************/485 typedef struct486 {487 SVGA3dSize size;488 uint32_t cbSurface;489 uint32_t cbSurfacePitch;490 void *pSurfaceData;491 bool fDirty;492 } VMSVGA3DMIPMAPLEVEL, *PVMSVGA3DMIPMAPLEVEL;493 494 /**495 * SSM descriptor table for the VMSVGA3DMIPMAPLEVEL structure.496 */497 static SSMFIELD const g_aVMSVGA3DMIPMAPLEVELFields[] =498 {499 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, size),500 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurface),501 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurfacePitch),502 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DMIPMAPLEVEL, pSurfaceData),503 SSMFIELD_ENTRY_IGNORE( VMSVGA3DMIPMAPLEVEL, fDirty),504 SSMFIELD_ENTRY_TERM()505 };506 507 typedef struct508 {509 uint32_t id;510 #ifdef VMSVGA3D_OGL_WITH_SHARED_CTX511 uint32_t idWeakContextAssociation;512 #else513 uint32_t idAssociatedContext;514 #endif515 uint32_t flags;516 SVGA3dSurfaceFormat format;517 GLint internalFormatGL;518 GLint formatGL;519 GLint typeGL;520 union521 {522 GLuint texture;523 GLuint buffer;524 GLuint renderbuffer;525 } oglId;526 SVGA3dSurfaceFace faces[SVGA3D_MAX_SURFACE_FACES];527 uint32_t cFaces;528 PVMSVGA3DMIPMAPLEVEL pMipmapLevels;529 uint32_t multiSampleCount;530 SVGA3dTextureFilter autogenFilter;531 uint32_t cbBlock; /* block/pixel size in bytes */532 /* Dirty state; surface was manually updated. */533 bool fDirty;534 } VMSVGA3DSURFACE, *PVMSVGA3DSURFACE;535 536 /**537 * SSM descriptor table for the VMSVGA3DSURFACE structure.538 */539 static SSMFIELD const g_aVMSVGA3DSURFACEFields[] =540 {541 SSMFIELD_ENTRY( VMSVGA3DSURFACE, id),542 #ifdef VMSVGA3D_OGL_WITH_SHARED_CTX543 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idWeakContextAssociation),544 #else545 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idAssociatedContext),546 #endif547 SSMFIELD_ENTRY( VMSVGA3DSURFACE, flags),548 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format),549 SSMFIELD_ENTRY( VMSVGA3DSURFACE, internalFormatGL),550 SSMFIELD_ENTRY( VMSVGA3DSURFACE, formatGL),551 SSMFIELD_ENTRY( VMSVGA3DSURFACE, typeGL),552 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, id),553 SSMFIELD_ENTRY( VMSVGA3DSURFACE, faces),554 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cFaces),555 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, pMipmapLevels),556 SSMFIELD_ENTRY( VMSVGA3DSURFACE, multiSampleCount),557 SSMFIELD_ENTRY( VMSVGA3DSURFACE, autogenFilter),558 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cbBlock),559 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fDirty),560 SSMFIELD_ENTRY_TERM()561 };562 563 typedef struct564 {565 uint32_t id;566 uint32_t cid;567 SVGA3dShaderType type;568 uint32_t cbData;569 void *pShaderProgram;570 union571 {572 void *pVertexShader;573 void *pPixelShader;574 } u;575 } VMSVGA3DSHADER, *PVMSVGA3DSHADER;576 577 /**578 * SSM descriptor table for the VMSVGA3DSHADER structure.579 */580 static SSMFIELD const g_aVMSVGA3DSHADERFields[] =581 {582 SSMFIELD_ENTRY( VMSVGA3DSHADER, id),583 SSMFIELD_ENTRY( VMSVGA3DSHADER, cid),584 SSMFIELD_ENTRY( VMSVGA3DSHADER, type),585 SSMFIELD_ENTRY( VMSVGA3DSHADER, cbData),586 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, pShaderProgram),587 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, u.pVertexShader),588 SSMFIELD_ENTRY_TERM()589 };590 591 typedef struct592 {593 bool fValid;594 float matrix[16];595 } VMSVGATRANSFORMSTATE, *PVMSVGATRANSFORMSTATE;596 597 typedef struct598 {599 bool fValid;600 SVGA3dMaterial material;601 } VMSVGAMATERIALSTATE, *PVMSVGAMATERIALSTATE;602 603 typedef struct604 {605 bool fValid;606 float plane[4];607 } VMSVGACLIPPLANESTATE, *PVMSVGACLIPPLANESTATE;608 609 typedef struct610 {611 bool fEnabled;612 bool fValidData;613 SVGA3dLightData data;614 } VMSVGALIGHTSTATE, *PVMSVGALIGHTSTATE;615 616 typedef struct617 {618 bool fValid;619 SVGA3dShaderConstType ctype;620 uint32_t value[4];621 } VMSVGASHADERCONST, *PVMSVGASHADERCONST;622 623 /**624 * SSM descriptor table for the VMSVGASHADERCONST structure.625 */626 static SSMFIELD const g_aVMSVGASHADERCONSTFields[] =627 {628 SSMFIELD_ENTRY( VMSVGASHADERCONST, fValid),629 SSMFIELD_ENTRY( VMSVGASHADERCONST, ctype),630 SSMFIELD_ENTRY( VMSVGASHADERCONST, value),631 SSMFIELD_ENTRY_TERM()632 };633 634 #define VMSVGA3D_UPDATE_SCISSORRECT RT_BIT(0)635 #define VMSVGA3D_UPDATE_ZRANGE RT_BIT(1)636 #define VMSVGA3D_UPDATE_VIEWPORT RT_BIT(2)637 #define VMSVGA3D_UPDATE_VERTEXSHADER RT_BIT(3)638 #define VMSVGA3D_UPDATE_PIXELSHADER RT_BIT(4)639 #define VMSVGA3D_UPDATE_TRANSFORM RT_BIT(5)640 #define VMSVGA3D_UPDATE_MATERIAL RT_BIT(6)641 642 typedef struct VMSVGA3DCONTEXT643 {644 uint32_t id;645 #ifdef RT_OS_WINDOWS646 /* Device context of the context window. */647 HDC hdc;648 /* OpenGL rendering context handle. */649 HGLRC hglrc;650 /* Device context window handle. */651 HWND hwnd;652 #elif defined(RT_OS_DARWIN)653 /* OpenGL rendering context */654 NativeNSOpenGLContextRef cocoaContext;655 NativeNSViewRef cocoaView;656 bool fOtherProfile;657 #else658 /** XGL rendering context handle */659 GLXContext glxContext;660 /** Device context window handle */661 Window window;662 /** flag whether the window is mapped (=visible) */663 bool fMapped;664 #endif665 /* Framebuffer object associated with this context. */666 GLuint idFramebuffer;667 /* Read and draw framebuffer objects for various operations. */668 GLuint idReadFramebuffer;669 GLuint idDrawFramebuffer;670 /* Last GL error recorded. */671 GLenum lastError;672 673 /* Current active render target (if any) */674 uint32_t sidRenderTarget;675 /* Current selected texture surfaces (if any) */676 uint32_t aSidActiveTexture[SVGA3D_MAX_TEXTURE_STAGE];677 /* Per context pixel and vertex shaders. */678 uint32_t cPixelShaders;679 PVMSVGA3DSHADER paPixelShader;680 uint32_t cVertexShaders;681 PVMSVGA3DSHADER paVertexShader;682 void *pShaderContext;683 /* Keep track of the internal state to be able to recreate the context properly (save/restore, window resize). */684 struct685 {686 uint32_t u32UpdateFlags;687 688 SVGA3dRenderState aRenderState[SVGA3D_RS_MAX];689 SVGA3dTextureState aTextureState[SVGA3D_MAX_TEXTURE_STAGE][SVGA3D_TS_MAX];690 VMSVGATRANSFORMSTATE aTransformState[SVGA3D_TRANSFORM_MAX];691 VMSVGAMATERIALSTATE aMaterial[SVGA3D_FACE_MAX];692 VMSVGACLIPPLANESTATE aClipPlane[SVGA3D_CLIPPLANE_MAX];693 VMSVGALIGHTSTATE aLightData[SVGA3D_MAX_LIGHTS];694 695 uint32_t aRenderTargets[SVGA3D_RT_MAX];696 SVGA3dRect RectScissor;697 SVGA3dRect RectViewPort;698 SVGA3dZRange zRange;699 uint32_t shidPixel;700 uint32_t shidVertex;701 702 uint32_t cPixelShaderConst;703 PVMSVGASHADERCONST paPixelShaderConst;704 uint32_t cVertexShaderConst;705 PVMSVGASHADERCONST paVertexShaderConst;706 } state;707 } VMSVGA3DCONTEXT, *PVMSVGA3DCONTEXT;708 709 /**710 * SSM descriptor table for the VMSVGA3DCONTEXT structure.711 */712 static SSMFIELD const g_aVMSVGA3DCONTEXTFields[] =713 {714 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, id),715 #ifdef RT_OS_WINDOWS716 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hdc),717 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hglrc),718 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hwnd),719 #endif720 721 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idFramebuffer),722 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idReadFramebuffer),723 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idDrawFramebuffer),724 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, lastError),725 726 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, sidRenderTarget),727 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, aSidActiveTexture),728 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cPixelShaders),729 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paPixelShader),730 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cVertexShaders),731 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paVertexShader),732 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pShaderContext),733 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.u32UpdateFlags),734 735 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderState),736 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTextureState),737 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTransformState),738 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aMaterial),739 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aClipPlane),740 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aLightData),741 742 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderTargets),743 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectScissor),744 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectViewPort),745 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.zRange),746 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidPixel),747 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidVertex),748 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cPixelShaderConst),749 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paPixelShaderConst),750 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cVertexShaderConst),751 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paVertexShaderConst),752 SSMFIELD_ENTRY_TERM()753 };754 755 /**756 * VMSVGA3d state data.757 *758 * Allocated on the heap and pointed to by VMSVGAState::p3dState.759 */760 typedef struct VMSVGA3DSTATE761 {762 #ifdef RT_OS_WINDOWS763 /** Window Thread. */764 R3PTRTYPE(RTTHREAD) pWindowThread;765 DWORD idWindowThread;766 HMODULE hInstance;767 /** Window request semaphore. */768 RTSEMEVENT WndRequestSem;769 #elif defined(RT_OS_LINUX)770 /* The X display */771 Display *display;772 R3PTRTYPE(RTTHREAD) pWindowThread;773 bool bTerminate;774 #endif775 776 float fGLVersion;777 /* Current active context. */778 uint32_t idActiveContext;779 780 struct781 {782 PFNGLISRENDERBUFFERPROC glIsRenderbuffer;783 PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;784 PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;785 PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;786 PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;787 PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv;788 PFNGLISFRAMEBUFFERPROC glIsFramebuffer;789 PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;790 PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;791 PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;792 PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;793 PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;794 PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;795 PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D;796 PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;797 PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv;798 PFNGLGENERATEMIPMAPPROC glGenerateMipmap;799 PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;800 PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample;801 PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer;802 PFNGLPOINTPARAMETERFPROC glPointParameterf;803 #if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x102804 PFNGLBLENDCOLORPROC glBlendColor;805 PFNGLBLENDEQUATIONPROC glBlendEquation;806 #endif807 PFNGLBLENDEQUATIONSEPARATEPROC glBlendEquationSeparate;808 PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;809 PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate;810 PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate;811 PFNGLBINDBUFFERPROC glBindBuffer;812 PFNGLDELETEBUFFERSPROC glDeleteBuffers;813 PFNGLGENBUFFERSPROC glGenBuffers;814 PFNGLBUFFERDATAPROC glBufferData;815 PFNGLMAPBUFFERPROC glMapBuffer;816 PFNGLUNMAPBUFFERPROC glUnmapBuffer;817 PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;818 PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;819 PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;820 PFNGLFOGCOORDPOINTERPROC glFogCoordPointer;821 PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex;822 PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex;823 PFNGLACTIVETEXTUREPROC glActiveTexture;824 #if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x103825 PFNGLCLIENTACTIVETEXTUREPROC glClientActiveTexture;826 #endif827 PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;828 PFNGLPROVOKINGVERTEXPROC glProvokingVertex;829 bool fEXT_stencil_two_side;830 } ext;831 832 struct833 {834 GLint maxActiveLights;835 GLint maxTextureBufferSize;836 GLint maxTextures;837 GLint maxClipDistances;838 GLint maxColorAttachments;839 GLint maxRectangleTextureSize;840 GLint maxTextureAnisotropy;841 GLint maxVertexShaderInstructions;842 GLint maxFragmentShaderInstructions;843 GLint maxVertexShaderTemps;844 GLint maxFragmentShaderTemps;845 GLfloat flPointSize[2];846 SVGA3dPixelShaderVersion fragmentShaderVersion;847 SVGA3dVertexShaderVersion vertexShaderVersion;848 bool fS3TCSupported;849 } caps;850 851 uint32_t cContexts;852 PVMSVGA3DCONTEXT *papContexts;853 uint32_t cSurfaces;854 PVMSVGA3DSURFACE *papSurfaces;855 #ifdef DEBUG_GFX_WINDOW_TEST_CONTEXT856 uint32_t idTestContext;857 #endif858 /** The GL_EXTENSIONS value (space padded) for the default OpenGL profile.859 * Free with RTStrFree. */860 R3PTRTYPE(char *) pszExtensions;861 862 /** The GL_EXTENSIONS value (space padded) for the other OpenGL profile.863 * Free with RTStrFree.864 *865 * This is used to detect shader model version since some implementations866 * (darwin) hides extensions that have made it into core and probably a867 * bunch of others when using a OpenGL core profile instead of a legacy one */868 R3PTRTYPE(char *) pszOtherExtensions;869 /** The version of the other GL profile. */870 float fOtherGLVersion;871 872 /** Shader talk back interface. */873 VBOXVMSVGASHADERIF ShaderIf;874 875 #ifdef VMSVGA3D_OGL_WITH_SHARED_CTX876 /** The shared context. */877 VMSVGA3DCONTEXT SharedCtx;878 #endif879 } VMSVGA3DSTATE;880 881 /**882 * SSM descriptor table for the VMSVGA3DSTATE structure.883 */884 static SSMFIELD const g_aVMSVGA3DSTATEFields[] =885 {886 #ifdef RT_OS_WINDOWS887 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, pWindowThread),888 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, idWindowThread),889 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, hInstance),890 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, WndRequestSem),891 #elif defined(RT_OS_LINUX)892 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, display),893 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, pWindowThread),894 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, bTerminate),895 #endif896 SSMFIELD_ENTRY( VMSVGA3DSTATE, fGLVersion),897 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, idActiveContext),898 899 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, ext),900 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, caps),901 902 SSMFIELD_ENTRY( VMSVGA3DSTATE, cContexts),903 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, papContexts),904 SSMFIELD_ENTRY( VMSVGA3DSTATE, cSurfaces),905 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, papSurfaces),906 SSMFIELD_ENTRY_TERM()907 };908 909 910 /** Save and setup everything. */911 #define VMSVGA3D_PARANOID_TEXTURE_PACKING912 913 /**914 * Saved texture packing parameters (shared by both pack and unpack).915 */916 typedef struct VMSVGAPACKPARAMS917 {918 GLint iAlignment;919 GLint cxRow;920 #ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING921 GLint cyImage;922 GLboolean fSwapBytes;923 GLboolean fLsbFirst;924 GLint cSkipRows;925 GLint cSkipPixels;926 GLint cSkipImages;927 #endif928 } VMSVGAPACKPARAMS;929 /** Pointer to saved texture packing parameters. */930 typedef VMSVGAPACKPARAMS *PVMSVGAPACKPARAMS;931 /** Pointer to const saved texture packing parameters. */932 typedef VMSVGAPACKPARAMS const *PCVMSVGAPACKPARAMS;933 934 935 /*******************************************************************************936 139 * Global Variables * 937 140 *******************************************************************************/ … … 959 162 *******************************************************************************/ 960 163 static int vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface); 961 static int vmsvga3dContextDefineOgl(PVGASTATE pThis, uint32_t cid, uint32_t fFlags);962 164 static int vmsvga3dContextDestroyOgl(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext, uint32_t cid); 963 165 static void vmsvgaColor2GLFloatArray(uint32_t color, GLfloat *pRed, GLfloat *pGreen, GLfloat *pBlue, GLfloat *pAlpha); 964 static void vmsvga3dSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,965 PVMSVGAPACKPARAMS pSave);966 static void vmsvga3dRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,967 PCVMSVGAPACKPARAMS pSave);968 166 969 167 /* Generated by VBoxDef2LazyLoad from the VBoxSVGA3D.def and VBoxSVGA3DObjC.def files. */ … … 1886 1084 } 1887 1085 1888 /* Shared functions that depend on private structure definitions. */1889 #define VMSVGA3D_OPENGL1890 #include "DevVGA-SVGA3d-shared.h"1891 1086 1892 1087 /** … … 3286 2481 * @param pSave Where to save stuff. 3287 2482 */ 3288 static void vmsvga3dSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface, 3289 PVMSVGAPACKPARAMS pSave) 2483 void vmsvga3dSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface, PVMSVGAPACKPARAMS pSave) 3290 2484 { 3291 2485 /* … … 3361 2555 * @param pSave Where stuff was saved. 3362 2556 */ 3363 staticvoid vmsvga3dRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,3364 2557 void vmsvga3dRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface, 2558 PCVMSVGAPACKPARAMS pSave) 3365 2559 { 3366 2560 NOREF(pSurface); … … 4287 3481 * @param fFlags VMSVGA3D_DEF_CTX_F_XXX. 4288 3482 */ 4289 staticint vmsvga3dContextDefineOgl(PVGASTATE pThis, uint32_t cid, uint32_t fFlags)3483 int vmsvga3dContextDefineOgl(PVGASTATE pThis, uint32_t cid, uint32_t fFlags) 4290 3484 { 4291 3485 int rc;
Note:
See TracChangeset
for help on using the changeset viewer.