DevVGA-SVGA3d-ogl.cpp revision 8177818e385db2d90f58710d17aa5f66e074f2f6
/* $Id$ */
/** @file
* DevVMWare - VMWare SVGA device
*/
/*
* Copyright (C) 2013-2015 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/* Enable to disassemble defined shaders. (Windows host only) */
#if defined(RT_OS_WINDOWS) && defined(DEBUG) && 0 /* Disabled as we don't have the DirectX SDK avaible atm. */
# define DUMP_SHADER_DISASSEMBLY
#endif
#ifdef DEBUG_bird
# define RTMEM_WRAP_TO_EF_APIS
#endif
#define LOG_GROUP LOG_GROUP_DEV_VMSVGA
#include <iprt/semaphore.h>
#include <VBox/VBoxVideo.h>
#include <VBox/bioslogo.h>
/* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
#include "DevVGA.h"
#include "DevVGA-SVGA.h"
#include "DevVGA-SVGA3d.h"
#include "vmsvga/svga_reg.h"
#include "vmsvga/svga3d_reg.h"
#include "vmsvga/svga3d_shaderdefs.h"
#ifdef RT_OS_WINDOWS
# include "vmsvga_glext/wglext.h"
#elif defined(RT_OS_DARWIN)
# include "DevVGA-SVGA3d-cocoa.h"
/* work around conflicting definition of GLhandleARB in VMware's glext.h */
//#define GL_ARB_shader_objects
// HACK
typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer);
# define GL_RGBA_S3TC 0x83A2
# define GL_ALPHA8_EXT 0x803c
# define GL_LUMINANCE8_EXT 0x8040
# define GL_LUMINANCE16_EXT 0x8042
# define GL_LUMINANCE4_ALPHA4_EXT 0x8043
# define GL_LUMINANCE8_ALPHA8_EXT 0x8045
# define GL_INT_2_10_10_10_REV 0x8D9F
#else
# define VBOX_VMSVGA3D_GL_HACK_LEVEL 0x103
#endif
#ifdef DUMP_SHADER_DISASSEMBLY
# include <d3dx9shader.h>
#endif
#include "vmsvga_glext/glext.h"
#include "shaderlib/shaderlib.h"
#include <stdlib.h>
#include <math.h>
#include <float.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Experimental: Create a dedicated context for handling surfaces in, thus
* avoiding orphaned surfaces after context destruction.
*
* This cures, for instance, an assertion on fedora 21 that happens in
* vmsvga3dSurfaceStretchBlt if the login screen and the desktop has different
* sizes. The context of the login screen seems to have just been destroyed
* screen content onto the new sized screen.
*
* @remarks This probably comes at a slight preformance expense, as we currently
* switches context when setting up the surface the first time. Not sure
* if we really need to, but as this is an experiment, I'm playing it safe.
*/
#define VMSVGA3D_OGL_WITH_SHARED_CTX
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
/** Fake surface ID for the shared context. */
#endif
/** @def VBOX_VMSVGA3D_GL_HACK_LEVEL
* Turns out that on Linux gl.h may often define the first 2-4 OpenGL versions
* worth of extensions, but missing out on a function pointer of fifteen. This
* causes headache for us when we use the function pointers below. This hack
* changes the code to call the known problematic functions directly.
* The value is ((x)<<16 | (y)) where x and y are taken from the GL_VERSION_x_y.
*/
#ifndef VBOX_VMSVGA3D_GL_HACK_LEVEL
# define VBOX_VMSVGA3D_GL_HACK_LEVEL 0
#endif
# define VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE 1.0
#endif
#ifdef RT_OS_WINDOWS
# define OGLGETPROCADDRESS wglGetProcAddress
#elif defined(RT_OS_DARWIN)
# include <dlfcn.h>
# define OGLGETPROCADDRESS MyNSGLGetProcAddress
/** Resolves an OpenGL symbol. */
static void *MyNSGLGetProcAddress(const char *pszSymbol)
{
/* Another copy in shaderapi.c. */
s_pvImage = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
}
#else
#endif
/* Invert y-coordinate for OpenGL's bottom left origin. */
#define D3D_TO_OGL_Y_COORD(ptrSurface, y_coordinate) (ptrSurface->pMipmapLevels[0].size.height - (y_coordinate))
#define D3D_TO_OGL_Y_COORD_MIPLEVEL(ptrMipLevel, y_coordinate) (ptrMipLevel->size.height - (y_coordinate))
#define OPENGL_INVALID_ID 0
//#define MANUAL_FLIP_SURFACE_DATA
/* Enable to render the result of DrawPrimitive in a seperate window. */
//#define DEBUG_GFX_WINDOW
/** @name VMSVGA3D_DEF_CTX_F_XXX - vmsvga3dContextDefineOgl flags.
* @{ */
/** When clear, the context is created using the default OpenGL profile.
* When set, it's created using the alternative profile. The latter is only
* allowed if the VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE is set. */
#define VMSVGA3D_DEF_CTX_F_OTHER_PROFILE RT_BIT_32(0)
/** Defining the shared context. */
/** Defining the init time context (EMT). */
/** @} */
#define VMSVGA3D_CLEAR_CURRENT_CONTEXT(pState) \
/** @def VMSVGA3D_SET_CURRENT_CONTEXT
* Makes sure the @a pContext is the active OpenGL context.
* @parm pState The VMSVGA3d state.
* @parm pContext The new context.
*/
#ifdef RT_OS_WINDOWS
{ \
} else do { } while (0)
#elif defined(RT_OS_DARWIN)
{ \
} else do { } while (0)
#else
{ \
(pContext)->glxContext); \
} else do { } while (0)
#endif
/** @def VMSVGA3D_CLEAR_GL_ERRORS
* Clears all pending OpenGL errors.
*
* If I understood this correctly, OpenGL maintains a bitmask internally and
* glGetError gets the next bit (clearing it) from the bitmap and translates it
* into a GL_XXX constant value which it then returns. A single OpenGL call can
* set more than one bit, and they stick around across calls, from what I
* understand.
*
* So in order to be able to use glGetError to check whether a function
* succeeded, we need to call glGetError until all error bits have been cleared.
* This macro does that (in all types of builds).
*
* @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS
*/
#define VMSVGA3D_CLEAR_GL_ERRORS() \
do { \
{ \
} \
} while (0)
/** @def VMSVGA3D_GET_LAST_GL_ERROR
* Gets the last OpenGL error, stores it in a_pContext->lastError and returns
* it.
*
* @returns Same as glGetError.
* @param a_pContext The context to store the error in.
*
* @sa VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
*/
/** @def VMSVGA3D_GL_SUCCESS
* Checks whether VMSVGA3D_GET_LAST_GL_ERROR() return GL_NO_ERROR.
*
* Will call glGetError() and store the result in a_pContext->lastError.
* Will predict GL_NO_ERROR outcome.
*
* @returns True on success, false on error.
* @parm a_pContext The context to store the error in.
*
* @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_COMPLAIN
*/
#define VMSVGA3D_GL_IS_SUCCESS(a_pContext) RT_LIKELY((((a_pContext)->lastError = glGetError()) == GL_NO_ERROR))
/** @def VMSVGA3D_GL_COMPLAIN
* Complains about one or more OpenGL errors (first in a_pContext->lastError).
*
* Strict builds will trigger an assertion, while other builds will put the
* first few occurences in the release log.
*
* All GL errors will be cleared after invocation. Assumes lastError
* is an error, will not check for GL_NO_ERROR.
*
* @param a_pState The 3D state structure.
* @param a_pContext The context that holds the first error.
* @param a_LogRelDetails Argument list for LogRel or similar that describes
* the operation in greater detail.
*
* @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS
*/
#ifdef VBOX_STRICT
do { \
GLenum iNextError; \
AssertMsgFailed(("first error: %#x (idActiveContext=%#x)\n", (a_pContext)->lastError, (a_pContext)->id)); \
} while (0)
#else
do { \
LogRelMax(32, ("VMSVGA3d: OpenGL error %#x (idActiveContext=%#x) on line %u ", (a_pContext)->lastError, (a_pContext)->id)); \
GLenum iNextError; \
} while (0)
#endif
/** @def VMSVGA3D_GL_GET_AND_COMPLAIN
* Combination of VMSVGA3D_GET_GL_ERROR and VMSVGA3D_GL_COMPLAIN, assuming that
* there is a pending error.
*
* @param a_pState The 3D state structure.
* @param a_pContext The context that holds the first error.
* @param a_LogRelDetails Argument list for LogRel or similar that describes
* the operation in greater detail.
*
* @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
*/
do { \
} while (0)
/** @def VMSVGA3D_GL_ASSERT_SUCCESS
* Asserts that VMSVGA3D_GL_IS_SUCCESS is true, complains if not.
*
* Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
* logging in non-strict builds.
*
* @param a_pState The 3D state structure.
* @param a_pContext The context that holds the first error.
* @param a_LogRelDetails Argument list for LogRel or similar that describes
* the operation in greater detail.
*
* @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
*/
if (VMSVGA3D_GL_IS_SUCCESS(a_pContext)) \
{ /* likely */ } \
else do { \
} while (0)
/** @def VMSVGA3D_ASSERT_GL_CALL_EX
* Executes the specified OpenGL API call and asserts that it succeeded, variant
* with extra logging flexibility.
*
* ASSUMES no GL errors pending prior to invocation - caller should use
* VMSVGA3D_CLEAR_GL_ERRORS if uncertain.
*
* Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
* logging in non-strict builds.
*
* @param a_GlCall Expression making an OpenGL call.
* @param a_pState The 3D state structure.
* @param a_pContext The context that holds the first error.
* @param a_LogRelDetails Argument list for LogRel or similar that describes
* the operation in greater detail.
*
* @sa VMSVGA3D_ASSERT_GL_CALL, VMSVGA3D_GL_ASSERT_SUCCESS,
* VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
*/
do { \
(a_GlCall); \
} while (0)
/** @def VMSVGA3D_ASSERT_GL_CALL
* Executes the specified OpenGL API call and asserts that it succeeded.
*
* ASSUMES no GL errors pending prior to invocation - caller should use
* VMSVGA3D_CLEAR_GL_ERRORS if uncertain.
*
* Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
* logging in non-strict builds.
*
* @param a_GlCall Expression making an OpenGL call.
* @param a_pState The 3D state structure.
* @param a_pContext The context that holds the first error.
*
* @sa VMSVGA3D_ASSERT_GL_CALL_EX, VMSVGA3D_GL_ASSERT_SUCCESS,
* VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
*/
/** @def VMSVGA3D_CHECK_LAST_ERROR
* Checks that the last OpenGL error code indicates success.
*
* Will assert and return VERR_INTERNAL_ERROR in strict builds, in other
* builds it will do nothing and is a NOOP.
*
* @parm pState The VMSVGA3d state.
* @parm pContext The context.
*
* @todo Replace with proper error handling, it's crazy to return
* VERR_INTERNAL_ERROR in strict builds and just barge on ahead in
* release builds.
*/
#ifdef VBOX_STRICT
} while (0)
#else
#endif
/** @def VMSVGA3D_CHECK_LAST_ERROR_WARN
* Checks that the last OpenGL error code indicates success.
*
* Will assert in strict builds, otherwise it's a NOOP.
*
* @parm pState The VMSVGA3d state.
* @parm pContext The new context.
*/
#ifdef VBOX_STRICT
AssertMsg((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError)); \
} while (0)
#else
#endif
/**
* Macro for doing something and then checking for errors during initialization.
* Uses AssertLogRelMsg.
*/
#define VMSVGA3D_INIT_CHECKED(a_Expr) \
do \
{ \
a_Expr; \
} while (0)
/**
* Macro for doing something and then checking for errors during initialization,
* doing the same in the other context when enabled.
*
* This will try both profiles in dual profile builds. Caller must be in the
* default context.
*
* Uses AssertLogRelMsg to indicate trouble.
*/
do \
{ \
for (uint32_t i = 0; i < 64; i++) if (glGetError() == GL_NO_ERROR) break; Assert(glGetError() == GL_NO_ERROR); \
a_Expr; \
if (iGlError != GL_NO_ERROR) \
{ \
for (uint32_t i = 0; i < 64; i++) if (glGetError() == GL_NO_ERROR) break; Assert(glGetError() == GL_NO_ERROR); \
a_Expr; \
AssertLogRelMsg(iGlError2 == GL_NO_ERROR, ("VMSVGA3d: %s -> %#x / %#x\n", #a_Expr, iGlError, iGlError2)); \
} \
} while (0)
#else
# define VMSVGA3D_INIT_CHECKED_BOTH(a_pState, a_pContext, a_pOtherCtx, a_Expr) VMSVGA3D_INIT_CHECKED(a_Expr)
#endif
/*******************************************************************************
* Structures, Typedefs and Globals. *
*******************************************************************************/
typedef struct
{
void *pSurfaceData;
bool fDirty;
/**
* SSM descriptor table for the VMSVGA3DMIPMAPLEVEL structure.
*/
static SSMFIELD const g_aVMSVGA3DMIPMAPLEVELFields[] =
{
};
typedef struct
{
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#else
#endif
union
{
} oglId;
/* Dirty state; surface was manually updated. */
bool fDirty;
/**
* SSM descriptor table for the VMSVGA3DSURFACE structure.
*/
static SSMFIELD const g_aVMSVGA3DSURFACEFields[] =
{
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#else
#endif
};
typedef struct
{
void *pShaderProgram;
union
{
void *pVertexShader;
void *pPixelShader;
} u;
/**
* SSM descriptor table for the VMSVGA3DSHADER structure.
*/
static SSMFIELD const g_aVMSVGA3DSHADERFields[] =
{
};
typedef struct
{
bool fValid;
float matrix[16];
typedef struct
{
bool fValid;
typedef struct
{
bool fValid;
float plane[4];
typedef struct
{
bool fEnabled;
bool fValidData;
typedef struct
{
bool fValid;
/**
* SSM descriptor table for the VMSVGASHADERCONST structure.
*/
static SSMFIELD const g_aVMSVGASHADERCONSTFields[] =
{
};
#define VMSVGA3D_UPDATE_SCISSORRECT RT_BIT(0)
typedef struct
{
#ifdef RT_OS_WINDOWS
/* Device context of the context window. */
/* OpenGL rendering context handle. */
/* Device context window handle. */
#elif defined(RT_OS_DARWIN)
/* OpenGL rendering context */
bool fOtherProfile;
#else
/** XGL rendering context handle */
/** Device context window handle */
/** flag whether the window is mapped (=visible) */
bool fMapped;
#endif
/* Framebuffer object associated with this context. */
/* Read and draw framebuffer objects for various operations. */
/* Last GL error recorded. */
/* Current active render target (if any) */
/* Current selected texture surfaces (if any) */
/* Per context pixel and vertex shaders. */
void *pShaderContext;
/* Keep track of the internal state to be able to recreate the context properly (save/restore, window resize). */
struct
{
} state;
/**
* SSM descriptor table for the VMSVGA3DCONTEXT structure.
*/
static SSMFIELD const g_aVMSVGA3DCONTEXTFields[] =
{
#ifdef RT_OS_WINDOWS
#endif
};
/**
* VMSVGA3d state data.
*
* Allocated on the heap and pointed to by VMSVGAState::p3dState.
*/
typedef struct VMSVGA3DSTATE
{
#ifdef RT_OS_WINDOWS
/** Window Thread. */
/** Window request semaphore. */
#elif defined(RT_OS_LINUX)
/* The X display */
bool bTerminate;
#endif
float fGLVersion;
/* Current active context. */
struct
{
#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x102
#endif
#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x103
#endif
bool fEXT_stencil_two_side;
} ext;
struct
{
bool fS3TCSupported;
} caps;
#endif
/** The GL_EXTENSIONS value (space padded) for the default OpenGL profile.
* Free with RTStrFree. */
R3PTRTYPE(char *) pszExtensions;
/** The GL_EXTENSIONS value (space padded) for the other OpenGL profile.
* Free with RTStrFree.
*
* This is used to detect shader model version since some implementations
* (darwin) hides extensions that have made it into core and probably a
* bunch of others when using a OpenGL core profile instead of a legacy one */
R3PTRTYPE(char *) pszOtherExtensions;
/** The version of the other GL profile. */
float fOtherGLVersion;
/** Shader talk back interface. */
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
/** The shared context. */
#endif
/** Pointer to the VMSVGA3d state. */
typedef VMSVGA3DSTATE *PVMSVGA3DSTATE;
/**
* SSM descriptor table for the VMSVGA3DSTATE structure.
*/
static SSMFIELD const g_aVMSVGA3DSTATEFields[] =
{
#ifdef RT_OS_WINDOWS
#elif defined(RT_OS_LINUX)
#endif
};
/** Save and setup everything. */
/**
* Saved texture packing parameters (shared by both pack and unpack).
*/
typedef struct VMSVGAPACKPARAMS
{
#endif
/** Pointer to saved texture packing parameters. */
typedef VMSVGAPACKPARAMS *PVMSVGAPACKPARAMS;
/** Pointer to const saved texture packing parameters. */
typedef VMSVGAPACKPARAMS const *PCVMSVGAPACKPARAMS;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/* Define the default light parameters as specified by MSDN. */
/* @todo move out; fetched from Wine */
{
SVGA3D_LIGHTTYPE_DIRECTIONAL, /* type */
false, /* inWorldSpace */
{ 1.0f, 1.0f, 1.0f, 0.0f }, /* diffuse r,g,b,a */
{ 0.0f, 0.0f, 0.0f, 0.0f }, /* specular r,g,b,a */
{ 0.0f, 0.0f, 0.0f, 0.0f }, /* ambient r,g,b,a, */
{ 0.0f, 0.0f, 0.0f }, /* position x,y,z */
{ 0.0f, 0.0f, 1.0f }, /* direction x,y,z */
0.0f, /* range */
0.0f, /* falloff */
0.0f, 0.0f, 0.0f, /* attenuation 0,1,2 */
0.0f, /* theta */
0.0f /* phi */
};
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static int vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface);
static void vmsvgaColor2GLFloatArray(uint32_t color, GLfloat *pRed, GLfloat *pGreen, GLfloat *pBlue, GLfloat *pAlpha);
static void vmsvga3dSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
static void vmsvga3dRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
/* Generated by VBoxDef2LazyLoad from the VBoxSVGA3D.def and VBoxSVGA3DObjC.def files. */
#ifdef RT_OS_DARWIN
#endif
/**
* Checks if the given OpenGL extension is supported.
*
* @returns true if supported, false if not.
* @param pState The VMSVGA3d state.
* @param fActualGLVersion The actual OpenGL version we're working against.
* @param fMinGLVersion The OpenGL version that introduced this feature
* into the core.
* @param pszWantedExtension The name of the OpenGL extension we want padded
* with one space at each end.
* @remarks Init time only.
*/
static bool vmsvga3dCheckGLExtension(PVMSVGA3DSTATE pState, float fMinGLVersion, const char *pszWantedExtension)
{
/* check padding. */
/* Look it up. */
bool fRet = false;
fRet = true;
/* Temporarily. Later start if (fMinGLVersion != 0.0 && fActualGLVersion >= fMinGLVersion) return true; */
#ifdef RT_OS_DARWIN
|| VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE == 2.1,
("%s actual:%d min:%d fRet=%d\n",
#else
("%s actual:%d min:%d fRet=%d\n",
#endif
return fRet;
}
/**
* Outputs GL_EXTENSIONS list to the release log.
*/
{
/* OpenGL 3.0 interface (glGetString(GL_EXTENSIONS) return NULL). */
bool fBuffered = RTLogRelSetBuffering(true);
/*
* Determin the column widths first.
*/
uint32_t i;
const char *psz = pszExtensions;
for (i = 0; ; i++)
{
while (*psz == ' ')
psz++;
if (!*psz)
break;
}
/*
* Output it.
*/
psz = pszExtensions;
for (i = 0; ; i++)
{
while (*psz == ' ')
psz++;
if (!*psz)
break;
if (iColumn == 0)
else
}
LogRel(("\n"));
}
/**
* Gathers the GL_EXTENSIONS list, storing it as a space padded list at
* @a ppszExtensions.
*
* @returns VINF_SUCCESS or VERR_NO_STR_MEMORY
* @param ppszExtensions Pointer to the string pointer. Free with RTStrFree.
* @param fGLProfileVersion The OpenGL profile version.
*/
{
int rc;
*ppszExtensions = NULL;
/*
* Try the old glGetString interface first.
*/
if (pszExtensions)
{
}
else
{
/*
* The new interface where each extension string is retrieved separately.
* Note! Cannot use VMSVGA3D_INIT_CHECKED_GL_GET_INTEGER_VALUE here because
* the above GL_EXTENSIONS error lingers on darwin. sucks.
*/
#ifndef GL_NUM_EXTENSIONS
# define GL_NUM_EXTENSIONS 0x821D
#endif
{
if (pszExt)
rc = RTStrAAppendExN(ppszExtensions, 2, pfnGlGetStringi(GL_EXTENSIONS, i), RTSTR_MAX, " ", (size_t)1);
}
}
#if 1
/*
* Add extensions promoted into the core OpenGL profile.
*/
static const struct
{
float fGLVersion;
const char *pszzExtensions;
} s_aPromotedExtensions[] =
{
{
1.1f,
" GL_EXT_vertex_array \0"
" GL_EXT_polygon_offset \0"
" GL_EXT_blend_logic_op \0"
" GL_EXT_texture \0"
" GL_EXT_copy_texture \0"
" GL_EXT_subtexture \0"
" GL_EXT_texture_object \0"
" GL_ARB_framebuffer_object \0"
" GL_ARB_map_buffer_range \0"
" GL_ARB_vertex_array_object \0"
"\0"
},
{
1.2f,
" EXT_texture3D \0"
" EXT_bgra \0"
" EXT_packed_pixels \0"
" EXT_rescale_normal \0"
" EXT_separate_specular_color \0"
" SGIS_texture_edge_clamp \0"
" SGIS_texture_lod \0"
" EXT_draw_range_elements \0"
"\0"
},
{
1.3f,
" GL_ARB_texture_compression \0"
" GL_ARB_texture_cube_map \0"
" GL_ARB_multisample \0"
" GL_ARB_multitexture \0"
" GL_ARB_texture_env_add \0"
" GL_ARB_texture_env_combine \0"
" GL_ARB_texture_env_dot3 \0"
" GL_ARB_texture_border_clamp \0"
" GL_ARB_transpose_matrix \0"
"\0"
},
{
1.5f,
" GL_SGIS_generate_mipmap \0"
/*" GL_NV_blend_equare \0"*/
" GL_ARB_depth_texture \0"
" GL_ARB_shadow \0"
" GL_EXT_fog_coord \0"
" GL_EXT_multi_draw_arrays \0"
" GL_ARB_point_parameters \0"
" GL_EXT_secondary_color \0"
" GL_EXT_blend_func_separate \0"
" GL_EXT_stencil_wrap \0"
" GL_ARB_texture_env_crossbar \0"
" GL_EXT_texture_lod_bias \0"
" GL_ARB_texture_mirrored_repeat \0"
" GL_ARB_window_pos \0"
"\0"
},
{
1.6f,
" GL_ARB_vertex_buffer_object \0"
" GL_ARB_occlusion_query \0"
" GL_EXT_shadow_funcs \0"
},
{
2.0f,
" GL_ARB_shader_objects \0" /*??*/
" GL_ARB_vertex_shader \0" /*??*/
" GL_ARB_fragment_shader \0" /*??*/
" GL_ARB_shading_language_100 \0" /*??*/
" GL_ARB_draw_buffers \0"
" GL_ARB_texture_non_power_of_two \0"
" GL_ARB_point_sprite \0"
" GL_ATI_separate_stencil \0"
" GL_EXT_stencil_two_side \0"
"\0"
},
{
2.1f,
" GL_ARB_pixel_buffer_object \0"
" GL_EXT_texture_sRGB \0"
"\0"
},
{
3.0f,
" GL_ARB_framebuffer_object \0"
" GL_ARB_map_buffer_range \0"
" GL_ARB_vertex_array_object \0"
"\0"
},
{
3.1f,
" GL_ARB_copy_buffer \0"
" GL_ARB_uniform_buffer_object \0"
"\0"
},
{
3.2f,
" GL_ARB_vertex_array_bgra \0"
" GL_ARB_draw_elements_base_vertex \0"
" GL_ARB_fragment_coord_conventions \0"
" GL_ARB_provoking_vertex \0"
" GL_ARB_seamless_cube_map \0"
" GL_ARB_texture_multisample \0"
" GL_ARB_depth_clamp \0"
" GL_ARB_sync \0"
" GL_ARB_geometry_shader4 \0" /*??*/
"\0"
},
{
3.3f,
" GL_ARB_blend_func_extended \0"
" GL_ARB_sampler_objects \0"
" GL_ARB_explicit_attrib_location \0"
" GL_ARB_occlusion_query2 \0"
" GL_ARB_shader_bit_encoding \0"
" GL_ARB_texture_rgb10_a2ui \0"
" GL_ARB_texture_swizzle \0"
" GL_ARB_timer_query \0"
" GL_ARB_vertex_type_2_10_10_10_rev \0"
"\0"
},
{
4.0f,
" GL_ARB_texture_query_lod \0"
" GL_ARB_draw_indirect \0"
" GL_ARB_gpu_shader5 \0"
" GL_ARB_gpu_shader_fp64 \0"
" GL_ARB_shader_subroutine \0"
" GL_ARB_tessellation_shader \0"
" GL_ARB_texture_buffer_object_rgb32 \0"
" GL_ARB_texture_cube_map_array \0"
" GL_ARB_texture_gather \0"
" GL_ARB_transform_feedback2 \0"
" GL_ARB_transform_feedback3 \0"
"\0"
},
{
4.1f,
" GL_ARB_ES2_compatibility \0"
" GL_ARB_get_program_binary \0"
" GL_ARB_separate_shader_objects \0"
" GL_ARB_shader_precision \0"
" GL_ARB_vertex_attrib_64bit \0"
" GL_ARB_viewport_array \0"
"\0"
}
};
for (uint32_t i = 0; i < RT_ELEMENTS(s_aPromotedExtensions) && s_aPromotedExtensions[i].fGLVersion <= fGLProfileVersion; i++)
{
while (*pszExt)
{
{
if (cPromoted++ == 0)
{
rc = RTStrAAppend(ppszExtensions, " <promoted-extensions:> <promoted-extensions:> <promoted-extensions:> ");
}
}
}
}
#endif
return VINF_SUCCESS;
}
/**
* @interface_method_impl{VBOXVMSVGASHADERIF, pfnSwitchInitProfile}
*/
static DECLCALLBACK(void) vmsvga3dShaderIfSwitchInitProfile(PVBOXVMSVGASHADERIF pThis, bool fOtherProfile)
{
#else
#endif
}
/**
* @interface_method_impl{VBOXVMSVGASHADERIF, pfnGetNextExtension}
*/
static DECLCALLBACK(bool) vmsvga3dShaderIfGetNextExtension(PVBOXVMSVGASHADERIF pThis, void **ppvEnumCtx,
{
while (*pszCur == ' ')
pszCur++;
if (!*pszCur)
return false;
AssertReturn(pszEnd, false);
{
}
else if (cbBuf > 0)
{
}
*ppvEnumCtx = (void *)pszEnd;
return true;
}
/**
* Initializes the VMSVGA3D state during VGA device construction.
*
* Failure are generally not fatal, 3D support will just be disabled.
*
* @returns VBox status code.
* @param pThis The VGA device state where svga.p3dState will be modified.
*/
{
AssertCompile(GL_FALSE == 0);
/*
* Load and resolve imports from the external shared libraries.
*/
if (RT_FAILURE(rc))
{
LogRel(("VMSVGA3d: Error loading VBoxSVGA3D and resolving necessary functions: %Rrc - %s\n", rc, ErrInfo.Core.pszMsg));
return rc;
}
#ifdef RT_OS_DARWIN
if (RT_FAILURE(rc))
{
LogRel(("VMSVGA3d: Error loading VBoxSVGA3DObjC and resolving necessary functions: %Rrc - %s\n", rc, ErrInfo.Core.pszMsg));
return rc;
}
#endif
/*
* Allocate the state.
*/
#ifdef RT_OS_WINDOWS
/* Create event semaphore and async IO thread. */
if (RT_SUCCESS(rc))
{
rc = RTThreadCreate(&pState->pWindowThread, vmsvga3dWindowThread, pState->WndRequestSem, 0, RTTHREADTYPE_GUI, 0,
"VMSVGA3DWND");
if (RT_SUCCESS(rc))
return VINF_SUCCESS;
/* bail out. */
}
else
return rc;
#else
return VINF_SUCCESS;
#endif
}
/* We must delay window creation until the PowerOn phase. Init is too early and will cause failures. */
{
#endif
int rc;
return VINF_SUCCESS; /* already initialized (load state) */
/*
* OpenGL function calls aren't possible without a valid current context, so create a fake one here.
*/
LogRel(("VMSVGA3d: OpenGL version: %s\n"
"VMSVGA3d: OpenGL Vendor: %s\n"
"VMSVGA3d: OpenGL Renderer: %s\n"
"VMSVGA3d: OpenGL shader language version: %s\n",
/*
* Get the extension list for the alternative profile so we can better
* figure out the shader model and stuff.
*/
rc = vmsvga3dContextDefineOgl(pThis, 2, VMSVGA3D_DEF_CTX_F_INIT | VMSVGA3D_DEF_CTX_F_OTHER_PROFILE);
LogRel(("VMSVGA3d: Alternative OpenGL version: %s\n"
"VMSVGA3d: Alternative OpenGL Vendor: %s\n"
"VMSVGA3d: Alternative OpenGL Renderer: %s\n"
"VMSVGA3d: Alternative OpenGL shader language version: %s\n",
#else
#endif
{
pState->ext.glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)OGLGETPROCADDRESS("glBindRenderbuffer");
pState->ext.glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)OGLGETPROCADDRESS("glDeleteRenderbuffers");
pState->ext.glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)OGLGETPROCADDRESS("glGenRenderbuffers");
pState->ext.glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)OGLGETPROCADDRESS("glRenderbufferStorage");
pState->ext.glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)OGLGETPROCADDRESS("glGetRenderbufferParameteriv");
pState->ext.glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)OGLGETPROCADDRESS("glDeleteFramebuffers");
pState->ext.glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)OGLGETPROCADDRESS("glCheckFramebufferStatus");
pState->ext.glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)OGLGETPROCADDRESS("glFramebufferTexture1D");
pState->ext.glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)OGLGETPROCADDRESS("glFramebufferTexture2D");
pState->ext.glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)OGLGETPROCADDRESS("glFramebufferTexture3D");
pState->ext.glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)OGLGETPROCADDRESS("glFramebufferRenderbuffer");
pState->ext.glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)OGLGETPROCADDRESS("glGetFramebufferAttachmentParameteriv");
pState->ext.glRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC)OGLGETPROCADDRESS("glRenderbufferStorageMultisample");
pState->ext.glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC)OGLGETPROCADDRESS("glFramebufferTextureLayer");
}
AssertMsgReturn(pState->ext.glPointParameterf, ("glPointParameterf missing"), VERR_NOT_IMPLEMENTED);
#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x102
#endif
pState->ext.glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC)OGLGETPROCADDRESS("glBlendEquationSeparate");
AssertMsgReturn(pState->ext.glBlendEquationSeparate, ("glBlendEquationSeparate missing"), VERR_NOT_IMPLEMENTED);
pState->ext.glBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC)OGLGETPROCADDRESS("glBlendFuncSeparate");
AssertMsgReturn(pState->ext.glBlendFuncSeparate, ("glBlendFuncSeparate missing"), VERR_NOT_IMPLEMENTED);
pState->ext.glStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC)OGLGETPROCADDRESS("glStencilOpSeparate");
AssertMsgReturn(pState->ext.glStencilOpSeparate, ("glStencilOpSeparate missing"), VERR_NOT_IMPLEMENTED);
pState->ext.glStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC)OGLGETPROCADDRESS("glStencilFuncSeparate");
AssertMsgReturn(pState->ext.glStencilFuncSeparate, ("glStencilFuncSeparate missing"), VERR_NOT_IMPLEMENTED);
pState->ext.glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)OGLGETPROCADDRESS("glEnableVertexAttribArray");
AssertMsgReturn(pState->ext.glEnableVertexAttribArray, ("glEnableVertexAttribArray missing"), VERR_NOT_IMPLEMENTED);
pState->ext.glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC)OGLGETPROCADDRESS("glDisableVertexAttribArray");
AssertMsgReturn(pState->ext.glDisableVertexAttribArray, ("glDisableVertexAttribArray missing"), VERR_NOT_IMPLEMENTED);
pState->ext.glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)OGLGETPROCADDRESS("glVertexAttribPointer");
AssertMsgReturn(pState->ext.glVertexAttribPointer, ("glVertexAttribPointer missing"), VERR_NOT_IMPLEMENTED);
AssertMsgReturn(pState->ext.glFogCoordPointer, ("glFogCoordPointer missing"), VERR_NOT_IMPLEMENTED);
#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x103
pState->ext.glClientActiveTexture = (PFNGLCLIENTACTIVETEXTUREPROC)OGLGETPROCADDRESS("glClientActiveTexture");
AssertMsgReturn(pState->ext.glClientActiveTexture, ("glClientActiveTexture missing"), VERR_NOT_IMPLEMENTED);
#endif
AssertMsgReturn(pState->ext.glGetProgramivARB, ("glGetProgramivARB missing"), VERR_NOT_IMPLEMENTED);
/* OpenGL 3.2 core */
{
pState->ext.glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC)OGLGETPROCADDRESS("glDrawElementsBaseVertex");
pState->ext.glDrawElementsInstancedBaseVertex = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC)OGLGETPROCADDRESS("glDrawElementsInstancedBaseVertex");
}
else
LogRel(("VMSVGA3d: missing extension GL_ARB_draw_elements_base_vertex\n"));
/* OpenGL 3.2 core */
{
}
else
LogRel(("VMSVGA3d: missing extension GL_ARB_provoking_vertex\n"));
/* Extension support */
#if defined(RT_OS_DARWIN)
/** @todo OpenGL version history suggest this, verify... */
pState->ext.fEXT_stencil_two_side = vmsvga3dCheckGLExtension(pState, 2.0f, " GL_EXT_stencil_two_side ");
#else
pState->ext.fEXT_stencil_two_side = vmsvga3dCheckGLExtension(pState, 0.0f, " GL_EXT_stencil_two_side ");
#endif
/*
* Initialize the capabilities with sensible defaults.
*/
/*
* Query capabilities
*/
VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx, glGetIntegerv(GL_MAX_LIGHTS, &pState->caps.maxActiveLights));
VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx, glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &pState->caps.maxTextureBufferSize));
VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx, glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &pState->caps.maxTextures));
#ifdef VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE /* The alternative profile has a higher number here (ati/darwin). */
VMSVGA3D_INIT_CHECKED_BOTH(pState, pOtherCtx, pContext, glGetIntegerv(GL_MAX_CLIP_DISTANCES, &pState->caps.maxClipDistances));
#else
#endif
VMSVGA3D_INIT_CHECKED(glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE, &pState->caps.maxRectangleTextureSize));
VMSVGA3D_INIT_CHECKED(glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &pState->caps.maxTextureAnisotropy));
VMSVGA3D_INIT_CHECKED_BOTH(pState, pContext, pOtherCtx, glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pState->caps.flPointSize));
{
}
pState->caps.fS3TCSupported = vmsvga3dCheckGLExtension(pState, 0.0f, " GL_EXT_texture_compression_s3tc ");
* ARB Assembly Language
* These are done through testing the presence of extensions. You should test them in this order:
* GL_NV_gpu_program4: SM 4.0 or better.
* GL_NV_vertex_program3: SM 3.0 or better.
* GL_ARB_fragment_program: SM 2.0 or better.
* ATI does not support higher than SM 2.0 functionality in assembly shaders.
*
*/
/** @todo: distinguish between vertex and pixel shaders??? */
{
}
else
|| vmsvga3dCheckGLExtension(pState, 0.0f, " GL_ARB_shader_texture_lod ") /* Wine claims this suggests SM 3.0 support */
)
{
}
else
{
}
else
{
LogRel(("VMSVGA3D: WARNING: unknown support for assembly shaders!!\n"));
}
{
/** @todo Intel drivers don't support this extension! */
LogRel(("VMSVGA3D: WARNING: Missing required extension GL_ARB_vertex_array_bgra (d3dcolor)!!!\n"));
}
#if 0
#endif
LogRel(("VMSVGA3d: Capabilities:\n"));
LogRel(("VMSVGA3d: maxActiveLights=%-2d maxTextures=%-2d maxTextureBufferSize=%d\n",
LogRel(("VMSVGA3d: maxClipDistances=%-2d maxColorAttachments=%-2d maxClipDistances=%d\n",
LogRel(("VMSVGA3d: maxColorAttachments=%-2d maxTextureAnisotropy=%-2d maxRectangleTextureSize=%d\n",
pState->caps.maxColorAttachments, pState->caps.maxTextureAnisotropy, pState->caps.maxRectangleTextureSize));
LogRel(("VMSVGA3d: maxVertexShaderTemps=%-2d maxVertexShaderInstructions=%d maxFragmentShaderInstructions=%d\n",
pState->caps.maxVertexShaderTemps, pState->caps.maxVertexShaderInstructions, pState->caps.maxFragmentShaderInstructions));
LogRel(("VMSVGA3d: maxFragmentShaderTemps=%d flPointSize={%d.%02u, %d.%02u}\n",
LogRel(("VMSVGA3d: fragmentShaderVersion=%-2d vertexShaderVersion=%-2d fS3TCSupported=%d\n",
pState->caps.fragmentShaderVersion, pState->caps.vertexShaderVersion, pState->caps.fS3TCSupported));
/* Initialize the shader library. */
/* Cleanup */
#endif
{
LogRel(("VMSVGA3d: unsupported OpenGL version; minimum is 3.0\n"));
return VERR_NOT_IMPLEMENTED;
}
{
LogRel(("VMSVGA3d: missing required OpenGL extension; aborting\n"));
return VERR_NOT_IMPLEMENTED;
}
#endif
return VINF_SUCCESS;
}
{
/* Destroy all leftover surfaces. */
{
}
/* Destroy all leftover contexts. */
{
}
return VINF_SUCCESS;
}
{
int rc;
/* Terminate the shader library. */
rc = ShaderDestroyLib();
#ifdef RT_OS_WINDOWS
/* Terminate the window creation thread. */
rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_EXIT, 0, 0);
#elif defined(RT_OS_DARWIN)
#elif defined(RT_OS_LINUX)
/* signal to the thread that it is supposed to exit */
pState->bTerminate = true;
/* wait for it to terminate */
#endif
#endif
return VINF_SUCCESS;
}
/* Shared functions that depend on private structure definitions. */
#define VMSVGA3D_OPENGL
#include "DevVGA-SVGA3d-shared.h"
/**
* Worker for vmsvga3dQueryCaps that figures out supported operations for a
* given surface format capability.
*
* @param pState3D The 3D state.
* @param idx3dCaps The SVGA3D_CAPS_XXX value of the surface format.
*
* @remarks See fromat_cap_table in svga_format.c (mesa/gallium) for a reference
* of implicit guest expectations:
*/
{
/* @todo missing:
*
* SVGA3DFORMAT_OP_PIXELSIZE
*/
switch (idx3dCaps)
{
| SVGA3DFORMAT_OP_DISPLAYMODE /* Should not be set for alpha formats. */
| SVGA3DFORMAT_OP_3DACCELERATION; /* implies OP_DISPLAYMODE */
break;
break;
}
/* @todo check hardware caps! */
switch (idx3dCaps)
{
break;
| SVGA3DFORMAT_OP_TEXTURE /* Necessary for Ubuntu Unity */;
break;
break;
break;
break;
break;
}
return result;
}
{
/* @todo test this somehow */
return result;
}
{
int rc = VINF_SUCCESS;
*pu32Val = 0;
/*
* The capabilities access by current (2015-03-01) linux sources (gallium,
* vmwgfx, xorg-video-vmware) are annotated, caps without xref annotations
* aren't access.
*/
switch (idx3dCaps)
{
/* Linux: vmwgfx_fifo.c in kmod; only used with SVGA_CAP_GBOBJECTS. */
case SVGA3D_DEVCAP_3D:
break;
case SVGA3D_DEVCAP_MAX_LIGHTS:
break;
break;
break;
/* Linux: svga_screen.c in gallium; 3.0 or later required. */
break;
/* boolean? */
break;
/* Linux: svga_screen.c in gallium; 3.0 or later required. */
break;
/* boolean? */
break;
/* Must be obsolete by now; surface format caps specify the same thing. */
break;
break;
/*
* 2. The BUFFER_FORMAT capabilities are deprecated, and they always
* return TRUE. Even on physical hardware that does not support
* these formats natively, the SVGA3D device will provide an emulation
* which should be invisible to the guest OS.
*/
*pu32Val = 1;
break;
break;
break;
/* Linux: svga_screen.c in gallium; capped at 80.0, default 1.0. */
AssertCompile(sizeof(uint32_t) == sizeof(float));
break;
/* @todo ?? */
break;
/* Linux: svga_screen.c in gallium (for PIPE_CAP_MAX_TEXTURE_2D_LEVELS); have default if missing. */
break;
/* Linux: svga_screen.c in gallium (for PIPE_CAP_MAX_TEXTURE_3D_LEVELS); have default if missing. */
//*pu32Val = pCaps->MaxVolumeExtent;
break;
break;
//*pu32Val = pCaps->MaxTextureAspectRatio;
break;
/* Linux: svga_screen.c in gallium (for PIPE_CAPF_MAX_TEXTURE_ANISOTROPY); defaults to 4.0. */
break;
break;
/* Linux: svga_screen.c in gallium (for PIPE_SHADER_VERTEX/PIPE_SHADER_CAP_MAX_INSTRUCTIONS); defaults to 512. */
break;
break;
/* Linux: svga_screen.c in gallium (for PIPE_SHADER_VERTEX/PIPE_SHADER_CAP_MAX_TEMPS); defaults to 32. */
break;
/* Linux: svga_screen.c in gallium (for PIPE_SHADER_FRAGMENT/PIPE_SHADER_CAP_MAX_TEMPS); defaults to 32. */
break;
break;
break;
break;
break;
break;
//*pu32Val = !!(pCaps->Caps2 & D3DCAPS2_CANAUTOGENMIPMAP);
break;
break;
case SVGA3D_DEVCAP_MAX_RENDER_TARGETS: /* @todo same thing? */
break;
/*
* This is the maximum number of SVGA context IDs that the guest
* can define using SVGA_3D_CMD_CONTEXT_DEFINE.
*/
break;
/*
* This is the maximum number of SVGA surface IDs that the guest
* can define using SVGA_3D_CMD_SURFACE_DEFINE*.
*/
break;
#if 0 /* Appeared more recently, not yet implemented. */
/* Linux: svga_screen.c in gallium; defaults to FALSE. */
case SVGA3D_DEVCAP_LINE_AA:
break;
/* Linux: svga_screen.c in gallium; defaults to FALSE. */
break;
/* Linux: svga_screen.c in gallium; defaults to 1.0. */
break;
/* Linux: svga_screen.c in gallium; defaults to 1.0. */
break;
#endif
/*
* Supported surface formats.
* Linux: svga_format.c in gallium, format_cap_table defines implicit expectations.
*/
break;
*pu32Val = 0; /* apparently not supported in OpenGL */
break;
break;
/* Linux: Not referenced in current sources. */
*pu32Val = 0;
break;
default:
break;
}
return rc;
}
/**
* Convert SVGA format value to its OpenGL equivalent
*
* help from wined3dformat_from_d3dformat().
*/
{
switch (format)
{
case SVGA3D_X8R8G8B8: /* D3DFMT_X8R8G8B8 - WINED3DFMT_B8G8R8X8_UNORM */
break;
case SVGA3D_A8R8G8B8: /* D3DFMT_A8R8G8B8 - WINED3DFMT_B8G8R8A8_UNORM */
break;
case SVGA3D_R5G6B5: /* D3DFMT_R5G6B5 - WINED3DFMT_B5G6R5_UNORM */
AssertMsgFailed(("Test me - SVGA3D_R5G6B5\n"));
break;
case SVGA3D_X1R5G5B5: /* D3DFMT_X1R5G5B5 - WINED3DFMT_B5G5R5X1_UNORM */
AssertMsgFailed(("Test me - SVGA3D_X1R5G5B5\n"));
break;
case SVGA3D_A1R5G5B5: /* D3DFMT_A1R5G5B5 - WINED3DFMT_B5G5R5A1_UNORM */
AssertMsgFailed(("Test me - SVGA3D_A1R5G5B5\n"));
break;
case SVGA3D_A4R4G4B4: /* D3DFMT_A4R4G4B4 - WINED3DFMT_B4G4R4A4_UNORM */
AssertMsgFailed(("Test me - SVGA3D_A4R4G4B4\n"));
break;
case SVGA3D_Z_D32: /* D3DFMT_D32 - WINED3DFMT_D32_UNORM */
break;
case SVGA3D_Z_D16: /* D3DFMT_D16 - WINED3DFMT_D16_UNORM */
AssertMsgFailed(("Test me - SVGA3D_Z_D16\n"));
break;
case SVGA3D_Z_D24S8: /* D3DFMT_D24S8 - WINED3DFMT_D24_UNORM_S8_UINT */
break;
case SVGA3D_Z_D15S1: /* D3DFMT_D15S1 - WINED3DFMT_S1_UINT_D15_UNORM */
/** @todo Wine sources hints at no hw support for this, so test this one! */
AssertMsgFailed(("Test me - SVGA3D_Z_D15S1\n"));
break;
case SVGA3D_Z_D24X8: /* D3DFMT_D24X8 - WINED3DFMT_X8D24_UNORM */
break;
/* Advanced D3D9 depth formats. */
case SVGA3D_Z_DF16: /* D3DFMT_DF16? - not supported */
break;
case SVGA3D_Z_DF24: /* D3DFMT_DF24? - not supported */
break;
case SVGA3D_Z_D24S8_INT: /* D3DFMT_??? - not supported */
break;
case SVGA3D_DXT1: /* D3DFMT_DXT1 - WINED3DFMT_DXT1 */
#if 0
#else /* wine suggests: */
AssertMsgFailed(("Test me - SVGA3D_DXT1\n"));
#endif
break;
case SVGA3D_DXT3: /* D3DFMT_DXT3 - WINED3DFMT_DXT3 */
#if 0 /** @todo this needs testing... */
#else /* wine suggests: */
AssertMsgFailed(("Test me - SVGA3D_DXT3\n"));
#endif
break;
case SVGA3D_DXT5: /* D3DFMT_DXT5 - WINED3DFMT_DXT5 */
#if 0 /** @todo this needs testing... */
#else /* wine suggests: */
AssertMsgFailed(("Test me - SVGA3D_DXT5\n"));
#endif
break;
case SVGA3D_LUMINANCE8: /* D3DFMT_? - ? */
break;
case SVGA3D_LUMINANCE16: /* D3DFMT_? - ? */
break;
case SVGA3D_LUMINANCE4_ALPHA4: /* D3DFMT_? - ? */
break;
case SVGA3D_LUMINANCE8_ALPHA8: /* D3DFMT_? - ? */
pSurface->typeGL = GL_UNSIGNED_BYTE; /* unsigned_short causes issues even though this type should be 16-bit */
break;
case SVGA3D_ALPHA8: /* D3DFMT_A8? - WINED3DFMT_A8_UNORM? */
break;
#if 0
/* Bump-map formats */
case SVGA3D_BUMPU8V8:
return D3DFMT_V8U8;
case SVGA3D_BUMPL6V5U5:
return D3DFMT_L6V5U5;
case SVGA3D_BUMPX8L8V8U8:
return D3DFMT_X8L8V8U8;
case SVGA3D_BUMPL8V8U8:
/* No corresponding D3D9 equivalent. */
/* signed bump-map formats */
case SVGA3D_V8U8:
return D3DFMT_V8U8;
case SVGA3D_Q8W8V8U8:
return D3DFMT_Q8W8V8U8;
case SVGA3D_CxV8U8:
return D3DFMT_CxV8U8;
/* mixed bump-map formats */
case SVGA3D_X8L8V8U8:
return D3DFMT_X8L8V8U8;
case SVGA3D_A2W10V10U10:
return D3DFMT_A2W10V10U10;
#endif
case SVGA3D_ARGB_S10E5: /* 16-bit floating-point ARGB */ /* D3DFMT_A16B16G16R16F - WINED3DFMT_R16G16B16A16_FLOAT */
#if 0 /* bird: wine uses half float, sounds correct to me... */
#else
AssertMsgFailed(("Test me - SVGA3D_ARGB_S10E5\n"));
#endif
break;
case SVGA3D_ARGB_S23E8: /* 32-bit floating-point ARGB */ /* D3DFMT_A32B32G32R32F - WINED3DFMT_R32G32B32A32_FLOAT */
break;
case SVGA3D_A2R10G10B10: /* D3DFMT_A2R10G10B10 - WINED3DFMT_B10G10R10A2_UNORM */
#if 0 /* bird: Wine uses GL_BGRA instead of GL_RGBA. */
#else
#endif
AssertMsgFailed(("Test me - SVGA3D_A2R10G10B10\n"));
break;
/* Single- and dual-component floating point formats */
case SVGA3D_R_S10E5: /* D3DFMT_R16F - WINED3DFMT_R16_FLOAT */
#if 0 /* bird: wine uses half float, sounds correct to me... */
#else
AssertMsgFailed(("Test me - SVGA3D_R_S10E5\n"));
#endif
break;
case SVGA3D_R_S23E8: /* D3DFMT_R32F - WINED3DFMT_R32_FLOAT */
break;
case SVGA3D_RG_S10E5: /* D3DFMT_G16R16F - WINED3DFMT_R16G16_FLOAT */
#if 0 /* bird: wine uses half float, sounds correct to me... */
#else
AssertMsgFailed(("Test me - SVGA3D_RG_S10E5\n"));
#endif
break;
case SVGA3D_RG_S23E8: /* D3DFMT_G32R32F - WINED3DFMT_R32G32_FLOAT */
break;
/*
* Any surface can be used as a buffer object, but SVGA3D_BUFFER is
* the most efficient format to use when creating new surfaces
* expressly for index or vertex data.
*/
case SVGA3D_BUFFER:
break;
#if 0
return D3DFMT_UNKNOWN;
case SVGA3D_V16U16:
return D3DFMT_V16U16;
#endif
case SVGA3D_G16R16: /* D3DFMT_G16R16 - WINED3DFMT_R16G16_UNORM */
#if 0 /* bird: Wine uses GL_UNSIGNED_SHORT here. */
#else
AssertMsgFailed(("test me - SVGA3D_G16R16\n"));
#endif
break;
case SVGA3D_A16B16G16R16: /* D3DFMT_A16B16G16R16 - WINED3DFMT_R16G16B16A16_UNORM */
#if 0 /* bird: Wine uses GL_UNSIGNED_SHORT here. */
#else
AssertMsgFailed(("Test me - SVGA3D_A16B16G16R16\n"));
#endif
break;
#if 0
/* Packed Video formats */
case SVGA3D_UYVY:
return D3DFMT_UYVY;
case SVGA3D_YUY2:
return D3DFMT_YUY2;
/* Planar video formats */
case SVGA3D_NV12:
/* Video format with alpha */
case SVGA3D_AYUV:
case SVGA3D_BC4_UNORM:
case SVGA3D_BC5_UNORM:
/* Unknown; only in DX10 & 11 */
break;
#endif
default:
break;
}
}
#if 0
/**
* Convert SVGA multi sample count value to its D3D equivalent
*/
{
if (multisampleCount > 16)
return D3DMULTISAMPLE_NONE;
/* @todo exact same mapping as d3d? */
return (D3DMULTISAMPLE_TYPE)multisampleCount;
}
#endif
int vmsvga3dSurfaceDefine(PVGASTATE pThis, uint32_t sid, uint32_t surfaceFlags, SVGA3dSurfaceFormat format,
{
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));
/* Assuming all faces have the same nr of mipmaps. */
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));
}
/* If one already exists with this id, then destroy it now. */
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#else
#endif
/* The surface type is sort of undefined now, even though the hints and format can help to clear that up.
* In some case we'll have to wait until the surface is used to create the D3D object.
*/
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:
break;
/* Texture compression formats */
case SVGA3D_DXT1:
case SVGA3D_DXT2:
case SVGA3D_DXT3:
case SVGA3D_DXT4:
case SVGA3D_DXT5:
/* Bump-map formats */
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:
/* Typical render target formats; we should allow render target buffers to be used as textures. */
case SVGA3D_X8R8G8B8:
case SVGA3D_A8R8G8B8:
case SVGA3D_R5G6B5:
case SVGA3D_X1R5G5B5:
case SVGA3D_A1R5G5B5:
case SVGA3D_A4R4G4B4:
break;
case SVGA3D_LUMINANCE8:
case SVGA3D_LUMINANCE4_ALPHA4:
case SVGA3D_LUMINANCE16:
case SVGA3D_LUMINANCE8_ALPHA8:
case SVGA3D_ARGB_S10E5: /* 16-bit floating-point ARGB */
case SVGA3D_ARGB_S23E8: /* 32-bit floating-point ARGB */
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:
break;
/*
* Any surface can be used as a buffer object, but SVGA3D_BUFFER is
* the most efficient format to use when creating new surfaces
* expressly for index or vertex data.
*/
case SVGA3D_BUFFER:
break;
default:
break;
}
pSurface->pMipmapLevels = (PVMSVGA3DMIPMAPLEVEL)RTMemAllocZ(cMipLevels * sizeof(VMSVGA3DMIPMAPLEVEL));
for (uint32_t i=0; i < cMipLevels; i++)
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(("SVGA3D_SURFACE_CUBEMAP\n"));
break;
Log(("SVGA3D_SURFACE_HINT_INDEXBUFFER\n"));
/* else type unknown at this time; postpone buffer creation */
break;
Log(("SVGA3D_SURFACE_HINT_VERTEXBUFFER\n"));
/* Type unknown at this time; postpone buffer creation */
break;
Log(("SVGA3D_SURFACE_HINT_TEXTURE\n"));
break;
Log(("SVGA3D_SURFACE_HINT_RENDERTARGET\n"));
break;
Log(("SVGA3D_SURFACE_HINT_DEPTHSTENCIL\n"));
break;
default:
/* Unknown; decide later. */
break;
}
/* Allocate buffer to hold the surface data until we can move it into a D3D object */
{
{
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;
}
{
{
#if 1 /* Windows is doing this, guess it makes sense here as well... */
/* Check all contexts if this surface is used as a render target or active texture. */
{
{
}
}
#endif
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#else
/* @todo stricter checks for associated context */
{
}
/* If there is a GL buffer or something associated with the surface, we
really need something here, so pick any active context. */
{
{
{
break;
}
}
AssertReturn(pContext, VERR_INTERNAL_ERROR); /* otherwise crashes/fails; create temp context if this ever triggers! */
}
#endif
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:
AssertFailed(); /* @todo */
break;
{
}
break;
{
}
break;
case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE: /* @todo actual texture surface not supported */
{
}
break;
default:
break;
}
if (pSurface->pMipmapLevels)
{
{
{
}
}
}
}
else
return VINF_SUCCESS;
}
int vmsvga3dSurfaceCopy(PVGASTATE pThis, SVGA3dSurfaceImageId dest, SVGA3dSurfaceImageId src, uint32_t cCopyBoxes, SVGA3dCopyBox *pBox)
{
int rc = VINF_SUCCESS;
AssertReturn(sidSrc < pState->cSurfaces && pState->paSurface[sidSrc].id == sidSrc, VERR_INVALID_PARAMETER);
AssertReturn(sidDest < pState->cSurfaces && pState->paSurface[sidDest].id == sidDest, VERR_INVALID_PARAMETER);
for (uint32_t i = 0; i < cCopyBoxes; i++)
{
}
return VINF_SUCCESS;
}
/**
* Save texture unpacking parameters and loads those appropriate for the given
* surface.
*
* @param pState The VMSVGA3D state structure.
* @param pContext The active context.
* @param pSurface The surface.
* @param pSave Where to save stuff.
*/
static void vmsvga3dSetUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
{
/*
* Save (ignore errors, setting the defaults we want and avoids restore).
*/
pSave->cSkipPixels = 0;
pSave->cSkipImages = 0;
#endif
/*
* Setup unpack.
*
* Note! We use 1 as alignment here because we currently don't do any
* aligning of line pitches anywhere.
*/
if (pSave->fSwapBytes != 0)
if (pSave->cSkipPixels != 0)
if (pSave->cSkipImages != 0)
#endif
}
/**
* Restores texture unpacking parameters.
*
* @param pState The VMSVGA3D state structure.
* @param pContext The active context.
* @param pSurface The surface.
* @param pSave Where stuff was saved.
*/
static void vmsvga3dRestoreUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
{
if (pSave->fSwapBytes != 0)
if (pSave->cSkipPixels != 0)
VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS, pSave->cSkipPixels), pState, pContext);
if (pSave->cSkipImages != 0)
VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_SKIP_IMAGES, pSave->cSkipImages), pState, pContext);
#endif
}
/* Create D3D texture object for the specified surface. */
static int vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext,
{
GLint activeTexture = 0;
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
/* @todo Set the mip map generation filter settings. */
/* Must bind texture to the current context in order to change it. */
/* Set the unpacking parameters. */
{
Log(("vmsvga3dCreateTexture: sync dirty texture\n"));
{
/* Paranoia: Always do level 0 here to mirror the non-dirty case. */
{
Log(("vmsvga3dCreateTexture: sync dirty texture mipmap level %d (pitch %x)\n", i, pSurface->pMipmapLevels[i].cbSurfacePitch));
i,
0,
}
}
}
else
{
/* Allocate and initialize texture memory. Passing the zero filled pSurfaceData avoids
exposing random host memory to the guest and helps a with the fedora 21 surface
corruption issues (launchpad, background, search field, login). */
0,
0,
}
/* Restore unpacking parameters. */
/* Restore the old active texture. */
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
return VINF_SUCCESS;
}
{
int rc = VINF_SUCCESS;
AssertReturn(sidSrc < pState->cSurfaces && pState->paSurface[sidSrc].id == sidSrc, VERR_INVALID_PARAMETER);
AssertReturn(sidDest < pState->cSurfaces && pState->paSurface[sidDest].id == sidDest, VERR_INVALID_PARAMETER);
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
Log(("vmsvga3dSurfaceStretchBlt: src sid=%x (%d,%d)(%d,%d) dest sid=%x (%d,%d)(%d,%d) mode=%x\n",
#else
Log(("vmsvga3dSurfaceStretchBlt: src sid=%x cid=%x (%d,%d)(%d,%d) dest sid=%x cid=%x (%d,%d)(%d,%d) mode=%x\n",
src.sid, pSurfaceSrc->idAssociatedContext, srcBox.x, srcBox.y, srcBox.x + srcBox.w, srcBox.y + srcBox.h,
dest.sid, pSurfaceDest->idAssociatedContext, destBox.x, destBox.y, destBox.x + destBox.w, destBox.y + destBox.h, mode));
/* @todo stricter checks for associated context */
if (cid == SVGA3D_INVALID_ID)
{
Log(("vmsvga3dSurfaceStretchBlt invalid context id!\n"));
}
#endif
{
/* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
Log(("vmsvga3dSurfaceStretchBlt: unknown src surface id=%x type=%d format=%d -> create texture\n", sidSrc, pSurfaceSrc->flags, pSurfaceSrc->format));
}
{
/* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
Log(("vmsvga3dSurfaceStretchBlt: unknown dest surface id=%x type=%d format=%d -> create texture\n", sidDest, pSurfaceDest->flags, pSurfaceDest->format));
}
/* Activate the read and draw framebuffer objects. */
/* Bind the source and destination objects to the right place. */
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
#else
srcBox.y,
#endif
#ifdef MANUAL_FLIP_SURFACE_DATA
#else
#endif
destBox.x,
#ifdef MANUAL_FLIP_SURFACE_DATA
#else
destBox.y,
#endif
#ifdef MANUAL_FLIP_SURFACE_DATA
#else
#endif
/* Reset the frame buffer association */
return VINF_SUCCESS;
}
/**
* Save texture packing parameters and loads those appropriate for the given
* surface.
*
* @param pState The VMSVGA3D state structure.
* @param pContext The active context.
* @param pSurface The surface.
* @param pSave Where to save stuff.
*/
static void vmsvga3dSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
{
/*
* Save (ignore errors, setting the defaults we want and avoids restore).
*/
pSave->cSkipPixels = 0;
pSave->cSkipImages = 0;
#endif
/*
* Setup unpack.
*
* Note! We use 1 as alignment here because we currently don't do any
* aligning of line pitches anywhere.
*/
if (pSave->fSwapBytes != 0)
if (pSave->cSkipPixels != 0)
if (pSave->cSkipImages != 0)
#endif
}
/**
* Restores texture packing parameters.
*
* @param pState The VMSVGA3D state structure.
* @param pContext The active context.
* @param pSurface The surface.
* @param pSave Where stuff was saved.
*/
static void vmsvga3dRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
{
if (pSave->fSwapBytes != 0)
if (pSave->cSkipPixels != 0)
if (pSave->cSkipImages != 0)
#endif
}
int vmsvga3dSurfaceDMA(PVGASTATE pThis, SVGA3dGuestImage guest, SVGA3dSurfaceImageId host, SVGA3dTransferType transfer,
{
int rc = VINF_SUCCESS;
Log(("vmsvga3dSurfaceDMA TEXTURE guestptr gmr=%x offset=%x pitch=%x host sid=%x face=%d mipmap=%d transfer=%s cCopyBoxes=%d\n", guest.ptr.gmrId, guest.ptr.offset, guest.pitch, host.sid, host.face, host.mipmap, (transfer == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", cCopyBoxes));
else
Log(("vmsvga3dSurfaceDMA guestptr gmr=%x offset=%x pitch=%x host sid=%x face=%d mipmap=%d transfer=%s cCopyBoxes=%d\n", guest.ptr.gmrId, guest.ptr.offset, guest.pitch, host.sid, host.face, host.mipmap, (transfer == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", 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));
/* Apparently we're supposed to clip it (gmr test sample) */
if ( !pBoxes[i].w
|| !pBoxes[i].h
|| !pBoxes[i].d
{
Log(("Empty box; skip\n"));
continue;
}
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
#else
#endif
#ifdef MANUAL_FLIP_SURFACE_DATA
#else
#endif
}
}
else
{
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#else
/* @todo stricter checks for associated context */
{
Log(("vmsvga3dSurfaceDMA invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->paContext[cid].id));
}
#endif
for (unsigned i = 0; i < cCopyBoxes; i++)
{
bool fVertex = false;
unsigned cbSrcPitch;
/* Apparently we're supposed to clip it (gmr test sample) */
if ( !pBoxes[i].w
|| !pBoxes[i].h
{
Log(("Empty box; skip\n"));
continue;
}
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;
if (transfer == SVGA3D_READ_HOST_VRAM)
{
/* Must bind texture to the current context in order to read it. */
/* Set row length and alignment of the input data. */
/* Restore the old active texture. */
AssertReturnStmt( uDestOffset + pBoxes[i].w * pSurface->cbBlock + (pBoxes[i].h - 1) * pMipLevel->cbSurfacePitch
#ifdef MANUAL_FLIP_SURFACE_DATA
- cbSurfacePitch; /* flip image during copy */
#else
#endif
}
else
{
#ifdef MANUAL_FLIP_SURFACE_DATA
pBufferStart = pDoubleBuffer + cbSurfacePitch * pBoxes[i].h - cbSurfacePitch; /* flip image during copy */
#else
#endif
}
#ifdef MANUAL_FLIP_SURFACE_DATA
#else
#endif
pBoxes[i].h);
/* Update the opengl surface data. */
if (transfer == SVGA3D_WRITE_HOST_VRAM)
{
GLint activeTexture = 0;
/* Must bind texture to the current context in order to change it. */
Log(("vmsvga3dSurfaceDMA: copy texture mipmap level %d (pitch %x)\n", host.mipmap, pMipLevel->cbSurfacePitch));
/* Set row length and alignment of the input data. */
vmsvga3dSetUnpackParams(pState, pContext, pSurface, &SavedParams); /** @todo do we need to set ROW_LENGTH to w here? */
pBoxes[i].x,
pBoxes[i].y,
pBoxes[i].w,
pBoxes[i].h,
/* Restore old values. */
/* Restore the old active texture. */
}
/* Free the double buffer. */
break;
}
AssertFailed(); /* @todo */
break;
{
{
{
#if defined(VBOX_STRICT) && defined(RT_OS_DARWIN)
# ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
("cbStrictBufSize=%#x cbSurface=%#x pContext->id=%#x\n", (uint32_t)cbStrictBufSize, pMipLevel->cbSurface, pContext->id));
# else
("cbStrictBufSize=%#x cbSurface=%#x isAssociatedContext=%#x pContext->id=%#x\n", (uint32_t)cbStrictBufSize, pMipLevel->cbSurface, pSurface->idAssociatedContext, pContext->id));
# endif
#endif
if (RT_LIKELY( offDst + pBoxes[i].w * pSurface->cbBlock + (pBoxes[i].h - 1) * pMipLevel->cbSurfacePitch
{
pBoxes[i].h);
}
else
{
AssertFailed();
}
}
else
VMSVGA3D_GL_GET_AND_COMPLAIN(pState, pContext, ("glMapBuffer(GL_ARRAY_BUFFER, %#x) -> NULL\n", enmGlTransfer));
}
else
VMSVGA3D_GL_COMPLAIN(pState, pContext, ("glBindBuffer(GL_ARRAY_BUFFER, %#x)\n", pSurface->oglId.buffer));
break;
}
default:
AssertFailed();
break;
}
}
}
return rc;
}
int vmsvga3dSurfaceBlitToScreen(PVGASTATE pThis, uint32_t dest, SVGASignedRect destRect, SVGA3dSurfaceImageId src, SVGASignedRect srcRect, uint32_t cRects, SVGASignedRect *pRect)
{
/* Requires SVGA_FIFO_CAP_SCREEN_OBJECT support */
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));
}
/* @todo Only screen 0 for now. */
/* @todo scaling */
AssertReturn(destRect.right - destRect.left == srcRect.right - srcRect.left && destRect.bottom - destRect.top == srcRect.bottom - srcRect.top, VERR_INVALID_PARAMETER);
if (cRects == 0)
{
/* easy case; no clipping */
box.z = 0;
box.d = 1;
return VINF_SUCCESS;
}
else
{
box.z = 0;
box.d = 1;
/* @todo merge into one SurfaceDMA call */
{
/* The clipping rectangle is relative to the top-left corner of srcRect & destRect. Adjust here. */
box.z = 0;
}
return VINF_SUCCESS;
}
}
{
int rc = VINF_SUCCESS;
GLint activeTexture = 0;
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#else
/* @todo stricter checks for associated context */
{
Log(("vmsvga3dGenerateMipmaps invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
#endif
{
/* Unknown surface type; turn it into a texture. */
Log(("vmsvga3dGenerateMipmaps: unknown src surface id=%x type=%d format=%d -> create texture\n", sid, pSurface->flags, pSurface->format));
}
else
{
/* @todo new filter */
AssertFailed();
}
/* Must bind texture to the current context in order to change it. */
/* Generate the mip maps. */
/* Restore the old texture. */
return VINF_SUCCESS;
}
{
int rc = VINF_SUCCESS;
struct
{
uint32_t x;
uint32_t y;
} srcViewPort;
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
/* @todo stricter checks for associated context */
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));
#else
/* @todo stricter checks for associated context */
{
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));
}
{
Log(("vmsvga3dCommandPresent invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
#endif
/* Source surface different size? */
{
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)));
}
else
{
}
#if 1
/* @note this path is slightly faster than the glBlitFrameBuffer path below. */
if (cRects == 0)
{
cRects = 1;
}
//glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT);
#if 0
#endif
/* Flush shader changes. */
if (pContext->pShaderContext)
/* Activate the read and draw framebuffer objects. */
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
/* Reset the transformation matrices. */
glPushMatrix();
glPushMatrix();
{
{
/* Intersection is empty; skip */
continue;
}
vertexLeft = pRect[i].x;
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)));
/* bottom left */
/* top left */
/* top right */
/* bottom right */
glEnd();
}
/* Restore old settings. */
glPopMatrix();
glPopMatrix();
//glPopAttrib();
/* Reset the frame buffer association */
#else
/* Activate the read and draw framebuffer objects. */
/* Bind the source objects to the right place. */
pState->ext.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pSurface->oglId.texture, 0 /* level 0 */);
/* Blit the surface rectangle(s) to the back buffer. */
if (cRects == 0)
{
srcViewPort.y,
0,
0,
}
else
{
{
{
/* Intersection is empty; skip */
continue;
}
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. */
}
}
/* Reset the frame buffer association */
#endif
/* Flip the front and back buffers. */
#ifdef RT_OS_WINDOWS
#elif defined(RT_OS_DARWIN)
#else
/* show the window if not already done */
{
}
/* now swap the buffers, i.e. display the rendering result */
#endif
return VINF_SUCCESS;
}
#ifdef RT_OS_LINUX
/**
* X11 event handling thread
* @param ThreadSelf thread handle
* @param pvUser pointer to pState structure
* @returns VBox status code
*/
{
while (!pState->bTerminate)
{
{
{
default:
break;
}
}
/* sleep for 16ms to not burn too many cycles */
RTThreadSleep(16);
}
return VINF_SUCCESS;
}
#endif // RT_OS_LINUX
/**
* Create a new 3d context
*
* @returns VBox status code.
* @param pThis VGA device instance data.
* @param cid Context id
* @param fFlags VMSVGA3D_DEF_CTX_F_XXX.
*/
{
int rc;
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
|| (cid == VMSVGA3D_SHARED_CTX_ID && (fFlags & VMSVGA3D_DEF_CTX_F_SHARED_CTX)), VERR_INVALID_PARAMETER);
#else
#endif
#if !defined(VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE) || !(defined(RT_OS_DARWIN))
#endif
{
}
#endif
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
if (cid == VMSVGA3D_SHARED_CTX_ID)
else
#endif
{
{
pState->paContext = (PVMSVGA3DCONTEXT)RTMemRealloc(pState->paContext, sizeof(VMSVGA3DCONTEXT) * (cid + 1));
memset(&pState->paContext[pState->cContexts], 0, sizeof(VMSVGA3DCONTEXT) * (cid + 1 - pState->cContexts));
}
/* If one already exists with this id, then destroy it now. */
}
/*
* Find the shared context (necessary for sharing e.g. textures between contexts).
*/
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
{
{
}
}
#else
// TODO isn't this default on Linux since OpenGL 1.1?
/* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
&& i != cid
# endif
)
{
break;
}
#endif
/*
* Initialize the context.
*/
#ifdef RT_OS_WINDOWS
/* Create a context window. */
# ifdef DEBUG_GFX_WINDOW
# else
# endif
# ifdef DEBUG_GFX_WINDOW
# else
# endif
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);
sizeof(PIXELFORMATDESCRIPTOR), /* size of this pfd */
1, /* version number */
PFD_DRAW_TO_WINDOW | /* support window */
PFD_DOUBLEBUFFER | /* support double buffering */
PFD_SUPPORT_OPENGL, /* support OpenGL */
PFD_TYPE_RGBA, /* RGBA type */
24, /* 24-bit color depth */
0, 0, 0, 0, 0, 0, /* color bits ignored */
8, /* alpha buffer */
0, /* shift bit ignored */
0, /* no accumulation buffer */
0, 0, 0, 0, /* accum bits ignored */
16, /* set depth buffer */
16, /* set stencil buffer */
0, /* no auxiliary buffer */
PFD_MAIN_PLANE, /* main layer */
0, /* reserved */
0, 0, 0 /* layer masks ignored */
};
int pixelFormat;
/* @todo is this really necessary?? */
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);
if (pSharedCtx)
{
AssertMsg(ret == TRUE, ("wglShareLists(%p, %p) failed with %d\n", pSharedCtx->hglrc, pContext->hglrc, GetLastError()));
}
#elif defined(RT_OS_DARWIN)
#else
{
/* get an X display and make sure we have glX 1.3 */
AssertMsgReturn(ret && glxMajor == 1 && glxMinor >= 3, ("glX >=1.3 not present"), VERR_INTERNAL_ERROR);
/* start our X event handling thread */
rc = RTThreadCreate(&pState->pWindowThread, vmsvga3dXEventThread, pState, 0, RTTHREADTYPE_GUI, RTTHREADFLAGS_WAITABLE, "VMSVGA3DXEVENT");
if (RT_FAILURE(rc))
{
AssertMsgFailed(("%s: Async IO Thread creation for 3d window handling failed rc=%d\n", __FUNCTION__, rc));
return rc;
}
}
int attrib[] =
{
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
//GLX_ALPHA_SIZE, 1, this flips the bbos screen
};
swa.colormap = XCreateColormap(pState->display, XDefaultRootWindow(pState->display), vi->visual, AllocNone);
swa.border_pixel = 0;
swa.background_pixel = 0;
pContext->window = XCreateWindow(pState->display, hostWindow,//XDefaultRootWindow(pState->display),//hostWindow,
/* the window is hidden by default and only mapped when CommandPresent is executed on it */
#endif
/* NULL during the first PowerOn call. */
{
/* Create a framebuffer object for this context. */
/* Bind the object to the framebuffer target. */
/* Create read and draw framebuffer objects for this context. */
}
#if 0
/* @todo move to shader lib!!! */
/* Clear the screen */
glClearIndex(0);
glClearDepth(1);
glClearStencil(0xffff);
/* @todo move to shader lib!!! */
#endif
return VINF_SUCCESS;
}
/**
* Create a new 3d context
*
* @returns VBox status code.
* @param pThis VGA device instance data.
* @param cid Context id
*/
{
}
/**
* Destroy an existing 3d context
*
* @returns VBox status code.
* @param pThis VGA device instance data.
* @param cid Context id
*/
{
{
/* Destroy all leftover pixel shaders. */
{
vmsvga3dShaderDestroy(pThis, pContext->paPixelShader[i].cid, pContext->paPixelShader[i].id, pContext->paPixelShader[i].type);
}
if (pContext->paPixelShader)
/* Destroy all leftover vertex shaders. */
{
vmsvga3dShaderDestroy(pThis, pContext->paVertexShader[i].cid, pContext->paVertexShader[i].id, pContext->paVertexShader[i].type);
}
if (pContext->paVertexShader)
if (pContext->pShaderContext)
{
}
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX /* This is done on windows - prevents various assertions at runtime, as well as shutdown & reset assertions when destroying surfaces. */
/* Check for all surfaces that are associated with this context to remove all dependencies */
{
{
int rc;
pMipLevelSize = (SVGA3dSize *)RTMemAllocZ(pSurface->faces[0].numMipLevels * pSurface->cFaces * sizeof(SVGA3dSize));
{
{
}
}
/* Recreate the surface with the original settings; destroys the contents, but that seems fairly safe since the context is also destroyed. */
rc = vmsvga3dSurfaceDefine(pThis, sid, surfaceFlags, format, face, multisampleCount, autogenFilter, face[0].numMipLevels * cFaces, pMipLevelSize);
}
}
#endif
{
/* Unbind the object from the framebuffer target. */
{
}
{
}
}
#ifdef RT_OS_WINDOWS
/* Destroy the window we've created. */
int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_DESTROYWINDOW, (WPARAM)pContext->hwnd, 0);
#elif defined(RT_OS_DARWIN)
#elif defined(RT_OS_LINUX)
#endif
}
else
AssertFailed();
return VINF_SUCCESS;
}
/* Handle resize */
{
/* Resize all active contexts. */
{
if (cid != SVGA3D_INVALID_ID)
{
#ifdef RT_OS_WINDOWS
/* Resize the window. */
int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_RESIZEWINDOW, (WPARAM)pContext->hwnd, (LPARAM)&cs);
#elif defined(RT_OS_DARWIN)
#elif defined(RT_OS_LINUX)
#endif
}
}
return VINF_SUCCESS;
}
{
bool fModelViewChanged = false;
{
Log(("vmsvga3dSetTransform invalid context id!\n"));
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:
/* View * World = Model View */
fModelViewChanged = true;
break;
{
int rc = ShaderTransformProjection(pContext->state.RectViewPort.w, pContext->state.RectViewPort.h, matrix);
break;
}
break;
Log(("vmsvga3dSetTransform: unsupported SVGA3D_TRANSFORM_TEXTUREx transform!!\n"));
return VERR_INVALID_PARAMETER;
case SVGA3D_TRANSFORM_WORLD:
/* View * World = Model View */
else
fModelViewChanged = true;
break;
case SVGA3D_TRANSFORM_WORLD1:
case SVGA3D_TRANSFORM_WORLD2:
case SVGA3D_TRANSFORM_WORLD3:
Log(("vmsvga3dSetTransform: unsupported SVGA3D_TRANSFORM_WORLDx transform!!\n"));
return VERR_INVALID_PARAMETER;
default:
Log(("vmsvga3dSetTransform: unknown type!!\n"));
return VERR_INVALID_PARAMETER;
}
/* Apparently we need to reset the light and clip data after modifying the modelview matrix. */
if (fModelViewChanged)
{
/* Reprogram the clip planes. */
{
}
/* Reprogram the light data. */
{
}
}
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)));
{
Log(("vmsvga3dSetZRange invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
return VINF_SUCCESS;
}
/**
* Convert SVGA blend op value to its OpenGL equivalent
*/
{
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;
return GL_CONSTANT_ALPHA; /* @todo correct?? */
return GL_ONE_MINUS_CONSTANT_ALPHA; /* @todo correct?? */
default:
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;
default:
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;
default:
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;
default:
AssertFailed();
return GL_KEEP;
}
}
int vmsvga3dSetRenderState(PVGASTATE pThis, uint32_t cid, uint32_t cRenderStates, SVGA3dRenderState *pRenderState)
{
{
Log(("vmsvga3dSetRenderState invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
for (unsigned i = 0; i < cRenderStates; i++)
{
Log(("vmsvga3dSetRenderState: cid=%x state=%s (%d) val=%x\n", cid, vmsvga3dGetRenderStateName(pRenderState[i].state), pRenderState[i].state, pRenderState[i].uintValue));
/* Save the render state for vm state saving. */
switch (pRenderState[i].state)
{
case SVGA3D_RS_ZENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_ZWRITEENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_ALPHATESTENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_DITHERENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_FOGENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_SPECULARENABLE: /* SVGA3dBool */
Log(("vmsvga3dSetRenderState: WARNING: not applicable.\n"));
break;
case SVGA3D_RS_LIGHTINGENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_NORMALIZENORMALS: /* SVGA3dBool */
/* not applicable */
Log(("vmsvga3dSetRenderState: WARNING: not applicable.\n"));
break;
case SVGA3D_RS_POINTSPRITEENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_POINTSIZE: /* float */
/* @todo we need to apply scaling for point sizes below the min or above the max; see Wine) */
break;
case SVGA3D_RS_POINTSIZEMIN: /* float */
break;
case SVGA3D_RS_POINTSIZEMAX: /* float */
break;
case SVGA3D_RS_POINTSCALEENABLE: /* SVGA3dBool */
case SVGA3D_RS_POINTSCALE_A: /* float */
case SVGA3D_RS_POINTSCALE_B: /* float */
case SVGA3D_RS_POINTSCALE_C: /* float */
Log(("vmsvga3dSetRenderState: WARNING: not applicable.\n"));
break;
case SVGA3D_RS_AMBIENT: /* SVGA3dColor */
{
break;
}
case SVGA3D_RS_CLIPPLANEENABLE: /* SVGA3dClipPlanes */
{
for (uint32_t j = 0; j <= 5; j++)
{
glEnable(GL_CLIP_PLANE0 + j);
else
glDisable(GL_CLIP_PLANE0 + j);
}
break;
}
case SVGA3D_RS_FOGCOLOR: /* SVGA3dColor */
{
break;
}
case SVGA3D_RS_FOGSTART: /* float */
break;
case SVGA3D_RS_FOGEND: /* float */
break;
case SVGA3D_RS_FOGDENSITY: /* float */
break;
case SVGA3D_RS_RANGEFOGENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_FOGMODE: /* SVGA3dFogMode */
{
{
case SVGA3D_FOGFUNC_EXP:
break;
case SVGA3D_FOGFUNC_EXP2:
break;
case SVGA3D_FOGFUNC_LINEAR:
break;
default:
break;
}
/* @todo how to switch between vertex and pixel fog modes??? */
#if 0
/* The fog type determines the render state. */
{
case SVGA3D_FOGTYPE_VERTEX:
break;
case SVGA3D_FOGTYPE_PIXEL:
break;
default:
break;
}
#endif
/* Set the fog base to depth or range. */
{
break;
break;
default:
/* ignore */
break;
}
break;
}
case SVGA3D_RS_FILLMODE: /* SVGA3dFillMode */
{
{
case SVGA3D_FILLMODE_POINT:
break;
case SVGA3D_FILLMODE_LINE:
break;
case SVGA3D_FILLMODE_FILL:
break;
default:
break;
}
/* @note only front and back faces */
break;
}
case SVGA3D_RS_SHADEMODE: /* SVGA3dShadeMode */
switch (pRenderState[i].uintValue)
{
case SVGA3D_SHADEMODE_FLAT:
break;
case SVGA3D_SHADEMODE_SMOOTH:
break;
default:
AssertMsgFailedReturn(("Unexpected shade mode %d\n", pRenderState[i].uintValue), VERR_INTERNAL_ERROR);
break;
}
break;
case SVGA3D_RS_LINEPATTERN: /* SVGA3dLinePattern */
/* No longer supported by d3d; mesagl comments suggest not all backends support it */
/* @todo */
/*
renderState = D3DRS_LINEPATTERN;
val = pRenderState[i].uintValue;
*/
break;
case SVGA3D_RS_LINEAA: /* SVGA3dBool */
break;
case SVGA3D_RS_LINEWIDTH: /* float */
break;
case SVGA3D_RS_SEPARATEALPHABLENDENABLE: /* SVGA3dBool */
{
/* Refresh the blending state based on the new enable setting. */
continue; /* ignore if blend is already enabled */
/* no break */
}
case SVGA3D_RS_BLENDENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_SRCBLENDALPHA: /* SVGA3dBlendOp */
case SVGA3D_RS_DSTBLENDALPHA: /* SVGA3dBlendOp */
case SVGA3D_RS_SRCBLEND: /* SVGA3dBlendOp */
case SVGA3D_RS_DSTBLEND: /* SVGA3dBlendOp */
{
switch (pRenderState[i].state)
{
case SVGA3D_RS_SRCBLEND:
break;
case SVGA3D_RS_DSTBLEND:
break;
case SVGA3D_RS_SRCBLENDALPHA:
break;
case SVGA3D_RS_DSTBLENDALPHA:
break;
default:
/* not possible; shut up gcc */
AssertFailed();
break;
}
else
break;
}
case SVGA3D_RS_BLENDEQUATIONALPHA: /* SVGA3dBlendEquation */
case SVGA3D_RS_BLENDEQUATION: /* SVGA3dBlendEquation */
pState->ext.glBlendEquationSeparate(vmsvga3dBlendEquation2GL(pContext->state.aRenderState[SVGA3D_RS_BLENDEQUATION].uintValue),
else
{
#if VBOX_VMSVGA3D_GL_HACK_LEVEL >= 0x102
#else
#endif
}
break;
case SVGA3D_RS_BLENDCOLOR: /* SVGA3dColor */
{
#if VBOX_VMSVGA3D_GL_HACK_LEVEL >= 0x102
#else
#endif
break;
}
case SVGA3D_RS_CULLMODE: /* SVGA3dFace */
{
switch (pRenderState[i].uintValue)
{
case SVGA3D_FACE_NONE:
break;
case SVGA3D_FACE_FRONT:
break;
case SVGA3D_FACE_BACK:
break;
case SVGA3D_FACE_FRONT_BACK:
break;
default:
AssertMsgFailedReturn(("Unexpected cull mode %d\n", pRenderState[i].uintValue), VERR_INTERNAL_ERROR);
break;
}
{
val = 1;
}
else
val = 0;
break;
}
case SVGA3D_RS_ZFUNC: /* SVGA3dCmpFunc */
break;
case SVGA3D_RS_ALPHAFUNC: /* SVGA3dCmpFunc */
{
break;
}
case SVGA3D_RS_ALPHAREF: /* float (0.0 .. 1.0) */
{
break;
}
case SVGA3D_RS_STENCILENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_STENCILFUNC: /* SVGA3dCmpFunc */
case SVGA3D_RS_STENCILREF: /* uint32_t */
case SVGA3D_RS_STENCILMASK: /* uint32_t */
{
switch (pRenderState[i].state)
{
case SVGA3D_RS_STENCILFUNC: /* SVGA3dCmpFunc */
break;
case SVGA3D_RS_STENCILREF: /* uint32_t */
break;
case SVGA3D_RS_STENCILMASK: /* uint32_t */
break;
default:
/* not possible; shut up gcc */
AssertFailed();
break;
}
break;
}
case SVGA3D_RS_STENCILWRITEMASK: /* uint32_t */
break;
case SVGA3D_RS_STENCILFAIL: /* SVGA3dStencilOp */
case SVGA3D_RS_STENCILZFAIL: /* SVGA3dStencilOp */
case SVGA3D_RS_STENCILPASS: /* SVGA3dStencilOp */
{
switch (pRenderState[i].state)
{
case SVGA3D_RS_STENCILFAIL: /* SVGA3dStencilOp */
break;
case SVGA3D_RS_STENCILZFAIL: /* SVGA3dStencilOp */
break;
case SVGA3D_RS_STENCILPASS: /* SVGA3dStencilOp */
break;
default:
/* not possible; shut up gcc */
AssertFailed();
break;
}
break;
}
case SVGA3D_RS_STENCILENABLE2SIDED: /* SVGA3dBool */
/* @note GL_EXT_stencil_two_side required! */
{
}
else
Log(("vmsvga3dSetRenderState: WARNING unsupported SVGA3D_RS_STENCILENABLE2SIDED\n"));
break;
case SVGA3D_RS_CCWSTENCILFUNC: /* SVGA3dCmpFunc */
{
/* @todo SVGA3D_RS_STENCILFAIL/ZFAIL/PASS for front & back faces
* SVGA3D_RS_CCWSTENCILFAIL/ZFAIL/PASS for back faces ??
*/
break;
}
case SVGA3D_RS_CCWSTENCILFAIL: /* SVGA3dStencilOp */
case SVGA3D_RS_CCWSTENCILZFAIL: /* SVGA3dStencilOp */
case SVGA3D_RS_CCWSTENCILPASS: /* SVGA3dStencilOp */
{
/* @todo SVGA3D_RS_STENCILFAIL/ZFAIL/PASS for front & back faces
* SVGA3D_RS_CCWSTENCILFAIL/ZFAIL/PASS for back faces ??
*/
switch (pRenderState[i].state)
{
case SVGA3D_RS_CCWSTENCILFAIL: /* SVGA3dStencilOp */
break;
case SVGA3D_RS_CCWSTENCILZFAIL: /* SVGA3dStencilOp */
break;
case SVGA3D_RS_CCWSTENCILPASS: /* SVGA3dStencilOp */
break;
default:
/* not possible; shut up gcc */
AssertFailed();
break;
}
break;
}
case SVGA3D_RS_ZBIAS: /* float */
/* @todo unknown meaning; depth bias is not identical
renderState = D3DRS_DEPTHBIAS;
val = pRenderState[i].uintValue;
*/
Log(("vmsvga3dSetRenderState: WARNING unsupported SVGA3D_RS_ZBIAS\n"));
break;
case SVGA3D_RS_DEPTHBIAS: /* float */
{
/* @todo not sure if the d3d & ogl definitions are identical. */
/* Do not change the factor part. */
break;
}
case SVGA3D_RS_SLOPESCALEDEPTHBIAS: /* float */
{
/* @todo not sure if the d3d & ogl definitions are identical. */
/* Do not change the factor part. */
break;
}
case SVGA3D_RS_COLORWRITEENABLE: /* SVGA3dColorMask */
{
break;
}
case SVGA3D_RS_COLORWRITEENABLE1: /* SVGA3dColorMask to D3DCOLORWRITEENABLE_* */
case SVGA3D_RS_COLORWRITEENABLE2: /* SVGA3dColorMask to D3DCOLORWRITEENABLE_* */
case SVGA3D_RS_COLORWRITEENABLE3: /* SVGA3dColorMask to D3DCOLORWRITEENABLE_* */
Log(("vmsvga3dSetRenderState: WARNING SVGA3D_RS_COLORWRITEENABLEx not supported!!\n"));
break;
case SVGA3D_RS_SCISSORTESTENABLE: /* SVGA3dBool */
break;
#if 0
case SVGA3D_RS_DIFFUSEMATERIALSOURCE: /* SVGA3dVertexMaterial */
break;
case SVGA3D_RS_SPECULARMATERIALSOURCE: /* SVGA3dVertexMaterial */
break;
case SVGA3D_RS_AMBIENTMATERIALSOURCE: /* SVGA3dVertexMaterial */
break;
case SVGA3D_RS_EMISSIVEMATERIALSOURCE: /* SVGA3dVertexMaterial */
break;
#endif
case SVGA3D_RS_WRAP3: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP4: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP5: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP6: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP7: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP8: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP9: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP10: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP11: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP12: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP13: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP14: /* SVGA3dWrapFlags */
case SVGA3D_RS_WRAP15: /* SVGA3dWrapFlags */
Log(("vmsvga3dSetRenderState: WARNING unsupported SVGA3D_WRAPx (x >= 3)\n"));
break;
case SVGA3D_RS_LASTPIXEL: /* SVGA3dBool */
case SVGA3D_RS_TWEENFACTOR: /* float */
case SVGA3D_RS_INDEXEDVERTEXBLENDENABLE: /* SVGA3dBool */
case SVGA3D_RS_VERTEXBLEND: /* SVGA3dVertexBlendFlags */
Log(("vmsvga3dSetRenderState: WARNING not applicable!!\n"));
break;
case SVGA3D_RS_MULTISAMPLEANTIALIAS: /* SVGA3dBool */
break;
case SVGA3D_RS_MULTISAMPLEMASK: /* uint32_t */
case SVGA3D_RS_ANTIALIASEDLINEENABLE: /* SVGA3dBool */
Log(("vmsvga3dSetRenderState: WARNING not applicable??!!\n"));
break;
case SVGA3D_RS_COORDINATETYPE: /* SVGA3dCoordinateType */
/* @todo setup a view matrix to scale the world space by -1 in the z-direction for right handed coordinates. */
/*
renderState = D3DRS_COORDINATETYPE;
val = pRenderState[i].uintValue;
*/
break;
case SVGA3D_RS_FRONTWINDING: /* SVGA3dFrontWinding */
/* Invert the selected mode because of y-inversion (?) */
break;
case SVGA3D_RS_OUTPUTGAMMA: /* float */
//AssertFailed();
/*
D3DRS_SRGBWRITEENABLE ??
renderState = D3DRS_OUTPUTGAMMA;
val = pRenderState[i].uintValue;
*/
break;
#if 0
case SVGA3D_RS_VERTEXMATERIALENABLE: /* SVGA3dBool */
//AssertFailed();
break;
case SVGA3D_RS_TEXTUREFACTOR: /* SVGA3dColor */
break;
case SVGA3D_RS_LOCALVIEWER: /* SVGA3dBool */
break;
case SVGA3D_RS_ZVISIBLE: /* SVGA3dBool */
AssertFailed();
/*
renderState = D3DRS_ZVISIBLE;
val = pRenderState[i].uintValue;
*/
break;
case SVGA3D_RS_CLIPPING: /* SVGA3dBool */
break;
case SVGA3D_RS_WRAP0: /* SVGA3dWrapFlags */
break;
case SVGA3D_RS_WRAP1: /* SVGA3dWrapFlags */
break;
case SVGA3D_RS_WRAP2: /* SVGA3dWrapFlags */
break;
case SVGA3D_RS_SEPARATEALPHABLENDENABLE: /* SVGA3dBool */
break;
case SVGA3D_RS_BLENDEQUATIONALPHA: /* SVGA3dBlendEquation */
break;
case SVGA3D_RS_TRANSPARENCYANTIALIAS: /* SVGA3dTransparencyAntialiasType */
AssertFailed();
/*
renderState = D3DRS_TRANSPARENCYANTIALIAS;
val = pRenderState[i].uintValue;
*/
break;
#endif
default:
AssertFailed();
break;
}
if (enableCap != ~0U)
{
if (val)
else
}
}
return VINF_SUCCESS;
}
int vmsvga3dSetRenderTarget(PVGASTATE pThis, uint32_t cid, SVGA3dRenderTargetType type, SVGA3dSurfaceImageId target)
{
{
Log(("vmsvga3dSetRenderTarget invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
{
/* Disable render target. */
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);
break;
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);
break;
default:
}
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));
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#else
LogFlow(("vmsvga3dSetRenderTarget: sid=%x idAssociatedContext %#x -> %#x\n", pRenderTarget->id, pRenderTarget->idAssociatedContext, cid));
#endif
}
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
else
#endif
{
}
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
break;
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:
{
/* A texture surface can be used as a render target to fill it and later on used as a texture. */
{
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
if (status != GL_FRAMEBUFFER_COMPLETE)
#endif
/* @todo use glDrawBuffers too? */
break;
}
default:
}
return VINF_SUCCESS;
}
#if 0
/**
* Convert SVGA texture combiner value to its D3D equivalent
*/
{
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:
AssertFailed(); /* @todo ??? */
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;
default:
AssertFailed();
return D3DTOP_DISABLE;
}
}
/**
* Convert SVGA texture arg data value to its D3D equivalent
*/
{
switch (value)
{
case SVGA3D_TA_CONSTANT:
return D3DTA_CONSTANT;
case SVGA3D_TA_PREVIOUS:
return D3DTA_CURRENT; /* current = previous */
case SVGA3D_TA_DIFFUSE:
return D3DTA_DIFFUSE;
case SVGA3D_TA_TEXTURE:
return D3DTA_TEXTURE;
case SVGA3D_TA_SPECULAR:
return D3DTA_SPECULAR;
default:
AssertFailed();
return 0;
}
}
/**
* Convert SVGA texture transform flag value to its D3D equivalent
*/
{
switch (value)
{
case SVGA3D_TEX_TRANSFORM_OFF:
return D3DTTFF_DISABLE;
case SVGA3D_TEX_TRANSFORM_S:
return D3DTTFF_COUNT1; /* @todo correct? */
case SVGA3D_TEX_TRANSFORM_T:
return D3DTTFF_COUNT2; /* @todo correct? */
case SVGA3D_TEX_TRANSFORM_R:
return D3DTTFF_COUNT3; /* @todo correct? */
case SVGA3D_TEX_TRANSFORM_Q:
return D3DTTFF_COUNT4; /* @todo correct? */
case SVGA3D_TEX_PROJECTED:
return D3DTTFF_PROJECTED;
default:
AssertFailed();
return 0;
}
}
#endif
{
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();
return GL_CLAMP_TO_EDGE_SGIS; /* @todo correct? */
case SVGA3D_TEX_ADDRESS_EDGE:
default:
AssertFailed();
return GL_REPEAT; /* default */
}
}
{
switch (value)
{
case SVGA3D_TEX_FILTER_NONE:
case SVGA3D_TEX_FILTER_LINEAR:
return GL_LINEAR;
return GL_NEAREST;
/* @todo */
case SVGA3D_TEX_FILTER_FLATCUBIC: // Deprecated, not implemented
case SVGA3D_TEX_FILTER_GAUSSIANCUBIC: // Deprecated, not implemented
case SVGA3D_TEX_FILTER_PYRAMIDALQUAD: // Not currently implemented
case SVGA3D_TEX_FILTER_GAUSSIANQUAD: // Not currently implemented
default:
AssertFailed();
return GL_LINEAR; /* default */
}
}
{
/* flip the red and blue bytes */
}
int vmsvga3dSetTextureState(PVGASTATE pThis, uint32_t cid, uint32_t cTextureStates, SVGA3dTextureState *pTextureState)
{
GLenum currentStage = ~0L;
{
Log(("vmsvga3dSetTextureState invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
for (unsigned i = 0; i < cTextureStates; i++)
{
GLenum textureType = ~0U;
GLenum samplerType = ~0U;
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));
/* Record the texture state for vm state saving. */
{
}
/* Active the right texture unit for subsequent texture state changes. */
{
}
switch (pTextureState[i].name)
{
case SVGA3D_TS_BUMPENVMAT00: /* float */
case SVGA3D_TS_BUMPENVMAT01: /* float */
case SVGA3D_TS_BUMPENVMAT10: /* float */
case SVGA3D_TS_BUMPENVMAT11: /* float */
case SVGA3D_TS_BUMPENVLSCALE: /* float */
case SVGA3D_TS_BUMPENVLOFFSET: /* float */
Log(("vmsvga3dSetTextureState: bump mapping texture options not supported!!\n"));
break;
case SVGA3D_TS_COLOROP: /* SVGA3dTextureCombiner */
case SVGA3D_TS_COLORARG0: /* SVGA3dTextureArgData */
case SVGA3D_TS_COLORARG1: /* SVGA3dTextureArgData */
case SVGA3D_TS_COLORARG2: /* SVGA3dTextureArgData */
case SVGA3D_TS_ALPHAOP: /* SVGA3dTextureCombiner */
case SVGA3D_TS_ALPHAARG0: /* SVGA3dTextureArgData */
case SVGA3D_TS_ALPHAARG1: /* SVGA3dTextureArgData */
case SVGA3D_TS_ALPHAARG2: /* SVGA3dTextureArgData */
/* @todo; not used by MesaGL */
break;
#if 0
case SVGA3D_TS_TEXCOORDINDEX: /* uint32_t */
break;
case SVGA3D_TS_TEXTURETRANSFORMFLAGS: /* SVGA3dTexTransformFlags */
break;
#endif
case SVGA3D_TS_BIND_TEXTURE: /* SVGA3dSurfaceId */
{
Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture surface id=%x replacing=%x\n",
/* Unselect the currently associated texture. */
/* Necessary for the fixed pipeline. */
}
else
{
Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture surface id=%x (%d,%d) replacing=%x\n",
{
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
Log(("CreateTexture (%d,%d) level=%d\n", pSurface->pMipmapLevels[0].size.width, pSurface->pMipmapLevels[0].size.height, pSurface->faces[0].numMipLevels));
}
/* Necessary for the fixed pipeline. */
{
/* Recreate the texture state as glBindTexture resets them all (sigh). */
{
for (uint32_t j = 0; j < SVGA3D_TS_MAX; j++)
{
}
}
}
}
/* Finished; continue with the next one. */
continue;
case SVGA3D_TS_ADDRESSW: /* SVGA3dTextureAddress */
break;
case SVGA3D_TS_ADDRESSU: /* SVGA3dTextureAddress */
break;
case SVGA3D_TS_ADDRESSV: /* SVGA3dTextureAddress */
break;
case SVGA3D_TS_MIPFILTER: /* SVGA3dTextureFilter */
case SVGA3D_TS_MINFILTER: /* SVGA3dTextureFilter */
{
/* If SVGA3D_TS_MIPFILTER is set to NONE, then use SVGA3D_TS_MIPFILTER, otherwise SVGA3D_TS_MIPFILTER enables mipmap minification. */
if (mipFilter != SVGA3D_TEX_FILTER_NONE)
{
if (minFilter == SVGA3D_TEX_FILTER_NEAREST)
{
if (mipFilter == SVGA3D_TEX_FILTER_LINEAR)
else
}
else
{
if (mipFilter == SVGA3D_TEX_FILTER_LINEAR)
else
}
}
else
break;
}
case SVGA3D_TS_MAGFILTER: /* SVGA3dTextureFilter */
break;
case SVGA3D_TS_BORDERCOLOR: /* SVGA3dColor */
{
glTexParameterfv(GL_TEXTURE_2D /* @todo flexible type */, GL_TEXTURE_BORDER_COLOR, color); /* Identical; default 0.0 identical too */
break;
}
case SVGA3D_TS_TEXTURE_LOD_BIAS: /* float */
glTexParameterf(GL_TEXTURE_2D /* @todo flexible type */, GL_TEXTURE_LOD_BIAS, pTextureState[i].value); /* Identical; default 0.0 identical too */
break;
case SVGA3D_TS_TEXTURE_MIPMAP_LEVEL: /* uint32_t */
break;
#if 0
case SVGA3D_TS_TEXTURE_ANISOTROPIC_LEVEL: /* uint32_t */
break;
case SVGA3D_TS_GAMMA: /* float */
/* Boolean in D3D */
else
break;
#endif
/* Internal commands, that don't map directly to the SetTextureStageState API. */
case SVGA3D_TS_TEXCOORDGEN: /* SVGA3dTextureCoordGen */
AssertFailed();
break;
default:
//AssertFailed();
break;
}
if (textureType != ~0U)
{
}
}
return VINF_SUCCESS;
}
{
{
Log(("vmsvga3dSetMaterial invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
switch (face)
{
case SVGA3D_FACE_NONE:
case SVGA3D_FACE_FRONT:
break;
case SVGA3D_FACE_BACK:
break;
case SVGA3D_FACE_FRONT_BACK:
break;
default:
}
return VINF_SUCCESS;
}
/* @todo Move into separate library as we are using logic from Wine here. */
{
float QuadAttenuation;
{
Log(("vmsvga3dSetLightData invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
if (index < SVGA3D_MAX_LIGHTS)
{
}
else
AssertFailed();
{
Log(("vmsvga3dSetLightData: invalid negative attenuation values!!\n"));
return VINF_SUCCESS; /* ignore; could crash the GL driver */
}
/* Light settings are affected by the model view in OpenGL, the View transform in direct3d */
glPushMatrix();
else
QuadAttenuation = 0.0f;
{
case SVGA3D_LIGHTTYPE_POINT:
{
/* Attenuation - Are these right? guessing... */
glLightf(GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION, (QuadAttenuation < pData->attenuation2) ? pData->attenuation2 : QuadAttenuation);
/* @todo range */
break;
}
case SVGA3D_LIGHTTYPE_SPOT1:
{
/*
* opengl-ish and d3d-ish spot lights use too different models for the
* light "intensity" as a function of the angle towards the main light direction,
* so we only can approximate very roughly.
* however spot lights are rather rarely used in games (if ever used at all).
* furthermore if still used, probably nobody pays attention to such details.
*/
{
/* Falloff = 0 is easy, because d3d's and opengl's spot light equations have the
* falloff resp. exponent parameter as an exponent, so the spot light lighting
* will always be 1.0 for both of them, and we don't have to care for the
* rest of the rather complex calculation
*/
exponent = 0.0f;
}
else
{
if (rho < 0.0001f)
rho = 0.0001f;
}
if (exponent > 128.0f)
exponent = 128.0f;
/* Attenuation - Are these right? guessing... */
glLightf(GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION, (QuadAttenuation < pData->attenuation2) ? pData->attenuation2 : QuadAttenuation);
/* @todo range */
break;
}
{
glLightfv(GL_LIGHT0 + index, GL_POSITION, position); /* Note gl uses w position of 0 for direction! */
break;
}
case SVGA3D_LIGHTTYPE_SPOT2:
default:
Log(("Unsupported light type!!\n"));
return VERR_INVALID_PARAMETER;
}
/* Restore the modelview matrix */
glPopMatrix();
return VINF_SUCCESS;
}
{
{
Log(("vmsvga3dSetLightEnabled invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
if (index < SVGA3D_MAX_LIGHTS)
else
AssertFailed();
if (enabled)
{
/* Load the default settings if none have been set yet. */
}
else
return VINF_SUCCESS;
}
{
{
Log(("vmsvga3dSetViewPort invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
/* @todo y-inversion for partial viewport coordinates? */
/* Reset the projection matrix as that relies on the viewport setting. */
{
vmsvga3dSetTransform(pThis, cid, SVGA3D_TRANSFORM_PROJECTION, pContext->state.aTransformState[SVGA3D_TRANSFORM_PROJECTION].matrix);
}
else
{
float matrix[16];
/* identity matrix if no matrix set. */
matrix[0] = 1.0;
}
return VINF_SUCCESS;
}
{
double oglPlane[4];
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)));
{
Log(("vmsvga3dSetClipPlane invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
memcpy(pContext->state.aClipPlane[index].plane, plane, sizeof(pContext->state.aClipPlane[index].plane));
/** @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));
{
Log(("vmsvga3dSetScissorRect invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
return VINF_SUCCESS;
}
static void vmsvgaColor2GLFloatArray(uint32_t color, GLfloat *pRed, GLfloat *pGreen, GLfloat *pBlue, GLfloat *pAlpha)
{
/* Convert byte color components to float (0-1.0) */
}
int vmsvga3dCommandClear(PVGASTATE pThis, uint32_t cid, SVGA3dClearFlag clearFlag, uint32_t color, float depth, uint32_t stencil,
{
GLbitfield mask = 0;
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));
{
Log(("vmsvga3dCommandClear invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
if (clearFlag & SVGA3D_CLEAR_COLOR)
{
/* Set the color clear value. */
}
if (clearFlag & SVGA3D_CLEAR_STENCIL)
{
/* @todo possibly the same problem as with glDepthMask */
}
if (clearFlag & SVGA3D_CLEAR_DEPTH)
{
/* glClear will not clear the depth buffer if writing is disabled. */
if (fDepthWriteEnabled == GL_FALSE)
}
if (cRects)
{
/* Save the current scissor test bit and scissor box. */
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));
}
/* Restore the old scissor test bit and box */
glPopAttrib();
}
else
{
}
/* Restore depth write state. */
if ( (clearFlag & SVGA3D_CLEAR_DEPTH)
&& fDepthWriteEnabled == GL_FALSE)
return VINF_SUCCESS;
}
/* Convert VMWare vertex declaration to its OpenGL equivalent. */
int vmsvga3dVertexDecl2OGL(SVGA3dVertexArrayIdentity &identity, GLint &size, GLenum &type, GLboolean &normalized)
{
{
case SVGA3D_DECLTYPE_FLOAT1:
size = 1;
break;
case SVGA3D_DECLTYPE_FLOAT2:
size = 2;
break;
case SVGA3D_DECLTYPE_FLOAT3:
size = 3;
break;
case SVGA3D_DECLTYPE_FLOAT4:
size = 4;
break;
case SVGA3D_DECLTYPE_D3DCOLOR:
break;
case SVGA3D_DECLTYPE_UBYTE4N:
/* no break */
case SVGA3D_DECLTYPE_UBYTE4:
size = 4;
break;
case SVGA3D_DECLTYPE_SHORT2N:
/* no break */
case SVGA3D_DECLTYPE_SHORT2:
size = 2;
break;
case SVGA3D_DECLTYPE_SHORT4N:
/* no break */
case SVGA3D_DECLTYPE_SHORT4:
size = 4;
break;
case SVGA3D_DECLTYPE_USHORT4N:
size = 4;
break;
case SVGA3D_DECLTYPE_USHORT2N:
size = 2;
break;
case SVGA3D_DECLTYPE_UDEC3:
size = 3;
break;
case SVGA3D_DECLTYPE_DEC3N:
normalized = true;
size = 3;
break;
size = 2;
break;
size = 4;
break;
default:
}
//pVertexElement->Method = identity.method;
//pVertexElement->Usage = identity.usage;
return VINF_SUCCESS;
}
/* Convert VMWare primitive type to its OpenGL equivalent. */
/* Calculate the vertex count based on the primitive type and nr of primitives. */
int vmsvga3dPrimitiveType2OGL(SVGA3dPrimitiveType PrimitiveType, GLenum *pMode, uint32_t cPrimitiveCount, uint32_t *pcVertices)
{
switch (PrimitiveType)
{
*pMode = GL_TRIANGLES;
break;
break;
break;
*pMode = GL_LINE_STRIP;
break;
break;
*pMode = GL_TRIANGLE_FAN;
break;
default:
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));
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
pState->ext.glBufferData(GL_ARRAY_BUFFER, pVertexSurface->pMipmapLevels[0].cbSurface, pVertexSurface->pMipmapLevels[0].pSurfaceData, GL_DYNAMIC_DRAW);
pVertexSurface->fDirty = false;
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
}
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
else
#endif
{
}
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
LogFlow(("vmsvga3dDrawPrimitivesProcessVertexDecls: sid=%x idAssociatedContext %#x -> %#x\n", pVertexSurface->id, pVertexSurface->idAssociatedContext, pContext->id));
#endif
/* Setup the vertex declarations. */
{
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));
{
/* Use numbered vertex arrays when shaders are active. */
/* case SVGA3D_DECLUSAGE_COLOR: @todo color component order not identical!! test GL_BGRA!! */
}
else
{
/* Use the predefined selection of vertex streams for the fixed pipeline. */
{
break;
AssertFailed();
break;
AssertFailed();
break;
case SVGA3D_DECLUSAGE_NORMAL:
break;
case SVGA3D_DECLUSAGE_PSIZE:
AssertFailed();
break;
/* Specify the affected texture unit. */
#if VBOX_VMSVGA3D_GL_HACK_LEVEL >= 0x103
#else
#endif
break;
case SVGA3D_DECLUSAGE_TANGENT:
AssertFailed();
break;
AssertFailed();
break;
AssertFailed();
break;
AssertFailed(); /* see position_transformed in Wine */
break;
case SVGA3D_DECLUSAGE_COLOR: /** @todo color component order not identical!! test GL_BGRA!! */
break;
case SVGA3D_DECLUSAGE_FOG:
break;
case SVGA3D_DECLUSAGE_DEPTH:
AssertFailed();
break;
case SVGA3D_DECLUSAGE_SAMPLE:
AssertFailed();
break;
}
}
#ifdef LOG_ENABLED
Log(("vmsvga3dDrawPrimitives: stride == 0! Can be valid\n"));
#endif
}
return VINF_SUCCESS;
}
int vmsvga3dDrawPrimitivesCleanupVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl)
{
/* Setup the vertex declarations. */
{
{
/* Use numbered vertex arrays when shaders are active. */
}
else
{
/* Use the predefined selection of vertex streams for the fixed pipeline. */
{
break;
break;
break;
case SVGA3D_DECLUSAGE_NORMAL:
break;
case SVGA3D_DECLUSAGE_PSIZE:
break;
/* Specify the affected texture unit. */
#if VBOX_VMSVGA3D_GL_HACK_LEVEL >= 0x103
#else
#endif
break;
case SVGA3D_DECLUSAGE_TANGENT:
break;
break;
break;
break;
case SVGA3D_DECLUSAGE_COLOR: /* @todo color component order not identical!! */
break;
case SVGA3D_DECLUSAGE_FOG:
break;
case SVGA3D_DECLUSAGE_DEPTH:
break;
case SVGA3D_DECLUSAGE_SAMPLE:
break;
}
}
}
/* Unbind the vertex buffer after usage. */
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)
{
int rc = VERR_NOT_IMPLEMENTED;
Log(("vmsvga3dDrawPrimitives cid=%x numVertexDecls=%d numRanges=%d, cVertexDivisor=%d\n", cid, numVertexDecls, numRanges, cVertexDivisor));
/* @todo */
{
Log(("vmsvga3dDrawPrimitives invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
/* Flush any shader changes. */
if (pContext->pShaderContext)
{
{
}
}
/* Process all vertex declarations. Each vertex buffer is represented by one stream. */
iCurrentVertex = 0;
while (iCurrentVertex < numVertexDecls)
{
{
if ( sidVertex != SVGA_ID_INVALID
)
break;
}
rc = vmsvga3dDrawPrimitivesProcessVertexDecls(pState, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);
}
/* Now draw the primitives. */
{
unsigned cVertices;
Log(("Primitive %d: type %s\n", iPrimitive, vmsvga3dPrimitiveType2String(pRange[iPrimitive].primType)));
rc = vmsvga3dPrimitiveType2OGL(pRange[iPrimitive].primType, &modeDraw, pRange[iPrimitive].primitiveCount, &cVertices);
if (RT_FAILURE(rc))
{
goto internal_error;
}
if (sidIndex != SVGA3D_INVALID_ID)
{
AssertMsg(pRange[iPrimitive].indexWidth == sizeof(uint32_t) || pRange[iPrimitive].indexWidth == sizeof(uint16_t), ("Unsupported primitive width %d\n", pRange[iPrimitive].indexWidth));
if ( sidIndex >= SVGA3D_MAX_SURFACE_IDS
{
goto internal_error;
}
{
Log(("vmsvga3dDrawPrimitives: create index buffer fDirty=%d size=%x bytes\n", pIndexSurface->fDirty, pIndexSurface->pMipmapLevels[0].cbSurface));
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
pState->ext.glBufferData(GL_ELEMENT_ARRAY_BUFFER, pIndexSurface->pMipmapLevels[0].cbSurface, pIndexSurface->pMipmapLevels[0].pSurfaceData, GL_DYNAMIC_DRAW);
pIndexSurface->fDirty = false;
#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
#endif
}
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
else
#endif
{
}
#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
LogFlow(("vmsvga3dDrawPrimitives: sid=%x idAssociatedContext %#x -> %#x\n", pIndexSurface->id, pIndexSurface->idAssociatedContext, pContext->id));
#endif
}
if (!pIndexSurface)
{
/* Render without an index buffer */
Log(("DrawPrimitive %x cPrimitives=%d cVertices=%d index index bias=%d\n", modeDraw, pRange[iPrimitive].primitiveCount, cVertices, pRange[iPrimitive].indexBias));
}
else
{
/* Render with an index buffer */
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));
else
/* Unbind the index buffer after usage. */
}
}
/* Deactivate the vertex declarations. */
iCurrentVertex = 0;
while (iCurrentVertex < numVertexDecls)
{
{
if ( sidVertex != SVGA_ID_INVALID
)
break;
}
rc = vmsvga3dDrawPrimitivesCleanupVertexDecls(pState, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);
}
#ifdef DEBUG
{
{
GLint activeTexture = 0;
GLint activeTextureUnit = 0;
# if 0 /* Aren't we checking whether 'activeTexture' on texture unit 'i' matches what we expected? This works if only one unit is active, but if both are it _will_ fail for one of them. */
{
AssertMsg(pTexture->oglId.texture == (GLuint)activeTexture, ("%x vs %x unit %d - %d\n", pTexture->oglId.texture, activeTexture, i, activeTextureUnit - GL_TEXTURE0));
}
# else
AssertMsg(pTexture->id == pContext->aSidActiveTexture[i], ("%x vs %x\n", pTexture->id == pContext->aSidActiveTexture[i]));
# endif
}
}
#endif
#ifdef DEBUG_GFX_WINDOW
if (pContext->aSidActiveTexture[0])
{
rect.w = 800;
rect.h = 600;
}
#endif
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));
{
Log(("vmsvga3dShaderDefine invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
if (type == SVGA3D_SHADERTYPE_VS)
{
{
pContext->paVertexShader = (PVMSVGA3DSHADER)RTMemRealloc(pContext->paVertexShader, sizeof(VMSVGA3DSHADER) * (shid + 1));
memset(&pContext->paVertexShader[pContext->cVertexShaders], 0, sizeof(VMSVGA3DSHADER) * (shid + 1 - pContext->cVertexShaders));
}
/* If one already exists with this id, then destroy it now. */
}
else
{
{
pContext->paPixelShader = (PVMSVGA3DSHADER)RTMemRealloc(pContext->paPixelShader, sizeof(VMSVGA3DSHADER) * (shid + 1));
memset(&pContext->paPixelShader[pContext->cPixelShaders], 0, sizeof(VMSVGA3DSHADER) * (shid + 1 - pContext->cPixelShaders));
}
/* If one already exists with this id, then destroy it now. */
}
#ifdef DUMP_SHADER_DISASSEMBLY
{
pDisassembly->Release();
}
#endif
switch (type)
{
case SVGA3D_SHADERTYPE_VS:
rc = ShaderCreateVertexShader(pContext->pShaderContext, (const uint32_t *)pShaderData, &pShader->u.pVertexShader);
break;
case SVGA3D_SHADERTYPE_PS:
rc = ShaderCreatePixelShader(pContext->pShaderContext, (const uint32_t *)pShaderData, &pShader->u.pPixelShader);
break;
default:
}
if (rc != VINF_SUCCESS)
{
}
return rc;
}
{
int rc;
Log(("vmsvga3dShaderDestroy cid=%x shid=%x type=%s\n", cid, shid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL"));
{
Log(("vmsvga3dShaderDestroy invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
if (type == SVGA3D_SHADERTYPE_VS)
{
{
}
}
else
{
{
}
}
if (pShader)
{
if (pShader->pShaderProgram)
}
else
return VINF_SUCCESS;
}
{
int rc;
Log(("vmsvga3dShaderSet cid=%x type=%s shid=%d\n", cid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", shid));
{
Log(("vmsvga3dShaderSet invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
if (type == SVGA3D_SHADERTYPE_VS)
{
{
}
else
if (shid == SVGA_ID_INVALID)
{
/* Unselect shader. */
}
else
}
else
{
{
}
else
if (shid == SVGA_ID_INVALID)
{
/* Unselect shader. */
}
else
}
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));
{
Log(("vmsvga3dShaderSetConst invalid context id!\n"));
return VERR_INVALID_PARAMETER;
}
for (uint32_t i = 0; i < cRegisters; i++)
{
#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)));
break;
}
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]));
break;
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]));
break;
}
#endif
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);
break;
case SVGA3D_CONST_TYPE_INT:
rc = ShaderSetVertexShaderConstantI(pContext->pShaderContext, reg, (const int32_t *)pValues, cRegisters);
break;
case SVGA3D_CONST_TYPE_BOOL:
rc = ShaderSetVertexShaderConstantB(pContext->pShaderContext, reg, (const uint8_t *)pValues, cRegisters);
break;
default:
}
break;
case SVGA3D_SHADERTYPE_PS:
switch (ctype)
{
case SVGA3D_CONST_TYPE_FLOAT:
rc = ShaderSetPixelShaderConstantF(pContext->pShaderContext, reg, (const float *)pValues, cRegisters);
break;
case SVGA3D_CONST_TYPE_INT:
rc = ShaderSetPixelShaderConstantI(pContext->pShaderContext, reg, (const int32_t *)pValues, cRegisters);
break;
case SVGA3D_CONST_TYPE_BOOL:
rc = ShaderSetPixelShaderConstantB(pContext->pShaderContext, reg, (const uint8_t *)pValues, cRegisters);
break;
default:
}
break;
default:
}
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;
}