DevVGA-SVGA3d-ogl.cpp revision e819feefdc34d50781a3c95edecda1072e8575d0
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * DevVMWare - VMWare SVGA device
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2013-2014 Oracle Corporation
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * available from http://www.virtualbox.org. This file is free software;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * you can redistribute it and/or modify it under the terms of the GNU
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * General Public License (GPL) as published by the Free Software
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync/*******************************************************************************
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync* Header Files *
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync*******************************************************************************/
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync# define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync/* work around conflicting definition of GLhandleARB in VMware's glext.h */
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync//#define GL_ARB_shader_objects
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsynctypedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer);
044af0d1e6474076366759db86f101778c5f20ccvboxsynctypedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsynctypedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params);
044af0d1e6474076366759db86f101778c5f20ccvboxsync//HACK FOR NOW
044af0d1e6474076366759db86f101778c5f20ccvboxsynctypedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* Another copy in shaderapi.c. */
044af0d1e6474076366759db86f101778c5f20ccvboxsync s_image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
044af0d1e6474076366759db86f101778c5f20ccvboxsync# define OGLGETPROCADDRESS(x) glXGetProcAddress((const GLubyte *)x)
044af0d1e6474076366759db86f101778c5f20ccvboxsync/* Invert y-coordinate for OpenGL's bottom left origin. */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#define D3D_TO_OGL_Y_COORD(ptrSurface, y_coordinate) (ptrSurface->pMipmapLevels[0].size.height - (y_coordinate))
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#define D3D_TO_OGL_Y_COORD_MIPLEVEL(ptrMipLevel, y_coordinate) (ptrMipLevel->size.height - (y_coordinate))
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync//#define MANUAL_FLIP_SURFACE_DATA
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync/* Enable to render the result of DrawPrimitive in a seperate window. */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync//#define DEBUG_GFX_WINDOW
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/*******************************************************************************
044af0d1e6474076366759db86f101778c5f20ccvboxsync* Structures and Typedefs *
044af0d1e6474076366759db86f101778c5f20ccvboxsync*******************************************************************************/
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync do { (pState)->idActiveContext = OPENGL_INVALID_ID; } while (0)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
044af0d1e6474076366759db86f101778c5f20ccvboxsync BOOL makecurret = wglMakeCurrent((pContext)->hdc, (pContext)->hglrc); \
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync } else do { } while (0)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync vmsvga3dCocoaViewMakeCurrentContext((pContext)->cocoaView, (pContext)->cocoaContext); \
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync } else do { } while (0)
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync Bool makecurret = glXMakeCurrent((pState)->display, \
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync } else do { } while (0)
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { \
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync Assert((pState)->idActiveContext == (pContext)->id); \
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync AssertMsgReturn((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError), VERR_INTERNAL_ERROR); \
a1df400bbe9d64aad400442e56eb637019300a5evboxsync } while (0)
a1df400bbe9d64aad400442e56eb637019300a5evboxsync# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { } while (0)
044af0d1e6474076366759db86f101778c5f20ccvboxsync# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { \
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync Assert((pState)->idActiveContext == (pContext)->id); \
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync AssertMsg((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError)); \
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync } while (0)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { } while (0)
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync/** Macro wrapping glGetIntegerv for use during initialization.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * This will release log errors. */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#define VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE(a_enmGlValue, a_pDest) \
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync LogRel(("VMSVGA3d: glGetIntegerv(" #a_enmGlValue " (%#x),) -> %#x\n", (int)a_enmGlValue, iGlError)); \
044af0d1e6474076366759db86f101778c5f20ccvboxsync } while (0)
044af0d1e6474076366759db86f101778c5f20ccvboxsync/** Macro for doing something and then checking for errors during initialization. */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync LogRel(("VMSVGA3d: " #a_Expr " -> %#x\n", iGlError)); \
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync } while (0)
7d80dfbe5d66fc4c6de6fe109ce96a081496dcd4vboxsynctypedef struct
7d80dfbe5d66fc4c6de6fe109ce96a081496dcd4vboxsync * SSM descriptor table for the VMSVGA3DMIPMAPLEVEL structure.
7d80dfbe5d66fc4c6de6fe109ce96a081496dcd4vboxsyncstatic SSMFIELD const g_aVMSVGA3DMIPMAPLEVELFields[] =
7d80dfbe5d66fc4c6de6fe109ce96a081496dcd4vboxsync SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurfacePitch),
7d80dfbe5d66fc4c6de6fe109ce96a081496dcd4vboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DMIPMAPLEVEL, pSurfaceData),
7d80dfbe5d66fc4c6de6fe109ce96a081496dcd4vboxsync SSMFIELD_ENTRY_IGNORE( VMSVGA3DMIPMAPLEVEL, fDirty),
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsynctypedef struct
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* Dirty state; surface was manually updated. */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync * SSM descriptor table for the VMSVGA3DSURFACE structure.
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync SSMFIELD_ENTRY( VMSVGA3DSURFACE, idAssociatedContext),
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync SSMFIELD_ENTRY( VMSVGA3DSURFACE, internalFormatGL),
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, pMipmapLevels),
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync SSMFIELD_ENTRY( VMSVGA3DSURFACE, multiSampleCount),
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsynctypedef struct
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync * SSM descriptor table for the VMSVGA3DSHADER structure.
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, pShaderProgram),
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, u.pVertexShader),
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsynctypedef struct
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsynctypedef struct
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsynctypedef struct
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsynctypedef struct
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsynctypedef struct
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync * SSM descriptor table for the VMSVGASHADERCONST structure.
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsyncstatic SSMFIELD const g_aVMSVGASHADERCONSTFields[] =
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsynctypedef struct
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* Device context of the context window. */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* OpenGL rendering context handle. */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* Device context window handle. */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* OpenGL rendering context */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /** XGL rendering context handle */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /** Device context window handle */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /** flag whether the window is mapped (=visible) */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* Framebuffer object associated with this context. */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* Read and draw framebuffer objects for various operations. */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* Last GL error recorded. */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* Current active render target (if any) */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* Current selected texture surfaces (if any) */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync uint32_t aSidActiveTexture[SVGA3D_MAX_TEXTURE_STAGE];
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* Per context pixel and vertex shaders. */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* Keep track of the internal state to be able to recreate the context properly (save/restore, window resize). */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync SVGA3dTextureState aTextureState[SVGA3D_MAX_TEXTURE_STAGE][SVGA3D_TS_MAX];
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync VMSVGATRANSFORMSTATE aTransformState[SVGA3D_TRANSFORM_MAX];
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync VMSVGACLIPPLANESTATE aClipPlane[SVGA3D_CLIPPLANE_MAX];
d6f8b76ab3b2ec0c270c96f9db6e2568fc41b5fevboxsync * SSM descriptor table for the VMSVGA3DCONTEXT structure.
d6f8b76ab3b2ec0c270c96f9db6e2568fc41b5fevboxsync SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idFramebuffer),
d6f8b76ab3b2ec0c270c96f9db6e2568fc41b5fevboxsync SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idReadFramebuffer),
d6f8b76ab3b2ec0c270c96f9db6e2568fc41b5fevboxsync SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idDrawFramebuffer),
d6f8b76ab3b2ec0c270c96f9db6e2568fc41b5fevboxsync SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, sidRenderTarget),
d6f8b76ab3b2ec0c270c96f9db6e2568fc41b5fevboxsync SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, aSidActiveTexture),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paPixelShader),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paVertexShader),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pShaderContext),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.u32UpdateFlags),
9af7167fa39f1f139899c989da973e59b9cccc3fvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderState),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTextureState),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTransformState),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aClipPlane),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aLightData),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderTargets),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectScissor),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectViewPort),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidVertex),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cPixelShaderConst),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paPixelShaderConst),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cVertexShaderConst),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paVertexShaderConst),
daa94352f51be2329ac8660f70396e03a7cb983bvboxsynctypedef struct
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync /** Window Thread. */
6ba706e9f431401d425d16817fdcd6316f83b584vboxsync /** Window request semaphore. */
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync /* The X display */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Current active context. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLBLENDEQUATIONSEPARATEPROC glBlendEquationSeparate;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex;
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex;
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync PFNGLCLIENTACTIVETEXTUREPROC glClientActiveTexture;
31771163041e3661403a806eb3382d2a165c003bvboxsync * SSM descriptor table for the VMSVGA3DSTATE structure.
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, pWindowThread),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, idWindowThread),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, WndRequestSem),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, pWindowThread),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync SSMFIELD_ENTRY_IGNORE( VMSVGA3DSTATE, idActiveContext),
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, paContext),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSTATE, paSurface),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync/* Define the default light parameters as specified by MSDN. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync/* @todo move out; fetched from Wine */
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync false, /* inWorldSpace */
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsyncstatic int vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface);
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsyncstatic void vmsvgaColor2GLFloatArray(uint32_t color, GLfloat *pRed, GLfloat *pGreen, GLfloat *pBlue, GLfloat *pAlpha);
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync * Checks if the given OpenGL extension is supported.
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync * @returns true if supported, false if not.
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync * @param fActualGLVersion The actual OpenGL version we're working against.
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync * @param fMinGLVersion The OpenGL version that introduced this feature
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync * into the core.
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync * @param pszWantedExtension The name of the OpenGL extension we want.
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync * @remarks Init time only.
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsyncstatic bool vmsvga3dCheckGLExtension(float fActualGLVersion, float fMinGLVersion, const char *pszWantedExtension)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync bool fRet = false;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * OpenGL 3.2+ core profile (glGetString(GL_EXTENSIONS) returns NULL).
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * It also avoids listing extensions that have been promoted into the core.
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Seems like extensions are assimilated into the OpenGL core, so we do
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync hardcoded checks for these as per gl3.h. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (0) { /*nothing*/ }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && ( strcmp(pszWantedExtension, "GL_ARB_draw_buffers") == 0
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync || strcmp(pszWantedExtension, "GL_ARB_shader_objects") == 0 /*??*/
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_vertex_shader") == 0 /*??*/
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_fragment_shader") == 0 /*??*/
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_shading_language_100") == 0 /*??*/
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_texture_non_power_of_two") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_point_sprite") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ATI_separate_stencil") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_EXT_stencil_two_side") == 0) )
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && ( strcmp(pszWantedExtension, "GL_EXT_texture_sRGB") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_pixel_buffer_object") == 0) )
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && ( strcmp(pszWantedExtension, "GL_ARB_framebuffer_object") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_map_buffer_range") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_vertex_array_object") == 0) )
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync && ( strcmp(pszWantedExtension, "GL_ARB_copy_buffer") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_uniform_buffer_object") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_vertex_array_object") == 0) )
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && ( strcmp(pszWantedExtension, "GL_ARB_draw_elements_base_vertex") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_vertex_array_bgra") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_provoking_vertex") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_seamless_cube_map") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_fragment_coord_conventions") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_depth_clamp") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_texture_multisample") == 0) )
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && ( strcmp(pszWantedExtension, "GL_ARB_blend_func_extended") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_sampler_objects") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_explicit_attrib_location") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_occlusion_query2") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_shader_bit_encoding") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_texture_rgb10_a2ui") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_texture_swizzle") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_timer_query") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_vertex_type_2_10_10_10_rev") == 0) )
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && ( strcmp(pszWantedExtension, "GL_ARB_texture_query_lod") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_draw_indirect") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_gpu_shader5") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_gpu_shader_fp64") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_shader_subroutine") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_tessellation_shader") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_texture_buffer_object_rgb32") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_texture_cube_map_array") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_texture_gather") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_transform_feedback2") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_transform_feedback3") == 0) )
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && ( strcmp(pszWantedExtension, "GL_ARB_ES2_compatibility") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_get_program_binary") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_separate_shader_objects") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_shader_precision") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_vertex_attrib_64bit") == 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || strcmp(pszWantedExtension, "GL_ARB_viewport_array") == 0) )
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Search the GL_EXTENSIONS array. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync static PFNGLGETSTRINGIPROC s_pfnGlGetStringi = NULL;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync s_pfnGlGetStringi = (PFNGLGETSTRINGIPROC)OGLGETPROCADDRESS("glGetStringi");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE(GL_NUM_EXTENSIONS, &cExtensions);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync for (GLint idxCur = 0; idxCur < cExtensions; idxCur++)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync const char *pszCur = (const char *)s_pfnGlGetStringi(GL_EXTENSIONS, idxCur);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * Old interface.
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync char *pSupportedExtensions = (char *)glGetString(GL_EXTENSIONS);
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync size_t cchWantedExtension = strlen(pszWantedExtension);
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync while (true)
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync pExtensionSupported = strstr(pExtensionSupported, pszWantedExtension);
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync && ( pExtensionSupported[cchWantedExtension] == ' '
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync || pExtensionSupported[cchWantedExtension] == '\0')
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync /* Temporarily. Later start if (fMinGLVersion != 0.0 && fActualGLVersion >= fMinGLVersion) return true; */
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync AssertMsg(fMinGLVersion == 0.0 || fRet == (fActualGLVersion >= fMinGLVersion),
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync ("%s actual:%d min:%d\n", pszWantedExtension, (int)(fActualGLVersion * 10), (int)(fMinGLVersion * 10) ));
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync * Outputs GL_EXTENSIONS list to the release log.
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsyncstatic void vmsvga3dLogRelExtensions(void)
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync /* OpenGL 3.0 interface (glGetString(GL_EXTENSIONS) return NULL). */
9b19ad593b379ebfcc8273f85b90763b14b1da63vboxsync PFNGLGETSTRINGIPROC pfnGlGetStringi = (PFNGLGETSTRINGIPROC)OGLGETPROCADDRESS("glGetStringi");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE(GL_NUM_EXTENSIONS, &cExtensions);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync LogRel(("VMSVGA3d: OpenGL extensions (GL_NUM_EXTENSIONS=%d)", cExtensions));
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync for (GLint idxCur = 0; idxCur < cExtensions; idxCur++)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync const char *pszExt = (const char *)pfnGlGetStringi(GL_EXTENSIONS, idxCur);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync const char *pszFmt = idxCur % 3 ? " %-26s" : "\nVMSVGA3d: %-26s";
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* Old interface. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync LogRel(("VMSVGA3d: OpenGL extensions: %s\n\n", glGetString(GL_EXTENSIONS)));
2d8870843ff566fee9bd3a6a5942414254106479vboxsync pThis->svga.p3dState = RTMemAllocZ(sizeof(VMSVGA3DSTATE));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Create event semaphore. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Log(("%s: Failed to create event semaphore for window handling.\n", __FUNCTION__));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Create the async IO thread. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = RTThreadCreate(&pState->pWindowThread, vmsvga3dWindowThread, pState->WndRequestSem, 0, RTTHREADTYPE_GUI, 0, "VMSVGA3DWND");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertMsgFailed(("%s: Async IO Thread creation for 3d window handling failed rc=%d\n", __FUNCTION__, rc));
9d020a0622f95aec3aabaff436a495e88dbbd71avboxsync/* We must delay window creation until the PowerOn phase. Init is too early and will cause failures. */
2d8870843ff566fee9bd3a6a5942414254106479vboxsync PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync return VINF_SUCCESS; /* already initialized (load state) */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* OpenGL function calls aren't possible without a valid current context, so create a fake one here. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync LogRel(("VMSVGA3d: OpenGL version: %s\nOpenGL Vendor: %s\nOpenGL Renderer: %s\n", glGetString(GL_VERSION), glGetString(GL_VENDOR), glGetString(GL_RENDERER)));
9d020a0622f95aec3aabaff436a495e88dbbd71avboxsync LogRel(("VMSVGA3d: OpenGL shader language version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION)));
9d020a0622f95aec3aabaff436a495e88dbbd71avboxsync pState->fGLVersion = atof((const char *)glGetString(GL_VERSION));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (vmsvga3dCheckGLExtension(pState->fGLVersion, 3.0, "GL_ARB_framebuffer_object"))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->ext.glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)OGLGETPROCADDRESS("glIsRenderbuffer");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->ext.glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)OGLGETPROCADDRESS("glBindRenderbuffer");
9d020a0622f95aec3aabaff436a495e88dbbd71avboxsync pState->ext.glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)OGLGETPROCADDRESS("glDeleteRenderbuffers");
9d020a0622f95aec3aabaff436a495e88dbbd71avboxsync pState->ext.glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)OGLGETPROCADDRESS("glGenRenderbuffers");
9d020a0622f95aec3aabaff436a495e88dbbd71avboxsync pState->ext.glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)OGLGETPROCADDRESS("glRenderbufferStorage");
9d020a0622f95aec3aabaff436a495e88dbbd71avboxsync pState->ext.glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)OGLGETPROCADDRESS("glGetRenderbufferParameteriv");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->ext.glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)OGLGETPROCADDRESS("glIsFramebuffer");
9d020a0622f95aec3aabaff436a495e88dbbd71avboxsync pState->ext.glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)OGLGETPROCADDRESS("glBindFramebuffer");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->ext.glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)OGLGETPROCADDRESS("glDeleteFramebuffers");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)OGLGETPROCADDRESS("glGenFramebuffers");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)OGLGETPROCADDRESS("glCheckFramebufferStatus");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)OGLGETPROCADDRESS("glFramebufferTexture1D");
682342827b0e80c493c820603508e79e76c42658vboxsync pState->ext.glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)OGLGETPROCADDRESS("glFramebufferTexture2D");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)OGLGETPROCADDRESS("glFramebufferTexture3D");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)OGLGETPROCADDRESS("glFramebufferRenderbuffer");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)OGLGETPROCADDRESS("glGetFramebufferAttachmentParameteriv");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)OGLGETPROCADDRESS("glGenerateMipmap");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC)OGLGETPROCADDRESS("glBlitFramebuffer");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC)OGLGETPROCADDRESS("glRenderbufferStorageMultisample");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC)OGLGETPROCADDRESS("glFramebufferTextureLayer");
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glPointParameterf = (PFNGLPOINTPARAMETERFPROC)OGLGETPROCADDRESS("glPointParameterf");
044af0d1e6474076366759db86f101778c5f20ccvboxsync AssertMsgReturn(pState->ext.glPointParameterf, ("glPointParameterf missing"), VERR_NOT_IMPLEMENTED);
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glBlendEquation = (PFNGLBLENDEQUATIONPROC)OGLGETPROCADDRESS("glBlendEquation");
044af0d1e6474076366759db86f101778c5f20ccvboxsync AssertMsgReturn(pState->ext.glBlendEquation, ("glBlendEquation missing"), VERR_NOT_IMPLEMENTED);
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC)OGLGETPROCADDRESS("glBlendEquationSeparate");
044af0d1e6474076366759db86f101778c5f20ccvboxsync AssertMsgReturn(pState->ext.glBlendEquationSeparate, ("glBlendEquationSeparate missing"), VERR_NOT_IMPLEMENTED);
044af0d1e6474076366759db86f101778c5f20ccvboxsync pState->ext.glBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC)OGLGETPROCADDRESS("glBlendFuncSeparate");
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync AssertMsgReturn(pState->ext.glBlendFuncSeparate, ("glBlendFuncSeparate missing"), VERR_NOT_IMPLEMENTED);
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync pState->ext.glStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC)OGLGETPROCADDRESS("glStencilOpSeparate");
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync AssertMsgReturn(pState->ext.glStencilOpSeparate, ("glStencilOpSeparate missing"), VERR_NOT_IMPLEMENTED);
682342827b0e80c493c820603508e79e76c42658vboxsync pState->ext.glStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC)OGLGETPROCADDRESS("glStencilFuncSeparate");
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync AssertMsgReturn(pState->ext.glStencilFuncSeparate, ("glStencilFuncSeparate missing"), VERR_NOT_IMPLEMENTED);
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync pState->ext.glBlendColor = (PFNGLBLENDCOLORPROC)OGLGETPROCADDRESS("glBlendColor");
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync AssertMsgReturn(pState->ext.glBlendColor, ("glBlendColor missing"), VERR_NOT_IMPLEMENTED);
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync pState->ext.glBindBuffer = (PFNGLBINDBUFFERPROC)OGLGETPROCADDRESS("glBindBuffer");
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync AssertMsgReturn(pState->ext.glBindBuffer, ("glBindBuffer missing"), VERR_NOT_IMPLEMENTED);
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync pState->ext.glDeleteBuffers = (PFNGLDELETEBUFFERSPROC)OGLGETPROCADDRESS("glDeleteBuffers");
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync AssertMsgReturn(pState->ext.glDeleteBuffers, ("glDeleteBuffers missing"), VERR_NOT_IMPLEMENTED);
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync pState->ext.glGenBuffers = (PFNGLGENBUFFERSPROC)OGLGETPROCADDRESS("glGenBuffers");
682342827b0e80c493c820603508e79e76c42658vboxsync AssertMsgReturn(pState->ext.glGenBuffers, ("glGenBuffers missing"), VERR_NOT_IMPLEMENTED);
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync pState->ext.glBufferData = (PFNGLBUFFERDATAPROC)OGLGETPROCADDRESS("glBufferData");
682342827b0e80c493c820603508e79e76c42658vboxsync AssertMsgReturn(pState->ext.glBufferData, ("glBufferData missing"), VERR_NOT_IMPLEMENTED);
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync pState->ext.glMapBuffer = (PFNGLMAPBUFFERPROC)OGLGETPROCADDRESS("glMapBuffer");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertMsgReturn(pState->ext.glMapBuffer, ("glMapBuffer missing"), VERR_NOT_IMPLEMENTED);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->ext.glUnmapBuffer = (PFNGLUNMAPBUFFERPROC)OGLGETPROCADDRESS("glUnmapBuffer");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertMsgReturn(pState->ext.glUnmapBuffer, ("glUnmapBuffer missing"), VERR_NOT_IMPLEMENTED);
682342827b0e80c493c820603508e79e76c42658vboxsync pState->ext.glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)OGLGETPROCADDRESS("glEnableVertexAttribArray");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertMsgReturn(pState->ext.glEnableVertexAttribArray, ("glEnableVertexAttribArray missing"), VERR_NOT_IMPLEMENTED);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->ext.glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC)OGLGETPROCADDRESS("glDisableVertexAttribArray");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertMsgReturn(pState->ext.glDisableVertexAttribArray, ("glDisableVertexAttribArray missing"), VERR_NOT_IMPLEMENTED);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->ext.glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)OGLGETPROCADDRESS("glVertexAttribPointer");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertMsgReturn(pState->ext.glVertexAttribPointer, ("glVertexAttribPointer missing"), VERR_NOT_IMPLEMENTED);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->ext.glFogCoordPointer = (PFNGLFOGCOORDPOINTERPROC)OGLGETPROCADDRESS("glFogCoordPointer");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertMsgReturn(pState->ext.glFogCoordPointer, ("glFogCoordPointer missing"), VERR_NOT_IMPLEMENTED);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->ext.glActiveTexture = (PFNGLACTIVETEXTUREPROC)OGLGETPROCADDRESS("glActiveTexture");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertMsgReturn(pState->ext.glActiveTexture, ("glActiveTexture missing"), VERR_NOT_IMPLEMENTED);
682342827b0e80c493c820603508e79e76c42658vboxsync pState->ext.glClientActiveTexture = (PFNGLCLIENTACTIVETEXTUREPROC)OGLGETPROCADDRESS("glClientActiveTexture");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertMsgReturn(pState->ext.glClientActiveTexture, ("glClientActiveTexture missing"), VERR_NOT_IMPLEMENTED);
682342827b0e80c493c820603508e79e76c42658vboxsync pState->ext.glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC)OGLGETPROCADDRESS("glGetProgramivARB");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertMsgReturn(pState->ext.glGetProgramivARB, ("glGetProgramivARB missing"), VERR_NOT_IMPLEMENTED);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* OpenGL 3.2 core */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync if (vmsvga3dCheckGLExtension(pState->fGLVersion, 3.2, "GL_ARB_draw_elements_base_vertex"))
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync pState->ext.glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC)OGLGETPROCADDRESS("glDrawElementsBaseVertex");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->ext.glDrawElementsInstancedBaseVertex = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC)OGLGETPROCADDRESS("glDrawElementsInstancedBaseVertex");
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync LogRel(("VMSVGA3d: missing extension GL_ARB_draw_elements_base_vertex\n"));
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* OpenGL 3.2 core */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync if (vmsvga3dCheckGLExtension(pState->fGLVersion, 3.2, "GL_ARB_provoking_vertex"))
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync pState->ext.glProvokingVertex = (PFNGLPROVOKINGVERTEXPROC)OGLGETPROCADDRESS("glProvokingVertex");
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync LogRel(("VMSVGA3d: missing extension GL_ARB_provoking_vertex\n"));
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* Extension support */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /** @todo OpenGL version history suggest this, verify... */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync pState->ext.fEXT_stencil_two_side = vmsvga3dCheckGLExtension(pState->fGLVersion, 2.0, "GL_EXT_stencil_two_side");
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync pState->ext.fEXT_stencil_two_side = vmsvga3dCheckGLExtension(pState->fGLVersion, 0.0, "GL_EXT_stencil_two_side");
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* First set sensible defaults. */
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync pState->caps.vertexShaderVersion = SVGA3DVSVERSION_NONE;
b7a07b07543924f45c1fffd2f90de582038b8ba6vboxsync pState->caps.fragmentShaderVersion = SVGA3DPSVERSION_NONE;
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* Query capabilities */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE(GL_MAX_LIGHTS, &pState->caps.maxActiveLights);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE(GL_MAX_TEXTURE_BUFFER_SIZE, &pState->caps.maxTextureBufferSize);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE(GL_MAX_TEXTURE_UNITS_ARB, &pState->caps.maxTextures);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE(GL_MAX_CLIP_DISTANCES, &pState->caps.maxClipDistances);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE(GL_MAX_COLOR_ATTACHMENTS, &pState->caps.maxColorAttachments);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE(GL_MAX_RECTANGLE_TEXTURE_SIZE, &pState->caps.maxRectangleTextureSize);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &pState->caps.maxTextureAnisotropy);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED(glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pState->caps.flPointSize));
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED(pState->ext.glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB,
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED(pState->ext.glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB,
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED(pState->ext.glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB,
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync VMSVGA3D_INIT_CHECKED(pState->ext.glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB,
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync pState->caps.fS3TCSupported = vmsvga3dCheckGLExtension(pState->fGLVersion, 0.0, "GL_EXT_texture_compression_s3tc");
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* http://http://www.opengl.org/wiki/Detecting_the_Shader_Model
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync * ARB Assembly Language
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * These are done through testing the presence of extensions. You should test them in this order:
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync * GL_NV_gpu_program4: SM 4.0 or better.
31771163041e3661403a806eb3382d2a165c003bvboxsync * GL_NV_vertex_program3: SM 3.0 or better.
31771163041e3661403a806eb3382d2a165c003bvboxsync * GL_ARB_fragment_program: SM 2.0 or better.
31771163041e3661403a806eb3382d2a165c003bvboxsync * ATI does not support higher than SM 2.0 functionality in assembly shaders.
31771163041e3661403a806eb3382d2a165c003bvboxsync /** @todo: distinguish between vertex and pixel shaders??? */
31771163041e3661403a806eb3382d2a165c003bvboxsync if (vmsvga3dCheckGLExtension(pState->fGLVersion, 0.0, "GL_NV_gpu_program4"))
31771163041e3661403a806eb3382d2a165c003bvboxsync pState->caps.vertexShaderVersion = SVGA3DVSVERSION_40;
31771163041e3661403a806eb3382d2a165c003bvboxsync pState->caps.fragmentShaderVersion = SVGA3DPSVERSION_40;
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync if ( vmsvga3dCheckGLExtension(pState->fGLVersion, 0.0, "GL_NV_vertex_program3")
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync#if 0 /** @todo this is contrary to the ATI <= SM2.0. */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync || vmsvga3dCheckGLExtension(pState->fGLVersion, 0.0, "GL_ARB_shader_texture_lod") /* Wine claims this suggests SM 3.0 support */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync pState->caps.vertexShaderVersion = SVGA3DVSVERSION_30;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pState->caps.fragmentShaderVersion = SVGA3DPSVERSION_30;
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync if (vmsvga3dCheckGLExtension(pState->fGLVersion, 0.0, "GL_ARB_fragment_program"))
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync pState->caps.vertexShaderVersion = SVGA3DVSVERSION_20;
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync pState->caps.fragmentShaderVersion = SVGA3DPSVERSION_20;
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync LogRel(("VMSVGA3D: WARNING: unknown support for assembly shaders!!\n"));
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync pState->caps.vertexShaderVersion = SVGA3DVSVERSION_11;
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync pState->caps.fragmentShaderVersion = SVGA3DPSVERSION_11;
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync if (!vmsvga3dCheckGLExtension(pState->fGLVersion, 3.2, "GL_ARB_vertex_array_bgra"))
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync /** @todo Intel drivers don't support this extension! */
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync LogRel(("VMSVGA3D: WARNING: Missing required extension GL_ARB_vertex_array_bgra (d3dcolor)!!!\n"));
d90eec53c9dcaa0f3d1054e8734ed46875b9093avboxsync SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS = 28,
bbb4c0bfd5ea55e99591d8811771257a437053eevboxsync LogRel(("VMSVGA3d: maxActiveLights=%d maxTextureBufferSize=%d maxTextures=%d\n",
bbb4c0bfd5ea55e99591d8811771257a437053eevboxsync pState->caps.maxActiveLights, pState->caps.maxTextureBufferSize, pState->caps.maxTextures));
bbb4c0bfd5ea55e99591d8811771257a437053eevboxsync LogRel(("VMSVGA3d: maxClipDistances=%d maxColorAttachments=%d maxClipDistances=%d\n",
bbb4c0bfd5ea55e99591d8811771257a437053eevboxsync pState->caps.maxClipDistances, pState->caps.maxColorAttachments, pState->caps.maxClipDistances));
bbb4c0bfd5ea55e99591d8811771257a437053eevboxsync LogRel(("VMSVGA3d: maxColorAttachments=%d maxRectangleTextureSize=%d maxTextureAnisotropy=%d\n",
bbb4c0bfd5ea55e99591d8811771257a437053eevboxsync pState->caps.maxColorAttachments, pState->caps.maxRectangleTextureSize, pState->caps.maxTextureAnisotropy));
bbb4c0bfd5ea55e99591d8811771257a437053eevboxsync LogRel(("VMSVGA3d: maxVertexShaderInstructions=%d maxFragmentShaderInstructions=%d maxVertexShaderTemps=%d\n",
bbb4c0bfd5ea55e99591d8811771257a437053eevboxsync pState->caps.maxVertexShaderInstructions, pState->caps.maxFragmentShaderInstructions, pState->caps.maxVertexShaderTemps));
bbb4c0bfd5ea55e99591d8811771257a437053eevboxsync LogRel(("VMSVGA3d: maxFragmentShaderTemps=%d flPointSize={%d.%02u, %d.%02u}\n",
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync (int)pState->caps.flPointSize[0], (int)(pState->caps.flPointSize[0] * 100) % 100,
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync (int)pState->caps.flPointSize[1], (int)(pState->caps.flPointSize[1] * 100) % 100));
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync LogRel(("VMSVGA3d: fragmentShaderVersion=%d vertexShaderVersion=%d fS3TCSupported=%d\n",
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync pState->caps.fragmentShaderVersion, pState->caps.vertexShaderVersion, pState->caps.fS3TCSupported));
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* Initialize the shader library. */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* Cleanup */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* on the Mac, OpenGL 3 came very late so we have a capable 2.1 implementation */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync LogRel(("VMSVGA3d: unsupported OpenGL version; minimum is 3.0\n"));
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync || !pState->ext.glGetFramebufferAttachmentParameteriv
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync LogRel(("VMSVGA3d: missing required OpenGL extension; aborting\n"));
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* Destroy all leftover surfaces. */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync vmsvga3dSurfaceDestroy(pThis, pState->paSurface[i].id);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* Destroy all leftover contexts. */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync vmsvga3dContextDestroy(pThis, pState->paContext[i].id);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* Terminate the shader library. */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /* Terminate the window creation thread. */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_EXIT, 0, 0);
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* signal to the thread that it is supposed to exit */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* wait for it to terminate */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync rc = RTThreadWait(pState->pWindowThread, 10000, NULL);
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync/* Shared functions that depend on private structure definitions. */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsyncstatic uint32_t vmsvga3dGetSurfaceFormatSupport(PVMSVGA3DSTATE pState3D, uint32_t idx3dCaps)
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* @todo missing:
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * SVGA3DFORMAT_OP_PIXELSIZE
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync | SVGA3DFORMAT_OP_DISPLAYMODE /* Should not be set for alpha formats. */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync | SVGA3DFORMAT_OP_3DACCELERATION; /* implies OP_DISPLAYMODE */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync | SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET;
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* @todo check hardware caps! */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync | SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync | SVGA3DFORMAT_OP_TEXTURE /* Necessary for Ubuntu Unity */;
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync Log(("CAPS: %s =\n%s\n", vmsvga3dGetCapString(idx3dCaps), vmsvga3dGet3dFormatString(result)));
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsyncstatic uint32_t vmsvga3dGetDepthFormatSupport(PVMSVGA3DSTATE pState3D, uint32_t idx3dCaps)
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* @todo test this somehow */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync result = SVGA3DFORMAT_OP_ZSTENCIL | SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH;
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync Log(("CAPS: %s =\n%s\n", vmsvga3dGetCapString(idx3dCaps), vmsvga3dGet3dFormatString(result)));
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsyncint vmsvga3dQueryCaps(PVGASTATE pThis, uint32_t idx3dCaps, uint32_t *pu32Val)
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* boolean? */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync *pu32Val = (pState->caps.vertexShaderVersion != SVGA3DVSVERSION_NONE);
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* boolean? */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync *pu32Val = (pState->caps.fragmentShaderVersion != SVGA3DPSVERSION_NONE);
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* Must be obsolete by now; surface format caps specify the same thing. */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * 2. The BUFFER_FORMAT capabilities are deprecated, and they always
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * return TRUE. Even on physical hardware that does not support
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * these formats natively, the SVGA3D device will provide an emulation
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * which should be invisible to the guest OS.
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* @todo ?? */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync //*pu32Val = pCaps->MaxVolumeExtent;
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync //*pu32Val = pCaps->MaxTextureAspectRatio;
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync *pu32Val = pState->caps.maxVertexShaderInstructions;
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync case SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS:
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync *pu32Val = pState->caps.maxFragmentShaderInstructions;
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync //*pu32Val = !!(pCaps->Caps2 & D3DCAPS2_CANAUTOGENMIPMAP);
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync case SVGA3D_DEVCAP_MAX_RENDER_TARGETS: /* @todo same thing? */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync case SVGA3D_DEVCAP_MAX_SIMULTANEOUS_RENDER_TARGETS:
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * This is the maximum number of SVGA context IDs that the guest
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * can define using SVGA_3D_CMD_CONTEXT_DEFINE.
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * This is the maximum number of SVGA surface IDs that the guest
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * can define using SVGA_3D_CMD_SURFACE_DEFINE*.
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* Supported surface formats. */
45c3e41d012100c5f4a3f77e391e4c6da8f5b97avboxsync *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps);
feffb6492a600891a421e4c1bf0a2bcd2213568dvboxsync *pu32Val = 0; /* apparently not supported in OpenGL */
feffb6492a600891a421e4c1bf0a2bcd2213568dvboxsync *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps);
feffb6492a600891a421e4c1bf0a2bcd2213568dvboxsync Log(("CAPS: Unknown CAP %s\n", vmsvga3dGetCapString(idx3dCaps)));
feffb6492a600891a421e4c1bf0a2bcd2213568dvboxsync Log(("CAPS: %s - %x\n", vmsvga3dGetCapString(idx3dCaps), *pu32Val));
4dcf37df51439573b55cc16f53590c7b68cb1051vboxsync * Convert SVGA format value to its OpenGL equivalent
feffb6492a600891a421e4c1bf0a2bcd2213568dvboxsyncstatic void vmsvga3dSurfaceFormat2OGL(PVMSVGA3DSURFACE pSurface, SVGA3dSurfaceFormat format)
case SVGA3D_Z_D15S1:
case SVGA3D_Z_D24X8:
case SVGA3D_Z_DF16:
case SVGA3D_Z_DF24:
case SVGA3D_Z_D24S8_INT:
case SVGA3D_DXT1:
case SVGA3D_DXT3:
case SVGA3D_DXT5:
case SVGA3D_LUMINANCE8:
case SVGA3D_LUMINANCE16:
case SVGA3D_LUMINANCE4_ALPHA4:
case SVGA3D_LUMINANCE8_ALPHA8:
pSurface->typeGL = GL_UNSIGNED_BYTE; /* unsigned_short causes issues even though this type should be 16-bit */
case SVGA3D_ALPHA8:
case SVGA3D_BUMPU8V8:
return D3DFMT_V8U8;
case SVGA3D_BUMPL6V5U5:
return D3DFMT_L6V5U5;
case SVGA3D_BUMPX8L8V8U8:
return D3DFMT_X8L8V8U8;
case SVGA3D_BUMPL8V8U8:
case SVGA3D_V8U8:
return D3DFMT_V8U8;
case SVGA3D_Q8W8V8U8:
return D3DFMT_Q8W8V8U8;
case SVGA3D_CxV8U8:
return D3DFMT_CxV8U8;
case SVGA3D_X8L8V8U8:
return D3DFMT_X8L8V8U8;
case SVGA3D_A2W10V10U10:
return D3DFMT_A2W10V10U10;
case SVGA3D_A2R10G10B10:
case SVGA3D_R_S10E5:
case SVGA3D_R_S23E8:
case SVGA3D_RG_S10E5:
case SVGA3D_RG_S23E8:
case SVGA3D_BUFFER:
return D3DFMT_UNKNOWN;
case SVGA3D_V16U16:
return D3DFMT_V16U16;
case SVGA3D_G16R16:
case SVGA3D_A16B16G16R16:
case SVGA3D_UYVY:
return D3DFMT_UYVY;
case SVGA3D_YUY2:
return D3DFMT_YUY2;
case SVGA3D_NV12:
case SVGA3D_AYUV:
case SVGA3D_BC4_UNORM:
case SVGA3D_BC5_UNORM:
return D3DMULTISAMPLE_NONE;
int vmsvga3dSurfaceDefine(PVGASTATE pThis, uint32_t sid, uint32_t surfaceFlags, SVGA3dSurfaceFormat format, SVGA3dSurfaceFace face[SVGA3D_MAX_SURFACE_FACES],
uint32_t multisampleCount, SVGA3dTextureFilter autogenFilter, uint32_t cMipLevels, SVGA3dSize *pMipLevelSize)
Log(("vmsvga3dSurfaceDefine: sid=%x surfaceFlags=%x format=%s (%x) multiSampleCount=%d autogenFilter=%d, cMipLevels=%d size=(%d,%d,%d)\n",
sid, surfaceFlags, vmsvgaSurfaceType2String(format), format, multisampleCount, autogenFilter, cMipLevels, pMipLevelSize->width, pMipLevelSize->height, pMipLevelSize->depth));
AssertReturn(!(surfaceFlags & SVGA3D_SURFACE_CUBEMAP) || cMipLevels == face[0].numMipLevels * 6, VERR_INVALID_PARAMETER);
AssertReturn((surfaceFlags & SVGA3D_SURFACE_CUBEMAP) || cMipLevels == face[0].numMipLevels, VERR_INVALID_PARAMETER);
pState->paSurface = (PVMSVGA3DSURFACE )RTMemRealloc(pState->paSurface, sizeof(VMSVGA3DSURFACE) * (sid + 1));
memset(&pState->paSurface[pState->cSurfaces], 0, sizeof(VMSVGA3DSURFACE) * (sid + 1 - pState->cSurfaces));
/* The surface type is sort of undefined now, even though the hints and format can help to clear that up.
switch (format)
case SVGA3D_Z_D32:
case SVGA3D_Z_D16:
case SVGA3D_Z_D24S8:
case SVGA3D_Z_D15S1:
case SVGA3D_Z_D24X8:
case SVGA3D_Z_DF16:
case SVGA3D_Z_DF24:
case SVGA3D_Z_D24S8_INT:
case SVGA3D_DXT1:
case SVGA3D_DXT2:
case SVGA3D_DXT3:
case SVGA3D_DXT4:
case SVGA3D_DXT5:
case SVGA3D_BUMPU8V8:
case SVGA3D_BUMPL6V5U5:
case SVGA3D_BUMPX8L8V8U8:
case SVGA3D_BUMPL8V8U8:
case SVGA3D_V8U8:
case SVGA3D_Q8W8V8U8:
case SVGA3D_CxV8U8:
case SVGA3D_X8L8V8U8:
case SVGA3D_A2W10V10U10:
case SVGA3D_V16U16:
case SVGA3D_X8R8G8B8:
case SVGA3D_A8R8G8B8:
case SVGA3D_R5G6B5:
case SVGA3D_X1R5G5B5:
case SVGA3D_A1R5G5B5:
case SVGA3D_A4R4G4B4:
case SVGA3D_LUMINANCE8:
case SVGA3D_LUMINANCE4_ALPHA4:
case SVGA3D_LUMINANCE16:
case SVGA3D_LUMINANCE8_ALPHA8:
case SVGA3D_A2R10G10B10:
case SVGA3D_ALPHA8:
case SVGA3D_R_S10E5:
case SVGA3D_R_S23E8:
case SVGA3D_RG_S10E5:
case SVGA3D_RG_S23E8:
case SVGA3D_G16R16:
case SVGA3D_A16B16G16R16:
case SVGA3D_UYVY:
case SVGA3D_YUY2:
case SVGA3D_NV12:
case SVGA3D_AYUV:
case SVGA3D_BC4_UNORM:
case SVGA3D_BC5_UNORM:
case SVGA3D_BUFFER:
pSurface->pMipmapLevels = (PVMSVGA3DMIPMAPLEVEL)RTMemAllocZ(cMipLevels * sizeof(VMSVGA3DMIPMAPLEVEL));
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))
case SVGA3D_SURFACE_CUBEMAP:
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));
Log(("vmsvga3dSurfaceDefine: cbPitch=%x cbBlock=%x \n", pSurface->cbBlock * pSurface->pMipmapLevels[idx].size.width, pSurface->cbBlock));
pSurface->pMipmapLevels[idx].cbSurfacePitch = pSurface->cbBlock * pSurface->pMipmapLevels[idx].size.width;
pSurface->pMipmapLevels[idx].cbSurface = pSurface->pMipmapLevels[idx].cbSurfacePitch * pSurface->pMipmapLevels[idx].size.height * pSurface->pMipmapLevels[idx].size.depth;
return VINF_SUCCESS;
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))
case SVGA3D_SURFACE_CUBEMAP:
case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE: /* @todo actual texture surface not supported */
return VINF_SUCCESS;
int vmsvga3dSurfaceCopy(PVGASTATE pThis, SVGA3dSurfaceImageId dest, SVGA3dSurfaceImageId src, uint32_t cCopyBoxes, SVGA3dCopyBox *pBox)
AssertReturn(sidSrc < pState->cSurfaces && pState->paSurface[sidSrc].id == sidSrc, VERR_INVALID_PARAMETER);
AssertReturn(sidDest < pState->cSurfaces && pState->paSurface[sidDest].id == sidDest, VERR_INVALID_PARAMETER);
return VINF_SUCCESS;
static int vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface)
Log(("vmsvga3dCreateTexture: sync dirty texture mipmap level %d (pitch %x)\n", i, pSurface->pMipmapLevels[i].cbSurfacePitch));
NULL);
return VINF_SUCCESS;
int vmsvga3dSurfaceStretchBlt(PVGASTATE pThis, SVGA3dSurfaceImageId dest, SVGA3dBox destBox, SVGA3dSurfaceImageId src, SVGA3dBox srcBox, SVGA3dStretchBltMode mode)
AssertReturn(sidSrc < pState->cSurfaces && pState->paSurface[sidSrc].id == sidSrc, VERR_INVALID_PARAMETER);
AssertReturn(sidDest < pState->cSurfaces && pState->paSurface[sidDest].id == sidDest, VERR_INVALID_PARAMETER);
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));
Log(("vmsvga3dSurfaceStretchBlt: unknown src surface id=%x type=%d format=%d -> create texture\n", sidSrc, pSurfaceSrc->flags, pSurfaceSrc->format));
Log(("vmsvga3dSurfaceStretchBlt: unknown dest surface id=%x type=%d format=%d -> create texture\n", sidDest, pSurfaceDest->flags, pSurfaceDest->format));
pState->ext.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pSurfaceSrc->oglId.texture, src.mipmap);
pState->ext.glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pSurfaceDest->oglId.texture, dest.mipmap);
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),
srcBox.x + srcBox.w, D3D_TO_OGL_Y_COORD(pSurfaceSrc, srcBox.y), destBox.x, D3D_TO_OGL_Y_COORD(pSurfaceDest, destBox.y + destBox.h),
#ifdef MANUAL_FLIP_SURFACE_DATA
srcBox.y,
#ifdef MANUAL_FLIP_SURFACE_DATA
destBox.x,
#ifdef MANUAL_FLIP_SURFACE_DATA
destBox.y,
#ifdef MANUAL_FLIP_SURFACE_DATA
return VINF_SUCCESS;
int vmsvga3dSurfaceDMA(PVGASTATE pThis, SVGA3dGuestImage guest, SVGA3dSurfaceImageId host, SVGA3dTransferType transfer, uint32_t cCopyBoxes, SVGA3dCopyBox *pBoxes)
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));
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));
for (unsigned i = 0; i < cCopyBoxes; i++)
unsigned uDestOffset;
unsigned cbSrcPitch;
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));
if ( !pBoxes[i].w
|| !pBoxes[i].h
|| !pBoxes[i].d
uDestOffset = pBoxes[i].x * pSurface->cbBlock + pBoxes[i].y * pMipLevel->cbSurfacePitch + pBoxes[i].z * pMipLevel->size.height * pMipLevel->cbSurfacePitch;
AssertReturn(uDestOffset + pBoxes[i].w * pSurface->cbBlock * pBoxes[i].h * pBoxes[i].d <= pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
#ifdef MANUAL_FLIP_SURFACE_DATA
#ifdef MANUAL_FLIP_SURFACE_DATA
Log(("vmsvga3dSurfaceDMA invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->paContext[cid].id));
for (unsigned i = 0; i < cCopyBoxes; i++)
bool fVertex = false;
unsigned cbSrcPitch;
if ( !pBoxes[i].w
|| !pBoxes[i].h
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));
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))
unsigned uDestOffset = 0;
AssertReturn(uDestOffset + pBoxes[i].w * pSurface->cbBlock + (pBoxes[i].h - 1) * pMipLevel->cbSurfacePitch <= pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
#ifdef MANUAL_FLIP_SURFACE_DATA
#ifdef MANUAL_FLIP_SURFACE_DATA
pBufferStart = pDoubleBuffer + cbSurfacePitch * pBoxes[i].h - cbSurfacePitch; /* flip image during copy */
#ifdef MANUAL_FLIP_SURFACE_DATA
pBoxes[i].h);
Log(("vmsvga3dSurfaceDMA: copy texture mipmap level %d (pitch %x)\n", host.mipmap, pMipLevel->cbSurfacePitch));
pBoxes[i].x,
pBoxes[i].y,
pBoxes[i].w,
pBoxes[i].h,
unsigned uDestOffset;
pData = (uint8_t *)pState->ext.glMapBuffer(GL_ARRAY_BUFFER, (transfer == SVGA3D_READ_HOST_VRAM) ? GL_READ_ONLY : GL_WRITE_ONLY);
AssertReturn(uDestOffset + pBoxes[i].w * pSurface->cbBlock + (pBoxes[i].h - 1) * pMipLevel->cbSurfacePitch <= pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
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));
pBoxes[i].h);
AssertFailed();
return rc;
int vmsvga3dSurfaceBlitToScreen(PVGASTATE pThis, uint32_t dest, SVGASignedRect destRect, SVGA3dSurfaceImageId src, SVGASignedRect srcRect, uint32_t cRects, SVGASignedRect *pRect)
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));
Log(("vmsvga3dSurfaceBlitToScreen: clipping rect %d (%d,%d)(%d,%d)\n", i, pRect[i].left, pRect[i].top, pRect[i].right, pRect[i].bottom));
AssertReturn(destRect.right - destRect.left == srcRect.right - srcRect.left && destRect.bottom - destRect.top == srcRect.bottom - srcRect.top, VERR_INVALID_PARAMETER);
if (cRects == 0)
box.z = 0;
return VINF_SUCCESS;
box.z = 0;
box.z = 0;
return VINF_SUCCESS;
return VERR_INVALID_PARAMETER;
Log(("vmsvga3dGenerateMipmaps: unknown src surface id=%x type=%d format=%d -> create texture\n", sid, pSurface->flags, pSurface->format));
AssertFailed();
return VINF_SUCCESS;
uint32_t x;
uint32_t y;
} srcViewPort;
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));
return VERR_INVALID_PARAMETER;
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)));
if (cRects == 0)
glPushMatrix();
glPushMatrix();
vertexTop = ((uint32_t)pThis->svga.uHeight >= pRect[i].y + pRect[i].h) ? pThis->svga.uHeight - pRect[i].y - pRect[i].h : 0;
Log(("vertex (%d,%d) (%d,%d) (%d,%d) (%d,%d)\n", vertexLeft, vertexBottom, vertexLeft, vertexTop, vertexRight, vertexTop, vertexRight, vertexBottom));
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)));
glEnd();
glPopMatrix();
glPopMatrix();
pState->ext.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pSurface->oglId.texture, 0 /* level 0 */);
if (cRects == 0)
srcViewPort.y,
pSurface->pMipmapLevels[0].size.width - RT_MAX(pRect[i].srcy, srcViewPort.y), /* exclusive. (reverse to flip the image) */
pSurface->pMipmapLevels[0].size.width - RT_MIN(pRect[i].srcy + pRect[i].h, srcViewPort.y + srcViewPort.cy),
pThis->svga.uHeight - (RT_MIN(pRect[i].y + pRect[i].h, pThis->svga.viewport.y + pThis->svga.viewport.cy) - pThis->svga.viewport.y), /* exclusive. */
RT_MIN(pRect[i].x + pRect[i].w, pThis->svga.viewport.x + pThis->svga.viewport.cx) - pThis->svga.viewport.x, /* exclusive. */
#ifdef RT_OS_WINDOWS
return VINF_SUCCESS;
#ifdef RT_OS_LINUX
return VINF_SUCCESS;
int rc;
pState->paContext = (PVMSVGA3DCONTEXT)RTMemRealloc(pState->paContext, sizeof(VMSVGA3DCONTEXT) * (cid + 1));
memset(&pState->paContext[pState->cContexts], 0, sizeof(VMSVGA3DCONTEXT) * (cid + 1 - pState->cContexts));
#ifdef RT_OS_WINDOWS
# ifdef DEBUG_GFX_WINDOW
# ifdef DEBUG_GFX_WINDOW
cs.x = 0;
cs.y = 0;
rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_CREATEWINDOW, (WPARAM)&pContext->hwnd, (LPARAM)&cs);
AssertMsgReturn(pContext->hdc, ("GetDC %x failed with %d\n", pContext->hwnd, GetLastError()), VERR_INTERNAL_ERROR);
int pixelFormat;
AssertMsgReturn(pixelFormat != 0, ("ChoosePixelFormat failed with %d\n", GetLastError()), VERR_INTERNAL_ERROR);
AssertMsgReturn(ret == TRUE, ("SetPixelFormat failed with %d\n", GetLastError()), VERR_INTERNAL_ERROR);
AssertMsgReturn(pContext->hglrc, ("wglCreateContext %x failed with %d\n", pContext->hdc, GetLastError()), VERR_INTERNAL_ERROR);
/* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
/* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
AssertMsgReturn(ret && glxMajor == 1 && glxMinor >= 3, ("glX >=1.3 not present"), VERR_INTERNAL_ERROR);
rc = RTThreadCreate(&pState->pWindowThread, vmsvga3dXEventThread, pState, 0, RTTHREADTYPE_GUI, RTTHREADFLAGS_WAITABLE, "VMSVGA3DXEVENT");
AssertMsgFailed(("%s: Async IO Thread creation for 3d window handling failed rc=%d\n", __FUNCTION__, rc));
return rc;
int attrib[] =
swa.colormap = XCreateColormap(pState->display, XDefaultRootWindow(pState->display), vi->visual, AllocNone);
pContext->window = XCreateWindow(pState->display, hostWindow,//XDefaultRootWindow(pState->display),//hostWindow,
/* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
glClearIndex(0);
return VINF_SUCCESS;
vmsvga3dShaderDestroy(pThis, pContext->paPixelShader[i].cid, pContext->paPixelShader[i].id, pContext->paPixelShader[i].type);
vmsvga3dShaderDestroy(pThis, pContext->paVertexShader[i].cid, pContext->paVertexShader[i].id, pContext->paVertexShader[i].type);
#ifdef RT_OS_WINDOWS
int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_DESTROYWINDOW, (WPARAM)pContext->hwnd, 0);
AssertFailed();
return VINF_SUCCESS;
#ifdef RT_OS_WINDOWS
int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_RESIZEWINDOW, (WPARAM)pContext->hwnd, (LPARAM)&cs);
return VINF_SUCCESS;
bool fModelViewChanged = false;
return VERR_INVALID_PARAMETER;
memcpy(pContext->state.aTransformState[type].matrix, matrix, sizeof(pContext->state.aTransformState[type].matrix));
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)));
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)));
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)));
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)));
switch (type)
case SVGA3D_TRANSFORM_VIEW:
fModelViewChanged = true;
int rc = ShaderTransformProjection(pContext->state.RectViewPort.w, pContext->state.RectViewPort.h, matrix);
return VERR_INVALID_PARAMETER;
case SVGA3D_TRANSFORM_WORLD:
fModelViewChanged = true;
case SVGA3D_TRANSFORM_WORLD1:
case SVGA3D_TRANSFORM_WORLD2:
case SVGA3D_TRANSFORM_WORLD3:
return VERR_INVALID_PARAMETER;
return VERR_INVALID_PARAMETER;
if (fModelViewChanged)
return VINF_SUCCESS;
Log(("vmsvga3dSetZRange cid=%x min=%d max=%d\n", cid, (uint32_t)(zRange.min * 100.0), (uint32_t)(zRange.max * 100.0)));
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
switch (blendOp)
case SVGA3D_BLENDOP_ZERO:
return GL_ZERO;
case SVGA3D_BLENDOP_ONE:
return GL_ONE;
case SVGA3D_BLENDOP_SRCCOLOR:
return GL_SRC_COLOR;
return GL_ONE_MINUS_SRC_COLOR;
case SVGA3D_BLENDOP_SRCALPHA:
return GL_SRC_ALPHA;
return GL_ONE_MINUS_SRC_ALPHA;
case SVGA3D_BLENDOP_DESTALPHA:
return GL_DST_ALPHA;
return GL_ONE_MINUS_DST_ALPHA;
case SVGA3D_BLENDOP_DESTCOLOR:
return GL_DST_COLOR;
return GL_ONE_MINUS_DST_COLOR;
return GL_SRC_ALPHA_SATURATE;
AssertFailed();
return GL_ONE;
switch (blendEq)
case SVGA3D_BLENDEQ_ADD:
return GL_FUNC_ADD;
case SVGA3D_BLENDEQ_SUBTRACT:
return GL_FUNC_SUBTRACT;
return GL_FUNC_REVERSE_SUBTRACT;
case SVGA3D_BLENDEQ_MINIMUM:
return GL_MIN;
case SVGA3D_BLENDEQ_MAXIMUM:
return GL_MAX;
AssertFailed();
return GL_FUNC_ADD;
switch (cmpFunc)
case SVGA3D_CMP_NEVER:
return GL_NEVER;
case SVGA3D_CMP_LESS:
return GL_LESS;
case SVGA3D_CMP_EQUAL:
return GL_EQUAL;
case SVGA3D_CMP_LESSEQUAL:
return GL_LEQUAL;
case SVGA3D_CMP_GREATER:
return GL_GREATER;
case SVGA3D_CMP_NOTEQUAL:
return GL_NOTEQUAL;
case SVGA3D_CMP_GREATEREQUAL:
return GL_GEQUAL;
case SVGA3D_CMP_ALWAYS:
return GL_ALWAYS;
AssertFailed();
return GL_LESS;
switch (stencilOp)
case SVGA3D_STENCILOP_KEEP:
return GL_KEEP;
case SVGA3D_STENCILOP_ZERO:
return GL_ZERO;
case SVGA3D_STENCILOP_REPLACE:
return GL_REPLACE;
case SVGA3D_STENCILOP_INCRSAT:
return GL_INCR_WRAP;
case SVGA3D_STENCILOP_DECRSAT:
return GL_DECR_WRAP;
case SVGA3D_STENCILOP_INVERT:
return GL_INVERT;
case SVGA3D_STENCILOP_INCR:
return GL_INCR;
case SVGA3D_STENCILOP_DECR:
return GL_DECR;
AssertFailed();
return GL_KEEP;
int vmsvga3dSetRenderState(PVGASTATE pThis, uint32_t cid, uint32_t cRenderStates, SVGA3dRenderState *pRenderState)
return VERR_INVALID_PARAMETER;
for (unsigned i = 0; i < cRenderStates; i++)
Log(("vmsvga3dSetRenderState: cid=%d state=%s (%d) val=%x\n", cid, vmsvga3dGetRenderStateName(pRenderState[i].state), pRenderState[i].state, pRenderState[i].uintValue));
case SVGA3D_FOGFUNC_EXP:
case SVGA3D_FOGFUNC_EXP2:
case SVGA3D_FOGFUNC_LINEAR:
case SVGA3D_FOGTYPE_VERTEX:
case SVGA3D_FOGTYPE_PIXEL:
case SVGA3D_FILLMODE_POINT:
case SVGA3D_FILLMODE_LINE:
case SVGA3D_FILLMODE_FILL:
case SVGA3D_SHADEMODE_FLAT:
case SVGA3D_SHADEMODE_SMOOTH:
AssertMsgFailedReturn(("Unexpected shade mode %d\n", pRenderState[i].uintValue), VERR_INTERNAL_ERROR);
case SVGA3D_RS_SRCBLEND:
case SVGA3D_RS_DSTBLEND:
case SVGA3D_RS_SRCBLENDALPHA:
case SVGA3D_RS_DSTBLENDALPHA:
AssertFailed();
pState->ext.glBlendEquationSeparate(vmsvga3dBlendEquation2GL(pContext->state.aRenderState[SVGA3D_RS_BLENDEQUATION].uintValue),
case SVGA3D_FACE_NONE:
case SVGA3D_FACE_FRONT:
case SVGA3D_FACE_BACK:
case SVGA3D_FACE_FRONT_BACK:
AssertMsgFailedReturn(("Unexpected cull mode %d\n", pRenderState[i].uintValue), VERR_INTERNAL_ERROR);
val = 0;
AssertFailed();
AssertFailed();
/* @todo SVGA3D_RS_STENCILFAIL/ZFAIL/PASS for front & back faces
* SVGA3D_RS_CCWSTENCILFAIL/ZFAIL/PASS for back faces ??
/* @todo SVGA3D_RS_STENCILFAIL/ZFAIL/PASS for front & back faces
* SVGA3D_RS_CCWSTENCILFAIL/ZFAIL/PASS for back faces ??
AssertFailed();
/* @todo setup a view matrix to scale the world space by -1 in the z-direction for right handed coordinates. */
AssertFailed();
AssertFailed();
AssertFailed();
if (enableCap != ~0U)
if (val)
return VINF_SUCCESS;
int vmsvga3dSetRenderTarget(PVGASTATE pThis, uint32_t cid, SVGA3dRenderTargetType type, SVGA3dSurfaceImageId target)
return VERR_INVALID_PARAMETER;
switch (type)
case SVGA3D_RT_DEPTH:
case SVGA3D_RT_STENCIL:
pState->ext.glFramebufferRenderbuffer(GL_FRAMEBUFFER, (type == SVGA3D_RT_DEPTH) ? GL_DEPTH_ATTACHMENT : GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
case SVGA3D_RT_COLOR0:
case SVGA3D_RT_COLOR1:
case SVGA3D_RT_COLOR2:
case SVGA3D_RT_COLOR3:
case SVGA3D_RT_COLOR4:
case SVGA3D_RT_COLOR5:
case SVGA3D_RT_COLOR6:
case SVGA3D_RT_COLOR7:
pState->ext.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + type - SVGA3D_RT_COLOR0, 0, 0, 0);
return VINF_SUCCESS;
AssertReturn(target.sid < pState->cSurfaces && pState->paSurface[target.sid].id == target.sid, VERR_INVALID_PARAMETER);
switch (type)
case SVGA3D_RT_DEPTH:
case SVGA3D_RT_STENCIL:
Log(("vmsvga3dSetRenderTarget: create renderbuffer to be used as render target; surface id=%x type=%d format=%d\n", target.sid, pRenderTarget->flags, pRenderTarget->internalFormatGL));
pState->ext.glFramebufferRenderbuffer(GL_FRAMEBUFFER, (type == SVGA3D_RT_DEPTH) ? GL_DEPTH_ATTACHMENT : GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, pRenderTarget->oglId.renderbuffer);
case SVGA3D_RT_COLOR0:
case SVGA3D_RT_COLOR1:
case SVGA3D_RT_COLOR2:
case SVGA3D_RT_COLOR3:
case SVGA3D_RT_COLOR4:
case SVGA3D_RT_COLOR5:
case SVGA3D_RT_COLOR6:
case SVGA3D_RT_COLOR7:
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));
pState->ext.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + type - SVGA3D_RT_COLOR0, GL_TEXTURE_2D, pRenderTarget->oglId.texture, target.mipmap);
#ifdef DEBUG
return VINF_SUCCESS;
switch (value)
case SVGA3D_TC_DISABLE:
return D3DTOP_DISABLE;
case SVGA3D_TC_SELECTARG1:
return D3DTOP_SELECTARG1;
case SVGA3D_TC_SELECTARG2:
return D3DTOP_SELECTARG2;
case SVGA3D_TC_MODULATE:
return D3DTOP_MODULATE;
case SVGA3D_TC_ADD:
return D3DTOP_ADD;
case SVGA3D_TC_ADDSIGNED:
return D3DTOP_ADDSIGNED;
case SVGA3D_TC_SUBTRACT:
return D3DTOP_SUBTRACT;
return D3DTOP_BLENDTEXTUREALPHA;
return D3DTOP_BLENDDIFFUSEALPHA;
return D3DTOP_BLENDCURRENTALPHA;
return D3DTOP_BLENDFACTORALPHA;
case SVGA3D_TC_MODULATE2X:
return D3DTOP_MODULATE2X;
case SVGA3D_TC_MODULATE4X:
return D3DTOP_MODULATE4X;
case SVGA3D_TC_DSDT:
return D3DTOP_DISABLE;
case SVGA3D_TC_DOTPRODUCT3:
return D3DTOP_DOTPRODUCT3;
return D3DTOP_BLENDTEXTUREALPHAPM;
case SVGA3D_TC_ADDSIGNED2X:
return D3DTOP_ADDSIGNED2X;
case SVGA3D_TC_ADDSMOOTH:
return D3DTOP_ADDSMOOTH;
case SVGA3D_TC_PREMODULATE:
return D3DTOP_PREMODULATE;
return D3DTOP_MODULATEALPHA_ADDCOLOR;
return D3DTOP_MODULATECOLOR_ADDALPHA;
return D3DTOP_MODULATEINVALPHA_ADDCOLOR;
return D3DTOP_MODULATEINVCOLOR_ADDALPHA;
return D3DTOP_BUMPENVMAPLUMINANCE;
case SVGA3D_TC_MULTIPLYADD:
return D3DTOP_MULTIPLYADD;
case SVGA3D_TC_LERP:
return D3DTOP_LERP;
AssertFailed();
return D3DTOP_DISABLE;
switch (value)
case SVGA3D_TA_CONSTANT:
return D3DTA_CONSTANT;
case SVGA3D_TA_PREVIOUS:
case SVGA3D_TA_DIFFUSE:
return D3DTA_DIFFUSE;
case SVGA3D_TA_TEXTURE:
return D3DTA_TEXTURE;
case SVGA3D_TA_SPECULAR:
return D3DTA_SPECULAR;
AssertFailed();
switch (value)
case SVGA3D_TEX_TRANSFORM_OFF:
return D3DTTFF_DISABLE;
case SVGA3D_TEX_TRANSFORM_S:
case SVGA3D_TEX_TRANSFORM_T:
case SVGA3D_TEX_TRANSFORM_R:
case SVGA3D_TEX_TRANSFORM_Q:
case SVGA3D_TEX_PROJECTED:
return D3DTTFF_PROJECTED;
AssertFailed();
switch (value)
case SVGA3D_TEX_ADDRESS_WRAP:
return GL_REPEAT;
return GL_MIRRORED_REPEAT;
case SVGA3D_TEX_ADDRESS_CLAMP:
return GL_CLAMP_TO_EDGE;
return GL_CLAMP_TO_BORDER;
AssertFailed();
case SVGA3D_TEX_ADDRESS_EDGE:
AssertFailed();
switch (value)
case SVGA3D_TEX_FILTER_NONE:
case SVGA3D_TEX_FILTER_LINEAR:
return GL_LINEAR;
return GL_NEAREST;
AssertFailed();
int vmsvga3dSetTextureState(PVGASTATE pThis, uint32_t cid, uint32_t cTextureStates, SVGA3dTextureState *pTextureState)
return VERR_INVALID_PARAMETER;
for (unsigned i = 0; i < cTextureStates; i++)
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));
Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture surface id=%x\n", pTextureState[i].stage, pTextureState[i].value));
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));
Log(("CreateTexture (%d,%d) level=%d\n", pSurface->pMipmapLevels[0].size.width, pSurface->pMipmapLevels[0].size.height, pSurface->faces[0].numMipLevels));
glTexParameterfv(GL_TEXTURE_2D /* @todo flexible type */, GL_TEXTURE_BORDER_COLOR, color); /* Identical; default 0.0 identical too */
glTexParameterf(GL_TEXTURE_2D /* @todo flexible type */, GL_TEXTURE_LOD_BIAS, pTextureState[i].value); /* Identical; default 0.0 identical too */
AssertFailed();
if (textureType != ~0U)
return VINF_SUCCESS;
return VERR_INVALID_PARAMETER;
switch (face)
case SVGA3D_FACE_NONE:
case SVGA3D_FACE_FRONT:
case SVGA3D_FACE_BACK:
case SVGA3D_FACE_FRONT_BACK:
return VINF_SUCCESS;
float QuadAttenuation;
return VERR_INVALID_PARAMETER;
AssertFailed();
glPushMatrix();
case SVGA3D_LIGHTTYPE_POINT:
glLightf(GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION, (QuadAttenuation < pData->attenuation2) ? pData->attenuation2 : QuadAttenuation);
case SVGA3D_LIGHTTYPE_SPOT1:
glLightf(GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION, (QuadAttenuation < pData->attenuation2) ? pData->attenuation2 : QuadAttenuation);
glLightfv(GL_LIGHT0 + index, GL_POSITION, position); /* Note gl uses w position of 0 for direction! */
case SVGA3D_LIGHTTYPE_SPOT2:
return VERR_INVALID_PARAMETER;
glPopMatrix();
return VINF_SUCCESS;
return VERR_INVALID_PARAMETER;
AssertFailed();
if (enabled)
return VINF_SUCCESS;
return VERR_INVALID_PARAMETER;
vmsvga3dSetTransform(pThis, cid, SVGA3D_TRANSFORM_PROJECTION, pContext->state.aTransformState[SVGA3D_TRANSFORM_PROJECTION].matrix);
return VINF_SUCCESS;
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)));
return VERR_INVALID_PARAMETER;
/* @todo clip plane affected by model view in OpenGL & view in D3D + vertex shader -> not transformed (see Wine; state.c clipplane) */
return VINF_SUCCESS;
Log(("vmsvga3dSetScissorRect cid=%x (%d,%d)(%d,%d)\n", cid, pRect->x, pRect->y, pRect->w, pRect->h));
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
static void vmsvgaColor2GLFloatArray(uint32_t color, GLfloat *pRed, GLfloat *pGreen, GLfloat *pBlue, GLfloat *pAlpha)
int vmsvga3dCommandClear(PVGASTATE pThis, uint32_t cid, SVGA3dClearFlag clearFlag, uint32_t color, float depth, uint32_t stencil, uint32_t cRects, SVGA3dRect *pRect)
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));
return VERR_INVALID_PARAMETER;
if (cRects)
for (unsigned i=0; i < cRects; i++)
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));
glPopAttrib();
return VINF_SUCCESS;
int vmsvga3dVertexDecl2OGL(SVGA3dVertexArrayIdentity &identity, GLint &size, GLenum &type, GLboolean &normalized)
case SVGA3D_DECLTYPE_FLOAT1:
case SVGA3D_DECLTYPE_FLOAT2:
case SVGA3D_DECLTYPE_FLOAT3:
case SVGA3D_DECLTYPE_FLOAT4:
case SVGA3D_DECLTYPE_D3DCOLOR:
case SVGA3D_DECLTYPE_UBYTE4N:
case SVGA3D_DECLTYPE_UBYTE4:
case SVGA3D_DECLTYPE_SHORT2N:
case SVGA3D_DECLTYPE_SHORT2:
case SVGA3D_DECLTYPE_SHORT4N:
case SVGA3D_DECLTYPE_SHORT4:
case SVGA3D_DECLTYPE_USHORT4N:
case SVGA3D_DECLTYPE_USHORT2N:
case SVGA3D_DECLTYPE_UDEC3:
case SVGA3D_DECLTYPE_DEC3N:
normalized = true;
return VINF_SUCCESS;
int vmsvga3dPrimitiveType2OGL(SVGA3dPrimitiveType PrimitiveType, GLenum *pMode, uint32_t cPrimitiveCount, uint32_t *pcVertices)
switch (PrimitiveType)
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
int vmsvga3dDrawPrimitivesProcessVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl)
AssertReturn(sidVertex < pState->cSurfaces && pState->paSurface[sidVertex].id == sidVertex, VERR_INVALID_PARAMETER);
Log(("vmsvga3dDrawPrimitives: create vertex buffer fDirty=%d size=%x bytes\n", pVertexSurface->fDirty, pVertexSurface->pMipmapLevels[0].cbSurface));
pState->ext.glBufferData(GL_ARRAY_BUFFER, pVertexSurface->pMipmapLevels[0].cbSurface, pVertexSurface->pMipmapLevels[0].pSurfaceData, GL_DYNAMIC_DRAW);
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));
pState->ext.glVertexAttribPointer(index, size, type, normalized, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
glVertexPointer(size, type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
AssertFailed();
AssertFailed();
case SVGA3D_DECLUSAGE_NORMAL:
glNormalPointer(type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
case SVGA3D_DECLUSAGE_PSIZE:
AssertFailed();
glTexCoordPointer(size, type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
case SVGA3D_DECLUSAGE_TANGENT:
AssertFailed();
AssertFailed();
AssertFailed();
glColorPointer(size, type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
case SVGA3D_DECLUSAGE_FOG:
pState->ext.glFogCoordPointer(type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
case SVGA3D_DECLUSAGE_DEPTH:
AssertFailed();
case SVGA3D_DECLUSAGE_SAMPLE:
AssertFailed();
#ifdef LOG_ENABLED
return VINF_SUCCESS;
int vmsvga3dDrawPrimitivesCleanupVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl)
case SVGA3D_DECLUSAGE_NORMAL:
case SVGA3D_DECLUSAGE_PSIZE:
case SVGA3D_DECLUSAGE_TANGENT:
case SVGA3D_DECLUSAGE_FOG:
case SVGA3D_DECLUSAGE_DEPTH:
case SVGA3D_DECLUSAGE_SAMPLE:
return VINF_SUCCESS;
int vmsvga3dDrawPrimitives(PVGASTATE pThis, uint32_t cid, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl, uint32_t numRanges, SVGA3dPrimitiveRange *pRange, uint32_t cVertexDivisor, SVGA3dVertexDivisor *pVertexDivisor)
Log(("vmsvga3dDrawPrimitives cid=%x numVertexDecls=%d numRanges=%d, cVertexDivisor=%d\n", cid, numVertexDecls, numRanges, cVertexDivisor));
return VERR_INVALID_PARAMETER;
iCurrentVertex = 0;
rc = vmsvga3dDrawPrimitivesProcessVertexDecls(pState, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);
unsigned cVertices;
Log(("Primitive %d: type %s\n", iPrimitive, vmsvga3dPrimitiveType2String(pRange[iPrimitive].primType)));
rc = vmsvga3dPrimitiveType2OGL(pRange[iPrimitive].primType, &modeDraw, pRange[iPrimitive].primitiveCount, &cVertices);
goto internal_error;
AssertMsg(pRange[iPrimitive].indexWidth == sizeof(uint32_t) || pRange[iPrimitive].indexWidth == sizeof(uint16_t), ("Unsupported primitive width %d\n", pRange[iPrimitive].indexWidth));
goto internal_error;
Log(("vmsvga3dDrawPrimitives: create index buffer fDirty=%d size=%x bytes\n", pIndexSurface->fDirty, pIndexSurface->pMipmapLevels[0].cbSurface));
pState->ext.glBufferData(GL_ELEMENT_ARRAY_BUFFER, pIndexSurface->pMipmapLevels[0].cbSurface, pIndexSurface->pMipmapLevels[0].pSurfaceData, GL_DYNAMIC_DRAW);
if (!pIndexSurface)
Log(("DrawPrimitive %x cPrimitives=%d cVertices=%d index index bias=%d\n", modeDraw, pRange[iPrimitive].primitiveCount, cVertices, pRange[iPrimitive].indexBias));
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));
iCurrentVertex = 0;
rc = vmsvga3dDrawPrimitivesCleanupVertexDecls(pState, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);
#ifdef DEBUG
AssertMsg(pTexture->oglId.texture == (GLuint)activeTexture, ("%x vs %x unit %d - %d\n", pTexture->oglId.texture, activeTexture, i, activeTextureUnit - GL_TEXTURE0));
#ifdef DEBUG_GFX_WINDOW
return rc;
int vmsvga3dShaderDefine(PVGASTATE pThis, uint32_t cid, uint32_t shid, SVGA3dShaderType type, uint32_t cbData, uint32_t *pShaderData)
int rc;
Log(("vmsvga3dShaderDefine cid=%x shid=%x type=%s cbData=%x\n", cid, shid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", cbData));
return VERR_INVALID_PARAMETER;
pContext->paVertexShader = (PVMSVGA3DSHADER)RTMemRealloc(pContext->paVertexShader, sizeof(VMSVGA3DSHADER) * (shid + 1));
memset(&pContext->paVertexShader[pContext->cVertexShaders], 0, sizeof(VMSVGA3DSHADER) * (shid + 1 - pContext->cVertexShaders));
pContext->paPixelShader = (PVMSVGA3DSHADER)RTMemRealloc(pContext->paPixelShader, sizeof(VMSVGA3DSHADER) * (shid + 1));
memset(&pContext->paPixelShader[pContext->cPixelShaders], 0, sizeof(VMSVGA3DSHADER) * (shid + 1 - pContext->cPixelShaders));
switch (type)
case SVGA3D_SHADERTYPE_VS:
rc = ShaderCreateVertexShader(pContext->pShaderContext, (const uint32_t *)pShaderData, &pShader->u.pVertexShader);
case SVGA3D_SHADERTYPE_PS:
rc = ShaderCreatePixelShader(pContext->pShaderContext, (const uint32_t *)pShaderData, &pShader->u.pPixelShader);
return rc;
int rc;
Log(("vmsvga3dShaderDestroy cid=%x shid=%x type=%s\n", cid, shid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL"));
return VERR_INVALID_PARAMETER;
if (pShader)
return VINF_SUCCESS;
int rc;
Log(("vmsvga3dShaderSet cid=%x type=%s shid=%d\n", cid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", shid));
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
int vmsvga3dShaderSetConst(PVGASTATE pThis, uint32_t cid, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype, uint32_t cRegisters, uint32_t *pValues)
int rc;
Log(("vmsvga3dShaderSetConst cid=%x reg=%x type=%s cregs=%d ctype=%x\n", cid, reg, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", cRegisters, ctype));
return VERR_INVALID_PARAMETER;
#ifdef LOG_ENABLED
switch (ctype)
case SVGA3D_CONST_TYPE_FLOAT:
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)));
case SVGA3D_CONST_TYPE_INT:
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]));
case SVGA3D_CONST_TYPE_BOOL:
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]));
vmsvga3dSaveShaderConst(pContext, reg + i, type, ctype, pValues[i*4 + 0], pValues[i*4 + 1], pValues[i*4 + 2], pValues[i*4 + 3]);
switch (type)
case SVGA3D_SHADERTYPE_VS:
switch (ctype)
case SVGA3D_CONST_TYPE_FLOAT:
rc = ShaderSetVertexShaderConstantF(pContext->pShaderContext, reg, (const float *)pValues, cRegisters);
case SVGA3D_CONST_TYPE_INT:
rc = ShaderSetVertexShaderConstantI(pContext->pShaderContext, reg, (const int32_t *)pValues, cRegisters);
case SVGA3D_CONST_TYPE_BOOL:
rc = ShaderSetVertexShaderConstantB(pContext->pShaderContext, reg, (const uint8_t *)pValues, cRegisters);
case SVGA3D_SHADERTYPE_PS:
switch (ctype)
case SVGA3D_CONST_TYPE_FLOAT:
rc = ShaderSetPixelShaderConstantF(pContext->pShaderContext, reg, (const float *)pValues, cRegisters);
case SVGA3D_CONST_TYPE_INT:
rc = ShaderSetPixelShaderConstantI(pContext->pShaderContext, reg, (const int32_t *)pValues, cRegisters);
case SVGA3D_CONST_TYPE_BOOL:
rc = ShaderSetPixelShaderConstantB(pContext->pShaderContext, reg, (const uint8_t *)pValues, cRegisters);
return VINF_SUCCESS;
AssertFailed();
return VERR_NOT_IMPLEMENTED;
AssertFailed();
return VERR_NOT_IMPLEMENTED;
int vmsvga3dQueryWait(PVGASTATE pThis, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
AssertFailed();
return VERR_NOT_IMPLEMENTED;