VirtualBox

Changeset 54658 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 5, 2015 8:04:05 PM (10 years ago)
Author:
vboxsync
Message:

DevVGA-SVGA3d-ogl.cpp: Texture (surface) load and saving (to memory) fixes. Fixed crash when loading a 1 pixel wide texture. Fixed crashes loading and saving SVGA3D_A1R5G5B5 formatted textures.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp

    r54641 r54658  
    2020*   Header Files                                                               *
    2121*******************************************************************************/
     22#ifdef DEBUG_bird
     23# define RTMEM_WRAP_TO_EF_APIS
     24#endif
    2225#define LOG_GROUP LOG_GROUP_DEV_VMSVGA
    2326#include <VBox/vmm/pdmdev.h>
     
    275278 * @param   a_pState    The 3D state structure.
    276279 * @param   a_pContext  The context that holds the first error.
     280 * @param   a_LogRelDetails Argument list for LogRel or similar that describes
     281 *                          the operation in greater detail.
    277282 *
    278283 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
     
    283288        VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails); \
    284289    } while (0)
     290
     291/** @def VMSVGA3D_GL_ASSERT_SUCCESS
     292 * Asserts that VMSVGA3D_GL_IS_SUCCESS is true, complains if not.
     293 *
     294 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
     295 * logging in non-strict builds.
     296 *
     297 * @param   a_pState    The 3D state structure.
     298 * @param   a_pContext  The context that holds the first error.
     299 * @param   a_LogRelDetails Argument list for LogRel or similar that describes
     300 *                          the operation in greater detail.
     301 *
     302 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
     303 */
     304#define VMSVGA3D_GL_ASSERT_SUCCESS(a_pState, a_pContext, a_LogRelDetails) \
     305    if (VMSVGA3D_GL_IS_SUCCESS(a_pContext)) \
     306    { /* likely */ } \
     307    else do { \
     308        VMSVGA3D_GET_GL_ERROR(a_pContext); \
     309        VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails); \
     310    } while (0)
     311
     312/** @def VMSVGA3D_ASSERT_GL_CALL_EX
     313 * Executes the specified OpenGL API call and asserts that it succeeded, variant
     314 * with extra logging flexibility.
     315 *
     316 * ASSUMES no GL errors pending prior to invocation - caller should use
     317 * VMSVGA3D_CLEAR_GL_ERRORS if uncertain.
     318 *
     319 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
     320 * logging in non-strict builds.
     321 *
     322 * @param   a_GlCall    Expression making an OpenGL call.
     323 * @param   a_pState    The 3D state structure.
     324 * @param   a_pContext  The context that holds the first error.
     325 * @param   a_LogRelDetails Argument list for LogRel or similar that describes
     326 *                          the operation in greater detail.
     327 *
     328 * @sa VMSVGA3D_ASSERT_GL_CALL, VMSVGA3D_GL_ASSERT_SUCCESS,
     329 *     VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
     330 */
     331#define VMSVGA3D_ASSERT_GL_CALL_EX(a_GlCall, a_pState, a_pContext, a_LogRelDetails) \
     332    do { \
     333        (a_GlCall); \
     334        VMSVGA3D_GL_ASSERT_SUCCESS(a_pState, a_pContext, a_LogRelDetails); \
     335    } while (0)
     336
     337/** @def VMSVGA3D_ASSERT_GL_CALL
     338 * Executes the specified OpenGL API call and asserts that it succeeded.
     339 *
     340 * ASSUMES no GL errors pending prior to invocation - caller should use
     341 * VMSVGA3D_CLEAR_GL_ERRORS if uncertain.
     342 *
     343 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
     344 * logging in non-strict builds.
     345 *
     346 * @param   a_GlCall    Expression making an OpenGL call.
     347 * @param   a_pState    The 3D state structure.
     348 * @param   a_pContext  The context that holds the first error.
     349 *
     350 * @sa VMSVGA3D_ASSERT_GL_CALL_EX, VMSVGA3D_GL_ASSERT_SUCCESS,
     351 *     VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
     352 */
     353#define VMSVGA3D_ASSERT_GL_CALL(a_GlCall, a_pState, a_pContext) \
     354    VMSVGA3D_ASSERT_GL_CALL_EX(a_GlCall, a_pState, a_pContext, ("%s\n", #a_GlCall))
    285355
    286356
     
    789859
    790860
     861/** Save and setup everything. */
     862#define VMSVGA3D_PARANOID_TEXTURE_PACKING
     863
     864/**
     865 * Saved texture packing parameters (shared by both pack and unpack).
     866 */
     867typedef struct VMSVGAPACKPARAMS
     868{
     869    GLint       iAlignment;
     870    GLint       cxRow;
     871#ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
     872    GLint       cyImage;
     873    GLboolean   fSwapBytes;
     874    GLboolean   fLsbFirst;
     875    GLint       cSkipRows;
     876    GLint       cSkipPixels;
     877    GLint       cSkipImages;
     878#endif
     879} VMSVGAPACKPARAMS;
     880/** Pointer to saved texture packing parameters. */
     881typedef VMSVGAPACKPARAMS *PVMSVGAPACKPARAMS;
     882/** Pointer to const saved texture packing parameters. */
     883typedef VMSVGAPACKPARAMS const *PCVMSVGAPACKPARAMS;
     884
     885
     886/*******************************************************************************
     887*   Global Variables                                                           *
     888*******************************************************************************/
    791889/* Define the default light parameters as specified by MSDN. */
    792890/* @todo move out; fetched from Wine */
     
    807905};
    808906
     907
     908/*******************************************************************************
     909*   Internal Functions                                                         *
     910*******************************************************************************/
    809911RT_C_DECLS_BEGIN
    810912static int vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface);
     
    21232225/**
    21242226 * Convert SVGA format value to its OpenGL equivalent
     2227 *
     2228 * @remarks  Clues to be had in format_texture_info table (wined3d/utils.c) with
     2229 *           help from wined3dformat_from_d3dformat().
    21252230 */
    21262231static void vmsvga3dSurfaceFormat2OGL(PVMSVGA3DSURFACE pSurface, SVGA3dSurfaceFormat format)
     
    21282233    switch (format)
    21292234    {
    2130     case SVGA3D_X8R8G8B8:
     2235    case SVGA3D_X8R8G8B8:               /* D3DFMT_X8R8G8B8 - WINED3DFMT_B8G8R8X8_UNORM */
    21312236        pSurface->internalFormatGL = GL_RGB8;
    21322237        pSurface->formatGL = GL_BGRA;
    21332238        pSurface->typeGL = GL_UNSIGNED_INT_8_8_8_8_REV;
    21342239        break;
    2135     case SVGA3D_A8R8G8B8:
     2240    case SVGA3D_A8R8G8B8:               /* D3DFMT_A8R8G8B8 - WINED3DFMT_B8G8R8A8_UNORM */
    21362241        pSurface->internalFormatGL = GL_RGBA8;
    21372242        pSurface->formatGL = GL_BGRA;
    21382243        pSurface->typeGL = GL_UNSIGNED_INT_8_8_8_8_REV;
    21392244        break;
    2140     case SVGA3D_R5G6B5:
    2141         pSurface->internalFormatGL = GL_RGB;
     2245    case SVGA3D_R5G6B5:                 /* D3DFMT_R5G6B5 - WINED3DFMT_B5G6R5_UNORM */
     2246        pSurface->internalFormatGL = GL_RGB5;
    21422247        pSurface->formatGL = GL_RGB;
    21432248        pSurface->typeGL = GL_UNSIGNED_SHORT_5_6_5;
    2144         break;
    2145     case SVGA3D_X1R5G5B5:
    2146         pSurface->internalFormatGL = GL_RGB;
    2147         pSurface->formatGL = GL_RGB;
     2249        AssertMsgFailed(("Test me - SVGA3D_R5G6B5\n"));
     2250        break;
     2251    case SVGA3D_X1R5G5B5:               /* D3DFMT_X1R5G5B5 - WINED3DFMT_B5G5R5X1_UNORM */
     2252        pSurface->internalFormatGL = GL_RGB5;
     2253        pSurface->formatGL = GL_BGRA;
    21482254        pSurface->typeGL = GL_UNSIGNED_SHORT_1_5_5_5_REV;
    2149         break;
    2150     case SVGA3D_A1R5G5B5:
    2151         pSurface->internalFormatGL = GL_RGBA;
    2152         pSurface->formatGL = GL_RGB;
     2255        AssertMsgFailed(("Test me - SVGA3D_X1R5G5B5\n"));
     2256        break;
     2257    case SVGA3D_A1R5G5B5:               /* D3DFMT_A1R5G5B5 - WINED3DFMT_B5G5R5A1_UNORM */
     2258        pSurface->internalFormatGL = GL_RGB5_A1;
     2259        pSurface->formatGL = GL_BGRA;
    21532260        pSurface->typeGL = GL_UNSIGNED_SHORT_1_5_5_5_REV;
    2154         break;
    2155     case SVGA3D_A4R4G4B4:
    2156         pSurface->internalFormatGL = GL_RGBA;
    2157         pSurface->formatGL = GL_RGBA;
    2158         pSurface->typeGL =  GL_UNSIGNED_SHORT_4_4_4_4;
    2159         break;
    2160 
    2161     case SVGA3D_Z_D32:
     2261        AssertMsgFailed(("Test me - SVGA3D_A1R5G5B5\n"));
     2262        break;
     2263    case SVGA3D_A4R4G4B4:               /* D3DFMT_A4R4G4B4 - WINED3DFMT_B4G4R4A4_UNORM */
     2264        pSurface->internalFormatGL = GL_RGBA4;
     2265        pSurface->formatGL = GL_BGRA;
     2266        pSurface->typeGL = GL_UNSIGNED_SHORT_4_4_4_4_REV;
     2267        AssertMsgFailed(("Test me - SVGA3D_A4R4G4B4\n"));
     2268        break;
     2269
     2270    case SVGA3D_Z_D32:                  /* D3DFMT_D32 - WINED3DFMT_D32_UNORM */
    21622271        pSurface->internalFormatGL = GL_DEPTH_COMPONENT32;
    21632272        pSurface->formatGL = GL_DEPTH_COMPONENT;
    21642273        pSurface->typeGL = GL_UNSIGNED_INT;
    21652274        break;
    2166     case SVGA3D_Z_D16:
    2167         pSurface->internalFormatGL = GL_DEPTH_COMPONENT16;
     2275    case SVGA3D_Z_D16:                  /* D3DFMT_D16 - WINED3DFMT_D16_UNORM */
     2276        pSurface->internalFormatGL = GL_DEPTH_COMPONENT16; /** @todo Wine suggests GL_DEPTH_COMPONENT24. */
    21682277        pSurface->formatGL = GL_DEPTH_COMPONENT;
    21692278        pSurface->typeGL = GL_UNSIGNED_SHORT;
    2170         break;
    2171     case SVGA3D_Z_D24S8:
     2279        AssertMsgFailed(("Test me - SVGA3D_Z_D16\n"));
     2280        break;
     2281    case SVGA3D_Z_D24S8:                /* D3DFMT_D24S8 - WINED3DFMT_D24_UNORM_S8_UINT */
    21722282        pSurface->internalFormatGL = GL_DEPTH24_STENCIL8;
    21732283        pSurface->formatGL = GL_DEPTH_STENCIL;
    21742284        pSurface->typeGL = GL_UNSIGNED_INT;
    21752285        break;
    2176     case SVGA3D_Z_D15S1:
     2286    case SVGA3D_Z_D15S1:                /* D3DFMT_D15S1 - WINED3DFMT_S1_UINT_D15_UNORM */
    21772287        pSurface->internalFormatGL = GL_DEPTH_COMPONENT16;  /* @todo ??? */
    21782288        pSurface->formatGL = GL_DEPTH_STENCIL;
    21792289        pSurface->typeGL = GL_UNSIGNED_SHORT;
    2180         break;
    2181     case SVGA3D_Z_D24X8:
     2290        /** @todo Wine sources hints at no hw support for this, so test this one! */
     2291        AssertMsgFailed(("Test me - SVGA3D_Z_D15S1\n"));
     2292        break;
     2293    case SVGA3D_Z_D24X8:                /* D3DFMT_D24X8 - WINED3DFMT_X8D24_UNORM */
    21822294        pSurface->internalFormatGL = GL_DEPTH_COMPONENT24;
    21832295        pSurface->formatGL = GL_DEPTH_COMPONENT;
     
    21862298
    21872299    /* Advanced D3D9 depth formats. */
    2188     case SVGA3D_Z_DF16:
     2300    case SVGA3D_Z_DF16:                 /* D3DFMT_DF16? - not supported */
    21892301        pSurface->internalFormatGL = GL_DEPTH_COMPONENT16;
    21902302        pSurface->formatGL = GL_DEPTH_COMPONENT;
     
    21922304        break;
    21932305
    2194     case SVGA3D_Z_DF24:
     2306    case SVGA3D_Z_DF24:                 /* D3DFMT_DF24? - not supported */
    21952307        pSurface->internalFormatGL = GL_DEPTH_COMPONENT24;
    21962308        pSurface->formatGL = GL_DEPTH_COMPONENT;
     
    21982310        break;
    21992311
    2200     case SVGA3D_Z_D24S8_INT:
     2312    case SVGA3D_Z_D24S8_INT:            /* D3DFMT_??? - not supported */
    22012313        pSurface->internalFormatGL = GL_DEPTH24_STENCIL8;
    22022314        pSurface->formatGL = GL_DEPTH_STENCIL;
     
    22042316        break;
    22052317
    2206     case SVGA3D_DXT1:
     2318    case SVGA3D_DXT1:                   /* D3DFMT_DXT1 - WINED3DFMT_DXT1 */
    22072319        pSurface->internalFormatGL = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
     2320#if 0
    22082321        pSurface->formatGL = GL_RGBA_S3TC;          /* ??? */
    22092322        pSurface->typeGL = GL_UNSIGNED_INT;         /* ??? */
    2210         break;
    2211 
    2212     case SVGA3D_DXT3:
     2323#else   /* wine suggests: */
     2324        pSurface->formatGL = GL_RGBA;
     2325        pSurface->typeGL = GL_UNSIGNED_BYTE;
     2326        AssertMsgFailed(("Test me - SVGA3D_DXT1\n"));
     2327#endif
     2328        break;
     2329
     2330    case SVGA3D_DXT3:                   /* D3DFMT_DXT3 - WINED3DFMT_DXT3 */
    22132331        pSurface->internalFormatGL = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
     2332#if 0 /** @todo this needs testing... */
    22142333        pSurface->formatGL = GL_RGBA_S3TC;          /* ??? */
    22152334        pSurface->typeGL = GL_UNSIGNED_INT;         /* ??? */
    2216         break;
    2217 
    2218     case SVGA3D_DXT5:
     2335#else   /* wine suggests: */
     2336        pSurface->formatGL = GL_RGBA;
     2337        pSurface->typeGL = GL_UNSIGNED_BYTE;
     2338        AssertMsgFailed(("Test me - SVGA3D_DXT3\n"));
     2339#endif
     2340        break;
     2341
     2342    case SVGA3D_DXT5:                   /* D3DFMT_DXT5 - WINED3DFMT_DXT5 */
    22192343        pSurface->internalFormatGL = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
     2344#if 0 /** @todo this needs testing... */
    22202345        pSurface->formatGL = GL_RGBA_S3TC;
    22212346        pSurface->typeGL = GL_UNSIGNED_INT;
    2222         break;
    2223 
    2224     case SVGA3D_LUMINANCE8:
     2347#else   /* wine suggests: */
     2348        pSurface->formatGL = GL_RGBA;
     2349        pSurface->typeGL = GL_UNSIGNED_BYTE;
     2350        AssertMsgFailed(("Test me - SVGA3D_DXT5\n"));
     2351#endif
     2352        break;
     2353
     2354    case SVGA3D_LUMINANCE8:             /* D3DFMT_? - ? */
    22252355        pSurface->internalFormatGL = GL_LUMINANCE8_EXT;
    22262356        pSurface->formatGL = GL_LUMINANCE;
     
    22282358        break;
    22292359
    2230     case SVGA3D_LUMINANCE16:
     2360    case SVGA3D_LUMINANCE16:            /* D3DFMT_? - ? */
    22312361        pSurface->internalFormatGL = GL_LUMINANCE16_EXT;
    22322362        pSurface->formatGL = GL_LUMINANCE;
     
    22342364        break;
    22352365
    2236     case SVGA3D_LUMINANCE4_ALPHA4:
     2366    case SVGA3D_LUMINANCE4_ALPHA4:     /* D3DFMT_? - ? */
    22372367        pSurface->internalFormatGL = GL_LUMINANCE4_ALPHA4_EXT;
    22382368        pSurface->formatGL = GL_LUMINANCE_ALPHA;
     
    22402370        break;
    22412371
    2242     case SVGA3D_LUMINANCE8_ALPHA8:
     2372    case SVGA3D_LUMINANCE8_ALPHA8:     /* D3DFMT_? - ? */
    22432373        pSurface->internalFormatGL = GL_LUMINANCE8_ALPHA8_EXT;
    22442374        pSurface->formatGL = GL_LUMINANCE_ALPHA;
     
    22462376        break;
    22472377
    2248     case SVGA3D_ALPHA8:
     2378    case SVGA3D_ALPHA8:                /* D3DFMT_A8? - WINED3DFMT_A8_UNORM? */
    22492379        pSurface->internalFormatGL = GL_ALPHA8_EXT;
    22502380        pSurface->formatGL = GL_ALPHA;
     
    22782408#endif
    22792409
    2280     case SVGA3D_ARGB_S10E5:   /* 16-bit floating-point ARGB */
     2410    case SVGA3D_ARGB_S10E5:   /* 16-bit floating-point ARGB */ /* D3DFMT_A16B16G16R16F - WINED3DFMT_R16G16B16A16_FLOAT */
    22812411        pSurface->internalFormatGL = GL_RGBA16F;
    22822412        pSurface->formatGL = GL_RGBA;
     2413#if 0 /* bird: wine uses half float, sounds correct to me... */
    22832414        pSurface->typeGL = GL_FLOAT;
    2284         break;
    2285 
    2286     case SVGA3D_ARGB_S23E8:   /* 32-bit floating-point ARGB */
     2415#else
     2416        pSurface->typeGL = GL_HALF_FLOAT;
     2417        AssertMsgFailed(("Test me - SVGA3D_ARGB_S10E5\n"));
     2418#endif
     2419        break;
     2420
     2421    case SVGA3D_ARGB_S23E8:   /* 32-bit floating-point ARGB */ /* D3DFMT_A32B32G32R32F - WINED3DFMT_R32G32B32A32_FLOAT */
    22872422        pSurface->internalFormatGL = GL_RGBA32F;
    22882423        pSurface->formatGL = GL_RGBA;
    2289         pSurface->typeGL = GL_FLOAT;    /* ?? */
    2290         break;
    2291 
    2292     case SVGA3D_A2R10G10B10:
    2293         pSurface->internalFormatGL = GL_RGB10_A2; /* ?? */
     2424        pSurface->typeGL = GL_FLOAT;    /* ?? - same as wine, so probably correct */
     2425        break;
     2426
     2427    case SVGA3D_A2R10G10B10:            /* D3DFMT_A2R10G10B10 - WINED3DFMT_B10G10R10A2_UNORM */
     2428        pSurface->internalFormatGL = GL_RGB10_A2; /* ?? - same as wine, so probably correct */
     2429#if 0 /* bird: Wine uses GL_BGRA instead of GL_RGBA. */
    22942430        pSurface->formatGL = GL_RGBA;
     2431#else
     2432        pSurface->formatGL = GL_BGRA;
     2433#endif
    22952434        pSurface->typeGL = GL_UNSIGNED_INT;
     2435        AssertMsgFailed(("Test me - SVGA3D_A2R10G10B10\n"));
    22962436        break;
    22972437
    22982438
    22992439    /* Single- and dual-component floating point formats */
    2300     case SVGA3D_R_S10E5:
     2440    case SVGA3D_R_S10E5:                /* D3DFMT_R16F - WINED3DFMT_R16_FLOAT */
    23012441        pSurface->internalFormatGL = GL_R16F;
    23022442        pSurface->formatGL = GL_RED;
     2443#if 0 /* bird: wine uses half float, sounds correct to me... */
    23032444        pSurface->typeGL = GL_FLOAT;
    2304         break;
    2305     case SVGA3D_R_S23E8:
     2445#else
     2446        pSurface->typeGL = GL_HALF_FLOAT;
     2447        AssertMsgFailed(("Test me - SVGA3D_R_S10E5\n"));
     2448#endif
     2449        break;
     2450    case SVGA3D_R_S23E8:                /* D3DFMT_R32F - WINED3DFMT_R32_FLOAT */
    23062451        pSurface->internalFormatGL = GL_R32F;
    23072452        pSurface->formatGL = GL_RG;
    23082453        pSurface->typeGL = GL_FLOAT;
    23092454        break;
    2310     case SVGA3D_RG_S10E5:
     2455    case SVGA3D_RG_S10E5:               /* D3DFMT_G16R16F - WINED3DFMT_R16G16_FLOAT */
    23112456        pSurface->internalFormatGL = GL_RG16F;
    23122457        pSurface->formatGL = GL_RG;
     2458#if 0 /* bird: wine uses half float, sounds correct to me... */
    23132459        pSurface->typeGL = GL_FLOAT;
    2314         break;
    2315     case SVGA3D_RG_S23E8:
     2460#else
     2461        pSurface->typeGL = GL_HALF_FLOAT;
     2462        AssertMsgFailed(("Test me - SVGA3D_RG_S10E5\n"));
     2463#endif
     2464        break;
     2465    case SVGA3D_RG_S23E8:               /* D3DFMT_G32R32F - WINED3DFMT_R32G32_FLOAT */
    23162466        pSurface->internalFormatGL = GL_RG32F;
    23172467        pSurface->formatGL = GL_RG;
     
    23372487#endif
    23382488
    2339     case SVGA3D_G16R16:
     2489    case SVGA3D_G16R16:                 /* D3DFMT_G16R16 - WINED3DFMT_R16G16_UNORM */
    23402490        pSurface->internalFormatGL = GL_RG16;
    23412491        pSurface->formatGL = GL_RG;
     2492#if 0 /* bird: Wine uses GL_UNSIGNED_SHORT here. */
    23422493        pSurface->typeGL = GL_UNSIGNED_INT;
    2343         break;
    2344 
    2345     case SVGA3D_A16B16G16R16:
     2494#else
     2495        pSurface->typeGL = GL_UNSIGNED_SHORT;
     2496        AssertMsgFailed(("test me - SVGA3D_G16R16\n"));
     2497#endif
     2498        break;
     2499
     2500    case SVGA3D_A16B16G16R16:           /* D3DFMT_A16B16G16R16 - WINED3DFMT_R16G16B16A16_UNORM */
    23462501        pSurface->internalFormatGL = GL_RGBA16;
    2347         pSurface->formatGL = GL_RG;
     2502        pSurface->formatGL = GL_RGBA;
     2503#if 0 /* bird: Wine uses GL_UNSIGNED_SHORT here. */
    23482504        pSurface->typeGL = GL_UNSIGNED_INT;     /* ??? */
     2505#else
     2506        pSurface->typeGL = GL_UNSIGNED_SHORT;
     2507        AssertMsgFailed(("Test me - SVGA3D_A16B16G16R16\n"));
     2508#endif
    23492509        break;
    23502510
     
    25872747    {
    25882748        PVMSVGA3DSURFACE pSurface = &pState->paSurface[sid];
    2589         PVMSVGA3DCONTEXT pContext = NULL;
     2749        PVMSVGA3DCONTEXT pContext;
    25902750
    25912751        Log(("vmsvga3dSurfaceDestroy id %x\n", sid));
     
    25952755        for (uint32_t cid = 0; cid < pState->cContexts; cid++)
    25962756        {
    2597             PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
     2757            pContext = &pState->paContext[cid];
    25982758            if (pContext->id == cid)
    25992759            {
     
    27292889}
    27302890
     2891
     2892/**
     2893 * Save texture unpacking parameters and loads those appropriate for the given
     2894 * surface.
     2895 *
     2896 * @param   pState              The VMSVGA3D state structure.
     2897 * @param   pContext            The active context.
     2898 * @param   pSurface            The surface.
     2899 * @param   pSave               Where to save stuff.
     2900 */
     2901static void vmsvga3dSetUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
     2902                                    PVMSVGAPACKPARAMS pSave)
     2903{
     2904    /*
     2905     * Save (ignore errors, setting the defaults we want and avoids restore).
     2906     */
     2907    pSave->iAlignment = 1;
     2908    VMSVGA3D_ASSERT_GL_CALL(glGetIntegerv(GL_UNPACK_ALIGNMENT, &pSave->iAlignment), pState, pContext);
     2909    pSave->cxRow = 0;
     2910    VMSVGA3D_ASSERT_GL_CALL(glGetIntegerv(GL_UNPACK_ROW_LENGTH, &pSave->cxRow), pState, pContext);
     2911
     2912#ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
     2913    pSave->cyImage = 0;
     2914    glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &pSave->cyImage);
     2915    Assert(pSave->cyImage == 0);
     2916
     2917    pSave->fSwapBytes = GL_FALSE;
     2918    glGetBooleanv(GL_UNPACK_SWAP_BYTES, &pSave->fSwapBytes);
     2919    Assert(pSave->fSwapBytes == GL_FALSE);
     2920
     2921    pSave->fLsbFirst = GL_FALSE;
     2922    glGetBooleanv(GL_UNPACK_LSB_FIRST, &pSave->fLsbFirst);
     2923    Assert(pSave->fLsbFirst == GL_FALSE);
     2924
     2925    pSave->cSkipRows = 0;
     2926    glGetIntegerv(GL_UNPACK_SKIP_ROWS, &pSave->cSkipRows);
     2927    Assert(pSave->cSkipRows == 0);
     2928
     2929    pSave->cSkipPixels = 0;
     2930    glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &pSave->cSkipPixels);
     2931    Assert(pSave->cSkipPixels == 0);
     2932
     2933    pSave->cSkipImages = 0;
     2934    glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &pSave->cSkipImages);
     2935    Assert(pSave->cSkipImages == 0);
     2936
     2937    VMSVGA3D_CLEAR_GL_ERRORS();
     2938#endif
     2939
     2940    /*
     2941     * Setup unpack.
     2942     *
     2943     * Note! We use 1 as alignment here because we currently don't do any
     2944     *       aligning of line pitches anywhere.
     2945     */
     2946    NOREF(pSurface);
     2947    if (pSave->iAlignment != 1)
     2948        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1), pState, pContext);
     2949    if (pSave->cxRow != 0)
     2950        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0), pState, pContext);
     2951#ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
     2952    if (pSave->cyImage != 0)
     2953        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0), pState, pContext);
     2954    if (pSave->fSwapBytes != 0)
     2955        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE), pState, pContext);
     2956    if (pSave->fLsbFirst != 0)
     2957        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE), pState, pContext);
     2958    if (pSave->cSkipRows != 0)
     2959        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_SKIP_ROWS, 0), pState, pContext);
     2960    if (pSave->cSkipPixels != 0)
     2961        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0), pState, pContext);
     2962    if (pSave->cSkipImages != 0)
     2963        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0), pState, pContext);
     2964#endif
     2965}
     2966
     2967
     2968/**
     2969 * Restores texture unpacking parameters.
     2970 *
     2971 * @param   pState              The VMSVGA3D state structure.
     2972 * @param   pContext            The active context.
     2973 * @param   pSurface            The surface.
     2974 * @param   pSave               Where stuff was saved.
     2975 */
     2976static void vmsvga3dRestoreUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
     2977                                        PCVMSVGAPACKPARAMS pSave)
     2978{
     2979    NOREF(pSurface);
     2980    if (pSave->iAlignment != 1)
     2981        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_ALIGNMENT, pSave->iAlignment), pState, pContext);
     2982    if (pSave->cxRow != 0)
     2983        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, pSave->cxRow), pState, pContext);
     2984#ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
     2985    if (pSave->cyImage != 0)
     2986        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, pSave->cyImage), pState, pContext);
     2987    if (pSave->fSwapBytes != 0)
     2988        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_SWAP_BYTES, pSave->fSwapBytes), pState, pContext);
     2989    if (pSave->fLsbFirst != 0)
     2990        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_LSB_FIRST, pSave->fLsbFirst), pState, pContext);
     2991    if (pSave->cSkipRows != 0)
     2992        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_SKIP_ROWS, pSave->cSkipRows), pState, pContext);
     2993    if (pSave->cSkipPixels != 0)
     2994        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS, pSave->cSkipPixels), pState, pContext);
     2995    if (pSave->cSkipImages != 0)
     2996        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_UNPACK_SKIP_IMAGES, pSave->cSkipImages), pState, pContext);
     2997#endif
     2998}
     2999
     3000
    27313001/* Create D3D texture object for the specified surface. */
    27323002static int vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext,
     
    27483018    if (pSurface->fDirty)
    27493019    {
     3020        /* Set the unacpking parameters. */
     3021        VMSVGAPACKPARAMS SavedParams;
     3022        vmsvga3dSetUnpackParams(pState, pContext, pSurface, &SavedParams);
     3023
    27503024        Log(("vmsvga3dCreateTexture: sync dirty texture\n"));
    27513025        for (uint32_t i = 0; i < pSurface->faces[0].numMipLevels; i++)
     
    27713045        }
    27723046        pSurface->fDirty = false;
     3047
     3048        /* Restore packing parameters. */
     3049        vmsvga3dRestoreUnpackParams(pState, pContext, pSurface, &SavedParams);
    27733050    }
    27743051    else
     
    29083185}
    29093186
     3187/**
     3188 * Save texture packing parameters and loads those appropriate for the given
     3189 * surface.
     3190 *
     3191 * @param   pState              The VMSVGA3D state structure.
     3192 * @param   pContext            The active context.
     3193 * @param   pSurface            The surface.
     3194 * @param   pSave               Where to save stuff.
     3195 */
     3196static void vmsvga3dSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
     3197                                  PVMSVGAPACKPARAMS pSave)
     3198{
     3199    /*
     3200     * Save (ignore errors, setting the defaults we want and avoids restore).
     3201     */
     3202    pSave->iAlignment = 1;
     3203    VMSVGA3D_ASSERT_GL_CALL(glGetIntegerv(GL_UNPACK_ALIGNMENT, &pSave->iAlignment), pState, pContext);
     3204    pSave->cxRow = 0;
     3205    VMSVGA3D_ASSERT_GL_CALL(glGetIntegerv(GL_UNPACK_ROW_LENGTH, &pSave->cxRow), pState, pContext);
     3206
     3207#ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
     3208    pSave->cyImage = 0;
     3209    glGetIntegerv(GL_PACK_IMAGE_HEIGHT, &pSave->cyImage);
     3210    Assert(pSave->cyImage == 0);
     3211
     3212    pSave->fSwapBytes = GL_FALSE;
     3213    glGetBooleanv(GL_PACK_SWAP_BYTES, &pSave->fSwapBytes);
     3214    Assert(pSave->fSwapBytes == GL_FALSE);
     3215
     3216    pSave->fLsbFirst = GL_FALSE;
     3217    glGetBooleanv(GL_PACK_LSB_FIRST, &pSave->fLsbFirst);
     3218    Assert(pSave->fLsbFirst == GL_FALSE);
     3219
     3220    pSave->cSkipRows = 0;
     3221    glGetIntegerv(GL_PACK_SKIP_ROWS, &pSave->cSkipRows);
     3222    Assert(pSave->cSkipRows == 0);
     3223
     3224    pSave->cSkipPixels = 0;
     3225    glGetIntegerv(GL_PACK_SKIP_PIXELS, &pSave->cSkipPixels);
     3226    Assert(pSave->cSkipPixels == 0);
     3227
     3228    pSave->cSkipImages = 0;
     3229    glGetIntegerv(GL_PACK_SKIP_IMAGES, &pSave->cSkipImages);
     3230    Assert(pSave->cSkipImages == 0);
     3231
     3232    VMSVGA3D_CLEAR_GL_ERRORS();
     3233#endif
     3234
     3235    /*
     3236     * Setup unpack.
     3237     *
     3238     * Note! We use 1 as alignment here because we currently don't do any
     3239     *       aligning of line pitches anywhere.
     3240     */
     3241    NOREF(pSurface);
     3242    if (pSave->iAlignment != 1)
     3243        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_ALIGNMENT, 1), pState, pContext);
     3244    if (pSave->cxRow != 0)
     3245        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_ROW_LENGTH, 0), pState, pContext);
     3246#ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
     3247    if (pSave->cyImage != 0)
     3248        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0), pState, pContext);
     3249    if (pSave->fSwapBytes != 0)
     3250        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE), pState, pContext);
     3251    if (pSave->fLsbFirst != 0)
     3252        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_LSB_FIRST, GL_FALSE), pState, pContext);
     3253    if (pSave->cSkipRows != 0)
     3254        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_SKIP_ROWS, 0), pState, pContext);
     3255    if (pSave->cSkipPixels != 0)
     3256        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_SKIP_PIXELS, 0), pState, pContext);
     3257    if (pSave->cSkipImages != 0)
     3258        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_SKIP_IMAGES, 0), pState, pContext);
     3259#endif
     3260}
     3261
     3262
     3263/**
     3264 * Restores texture packing parameters.
     3265 *
     3266 * @param   pState              The VMSVGA3D state structure.
     3267 * @param   pContext            The active context.
     3268 * @param   pSurface            The surface.
     3269 * @param   pSave               Where stuff was saved.
     3270 */
     3271static void vmsvga3dRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
     3272                                      PCVMSVGAPACKPARAMS pSave)
     3273{
     3274    NOREF(pSurface);
     3275    if (pSave->iAlignment != 1)
     3276        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_ALIGNMENT, pSave->iAlignment), pState, pContext);
     3277    if (pSave->cxRow != 0)
     3278        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_ROW_LENGTH, pSave->cxRow), pState, pContext);
     3279#ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
     3280    if (pSave->cyImage != 0)
     3281        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_IMAGE_HEIGHT, pSave->cyImage), pState, pContext);
     3282    if (pSave->fSwapBytes != 0)
     3283        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_SWAP_BYTES, pSave->fSwapBytes), pState, pContext);
     3284    if (pSave->fLsbFirst != 0)
     3285        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_LSB_FIRST, pSave->fLsbFirst), pState, pContext);
     3286    if (pSave->cSkipRows != 0)
     3287        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_SKIP_ROWS, pSave->cSkipRows), pState, pContext);
     3288    if (pSave->cSkipPixels != 0)
     3289        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_SKIP_PIXELS, pSave->cSkipPixels), pState, pContext);
     3290    if (pSave->cSkipImages != 0)
     3291        VMSVGA3D_ASSERT_GL_CALL(glPixelStorei(GL_PACK_SKIP_IMAGES, pSave->cSkipImages), pState, pContext);
     3292#endif
     3293}
     3294
     3295
    29103296int vmsvga3dSurfaceDMA(PVGASTATE pThis, SVGA3dGuestImage guest, SVGA3dSurfaceImageId host, SVGA3dTransferType transfer,
    29113297                       uint32_t cCopyBoxes, SVGA3dCopyBox *pBoxes)
     
    30513437                    GLint activeTexture;
    30523438
     3439                    /* Must bind texture to the current context in order to read it. */
    30533440                    glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
    30543441                    VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
     
    30563443                    glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
    30573444                    VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
     3445
     3446                    /* Set row length and alignment of the input data. */
     3447                    VMSVGAPACKPARAMS SavedParams;
     3448                    vmsvga3dSetPackParams(pState, pContext, pSurface, &SavedParams);
    30583449
    30593450                    glGetTexImage(GL_TEXTURE_2D,
     
    30633454                                  pDoubleBuffer);
    30643455                    VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
     3456
     3457                    vmsvga3dRestorePackParams(pState, pContext, pSurface, &SavedParams);
    30653458
    30663459                    /* Restore the old active texture. */
     
    31143507                {
    31153508                    GLint activeTexture = 0;
    3116                     GLint alignment;
    31173509
    31183510                    glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
     
    31263518
    31273519                    /* Set row length and alignment of the input data. */
    3128                     glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
    3129                     glPixelStorei(GL_UNPACK_ROW_LENGTH, pBoxes[i].w);
    3130                     glPixelStorei(GL_UNPACK_ALIGNMENT, pSurface->cbBlock);
     3520                    VMSVGAPACKPARAMS SavedParams;
     3521                    vmsvga3dSetUnpackParams(pState, pContext, pSurface, &SavedParams); /** @todo do we need to set ROW_LENGTH to w here? */
    31313522
    31323523                    glTexSubImage2D(GL_TEXTURE_2D,
     
    31433534
    31443535                    /* Restore old values. */
    3145                     glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    3146                     glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
     3536                    vmsvga3dRestoreUnpackParams(pState, pContext, pSurface, &SavedParams);
    31473537
    31483538                    /* Restore the old active texture. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette