VirtualBox

Ignore:
Timestamp:
Aug 3, 2011 11:20:01 AM (13 years ago)
Author:
vboxsync
Message:

crOpenGL: proper handling of pack/unpack states with PBO's

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_pixel.c

    r35263 r38298  
    175175}
    176176
     177static const CRPixelPackState _defaultPacking = {
     178   0, /* rowLength */
     179   0, /* skipRows */
     180   0, /* skipPixels */
     181   1, /* alignment */
     182   0, /* imageHeight */
     183   0, /* skipImages */
     184   GL_FALSE, /* swapBytes */
     185   GL_FALSE, /* psLSBFirst */
     186};
     187
     188#define APPLY_IF_NEQ(state, field, enum)        \
     189    if (state.field != _defaultPacking.field)   \
     190    {                                           \
     191        crPackPixelStorei(enum, state.field);   \
     192    }
     193
     194#define RESTORE_IF_NEQ(state, field, enum)              \
     195    if (state.field != _defaultPacking.field)           \
     196    {                                                   \
     197        crPackPixelStorei(enum, _defaultPacking.field); \
     198    }
     199
     200static void packspu_ApplyUnpackState()
     201{
     202    GET_THREAD(thread);
     203    ContextInfo *ctx = thread->currentContext;
     204    CRClientState *clientState = &(ctx->clientState->client);
     205
     206    APPLY_IF_NEQ(clientState->unpack, rowLength, GL_UNPACK_ROW_LENGTH);
     207    APPLY_IF_NEQ(clientState->unpack, skipRows, GL_UNPACK_SKIP_ROWS);
     208    APPLY_IF_NEQ(clientState->unpack, skipPixels, GL_UNPACK_SKIP_PIXELS);
     209    APPLY_IF_NEQ(clientState->unpack, alignment, GL_UNPACK_ALIGNMENT);
     210    APPLY_IF_NEQ(clientState->unpack, imageHeight, GL_UNPACK_IMAGE_HEIGHT);
     211    APPLY_IF_NEQ(clientState->unpack, skipImages, GL_UNPACK_SKIP_IMAGES);
     212    APPLY_IF_NEQ(clientState->unpack, swapBytes, GL_UNPACK_SWAP_BYTES);
     213    APPLY_IF_NEQ(clientState->unpack, psLSBFirst, GL_UNPACK_LSB_FIRST);
     214}
     215
     216static void packspu_RestoreUnpackState()
     217{
     218    GET_THREAD(thread);
     219    ContextInfo *ctx = thread->currentContext;
     220    CRClientState *clientState = &(ctx->clientState->client);
     221
     222    RESTORE_IF_NEQ(clientState->unpack, rowLength, GL_UNPACK_ROW_LENGTH);
     223    RESTORE_IF_NEQ(clientState->unpack, skipRows, GL_UNPACK_SKIP_ROWS);
     224    RESTORE_IF_NEQ(clientState->unpack, skipPixels, GL_UNPACK_SKIP_PIXELS);
     225    RESTORE_IF_NEQ(clientState->unpack, alignment, GL_UNPACK_ALIGNMENT);
     226    RESTORE_IF_NEQ(clientState->unpack, imageHeight, GL_UNPACK_IMAGE_HEIGHT);
     227    RESTORE_IF_NEQ(clientState->unpack, skipImages, GL_UNPACK_SKIP_IMAGES);
     228    RESTORE_IF_NEQ(clientState->unpack, swapBytes, GL_UNPACK_SWAP_BYTES);
     229    RESTORE_IF_NEQ(clientState->unpack, psLSBFirst, GL_UNPACK_LSB_FIRST);
     230}
     231
     232static void packspu_ApplyPackState()
     233{
     234    GET_THREAD(thread);
     235    ContextInfo *ctx = thread->currentContext;
     236    CRClientState *clientState = &(ctx->clientState->client);
     237
     238    APPLY_IF_NEQ(clientState->pack, rowLength, GL_PACK_ROW_LENGTH);
     239    APPLY_IF_NEQ(clientState->pack, skipRows, GL_PACK_SKIP_ROWS);
     240    APPLY_IF_NEQ(clientState->pack, skipPixels, GL_PACK_SKIP_PIXELS);
     241    APPLY_IF_NEQ(clientState->pack, alignment, GL_PACK_ALIGNMENT);
     242    APPLY_IF_NEQ(clientState->pack, imageHeight, GL_PACK_IMAGE_HEIGHT);
     243    APPLY_IF_NEQ(clientState->pack, skipImages, GL_PACK_SKIP_IMAGES);
     244    APPLY_IF_NEQ(clientState->pack, swapBytes, GL_PACK_SWAP_BYTES);
     245    APPLY_IF_NEQ(clientState->pack, psLSBFirst, GL_PACK_LSB_FIRST);
     246}
     247
     248static void packspu_RestorePackState()
     249{
     250    GET_THREAD(thread);
     251    ContextInfo *ctx = thread->currentContext;
     252    CRClientState *clientState = &(ctx->clientState->client);
     253
     254    RESTORE_IF_NEQ(clientState->pack, rowLength, GL_PACK_ROW_LENGTH);
     255    RESTORE_IF_NEQ(clientState->pack, skipRows, GL_PACK_SKIP_ROWS);
     256    RESTORE_IF_NEQ(clientState->pack, skipPixels, GL_PACK_SKIP_PIXELS);
     257    RESTORE_IF_NEQ(clientState->pack, alignment, GL_PACK_ALIGNMENT);
     258    RESTORE_IF_NEQ(clientState->pack, imageHeight, GL_PACK_IMAGE_HEIGHT);
     259    RESTORE_IF_NEQ(clientState->pack, skipImages, GL_PACK_SKIP_IMAGES);
     260    RESTORE_IF_NEQ(clientState->pack, swapBytes, GL_PACK_SWAP_BYTES);
     261    RESTORE_IF_NEQ(clientState->pack, psLSBFirst, GL_PACK_LSB_FIRST);
     262}
     263
    177264void PACKSPU_APIENTRY packspu_PixelStoref( GLenum pname, GLfloat param )
    178265{
     
    195282    ContextInfo *ctx = thread->currentContext;
    196283    CRClientState *clientState = &(ctx->clientState->client);
    197     if (pack_spu.swap)
    198         crPackDrawPixelsSWAP( width, height, format, type, pixels, &(clientState->unpack) );
    199     else
    200         crPackDrawPixels( width, height, format, type, pixels, &(clientState->unpack) );
     284
     285    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     286    {
     287        packspu_ApplyUnpackState();
     288    }
     289
     290    crPackDrawPixels( width, height, format, type, pixels, &(clientState->unpack) );
     291
     292    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     293    {
     294        packspu_RestoreUnpackState();
     295    }
    201296}
    202297
     
    208303    int writeback;   
    209304
    210     if (pack_spu.swap)
    211     {
    212         crPackReadPixelsSWAP(x, y, width, height, format, type, pixels,
    213                              &(clientState->pack), &writeback);
    214     }
    215     else
    216     {
    217         crPackReadPixels(x, y, width, height, format, type, pixels,
    218                          &(clientState->pack), &writeback);
     305    if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     306    {
     307        packspu_ApplyPackState();
     308    }
     309
     310    crPackReadPixels(x, y, width, height, format, type, pixels, &(clientState->pack), &writeback);
     311
     312    if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     313    {
     314        packspu_RestorePackState();
    219315    }
    220316
     
    231327}
    232328
     329/*@todo check with pbo's*/
    233330void PACKSPU_APIENTRY packspu_CopyPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum type )
    234331{
     
    246343    GET_CONTEXT(ctx);
    247344    CRClientState *clientState = &(ctx->clientState->client);
    248     if (pack_spu.swap)
    249         crPackBitmapSWAP( width, height, xorig, yorig, xmove, ymove, bitmap, &(clientState->unpack) );
    250     else
    251         crPackBitmap( width, height, xorig, yorig, xmove, ymove, bitmap, &(clientState->unpack) );
     345
     346    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     347    {
     348        packspu_ApplyUnpackState();
     349    }
     350
     351    crPackBitmap(width, height, xorig, yorig, xmove, ymove, bitmap, &(clientState->unpack));
     352
     353    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     354    {
     355        packspu_RestoreUnpackState();
     356    }
    252357}
    253358
     
    269374    }
    270375
     376    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     377    {
     378        packspu_ApplyUnpackState();
     379    }
     380
    271381    if (pack_spu.swap)
    272382        crPackTexImage1DSWAP( target, level, internalformat, width, border, format, type, pixels, &(clientState->unpack) );
    273383    else
    274384        crPackTexImage1D( target, level, internalformat, width, border, format, type, pixels, &(clientState->unpack) );
     385
     386    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     387    {
     388        packspu_RestoreUnpackState();
     389    }
    275390}
    276391
     
    292407    }
    293408
     409    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     410    {
     411        packspu_ApplyUnpackState();
     412    }
     413
    294414    if (pack_spu.swap)
    295415        crPackTexImage2DSWAP( target, level, internalformat, width, height, border, format, type, pixels, &(clientState->unpack) );
    296416    else
    297417        crPackTexImage2D( target, level, internalformat, width, height, border, format, type, pixels, &(clientState->unpack) );
     418
     419    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     420    {
     421        packspu_RestoreUnpackState();
     422    }
    298423}
    299424
     
    304429    CRClientState *clientState = &(ctx->clientState->client);
    305430
     431    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     432    {
     433        packspu_ApplyUnpackState();
     434    }
     435
    306436    if (pack_spu.swap)
    307437        crPackTexImage3DEXTSWAP( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
    308438    else
    309439        crPackTexImage3DEXT( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
     440
     441    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     442    {
     443        packspu_RestoreUnpackState();
     444    }
    310445}
    311446#endif
     
    316451    GET_CONTEXT(ctx);
    317452    CRClientState *clientState = &(ctx->clientState->client);
     453
     454    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     455    {
     456        packspu_ApplyUnpackState();
     457    }
     458
    318459    if (pack_spu.swap)
    319460        crPackTexImage3DSWAP( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
    320461    else
    321462        crPackTexImage3D( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
     463
     464    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     465    {
     466        packspu_RestoreUnpackState();
     467    }
    322468}
    323469#endif /* CR_OPENGL_VERSION_1_2 */
     
    334480    }
    335481
     482    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     483    {
     484        packspu_ApplyUnpackState();
     485    }
     486
    336487    if (pack_spu.swap)
    337488        crPackTexSubImage1DSWAP( target, level, xoffset, width, format, type, pixels, &(clientState->unpack) );
    338489    else
    339490        crPackTexSubImage1D( target, level, xoffset, width, format, type, pixels, &(clientState->unpack) );
     491
     492    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     493    {
     494        packspu_RestoreUnpackState();
     495    }
    340496}
    341497
     
    351507    }
    352508
     509    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     510    {
     511        packspu_ApplyUnpackState();
     512    }
     513
    353514    if (pack_spu.swap)
    354515        crPackTexSubImage2DSWAP( target, level, xoffset, yoffset, width, height, format, type, pixels, &(clientState->unpack) );
    355516    else
    356517        crPackTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels, &(clientState->unpack) );
     518
     519    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     520    {
     521        packspu_RestoreUnpackState();
     522    }
    357523}
    358524
     
    362528    GET_CONTEXT(ctx);
    363529    CRClientState *clientState = &(ctx->clientState->client);
     530
     531    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     532    {
     533        packspu_ApplyUnpackState();
     534    }
     535
    364536    if (pack_spu.swap)
    365537        crPackTexSubImage3DSWAP( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, &(clientState->unpack) );
    366538    else
    367539        crPackTexSubImage3D( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, &(clientState->unpack) );
     540
     541    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     542    {
     543        packspu_RestoreUnpackState();
     544    }
    368545}
    369546#endif /* CR_OPENGL_VERSION_1_2 */
     
    385562    CRClientState *clientState = &(ctx->clientState->client);
    386563    int writeback = 1;
    387     /* XXX note: we're not observing the pixel pack parameters here.
     564
     565    /* XXX note: we're not observing the pixel pack parameters here unless PACK PBO is bound
    388566     * To do so, we'd have to allocate a temporary image buffer (how large???)
    389567     * and copy the image to the user's buffer using the pixel pack params.
    390568     */
     569
     570    if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     571    {
     572        packspu_ApplyPackState();
     573    }
     574
    391575    if (pack_spu.swap)
    392576        crPackGetTexImageSWAP( target, level, format, type, pixels, &(clientState->pack), &writeback );
    393577    else
    394578        crPackGetTexImage( target, level, format, type, pixels, &(clientState->pack), &writeback );
     579
     580    if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     581    {
     582        packspu_RestorePackState();
     583    }
    395584
    396585#ifdef CR_ARB_pixel_buffer_object
     
    409598    int writeback = 1;
    410599
     600    if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     601    {
     602        packspu_ApplyPackState();
     603    }
     604
    411605    if (pack_spu.swap)
    412606    {
     
    416610    {
    417611        crPackGetCompressedTexImageARB( target, level, img, &writeback );
     612    }
     613
     614    if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     615    {
     616        packspu_RestorePackState();
    418617    }
    419618
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