VirtualBox

Changeset 78375 in vbox for trunk/src


Ignore:
Timestamp:
May 3, 2019 9:51:02 PM (6 years ago)
Author:
vboxsync
Message:

Additions/common/crOpengl,GuestHost/OpenGL,HostServices/SharedOpenGL: Eliminate all global variables from the state tracker library (state_tracker) in preparation of the SPU DLL merging, bugref:9435

Location:
trunk/src/VBox
Files:
113 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/crOpenGL/feedback/feedback.py

    r63942 r78375  
    9494        }
    9595
    96         return crStateRenderMode( mode );
     96        return crStateRenderMode(&feedback_spu.StateTracker, mode );
    9797}
    9898
     
    100100{
    101101        if (feedback_spu.render_mode == GL_FEEDBACK)
    102                 crStateFeedbackBegin( mode );
    103         else if (feedback_spu.render_mode == GL_SELECT)
    104                 crStateSelectBegin( mode );
     102                crStateFeedbackBegin(&feedback_spu.StateTracker, mode );
     103        else if (feedback_spu.render_mode == GL_SELECT)
     104                crStateSelectBegin(&feedback_spu.StateTracker, mode );
    105105        else
    106106        {
    107                 crStateBegin( mode );
     107                crStateBegin(&feedback_spu.StateTracker, mode );
    108108                feedback_spu.super.Begin( mode );
    109109        }
     
    113113{
    114114        if (feedback_spu.render_mode == GL_FEEDBACK)
    115                 crStateFeedbackEnd( );
    116         else if (feedback_spu.render_mode == GL_SELECT)
    117                 crStateSelectEnd( );
     115                crStateFeedbackEnd(&feedback_spu.StateTracker);
     116        else if (feedback_spu.render_mode == GL_SELECT)
     117                crStateSelectEnd(&feedback_spu.StateTracker);
    118118        else
    119119        {
    120                 crStateEnd( );
     120                crStateEnd(&feedback_spu.StateTracker);
    121121                feedback_spu.super.End( );
    122122        }
     
    125125static void FEEDBACKSPU_APIENTRY feedbackspu_Bitmap ( GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap )
    126126{
    127         crStateBitmap( width, height, xorig, yorig, xmove, ymove, bitmap );
    128 
    129         if (feedback_spu.render_mode == GL_FEEDBACK)
    130                 crStateFeedbackBitmap( width, height, xorig, yorig, xmove, ymove, bitmap );
    131         else if (feedback_spu.render_mode == GL_SELECT)
    132                 crStateSelectBitmap( width, height, xorig, yorig, xmove, ymove, bitmap );
     127        crStateBitmap(&feedback_spu.StateTracker, width, height, xorig, yorig, xmove, ymove, bitmap );
     128
     129        if (feedback_spu.render_mode == GL_FEEDBACK)
     130                crStateFeedbackBitmap(&feedback_spu.StateTracker, width, height, xorig, yorig, xmove, ymove, bitmap );
     131        else if (feedback_spu.render_mode == GL_SELECT)
     132                crStateSelectBitmap(&feedback_spu.StateTracker, width, height, xorig, yorig, xmove, ymove, bitmap );
    133133        else
    134134                feedback_spu.super.Bitmap( width, height, xorig, yorig, xmove, ymove, bitmap );
     
    138138{
    139139        if (feedback_spu.render_mode == GL_FEEDBACK)
    140                 crStateFeedbackCopyPixels( x, y, width, height, type );
    141         else if (feedback_spu.render_mode == GL_SELECT)
    142                 crStateSelectCopyPixels( x, y, width, height, type );
     140                crStateFeedbackCopyPixels(&feedback_spu.StateTracker, x, y, width, height, type );
     141        else if (feedback_spu.render_mode == GL_SELECT)
     142                crStateSelectCopyPixels(&feedback_spu.StateTracker, x, y, width, height, type );
    143143        else
    144144                feedback_spu.super.CopyPixels( x, y, width, height, type );
     
    148148{
    149149        if (feedback_spu.render_mode == GL_FEEDBACK)
    150                 crStateFeedbackDrawPixels( width, height, format, type, pixels );
    151         else if (feedback_spu.render_mode == GL_SELECT)
    152                 crStateSelectDrawPixels( width, height, format, type, pixels );
     150                crStateFeedbackDrawPixels(&feedback_spu.StateTracker, width, height, format, type, pixels );
     151        else if (feedback_spu.render_mode == GL_SELECT)
     152                crStateSelectDrawPixels(&feedback_spu.StateTracker, width, height, format, type, pixels );
    153153        else
    154154                feedback_spu.super.DrawPixels( width, height, format, type, pixels );
     
    161161            pname == GL_FEEDBACK_BUFFER_TYPE ||
    162162            pname == GL_SELECTION_BUFFER_SIZE)
    163                 crStateFeedbackGetBooleanv( pname, params );
    164         else
    165         if (pname == GL_VIEWPORT && feedback_spu.default_viewport)
    166                 crStateGetBooleanv( pname, params );
     163                crStateFeedbackGetBooleanv(&feedback_spu.StateTracker, pname, params );
     164        else
     165        if (pname == GL_VIEWPORT && feedback_spu.default_viewport)
     166                crStateGetBooleanv(&feedback_spu.StateTracker, pname, params );
    167167        else
    168168                feedback_spu.super.GetBooleanv( pname, params );
     
    175175            pname == GL_FEEDBACK_BUFFER_TYPE ||
    176176            pname == GL_SELECTION_BUFFER_SIZE)
    177                 crStateFeedbackGetDoublev( pname, params );
    178         else
    179         if (pname == GL_VIEWPORT && feedback_spu.default_viewport)
    180                 crStateGetDoublev( pname, params );
     177                crStateFeedbackGetDoublev(&feedback_spu.StateTracker, pname, params );
     178        else
     179        if (pname == GL_VIEWPORT && feedback_spu.default_viewport)
     180                crStateGetDoublev(&feedback_spu.StateTracker, pname, params );
    181181        else
    182182                feedback_spu.super.GetDoublev( pname, params );
     
    189189            pname == GL_FEEDBACK_BUFFER_TYPE ||
    190190            pname == GL_SELECTION_BUFFER_SIZE)
    191                 crStateFeedbackGetFloatv( pname, params );
    192         else
    193         if (pname == GL_VIEWPORT && feedback_spu.default_viewport)
    194                 crStateGetFloatv( pname, params );
     191                crStateFeedbackGetFloatv(&feedback_spu.StateTracker, pname, params );
     192        else
     193        if (pname == GL_VIEWPORT && feedback_spu.default_viewport)
     194                crStateGetFloatv(&feedback_spu.StateTracker, pname, params );
    195195        else
    196196                feedback_spu.super.GetFloatv( pname, params );
     
    203203            pname == GL_FEEDBACK_BUFFER_TYPE ||
    204204            pname == GL_SELECTION_BUFFER_SIZE)
    205                 crStateFeedbackGetIntegerv( pname, params );
    206         else
    207         if (pname == GL_VIEWPORT && feedback_spu.default_viewport)
    208                 crStateGetIntegerv( pname, params );
     205                crStateFeedbackGetIntegerv(&feedback_spu.StateTracker, pname, params );
     206        else
     207        if (pname == GL_VIEWPORT && feedback_spu.default_viewport)
     208                crStateGetIntegerv(&feedback_spu.StateTracker, pname, params );
    209209        else
    210210                feedback_spu.super.GetIntegerv( pname, params );
  • trunk/src/VBox/Additions/common/crOpenGL/feedback/feedback_context.c

    r78341 r78375  
    5050    }
    5151
    52     feedback_spu.context[slot].clientState = crStateCreateContext(NULL, visual, NULL);
     52    feedback_spu.context[slot].clientState = crStateCreateContext(&feedback_spu.StateTracker, NULL, visual, NULL);
    5353    feedback_spu.context[slot].clientCtx = ctx;
    5454
     
    7777        CRASSERT(slot < feedback_spu.numContexts);
    7878
    79         crStateMakeCurrent(feedback_spu.context[slot].clientState);
     79        crStateMakeCurrent(&feedback_spu.StateTracker, feedback_spu.context[slot].clientState);
    8080
    81         crStateGetIntegerv(GL_RENDER_MODE, &oldmode);
     81        crStateGetIntegerv(&feedback_spu.StateTracker, GL_RENDER_MODE, &oldmode);
    8282
    8383        if (oldmode!=feedback_spu.render_mode)
     
    8888    else
    8989    {
    90         crStateMakeCurrent(NULL);
     90        crStateMakeCurrent(&feedback_spu.StateTracker, NULL);
    9191    }
    9292
     
    107107        CRASSERT(slot < feedback_spu.numContexts);
    108108
    109         crStateDestroyContext(feedback_spu.context[slot].clientState);
     109        crStateDestroyContext(&feedback_spu.StateTracker, feedback_spu.context[slot].clientState);
    110110
    111111        feedback_spu.context[slot].clientState = NULL;
  • trunk/src/VBox/Additions/common/crOpenGL/feedback/feedback_state.py

    r63942 r78375  
    2929        print('%s FEEDBACKSPU_APIENTRY feedbackspu_%s(%s)' % (return_type, func_name, apiutil.MakeDeclarationString(params)))
    3030        print('{')
    31         print('\tcrState%s(%s);' % (func_name, apiutil.MakeCallString(params)))
     31        if len(params) == 0:
     32            print('\tcrState%s(&feedback_spu.StateTracker);' % (func_name,))
     33        else:
     34            print('\tcrState%s(&feedback_spu.StateTracker, %s);' % (func_name, apiutil.MakeCallString(params)))
    3235        print('')
    3336        print('\tfeedback_spu.super.%s(%s);' % (func_name, apiutil.MakeCallString(params)))
  • trunk/src/VBox/Additions/common/crOpenGL/feedback/feedbackspu.h

    r78341 r78375  
    4343
    4444    CRmutex mutex;
     45
     46    /** The state tracker state. */
     47    CRStateTracker StateTracker;
    4548} feedbackSPU;
    4649
  • trunk/src/VBox/Additions/common/crOpenGL/feedback/feedbackspu_init.c

    r78341 r78375  
    4545
    4646        /* create/init default state tracker */
    47         crStateInit();
     47        crStateInit(&feedback_spu.StateTracker);
    4848
    49     feedback_spu.defaultctx = crStateCreateContext(NULL, 0, NULL);
    50     crStateSetCurrent(feedback_spu.defaultctx);
     49    feedback_spu.defaultctx = crStateCreateContext(&feedback_spu.StateTracker, NULL, 0, NULL);
     50    crStateSetCurrent(&feedback_spu.StateTracker, feedback_spu.defaultctx);
    5151
    5252    feedback_spu.numContexts = 0;
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu.h

    r78341 r78375  
    109109    int numContexts;
    110110    ContextInfo context[CR_MAX_CONTEXTS];
     111
     112    /** State tracker state. */
     113    CRStateTracker    StateTracker;
    111114} PackSPU;
    112115
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_beginend.py

    r78190 r78375  
    3636        GLboolean serverArrays = GL_FALSE;
    3737        if (ctx->clientState->extensions.ARB_vertex_buffer_object)
    38             serverArrays = crStateUseServerArrays();
     38            serverArrays = crStateUseServerArrays(&pack_spu.StateTracker);
    3939        if (serverArrays) {
    4040            CRClientState *clientState = &(ctx->clientState->client);
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_bufferobject.c

    r78190 r78375  
    3131
    3232    CRASSERT(GL_TRUE == ctx->clientState->bufferobject.retainBufferData);
    33     buffer = crStateMapBufferARB(target, access);
     33    buffer = crStateMapBufferARB(&pack_spu.StateTracker, target, access);
    3434
    3535#ifdef CR_ARB_pixel_buffer_object
     
    6767#endif
    6868
    69     crStateGetBufferSubDataARB(target, offset, size, data);
     69    crStateGetBufferSubDataARB(&pack_spu.StateTracker, target, offset, size, data);
    7070}
    7171
     
    8686
    8787    CRASSERT(GL_TRUE == ctx->clientState->bufferobject.retainBufferData);
    88     crStateUnmapBufferARB( target );
     88    crStateUnmapBufferARB(&pack_spu.StateTracker, target );
    8989
    9090    return GL_TRUE;
     
    9696{
    9797    /*crDebug("packspu_BufferDataARB size:%d", size);*/
    98     crStateBufferDataARB(target, size, data, usage);
     98    crStateBufferDataARB(&pack_spu.StateTracker,target, size, data, usage);
    9999    crPackBufferDataARB(target, size, data, usage);
    100100}
     
    104104{
    105105    /*crDebug("packspu_BufferSubDataARB size:%d", size);*/
    106     crStateBufferSubDataARB(target, offset, size, data);
     106    crStateBufferSubDataARB(&pack_spu.StateTracker,target, offset, size, data);
    107107    crPackBufferSubDataARB(target, offset, size, data);
    108108}
     
    112112packspu_GetBufferPointervARB(GLenum target, GLenum pname, GLvoid **params)
    113113{
    114     crStateGetBufferPointervARB( target, pname, params );
     114    crStateGetBufferPointervARB(&pack_spu.StateTracker, target, pname, params );
    115115}
    116116
     
    119119packspu_GetBufferParameterivARB( GLenum target, GLenum pname, GLint * params )
    120120{
    121     crStateGetBufferParameterivARB( target, pname, params );
     121    crStateGetBufferParameterivARB(&pack_spu.StateTracker, target, pname, params );
    122122}
    123123
     
    128128packspu_BindBufferARB( GLenum target, GLuint buffer )
    129129{
    130     crStateBindBufferARB(target, buffer);
     130    crStateBindBufferARB(&pack_spu.StateTracker, target, buffer);
    131131    crPackBindBufferARB(target, buffer);
    132132}
     
    145145    CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
    146146
    147     crStateRegBuffers(n, buffer);
     147    crStateRegBuffers(&pack_spu.StateTracker,n, buffer);
    148148}
    149149
    150150void PACKSPU_APIENTRY packspu_DeleteBuffersARB( GLsizei n, const GLuint * buffer )
    151151{
    152     crStateDeleteBuffersARB( n, buffer );
     152    crStateDeleteBuffersARB(&pack_spu.StateTracker, n, buffer );
    153153    crPackDeleteBuffersARB(n, buffer);
    154154}
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_client.c

    r78190 r78375  
    1919    }
    2020#endif
    21     crStateFogCoordPointerEXT( type, stride, pointer );
     21    crStateFogCoordPointerEXT(&pack_spu.StateTracker, type, stride, pointer );
    2222}
    2323
     
    3030    }
    3131#endif
    32     crStateColorPointer( size, type, stride, pointer );
     32    crStateColorPointer(&pack_spu.StateTracker, size, type, stride, pointer );
    3333}
    3434
     
    4141    }
    4242#endif
    43     crStateSecondaryColorPointerEXT( size, type, stride, pointer );
     43    crStateSecondaryColorPointerEXT(&pack_spu.StateTracker, size, type, stride, pointer );
    4444}
    4545
     
    5353    }
    5454#endif
    55     crStateVertexPointer( size, type, stride, pointer );
     55    crStateVertexPointer(&pack_spu.StateTracker, size, type, stride, pointer );
    5656}
    5757
     
    6464    }
    6565#endif
    66     crStateTexCoordPointer( size, type, stride, pointer );
     66    crStateTexCoordPointer(&pack_spu.StateTracker, size, type, stride, pointer );
    6767}
    6868
     
    7575    }
    7676#endif
    77     crStateNormalPointer( type, stride, pointer );
     77    crStateNormalPointer(&pack_spu.StateTracker, type, stride, pointer );
    7878}
    7979
     
    8686    }
    8787#endif
    88     crStateEdgeFlagPointer( stride, pointer );
     88    crStateEdgeFlagPointer(&pack_spu.StateTracker, stride, pointer );
    8989}
    9090
     
    9797    }
    9898#endif
    99     crStateVertexAttribPointerARB( index, size, type, normalized, stride, pointer );
     99    crStateVertexAttribPointerARB(&pack_spu.StateTracker, index, size, type, normalized, stride, pointer );
    100100}
    101101
     
    108108    }
    109109#endif
    110     crStateVertexAttribPointerNV( index, size, type, stride, pointer );
     110    crStateVertexAttribPointerNV(&pack_spu.StateTracker, index, size, type, stride, pointer );
    111111}
    112112
     
    119119    }
    120120#endif
    121     crStateIndexPointer(type, stride, pointer);
     121    crStateIndexPointer(&pack_spu.StateTracker, type, stride, pointer);
    122122}
    123123
    124124void PACKSPU_APIENTRY packspu_GetPointerv( GLenum pname, GLvoid **params )
    125125{
    126     crStateGetPointerv( pname, params );
     126    crStateGetPointerv(&pack_spu.StateTracker, pname, params );
    127127}
    128128
     
    138138    /*crDebug("packspu_InterleavedArrays");*/
    139139
    140     crStateInterleavedArrays( format, stride, pointer );
     140    crStateInterleavedArrays(&pack_spu.StateTracker, format, stride, pointer );
    141141}
    142142
     
    219219#ifdef DEBUG
    220220    {
    221         CRContext *pCurState = crStateGetCurrent();
     221        CRContext *pCurState = crStateGetCurrent(&pack_spu.StateTracker);
    222222
    223223        Assert(g == pCurState);
     
    282282    {
    283283        CRContext *g = pRestoreCtx->pCtx->clientState;
    284         CRContext *pCurState = crStateGetCurrent();
     284        CRContext *pCurState = crStateGetCurrent(&pack_spu.StateTracker);
    285285
    286286        Assert(g == pCurState);
     
    319319        if (ctx->clientState->extensions.ARB_vertex_buffer_object)
    320320        {
    321             serverArrays = crStateUseServerArrays();
     321            serverArrays = crStateUseServerArrays(&pack_spu.StateTracker);
    322322            if (ctx->fCheckZerroVertAttr)
    323323                cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
     
    395395    {
    396396        GET_CONTEXT(ctx);
    397         elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
     397        elementsBuffer = crStateGetCurrent(&pack_spu.StateTracker)->bufferobject.elementsBuffer;
    398398        /*crDebug("DrawElements count=%d, indices=%p", count, indices);*/
    399399        if (ctx->clientState->extensions.ARB_vertex_buffer_object)
    400400        {
    401             serverArrays = crStateUseServerArrays();
     401            serverArrays = crStateUseServerArrays(&pack_spu.StateTracker);
    402402            if (ctx->fCheckZerroVertAttr)
    403403                cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
     
    452452        if ((max-min)<(GLuint)(2*count))
    453453        {
    454             crStateLockArraysEXT(min, max-min+1);
     454            crStateLockArraysEXT(&pack_spu.StateTracker, min, max-min+1);
    455455
    456456            serverArrays = crStateUseServerArrays();
     
    461461            else
    462462            {
    463                 crStateUnlockArraysEXT();
     463                crStateUnlockArraysEXT(&pack_spu.StateTracker);
    464464            }
    465465        }
     
    539539        if (ctx->clientState->extensions.ARB_vertex_buffer_object)
    540540        {
    541              serverArrays = crStateUseServerArrays();
     541             serverArrays = crStateUseServerArrays(&pack_spu.StateTracker);
    542542             if (ctx->fCheckZerroVertAttr)
    543543                 cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
     
    608608        if (ctx->clientState->extensions.ARB_vertex_buffer_object)
    609609        {
    610              serverArrays = crStateUseServerArrays();
     610             serverArrays = crStateUseServerArrays(&pack_spu.StateTracker);
    611611             if (ctx->fCheckZerroVertAttr)
    612612                 cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
     
    617617    if (!serverArrays && !ctx->clientState->client.array.locked && (count>3))
    618618    {
    619         crStateLockArraysEXT(first, count);
    620         serverArrays = crStateUseServerArrays();
     619        crStateLockArraysEXT(&pack_spu.StateTracker, first, count);
     620        serverArrays = crStateUseServerArrays(&pack_spu.StateTracker);
    621621        if (serverArrays)
    622622        {
     
    625625        else
    626626        {
    627             crStateUnlockArraysEXT();
     627            crStateUnlockArraysEXT(&pack_spu.StateTracker);
    628628        }
    629629    }
     
    714714void PACKSPU_APIENTRY packspu_EnableClientState( GLenum array )
    715715{
    716     crStateEnableClientState(array);
     716    crStateEnableClientState(&pack_spu.StateTracker, array);
    717717    crPackEnableClientState(array);
    718718}
     
    720720void PACKSPU_APIENTRY packspu_DisableClientState( GLenum array )
    721721{
    722     crStateDisableClientState(array);
     722    crStateDisableClientState(&pack_spu.StateTracker, array);
    723723    crPackDisableClientState(array);
    724724}
     
    726726void PACKSPU_APIENTRY packspu_ClientActiveTextureARB( GLenum texUnit )
    727727{
    728     crStateClientActiveTextureARB(texUnit);
     728    crStateClientActiveTextureARB(&pack_spu.StateTracker, texUnit);
    729729    crPackClientActiveTextureARB(texUnit);
    730730}
     
    732732void PACKSPU_APIENTRY packspu_EnableVertexAttribArrayARB(GLuint index)
    733733{
    734     crStateEnableVertexAttribArrayARB(index);
     734    crStateEnableVertexAttribArrayARB(&pack_spu.StateTracker, index);
    735735    crPackEnableVertexAttribArrayARB(index);
    736736}
     
    739739void PACKSPU_APIENTRY packspu_DisableVertexAttribArrayARB(GLuint index)
    740740{
    741     crStateDisableVertexAttribArrayARB(index);
     741    crStateDisableVertexAttribArrayARB(&pack_spu.StateTracker, index);
    742742    crPackDisableVertexAttribArrayARB(index);
    743743}
     
    747747    if (cap!=GL_LIGHT_MODEL_TWO_SIDE)
    748748    {
    749         crStateEnable(cap);
     749        crStateEnable(&pack_spu.StateTracker, cap);
    750750        crPackEnable(cap);
    751751    }
     
    758758            g_glmts1_warn=1;
    759759        }
    760         crStateLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
     760        crStateLightModeli(&pack_spu.StateTracker, GL_LIGHT_MODEL_TWO_SIDE, 1);
    761761        crPackLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
    762762    }
     
    768768    if (cap!=GL_LIGHT_MODEL_TWO_SIDE)
    769769    {
    770         crStateDisable(cap);
     770        crStateDisable(&pack_spu.StateTracker, cap);
    771771        crPackDisable(cap);
    772772    }
     
    779779            g_glmts0_warn=1;
    780780        }
    781         crStateLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
     781        crStateLightModeli(&pack_spu.StateTracker, GL_LIGHT_MODEL_TWO_SIDE, 0);
    782782        crPackLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
    783783    }
     
    786786GLboolean PACKSPU_APIENTRY packspu_IsEnabled(GLenum cap)
    787787{
    788     GLboolean res = crStateIsEnabled(cap);
     788    GLboolean res = crStateIsEnabled(&pack_spu.StateTracker, cap);
    789789#ifdef DEBUG
    790790    {
     
    804804void PACKSPU_APIENTRY packspu_PushClientAttrib( GLbitfield mask )
    805805{
    806     crStatePushClientAttrib(mask);
     806    crStatePushClientAttrib(&pack_spu.StateTracker, mask);
    807807    crPackPushClientAttrib(mask);
    808808}
     
    810810void PACKSPU_APIENTRY packspu_PopClientAttrib( void )
    811811{
    812     crStatePopClientAttrib();
     812    crStatePopClientAttrib(&pack_spu.StateTracker);
    813813    crPackPopClientAttrib();
    814814}
     
    818818    if (first>=0 && count>0)
    819819    {
    820         crStateLockArraysEXT(first, count);
     820        crStateLockArraysEXT(&pack_spu.StateTracker, first, count);
    821821        /*Note: this is a workaround for quake3 based apps.
    822822          It's modifying vertex data between glLockArraysEXT and glDrawElements calls,
     
    838838    }
    839839
    840     crStateUnlockArraysEXT();
    841 }
     840    crStateUnlockArraysEXT(&pack_spu.StateTracker);
     841}
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_context.c

    r78341 r78375  
    394394    /* Fill in the new context info */
    395395    /* XXX fix-up sharedCtx param here */
    396     pack_spu.context[slot].clientState = crStateCreateContext(NULL, visual, NULL);
     396    pack_spu.context[slot].clientState = crStateCreateContext(&pack_spu.StateTracker, NULL, visual, NULL);
    397397    pack_spu.context[slot].clientState->bufferobject.retainBufferData = GL_TRUE;
    398398    pack_spu.context[slot].serverCtx = serverCtx;
     
    442442
    443443        crPackDestroyContext( context->serverCtx );
    444         crStateDestroyContext( context->clientState );
     444        crStateDestroyContext(&pack_spu.StateTracker, context->clientState );
    445445
    446446        context->clientState = NULL;
     
    463463            crPackSetContext(NULL);
    464464        }
    465         crStateMakeCurrent( NULL );
     465        crStateMakeCurrent(&pack_spu.StateTracker, NULL);
    466466    }
    467467    else
     
    540540        }
    541541
    542         crStateMakeCurrent( newCtx->clientState );
     542        crStateMakeCurrent(&pack_spu.StateTracker, newCtx->clientState );
    543543        //crStateSetCurrentPointers(newCtx->clientState, &thread->packer->current);
    544544        serverCtx = pack_spu.context[slot].serverCtx;
    545545    }
    546546    else {
    547         crStateMakeCurrent( NULL );
     547        crStateMakeCurrent(&pack_spu.StateTracker, NULL );
    548548        if (CRPACKSPU_IS_WDDM_CRHGSMI())
    549549        {
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_framebuffer.c

    r78190 r78375  
    2525packspu_FramebufferTexture1DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
    2626{
    27     crStateFramebufferTexture1DEXT(target, attachment, textarget, texture, level);
     27    crStateFramebufferTexture1DEXT(&pack_spu.StateTracker, target, attachment, textarget, texture, level);
    2828    crPackFramebufferTexture1DEXT(target, attachment, textarget, texture, level);
    2929}
     
    3232packspu_FramebufferTexture2DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
    3333{
    34     crStateFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
     34    crStateFramebufferTexture2DEXT(&pack_spu.StateTracker, target, attachment, textarget, texture, level);
    3535    crPackFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
    3636}
     
    3939packspu_FramebufferTexture3DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset)
    4040{
    41     crStateFramebufferTexture3DEXT(target, attachment, textarget, texture, level, zoffset);
     41    crStateFramebufferTexture3DEXT(&pack_spu.StateTracker, target, attachment, textarget, texture, level, zoffset);
    4242    crPackFramebufferTexture3DEXT(target, attachment, textarget, texture, level, zoffset);
    4343}
     
    4646packspu_BindFramebufferEXT(GLenum target, GLuint framebuffer)
    4747{
    48         crStateBindFramebufferEXT(target, framebuffer);
     48    crStateBindFramebufferEXT(&pack_spu.StateTracker, target, framebuffer);
    4949    crPackBindFramebufferEXT(target, framebuffer);
    5050}
     
    5353packspu_DeleteFramebuffersEXT(GLsizei n, const GLuint * framebuffers)
    5454{
    55         crStateDeleteFramebuffersEXT(n, framebuffers);
     55    crStateDeleteFramebuffersEXT(&pack_spu.StateTracker, n, framebuffers);
    5656    crPackDeleteFramebuffersEXT(n, framebuffers);
    5757}
     
    6060packspu_DeleteRenderbuffersEXT(GLsizei n, const GLuint * renderbuffers)
    6161{
    62         crStateDeleteRenderbuffersEXT(n, renderbuffers);
     62    crStateDeleteRenderbuffersEXT(&pack_spu.StateTracker, n, renderbuffers);
    6363    crPackDeleteRenderbuffersEXT(n, renderbuffers);
    6464}
     
    6767packspu_FramebufferRenderbufferEXT(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
    6868{
    69         crStateFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, renderbuffer);
     69    crStateFramebufferRenderbufferEXT(&pack_spu.StateTracker, target, attachment, renderbuffertarget, renderbuffer);
    7070    crPackFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, renderbuffer);
    7171}
     
    7474packspu_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
    7575{
    76     crStateBindRenderbufferEXT(target, renderbuffer);
     76    crStateBindRenderbufferEXT(&pack_spu.StateTracker, target, renderbuffer);
    7777    crPackBindRenderbufferEXT(target, renderbuffer);
    7878}
     
    8181packspu_CheckFramebufferStatusEXT(GLenum target)
    8282{
    83         GET_THREAD(thread);
    84         int writeback = 1;
    85     GLenum status = crStateCheckFramebufferStatusEXT(target);
     83    GET_THREAD(thread);
     84    int writeback = 1;
     85    GLenum status = crStateCheckFramebufferStatusEXT(&pack_spu.StateTracker, target);
    8686
    8787    if (status!=GL_FRAMEBUFFER_UNDEFINED)
     
    9292    crPackCheckFramebufferStatusEXT(target, &status, &writeback);
    9393
    94         packspuFlush((void *) thread);
     94    packspuFlush((void *) thread);
    9595    CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
    9696
    97     crStateSetFramebufferStatus(target, status);
     97    crStateSetFramebufferStatus(&pack_spu.StateTracker, target, status);
    9898    return status;
    9999}
     
    112112    CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
    113113
    114     crStateRegFramebuffers(n, framebuffers);
     114    crStateRegFramebuffers(&pack_spu.StateTracker, n, framebuffers);
    115115}
    116116
     
    128128    CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
    129129
    130     crStateRegRenderbuffers(n, renderbuffers);
     130    crStateRegRenderbuffers(&pack_spu.StateTracker, n, renderbuffers);
    131131}
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_get.py

    r78190 r78375  
    118118                %s localparams;
    119119                localparams = (%s) crAlloc(__numValues(pname) * sizeof(*localparams));
    120                 crState%s(pname, localparams);
     120                crState%s(&pack_spu.StateTracker, pname, localparams);
    121121                crPack%s(%s, &writeback);
    122122                packspuFlush( (void *) thread );
     
    136136#endif
    137137            {
    138                 crState%s(pname, params);
     138                crState%s(&pack_spu.StateTracker, pname, params);
    139139                return;
    140140            }
     
    150150        %s localparams;
    151151        localparams = (%s) crAlloc(__numValues(pname) * sizeof(*localparams));
    152         crState%s(index, pname, localparams);
     152        crState%s(&pack_spu.StateTracker, index, pname, localparams);
    153153        crPack%s(index, %s, &writeback);
    154154        packspuFlush( (void *) thread );
     
    164164        crFree(localparams);
    165165#else
    166         crState%s(pname, params);
     166        crState%s(&pack_spu.StateTracker, pname, params);
    167167#endif
    168168        return;
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_getstring.c

    r78190 r78375  
    149149#endif
    150150            {
    151                 return crStateGetString(name);
     151                return crStateGetString(&pack_spu.StateTracker, name);
    152152            }
    153153        case GL_RENDERER:
     
    161161#endif
    162162            {
    163                 return crStateGetString(name);
     163                return crStateGetString(&pack_spu.StateTracker, name);
    164164            }
    165165
     
    188188#endif
    189189        default:
    190             return crStateGetString(name);
     190            return crStateGetString(&pack_spu.StateTracker, name);
    191191    }
    192192}
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_glsl.c

    r78190 r78375  
    3636    packspuFlush((void *) thread);
    3737    CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
    38     crStateCreateProgram(return_val);
     38    crStateCreateProgram(&pack_spu.StateTracker, return_val);
    3939
    4040    return return_val;
     
    5959GLint PACKSPU_APIENTRY packspu_GetUniformLocation(GLuint program, const char * name)
    6060{
    61     if (!crStateIsProgramUniformsCached(program))
     61    if (!crStateIsProgramUniformsCached(&pack_spu.StateTracker, program))
    6262    {
    6363        GET_THREAD(thread);
     
    8282        CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
    8383
    84         crStateGLSLProgramCacheUniforms(program, pData[0], &pData[1]);
    85 
    86         CRASSERT(crStateIsProgramUniformsCached(program));
     84        crStateGLSLProgramCacheUniforms(&pack_spu.StateTracker, program, pData[0], &pData[1]);
     85
     86        CRASSERT(crStateIsProgramUniformsCached(&pack_spu.StateTracker, program));
    8787
    8888        crFree(pData);
     
    9090
    9191    /*crDebug("packspu_GetUniformLocation(%d, %s)=%i", program, name, crStateGetUniformLocation(program, name));*/
    92     return crStateGetUniformLocation(program, name);
     92    return crStateGetUniformLocation(&pack_spu.StateTracker, program, name);
    9393}
    9494
     
    114114        return packspu_GetAttribLocationUnchached(program, name);
    115115
    116     if (!crStateIsProgramAttribsCached(program))
     116    if (!crStateIsProgramAttribsCached(&pack_spu.StateTracker, program))
    117117    {
    118118        GET_THREAD(thread);
     
    137137        CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
    138138
    139         crStateGLSLProgramCacheAttribs(program, pData[0], &pData[1]);
    140 
    141         CRASSERT(crStateIsProgramAttribsCached(program));
     139        crStateGLSLProgramCacheAttribs(&pack_spu.StateTracker, program, pData[0], &pData[1]);
     140
     141        CRASSERT(crStateIsProgramAttribsCached(&pack_spu.StateTracker, program));
    142142
    143143        crFree(pData);
     
    145145
    146146    /*crDebug("packspu_GetAttribLocation(%d, %s)=%i", program, name, crStateGetAttribLocation(program, name));*/
    147     return crStateGetAttribLocation(program, name);
     147    return crStateGetAttribLocation(&pack_spu.StateTracker, program, name);
    148148}
    149149
     
    168168void PACKSPU_APIENTRY packspu_DeleteProgram(GLuint program)
    169169{
    170     crStateDeleteProgram(program);
     170    crStateDeleteProgram(&pack_spu.StateTracker, program);
    171171    crPackDeleteProgram(program);
    172172}
     
    174174void PACK_APIENTRY packspu_DeleteObjectARB(VBoxGLhandleARB obj)
    175175{
    176     GLuint hwid = crStateGetProgramHWID(obj);
     176    GLuint hwid = crStateGetProgramHWID(&pack_spu.StateTracker, obj);
    177177
    178178    CRASSERT(obj);
     
    182182    if (hwid)
    183183    {
    184         crStateDeleteProgram(obj);
     184        crStateDeleteProgram(&pack_spu.StateTracker, obj);
    185185    }
    186186
     
    206206#endif
    207207
    208     crStateLinkProgram(program);
     208    crStateLinkProgram(&pack_spu.StateTracker, program);
    209209    crPackLinkProgram(program);
    210210
     
    214214    if (!linkStatus)
    215215    {
    216         CRContext *ctx = crStateGetCurrent();
     216        CRContext *ctx = crStateGetCurrent(&pack_spu.StateTracker);
    217217        packspu_RecCheckInitRec();
    218218        crRecDumpProgram(&pack_spu.Recorder, ctx, program, program);
     
    235235    if (!compileStatus)
    236236    {
    237         CRContext *ctx = crStateGetCurrent();
     237        CRContext *ctx = crStateGetCurrent(&pack_spu.StateTracker);
    238238        packspu_RecCheckInitRec();
    239239        crRecDumpShader(&pack_spu.Recorder, ctx, shader, shader);
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_init.c

    r78341 r78375  
    77#include "cr_mem.h"
    88#include "cr_spu.h"
    9 #include "cr_glstate.h"
    109#include "packspu.h"
    1110#include "cr_packfunctions.h"
     
    2120
    2221PackSPU pack_spu;
     22DECLHIDDEN(PCRStateTracker) g_pStateTracker;
    2323
    2424CRtsd _PackTSD;
     
    9393
    9494    packspuCreateFunctions();
    95     crStateInit();
     95    crStateInit(&pack_spu.StateTracker);
     96    g_pStateTracker = &pack_spu.StateTracker;
    9697
    9798    return &pack_functions;
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c

    r78341 r78375  
    9898    GLint buffer;
    9999
    100     crStateGetIntegerv(GL_DRAW_BUFFER, &buffer);
     100    crStateGetIntegerv(&pack_spu.StateTracker, GL_DRAW_BUFFER, &buffer);
    101101    /*Usually buffer==GL_BACK, so put this extra check to simplify boolean eval on runtime*/
    102102    return  (buffer != GL_BACK)
     
    116116    hadtoflush = packspuSyncOnFlushes();
    117117
    118     crStateDrawBuffer(mode);
     118    crStateDrawBuffer(&pack_spu.StateTracker, mode);
    119119    crPackDrawBuffer(mode);
    120120
     
    197197void PACKSPU_APIENTRY packspu_NewList(GLuint list, GLenum mode)
    198198{
    199     crStateNewList(list, mode);
     199    crStateNewList(&pack_spu.StateTracker, list, mode);
    200200    crPackNewList(list, mode);
    201201}
     
    203203void PACKSPU_APIENTRY packspu_EndList()
    204204{
    205     crStateEndList();
     205    crStateEndList(&pack_spu.StateTracker);
    206206    crPackEndList();
    207207}
     
    366366    crPackGetPolygonStipple( mask, &writeback );
    367367#ifdef CR_ARB_pixel_buffer_object
    368     if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     368    if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    369369#endif
    370370    {
     
    381381    crPackGetPixelMapfv( map, values, &writeback );
    382382#ifdef CR_ARB_pixel_buffer_object
    383     if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     383    if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    384384#endif
    385385    {
     
    397397
    398398#ifdef CR_ARB_pixel_buffer_object
    399     if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     399    if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    400400#endif
    401401    {
     
    412412    crPackGetPixelMapusv( map, values, &writeback );
    413413#ifdef CR_ARB_pixel_buffer_object
    414     if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     414    if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    415415#endif
    416416    {
     
    449449            return;
    450450        case GL_SHARE_CONTEXT_RESOURCES_CR:
    451             crStateShareContext(value);
     451            crStateShareContext(&pack_spu.StateTracker, value);
    452452            break;
    453453        case GL_RCUSAGE_TEXTURE_SET_CR:
    454454        {
    455455            Assert(value);
    456             crStateSetTextureUsed(value, GL_TRUE);
     456            crStateSetTextureUsed(&pack_spu.StateTracker, value, GL_TRUE);
    457457            break;
    458458        }
     
    462462#ifdef DEBUG
    463463            {
    464                 CRContext *pCurState = crStateGetCurrent();
     464                CRContext *pCurState = crStateGetCurrent(&pack_spu.StateTracker);
    465465                CRTextureObj *tobj = (CRTextureObj*)crHashtableSearch(pCurState->shared->textureTable, value);
    466466                Assert(tobj);
    467467            }
    468468#endif
    469             crStateSetTextureUsed(value, GL_FALSE);
     469            crStateSetTextureUsed(&pack_spu.StateTracker, value, GL_FALSE);
    470470            break;
    471471        }
     
    481481    int writeback = 1;
    482482    GLenum return_val = (GLenum) 0;
    483     CRContext *pCurState = crStateGetCurrent();
     483    CRContext *pCurState = crStateGetCurrent(&pack_spu.StateTracker);
    484484    NOREF(pCurState); /* it's unused, but I don't know about side effects.. */
    485485
     
    620620    crSetTSD(&_PackTSD, NULL);
    621621
    622     crStateVBoxAttachThread();
     622    crStateVBoxAttachThread(&pack_spu.StateTracker);
    623623}
    624624
     
    701701    }
    702702
    703     crStateVBoxDetachThread();
     703    crStateVBoxDetachThread(&pack_spu.StateTracker);
    704704}
    705705
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_pixel.c

    r78190 r78375  
    269269     * image in a canonical layout (see util/pixel.c).
    270270     */
    271     crStatePixelStoref( pname, param );
     271    crStatePixelStoref(&pack_spu.StateTracker, pname, param );
    272272}
    273273
    274274void PACKSPU_APIENTRY packspu_PixelStorei( GLenum pname, GLint param )
    275275{
    276     crStatePixelStorei( pname, param );
     276    crStatePixelStorei(&pack_spu.StateTracker, pname, param );
    277277}
    278278
     
    283283    CRClientState *clientState = &(ctx->clientState->client);
    284284
    285     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     285    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    286286    {
    287287        packspu_ApplyUnpackState();
     
    290290    crPackDrawPixels( width, height, format, type, pixels, &(clientState->unpack) );
    291291
    292     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     292    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    293293    {
    294294        packspu_RestoreUnpackState();
     
    303303    int writeback;
    304304
    305     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     305    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    306306    {
    307307        packspu_ApplyPackState();
     
    310310    crPackReadPixels(x, y, width, height, format, type, pixels, &(clientState->pack), &writeback);
    311311
    312     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     312    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    313313    {
    314314        packspu_RestorePackState();
     
    316316
    317317#ifdef CR_ARB_pixel_buffer_object
    318     if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     318    if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    319319#endif
    320320    {
     
    340340    CRClientState *clientState = &(ctx->clientState->client);
    341341
    342     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     342    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    343343    {
    344344        packspu_ApplyUnpackState();
     
    347347    crPackBitmap(width, height, xorig, yorig, xmove, ymove, bitmap, &(clientState->unpack));
    348348
    349     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     349    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    350350    {
    351351        packspu_RestoreUnpackState();
     
    360360    if (!packspu_CheckTexImageParams(internalformat, format, type))
    361361    {
    362         if (pixels || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     362        if (pixels || crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    363363        {
    364364            crWarning("packspu_TexImage1D invalid internalFormat(%x)/format(%x)/type(%x)", internalformat, format, type);
     
    370370    }
    371371
    372     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     372    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    373373    {
    374374        packspu_ApplyUnpackState();
     
    376376
    377377    crPackTexImage1D( target, level, internalformat, width, border, format, type, pixels, &(clientState->unpack) );
    378     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     378    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    379379    {
    380380        packspu_RestoreUnpackState();
     
    389389    if (!packspu_CheckTexImageParams(internalformat, format, type))
    390390    {
    391         if (pixels || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     391        if (pixels || crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    392392        {
    393393            crWarning("packspu_TexImage2D invalid internalFormat(%x)/format(%x)/type(%x)", internalformat, format, type);
     
    399399    }
    400400
    401     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     401    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    402402    {
    403403        packspu_ApplyUnpackState();
     
    405405
    406406    crPackTexImage2D( target, level, internalformat, width, height, border, format, type, pixels, &(clientState->unpack) );
    407     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     407    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    408408    {
    409409        packspu_RestoreUnpackState();
     
    417417    CRClientState *clientState = &(ctx->clientState->client);
    418418
    419     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     419    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    420420    {
    421421        packspu_ApplyUnpackState();
     
    423423
    424424    crPackTexImage3DEXT( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
    425     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     425    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    426426    {
    427427        packspu_RestoreUnpackState();
     
    436436    CRClientState *clientState = &(ctx->clientState->client);
    437437
    438     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     438    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    439439    {
    440440        packspu_ApplyUnpackState();
     
    442442
    443443    crPackTexImage3D( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
    444     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     444    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    445445    {
    446446        packspu_RestoreUnpackState();
     
    460460    }
    461461
    462     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     462    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    463463    {
    464464        packspu_ApplyUnpackState();
     
    466466
    467467    crPackTexSubImage1D( target, level, xoffset, width, format, type, pixels, &(clientState->unpack) );
    468     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     468    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    469469    {
    470470        packspu_RestoreUnpackState();
     
    483483    }
    484484
    485     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     485    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    486486    {
    487487        packspu_ApplyUnpackState();
     
    489489
    490490    crPackTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels, &(clientState->unpack) );
    491     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     491    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    492492    {
    493493        packspu_RestoreUnpackState();
     
    501501    CRClientState *clientState = &(ctx->clientState->client);
    502502
    503     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     503    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    504504    {
    505505        packspu_ApplyUnpackState();
     
    507507
    508508    crPackTexSubImage3D( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, &(clientState->unpack) );
    509     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     509    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    510510    {
    511511        packspu_RestoreUnpackState();
     
    533533     */
    534534
    535     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     535    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    536536    {
    537537        packspu_ApplyPackState();
     
    539539
    540540    crPackGetTexImage( target, level, format, type, pixels, &(clientState->pack), &writeback );
    541     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     541    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    542542    {
    543543        packspu_RestorePackState();
     
    545545
    546546#ifdef CR_ARB_pixel_buffer_object
    547     if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     547    if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    548548#endif
    549549    {
     
    558558    int writeback = 1;
    559559
    560     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     560    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    561561    {
    562562        packspu_ApplyPackState();
     
    564564
    565565    crPackGetCompressedTexImageARB( target, level, img, &writeback );
    566     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     566    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    567567    {
    568568        packspu_RestorePackState();
     
    570570
    571571#ifdef CR_ARB_pixel_buffer_object
    572     if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     572    if (!crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    573573#endif
    574574    {
     
    582582                                GLint border, GLsizei imagesize, const GLvoid *data)
    583583{
    584     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     584    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    585585    {
    586586        packspu_ApplyUnpackState();
     
    589589    crPackCompressedTexImage1DARB(target, level, internalformat, width, border, imagesize, data);
    590590
    591     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     591    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    592592    {
    593593        packspu_RestoreUnpackState();
     
    599599                                GLsizei height, GLint border, GLsizei imagesize, const GLvoid *data)
    600600{
    601     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     601    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    602602    {
    603603        packspu_ApplyUnpackState();
     
    606606    crPackCompressedTexImage2DARB(target, level, internalformat, width, height, border, imagesize, data);
    607607
    608     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     608    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    609609    {
    610610        packspu_RestoreUnpackState();
     
    616616                                GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid *data)
    617617{
    618     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     618    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    619619    {
    620620        packspu_ApplyUnpackState();
     
    623623    crPackCompressedTexImage3DARB(target, level, internalformat, width, height, depth, border, imagesize, data);
    624624
    625     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     625    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    626626    {
    627627        packspu_RestoreUnpackState();
     
    633633                                   GLenum format, GLsizei imagesize, const GLvoid *data)
    634634{
    635     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     635    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    636636    {
    637637        packspu_ApplyUnpackState();
     
    640640    crPackCompressedTexSubImage1DARB(target, level, xoffset, width, format, imagesize, data);
    641641
    642     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     642    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    643643    {
    644644        packspu_RestoreUnpackState();
     
    650650                                   GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid *data)
    651651{
    652     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     652    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    653653    {
    654654        packspu_ApplyUnpackState();
     
    657657    crPackCompressedTexSubImage2DARB(target, level, xoffset, yoffset, width, height, format, imagesize, data);
    658658
    659     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     659    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    660660    {
    661661        packspu_RestoreUnpackState();
     
    668668                                   GLsizei imagesize, const GLvoid *data)
    669669{
    670     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     670    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    671671    {
    672672        packspu_ApplyUnpackState();
     
    675675    crPackCompressedTexSubImage3DARB(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imagesize, data);
    676676
    677     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
    678     {
    679         packspu_RestoreUnpackState();
    680     }
    681 }
     677    if (crStateIsBufferBound(&pack_spu.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
     678    {
     679        packspu_RestoreUnpackState();
     680    }
     681}
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_texture.c

    r78190 r78375  
    2424void PACKSPU_APIENTRY packspu_ActiveTextureARB(GLenum texture)
    2525{
    26     crStateActiveTextureARB(texture);
     26    crStateActiveTextureARB(&pack_spu.StateTracker, texture);
    2727    crPackActiveTextureARB(texture);
    2828}
     
    3030void PACKSPU_APIENTRY packspu_BindTexture(GLenum target, GLuint texture)
    3131{
    32     crStateBindTexture(target, texture);
     32    crStateBindTexture(&pack_spu.StateTracker, target, texture);
    3333    crPackBindTexture(target, texture);
    3434}
     
    3636void PACKSPU_APIENTRY packspu_DeleteTextures(GLsizei n, const GLuint * textures)
    3737{
    38     crStateDeleteTextures(n, textures);
     38    crStateDeleteTextures(&pack_spu.StateTracker, n, textures);
    3939    crPackDeleteTextures(n, textures);
    4040}
     
    5252    packspuFlush( (void *) thread );
    5353    CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
    54     crStateRegTextures(n, textures);
     54    crStateRegTextures(&pack_spu.StateTracker, n, textures);
    5555}
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h

    r78341 r78375  
    192192#endif
    193193
     194    /** The state tracker the context is attached to. */
     195    PCRStateTracker    pStateTracker;
     196
    194197    /** For buffering vertices for selection/feedback */
    195198    /*@{*/
     
    202205
    203206
    204 DECLEXPORT(void) crStateInit(void);
    205 DECLEXPORT(void) crStateDestroy(void);
    206 DECLEXPORT(void) crStateVBoxDetachThread(void);
    207 DECLEXPORT(void) crStateVBoxAttachThread(void);
    208 DECLEXPORT(CRContext *) crStateCreateContext(const CRLimitsState *limits, GLint visBits, CRContext *share);
    209 DECLEXPORT(CRContext *) crStateCreateContextEx(const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID);
    210 DECLEXPORT(void) crStateMakeCurrent(CRContext *ctx);
    211 DECLEXPORT(void) crStateSetCurrent(CRContext *ctx);
    212 DECLEXPORT(void) crStateCleanupCurrent(void);
    213 DECLEXPORT(CRContext *) crStateGetCurrent(void);
    214 DECLEXPORT(void) crStateDestroyContext(CRContext *ctx);
    215 DECLEXPORT(GLboolean) crStateEnableDiffOnMakeCurrent(GLboolean fEnable);
     207/**
     208 * CR state tracker.
     209 */
     210typedef struct CRStateTracker
     211{
     212    bool             fContextTLSInit;
     213    CRtsd            contextTSD;
     214    CRStateBits      *pCurrentBits;
     215    CRContext        *apAvailableContexts[CR_MAX_CONTEXTS];
     216    uint32_t         cContexts;
     217    CRSharedState    *pSharedState;
     218    CRContext        *pDefaultContext;
     219    GLboolean        fVBoxEnableDiffOnMakeCurrent;
     220    SPUDispatchTable diff_api;
     221} CRStateTracker;
     222/** Pointer to a state tracker state. */
     223typedef CRStateTracker *PCRStateTracker;
     224
     225DECLEXPORT(void) crStateInit(PCRStateTracker pState);
     226DECLEXPORT(void) crStateDestroy(PCRStateTracker pState);
     227DECLEXPORT(void) crStateVBoxDetachThread(PCRStateTracker pState);
     228DECLEXPORT(void) crStateVBoxAttachThread(PCRStateTracker pState);
     229DECLEXPORT(CRContext *) crStateCreateContext(PCRStateTracker pState, const CRLimitsState *limits, GLint visBits, CRContext *share);
     230DECLEXPORT(CRContext *) crStateCreateContextEx(PCRStateTracker pState, const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID);
     231DECLEXPORT(void) crStateMakeCurrent(PCRStateTracker pState, CRContext *ctx);
     232DECLEXPORT(void) crStateSetCurrent(PCRStateTracker pState, CRContext *ctx);
     233DECLEXPORT(void) crStateCleanupCurrent(PCRStateTracker pState);
     234DECLEXPORT(CRContext *) crStateGetCurrent(PCRStateTracker pState);
     235DECLEXPORT(void) crStateDestroyContext(PCRStateTracker pState, CRContext *ctx);
     236DECLEXPORT(GLboolean) crStateEnableDiffOnMakeCurrent(PCRStateTracker pState, GLboolean fEnable);
    216237
    217238void crStateSwitchPrepare(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO);
     
    219240
    220241void crStateSyncHWErrorState(CRContext *ctx);
    221 GLenum crStateCleanHWErrorState(void);
    222 
    223 #define CR_STATE_CLEAN_HW_ERR_WARN(_s) do {\
    224             GLenum _err = crStateCleanHWErrorState(); \
     242GLenum crStateCleanHWErrorState(PCRStateTracker pState);
     243
     244#define CR_STATE_CLEAN_HW_ERR_WARN(a_pState, _s) do {\
     245            GLenum _err = crStateCleanHWErrorState((a_pState)); \
    225246            if (_err != GL_NO_ERROR) { \
    226247                static int _cErrPrints = 0; \
     
    232253        } while (0)
    233254
    234 DECLEXPORT(void) crStateFlushFunc( CRStateFlushFunc ff );
    235 DECLEXPORT(void) crStateFlushArg( void *arg );
    236 DECLEXPORT(void) crStateDiffAPI( SPUDispatchTable *api );
    237 DECLEXPORT(void) crStateUpdateColorBits( void );
    238 
    239 DECLEXPORT(void) crStateSetCurrentPointers( CRContext *ctx, CRCurrentStatePointers *current );
    240 DECLEXPORT(void) crStateResetCurrentPointers( CRCurrentStatePointers *current );
    241 
    242 DECLEXPORT(void) crStateSetExtensionString( CRContext *ctx, const GLubyte *extensions );
    243 
    244 DECLEXPORT(void) crStateDiffContext( CRContext *from, CRContext *to );
    245 DECLEXPORT(void) crStateSwitchContext( CRContext *from, CRContext *to );
    246 
    247 DECLEXPORT(unsigned int) crStateHlpComponentsCount( GLenum pname );
     255DECLEXPORT(void) crStateFlushFunc(PCRStateTracker pState, CRStateFlushFunc ff);
     256DECLEXPORT(void) crStateFlushArg(PCRStateTracker pState, void *arg );
     257DECLEXPORT(void) crStateDiffAPI(PCRStateTracker pState, SPUDispatchTable *api);
     258DECLEXPORT(void) crStateUpdateColorBits(PCRStateTracker pState);
     259
     260DECLEXPORT(void) crStateSetCurrentPointers(CRContext *ctx, CRCurrentStatePointers *current);
     261DECLEXPORT(void) crStateResetCurrentPointers(CRCurrentStatePointers *current);
     262
     263DECLEXPORT(void) crStateSetExtensionString(CRContext *ctx, const GLubyte *extensions);
     264
     265DECLEXPORT(void) crStateDiffContext(CRContext *from, CRContext *to);
     266DECLEXPORT(void) crStateSwitchContext(CRContext *from, CRContext *to);
     267
     268DECLEXPORT(unsigned int) crStateHlpComponentsCount(GLenum pname);
    248269
    249270typedef struct CRFBDataElement
     
    277298
    278299DECLEXPORT(void) crStateGetTextureObjectAndImage(CRContext *g, GLenum texTarget, GLint level,
    279                                      CRTextureObj **obj, CRTextureLevel **img);
     300                                                 CRTextureObj **obj, CRTextureLevel **img);
    280301
    281302
     
    287308typedef FNCRSTATE_CONTEXT_GET *PFNCRSTATE_CONTEXT_GET;
    288309DECLEXPORT(int32_t) crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM, uint32_t u32Version);
    289 DECLEXPORT(void) crStateFreeShared(CRContext *pContext, CRSharedState *s);
    290 
    291 DECLEXPORT(int32_t) crStateLoadGlobals(PSSMHANDLE pSSM, uint32_t u32Version);
    292 DECLEXPORT(int32_t) crStateSaveGlobals(PSSMHANDLE pSSM);
    293 
    294 DECLEXPORT(CRSharedState *) crStateGlobalSharedAcquire(void);
    295 DECLEXPORT(void) crStateGlobalSharedRelease(void);
    296 #endif
    297 
    298 DECLEXPORT(void) crStateSetTextureUsed(GLuint texture, GLboolean used);
    299 DECLEXPORT(void) crStatePinTexture(GLuint texture, GLboolean pin);
    300 DECLEXPORT(void) crStateDeleteTextureCallback(void *texObj);
     310DECLEXPORT(void) crStateFreeShared(PCRStateTracker pState, CRContext *pContext, CRSharedState *s);
     311
     312DECLEXPORT(int32_t) crStateLoadGlobals(PCRStateTracker pState, PSSMHANDLE pSSM, uint32_t u32Version);
     313DECLEXPORT(int32_t) crStateSaveGlobals(PCRStateTracker pState, PSSMHANDLE pSSM);
     314
     315DECLEXPORT(CRSharedState *) crStateGlobalSharedAcquire(PCRStateTracker pState);
     316DECLEXPORT(void) crStateGlobalSharedRelease(PCRStateTracker pState);
     317#endif
     318
     319DECLEXPORT(void) crStateSetTextureUsed(PCRStateTracker pState, GLuint texture, GLboolean used);
     320DECLEXPORT(void) crStatePinTexture(PCRStateTracker pState, GLuint texture, GLboolean pin);
     321DECLEXPORT(void) crStateDeleteTextureCallback(void *texObj, void *pvUser);
    301322
    302323   /* XXX move these! */
    303324
    304 DECLEXPORT(void) STATE_APIENTRY
    305 crStateChromiumParameteriCR( GLenum target, GLint value );
    306 
    307 DECLEXPORT(void) STATE_APIENTRY
    308 crStateChromiumParameterfCR( GLenum target, GLfloat value );
    309 
    310 DECLEXPORT(void) STATE_APIENTRY
    311 crStateChromiumParametervCR( GLenum target, GLenum type, GLsizei count, const GLvoid *values );
    312 
    313 DECLEXPORT(void) STATE_APIENTRY
    314 crStateGetChromiumParametervCR( GLenum target, GLuint index, GLenum type,
    315                                 GLsizei count, GLvoid *values );
    316 
    317 DECLEXPORT(void) STATE_APIENTRY
    318 crStateReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
    319                    GLenum format, GLenum type, GLvoid *pixels );
    320 
    321 DECLEXPORT(void) STATE_APIENTRY crStateShareContext(GLboolean value);
     325DECLEXPORT(void) STATE_APIENTRY crStateChromiumParameteriCR(PCRStateTracker pState, GLenum target, GLint value );
     326DECLEXPORT(void) STATE_APIENTRY crStateChromiumParameterfCR(PCRStateTracker pState, GLenum target, GLfloat value );
     327DECLEXPORT(void) STATE_APIENTRY crStateChromiumParametervCR(PCRStateTracker pState, GLenum target, GLenum type, GLsizei count, const GLvoid *values );
     328DECLEXPORT(void) STATE_APIENTRY crStateGetChromiumParametervCR(PCRStateTracker pState, GLenum target, GLuint index, GLenum type,
     329                                                               GLsizei count, GLvoid *values );
     330DECLEXPORT(void) STATE_APIENTRY crStateReadPixels(PCRStateTracker pState, GLint x, GLint y, GLsizei width, GLsizei height,
     331                                                  GLenum format, GLenum type, GLvoid *pixels );
     332DECLEXPORT(void) STATE_APIENTRY crStateShareContext(PCRStateTracker pState, GLboolean value);
    322333DECLEXPORT(void) STATE_APIENTRY crStateShareLists(CRContext *pContext1, CRContext *pContext2);
    323334DECLEXPORT(void) STATE_APIENTRY crStateSetSharedContext(CRContext *pCtx);
    324335DECLEXPORT(GLboolean) STATE_APIENTRY crStateContextIsShared(CRContext *pCtx);
    325 
    326 DECLEXPORT(void) STATE_APIENTRY crStateQueryHWState(GLuint fbFbo, GLuint bbFbo);
     336DECLEXPORT(void) STATE_APIENTRY crStateQueryHWState(PCRStateTracker pState, GLuint fbFbo, GLuint bbFbo);
    327337#ifdef __cplusplus
    328338}
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_pack.h

    r78342 r78375  
    1212#include "cr_protocol.h"
    1313#include "cr_opcodes.h"
     14#ifndef IN_RING0
     15# include "cr_glstate.h"
     16#endif
    1417#include "state/cr_statetypes.h"
    1518#include "state/cr_currentpointers.h"
     
    98101# define CR_PACKER_CONTEXT_ARGCTX(C)
    99102extern CRtsd _PackerTSD;
     103#ifndef IN_RING0
     104extern DECLHIDDEN(PCRStateTracker) g_pStateTracker; /** Hack to make the state tracker available to pack_client.c which uses crStateGetCurrent(). */
     105#endif
    100106# define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = (CRPackContext *) crGetTSD(&_PackerTSD)
    101107# define CR_LOCK_PACKER_CONTEXT(PC) crLockMutex(&((PC)->mutex))
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h

    r78190 r78375  
    408408    /* visBits -> dummy mural association */
    409409    CRHashTable *dummyMuralTable;
     410
     411    /** State tracker state. */
     412    CRStateTracker StateTracker;
    410413
    411414    GLboolean fRootVrOn;
     
    594597extern int crVBoxServerHostCtl(VBOXCRCMDCTL *pCtl, uint32_t cbCtl);
    595598
     599extern DECLEXPORT(void) crVBoxServerDetachThread(void);
     600extern DECLEXPORT(void) crVBoxServerAttachThread(void);
     601
    596602#ifdef __cplusplus
    597603}
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_unpack.h

    r78263 r78375  
    1313#include "cr_mem.h"
    1414#include "cr_opcodes.h"
     15#include "cr_glstate.h"
    1516
    1617#include <iprt/types.h>
     
    4243     * on error if one unpacker detected out of bounds buffer access). */
    4344    int                         rcUnpack;
     45    /** Attached state tracker. */
     46    PCRStateTracker             pStateTracker;
    4447} CrUnpackerState;
    4548/** Pointer to an unpacker state. */
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_bufferobject.h

    r69474 r78375  
    5454
    5555        CRBufferObject *nullBuffer;  /* name = 0 */
     56    /** Attached state tracker. */
     57    PCRStateTracker pStateTracker;
    5658} CRBufferObjectState;
    5759
    5860DECLEXPORT(CRBufferObject *) crStateGetBoundBufferObject(GLenum target, CRBufferObjectState *b);
    59 DECLEXPORT(GLboolean) crStateIsBufferBound(GLenum target);
     61DECLEXPORT(GLboolean) crStateIsBufferBound(PCRStateTracker pState, GLenum target);
    6062struct CRContext;
    6163DECLEXPORT(GLboolean) crStateIsBufferBoundForCtx(struct CRContext *g, GLenum target);
    6264
    63 DECLEXPORT(GLuint) STATE_APIENTRY crStateBufferHWIDtoID(GLuint hwid);
    64 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetBufferHWID(GLuint id);
     65DECLEXPORT(GLuint) STATE_APIENTRY crStateBufferHWIDtoID(PCRStateTracker pState, GLuint hwid);
     66DECLEXPORT(GLuint) STATE_APIENTRY crStateGetBufferHWID(PCRStateTracker pState, GLuint id);
    6567
    66 DECLEXPORT(void) crStateRegBuffers(GLsizei n, GLuint *buffers);
     68DECLEXPORT(void) crStateRegBuffers(PCRStateTracker pState, GLsizei n, GLuint *buffers);
    6769#ifdef __cplusplus
    6870}
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_client.h

    r78116 r78375  
    139139DECLEXPORT(void) crStateClientDestroy(struct CRContext *g);
    140140
    141 DECLEXPORT(GLboolean) crStateUseServerArrays(void);
    142 DECLEXPORT(GLboolean) crStateUseServerArrayElements(void);
     141DECLEXPORT(GLboolean) crStateUseServerArrays(PCRStateTracker pState);
     142DECLEXPORT(GLboolean) crStateUseServerArrayElements(PCRStateTracker pState);
    143143DECLEXPORT(CRClientPointer*) crStateGetClientPointerByIndex(int index, CRVertexArrays *array);
    144144
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_current.h

    r69474 r78375  
    8888DECLEXPORT(void) crStateCurrentInit( CRContext *ctx );
    8989
    90 DECLEXPORT(void) crStateCurrentRecover( void );
     90DECLEXPORT(void) crStateCurrentRecover(PCRStateTracker pState);
    9191
    9292DECLEXPORT(void) crStateCurrentRecoverNew(CRContext *g, CRCurrentStatePointers  *current);
     
    9797                                    CRContext *fromCtx, CRContext *toCtx);
    9898
    99 DECLEXPORT(void) crStateRasterPosUpdate(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
     99DECLEXPORT(void) crStateRasterPosUpdate(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
    100100
    101101DECLEXPORT(GLuint) crStateNeedDummyZeroVertexArray(CRContext *g, CRCurrentStatePointers  *current, GLfloat *pZva);
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_framebuffer.h

    r76553 r78375  
    7575DECLEXPORT(void) STATE_APIENTRY crStateFramebufferObjectReenableHW(CRContext *fromCtx, CRContext *toCtx, GLuint idDrawFBO, GLuint idReadFBO);
    7676
    77 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetFramebufferHWID(GLuint id);
    78 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetRenderbufferHWID(GLuint id);
     77DECLEXPORT(GLuint) STATE_APIENTRY crStateGetFramebufferHWID(PCRStateTracker pState, GLuint id);
     78DECLEXPORT(GLuint) STATE_APIENTRY crStateGetRenderbufferHWID(PCRStateTracker pState, GLuint id);
    7979
    80 DECLEXPORT(void) STATE_APIENTRY crStateBindRenderbufferEXT(GLenum target, GLuint renderbuffer);
    81 DECLEXPORT(void) STATE_APIENTRY crStateDeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers);
    82 DECLEXPORT(void) STATE_APIENTRY crStateRenderbufferStorageEXT(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
    83 DECLEXPORT(void) STATE_APIENTRY crStateGetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params);
    84 DECLEXPORT(void) STATE_APIENTRY crStateBindFramebufferEXT(GLenum target, GLuint framebuffer);
    85 DECLEXPORT(void) STATE_APIENTRY crStateDeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers);
    86 DECLEXPORT(void) STATE_APIENTRY crStateFramebufferTexture1DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
    87 DECLEXPORT(void) STATE_APIENTRY crStateFramebufferTexture2DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
    88 DECLEXPORT(void) STATE_APIENTRY crStateFramebufferTexture3DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
    89 DECLEXPORT(void) STATE_APIENTRY crStateFramebufferRenderbufferEXT(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
    90 DECLEXPORT(void) STATE_APIENTRY crStateGetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, GLenum pname, GLint *params);
    91 DECLEXPORT(void) STATE_APIENTRY crStateGenerateMipmapEXT(GLenum target);
     80DECLEXPORT(void) STATE_APIENTRY crStateBindRenderbufferEXT(PCRStateTracker pState, GLenum target, GLuint renderbuffer);
     81DECLEXPORT(void) STATE_APIENTRY crStateDeleteRenderbuffersEXT(PCRStateTracker pState, GLsizei n, const GLuint *renderbuffers);
     82DECLEXPORT(void) STATE_APIENTRY crStateRenderbufferStorageEXT(PCRStateTracker pState, GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
     83DECLEXPORT(void) STATE_APIENTRY crStateGetRenderbufferParameterivEXT(PCRStateTracker pState, GLenum target, GLenum pname, GLint *params);
     84DECLEXPORT(void) STATE_APIENTRY crStateBindFramebufferEXT(PCRStateTracker pState, GLenum target, GLuint framebuffer);
     85DECLEXPORT(void) STATE_APIENTRY crStateDeleteFramebuffersEXT(PCRStateTracker pState, GLsizei n, const GLuint *framebuffers);
     86DECLEXPORT(void) STATE_APIENTRY crStateFramebufferTexture1DEXT(PCRStateTracker pState, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
     87DECLEXPORT(void) STATE_APIENTRY crStateFramebufferTexture2DEXT(PCRStateTracker pState, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
     88DECLEXPORT(void) STATE_APIENTRY crStateFramebufferTexture3DEXT(PCRStateTracker pState, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
     89DECLEXPORT(void) STATE_APIENTRY crStateFramebufferRenderbufferEXT(PCRStateTracker pState, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
     90DECLEXPORT(void) STATE_APIENTRY crStateGetFramebufferAttachmentParameterivEXT(PCRStateTracker pState, GLenum target, GLenum attachment, GLenum pname, GLint *params);
     91DECLEXPORT(void) STATE_APIENTRY crStateGenerateMipmapEXT(PCRStateTracker pState, GLenum target);
    9292
    93 DECLEXPORT(GLuint) STATE_APIENTRY crStateFBOHWIDtoID(GLuint hwid);
    94 DECLEXPORT(GLuint) STATE_APIENTRY crStateRBOHWIDtoID(GLuint hwid);
     93DECLEXPORT(GLuint) STATE_APIENTRY crStateFBOHWIDtoID(PCRStateTracker pState, GLuint hwid);
     94DECLEXPORT(GLuint) STATE_APIENTRY crStateRBOHWIDtoID(PCRStateTracker pState, GLuint hwid);
    9595
    96 DECLEXPORT(void) crStateRegFramebuffers(GLsizei n, GLuint *buffers);
    97 DECLEXPORT(void) crStateRegRenderbuffers(GLsizei n, GLuint *buffers);
     96DECLEXPORT(void) crStateRegFramebuffers(PCRStateTracker pState, GLsizei n, GLuint *buffers);
     97DECLEXPORT(void) crStateRegRenderbuffers(PCRStateTracker pState, GLsizei n, GLuint *buffers);
    9898
    9999#ifdef IN_GUEST
    100 DECLEXPORT(GLenum) STATE_APIENTRY crStateCheckFramebufferStatusEXT(GLenum target);
    101 DECLEXPORT(GLenum) STATE_APIENTRY crStateSetFramebufferStatus(GLenum target, GLenum status);
     100DECLEXPORT(GLenum) STATE_APIENTRY crStateCheckFramebufferStatusEXT(PCRStateTracker pState, GLenum target);
     101DECLEXPORT(GLenum) STATE_APIENTRY crStateSetFramebufferStatus(PCRStateTracker pState, GLenum target, GLenum status);
    102102#endif
    103103
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_glsl.h

    r76553 r78375  
    9393DECLEXPORT(void) STATE_APIENTRY crStateGLSLSwitch(CRContext *from, CRContext *to);
    9494
    95 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetShaderHWID(GLuint id);
    96 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetProgramHWID(GLuint id);
    97 DECLEXPORT(GLuint) STATE_APIENTRY crStateGLSLProgramHWIDtoID(GLuint hwid);
    98 DECLEXPORT(GLuint) STATE_APIENTRY crStateGLSLShaderHWIDtoID(GLuint hwid);
     95DECLEXPORT(GLuint) STATE_APIENTRY crStateGetShaderHWID(PCRStateTracker pState, GLuint id);
     96DECLEXPORT(GLuint) STATE_APIENTRY crStateGetProgramHWID(PCRStateTracker pState, GLuint id);
     97DECLEXPORT(GLuint) STATE_APIENTRY crStateGLSLProgramHWIDtoID(PCRStateTracker pState, GLuint hwid);
     98DECLEXPORT(GLuint) STATE_APIENTRY crStateGLSLShaderHWIDtoID(PCRStateTracker pState, GLuint hwid);
    9999
    100 DECLEXPORT(GLint) STATE_APIENTRY crStateGetUniformSize(GLenum type);
    101 DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsIntUniform(GLenum type);
     100DECLEXPORT(GLint) STATE_APIENTRY crStateGetUniformSize(PCRStateTracker pState, GLenum type);
     101DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsIntUniform(PCRStateTracker pState, GLenum type);
    102102
    103 DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateShader(GLuint id, GLenum type);
    104 DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateProgram(GLuint id);
    105 DECLEXPORT(GLuint) STATE_APIENTRY crStateDeleteObjectARB( VBoxGLhandleARB obj );
     103DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateShader(PCRStateTracker pState, GLuint id, GLenum type);
     104DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateProgram(PCRStateTracker pState, GLuint id);
     105DECLEXPORT(GLuint) STATE_APIENTRY crStateDeleteObjectARB(PCRStateTracker pState, VBoxGLhandleARB obj );
    106106
    107 DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramUniformsCached(GLuint program);
    108 DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramAttribsCached(GLuint program);
     107DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramUniformsCached(PCRStateTracker pState, GLuint program);
     108DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramAttribsCached(PCRStateTracker pState, GLuint program);
    109109
    110110#ifdef IN_GUEST
    111 DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheUniforms(GLuint program, GLsizei cbData, GLvoid *pData);
    112 DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheAttribs(GLuint program, GLsizei cbData, GLvoid *pData);
     111DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheUniforms(PCRStateTracker pState, GLuint program, GLsizei cbData, GLvoid *pData);
     112DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheAttribs(PCRStateTracker pState, GLuint program, GLsizei cbData, GLvoid *pData);
    113113#else
    114 DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheUniforms(GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData);
    115 DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheAttribs(GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData);
     114DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheUniforms(PCRStateTracker pState, GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData);
     115DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheAttribs(PCRStateTracker pState, GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData);
    116116#endif
    117117
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_lighting.h

    r69474 r78375  
    8484                                       CRContext *fromCtx, CRContext *toCtx);
    8585
    86 DECLEXPORT(void) crStateColorMaterialRecover( void );
     86DECLEXPORT(void) crStateColorMaterialRecover(PCRStateTracker pState);
    8787
    8888#ifdef __cplusplus
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_stateerror.h

    r69474 r78375  
    1212#include <iprt/cdefs.h>
    1313
    14 DECLEXPORT(void) crStateError( int line, const char *file, GLenum err, const char *format, ... );
     14DECLEXPORT(void) crStateError(PCRStateTracker pState, int line, const char *file, GLenum err, const char *format, ... );
    1515
    1616#endif /* CR_STATE_ERROR_H */
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_statetypes.h

    r69474 r78375  
    1515extern "C" {
    1616#endif
     17
     18typedef struct CRStateTracker *PCRStateTracker;
    1719
    1820typedef GLfloat GLdefault;
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_texture.h

    r69474 r78375  
    217217DECLEXPORT(CRTextureObj *) crStateTextureAllocate(GLuint name);
    218218    /*void crStateTextureDelete(GLuint name);*/
    219 DECLEXPORT(CRTextureObj *) crStateTextureGet(GLenum target, GLuint textureid);
     219DECLEXPORT(CRTextureObj *) crStateTextureGet(PCRStateTracker pState, GLenum target, GLuint textureid);
    220220DECLEXPORT(int) crStateTextureGetSize(GLenum target, GLenum level);
    221221DECLEXPORT(const GLvoid *) crStateTextureGetData(GLenum target, GLenum level);
     
    238238DECLEXPORT(void) crStateDeleteTextureObject(CRTextureObj *tobj);
    239239
    240 DECLEXPORT(GLuint) STATE_APIENTRY crStateTextureHWIDtoID(GLuint hwid);
    241 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureHWID(GLuint id);
    242 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureObjHWID(CRTextureObj *tobj);
    243 
    244 void crStateRegTextures(GLsizei n, GLuint *names);
     240DECLEXPORT(GLuint) STATE_APIENTRY crStateTextureHWIDtoID(PCRStateTracker pState, GLuint hwid);
     241DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureHWID(PCRStateTracker pState, GLuint id);
     242DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureObjHWID(PCRStateTracker pState, CRTextureObj *tobj);
     243
     244void crStateRegTextures(PCRStateTracker pState, GLsizei n, GLuint *names);
    245245
    246246#ifdef __cplusplus
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_transform.h

    r69474 r78375  
    7171DECLEXPORT(void) crStateInitMatrixStack(CRMatrixStack *stack, int maxDepth);
    7272
    73 DECLEXPORT(void) crStateLoadMatrix(const CRmatrix *m);
     73DECLEXPORT(void) crStateLoadMatrix(PCRStateTracker pState, const CRmatrix *m);
    7474
    7575DECLEXPORT(void) crStateTransformUpdateTransform(CRTransformState *t);
  • trunk/src/VBox/GuestHost/OpenGL/packer/pack_client.c

    r69392 r78375  
    308308    unsigned int unit, attr;
    309309    const CRVertexArrays *array = &(c->array);
    310     const GLboolean vpEnabled = crStateGetCurrent()->program.vpEnabled;
     310    const GLboolean vpEnabled = crStateGetCurrent(g_pStateTracker)->program.vpEnabled;
    311311
    312312    /*crDebug("crPackExpandArrayElement(%i)", index);*/
     
    669669    GLsizei indexsize;
    670670#ifdef CR_ARB_vertex_buffer_object
    671     CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
     671    CRBufferObject *elementsBuffer = crStateGetCurrent(g_pStateTracker)->bufferobject.elementsBuffer;
    672672    packet_length += sizeof(GLint);
    673673    if (elementsBuffer && elementsBuffer->id)
     
    708708void PACK_APIENTRY
    709709crPackDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
    710                                                 GLenum type, const GLvoid *indices)
     710                        GLenum type, const GLvoid *indices)
    711711{
    712712    unsigned char *data_ptr, *start_ptr;
     
    716716
    717717#ifdef CR_ARB_vertex_buffer_object
    718     CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
     718    CRBufferObject *elementsBuffer = crStateGetCurrent(g_pStateTracker)->bufferobject.elementsBuffer;
    719719    packet_length += sizeof(GLint);
    720720    if (elementsBuffer && elementsBuffer->id)
     
    762762void
    763763crPackExpandDrawElements(GLenum mode, GLsizei count, GLenum type,
    764                                                  const GLvoid *indices, CRClientState *c, const GLfloat *pZva)
     764                         const GLvoid *indices, CRClientState *c, const GLfloat *pZva)
    765765{
    766766    int i;
    767767    GLubyte *p = (GLubyte *)indices;
    768768#ifdef CR_ARB_vertex_buffer_object
    769     CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
     769    CRBufferObject *elementsBuffer = crStateGetCurrent(g_pStateTracker)->bufferobject.elementsBuffer;
    770770#endif
    771771
     
    10651065void PACK_APIENTRY crPackLockArraysEXT(GLint first, GLint count)
    10661066{
    1067     CRContext *g = crStateGetCurrent();
     1067    CRContext *g = crStateGetCurrent(g_pStateTracker);
    10681068    CRClientState *c = &g->client;
    10691069    unsigned char *data_ptr, *start_ptr;
  • trunk/src/VBox/GuestHost/OpenGL/packer/pack_pixelmap.c

    r69392 r78375  
    1111static unsigned char * __gl_HandlePixelMapData(GLenum map, GLsizei mapsize, int size_of_value, const GLvoid *values)
    1212{
    13     int nodata = (values == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     13    int nodata = (values == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    1414    int packet_length =
    1515        sizeof( map ) +
  • trunk/src/VBox/GuestHost/OpenGL/packer/pack_pixels.c

    r69392 r78375  
    1919    unsigned char *data_ptr;
    2020    int packet_length, imagesize;
    21     int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     21    int noimagedata = (pixels == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    2222
    2323    packet_length =
     
    115115                                const GLubyte *bitmap, const CRPixelPackState *unpack )
    116116{
    117     const int noimagedata = (bitmap == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     117    const int noimagedata = (bitmap == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    118118    unsigned char *data_ptr;
    119119    int data_length = 0;
  • trunk/src/VBox/GuestHost/OpenGL/packer/pack_stipple.c

    r69392 r78375  
    1414    CR_GET_PACKER_CONTEXT(pc);
    1515    unsigned char *data_ptr;
    16     int nodata = crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     16    int nodata = crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    1717    int packet_length = sizeof(int);
    1818
  • trunk/src/VBox/GuestHost/OpenGL/packer/pack_texture.c

    r69392 r78375  
    2020    unsigned char *data_ptr;
    2121    int packet_length;
    22     int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     22    int noimagedata = (pixels == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    2323
    2424    packet_length =
     
    6363    unsigned char *data_ptr;
    6464    int packet_length;
    65     const int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     65    const int noimagedata = (pixels == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    6666    const int is_distrib = ((type == GL_TRUE) || (type == GL_FALSE));
    6767    int distrib_buf_len = 0;
     
    139139    unsigned char *data_ptr;
    140140    int packet_length;
    141     int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     141    int noimagedata = (pixels == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    142142    int is_distrib = ( (type == GL_TRUE) || (type == GL_FALSE) ) ;
    143143    int distrib_buf_len = 0;
     
    215215    unsigned char *data_ptr;
    216216    int packet_length;
    217     int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     217    int noimagedata = (pixels == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    218218    int is_distrib = ( (type == GL_TRUE) || (type == GL_FALSE) ) ;
    219219    int distrib_buf_len = 0;
     
    561561    unsigned char *data_ptr;
    562562    int packet_length;
    563     int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     563    int noimagedata = (pixels == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    564564
    565565    packet_length =
     
    614614    unsigned char *data_ptr;
    615615    int packet_length;
    616     int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     616    int noimagedata = (pixels == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    617617
    618618    packet_length =
     
    660660    unsigned char *data_ptr;
    661661    int packet_length;
    662     int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     662    int noimagedata = (pixels == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    663663
    664664    packet_length =
     
    732732    unsigned char *data_ptr;
    733733    int packet_length;
    734     int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     734    int noimagedata = (data == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    735735
    736736    /* All extended opcodes have their first 8 bytes predefined:
     
    777777    unsigned char *data_ptr;
    778778    int packet_length;
    779     int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     779    int noimagedata = (data == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    780780
    781781    /* All extended opcodes have their first 8 bytes predefined:
     
    825825    unsigned char *data_ptr;
    826826    int packet_length;
    827     int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     827    int noimagedata = (data == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    828828
    829829    /* All extended opcodes have their first 8 bytes predefined:
     
    873873    unsigned char *data_ptr;
    874874    int packet_length;
    875     int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     875    int noimagedata = (data == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    876876
    877877    /* All extended opcodes have their first 8 bytes predefined:
     
    917917    unsigned char *data_ptr;
    918918    int packet_length;
    919     int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     919    int noimagedata = (data == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    920920
    921921    /* All extended opcodes have their first 8 bytes predefined:
     
    965965    unsigned char *data_ptr;
    966966    int packet_length;
    967     int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     967    int noimagedata = (data == NULL) || crStateIsBufferBound(g_pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB);
    968968
    969969    /* All extended opcodes have their first 8 bytes predefined:
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/gendiffcode.py

    r69392 r78375  
    2020                CRContext *fromCtx, CRContext *toCtx)
    2121{
     22    PCRStateTracker pState = fromCtx->pStateTracker;
    2223        CR%(Name)sState *from = &(fromCtx->%(name)s);
    2324        CR%(Name)sState *to = &(toCtx->%(name)s);"""%vars())
     
    2829                CRContext *fromCtx, CRContext *toCtx)
    2930{
     31    PCRStateTracker pState = fromCtx->pStateTracker;
    3032        CR%(Name)sState *from = &(fromCtx->%(name)s);
    3133        CR%(Name)sState *to = &(toCtx->%(name)s);"""%vars())
     
    5860        print("""       unsigned int j, i;
    5961        CRbitvalue nbitID[CR_MAX_BITARRAY];
     62    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
    6063        for (j = 0; j<CR_MAX_BITARRAY; j++)
    6164                nbitID[j] = ~bitID[j];
     
    151154                        if members[0] != "*" and guardbit[0:6] == "enable":
    152155                                print(tab+"glAble able[2];")
    153                                 print(tab+"able[0] = diff_api.Disable;")
    154                                 print(tab+"able[1] = diff_api.Enable;")
     156                                print(tab+"able[0] = pState->diff_api.Disable;")
     157                                print(tab+"able[1] = pState->diff_api.Enable;")
    155158
    156159                current_dependency = dependency
     
    226229                                                                i += 1
    227230
    228                                                 sys.stdout.write(tab+"diff_api.%(func)s("%vars())
     231                                                sys.stdout.write(tab+"pState->diff_api.%(func)s("%vars())
    229232                                                for funcarg in funcargs:
    230233                                                        sys.stdout.write(funcarg+", ")
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state.h

    r78341 r78375  
    1212#define CRSTATE_CHECKERR_RET(expr, result, message, ret)         \
    1313    if (expr) {                                             \
    14         crStateError(__LINE__, __FILE__, result, message);  \
     14        crStateError(pState, __LINE__, __FILE__, result, message);  \
    1515        return ret;                                             \
    1616    }
     
    2222typedef struct _crCheckIDHWID {
    2323    GLuint id, hwid;
     24    PCRStateTracker pState;
    2425} crCheckIDHWID_t;
    2526
    26 extern SPUDispatchTable diff_api;
    27 extern CRStateBits *__currentBits;
    28 
    29 #define GetCurrentBits() __currentBits
     27#define GetCurrentBits(a_pState) (a_pState)->pCurrentBits
    3028
    3129#include <cr_threads.h>
    3230
    33 extern CRtsd __contextTSD;
    34 #define GetCurrentContext() VBoxTlsRefGetCurrent(CRContext, &__contextTSD)
     31#define GetCurrentContext(a_pState) VBoxTlsRefGetCurrent(CRContext, &((a_pState)->contextTSD))
    3532
    3633/* NOTE: below SetCurrentContext stuff is supposed to be used only internally!!
    3734 * it is placed here only to simplify things since some code besides state_init.c
    3835 * (i.e. state_glsl.c) is using it */
    39 #define SetCurrentContext(_ctx) VBoxTlsRefSetCurrent(CRContext, &__contextTSD, _ctx)
    40 
    41 extern GLboolean g_bVBoxEnableDiffOnMakeCurrent;
    42 
    43 extern CRContext *g_pAvailableContexts[CR_MAX_CONTEXTS];
    44 extern uint32_t g_cContexts;
     36#define SetCurrentContext(a_pState, _ctx) VBoxTlsRefSetCurrent(CRContext, &((a_pState)->contextTSD), _ctx)
    4537
    4638extern void crStateTextureInitTextureObj (CRContext *ctx, CRTextureObj *tobj, GLuint name, GLenum target);
     
    6658void crStateClientSwitch(CRClientBits *cb, CRbitvalue *bitID,   CRContext *from, CRContext *to);
    6759
    68 void crStateFreeBufferObject(void *data);
    69 void crStateFreeFBO(void *data);
    70 void crStateFreeRBO(void *data);
     60void crStateFreeBufferObject(void *data, void *pvUser);
     61void crStateFreeFBO(void *data, void *pvUser);
     62void crStateFreeRBO(void *data, void *pvUser);
    7163
    7264void crStateGenNames(CRContext *g, CRHashTable *table, GLsizei n, GLuint *names);
    7365void crStateRegNames(CRContext *g, CRHashTable *table, GLsizei n, GLuint *names);
    74 void crStateOnTextureUsageRelease(CRSharedState *pS, CRTextureObj *pObj);
     66void crStateOnTextureUsageRelease(PCRStateTracker pState, CRSharedState *pS, CRTextureObj *pObj);
    7567#endif
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_attrib.c

    r69392 r78375  
    8383
    8484static void
    85 copy_texobj(CRTextureObj *dest, CRTextureObj *src, GLboolean copyName)
     85copy_texobj(PCRStateTracker pState, CRTextureObj *dest, CRTextureObj *src, GLboolean copyName)
    8686{
    8787    if (copyName)
    8888    {
    8989        dest->id = src->id;
    90         dest->hwid = crStateGetTextureObjHWID(src);
     90        dest->hwid = crStateGetTextureObjHWID(pState, src);
    9191    }
    9292
     
    109109}
    110110
    111 void STATE_APIENTRY crStatePushAttrib(GLbitfield mask)
     111void STATE_APIENTRY crStatePushAttrib(PCRStateTracker pState, GLbitfield mask)
    112112{
    113     CRContext *g = GetCurrentContext();
     113    CRContext *g = GetCurrentContext(pState);
    114114    CRAttribState *a = &(g->attrib);
    115     CRStateBits *sb = GetCurrentBits();
     115    CRStateBits *sb = GetCurrentBits(pState);
    116116    CRAttribBits *ab = &(sb->attrib);
    117117    unsigned int i;
     
    119119    if (g->current.inBeginEnd)
    120120    {
    121         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glPushAttrib called in Begin/End");
     121        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glPushAttrib called in Begin/End");
    122122        return;
    123123    }
     
    125125    if (a->attribStackDepth == CR_MAX_ATTRIB_STACK_DEPTH - 1)
    126126    {
    127         crStateError(__LINE__, __FILE__, GL_STACK_OVERFLOW, "glPushAttrib called with a full stack!" );
     127        crStateError(pState, __LINE__, __FILE__, GL_STACK_OVERFLOW, "glPushAttrib called with a full stack!" );
    128128        return;
    129129    }
     
    462462            copy_texunit(&tState->unit[i], &g->texture.unit[i]);
    463463            /* texture object state */
    464             copy_texobj(&tState->unit[i].Saved1D, g->texture.unit[i].currentTexture1D, GL_TRUE);
    465             copy_texobj(&tState->unit[i].Saved2D, g->texture.unit[i].currentTexture2D, GL_TRUE);
     464            copy_texobj(pState, &tState->unit[i].Saved1D, g->texture.unit[i].currentTexture1D, GL_TRUE);
     465            copy_texobj(pState, &tState->unit[i].Saved2D, g->texture.unit[i].currentTexture2D, GL_TRUE);
    466466#ifdef CR_OPENGL_VERSION_1_2
    467             copy_texobj(&tState->unit[i].Saved3D, g->texture.unit[i].currentTexture3D, GL_TRUE);
     467            copy_texobj(pState, &tState->unit[i].Saved3D, g->texture.unit[i].currentTexture3D, GL_TRUE);
    468468#endif
    469469#ifdef CR_ARB_texture_cube_map
    470             copy_texobj(&tState->unit[i].SavedCubeMap, g->texture.unit[i].currentTextureCubeMap, GL_TRUE);
     470            copy_texobj(pState, &tState->unit[i].SavedCubeMap, g->texture.unit[i].currentTextureCubeMap, GL_TRUE);
    471471#endif
    472472#ifdef CR_NV_texture_rectangle
    473             copy_texobj(&tState->unit[i].SavedRect, g->texture.unit[i].currentTextureRect, GL_TRUE);
     473            copy_texobj(pState, &tState->unit[i].SavedRect, g->texture.unit[i].currentTextureRect, GL_TRUE);
    474474#endif
    475475        }
     
    512512}
    513513
    514 void STATE_APIENTRY crStatePopAttrib(void)
     514void STATE_APIENTRY crStatePopAttrib(PCRStateTracker pState)
    515515{
    516     CRContext *g = GetCurrentContext();
     516    CRContext *g = GetCurrentContext(pState);
    517517    CRAttribState *a = &(g->attrib);
    518     CRStateBits *sb = GetCurrentBits();
     518    CRStateBits *sb = GetCurrentBits(pState);
    519519    CRAttribBits *ab = &(sb->attrib);
    520520    CRbitvalue mask;
     
    523523    if (g->current.inBeginEnd)
    524524    {
    525         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glPopAttrib called in Begin/End");
     525        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glPopAttrib called in Begin/End");
    526526        return;
    527527    }
     
    529529    if (a->attribStackDepth == 0)
    530530    {
    531         crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty stack!" );
     531        crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty stack!" );
    532532        return;
    533533    }
     
    541541        if (a->accumBufferStackDepth == 0)
    542542        {
    543             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty accum buffer stack!" );
     543            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty accum buffer stack!" );
    544544            return;
    545545        }
     
    553553        if (a->colorBufferStackDepth == 0)
    554554        {
    555             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty color buffer stack!" );
     555            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty color buffer stack!" );
    556556            return;
    557557        }
     
    604604        if (a->currentStackDepth == 0)
    605605        {
    606             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty current stack!" );
     606            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty current stack!" );
    607607            return;
    608608        }
     
    626626        if (a->depthBufferStackDepth == 0)
    627627        {
    628             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty depth buffer stack!" );
     628            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty depth buffer stack!" );
    629629            return;
    630630        }
     
    644644        if (a->enableStackDepth == 0)
    645645        {
    646             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty enable stack!" );
     646            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty enable stack!" );
    647647            return;
    648648        }
     
    738738        if (a->evalStackDepth == 0)
    739739        {
    740             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty eval stack!" );
     740            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty eval stack!" );
    741741            return;
    742742        }
     
    787787        if (a->fogStackDepth == 0)
    788788        {
    789             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty fog stack!" );
     789            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty fog stack!" );
    790790            return;
    791791        }
     
    811811        if (a->hintStackDepth == 0)
    812812        {
    813             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty hint stack!" );
     813            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty hint stack!" );
    814814            return;
    815815        }
     
    842842        if (a->lightingStackDepth == 0)
    843843        {
    844             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty lighting stack!" );
     844            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty lighting stack!" );
    845845            return;
    846846        }
     
    903903        if (a->lineStackDepth == 0)
    904904        {
    905             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty line stack!" );
     905            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty line stack!" );
    906906            return;
    907907        }
     
    921921        if (a->listStackDepth == 0)
    922922        {
    923             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty list stack!" );
     923            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty list stack!" );
    924924            return;
    925925        }
     
    932932        if (a->pixelModeStackDepth == 0)
    933933        {
    934             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty pixel mode stack!" );
     934            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty pixel mode stack!" );
    935935            return;
    936936        }
     
    955955        if (a->pointStackDepth == 0)
    956956        {
    957             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty point stack!" );
     957            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty point stack!" );
    958958            return;
    959959        }
     
    977977        if (a->polygonStackDepth == 0)
    978978        {
    979             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty polygon stack!" );
     979            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty polygon stack!" );
    980980            return;
    981981        }
     
    10031003        if (a->polygonStippleStackDepth == 0)
    10041004        {
    1005             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty polygon stipple stack!" );
     1005            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty polygon stipple stack!" );
    10061006            return;
    10071007        }
     
    10151015        if (a->scissorStackDepth == 0)
    10161016        {
    1017             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty scissor stack!" );
     1017            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty scissor stack!" );
    10181018            return;
    10191019        }
     
    10321032        if (a->stencilBufferStackDepth == 0)
    10331033        {
    1034             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty stencil stack!" );
     1034            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty stencil stack!" );
    10351035            return;
    10361036        }
     
    10651065        if (a->textureStackDepth == 0)
    10661066        {
    1067             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty texture stack!" );
     1067            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty texture stack!" );
    10681068            return;
    10691069        }
     
    10761076            copy_texunit(&g->texture.unit[i], &tState->unit[i]);
    10771077            /* first, restore the bindings! */
    1078             g->texture.unit[i].currentTexture1D = crStateTextureGet(GL_TEXTURE_1D, tState->unit[i].Saved1D.id);
    1079             copy_texobj(g->texture.unit[i].currentTexture1D, &tState->unit[i].Saved1D, GL_FALSE);
    1080             g->texture.unit[i].currentTexture2D = crStateTextureGet(GL_TEXTURE_2D, tState->unit[i].Saved2D.id);
    1081             copy_texobj(g->texture.unit[i].currentTexture2D, &tState->unit[i].Saved2D, GL_FALSE);
     1078            g->texture.unit[i].currentTexture1D = crStateTextureGet(pState, GL_TEXTURE_1D, tState->unit[i].Saved1D.id);
     1079            copy_texobj(pState, g->texture.unit[i].currentTexture1D, &tState->unit[i].Saved1D, GL_FALSE);
     1080            g->texture.unit[i].currentTexture2D = crStateTextureGet(pState, GL_TEXTURE_2D, tState->unit[i].Saved2D.id);
     1081            copy_texobj(pState, g->texture.unit[i].currentTexture2D, &tState->unit[i].Saved2D, GL_FALSE);
    10821082#ifdef CR_OPENGL_VERSION_1_2
    1083             g->texture.unit[i].currentTexture3D = crStateTextureGet(GL_TEXTURE_3D, tState->unit[i].Saved3D.id);
    1084             copy_texobj(g->texture.unit[i].currentTexture3D, &tState->unit[i].Saved3D, GL_FALSE);
     1083            g->texture.unit[i].currentTexture3D = crStateTextureGet(pState, GL_TEXTURE_3D, tState->unit[i].Saved3D.id);
     1084            copy_texobj(pState, g->texture.unit[i].currentTexture3D, &tState->unit[i].Saved3D, GL_FALSE);
    10851085#endif
    10861086#ifdef CR_ARB_texture_cube_map
    1087             g->texture.unit[i].currentTextureCubeMap = crStateTextureGet(GL_TEXTURE_CUBE_MAP_ARB, tState->unit[i].SavedCubeMap.id);
    1088             copy_texobj(g->texture.unit[i].currentTextureCubeMap, &tState->unit[i].SavedCubeMap, GL_FALSE);
     1087            g->texture.unit[i].currentTextureCubeMap = crStateTextureGet(pState, GL_TEXTURE_CUBE_MAP_ARB, tState->unit[i].SavedCubeMap.id);
     1088            copy_texobj(pState, g->texture.unit[i].currentTextureCubeMap, &tState->unit[i].SavedCubeMap, GL_FALSE);
    10891089#endif
    10901090#ifdef CR_NV_texture_rectangle
    1091             g->texture.unit[i].currentTextureRect = crStateTextureGet(GL_TEXTURE_CUBE_MAP_ARB, tState->unit[i].SavedRect.id);
    1092             copy_texobj(g->texture.unit[i].currentTextureRect, &tState->unit[i].SavedRect, GL_FALSE);
     1091            g->texture.unit[i].currentTextureRect = crStateTextureGet(pState, GL_TEXTURE_CUBE_MAP_ARB, tState->unit[i].SavedRect.id);
     1092            copy_texobj(pState, g->texture.unit[i].currentTextureRect, &tState->unit[i].SavedRect, GL_FALSE);
    10931093#endif
    10941094        }
     
    11301130        if (a->transformStackDepth == 0)
    11311131        {
    1132             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty transform stack!" );
     1132            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty transform stack!" );
    11331133            return;
    11341134        }
    11351135        a->transformStackDepth--;
    11361136        g->transform.matrixMode = a->transformStack[a->transformStackDepth].matrixMode;
    1137         crStateMatrixMode(g->transform.matrixMode);
     1137        crStateMatrixMode(pState, g->transform.matrixMode);
    11381138        for (i = 0 ; i < g->limits.maxClipPlanes ; i++)
    11391139        {
     
    11541154        if (a->viewportStackDepth == 0)
    11551155        {
    1156             crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty viewport stack!" );
     1156            crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "glPopAttrib called with an empty viewport stack!" );
    11571157            return;
    11581158        }
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_buffer.c

    r69392 r78375  
    1313{
    1414    CRBufferState *b = &ctx->buffer;
    15     CRStateBits *sb          = GetCurrentBits();
     15    CRStateBits *sb          = GetCurrentBits(ctx->pStateTracker);
    1616    CRBufferBits *bb = &(sb->buffer);
    1717    GLcolorf zero_colorf = {0.0f, 0.0f, 0.0f, 0.0f};
     
    8383}
    8484
    85 void STATE_APIENTRY crStateAlphaFunc (GLenum func, GLclampf ref)
    86 {
    87     CRContext *g             = GetCurrentContext();
     85void STATE_APIENTRY crStateAlphaFunc (PCRStateTracker pState, GLenum func, GLclampf ref)
     86{
     87    CRContext *g             = GetCurrentContext(pState);
    8888    CRBufferState *b         = &(g->buffer);
    89     CRStateBits *sb          = GetCurrentBits();
    90     CRBufferBits *bb = &(sb->buffer);
    91 
    92     if (g->current.inBeginEnd)
    93     {
    94         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glAlphaFunc called in begin/end");
     89    CRStateBits *sb          = GetCurrentBits(pState);
     90    CRBufferBits *bb = &(sb->buffer);
     91
     92    if (g->current.inBeginEnd)
     93    {
     94        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glAlphaFunc called in begin/end");
    9595        return;
    9696    }
     
    110110            break;
    111111        default:
    112             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glAlphaFunc:  Invalid func: %d", func);
     112            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glAlphaFunc:  Invalid func: %d", func);
    113113            return;
    114114    }
     
    123123}
    124124
    125 void STATE_APIENTRY crStateDepthFunc (GLenum func)
    126 {
    127     CRContext *g = GetCurrentContext();
    128     CRBufferState *b = &(g->buffer);
    129     CRStateBits *sb = GetCurrentBits();
    130     CRBufferBits *bb = &(sb->buffer);
    131 
    132     if (g->current.inBeginEnd)
    133     {
    134         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDepthFunc called in begin/end");
     125void STATE_APIENTRY crStateDepthFunc (PCRStateTracker pState, GLenum func)
     126{
     127    CRContext *g = GetCurrentContext(pState);
     128    CRBufferState *b = &(g->buffer);
     129    CRStateBits *sb = GetCurrentBits(pState);
     130    CRBufferBits *bb = &(sb->buffer);
     131
     132    if (g->current.inBeginEnd)
     133    {
     134        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glDepthFunc called in begin/end");
    135135        return;
    136136    }
     
    150150            break;
    151151        default:
    152             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glDepthFunc:  Invalid func: %d", func);
     152            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glDepthFunc:  Invalid func: %d", func);
    153153            return;
    154154    }
     
    160160}
    161161
    162 void STATE_APIENTRY crStateBlendFunc (GLenum sfactor, GLenum dfactor)
    163 {
    164     CRContext *g = GetCurrentContext();
    165     CRBufferState *b = &(g->buffer);
    166     CRStateBits *sb = GetCurrentBits();
    167     CRBufferBits *bb = &(sb->buffer);
    168 
    169     if (g->current.inBeginEnd)
    170     {
    171         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glBlendFunc called in begin/end");
     162void STATE_APIENTRY crStateBlendFunc (PCRStateTracker pState, GLenum sfactor, GLenum dfactor)
     163{
     164    CRContext *g = GetCurrentContext(pState);
     165    CRBufferState *b = &(g->buffer);
     166    CRStateBits *sb = GetCurrentBits(pState);
     167    CRBufferBits *bb = &(sb->buffer);
     168
     169    if (g->current.inBeginEnd)
     170    {
     171        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glBlendFunc called in begin/end");
    172172        return;
    173173    }
     
    197197        RT_FALL_THRU();
    198198        default:
    199             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactor passed to glBlendFunc: %d", sfactor);
     199            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactor passed to glBlendFunc: %d", sfactor);
    200200            return;
    201201    }
     
    222222        RT_FALL_THRU();
    223223        default:
    224             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactor passed to glBlendFunc: %d", dfactor);
     224            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactor passed to glBlendFunc: %d", dfactor);
    225225            return;
    226226    }
     
    234234}
    235235
    236 void STATE_APIENTRY crStateBlendColorEXT( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
    237 {
    238     CRContext *g = GetCurrentContext();
    239     CRBufferState *b = &(g->buffer);
    240     CRStateBits *sb = GetCurrentBits();
    241     CRBufferBits *bb = &(sb->buffer);
    242 
    243     if (g->current.inBeginEnd)
    244     {
    245         crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendColorEXT called inside a Begin/End" );
     236void STATE_APIENTRY crStateBlendColorEXT(PCRStateTracker pState, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
     237{
     238    CRContext *g = GetCurrentContext(pState);
     239    CRBufferState *b = &(g->buffer);
     240    CRStateBits *sb = GetCurrentBits(pState);
     241    CRBufferBits *bb = &(sb->buffer);
     242
     243    if (g->current.inBeginEnd)
     244    {
     245        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendColorEXT called inside a Begin/End" );
    246246        return;
    247247    }
     
    256256
    257257#ifdef CR_EXT_blend_func_separate
    258 void STATE_APIENTRY crStateBlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA )
    259 {
    260     CRContext *g = GetCurrentContext();
    261     CRBufferState *b = &(g->buffer);
    262     CRStateBits *sb = GetCurrentBits();
    263     CRBufferBits *bb = &(sb->buffer);
    264 
    265     if (g->current.inBeginEnd)
    266     {
    267         crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendFuncSeparateEXT called inside a Begin/End" );
     258void STATE_APIENTRY crStateBlendFuncSeparateEXT(PCRStateTracker pState, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA )
     259{
     260    CRContext *g = GetCurrentContext(pState);
     261    CRBufferState *b = &(g->buffer);
     262    CRStateBits *sb = GetCurrentBits(pState);
     263    CRBufferBits *bb = &(sb->buffer);
     264
     265    if (g->current.inBeginEnd)
     266    {
     267        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendFuncSeparateEXT called inside a Begin/End" );
    268268        return;
    269269    }
     
    293293        RT_FALL_THRU();
    294294        default:
    295             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactorRGB passed to glBlendFuncSeparateEXT: %d", sfactorRGB);
     295            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactorRGB passed to glBlendFuncSeparateEXT: %d", sfactorRGB);
    296296            return;
    297297    }
     
    319319        RT_FALL_THRU();
    320320        default:
    321             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactorA passed to glBlendFuncSeparateEXT: %d", sfactorA);
     321            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactorA passed to glBlendFuncSeparateEXT: %d", sfactorA);
    322322            return;
    323323    }
     
    347347        RT_FALL_THRU();
    348348        default:
    349             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactorRGB passed to glBlendFuncSeparateEXT: %d", dfactorRGB);
     349            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactorRGB passed to glBlendFuncSeparateEXT: %d", dfactorRGB);
    350350            return;
    351351    }
     
    375375        RT_FALL_THRU();
    376376        default:
    377             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactorA passed to glBlendFuncSeparateEXT: %d", dfactorA);
     377            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactorA passed to glBlendFuncSeparateEXT: %d", dfactorA);
    378378            return;
    379379    }
     
    388388#endif
    389389
    390 void STATE_APIENTRY crStateBlendEquationEXT( GLenum mode )
    391 {
    392     CRContext *g = GetCurrentContext();
    393     CRBufferState *b = &(g->buffer);
    394     CRStateBits *sb = GetCurrentBits();
     390void STATE_APIENTRY crStateBlendEquationEXT(PCRStateTracker pState, GLenum mode )
     391{
     392    CRContext *g = GetCurrentContext(pState);
     393    CRBufferState *b = &(g->buffer);
     394    CRStateBits *sb = GetCurrentBits(pState);
    395395    CRBufferBits *bb = &(sb->buffer);
    396396
    397397    if( g->current.inBeginEnd )
    398398    {
    399         crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendEquationEXT called inside a Begin/End" );
     399        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendEquationEXT called inside a Begin/End" );
    400400        return;
    401401    }
     
    419419#endif /* defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op) */
    420420        default:
    421             crStateError( __LINE__, __FILE__, GL_INVALID_ENUM,
     421            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    422422                "BlendEquationEXT: mode called with illegal parameter: 0x%x", (GLenum) mode );
    423423            return;
     
    427427}
    428428
    429 void STATE_APIENTRY crStateLogicOp (GLenum opcode)
    430 {
    431     CRContext *g = GetCurrentContext();
    432     CRBufferState *b = &(g->buffer);
    433     CRStateBits *sb = GetCurrentBits();
    434     CRBufferBits *bb = &(sb->buffer);
    435 
    436     if (g->current.inBeginEnd)
    437     {
    438         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glLogicOp called in begin/end");
     429void STATE_APIENTRY crStateLogicOp (PCRStateTracker pState, GLenum opcode)
     430{
     431    CRContext *g = GetCurrentContext(pState);
     432    CRBufferState *b = &(g->buffer);
     433    CRStateBits *sb = GetCurrentBits(pState);
     434    CRBufferBits *bb = &(sb->buffer);
     435
     436    if (g->current.inBeginEnd)
     437    {
     438        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glLogicOp called in begin/end");
    439439        return;
    440440    }
     
    462462            break;
    463463        default:
    464             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glLogicOp called with bogus opcode: %d", opcode);
     464            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glLogicOp called with bogus opcode: %d", opcode);
    465465            return;
    466466    }
     
    472472}
    473473
    474 void STATE_APIENTRY crStateDrawBuffer (GLenum mode)
    475 {
    476     CRContext *g = GetCurrentContext();
    477     CRBufferState *b = &(g->buffer);
    478     CRStateBits *sb = GetCurrentBits();
    479     CRBufferBits *bb = &(sb->buffer);
    480 
    481     if (g->current.inBeginEnd)
    482     {
    483         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer called in begin/end");
     474void STATE_APIENTRY crStateDrawBuffer (PCRStateTracker pState, GLenum mode)
     475{
     476    CRContext *g = GetCurrentContext(pState);
     477    CRBufferState *b = &(g->buffer);
     478    CRStateBits *sb = GetCurrentBits(pState);
     479    CRBufferBits *bb = &(sb->buffer);
     480
     481    if (g->current.inBeginEnd)
     482    {
     483        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer called in begin/end");
    484484        return;
    485485    }
     
    506506            if (g->framebufferobject.drawFB)
    507507            {
    508                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer invalid mode while fbo is active");
     508                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer invalid mode while fbo is active");
    509509                return;
    510510            }
     
    515515                if (!g->framebufferobject.drawFB)
    516516                {
    517                     crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer invalid mode while fbo is inactive");
     517                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer invalid mode while fbo is inactive");
    518518                    return;
    519519                }
     
    521521            else
    522522            {
    523                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glDrawBuffer called with bogus mode: %d", mode);
     523                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glDrawBuffer called with bogus mode: %d", mode);
    524524                return;
    525525            }
     
    538538}
    539539
    540 void STATE_APIENTRY crStateReadBuffer (GLenum mode)
    541 {
    542     CRContext *g = GetCurrentContext();
    543     CRBufferState *b = &(g->buffer);
    544     CRStateBits *sb = GetCurrentBits();
    545     CRBufferBits *bb = &(sb->buffer);
    546 
    547     if (g->current.inBeginEnd)
    548     {
    549         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
     540void STATE_APIENTRY crStateReadBuffer (PCRStateTracker pState, GLenum mode)
     541{
     542    CRContext *g = GetCurrentContext(pState);
     543    CRBufferState *b = &(g->buffer);
     544    CRStateBits *sb = GetCurrentBits(pState);
     545    CRBufferBits *bb = &(sb->buffer);
     546
     547    if (g->current.inBeginEnd)
     548    {
     549        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
    550550        return;
    551551    }
     
    572572            if (g->framebufferobject.readFB)
    573573            {
    574                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer invalid mode while fbo is active");
     574                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer invalid mode while fbo is active");
    575575                return;
    576576            }
     
    581581                if (!g->framebufferobject.readFB)
    582582                {
    583                     crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer invalid mode while fbo is inactive");
     583                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer invalid mode while fbo is inactive");
    584584                    return;
    585585                }
     
    591591            else
    592592            {
    593                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glReadBuffer called with bogus mode: %d", mode);
     593                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glReadBuffer called with bogus mode: %d", mode);
    594594                return;
    595595            }
     
    608608}
    609609
    610 void STATE_APIENTRY crStateIndexMask (GLuint mask)
    611 {
    612     CRContext *g = GetCurrentContext();
    613     CRBufferState *b = &(g->buffer);
    614     CRStateBits *sp = GetCurrentBits();
     610void STATE_APIENTRY crStateIndexMask (PCRStateTracker pState, GLuint mask)
     611{
     612    CRContext *g = GetCurrentContext(pState);
     613    CRBufferState *b = &(g->buffer);
     614    CRStateBits *sp = GetCurrentBits(pState);
    615615    CRBufferBits *bb = &(sp->buffer);
    616616
    617617    if (g->current.inBeginEnd)
    618618    {
    619         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
     619        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
    620620        return;
    621621    }
     
    628628}
    629629
    630 void STATE_APIENTRY crStateColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
    631 {
    632     CRContext *g = GetCurrentContext();
    633     CRBufferState *b = &(g->buffer);
    634     CRStateBits *sp = GetCurrentBits();
     630void STATE_APIENTRY crStateColorMask (PCRStateTracker pState, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
     631{
     632    CRContext *g = GetCurrentContext(pState);
     633    CRBufferState *b = &(g->buffer);
     634    CRStateBits *sp = GetCurrentBits(pState);
    635635    CRBufferBits *bb = &(sp->buffer);
    636636
    637637    if (g->current.inBeginEnd)
    638638    {
    639         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
     639        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
    640640        return;
    641641    }
     
    651651}
    652652
    653 void STATE_APIENTRY crStateClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
    654 {
    655     CRContext *g = GetCurrentContext();
    656     CRBufferState *b = &(g->buffer);
    657     CRStateBits *sp = GetCurrentBits();
     653void STATE_APIENTRY crStateClearColor (PCRStateTracker pState, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
     654{
     655    CRContext *g = GetCurrentContext(pState);
     656    CRBufferState *b = &(g->buffer);
     657    CRStateBits *sp = GetCurrentBits(pState);
    658658    CRBufferBits *bb = &(sp->buffer);
    659659
    660660    if (g->current.inBeginEnd)
    661661    {
    662         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearColor called in begin/end");
     662        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glClearColor called in begin/end");
    663663        return;
    664664    }
     
    683683}
    684684
    685 void STATE_APIENTRY crStateClearIndex (GLfloat c)
    686 {
    687     CRContext *g = GetCurrentContext();
    688     CRBufferState *b = &(g->buffer);
    689     CRStateBits *sp = GetCurrentBits();
     685void STATE_APIENTRY crStateClearIndex (PCRStateTracker pState, GLfloat c)
     686{
     687    CRContext *g = GetCurrentContext(pState);
     688    CRBufferState *b = &(g->buffer);
     689    CRStateBits *sp = GetCurrentBits(pState);
    690690    CRBufferBits *bb = &(sp->buffer);
    691691
    692692    if (g->current.inBeginEnd)
    693693    {
    694         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearIndex called in begin/end");
     694        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glClearIndex called in begin/end");
    695695        return;
    696696    }
     
    701701}
    702702
    703 void STATE_APIENTRY crStateClearDepth (GLclampd depth)
    704 {
    705     CRContext *g = GetCurrentContext();
    706     CRBufferState *b = &(g->buffer);
    707     CRStateBits *sp = GetCurrentBits();
     703void STATE_APIENTRY crStateClearDepth (PCRStateTracker pState, GLclampd depth)
     704{
     705    CRContext *g = GetCurrentContext(pState);
     706    CRBufferState *b = &(g->buffer);
     707    CRStateBits *sp = GetCurrentBits(pState);
    708708    CRBufferBits *bb = &(sp->buffer);
    709709
    710710    if (g->current.inBeginEnd)
    711711    {
    712         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearDepth called in begin/end");
     712        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glClearDepth called in begin/end");
    713713        return;
    714714    }
     
    724724}
    725725
    726 void STATE_APIENTRY crStateClearAccum (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
    727 {
    728     CRContext *g = GetCurrentContext();
    729     CRBufferState *b = &(g->buffer);
    730     CRStateBits *sp = GetCurrentBits();
     726void STATE_APIENTRY crStateClearAccum (PCRStateTracker pState, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
     727{
     728    CRContext *g = GetCurrentContext(pState);
     729    CRBufferState *b = &(g->buffer);
     730    CRStateBits *sp = GetCurrentBits(pState);
    731731    CRBufferBits *bb = &(sp->buffer);
    732732
    733733    if (g->current.inBeginEnd)
    734734    {
    735         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearAccum called in begin/end");
     735        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glClearAccum called in begin/end");
    736736        return;
    737737    }
     
    756756}
    757757
    758 void STATE_APIENTRY crStateDepthMask (GLboolean b)
    759 {
    760     CRContext *g = GetCurrentContext();
     758void STATE_APIENTRY crStateDepthMask (PCRStateTracker pState, GLboolean b)
     759{
     760    CRContext *g = GetCurrentContext(pState);
    761761    CRBufferState *bs = &(g->buffer);
    762     CRStateBits *sp = GetCurrentBits();
     762    CRStateBits *sp = GetCurrentBits(pState);
    763763    CRBufferBits *bb = &(sp->buffer);
    764764
    765765    if (g->current.inBeginEnd)
    766766    {
    767         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "DepthMask called in begin/end");
     767        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "DepthMask called in begin/end");
    768768        return;
    769769    }
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_bufferobject.c

    r78116 r78375  
    2828}
    2929
    30 void STATE_APIENTRY crStateGenBuffersARB(GLsizei n, GLuint *buffers)
    31 {
    32     CRContext *g = GetCurrentContext();
     30void STATE_APIENTRY crStateGenBuffersARB(PCRStateTracker pState, GLsizei n, GLuint *buffers)
     31{
     32    CRContext *g = GetCurrentContext(pState);
    3333    crStateGenNames(g, g->shared->buffersTable, n, buffers);
    3434}
    3535
    36 void crStateRegBuffers(GLsizei n, GLuint *buffers)
    37 {
    38     CRContext *g = GetCurrentContext();
     36void crStateRegBuffers(PCRStateTracker pState, GLsizei n, GLuint *buffers)
     37{
     38    CRContext *g = GetCurrentContext(pState);
    3939    crStateRegNames(g, g->shared->buffersTable, n, buffers);
    4040}
     
    6161}
    6262
    63 GLboolean crStateIsBufferBound(GLenum target)
    64 {
    65     CRContext *g = GetCurrentContext();
     63GLboolean crStateIsBufferBound(PCRStateTracker pState, GLenum target)
     64{
     65    CRContext *g = GetCurrentContext(pState);
    6666    return crStateIsBufferBoundForCtx(g, target);
    6767}
     
    8686}
    8787
    88 DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsBufferARB( GLuint buffer )
    89 {
    90     CRContext *g = GetCurrentContext();
     88DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsBufferARB(PCRStateTracker pState, GLuint buffer )
     89{
     90    CRContext *g = GetCurrentContext(pState);
    9191
    9292    FLUSH();
    9393
    9494    if (g->current.inBeginEnd) {
    95         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     95        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    9696                                 "glIsBufferARB called in begin/end");
    9797        return GL_FALSE;
     
    103103void crStateBufferObjectInit (CRContext *ctx)
    104104{
    105     CRStateBits *sb          = GetCurrentBits();
     105    CRStateBits *sb          = GetCurrentBits(ctx->pStateTracker);
    106106    CRBufferObjectBits *bb = &sb->bufferobject;
    107107    CRBufferObjectState *b = &ctx->bufferobject;
     
    114114    RESET(bb->packBinding, ctx->bitid);
    115115#endif
     116
     117    b->pStateTracker = ctx->pStateTracker;
    116118
    117119#ifdef IN_GUEST
     
    134136}
    135137
    136 void crStateFreeBufferObject(void *data)
     138void crStateFreeBufferObject(void *data, void *pvUser)
    137139{
    138140    CRBufferObject *pObj = (CRBufferObject *)data;
     141    PCRStateTracker pState = (PCRStateTracker)pvUser;
    139142    if (pObj->data) crFree(pObj->data);
    140143
    141144#ifndef IN_GUEST
    142     if (diff_api.DeleteBuffersARB)
    143     {
    144         diff_api.DeleteBuffersARB(1, &pObj->hwid);
     145    if (pState->diff_api.DeleteBuffersARB)
     146    {
     147        pState->diff_api.DeleteBuffersARB(1, &pObj->hwid);
    145148    }
    146149#endif
     
    165168}
    166169
    167 DECLEXPORT(GLuint) STATE_APIENTRY crStateBufferHWIDtoID(GLuint hwid)
    168 {
    169     CRContext *g = GetCurrentContext();
     170DECLEXPORT(GLuint) STATE_APIENTRY crStateBufferHWIDtoID(PCRStateTracker pState, GLuint hwid)
     171{
     172    CRContext *g = GetCurrentContext(pState);
    170173    crCheckIDHWID_t parms;
    171174
     
    177180}
    178181
    179 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetBufferHWID(GLuint id)
    180 {
    181     CRContext *g = GetCurrentContext();
     182DECLEXPORT(GLuint) STATE_APIENTRY crStateGetBufferHWID(PCRStateTracker pState, GLuint id)
     183{
     184    CRContext *g = GetCurrentContext(pState);
    182185    CRBufferObject *pObj = (CRBufferObject *) crHashtableSearch(g->shared->buffersTable, id);
    183186
     
    186189
    187190void STATE_APIENTRY
    188 crStateBindBufferARB (GLenum target, GLuint buffer)
    189 {
    190     CRContext *g = GetCurrentContext();
     191crStateBindBufferARB (PCRStateTracker pState, GLenum target, GLuint buffer)
     192{
     193    CRContext *g = GetCurrentContext(pState);
    191194    CRBufferObjectState *b = &(g->bufferobject);
    192     CRStateBits *sb = GetCurrentBits();
     195    CRStateBits *sb = GetCurrentBits(pState);
    193196    CRBufferObjectBits *bb = &(sb->bufferobject);
    194197    CRBufferObject *oldObj, *newObj;
    195198
    196199    if (g->current.inBeginEnd) {
    197         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     200        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    198201                                 "glBindBufferARB called in begin/end");
    199202        return;
     
    205208    if (!oldObj)
    206209    {
    207         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glBindBufferARB(target)");
     210        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glBindBufferARB(target)");
    208211        return;
    209212    }
     
    219222            CRSTATE_CHECKERR(!newObj, GL_OUT_OF_MEMORY, "glBindBuffer");
    220223#ifndef IN_GUEST
    221             diff_api.GenBuffersARB(1, &newObj->hwid);
     224            pState->diff_api.GenBuffersARB(1, &newObj->hwid);
    222225            if (!newObj->hwid)
    223226            {
     
    268271        /*we shouldn't reach this point*/
    269272        CRASSERT(false);
    270         crHashtableDelete(g->shared->buffersTable, (unsigned long) oldObj->id, crStateFreeBufferObject);
     273        crHashtableDeleteEx(g->shared->buffersTable, (unsigned long) oldObj->id, crStateFreeBufferObject, pState);
    271274    }
    272275
     
    279282}
    280283
    281 static void ctStateBuffersRefsCleanup(CRContext *ctx, CRBufferObject *obj, CRbitvalue *neg_bitid)
     284static void ctStateBuffersRefsCleanup(PCRStateTracker pState, CRContext *ctx, CRBufferObject *obj, CRbitvalue *neg_bitid)
    282285{
    283286    CRBufferObjectState *b = &(ctx->bufferobject);
    284     CRStateBits *sb = GetCurrentBits();
     287    CRStateBits *sb = GetCurrentBits(pState);
    285288    CRBufferObjectBits *bb = &(sb->bufferobject);
    286289    int j, k;
     
    347350
    348351void STATE_APIENTRY
    349 crStateDeleteBuffersARB(GLsizei n, const GLuint *buffers)
    350 {
    351     CRContext *g = GetCurrentContext();
     352crStateDeleteBuffersARB(PCRStateTracker pState, GLsizei n, const GLuint *buffers)
     353{
     354    CRContext *g = GetCurrentContext(pState);
    352355    int i;
    353356
     
    355358
    356359    if (g->current.inBeginEnd) {
    357         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     360        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    358361                                 "glDeleteBuffersARB called in Begin/End");
    359362        return;
     
    361364
    362365    if (n < 0) {
    363         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     366        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    364367                                 "glDeleteBuffersARB(n < 0)");
    365368        return;
     
    373376                int j;
    374377
    375                 ctStateBuffersRefsCleanup(g, obj, g->neg_bitid);
     378                ctStateBuffersRefsCleanup(pState, g, obj, g->neg_bitid);
    376379
    377380                CR_STATE_SHAREDOBJ_USAGE_FOREACH_USED_IDX(obj, j)
     
    381384                     * This is why g_pAvailableContexts[j] could be NULL
    382385                     * also g_pAvailableContexts[0] will hold default context, which we should discard */
    383                     CRContext *ctx = g_pAvailableContexts[j];
     386                    CRContext *ctx = pState->apAvailableContexts[j];
    384387                    if (j && ctx)
    385388                    {
    386                         ctStateBuffersRefsCleanup(ctx, obj, g->neg_bitid); /* <- yes, use g->neg_bitid, i.e. neg_bitid of the current context to ensure others bits get dirtified,
    387                                                                             * but not the current context ones*/
     389                        ctStateBuffersRefsCleanup(pState, ctx, obj, g->neg_bitid); /* <- yes, use g->neg_bitid, i.e. neg_bitid of the current context to ensure others bits get dirtified,
     390                                                                                    * but not the current context ones*/
    388391                    }
    389392                    else
     
    391394                }
    392395
    393                 crHashtableDelete(g->shared->buffersTable, buffers[i], crStateFreeBufferObject);
     396                crHashtableDeleteEx(g->shared->buffersTable, buffers[i], crStateFreeBufferObject, pState);
    394397            }
    395398        }
     
    398401
    399402void STATE_APIENTRY
    400 crStateBufferDataARB(GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage)
    401 {
    402     CRContext *g = GetCurrentContext();
     403crStateBufferDataARB(PCRStateTracker pState, GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage)
     404{
     405    CRContext *g = GetCurrentContext(pState);
    403406    CRBufferObjectState *b = &g->bufferobject;
    404407    CRBufferObject *obj;
    405     CRStateBits *sb = GetCurrentBits();
     408    CRStateBits *sb = GetCurrentBits(pState);
    406409    CRBufferObjectBits *bb = &sb->bufferobject;
    407410
     
    409412
    410413    if (g->current.inBeginEnd) {
    411         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     414        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    412415                                 "glBufferDataARB called in begin/end");
    413416        return;
     
    415418
    416419    if (size < 0) {
    417         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     420        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    418421                                 "glBufferDataARB(size < 0)");
    419422        return;
     
    433436            break;
    434437        default:
    435             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     438            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    436439                                     "glBufferDataARB(usage)");
    437440            return;
     
    441444    if (!obj)
    442445    {
    443         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glBufferDataARB(target)");
     446        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glBufferDataARB(target)");
    444447        return;
    445448    }
    446449
    447450    if (obj->id == 0) {
    448         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glBufferDataARB");
     451        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glBufferDataARB");
    449452        return;
    450453    }
    451454
    452455    if (obj->pointer) {
    453         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     456        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    454457                                 "glBufferDataARB(buffer is mapped)");
    455458        return;
     
    469472        obj->data = crAlloc(size);
    470473        if (!obj->data) {
    471             crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glBufferDataARB");
     474            crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY, "glBufferDataARB");
    472475            return;
    473476        }
     
    484487
    485488void STATE_APIENTRY
    486 crStateBufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid * data)
    487 {
    488     CRContext *g = GetCurrentContext();
     489crStateBufferSubDataARB(PCRStateTracker pState, GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid * data)
     490{
     491    CRContext *g = GetCurrentContext(pState);
    489492    CRBufferObjectState *b = &g->bufferobject;
    490493    CRBufferObject *obj;
    491     CRStateBits *sb = GetCurrentBits();
     494    CRStateBits *sb = GetCurrentBits(pState);
    492495    CRBufferObjectBits *bb = &sb->bufferobject;
    493496
     
    495498
    496499    if (g->current.inBeginEnd) {
    497         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     500        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    498501                                 "glBufferSubDataARB called in begin/end");
    499502        return;
     
    503506    if (!obj)
    504507    {
    505         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glBufferSubDataARB(target)");
     508        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glBufferSubDataARB(target)");
    506509        return;
    507510    }
    508511
    509512    if (obj->id == 0) {
    510         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     513        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    511514                                 "glBufferSubDataARB");
    512515        return;
     
    514517
    515518    if (obj->pointer) {
    516         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     519        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    517520                                 "glBufferSubDataARB(buffer is mapped)");
    518521        return;
     
    520523
    521524    if (size < 0 || offset < 0 || (unsigned int)offset + size > obj->size) {
    522         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     525        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    523526                                 "glBufferSubDataARB(bad offset and/or size)");
    524527        return;
     
    540543
    541544void STATE_APIENTRY
    542 crStateGetBufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, void * data)
    543 {
    544     CRContext *g = GetCurrentContext();
     545crStateGetBufferSubDataARB(PCRStateTracker pState, GLenum target, GLintptrARB offset, GLsizeiptrARB size, void * data)
     546{
     547    CRContext *g = GetCurrentContext(pState);
    545548    CRBufferObjectState *b = &g->bufferobject;
    546549    CRBufferObject *obj;
     
    549552
    550553    if (g->current.inBeginEnd) {
    551         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     554        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    552555                                 "glGetBufferSubDataARB called in begin/end");
    553556        return;
     
    557560    if (!obj)
    558561    {
    559         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetBufferSubDataARB(target)");
     562        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetBufferSubDataARB(target)");
    560563        return;
    561564    }
    562565
    563566    if (obj->id == 0) {
    564         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     567        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    565568                                 "glGetBufferSubDataARB");
    566569        return;
     
    568571
    569572    if (obj->pointer) {
    570         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     573        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    571574                                 "glGetBufferSubDataARB(buffer is mapped)");
    572575        return;
     
    574577
    575578    if (size < 0 || offset < 0 || (unsigned int)offset + size > obj->size) {
    576         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     579        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    577580                                 "glGetBufferSubDataARB(bad offset and/or size)");
    578581        return;
     
    586589
    587590void * STATE_APIENTRY
    588 crStateMapBufferARB(GLenum target, GLenum access)
    589 {
    590     CRContext *g = GetCurrentContext();
     591crStateMapBufferARB(PCRStateTracker pState, GLenum target, GLenum access)
     592{
     593    CRContext *g = GetCurrentContext(pState);
    591594    CRBufferObjectState *b = &g->bufferobject;
    592595    CRBufferObject *obj;
     
    595598
    596599    if (g->current.inBeginEnd) {
    597         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     600        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    598601                                 "glMapBufferARB called in begin/end");
    599602        return NULL;
     
    603606    if (!obj)
    604607    {
    605         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMapBufferARB(target)");
     608        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMapBufferARB(target)");
    606609        return NULL;
    607610    }
    608611
    609612    if (obj->id == 0) {
    610         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glMapBufferARB");
     613        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glMapBufferARB");
    611614        return GL_FALSE;
    612615    }
     
    619622            break;
    620623        default:
    621             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     624            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    622625                                     "glMapBufferARB(access)");
    623626            return NULL;
     
    632635
    633636GLboolean STATE_APIENTRY
    634 crStateUnmapBufferARB(GLenum target)
    635 {
    636     CRContext *g = GetCurrentContext();
     637crStateUnmapBufferARB(PCRStateTracker pState, GLenum target)
     638{
     639    CRContext *g = GetCurrentContext(pState);
    637640    CRBufferObjectState *b = &g->bufferobject;
    638641    CRBufferObject *obj;
    639     CRStateBits *sb = GetCurrentBits();
     642    CRStateBits *sb = GetCurrentBits(pState);
    640643    CRBufferObjectBits *bb = &sb->bufferobject;
    641644
     
    643646
    644647    if (g->current.inBeginEnd) {
    645         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     648        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    646649                                 "glUnmapBufferARB called in begin/end");
    647650        return GL_FALSE;
     
    651654    if (!obj)
    652655    {
    653         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glUnmapBufferARB(target)");
     656        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glUnmapBufferARB(target)");
    654657        return GL_FALSE;
    655658    }
    656659
    657660    if (obj->id == 0) {
    658         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glUnmapBufferARB");
     661        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glUnmapBufferARB");
    659662        return GL_FALSE;
    660663    }
    661664
    662665    if (!obj->pointer) {
    663         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glUnmapBufferARB");
     666        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glUnmapBufferARB");
    664667        return GL_FALSE;
    665668    }
     
    680683
    681684void STATE_APIENTRY
    682 crStateGetBufferParameterivARB(GLenum target, GLenum pname, GLint *params)
    683 {
    684     CRContext *g = GetCurrentContext();
     685crStateGetBufferParameterivARB(PCRStateTracker pState, GLenum target, GLenum pname, GLint *params)
     686{
     687    CRContext *g = GetCurrentContext(pState);
    685688    CRBufferObjectState *b = &g->bufferobject;
    686689    CRBufferObject *obj;
     
    689692
    690693    if (g->current.inBeginEnd) {
    691         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     694        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    692695                                 "glGetBufferParameterivARB called in begin/end");
    693696        return;
     
    697700    if (!obj)
    698701    {
    699         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetBufferParameterivARB(target)");
     702        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetBufferParameterivARB(target)");
    700703        return;
    701704    }
     
    715718            break;
    716719        default:
    717             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     720            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    718721                                     "glGetBufferParameterivARB(pname)");
    719722            return;
     
    723726
    724727void STATE_APIENTRY
    725 crStateGetBufferPointervARB(GLenum target, GLenum pname, GLvoid **params)
    726 {
    727     CRContext *g = GetCurrentContext();
     728crStateGetBufferPointervARB(PCRStateTracker pState, GLenum target, GLenum pname, GLvoid **params)
     729{
     730    CRContext *g = GetCurrentContext(pState);
    728731    CRBufferObjectState *b = &g->bufferobject;
    729732    CRBufferObject *obj;
     
    732735
    733736    if (g->current.inBeginEnd) {
    734         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     737        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    735738                                 "glGetBufferPointervARB called in begin/end");
    736739        return;
     
    740743    if (!obj)
    741744    {
    742         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetBufferPointervARB(target)");
     745        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetBufferPointervARB(target)");
    743746        return;
    744747    }
    745748
    746749    if (pname != GL_BUFFER_MAP_POINTER_ARB) {
    747         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetBufferPointervARB(pname)");
     750        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetBufferPointervARB(pname)");
    748751        return;
    749752    }
     
    763766 */
    764767static GLboolean
    765 HaveBufferObjectExtension(void)
     768HaveBufferObjectExtension(PCRStateTracker pState)
    766769{
    767770    static GLint haveBufferObjectExt = -1;
     
    772775         * GetString into the diff'ing table in order for this to really work.
    773776         */
    774         if (!diff_api.GetString) {
     777        if (!pState->diff_api.GetString) {
    775778            haveBufferObjectExt = 0;
    776779            return 0;
    777780        }
    778         CRASSERT(diff_api.GetString);
    779         ext = (const char *) diff_api.GetString(GL_EXTENSIONS);
     781        CRASSERT(pState->diff_api.GetString);
     782        ext = (const char *) pState->diff_api.GetString(GL_EXTENSIONS);
    780783        if (crStrstr(ext, "GL_ARB_vertex_buffer_object") ||
    781784                crStrstr(ext, "GL_ARB_pixel_buffer_object")) {
     
    793796                                      GLboolean bSwitch)
    794797{
     798    PCRStateTracker pState = fromCtx->pStateTracker;
    795799    CRBufferObjectState *from = &(fromCtx->bufferobject);
    796800    const CRBufferObjectState *to = &(toCtx->bufferobject);
    797801
     802    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     803
    798804    /* ARRAY_BUFFER */
    799805    if (CHECKDIRTY(bb->arrayBinding, bitID))
     
    802808        {
    803809            GLuint bufferID = to->arrayBuffer ? to->arrayBuffer->hwid : 0;
    804             diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, bufferID);
     810            pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, bufferID);
    805811            if (bSwitch)
    806812            {
     
    825831        {
    826832            /* update whole buffer */
    827             diff_api.BufferDataARB(GL_ARRAY_BUFFER_ARB, bufObj->size,
    828                                    bufObj->data, bufObj->usage);
     833            pState->diff_api.BufferDataARB(GL_ARRAY_BUFFER_ARB, bufObj->size,
     834                                           bufObj->data, bufObj->usage);
    829835        }
    830836        else
    831837        {
    832838            /* update sub buffer */
    833             diff_api.BufferSubDataARB(GL_ARRAY_BUFFER_ARB,
    834                                       bufObj->dirtyStart, bufObj->dirtyLength,
    835                                       (char *) bufObj->data + bufObj->dirtyStart);
     839            pState->diff_api.BufferSubDataARB(GL_ARRAY_BUFFER_ARB,
     840                                              bufObj->dirtyStart, bufObj->dirtyLength,
     841                                              (char *) bufObj->data + bufObj->dirtyStart);
    836842        }
    837843        if (bSwitch) FILLDIRTY(bufObj->dirty);
     
    845851        {
    846852            GLuint bufferID = to->elementsBuffer ? to->elementsBuffer->hwid : 0;
    847             diff_api.BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, bufferID);
     853            pState->diff_api.BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, bufferID);
    848854            if (bSwitch)
    849855            {
     
    868874        {
    869875            /* update whole buffer */
    870             diff_api.BufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, bufObj->size,
    871                                    bufObj->data, bufObj->usage);
     876            pState->diff_api.BufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, bufObj->size,
     877                                           bufObj->data, bufObj->usage);
    872878        }
    873879        else
    874880        {
    875881            /* update sub buffer */
    876             diff_api.BufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
    877                                       bufObj->dirtyStart, bufObj->dirtyLength,
    878                                       (char *) bufObj->data + bufObj->dirtyStart);
     882            pState->diff_api.BufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
     883                                              bufObj->dirtyStart, bufObj->dirtyLength,
     884                                              (char *) bufObj->data + bufObj->dirtyStart);
    879885        }
    880886        if (bSwitch) FILLDIRTY(bufObj->dirty);
     
    889895        {
    890896            GLuint bufferID = to->packBuffer ? to->packBuffer->hwid : 0;
    891             diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, bufferID);
     897            pState->diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, bufferID);
    892898            if (bSwitch)
    893899            {
     
    912918        {
    913919            /* update whole buffer */
    914             diff_api.BufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, bufObj->size,
    915                                    bufObj->data, bufObj->usage);
     920            pState->diff_api.BufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, bufObj->size,
     921                                           bufObj->data, bufObj->usage);
    916922        }
    917923        else
    918924        {
    919925            /* update sub buffer */
    920             diff_api.BufferSubDataARB(GL_PIXEL_PACK_BUFFER_ARB,
    921                                       bufObj->dirtyStart, bufObj->dirtyLength,
    922                                       (char *) bufObj->data + bufObj->dirtyStart);
     926            pState->diff_api.BufferSubDataARB(GL_PIXEL_PACK_BUFFER_ARB,
     927                                              bufObj->dirtyStart, bufObj->dirtyLength,
     928                                              (char *) bufObj->data + bufObj->dirtyStart);
    923929        }
    924930        if (bSwitch) FILLDIRTY(bufObj->dirty);
     
    932938        {
    933939            GLuint bufferID = to->unpackBuffer ? to->unpackBuffer->hwid : 0;
    934             diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, bufferID);
     940            pState->diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, bufferID);
    935941            if (bSwitch)
    936942            {
     
    955961        {
    956962            /* update whole buffer */
    957             diff_api.BufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, bufObj->size,
    958                                    bufObj->data, bufObj->usage);
     963            pState->diff_api.BufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, bufObj->size,
     964                                           bufObj->data, bufObj->usage);
    959965        }
    960966        else
    961967        {
    962968            /* update sub buffer */
    963             diff_api.BufferSubDataARB(GL_PIXEL_UNPACK_BUFFER_ARB,
    964                                       bufObj->dirtyStart, bufObj->dirtyLength,
    965                                       (char *) bufObj->data + bufObj->dirtyStart);
     969            pState->diff_api.BufferSubDataARB(GL_PIXEL_UNPACK_BUFFER_ARB,
     970                                              bufObj->dirtyStart, bufObj->dirtyLength,
     971                                              (char *) bufObj->data + bufObj->dirtyStart);
    966972        }
    967973        if (bSwitch) FILLDIRTY(bufObj->dirty);
     
    974980                             CRContext *fromCtx, CRContext *toCtx)
    975981{
    976     /*CRBufferObjectState *from = &(fromCtx->bufferobject); - unused
    977     const CRBufferObjectState *to = &(toCtx->bufferobject); - unused */
    978 
    979     if (!HaveBufferObjectExtension())
     982    PCRStateTracker pState = fromCtx->pStateTracker;
     983    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     984
     985    if (!HaveBufferObjectExtension(pState))
    980986        return;
    981987
     
    991997    if (pBufferObj->id && !pBufferObj->hwid)
    992998    {
    993         diff_api.GenBuffersARB(1, &pBufferObj->hwid);
     999        pState->pStateTracker->diff_api.GenBuffersARB(1, &pBufferObj->hwid);
    9941000        CRASSERT(pBufferObj->hwid);
    9951001    }
     
    10041010          hurt performance."
    10051011         */
    1006         diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pBufferObj->hwid);
    1007         diff_api.BufferDataARB(GL_ARRAY_BUFFER_ARB, pBufferObj->size, pBufferObj->data, pBufferObj->usage);
     1012        pState->pStateTracker->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pBufferObj->hwid);
     1013        pState->pStateTracker->diff_api.BufferDataARB(GL_ARRAY_BUFFER_ARB, pBufferObj->size, pBufferObj->data, pBufferObj->usage);
    10081014
    10091015        if (!pState->retainBufferData)
     
    10211027                               CRContext *fromCtx, CRContext *toCtx)
    10221028{
    1023     /*const CRBufferObjectState *from = &(fromCtx->bufferobject); - unused */
    10241029    CRBufferObjectState *to = &(toCtx->bufferobject);
     1030    PCRStateTracker pState = fromCtx->pStateTracker;
    10251031    int i;
    10261032
    1027     if (!HaveBufferObjectExtension())
     1033    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     1034
     1035    if (!HaveBufferObjectExtension(pState))
    10281036        return;
    10291037
     
    10401048        if (cp->buffer && (cp->buffer->id || locked))
    10411049        {
    1042             diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
    1043             diff_api.VertexPointer(cp->size, cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
     1050            pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
     1051            pState->diff_api.VertexPointer(cp->size, cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
    10441052        }
    10451053
     
    10471055        if (cp->buffer && (cp->buffer->id || locked))
    10481056        {
    1049             diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
    1050             diff_api.ColorPointer(cp->size, cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
     1057            pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
     1058            pState->diff_api.ColorPointer(cp->size, cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
    10511059        }
    10521060
     
    10541062        if (cp->buffer && (cp->buffer->id || locked))
    10551063        {
    1056             diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
    1057             diff_api.FogCoordPointerEXT(cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
     1064            pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
     1065            pState->diff_api.FogCoordPointerEXT(cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
    10581066        }
    10591067
     
    10611069        if (cp->buffer && (cp->buffer->id || locked))
    10621070        {
    1063             diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
    1064             diff_api.SecondaryColorPointerEXT(cp->size, cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
     1071            pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
     1072            pState->diff_api.SecondaryColorPointerEXT(cp->size, cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
    10651073        }
    10661074
     
    10681076        if (cp->buffer && (cp->buffer->id || locked))
    10691077        {
    1070             diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
    1071             diff_api.EdgeFlagPointer(cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
     1078            pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
     1079            pState->diff_api.EdgeFlagPointer(cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
    10721080        }
    10731081
     
    10751083        if (cp->buffer && (cp->buffer->id || locked))
    10761084        {
    1077             diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
    1078             diff_api.IndexPointer(cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
     1085            pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
     1086            pState->diff_api.IndexPointer(cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
    10791087        }
    10801088
     
    10821090        if (cp->buffer && (cp->buffer->id || locked))
    10831091        {
    1084             diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
    1085             diff_api.NormalPointer(cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
     1092            pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
     1093            pState->diff_api.NormalPointer(cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
    10861094        }
    10871095
     
    10911099            if (cp->buffer && (cp->buffer->id || locked))
    10921100            {
    1093                 if (diff_api.ActiveTextureARB)
    1094                     diff_api.ActiveTextureARB(i+GL_TEXTURE0_ARB);
    1095                 diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
    1096                 diff_api.TexCoordPointer(cp->size, cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
    1097             }
    1098         }
    1099 
    1100         if (diff_api.ActiveTextureARB)
    1101             diff_api.ActiveTextureARB(toCtx->client.curClientTextureUnit+GL_TEXTURE0_ARB);
     1101                if (pState->diff_api.ActiveTextureARB)
     1102                    pState->diff_api.ActiveTextureARB(i+GL_TEXTURE0_ARB);
     1103                pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
     1104                pState->diff_api.TexCoordPointer(cp->size, cp->type, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
     1105            }
     1106        }
     1107
     1108        if (pState->diff_api.ActiveTextureARB)
     1109            pState->diff_api.ActiveTextureARB(toCtx->client.curClientTextureUnit+GL_TEXTURE0_ARB);
    11021110
    11031111#ifdef CR_NV_vertex_program
     
    11071115            if (cp->buffer && (cp->buffer->id || locked))
    11081116            {
    1109                 diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
    1110                 diff_api.VertexAttribPointerARB(i, cp->size, cp->type, cp->normalized, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
    1111             }
    1112         }
    1113 #endif
    1114         diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, to->arrayBuffer->hwid);
    1115         diff_api.BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, to->elementsBuffer->hwid);
     1117                pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->hwid);
     1118                pState->diff_api.VertexAttribPointerARB(i, cp->size, cp->type, cp->normalized, cp->stride, cp->p CRVBOX_HOST_ONLY_PARAM(-1 /*fRealPtr*/));
     1119            }
     1120        }
     1121#endif
     1122        pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, to->arrayBuffer->hwid);
     1123        pState->diff_api.BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, to->elementsBuffer->hwid);
    11161124#ifdef CR_ARB_pixel_buffer_object
    1117         diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, to->packBuffer->hwid);
    1118         diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, to->unpackBuffer->hwid);
     1125        pState->diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, to->packBuffer->hwid);
     1126        pState->diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, to->unpackBuffer->hwid);
    11191127#endif
    11201128    }
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_client.c

    r78263 r78375  
    376376 */
    377377
    378 void STATE_APIENTRY crStatePixelStoref (GLenum pname, GLfloat param)
     378void STATE_APIENTRY crStatePixelStoref (PCRStateTracker pState, GLenum pname, GLfloat param)
    379379{
    380380
     
    386386        case GL_UNPACK_SWAP_BYTES:
    387387        case GL_UNPACK_LSB_FIRST:
    388             crStatePixelStorei( pname, param == 0.0f ? 0: 1 );
     388            crStatePixelStorei(pState, pname, param == 0.0f ? 0: 1 );
    389389            break;
    390390        default:
    391             crStatePixelStorei( pname, (GLint) param );
    392             break;
    393     }
    394 }
    395 
    396 void STATE_APIENTRY crStatePixelStorei (GLenum pname, GLint param)
    397 {
    398     CRContext *g    = GetCurrentContext();
     391            crStatePixelStorei(pState, pname, (GLint) param );
     392            break;
     393    }
     394}
     395
     396void STATE_APIENTRY crStatePixelStorei (PCRStateTracker pState, GLenum pname, GLint param)
     397{
     398    CRContext *g    = GetCurrentContext(pState);
    399399    CRClientState *c = &(g->client);
    400     CRStateBits *sb = GetCurrentBits();
     400    CRStateBits *sb = GetCurrentBits(pState);
    401401    CRClientBits *cb = &(sb->client);
    402402
    403403    if (g->current.inBeginEnd)
    404404    {
    405         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "PixelStore{if} called in Begin/End");
     405        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "PixelStore{if} called in Begin/End");
    406406        return;
    407407    }
     
    421421            if (param < 0.0f)
    422422            {
    423                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Length: %f", param);
     423                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Length: %f", param);
    424424                return;
    425425            }
     
    431431            if (param < 0.0f)
    432432            {
    433                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative Image Height: %f", param);
     433                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Image Height: %f", param);
    434434                return;
    435435            }
     
    441441            if (param < 0.0f)
    442442            {
    443                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Images: %f", param);
     443                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Images: %f", param);
    444444                return;
    445445            }
     
    450450            if (param < 0.0f)
    451451            {
    452                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Pixels: %f", param);
     452                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Pixels: %f", param);
    453453                return;
    454454            }
     
    459459            if (param < 0.0f)
    460460            {
    461                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Skip: %f", param);
     461                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Skip: %f", param);
    462462                return;
    463463            }
     
    471471                    ((GLint) param) != 8)
    472472            {
    473                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Invalid Alignment: %f", param);
     473                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Invalid Alignment: %f", param);
    474474                return;
    475475            }
     
    489489            if (param < 0.0f)
    490490            {
    491                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Length: %f", param);
     491                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Length: %f", param);
    492492                return;
    493493            }
     
    499499            if (param < 0.0f)
    500500            {
    501                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative Image Height: %f", param);
     501                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Image Height: %f", param);
    502502                return;
    503503            }
     
    509509            if (param < 0.0f)
    510510            {
    511                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Images: %f", param);
     511                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Images: %f", param);
    512512                return;
    513513            }
     
    518518            if (param < 0.0f)
    519519            {
    520                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Pixels: %f", param);
     520                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Pixels: %f", param);
    521521                return;
    522522            }
     
    527527            if (param < 0.0f)
    528528            {
    529                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Skip: %f", param);
     529                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Skip: %f", param);
    530530                return;
    531531            }
     
    539539                    ((GLint) param) != 8)
    540540            {
    541                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Invalid Alignment: %f", param);
     541                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Invalid Alignment: %f", param);
    542542                return;
    543543            }
     
    546546            break;
    547547        default:
    548             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Unknown glPixelStore Pname: %d", pname);
     548            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Unknown glPixelStore Pname: %d", pname);
    549549            return;
    550550    }
     
    553553
    554554
    555 static void setClientState(CRClientState *c, CRClientBits *cb,
    556         CRbitvalue *neg_bitid, GLenum array, GLboolean state)
    557 {
    558     CRContext *g = GetCurrentContext();
     555static void setClientState(CRContext *g, CRClientState *c, CRClientBits *cb,
     556                           CRbitvalue *neg_bitid, GLenum array, GLboolean state)
     557{
     558    PCRStateTracker pState = g->pStateTracker;
    559559
    560560    switch (array)
     
    612612            }
    613613            else {
    614                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid Enum passed to Enable/Disable Client State: SECONDARY_COLOR_ARRAY_EXT - EXT_secondary_color is not enabled." );
     614                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid Enum passed to Enable/Disable Client State: SECONDARY_COLOR_ARRAY_EXT - EXT_secondary_color is not enabled." );
    615615                return;
    616616            }
     
    618618#endif
    619619        default:
    620             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid Enum passed to Enable/Disable Client State: 0x%x", array );
     620            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid Enum passed to Enable/Disable Client State: 0x%x", array );
    621621            return;
    622622    }
     
    625625}
    626626
    627 void STATE_APIENTRY crStateEnableClientState (GLenum array)
    628 {
    629     CRContext *g = GetCurrentContext();
     627void STATE_APIENTRY crStateEnableClientState (PCRStateTracker pState, GLenum array)
     628{
     629    CRContext *g = GetCurrentContext(pState);
    630630    CRClientState *c = &(g->client);
    631     CRStateBits *sb = GetCurrentBits();
     631    CRStateBits *sb = GetCurrentBits(pState);
    632632    CRClientBits *cb = &(sb->client);
    633633
    634634    FLUSH();
    635635
    636     setClientState(c, cb, g->neg_bitid, array, GL_TRUE);
    637 }
    638 
    639 void STATE_APIENTRY crStateDisableClientState (GLenum array)
    640 {
    641     CRContext *g = GetCurrentContext();
     636    setClientState(g, c, cb, g->neg_bitid, array, GL_TRUE);
     637}
     638
     639void STATE_APIENTRY crStateDisableClientState (PCRStateTracker pState, GLenum array)
     640{
     641    CRContext *g = GetCurrentContext(pState);
    642642    CRClientState *c = &(g->client);
    643     CRStateBits *sb = GetCurrentBits();
     643    CRStateBits *sb = GetCurrentBits(pState);
    644644    CRClientBits *cb = &(sb->client);
    645645
    646646    FLUSH();
    647647
    648     setClientState(c, cb, g->neg_bitid, array, GL_FALSE);
     648    setClientState(g, c, cb, g->neg_bitid, array, GL_FALSE);
    649649}
    650650
    651651static void
    652 crStateClientSetPointer(CRClientPointer *cp, GLint size, GLenum type, GLboolean normalized, GLsizei stride,
     652crStateClientSetPointer(CRContext *g, CRClientPointer *cp, GLint size, GLenum type, GLboolean normalized, GLsizei stride,
    653653                        const GLvoid *pointer  CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    654654{
    655     CRContext *g = GetCurrentContext();
     655    PCRStateTracker pState = g->pStateTracker;
    656656
    657657#ifdef CR_EXT_compiled_vertex_array
     
    701701            break;
    702702        default:
    703             crStateError( __LINE__, __FILE__, GL_INVALID_VALUE,
     703            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    704704                                        "Unknown type of vertex array: %d", type );
    705705            return;
     
    729729}
    730730
    731 void STATE_APIENTRY crStateVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    732 {
    733     CRContext *g = GetCurrentContext();
     731void STATE_APIENTRY crStateVertexPointer(PCRStateTracker pState, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     732{
     733    CRContext *g = GetCurrentContext(pState);
    734734    CRClientState *c = &(g->client);
    735     CRStateBits *sb = GetCurrentBits();
     735    CRStateBits *sb = GetCurrentBits(pState);
    736736    CRClientBits *cb = &(sb->client);
    737737
     
    740740    if (size != 2 && size != 3 && size != 4)
    741741    {
    742         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glVertexPointer: invalid size: %d", size);
     742        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glVertexPointer: invalid size: %d", size);
    743743        return;
    744744    }
     
    746746            type != GL_FLOAT && type != GL_DOUBLE)
    747747    {
    748         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glVertexPointer: invalid type: 0x%x", type);
     748        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glVertexPointer: invalid type: 0x%x", type);
    749749        return;
    750750    }
    751751    if (stride < 0)
    752752    {
    753         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glVertexPointer: stride was negative: %d", stride);
    754         return;
    755     }
    756 
    757     crStateClientSetPointer(&(c->array.v), size, type, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
     753        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glVertexPointer: stride was negative: %d", stride);
     754        return;
     755    }
     756
     757    crStateClientSetPointer(g, &(c->array.v), size, type, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
    758758    DIRTY(cb->dirty, g->neg_bitid);
    759759    DIRTY(cb->clientPointer, g->neg_bitid);
     
    761761}
    762762
    763 void STATE_APIENTRY crStateColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    764 {
    765     CRContext *g = GetCurrentContext();
     763void STATE_APIENTRY crStateColorPointer(PCRStateTracker pState, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     764{
     765    CRContext *g = GetCurrentContext(pState);
    766766    CRClientState *c = &(g->client);
    767     CRStateBits *sb = GetCurrentBits();
     767    CRStateBits *sb = GetCurrentBits(pState);
    768768    CRClientBits *cb = &(sb->client);
    769769
     
    772772    if (size != 3 && size != 4)
    773773    {
    774         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glColorPointer: invalid size: %d", size);
     774        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glColorPointer: invalid size: %d", size);
    775775        return;
    776776    }
     
    780780            type != GL_FLOAT && type != GL_DOUBLE)
    781781    {
    782         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glColorPointer: invalid type: 0x%x", type);
     782        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glColorPointer: invalid type: 0x%x", type);
    783783        return;
    784784    }
    785785    if (stride < 0)
    786786    {
    787         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glColorPointer: stride was negative: %d", stride);
    788         return;
    789     }
    790 
    791     crStateClientSetPointer(&(c->array.c), size, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
     787        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glColorPointer: stride was negative: %d", stride);
     788        return;
     789    }
     790
     791    crStateClientSetPointer(g, &(c->array.c), size, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
    792792    DIRTY(cb->dirty, g->neg_bitid);
    793793    DIRTY(cb->clientPointer, g->neg_bitid);
     
    795795}
    796796
    797 void STATE_APIENTRY crStateSecondaryColorPointerEXT(GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    798 {
    799     CRContext *g = GetCurrentContext();
     797void STATE_APIENTRY crStateSecondaryColorPointerEXT(PCRStateTracker pState, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     798{
     799    CRContext *g = GetCurrentContext(pState);
    800800    CRClientState *c = &(g->client);
    801     CRStateBits *sb = GetCurrentBits();
     801    CRStateBits *sb = GetCurrentBits(pState);
    802802    CRClientBits *cb = &(sb->client);
    803803
     
    821821    if ((size != 3) && (size != 4))
    822822    {
    823         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glSecondaryColorPointerEXT: invalid size: %d", size);
     823        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glSecondaryColorPointerEXT: invalid size: %d", size);
    824824        return;
    825825    }
     
    829829            type != GL_FLOAT && type != GL_DOUBLE)
    830830    {
    831         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glSecondaryColorPointerEXT: invalid type: 0x%x", type);
     831        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glSecondaryColorPointerEXT: invalid type: 0x%x", type);
    832832        return;
    833833    }
    834834    if (stride < 0)
    835835    {
    836         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glSecondaryColorPointerEXT: stride was negative: %d", stride);
    837         return;
    838     }
    839 
    840     crStateClientSetPointer(&(c->array.s), size, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
     836        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glSecondaryColorPointerEXT: stride was negative: %d", stride);
     837        return;
     838    }
     839
     840    crStateClientSetPointer(g, &(c->array.s), size, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
    841841    DIRTY(cb->dirty, g->neg_bitid);
    842842    DIRTY(cb->clientPointer, g->neg_bitid);
     
    844844}
    845845
    846 void STATE_APIENTRY crStateIndexPointer(GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    847 {
    848     CRContext *g = GetCurrentContext();
     846void STATE_APIENTRY crStateIndexPointer(PCRStateTracker pState, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     847{
     848    CRContext *g = GetCurrentContext(pState);
    849849    CRClientState *c = &(g->client);
    850     CRStateBits *sb = GetCurrentBits();
     850    CRStateBits *sb = GetCurrentBits(pState);
    851851    CRClientBits *cb = &(sb->client);
    852852
     
    856856            type != GL_FLOAT && type != GL_DOUBLE)
    857857    {
    858         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glIndexPointer: invalid type: 0x%x", type);
     858        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glIndexPointer: invalid type: 0x%x", type);
    859859        return;
    860860    }
    861861    if (stride < 0)
    862862    {
    863         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glIndexPointer: stride was negative: %d", stride);
    864         return;
    865     }
    866 
    867     crStateClientSetPointer(&(c->array.i), 1, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
     863        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glIndexPointer: stride was negative: %d", stride);
     864        return;
     865    }
     866
     867    crStateClientSetPointer(g, &(c->array.i), 1, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
    868868    DIRTY(cb->dirty, g->neg_bitid);
    869869    DIRTY(cb->clientPointer, g->neg_bitid);
     
    871871}
    872872
    873 void STATE_APIENTRY crStateNormalPointer(GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    874 {
    875     CRContext *g = GetCurrentContext();
     873void STATE_APIENTRY crStateNormalPointer(PCRStateTracker pState, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     874{
     875    CRContext *g = GetCurrentContext(pState);
    876876    CRClientState *c = &(g->client);
    877     CRStateBits *sb = GetCurrentBits();
     877    CRStateBits *sb = GetCurrentBits(pState);
    878878    CRClientBits *cb = &(sb->client);
    879879
     
    884884            type != GL_DOUBLE)
    885885    {
    886         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glNormalPointer: invalid type: 0x%x", type);
     886        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glNormalPointer: invalid type: 0x%x", type);
    887887        return;
    888888    }
    889889    if (stride < 0)
    890890    {
    891         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glNormalPointer: stride was negative: %d", stride);
    892         return;
    893     }
    894 
    895     crStateClientSetPointer(&(c->array.n), 3, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
     891        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glNormalPointer: stride was negative: %d", stride);
     892        return;
     893    }
     894
     895    crStateClientSetPointer(g, &(c->array.n), 3, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
    896896    DIRTY(cb->dirty, g->neg_bitid);
    897897    DIRTY(cb->clientPointer, g->neg_bitid);
     
    899899}
    900900
    901 void STATE_APIENTRY crStateTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    902 {
    903     CRContext *g = GetCurrentContext();
     901void STATE_APIENTRY crStateTexCoordPointer(PCRStateTracker pState, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     902{
     903    CRContext *g = GetCurrentContext(pState);
    904904    CRClientState *c = &(g->client);
    905     CRStateBits *sb = GetCurrentBits();
     905    CRStateBits *sb = GetCurrentBits(pState);
    906906    CRClientBits *cb = &(sb->client);
    907907
     
    910910    if (size != 1 && size != 2 && size != 3 && size != 4)
    911911    {
    912         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexCoordPointer: invalid size: %d", size);
     912        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glTexCoordPointer: invalid size: %d", size);
    913913        return;
    914914    }
     
    916916            type != GL_FLOAT && type != GL_DOUBLE)
    917917    {
    918         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexCoordPointer: invalid type: 0x%x", type);
     918        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glTexCoordPointer: invalid type: 0x%x", type);
    919919        return;
    920920    }
    921921    if (stride < 0)
    922922    {
    923         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexCoordPointer: stride was negative: %d", stride);
    924         return;
    925     }
    926 
    927     crStateClientSetPointer(&(c->array.t[c->curClientTextureUnit]), size, type, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
     923        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glTexCoordPointer: stride was negative: %d", stride);
     924        return;
     925    }
     926
     927    crStateClientSetPointer(g, &(c->array.t[c->curClientTextureUnit]), size, type, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
    928928    DIRTY(cb->dirty, g->neg_bitid);
    929929    DIRTY(cb->clientPointer, g->neg_bitid);
     
    931931}
    932932
    933 void STATE_APIENTRY crStateEdgeFlagPointer(GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    934 {
    935     CRContext *g = GetCurrentContext();
     933void STATE_APIENTRY crStateEdgeFlagPointer(PCRStateTracker pState, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     934{
     935    CRContext *g = GetCurrentContext(pState);
    936936    CRClientState *c = &(g->client);
    937     CRStateBits *sb = GetCurrentBits();
     937    CRStateBits *sb = GetCurrentBits(pState);
    938938    CRClientBits *cb = &(sb->client);
    939939
     
    942942    if (stride < 0)
    943943    {
    944         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexCoordPointer: stride was negative: %d", stride);
    945         return;
    946     }
    947 
    948     crStateClientSetPointer(&(c->array.e), 1, GL_UNSIGNED_BYTE, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
     944        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glTexCoordPointer: stride was negative: %d", stride);
     945        return;
     946    }
     947
     948    crStateClientSetPointer(g, &(c->array.e), 1, GL_UNSIGNED_BYTE, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
    949949    DIRTY(cb->dirty, g->neg_bitid);
    950950    DIRTY(cb->clientPointer, g->neg_bitid);
     
    952952}
    953953
    954 void STATE_APIENTRY crStateFogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    955 {
    956     CRContext *g = GetCurrentContext();
     954void STATE_APIENTRY crStateFogCoordPointerEXT(PCRStateTracker pState, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     955{
     956    CRContext *g = GetCurrentContext(pState);
    957957    CRClientState *c = &(g->client);
    958     CRStateBits *sb = GetCurrentBits();
     958    CRStateBits *sb = GetCurrentBits(pState);
    959959    CRClientBits *cb = &(sb->client);
    960960
     
    966966            type != GL_FLOAT && type != GL_DOUBLE)
    967967    {
    968         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glFogCoordPointerEXT: invalid type: 0x%x", type);
     968        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glFogCoordPointerEXT: invalid type: 0x%x", type);
    969969        return;
    970970    }
    971971    if (stride < 0)
    972972    {
    973         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glFogCoordPointerEXT: stride was negative: %d", stride);
    974         return;
    975     }
    976 
    977     crStateClientSetPointer(&(c->array.f), 1, type, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
     973        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glFogCoordPointerEXT: stride was negative: %d", stride);
     974        return;
     975    }
     976
     977    crStateClientSetPointer(g, &(c->array.f), 1, type, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
    978978    DIRTY(cb->dirty, g->neg_bitid);
    979979    DIRTY(cb->clientPointer, g->neg_bitid);
     
    982982
    983983
    984 void STATE_APIENTRY crStateVertexAttribPointerNV(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     984void STATE_APIENTRY crStateVertexAttribPointerNV(PCRStateTracker pState, GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    985985{
    986986    GLboolean normalized = GL_FALSE;
     
    988988    if (type != GL_UNSIGNED_BYTE && type != GL_SHORT &&
    989989            type != GL_FLOAT && type != GL_DOUBLE) {
    990         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     990        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    991991                                 "glVertexAttribPointerNV: invalid type: 0x%x", type);
    992992        return;
    993993    }
    994     crStateVertexAttribPointerARB(index, size, type, normalized, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
    995 }
    996 
    997 
    998 void STATE_APIENTRY crStateVertexAttribPointerARB(GLuint index, GLint size, GLenum type, GLboolean normalized,
     994    crStateVertexAttribPointerARB(pState, index, size, type, normalized, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
     995}
     996
     997
     998void STATE_APIENTRY crStateVertexAttribPointerARB(PCRStateTracker pState, GLuint index, GLint size, GLenum type, GLboolean normalized,
    999999                                                  GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    10001000{
    1001     CRContext *g = GetCurrentContext();
     1001    CRContext *g = GetCurrentContext(pState);
    10021002    CRClientState *c = &(g->client);
    1003     CRStateBits *sb = GetCurrentBits();
     1003    CRStateBits *sb = GetCurrentBits(pState);
    10041004    CRClientBits *cb = &(sb->client);
    10051005
     
    10081008    if (index >= CR_MAX_VERTEX_ATTRIBS)
    10091009    {
    1010         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glVertexAttribPointerARB: invalid index: %d", (int) index);
     1010        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glVertexAttribPointerARB: invalid index: %d", (int) index);
    10111011        return;
    10121012    }
    10131013    if (size != 1 && size != 2 && size != 3 && size != 4)
    10141014    {
    1015         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glVertexAttribPointerARB: invalid size: %d", size);
     1015        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glVertexAttribPointerARB: invalid size: %d", size);
    10161016        return;
    10171017    }
     
    10211021            type != GL_FLOAT && type != GL_DOUBLE)
    10221022    {
    1023         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glVertexAttribPointerARB: invalid type: 0x%x", type);
     1023        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glVertexAttribPointerARB: invalid type: 0x%x", type);
    10241024        return;
    10251025    }
    10261026    if (stride < 0)
    10271027    {
    1028         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glVertexAttribPointerARB: stride was negative: %d", stride);
    1029         return;
    1030     }
    1031 
    1032     crStateClientSetPointer(&(c->array.a[index]), size, type, normalized, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
     1028        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glVertexAttribPointerARB: stride was negative: %d", stride);
     1029        return;
     1030    }
     1031
     1032    crStateClientSetPointer(g, &(c->array.a[index]), size, type, normalized, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
    10331033    DIRTY(cb->dirty, g->neg_bitid);
    10341034    DIRTY(cb->clientPointer, g->neg_bitid);
     
    10371037
    10381038
    1039 void STATE_APIENTRY crStateGetVertexAttribPointervNV(GLuint index, GLenum pname, GLvoid **pointer)
    1040 {
    1041     CRContext *g = GetCurrentContext();
     1039void STATE_APIENTRY crStateGetVertexAttribPointervNV(PCRStateTracker pState, GLuint index, GLenum pname, GLvoid **pointer)
     1040{
     1041    CRContext *g = GetCurrentContext(pState);
    10421042
    10431043    if (g->current.inBeginEnd) {
    1044         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1044        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    10451045                                 "glGetVertexAttribPointervNV called in Begin/End");
    10461046        return;
     
    10481048
    10491049    if (index >= CR_MAX_VERTEX_ATTRIBS) {
    1050         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1050        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    10511051                                 "glGetVertexAttribPointervNV(index)");
    10521052        return;
     
    10541054
    10551055    if (pname != GL_ATTRIB_ARRAY_POINTER_NV) {
    1056         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1056        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    10571057                                 "glGetVertexAttribPointervNV(pname)");
    10581058        return;
     
    10631063
    10641064
    1065 void STATE_APIENTRY crStateGetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
    1066 {
    1067     crStateGetVertexAttribPointervNV(index, pname, pointer);
     1065void STATE_APIENTRY crStateGetVertexAttribPointervARB(PCRStateTracker pState, GLuint index, GLenum pname, GLvoid **pointer)
     1066{
     1067    crStateGetVertexAttribPointervNV(pState, index, pname, pointer);
    10681068}
    10691069
     
    10761076** lets me use the same glDrawArrays method.
    10771077*/
    1078 void STATE_APIENTRY crStateInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    1079 {
    1080     CRContext *g = GetCurrentContext();
     1078void STATE_APIENTRY crStateInterleavedArrays(PCRStateTracker pState, GLenum format, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     1079{
     1080    CRContext *g = GetCurrentContext(pState);
    10811081    CRClientState *c = &(g->client);
    1082     CRStateBits *sb = GetCurrentBits();
     1082    CRStateBits *sb = GetCurrentBits(pState);
    10831083    CRClientBits *cb = &(sb->client);
    10841084    CRClientPointer *cp;
     
    10911091    if (g->current.inBeginEnd)
    10921092    {
    1093         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glInterleavedArrays called in begin/end");
     1093        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glInterleavedArrays called in begin/end");
    10941094        return;
    10951095    }
     
    10991099    if (stride < 0)
    11001100    {
    1101         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glInterleavedArrays: stride < 0: %d", stride);
     1101        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glInterleavedArrays: stride < 0: %d", stride);
    11021102        return;
    11031103    }
     
    11211121            break;
    11221122        default:
    1123             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
     1123            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
    11241124            return;
    11251125    }
     
    12001200            break;
    12011201        default:
    1202             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
     1202            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
    12031203            return;
    12041204    }
     
    12501250            break;
    12511251        default:
    1252             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
     1252            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
    12531253            return;
    12541254    }
     
    13311331            break;
    13321332        default:
    1333             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
     1333            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
    13341334            return;
    13351335    }
     
    13831383            break;
    13841384        default:
    1385             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
     1385            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
    13861386            return;
    13871387    }
     
    13941394}
    13951395
    1396 void STATE_APIENTRY crStateGetPointerv(GLenum pname, GLvoid * * params)
    1397 {
    1398     CRContext *g = GetCurrentContext();
     1396void STATE_APIENTRY crStateGetPointerv(PCRStateTracker pState, GLenum pname, GLvoid * * params)
     1397{
     1398    CRContext *g = GetCurrentContext(pState);
    13991399    CRClientState *c = &(g->client);
    14001400
    14011401    if (g->current.inBeginEnd)
    14021402    {
    1403         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1403        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    14041404                "GetPointerv called in begin/end");
    14051405        return;
     
    14371437            }
    14381438            else {
    1439                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid Enum passed to glGetPointerv: SECONDARY_COLOR_ARRAY_EXT - EXT_secondary_color is not enabled." );
     1439                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid Enum passed to glGetPointerv: SECONDARY_COLOR_ARRAY_EXT - EXT_secondary_color is not enabled." );
    14401440                return;
    14411441            }
     
    14471447            break;
    14481448        default:
    1449             crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1449            crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    14501450                    "glGetPointerv: invalid pname: %d", pname);
    14511451            return;
     
    14541454
    14551455
    1456 void STATE_APIENTRY crStatePushClientAttrib( GLbitfield mask )
    1457 {
    1458     CRContext *g = GetCurrentContext();
     1456void STATE_APIENTRY crStatePushClientAttrib(PCRStateTracker pState, GLbitfield mask )
     1457{
     1458    CRContext *g = GetCurrentContext(pState);
    14591459    CRClientState *c = &(g->client);
    14601460
    14611461    if (g->current.inBeginEnd) {
    1462         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1462        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    14631463                                 "glPushClientAttrib called in Begin/End");
    14641464        return;
     
    14661466
    14671467    if (c->attribStackDepth == CR_MAX_CLIENT_ATTRIB_STACK_DEPTH - 1) {
    1468         crStateError(__LINE__, __FILE__, GL_STACK_OVERFLOW,
     1468        crStateError(pState, __LINE__, __FILE__, GL_STACK_OVERFLOW,
    14691469                                 "glPushClientAttrib called with a full stack!" );
    14701470        return;
     
    14891489
    14901490
    1491 void STATE_APIENTRY crStatePopClientAttrib( void )
    1492 {
    1493     CRContext *g = GetCurrentContext();
     1491void STATE_APIENTRY crStatePopClientAttrib(PCRStateTracker pState)
     1492{
     1493    CRContext *g = GetCurrentContext(pState);
    14941494    CRClientState *c = &(g->client);
    1495     CRStateBits *sb = GetCurrentBits();
     1495    CRStateBits *sb = GetCurrentBits(pState);
    14961496    CRClientBits *cb = &(sb->client);
    14971497    CRbitvalue mask;
    14981498
    14991499    if (g->current.inBeginEnd) {
    1500         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1500        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    15011501                                 "glPopClientAttrib called in Begin/End");
    15021502        return;
     
    15041504
    15051505    if (c->attribStackDepth == 0) {
    1506         crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW,
     1506        crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW,
    15071507                                 "glPopClientAttrib called with an empty stack!" );
    15081508        return;
     
    15511551}
    15521552
    1553 void STATE_APIENTRY crStateLockArraysEXT(GLint first, GLint count)
    1554 {
    1555     CRContext *g = GetCurrentContext();
     1553void STATE_APIENTRY crStateLockArraysEXT(PCRStateTracker pState, GLint first, GLint count)
     1554{
     1555    CRContext *g = GetCurrentContext(pState);
    15561556    CRClientState *c = &(g->client);
    15571557    int i;
     
    15831583}
    15841584
    1585 void STATE_APIENTRY crStateUnlockArraysEXT(void)
    1586 {
    1587     CRContext *g = GetCurrentContext();
     1585void STATE_APIENTRY crStateUnlockArraysEXT(PCRStateTracker pState)
     1586{
     1587    CRContext *g = GetCurrentContext(pState);
    15881588    CRClientState *c = &(g->client);
    15891589    int i;
     
    16061606}
    16071607
    1608 void STATE_APIENTRY crStateVertexArrayRangeNV(GLsizei length, const GLvoid *pointer CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
     1608void STATE_APIENTRY crStateVertexArrayRangeNV(PCRStateTracker pState, GLsizei length, const GLvoid *pointer CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
    16091609{
    16101610  /* XXX todo */
    16111611    crWarning("crStateVertexArrayRangeNV not implemented");
    1612     (void)length; (void)pointer CRVBOX_HOST_ONLY_PARAM((void)fRealPtr);
    1613 }
    1614 
    1615 
    1616 void STATE_APIENTRY crStateFlushVertexArrayRangeNV(void)
     1612    RT_NOREF(pState); (void)length; (void)pointer CRVBOX_HOST_ONLY_PARAM((void)fRealPtr);
     1613}
     1614
     1615
     1616void STATE_APIENTRY crStateFlushVertexArrayRangeNV(PCRStateTracker pState)
    16171617{
    16181618  /* XXX todo */
    16191619    crWarning("crStateFlushVertexArrayRangeNV not implemented");
     1620    RT_NOREF(pState);
    16201621}
    16211622
     
    16501651 * (via GL_ARB_vertex_buffer_object).
    16511652 */
    1652 GLboolean crStateUseServerArrays(void)
     1653GLboolean crStateUseServerArrays(PCRStateTracker pState)
    16531654{
    16541655#if defined(CR_ARB_vertex_buffer_object) && !defined(CR_NO_SERVER_ARRAYS)
    1655     CRContext *g = GetCurrentContext();
     1656    CRContext *g = GetCurrentContext(pState);
    16561657    CRClientState *c = &(g->client);
    16571658    int i;
     
    17611762 */
    17621763GLboolean
    1763 crStateUseServerArrayElements(void)
     1764crStateUseServerArrayElements(PCRStateTracker pState)
    17641765{
    17651766#ifdef CR_ARB_vertex_buffer_object
    1766     CRContext *g = GetCurrentContext();
     1767    CRContext *g = GetCurrentContext(pState);
    17671768    if (g->bufferobject.elementsBuffer &&
    17681769            g->bufferobject.elementsBuffer->id > 0)
     
    17811782                                    CRContext *fromCtx, CRContext *toCtx)
    17821783{
     1784    PCRStateTracker pState = fromCtx->pStateTracker;
    17831785    CRClientState *from = &(fromCtx->client);
    17841786    const CRClientState *to = &(toCtx->client);
     
    17881790    const GLint idHwInitialBuffer = idHwArrayBuffer;
    17891791
     1792    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     1793
    17901794#ifdef DEBUG_misha
    17911795    {
    17921796        GLint tstHwBuffer = -1;
    1793         diff_api.GetIntegerv(GL_ARRAY_BUFFER_BINDING, &tstHwBuffer);
     1797        pState->diff_api.GetIntegerv(GL_ARRAY_BUFFER_BINDING, &tstHwBuffer);
    17941798        CRASSERT(idHwInitialBuffer == tstHwBuffer);
    17951799    }
     
    18081812                if (idHwArrayBufferUsed != idHwArrayBuffer)
    18091813                {
    1810                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     1814                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    18111815                    idHwArrayBuffer = idHwArrayBufferUsed;
    18121816                }
    1813                 diff_api.VertexPointer(to->array.v.size, to->array.v.type, to->array.v.stride, to->array.v.p CRVBOX_HOST_ONLY_PARAM(to->array.v.fRealPtr));
     1817                pState->diff_api.VertexPointer(to->array.v.size, to->array.v.type, to->array.v.stride, to->array.v.p CRVBOX_HOST_ONLY_PARAM(to->array.v.fRealPtr));
    18141818                from->array.v.size = to->array.v.size;
    18151819                from->array.v.type = to->array.v.type;
     
    18291833                if (idHwArrayBufferUsed != idHwArrayBuffer)
    18301834                {
    1831                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     1835                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    18321836                    idHwArrayBuffer = idHwArrayBufferUsed;
    18331837                }
    1834                 diff_api.NormalPointer(to->array.n.type, to->array.n.stride, to->array.n.p CRVBOX_HOST_ONLY_PARAM(to->array.n.fRealPtr));
     1838                pState->diff_api.NormalPointer(to->array.n.type, to->array.n.stride, to->array.n.p CRVBOX_HOST_ONLY_PARAM(to->array.n.fRealPtr));
    18351839                from->array.n.type = to->array.n.type;
    18361840                from->array.n.stride = to->array.n.stride;
     
    18501854                if (idHwArrayBufferUsed != idHwArrayBuffer)
    18511855                {
    1852                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     1856                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    18531857                    idHwArrayBuffer = idHwArrayBufferUsed;
    18541858                }
    1855                 diff_api.ColorPointer(to->array.c.size, to->array.c.type, to->array.c.stride, to->array.c.p CRVBOX_HOST_ONLY_PARAM(to->array.c.fRealPtr));
     1859                pState->diff_api.ColorPointer(to->array.c.size, to->array.c.type, to->array.c.stride, to->array.c.p CRVBOX_HOST_ONLY_PARAM(to->array.c.fRealPtr));
    18561860                from->array.c.size = to->array.c.size;
    18571861                from->array.c.type = to->array.c.type;
     
    18711875                if (idHwArrayBufferUsed != idHwArrayBuffer)
    18721876                {
    1873                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     1877                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    18741878                    idHwArrayBuffer = idHwArrayBufferUsed;
    18751879                }
    1876                 diff_api.IndexPointer(to->array.i.type, to->array.i.stride, to->array.i.p CRVBOX_HOST_ONLY_PARAM(to->array.i.fRealPtr));
     1880                pState->diff_api.IndexPointer(to->array.i.type, to->array.i.stride, to->array.i.p CRVBOX_HOST_ONLY_PARAM(to->array.i.fRealPtr));
    18771881                from->array.i.type = to->array.i.type;
    18781882                from->array.i.stride = to->array.i.stride;
     
    18931897                    if (idHwArrayBufferUsed != idHwArrayBuffer)
    18941898                    {
    1895                         diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     1899                        pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    18961900                        idHwArrayBuffer = idHwArrayBufferUsed;
    18971901                    }
    1898                     diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
     1902                    pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
    18991903                    curClientTextureUnit = i;
    1900                     diff_api.TexCoordPointer(to->array.t[i].size, to->array.t[i].type, to->array.t[i].stride, to->array.t[i].p CRVBOX_HOST_ONLY_PARAM(to->array.t[i].fRealPtr));
     1904                    pState->diff_api.TexCoordPointer(to->array.t[i].size, to->array.t[i].type, to->array.t[i].stride, to->array.t[i].p CRVBOX_HOST_ONLY_PARAM(to->array.t[i].fRealPtr));
    19011905                    from->array.t[i].size = to->array.t[i].size;
    19021906                    from->array.t[i].type = to->array.t[i].type;
     
    19161920                if (idHwArrayBufferUsed != idHwArrayBuffer)
    19171921                {
    1918                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     1922                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    19191923                    idHwArrayBuffer = idHwArrayBufferUsed;
    19201924                }
    1921                 diff_api.EdgeFlagPointer(to->array.e.stride, to->array.e.p CRVBOX_HOST_ONLY_PARAM(to->array.e.fRealPtr));
     1925                pState->diff_api.EdgeFlagPointer(to->array.e.stride, to->array.e.p CRVBOX_HOST_ONLY_PARAM(to->array.e.fRealPtr));
    19221926                from->array.e.stride = to->array.e.stride;
    19231927                from->array.e.p = to->array.e.p;
     
    19361940                if (idHwArrayBufferUsed != idHwArrayBuffer)
    19371941                {
    1938                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     1942                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    19391943                    idHwArrayBuffer = idHwArrayBufferUsed;
    19401944                }
    1941                 diff_api.SecondaryColorPointerEXT(to->array.s.size, to->array.s.type, to->array.s.stride, to->array.s.p CRVBOX_HOST_ONLY_PARAM(to->array.s.fRealPtr));
     1945                pState->diff_api.SecondaryColorPointerEXT(to->array.s.size, to->array.s.type, to->array.s.stride, to->array.s.p CRVBOX_HOST_ONLY_PARAM(to->array.s.fRealPtr));
    19421946                from->array.s.size = to->array.s.size;
    19431947                from->array.s.type = to->array.s.type;
     
    19571961                if (idHwArrayBufferUsed != idHwArrayBuffer)
    19581962                {
    1959                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     1963                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    19601964                    idHwArrayBuffer = idHwArrayBufferUsed;
    19611965                }
    1962                 diff_api.FogCoordPointerEXT(to->array.f.type, to->array.f.stride, to->array.f.p CRVBOX_HOST_ONLY_PARAM(to->array.f.fRealPtr));
     1966                pState->diff_api.FogCoordPointerEXT(to->array.f.type, to->array.f.stride, to->array.f.p CRVBOX_HOST_ONLY_PARAM(to->array.f.fRealPtr));
    19631967                from->array.f.type = to->array.f.type;
    19641968                from->array.f.stride = to->array.f.stride;
     
    19811985                    if (idHwArrayBufferUsed != idHwArrayBuffer)
    19821986                    {
    1983                         diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     1987                        pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    19841988                        idHwArrayBuffer = idHwArrayBufferUsed;
    19851989                    }
    1986                     diff_api.VertexAttribPointerARB(i, to->array.a[i].size, to->array.a[i].type, to->array.a[i].normalized,
    1987                                                     to->array.a[i].stride, to->array.a[i].p CRVBOX_HOST_ONLY_PARAM(to->array.a[i].fRealPtr));
     1990                    pState->diff_api.VertexAttribPointerARB(i, to->array.a[i].size, to->array.a[i].type, to->array.a[i].normalized,
     1991                                                            to->array.a[i].stride, to->array.a[i].p CRVBOX_HOST_ONLY_PARAM(to->array.a[i].fRealPtr));
    19881992                    from->array.a[i].size = to->array.a[i].size;
    19891993                    from->array.a[i].type = to->array.a[i].type;
     
    20012005    if (idHwArrayBuffer != idHwInitialBuffer)
    20022006    {
    2003         diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwInitialBuffer);
     2007        pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwInitialBuffer);
    20042008    }
    20052009
     
    20072011        /* update vertex array enable/disable flags */
    20082012        glAble able[2];
    2009         able[0] = diff_api.DisableClientState;
    2010         able[1] = diff_api.EnableClientState;
     2013        able[0] = pState->diff_api.DisableClientState;
     2014        able[1] = pState->diff_api.EnableClientState;
    20112015        if (from->array.v.enabled != to->array.v.enabled) {
    20122016            able[to->array.v.enabled](GL_VERTEX_ARRAY);
     
    20272031        for (i = 0; (unsigned int)i < toCtx->limits.maxTextureUnits; i++) {
    20282032            if (from->array.t[i].enabled != to->array.t[i].enabled) {
    2029                 diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
     2033                pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
    20302034                curClientTextureUnit = i;
    20312035                able[to->array.t[i].enabled](GL_TEXTURE_COORD_ARRAY);
     
    20482052            if (from->array.a[i].enabled != to->array.a[i].enabled) {
    20492053                if (to->array.a[i].enabled)
    2050                     diff_api.EnableVertexAttribArrayARB(i);
     2054                    pState->diff_api.EnableVertexAttribArrayARB(i);
    20512055                else
    2052                     diff_api.DisableVertexAttribArrayARB(i);
     2056                    pState->diff_api.DisableVertexAttribArrayARB(i);
    20532057                from->array.a[i].enabled = to->array.a[i].enabled;
    20542058            }
     
    20592063    if (to->curClientTextureUnit != curClientTextureUnit)
    20602064    {
    2061         diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + to->curClientTextureUnit);
     2065        pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + to->curClientTextureUnit);
    20622066    }
    20632067}
     
    20682072                                        CRContext *fromCtx, CRContext *toCtx)
    20692073{
     2074    PCRStateTracker pState = fromCtx->pStateTracker;
    20702075    const CRClientState *from = &(fromCtx->client);
    20712076    const CRClientState *to = &(toCtx->client);
     
    20752080    const GLint idHwInitialBuffer = idHwArrayBuffer;
    20762081
     2082    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     2083
    20772084#ifdef DEBUG_misha
    20782085    {
    20792086        GLint tstHwBuffer = -1;
    2080         diff_api.GetIntegerv(GL_ARRAY_BUFFER_BINDING, &tstHwBuffer);
     2087        pState->diff_api.GetIntegerv(GL_ARRAY_BUFFER_BINDING, &tstHwBuffer);
    20812088        CRASSERT(idHwInitialBuffer == tstHwBuffer);
    20822089    }
     
    20942101                if (idHwArrayBufferUsed != idHwArrayBuffer)
    20952102                {
    2096                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     2103                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    20972104                    idHwArrayBuffer = idHwArrayBufferUsed;
    20982105                }
    2099                 diff_api.VertexPointer(to->array.v.size, to->array.v.type, to->array.v.stride, to->array.v.p CRVBOX_HOST_ONLY_PARAM(to->array.v.fRealPtr));
     2106                pState->diff_api.VertexPointer(to->array.v.size, to->array.v.type, to->array.v.stride, to->array.v.p CRVBOX_HOST_ONLY_PARAM(to->array.v.fRealPtr));
    21002107                FILLDIRTY(cb->v);
    21012108                FILLDIRTY(cb->clientPointer);
     
    21132120                if (idHwArrayBufferUsed != idHwArrayBuffer)
    21142121                {
    2115                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     2122                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    21162123                    idHwArrayBuffer = idHwArrayBufferUsed;
    21172124                }
    2118                 diff_api.NormalPointer(to->array.n.type, to->array.n.stride, to->array.n.p CRVBOX_HOST_ONLY_PARAM(to->array.n.fRealPtr));
     2125                pState->diff_api.NormalPointer(to->array.n.type, to->array.n.stride, to->array.n.p CRVBOX_HOST_ONLY_PARAM(to->array.n.fRealPtr));
    21192126                FILLDIRTY(cb->n);
    21202127                FILLDIRTY(cb->clientPointer);
     
    21332140                if (idHwArrayBufferUsed != idHwArrayBuffer)
    21342141                {
    2135                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     2142                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    21362143                    idHwArrayBuffer = idHwArrayBufferUsed;
    21372144                }
    2138                 diff_api.ColorPointer(to->array.c.size, to->array.c.type, to->array.c.stride, to->array.c.p CRVBOX_HOST_ONLY_PARAM(to->array.c.fRealPtr));
     2145                pState->diff_api.ColorPointer(to->array.c.size, to->array.c.type, to->array.c.stride, to->array.c.p CRVBOX_HOST_ONLY_PARAM(to->array.c.fRealPtr));
    21392146                FILLDIRTY(cb->c);
    21402147                FILLDIRTY(cb->clientPointer);
     
    21522159                if (idHwArrayBufferUsed != idHwArrayBuffer)
    21532160                {
    2154                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     2161                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    21552162                    idHwArrayBuffer = idHwArrayBufferUsed;
    21562163                }
    2157                 diff_api.IndexPointer(to->array.i.type, to->array.i.stride, to->array.i.p CRVBOX_HOST_ONLY_PARAM(to->array.i.fRealPtr));
     2164                pState->diff_api.IndexPointer(to->array.i.type, to->array.i.stride, to->array.i.p CRVBOX_HOST_ONLY_PARAM(to->array.i.fRealPtr));
    21582165                FILLDIRTY(cb->i);
    21592166                FILLDIRTY(cb->dirty);
     
    21732180                    if (idHwArrayBufferUsed != idHwArrayBuffer)
    21742181                    {
    2175                         diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     2182                        pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    21762183                        idHwArrayBuffer = idHwArrayBufferUsed;
    21772184                    }
    2178                     diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
     2185                    pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
    21792186                    curClientTextureUnit = i;
    2180                     diff_api.TexCoordPointer(to->array.t[i].size, to->array.t[i].type, to->array.t[i].stride, to->array.t[i].p CRVBOX_HOST_ONLY_PARAM(to->array.t[i].fRealPtr));
     2187                    pState->diff_api.TexCoordPointer(to->array.t[i].size, to->array.t[i].type, to->array.t[i].stride, to->array.t[i].p CRVBOX_HOST_ONLY_PARAM(to->array.t[i].fRealPtr));
    21812188                    FILLDIRTY(cb->t[i]);
    21822189                    FILLDIRTY(cb->clientPointer);
     
    21942201                if (idHwArrayBufferUsed != idHwArrayBuffer)
    21952202                {
    2196                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     2203                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    21972204                    idHwArrayBuffer = idHwArrayBufferUsed;
    21982205                }
    2199                 diff_api.EdgeFlagPointer(to->array.e.stride, to->array.e.p CRVBOX_HOST_ONLY_PARAM(to->array.e.fRealPtr));
     2206                pState->diff_api.EdgeFlagPointer(to->array.e.stride, to->array.e.p CRVBOX_HOST_ONLY_PARAM(to->array.e.fRealPtr));
    22002207                FILLDIRTY(cb->e);
    22012208                FILLDIRTY(cb->clientPointer);
     
    22142221                if (idHwArrayBufferUsed != idHwArrayBuffer)
    22152222                {
    2216                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     2223                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    22172224                    idHwArrayBuffer = idHwArrayBufferUsed;
    22182225                }
    2219                 diff_api.SecondaryColorPointerEXT(to->array.s.size, to->array.s.type, to->array.s.stride, to->array.s.p CRVBOX_HOST_ONLY_PARAM(to->array.s.fRealPtr));
     2226                pState->diff_api.SecondaryColorPointerEXT(to->array.s.size, to->array.s.type, to->array.s.stride, to->array.s.p CRVBOX_HOST_ONLY_PARAM(to->array.s.fRealPtr));
    22202227                FILLDIRTY(cb->s);
    22212228                FILLDIRTY(cb->clientPointer);
     
    22332240                if (idHwArrayBufferUsed != idHwArrayBuffer)
    22342241                {
    2235                     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     2242                    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    22362243                    idHwArrayBuffer = idHwArrayBufferUsed;
    22372244                }
    2238                 diff_api.FogCoordPointerEXT(to->array.f.type, to->array.f.stride, to->array.f.p CRVBOX_HOST_ONLY_PARAM(to->array.f.fRealPtr));
     2245                pState->diff_api.FogCoordPointerEXT(to->array.f.type, to->array.f.stride, to->array.f.p CRVBOX_HOST_ONLY_PARAM(to->array.f.fRealPtr));
    22392246                FILLDIRTY(cb->f);
    22402247                FILLDIRTY(cb->clientPointer);
     
    22562263                    if (idHwArrayBufferUsed != idHwArrayBuffer)
    22572264                    {
    2258                         diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
     2265                        pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
    22592266                        idHwArrayBuffer = idHwArrayBufferUsed;
    22602267                    }
    2261                     diff_api.VertexAttribPointerARB(i, to->array.a[i].size, to->array.a[i].type, to->array.a[i].normalized,
    2262                                                     to->array.a[i].stride, to->array.a[i].p  CRVBOX_HOST_ONLY_PARAM(to->array.a[i].fRealPtr));
     2268                    pState->diff_api.VertexAttribPointerARB(i, to->array.a[i].size, to->array.a[i].type, to->array.a[i].normalized,
     2269                                                            to->array.a[i].stride, to->array.a[i].p  CRVBOX_HOST_ONLY_PARAM(to->array.a[i].fRealPtr));
    22632270                    FILLDIRTY(cb->a[i]);
    22642271                    FILLDIRTY(cb->clientPointer);
     
    22732280    if (idHwArrayBuffer != idHwInitialBuffer)
    22742281    {
    2275         diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwInitialBuffer);
     2282        pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwInitialBuffer);
    22762283    }
    22772284
     
    22792286        /* update vertex array enable/disable flags */
    22802287        glAble able[2];
    2281         able[0] = diff_api.DisableClientState;
    2282         able[1] = diff_api.EnableClientState;
     2288        able[0] = pState->diff_api.DisableClientState;
     2289        able[1] = pState->diff_api.EnableClientState;
    22832290        if (from->array.v.enabled != to->array.v.enabled) {
    22842291            able[to->array.v.enabled](GL_VERTEX_ARRAY);
     
    23032310        for (i = 0; (unsigned int)i < toCtx->limits.maxTextureUnits; i++) {
    23042311            if (from->array.t[i].enabled != to->array.t[i].enabled) {
    2305                 diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
     2312                pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
    23062313                curClientTextureUnit = i;
    23072314                able[to->array.t[i].enabled](GL_TEXTURE_COORD_ARRAY);
     
    23282335            if (from->array.a[i].enabled != to->array.a[i].enabled) {
    23292336                if (to->array.a[i].enabled)
    2330                     diff_api.EnableVertexAttribArrayARB(i);
     2337                    pState->diff_api.EnableVertexAttribArrayARB(i);
    23312338                else
    2332                     diff_api.DisableVertexAttribArrayARB(i);
     2339                    pState->diff_api.DisableVertexAttribArrayARB(i);
    23332340                FILLDIRTY(cb->enableClientState);
    23342341                FILLDIRTY(cb->dirty);
     
    23402347    if (to->curClientTextureUnit != curClientTextureUnit)
    23412348    {
    2342         diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + to->curClientTextureUnit);
     2349        pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + to->curClientTextureUnit);
    23432350    }
    23442351
     
    23472354        if (from->unpack.rowLength != to->unpack.rowLength)
    23482355        {
    2349             diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, to->unpack.rowLength);
     2356            pState->diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, to->unpack.rowLength);
    23502357            FILLDIRTY(cb->unpack);
    23512358            FILLDIRTY(cb->dirty);
     
    23532360        if (from->unpack.skipRows != to->unpack.skipRows)
    23542361        {
    2355             diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, to->unpack.skipRows);
     2362            pState->diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, to->unpack.skipRows);
    23562363            FILLDIRTY(cb->unpack);
    23572364            FILLDIRTY(cb->dirty);
     
    23592366        if (from->unpack.skipPixels != to->unpack.skipPixels)
    23602367        {
    2361             diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, to->unpack.skipPixels);
     2368            pState->diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, to->unpack.skipPixels);
    23622369            FILLDIRTY(cb->unpack);
    23632370            FILLDIRTY(cb->dirty);
     
    23652372        if (from->unpack.alignment != to->unpack.alignment)
    23662373        {
    2367             diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, to->unpack.alignment);
     2374            pState->diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, to->unpack.alignment);
    23682375            FILLDIRTY(cb->unpack);
    23692376            FILLDIRTY(cb->dirty);
     
    23712378        if (from->unpack.imageHeight != to->unpack.imageHeight)
    23722379        {
    2373             diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, to->unpack.imageHeight);
     2380            pState->diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, to->unpack.imageHeight);
    23742381            FILLDIRTY(cb->unpack);
    23752382            FILLDIRTY(cb->dirty);
     
    23772384        if (from->unpack.skipImages != to->unpack.skipImages)
    23782385        {
    2379             diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, to->unpack.skipImages);
     2386            pState->diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, to->unpack.skipImages);
    23802387            FILLDIRTY(cb->unpack);
    23812388            FILLDIRTY(cb->dirty);
     
    23832390        if (from->unpack.swapBytes != to->unpack.swapBytes)
    23842391        {
    2385             diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, to->unpack.swapBytes);
     2392            pState->diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, to->unpack.swapBytes);
    23862393            FILLDIRTY(cb->unpack);
    23872394            FILLDIRTY(cb->dirty);
     
    23892396        if (from->unpack.psLSBFirst != to->unpack.psLSBFirst)
    23902397        {
    2391             diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, to->unpack.psLSBFirst);
     2398            pState->diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, to->unpack.psLSBFirst);
    23922399            FILLDIRTY(cb->unpack);
    23932400            FILLDIRTY(cb->dirty);
     
    24002407        if (from->pack.rowLength != to->pack.rowLength)
    24012408        {
    2402             diff_api.PixelStorei(GL_PACK_ROW_LENGTH, to->pack.rowLength);
     2409            pState->diff_api.PixelStorei(GL_PACK_ROW_LENGTH, to->pack.rowLength);
    24032410            FILLDIRTY(cb->pack);
    24042411            FILLDIRTY(cb->dirty);
     
    24062413        if (from->pack.skipRows != to->pack.skipRows)
    24072414        {
    2408             diff_api.PixelStorei(GL_PACK_SKIP_ROWS, to->pack.skipRows);
     2415            pState->diff_api.PixelStorei(GL_PACK_SKIP_ROWS, to->pack.skipRows);
    24092416            FILLDIRTY(cb->pack);
    24102417            FILLDIRTY(cb->dirty);
     
    24122419        if (from->pack.skipPixels != to->pack.skipPixels)
    24132420        {
    2414             diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, to->pack.skipPixels);
     2421            pState->diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, to->pack.skipPixels);
    24152422            FILLDIRTY(cb->pack);
    24162423            FILLDIRTY(cb->dirty);
     
    24182425        if (from->pack.alignment != to->pack.alignment)
    24192426        {
    2420             diff_api.PixelStorei(GL_PACK_ALIGNMENT, to->pack.alignment);
     2427            pState->diff_api.PixelStorei(GL_PACK_ALIGNMENT, to->pack.alignment);
    24212428            FILLDIRTY(cb->pack);
    24222429            FILLDIRTY(cb->dirty);
     
    24242431        if (from->pack.imageHeight != to->pack.imageHeight)
    24252432        {
    2426             diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, to->pack.imageHeight);
     2433            pState->diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, to->pack.imageHeight);
    24272434            FILLDIRTY(cb->pack);
    24282435            FILLDIRTY(cb->dirty);
     
    24302437        if (from->pack.skipImages != to->pack.skipImages)
    24312438        {
    2432             diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, to->pack.skipImages);
     2439            pState->diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, to->pack.skipImages);
    24332440            FILLDIRTY(cb->pack);
    24342441            FILLDIRTY(cb->dirty);
     
    24362443        if (from->pack.swapBytes != to->pack.swapBytes)
    24372444        {
    2438             diff_api.PixelStorei(GL_PACK_SWAP_BYTES, to->pack.swapBytes);
     2445            pState->diff_api.PixelStorei(GL_PACK_SWAP_BYTES, to->pack.swapBytes);
    24392446            FILLDIRTY(cb->pack);
    24402447            FILLDIRTY(cb->dirty);
     
    24422449        if (from->pack.psLSBFirst != to->pack.psLSBFirst)
    24432450        {
    2444             diff_api.PixelStorei(GL_PACK_LSB_FIRST, to->pack.psLSBFirst);
     2451            pState->diff_api.PixelStorei(GL_PACK_LSB_FIRST, to->pack.psLSBFirst);
    24452452            FILLDIRTY(cb->pack);
    24462453            FILLDIRTY(cb->dirty);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_current.c

    r69392 r78375  
    1919{
    2020    CRCurrentState *c = &ctx->current;
    21     CRStateBits *sb = GetCurrentBits();
     21    CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    2222    CRCurrentBits *cb = &(sb->current);
    2323    static const GLfloat default_normal[4]         = {0.0f, 0.0f, 1.0f, 1.0f};
     
    7070}
    7171
    72 void STATE_APIENTRY crStateColor3f( GLfloat r, GLfloat g, GLfloat b )
    73 {
    74     crStateColor4f(r, g, b, 1.0F);
    75 }
    76 
    77 void STATE_APIENTRY crStateColor3fv( const GLfloat *color )
    78 {
    79     crStateColor4f( color[0], color[1], color[2], 1.0F );
    80 }
    81 
    82 void STATE_APIENTRY crStateColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
    83 {
    84     CRContext *g = GetCurrentContext();
     72void STATE_APIENTRY crStateColor3f(PCRStateTracker pState, GLfloat r, GLfloat g, GLfloat b )
     73{
     74    crStateColor4f(pState, r, g, b, 1.0F);
     75}
     76
     77void STATE_APIENTRY crStateColor3fv(PCRStateTracker pState, const GLfloat *color )
     78{
     79    crStateColor4f(pState, color[0], color[1], color[2], 1.0F );
     80}
     81
     82void STATE_APIENTRY crStateColor4f(PCRStateTracker pState, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
     83{
     84    CRContext *g = GetCurrentContext(pState);
    8585    CRCurrentState *c = &(g->current);
    86     CRStateBits *sb = GetCurrentBits();
     86    CRStateBits *sb = GetCurrentBits(pState);
    8787    CRCurrentBits *cb = &(sb->current);
    8888
     
    9898}
    9999
    100 void STATE_APIENTRY crStateColor4fv( const GLfloat *color )
    101 {
    102     crStateColor4f( color[0], color[1], color[2], color[3] );
     100void STATE_APIENTRY crStateColor4fv(PCRStateTracker pState, const GLfloat *color )
     101{
     102    crStateColor4f(pState, color[0], color[1], color[2], color[3] );
    103103}
    104104
     
    118118}
    119119
    120 void STATE_APIENTRY crStateBegin( GLenum mode )
    121 {
    122     CRContext *g = GetCurrentContext();
     120void STATE_APIENTRY crStateBegin(PCRStateTracker pState, GLenum mode )
     121{
     122    CRContext *g = GetCurrentContext(pState);
    123123    CRCurrentState *c = &(g->current);
    124124
    125125    if (mode > GL_POLYGON)
    126126    {
    127         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Begin called with invalid mode: %d", mode);
     127        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Begin called with invalid mode: %d", mode);
    128128        return;
    129129    }
     
    131131    if (c->inBeginEnd)
    132132    {
    133         crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "glBegin called inside Begin/End");
     133        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glBegin called inside Begin/End");
    134134        return;
    135135    }
     
    141141}
    142142
    143 void STATE_APIENTRY crStateEnd( void )
    144 {
    145     CRContext *g = GetCurrentContext();
     143void STATE_APIENTRY crStateEnd(PCRStateTracker pState)
     144{
     145    CRContext *g = GetCurrentContext(pState);
    146146    CRCurrentState *c = &(g->current);
    147147
    148148    if (!c->inBeginEnd)
    149149    {
    150         crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "glEnd called outside Begin/End" );
     150        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glEnd called outside Begin/End" );
    151151        return;
    152152    }
     
    158158                                                     CRContext *fromCtx, CRContext *toCtx )
    159159{
     160    PCRStateTracker pState = fromCtx->pStateTracker;
    160161    const CRCurrentState *from = &(fromCtx->current);
    161162    const CRCurrentState *to = &(toCtx->current);
     
    163164    unsigned int i, j;
    164165    CRbitvalue nbitID[CR_MAX_BITARRAY];
     166
     167    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
    165168
    166169    for (j=0;j<CR_MAX_BITARRAY;j++)
     
    177180          if (toX != fromX || toY != fromY || toZ != fromZ) {
    178181                /* Use glWindowPos (which updates raster color) */
    179                 diff_api.WindowPos3fvARB(to->rasterAttrib[VERT_ATTRIB_POS]);
     182                pState->diff_api.WindowPos3fvARB(to->rasterAttrib[VERT_ATTRIB_POS]);
    180183              FILLDIRTY(c->rasterPos);
    181184              FILLDIRTY(c->dirty);
     
    195198    if (CHECKDIRTY(c->colorIndex, bitID)) {
    196199        if (to->colorIndex != from->colorIndex) {
    197             diff_api.Indexf(to->colorIndex);
     200            pState->diff_api.Indexf(to->colorIndex);
    198201            FILLDIRTY(c->colorIndex);
    199202            FILLDIRTY(c->dirty);
     
    204207    if (CHECKDIRTY(c->edgeFlag, bitID)) {
    205208        if (to->edgeFlag != from->edgeFlag) {
    206             diff_api.EdgeFlag(to->edgeFlag);
     209            pState->diff_api.EdgeFlag(to->edgeFlag);
    207210            FILLDIRTY(c->edgeFlag);
    208211            FILLDIRTY(c->dirty);
     
    223226                    && CHECKDIRTY(c->vertexAttrib[i], bitID)) {
    224227                if (COMPARE_VECTOR (from->vertexAttrib[i], to->vertexAttribPre[i])) {
    225                     diff_api.VertexAttrib4fvARB(i, &(to->vertexAttrib[i][0]));
     228                    pState->diff_api.VertexAttrib4fvARB(i, &(to->vertexAttrib[i][0]));
    226229                    FILLDIRTY(c->vertexAttrib[i]);
    227230                    FILLDIRTY(c->dirty);
     
    242245        if (CHECKDIRTY(c->vertexAttrib[VERT_ATTRIB_COLOR0], bitID)) {
    243246            if (COMPARE_COLOR(from->vertexAttrib[VERT_ATTRIB_COLOR0],to->vertexAttrib[VERT_ATTRIB_COLOR0])) {
    244                 diff_api.Color4fv ((GLfloat *) &(to->vertexAttrib[VERT_ATTRIB_COLOR0]));
     247                pState->diff_api.Color4fv ((GLfloat *) &(to->vertexAttrib[VERT_ATTRIB_COLOR0]));
    245248                FILLDIRTY(c->vertexAttrib[VERT_ATTRIB_COLOR0]);
    246249                FILLDIRTY(c->dirty);
     
    253256        if (CHECKDIRTY(c->vertexAttrib[VERT_ATTRIB_COLOR1], bitID)) {
    254257            if (COMPARE_COLOR(from->vertexAttrib[VERT_ATTRIB_COLOR1],to->vertexAttrib[VERT_ATTRIB_COLOR1])) {
    255                 diff_api.SecondaryColor3fvEXT ((GLfloat *) &(to->vertexAttrib[VERT_ATTRIB_COLOR1]));
     258                pState->diff_api.SecondaryColor3fvEXT ((GLfloat *) &(to->vertexAttrib[VERT_ATTRIB_COLOR1]));
    256259                FILLDIRTY(c->vertexAttrib[VERT_ATTRIB_COLOR1]);
    257260                FILLDIRTY(c->dirty);
     
    265268        if (CHECKDIRTY(c->vertexAttrib[VERT_ATTRIB_FOG], bitID)) {
    266269            if (from->vertexAttrib[VERT_ATTRIB_FOG][0] != to->vertexAttrib[VERT_ATTRIB_FOG][0] ) {
    267                 diff_api.FogCoordfvEXT ((GLfloat *) &(to->vertexAttrib[VERT_ATTRIB_FOG][0] ));
     270                pState->diff_api.FogCoordfvEXT ((GLfloat *) &(to->vertexAttrib[VERT_ATTRIB_FOG][0] ));
    268271                FILLDIRTY(c->vertexAttrib[VERT_ATTRIB_FOG]);
    269272                FILLDIRTY(c->dirty);
     
    275278        if (CHECKDIRTY(c->vertexAttrib[VERT_ATTRIB_NORMAL], bitID)) {
    276279            if (COMPARE_VECTOR (from->vertexAttrib[VERT_ATTRIB_NORMAL], to->vertexAttrib[VERT_ATTRIB_NORMAL])) {
    277                 diff_api.Normal3fv ((GLfloat *) &(to->vertexAttrib[VERT_ATTRIB_NORMAL][0]));
     280                pState->diff_api.Normal3fv ((GLfloat *) &(to->vertexAttrib[VERT_ATTRIB_NORMAL][0]));
    278281                FILLDIRTY(c->vertexAttrib[VERT_ATTRIB_NORMAL]);
    279282                FILLDIRTY(c->dirty);
     
    285288            if (CHECKDIRTY(c->vertexAttrib[VERT_ATTRIB_TEX0 + i], bitID)) {
    286289                if (COMPARE_TEXCOORD (from->vertexAttrib[VERT_ATTRIB_TEX0 + i], to->vertexAttribPre[VERT_ATTRIB_TEX0 + i])) {
    287                     diff_api.MultiTexCoord4fvARB (i+GL_TEXTURE0_ARB, (GLfloat *) &(to->vertexAttrib[VERT_ATTRIB_TEX0+ i][0]));
     290                    pState->diff_api.MultiTexCoord4fvARB (i+GL_TEXTURE0_ARB, (GLfloat *) &(to->vertexAttrib[VERT_ATTRIB_TEX0+ i][0]));
    288291                    FILLDIRTY(c->vertexAttrib[VERT_ATTRIB_TEX0 + i]);
    289292                    FILLDIRTY(c->dirty);
     
    301304                    CRContext *fromCtx, CRContext *toCtx )
    302305{
     306    PCRStateTracker pState = fromCtx->pStateTracker;
    303307    CRCurrentState *from = &(fromCtx->current);
    304308    const CRCurrentState *to = &(toCtx->current);
    305309    unsigned int i, j;
    306310    CRbitvalue nbitID[CR_MAX_BITARRAY];
     311
     312    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
    307313
    308314    for (j=0;j<CR_MAX_BITARRAY;j++)
     
    320326            if (toX != fromX || toY != fromY || toZ != fromZ) {
    321327                /* Use glWindowPos (which updates raster color) */
    322                 diff_api.WindowPos3fvARB(to->rasterAttrib[VERT_ATTRIB_POS]);
     328                pState->diff_api.WindowPos3fvARB(to->rasterAttrib[VERT_ATTRIB_POS]);
    323329                from->rasterAttrib[VERT_ATTRIB_POS][0] = toX;
    324330                from->rasterAttrib[VERT_ATTRIB_POS][1] = toY;
     
    342348    if (CHECKDIRTY(c->edgeFlag, bitID)) {
    343349        if (from->edgeFlag != to->edgeFlagPre) {
    344             diff_api.EdgeFlag (to->edgeFlagPre);
     350            pState->diff_api.EdgeFlag (to->edgeFlagPre);
    345351        }
    346352        from->edgeFlag = to->edgeFlag;
     
    351357    if (CHECKDIRTY(c->colorIndex, bitID)) {
    352358        if (from->colorIndex != to->colorIndexPre) {
    353             diff_api.Indexf (to->colorIndex);
     359            pState->diff_api.Indexf (to->colorIndex);
    354360        }
    355361        from->colorIndex = to->colorIndex;
     
    370376                    && CHECKDIRTY(c->vertexAttrib[i], bitID)) {
    371377                if (COMPARE_VECTOR (from->vertexAttrib[i], to->vertexAttribPre[i])) {
    372                     diff_api.VertexAttrib4fvARB(i, &(to->vertexAttribPre[i][0]));
     378                    pState->diff_api.VertexAttrib4fvARB(i, &(to->vertexAttribPre[i][0]));
    373379                }
    374380                COPY_4V(from->vertexAttrib[i] , to->vertexAttrib[i]);
     
    386392        if (CHECKDIRTY(c->vertexAttrib[VERT_ATTRIB_COLOR0], bitID)) {
    387393            if (COMPARE_COLOR(from->vertexAttrib[VERT_ATTRIB_COLOR0],to->vertexAttribPre[VERT_ATTRIB_COLOR0])) {
    388                 diff_api.Color4fv ((GLfloat *) &(to->vertexAttribPre[VERT_ATTRIB_COLOR0]));
     394                pState->diff_api.Color4fv ((GLfloat *) &(to->vertexAttribPre[VERT_ATTRIB_COLOR0]));
    389395            }
    390396            COPY_4V(from->vertexAttrib[VERT_ATTRIB_COLOR0] , to->vertexAttrib[VERT_ATTRIB_COLOR0]);
     
    395401        if (CHECKDIRTY(c->vertexAttrib[VERT_ATTRIB_COLOR1], bitID)) {
    396402            if (COMPARE_COLOR(from->vertexAttrib[VERT_ATTRIB_COLOR1],to->vertexAttribPre[VERT_ATTRIB_COLOR1])) {
    397                 diff_api.SecondaryColor3fvEXT ((GLfloat *) &(to->vertexAttribPre[VERT_ATTRIB_COLOR1]));
     403                pState->diff_api.SecondaryColor3fvEXT ((GLfloat *) &(to->vertexAttribPre[VERT_ATTRIB_COLOR1]));
    398404            }
    399405            COPY_4V(from->vertexAttrib[VERT_ATTRIB_COLOR1] , to->vertexAttrib[VERT_ATTRIB_COLOR1]);
     
    405411        if (CHECKDIRTY(c->vertexAttrib[VERT_ATTRIB_FOG], bitID)) {
    406412            if (from->vertexAttrib[VERT_ATTRIB_FOG]  != to->vertexAttribPre[VERT_ATTRIB_FOG]) {
    407                 diff_api.FogCoordfvEXT ((GLfloat *) &(to->vertexAttribPre[VERT_ATTRIB_FOG]));
     413                pState->diff_api.FogCoordfvEXT ((GLfloat *) &(to->vertexAttribPre[VERT_ATTRIB_FOG]));
    408414            }
    409415            COPY_4V(from->vertexAttrib[VERT_ATTRIB_FOG]  , to->vertexAttrib[VERT_ATTRIB_FOG]);
     
    414420        if (CHECKDIRTY(c->vertexAttrib[VERT_ATTRIB_NORMAL], bitID)) {
    415421            if (COMPARE_VECTOR (from->vertexAttrib[VERT_ATTRIB_NORMAL], to->vertexAttribPre[VERT_ATTRIB_NORMAL])) {
    416                 diff_api.Normal3fv ((GLfloat *) &(to->vertexAttribPre[VERT_ATTRIB_NORMAL]));
     422                pState->diff_api.Normal3fv ((GLfloat *) &(to->vertexAttribPre[VERT_ATTRIB_NORMAL]));
    417423            }
    418424            COPY_4V(from->vertexAttrib[VERT_ATTRIB_NORMAL] , to->vertexAttrib[VERT_ATTRIB_NORMAL]);
     
    424430            if (CHECKDIRTY(c->vertexAttrib[VERT_ATTRIB_TEX0 + i], bitID)) {
    425431                if (COMPARE_TEXCOORD (from->vertexAttrib[VERT_ATTRIB_TEX0 + i], to->vertexAttribPre[VERT_ATTRIB_TEX0 + i])) {
    426                     diff_api.MultiTexCoord4fvARB (GL_TEXTURE0_ARB + i, (GLfloat *) &(to->vertexAttribPre[VERT_ATTRIB_TEX0 + i]));
     432                    pState->diff_api.MultiTexCoord4fvARB (GL_TEXTURE0_ARB + i, (GLfloat *) &(to->vertexAttribPre[VERT_ATTRIB_TEX0 + i]));
    427433                }
    428434                COPY_4V(from->vertexAttrib[VERT_ATTRIB_TEX0 + i] , to->vertexAttrib[VERT_ATTRIB_TEX0 + i]);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_current.py

    r69392 r78375  
    7979print('''
    8080
    81 void crStateCurrentRecover( void )
     81void crStateCurrentRecover(PCRStateTracker pState)
    8282{
    8383        const unsigned char *v;
    8484        convert_func convert=NULL;
    85         CRContext *g = GetCurrentContext();
     85        CRContext *g = GetCurrentContext(pState);
    8686        CRCurrentState *c = &(g->current);
    87         CRStateBits *sb = GetCurrentBits();
     87        CRStateBits *sb = GetCurrentBits(pState);
    8888        CRCurrentBits *cb = &(sb->current);
    8989        static const GLfloat color_default[4]                   = {0.0f, 0.0f, 0.0f, 1.0f};
     
    295295    const unsigned char *v;
    296296    convert_func convert=NULL;
    297     CRCurrentState *c = &(g->current);
    298     CRStateBits *sb = GetCurrentBits();
    299     CRCurrentBits *cb = &(sb->current);
     297    CRCurrentState *c;
     298    CRStateBits *sb;
     299    CRCurrentBits *cb;
    300300
    301301    static const GLfloat vertexAttrib_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
     
    309309    if (!g || !current)
    310310        return;
     311
     312    c = &(g->current);
     313    sb = GetCurrentBits(g->pStateTracker);
     314    cb = &(sb->current);
    311315
    312316    /* silence warnings */
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_diff.c

    r76474 r78375  
    1414void crStateDiffContext( CRContext *from, CRContext *to )
    1515{
     16    PCRStateTracker pState = from->pStateTracker;
    1617        CRbitvalue *bitID = from->bitid;
    17         CRStateBits *sb = GetCurrentBits();
     18        CRStateBits *sb = GetCurrentBits(pState);
     19
     20    CRASSERT(from->pStateTracker == to->pStateTracker);
    1821
    1922        /*crDebug( "Diffing two contexts!" ); */
     
    143146int crStateAcquireFBImage(CRContext *to, CRFBData *data)
    144147{
     148    PCRStateTracker pState = to->pStateTracker;
    145149    /*CRBufferState *pBuf = &to->buffer; - unused */
    146150    CRPixelPackState packing = to->client.pack;
    147151    uint32_t i;
    148152
    149     diff_api.PixelStorei(GL_PACK_SKIP_ROWS, 0);
    150     diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, 0);
    151     diff_api.PixelStorei(GL_PACK_ALIGNMENT, 1);
    152     diff_api.PixelStorei(GL_PACK_ROW_LENGTH, 0);
    153     diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
    154     diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, 0);
    155     diff_api.PixelStorei(GL_PACK_SWAP_BYTES, 0);
    156     diff_api.PixelStorei(GL_PACK_LSB_FIRST, 0);
     153    pState->diff_api.PixelStorei(GL_PACK_SKIP_ROWS, 0);
     154    pState->diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, 0);
     155    pState->diff_api.PixelStorei(GL_PACK_ALIGNMENT, 1);
     156    pState->diff_api.PixelStorei(GL_PACK_ROW_LENGTH, 0);
     157    pState->diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
     158    pState->diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, 0);
     159    pState->diff_api.PixelStorei(GL_PACK_SWAP_BYTES, 0);
     160    pState->diff_api.PixelStorei(GL_PACK_LSB_FIRST, 0);
    157161
    158162    if (to->bufferobject.packBuffer->hwid>0)
    159163    {
    160         diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
     164        pState->diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
    161165    }
    162166
     
    169173            if (!to->buffer.depthTest)
    170174            {
    171                 diff_api.Enable(GL_DEPTH_TEST);
     175                pState->diff_api.Enable(GL_DEPTH_TEST);
    172176            }
    173177            if (to->pixel.depthScale != 1.0f)
    174178            {
    175                 diff_api.PixelTransferf (GL_DEPTH_SCALE, 1.0f);
     179                pState->diff_api.PixelTransferf (GL_DEPTH_SCALE, 1.0f);
    176180            }
    177181            if (to->pixel.depthBias != 0.0f)
    178182            {
    179                 diff_api.PixelTransferf (GL_DEPTH_BIAS, 0.0f);
     183                pState->diff_api.PixelTransferf (GL_DEPTH_BIAS, 0.0f);
    180184            }
    181185        }
     
    184188                if (!to->stencil.stencilTest)
    185189            {
    186                 diff_api.Enable(GL_STENCIL_TEST);
     190                pState->diff_api.Enable(GL_STENCIL_TEST);
    187191            }
    188192            if (to->pixel.mapStencil)
    189193            {
    190                 diff_api.PixelTransferi (GL_MAP_STENCIL, GL_FALSE);
     194                pState->diff_api.PixelTransferi (GL_MAP_STENCIL, GL_FALSE);
    191195            }
    192196            if (to->pixel.indexOffset)
    193197            {
    194                 diff_api.PixelTransferi (GL_INDEX_OFFSET, 0);
     198                pState->diff_api.PixelTransferi (GL_INDEX_OFFSET, 0);
    195199            }
    196200            if (to->pixel.indexShift)
    197201            {
    198                 diff_api.PixelTransferi (GL_INDEX_SHIFT, 0);
    199             }
    200         }
    201 
    202         diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, el->idFBO);
     202                pState->diff_api.PixelTransferi (GL_INDEX_SHIFT, 0);
     203            }
     204        }
     205
     206        pState->diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, el->idFBO);
    203207
    204208        if (el->enmBuffer)
    205             diff_api.ReadBuffer(el->enmBuffer);
    206 
    207         diff_api.ReadPixels(el->posX, el->posY, el->width, el->height, el->enmFormat, el->enmType, el->pvData);
     209            pState->diff_api.ReadBuffer(el->enmBuffer);
     210
     211        pState->diff_api.ReadPixels(el->posX, el->posY, el->width, el->height, el->enmFormat, el->enmType, el->pvData);
    208212        crDebug("Acquired %d;%d;%d;%d;%d;0x%p fb image", el->enmBuffer, el->width, el->height, el->enmFormat, el->enmType, el->pvData);
    209213
     
    212216            if (to->pixel.depthScale != 1.0f)
    213217            {
    214                 diff_api.PixelTransferf (GL_DEPTH_SCALE, to->pixel.depthScale);
     218                pState->diff_api.PixelTransferf (GL_DEPTH_SCALE, to->pixel.depthScale);
    215219            }
    216220            if (to->pixel.depthBias != 0.0f)
    217221            {
    218                 diff_api.PixelTransferf (GL_DEPTH_BIAS, to->pixel.depthBias);
     222                pState->diff_api.PixelTransferf (GL_DEPTH_BIAS, to->pixel.depthBias);
    219223            }
    220224            if (!to->buffer.depthTest)
    221225            {
    222                 diff_api.Disable(GL_DEPTH_TEST);
     226                pState->diff_api.Disable(GL_DEPTH_TEST);
    223227            }
    224228        }
     
    227231            if (to->pixel.indexOffset)
    228232            {
    229                 diff_api.PixelTransferi (GL_INDEX_OFFSET, to->pixel.indexOffset);
     233                pState->diff_api.PixelTransferi (GL_INDEX_OFFSET, to->pixel.indexOffset);
    230234            }
    231235            if (to->pixel.indexShift)
    232236            {
    233                 diff_api.PixelTransferi (GL_INDEX_SHIFT, to->pixel.indexShift);
     237                pState->diff_api.PixelTransferi (GL_INDEX_SHIFT, to->pixel.indexShift);
    234238            }
    235239            if (to->pixel.mapStencil)
    236240            {
    237                 diff_api.PixelTransferi (GL_MAP_STENCIL, GL_TRUE);
     241                pState->diff_api.PixelTransferi (GL_MAP_STENCIL, GL_TRUE);
    238242            }
    239243            if (!to->stencil.stencilTest)
    240244            {
    241                 diff_api.Disable(GL_STENCIL_TEST);
     245                pState->diff_api.Disable(GL_STENCIL_TEST);
    242246            }
    243247        }
     
    246250    if (to->bufferobject.packBuffer->hwid>0)
    247251    {
    248         diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, to->bufferobject.packBuffer->hwid);
     252        pState->diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, to->bufferobject.packBuffer->hwid);
    249253    }
    250254    if (to->framebufferobject.readFB)
    251255    {
    252256        CRASSERT(to->framebufferobject.readFB->hwid);
    253         diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, to->framebufferobject.readFB->hwid);
    254         diff_api.ReadBuffer(to->framebufferobject.readFB->readbuffer);
     257        pState->diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, to->framebufferobject.readFB->hwid);
     258        pState->diff_api.ReadBuffer(to->framebufferobject.readFB->readbuffer);
    255259
    256260    }
    257261    else if (data->idOverrrideFBO)
    258262    {
    259         diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, data->idOverrrideFBO);
    260         diff_api.ReadBuffer(GL_COLOR_ATTACHMENT0);
     263        pState->diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, data->idOverrrideFBO);
     264        pState->diff_api.ReadBuffer(GL_COLOR_ATTACHMENT0);
    261265    }
    262266    else
    263267    {
    264         diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, 0);
    265         diff_api.ReadBuffer(to->buffer.readBuffer);
    266     }
    267 
    268     diff_api.PixelStorei(GL_PACK_SKIP_ROWS, packing.skipRows);
    269     diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, packing.skipPixels);
    270     diff_api.PixelStorei(GL_PACK_ALIGNMENT, packing.alignment);
    271     diff_api.PixelStorei(GL_PACK_ROW_LENGTH, packing.rowLength);
    272     diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, packing.imageHeight);
    273     diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, packing.skipImages);
    274     diff_api.PixelStorei(GL_PACK_SWAP_BYTES, packing.swapBytes);
    275     diff_api.PixelStorei(GL_PACK_LSB_FIRST, packing.psLSBFirst);
     268        pState->diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, 0);
     269        pState->diff_api.ReadBuffer(to->buffer.readBuffer);
     270    }
     271
     272    pState->diff_api.PixelStorei(GL_PACK_SKIP_ROWS, packing.skipRows);
     273    pState->diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, packing.skipPixels);
     274    pState->diff_api.PixelStorei(GL_PACK_ALIGNMENT, packing.alignment);
     275    pState->diff_api.PixelStorei(GL_PACK_ROW_LENGTH, packing.rowLength);
     276    pState->diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, packing.imageHeight);
     277    pState->diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, packing.skipImages);
     278    pState->diff_api.PixelStorei(GL_PACK_SWAP_BYTES, packing.swapBytes);
     279    pState->diff_api.PixelStorei(GL_PACK_LSB_FIRST, packing.psLSBFirst);
    276280    return VINF_SUCCESS;
    277281}
     
    279283void crStateApplyFBImage(CRContext *to, CRFBData *data)
    280284{
    281     {
    282         /*CRBufferState *pBuf = &to->buffer; - unused */
    283         CRPixelPackState unpack = to->client.unpack;
    284         uint32_t i;
    285 
    286         diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    287         diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    288         diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
    289         diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    290         diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
    291         diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
    292         diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, 0);
    293         diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, 0);
    294 
    295         if (to->bufferobject.unpackBuffer->hwid>0)
    296         {
    297             diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
    298         }
    299 
    300         diff_api.Disable(GL_ALPHA_TEST);
    301         diff_api.Disable(GL_SCISSOR_TEST);
    302         diff_api.Disable(GL_BLEND);
    303         diff_api.Disable(GL_COLOR_LOGIC_OP);
    304         diff_api.Disable(GL_DEPTH_TEST);
    305         diff_api.Disable(GL_STENCIL_TEST);
    306 
    307         for (i = 0; i < data->cElements; ++i)
    308         {
    309             CRFBDataElement *el = &data->aElements[i];
     285    PCRStateTracker pState = to->pStateTracker;
     286    CRPixelPackState unpack = to->client.unpack;
     287    uint32_t i;
     288
     289    pState->diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
     290    pState->diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
     291    pState->diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
     292    pState->diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
     293    pState->diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
     294    pState->diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
     295    pState->diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, 0);
     296    pState->diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, 0);
     297
     298    if (to->bufferobject.unpackBuffer->hwid>0)
     299    {
     300        pState->diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
     301    }
     302
     303    pState->diff_api.Disable(GL_ALPHA_TEST);
     304    pState->diff_api.Disable(GL_SCISSOR_TEST);
     305    pState->diff_api.Disable(GL_BLEND);
     306    pState->diff_api.Disable(GL_COLOR_LOGIC_OP);
     307    pState->diff_api.Disable(GL_DEPTH_TEST);
     308    pState->diff_api.Disable(GL_STENCIL_TEST);
     309
     310    for (i = 0; i < data->cElements; ++i)
     311    {
     312        CRFBDataElement *el = &data->aElements[i];
    310313#if 0
    311             char fname[200];
    312             sprintf(fname, "./img_apply_%p_%d_%d.tga", to, i, el->enmFormat);
    313             crDumpNamedTGA(fname, el->width, el->height, el->pvData);
    314 #endif
    315 
    316             /* Before SSM version SHCROGL_SSM_VERSION_WITH_SEPARATE_DEPTH_STENCIL_BUFFERS
    317              * saved state file contined invalid DEPTH/STENCIL data. In order to prevent
    318              * crashes and improper guest App behavior, this data should be ignored. */
    319             if (   data->u32Version < SHCROGL_SSM_VERSION_WITH_SEPARATE_DEPTH_STENCIL_BUFFERS
    320                 && (   el->enmFormat == GL_DEPTH_COMPONENT
    321                     || el->enmFormat == GL_STENCIL_INDEX
    322                     || el->enmFormat == GL_DEPTH_STENCIL))
    323                 continue;
    324 
    325             if (el->enmFormat == GL_DEPTH_COMPONENT || el->enmFormat == GL_DEPTH_STENCIL)
    326             {
    327                 diff_api.Enable(GL_DEPTH_TEST);
    328                 if (to->pixel.depthScale != 1.0f)
    329                 {
    330                     diff_api.PixelTransferf (GL_DEPTH_SCALE, 1.0f);
    331                 }
    332                 if (to->pixel.depthBias != 0.0f)
    333                 {
    334                     diff_api.PixelTransferf (GL_DEPTH_BIAS, 0.0f);
    335                 }
    336             }
    337             if (el->enmFormat == GL_STENCIL_INDEX || el->enmFormat == GL_DEPTH_STENCIL)
    338             {
    339                 diff_api.Enable(GL_STENCIL_TEST);
    340                 if (to->pixel.mapStencil)
    341                 {
    342                     diff_api.PixelTransferi (GL_MAP_STENCIL, GL_FALSE);
    343                 }
    344                 if (to->pixel.indexOffset)
    345                 {
    346                     diff_api.PixelTransferi (GL_INDEX_OFFSET, 0);
    347                 }
    348                 if (to->pixel.indexShift)
    349                 {
    350                     diff_api.PixelTransferi (GL_INDEX_SHIFT, 0);
    351                 }
    352             }
    353 
    354             diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, el->idFBO);
    355 
    356             if (el->enmBuffer)
    357                 diff_api.DrawBuffer(el->enmBuffer);
    358 
    359             diff_api.WindowPos2iARB(el->posX, el->posY);
    360             diff_api.DrawPixels(el->width, el->height, el->enmFormat, el->enmType, el->pvData);
    361             crDebug("Applied %d;%d;%d;%d;%d;0x%p fb image", el->enmBuffer, el->width, el->height, el->enmFormat, el->enmType, el->pvData);
    362 
    363             if (el->enmFormat == GL_DEPTH_COMPONENT || el->enmFormat == GL_DEPTH_STENCIL)
    364             {
    365                 if (to->pixel.depthScale != 1.0f)
    366                 {
    367                     diff_api.PixelTransferf (GL_DEPTH_SCALE, to->pixel.depthScale);
    368                 }
    369                 if (to->pixel.depthBias != 0.0f)
    370                 {
    371                     diff_api.PixelTransferf (GL_DEPTH_BIAS, to->pixel.depthBias);
    372                 }
    373                 diff_api.Disable(GL_DEPTH_TEST);
    374             }
    375             if (el->enmFormat == GL_STENCIL_INDEX || el->enmFormat == GL_DEPTH_STENCIL)
    376             {
    377                 if (to->pixel.indexOffset)
    378                 {
    379                     diff_api.PixelTransferi (GL_INDEX_OFFSET, to->pixel.indexOffset);
    380                 }
    381                 if (to->pixel.indexShift)
    382                 {
    383                     diff_api.PixelTransferi (GL_INDEX_SHIFT, to->pixel.indexShift);
    384                 }
    385                 if (to->pixel.mapStencil)
    386                 {
    387                     diff_api.PixelTransferi (GL_MAP_STENCIL, GL_TRUE);
    388                 }
    389                 diff_api.Disable(GL_STENCIL_TEST);
    390             }
    391         }
    392 
    393         diff_api.WindowPos3fvARB(to->current.rasterAttrib[VERT_ATTRIB_POS]);
    394         if (to->bufferobject.unpackBuffer->hwid>0)
    395         {
    396             diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, to->bufferobject.unpackBuffer->hwid);
    397         }
    398         if (to->framebufferobject.drawFB)
    399         {
    400             CRASSERT(to->framebufferobject.drawFB->hwid);
    401             diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, to->framebufferobject.drawFB->hwid);
    402             diff_api.DrawBuffer(to->framebufferobject.drawFB->drawbuffer[0]);
    403         }
    404         else if (data->idOverrrideFBO)
    405         {
    406             diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, data->idOverrrideFBO);
    407             diff_api.DrawBuffer(GL_COLOR_ATTACHMENT0);
    408         }
    409         else
    410         {
    411             diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
    412             diff_api.DrawBuffer(to->buffer.drawBuffer);
    413         }
    414         if (to->buffer.alphaTest)
    415         {
    416             diff_api.Enable(GL_ALPHA_TEST);
    417         }
    418         if (to->viewport.scissorTest)
    419         {
    420             diff_api.Enable(GL_SCISSOR_TEST);
    421         }
    422         if (to->buffer.blend)
    423         {
    424             diff_api.Enable(GL_BLEND);
    425         }
    426         if (to->buffer.logicOp)
    427         {
    428             diff_api.Enable(GL_COLOR_LOGIC_OP);
    429         }
    430         if (to->buffer.depthTest)
    431         {
    432             diff_api.Enable(GL_DEPTH_TEST);
    433         }
    434         if (to->stencil.stencilTest)
    435         {
    436             diff_api.Enable(GL_STENCIL_TEST);
    437         }
    438 
    439         diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, unpack.skipRows);
    440         diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, unpack.skipPixels);
    441         diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, unpack.alignment);
    442         diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, unpack.rowLength);
    443         diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, unpack.imageHeight);
    444         diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, unpack.skipImages);
    445         diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, unpack.swapBytes);
    446         diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, unpack.psLSBFirst);
    447 
    448         diff_api.Finish();
    449     }
     314        char fname[200];
     315        sprintf(fname, "./img_apply_%p_%d_%d.tga", to, i, el->enmFormat);
     316        crDumpNamedTGA(fname, el->width, el->height, el->pvData);
     317#endif
     318
     319        /* Before SSM version SHCROGL_SSM_VERSION_WITH_SEPARATE_DEPTH_STENCIL_BUFFERS
     320         * saved state file contined invalid DEPTH/STENCIL data. In order to prevent
     321         * crashes and improper guest App behavior, this data should be ignored. */
     322        if (   data->u32Version < SHCROGL_SSM_VERSION_WITH_SEPARATE_DEPTH_STENCIL_BUFFERS
     323            && (   el->enmFormat == GL_DEPTH_COMPONENT
     324                || el->enmFormat == GL_STENCIL_INDEX
     325                || el->enmFormat == GL_DEPTH_STENCIL))
     326            continue;
     327
     328        if (el->enmFormat == GL_DEPTH_COMPONENT || el->enmFormat == GL_DEPTH_STENCIL)
     329        {
     330            pState->diff_api.Enable(GL_DEPTH_TEST);
     331            if (to->pixel.depthScale != 1.0f)
     332            {
     333                pState->diff_api.PixelTransferf (GL_DEPTH_SCALE, 1.0f);
     334            }
     335            if (to->pixel.depthBias != 0.0f)
     336            {
     337                pState->diff_api.PixelTransferf (GL_DEPTH_BIAS, 0.0f);
     338            }
     339        }
     340        if (el->enmFormat == GL_STENCIL_INDEX || el->enmFormat == GL_DEPTH_STENCIL)
     341        {
     342            pState->diff_api.Enable(GL_STENCIL_TEST);
     343            if (to->pixel.mapStencil)
     344            {
     345                pState->diff_api.PixelTransferi (GL_MAP_STENCIL, GL_FALSE);
     346            }
     347            if (to->pixel.indexOffset)
     348            {
     349                pState->diff_api.PixelTransferi (GL_INDEX_OFFSET, 0);
     350            }
     351            if (to->pixel.indexShift)
     352            {
     353                pState->diff_api.PixelTransferi (GL_INDEX_SHIFT, 0);
     354            }
     355        }
     356
     357        pState->diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, el->idFBO);
     358
     359        if (el->enmBuffer)
     360            pState->diff_api.DrawBuffer(el->enmBuffer);
     361
     362        pState->diff_api.WindowPos2iARB(el->posX, el->posY);
     363        pState->diff_api.DrawPixels(el->width, el->height, el->enmFormat, el->enmType, el->pvData);
     364        crDebug("Applied %d;%d;%d;%d;%d;0x%p fb image", el->enmBuffer, el->width, el->height, el->enmFormat, el->enmType, el->pvData);
     365
     366        if (el->enmFormat == GL_DEPTH_COMPONENT || el->enmFormat == GL_DEPTH_STENCIL)
     367        {
     368            if (to->pixel.depthScale != 1.0f)
     369            {
     370                pState->diff_api.PixelTransferf (GL_DEPTH_SCALE, to->pixel.depthScale);
     371            }
     372            if (to->pixel.depthBias != 0.0f)
     373            {
     374                pState->diff_api.PixelTransferf (GL_DEPTH_BIAS, to->pixel.depthBias);
     375            }
     376            pState->diff_api.Disable(GL_DEPTH_TEST);
     377        }
     378        if (el->enmFormat == GL_STENCIL_INDEX || el->enmFormat == GL_DEPTH_STENCIL)
     379        {
     380            if (to->pixel.indexOffset)
     381            {
     382                pState->diff_api.PixelTransferi (GL_INDEX_OFFSET, to->pixel.indexOffset);
     383            }
     384            if (to->pixel.indexShift)
     385            {
     386                pState->diff_api.PixelTransferi (GL_INDEX_SHIFT, to->pixel.indexShift);
     387            }
     388            if (to->pixel.mapStencil)
     389            {
     390                pState->diff_api.PixelTransferi (GL_MAP_STENCIL, GL_TRUE);
     391            }
     392            pState->diff_api.Disable(GL_STENCIL_TEST);
     393        }
     394    }
     395
     396    pState->diff_api.WindowPos3fvARB(to->current.rasterAttrib[VERT_ATTRIB_POS]);
     397    if (to->bufferobject.unpackBuffer->hwid>0)
     398    {
     399        pState->diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, to->bufferobject.unpackBuffer->hwid);
     400    }
     401    if (to->framebufferobject.drawFB)
     402    {
     403        CRASSERT(to->framebufferobject.drawFB->hwid);
     404        pState->diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, to->framebufferobject.drawFB->hwid);
     405        pState->diff_api.DrawBuffer(to->framebufferobject.drawFB->drawbuffer[0]);
     406    }
     407    else if (data->idOverrrideFBO)
     408    {
     409        pState->diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, data->idOverrrideFBO);
     410        pState->diff_api.DrawBuffer(GL_COLOR_ATTACHMENT0);
     411    }
     412    else
     413    {
     414        pState->diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
     415        pState->diff_api.DrawBuffer(to->buffer.drawBuffer);
     416    }
     417    if (to->buffer.alphaTest)
     418    {
     419        pState->diff_api.Enable(GL_ALPHA_TEST);
     420    }
     421    if (to->viewport.scissorTest)
     422    {
     423        pState->diff_api.Enable(GL_SCISSOR_TEST);
     424    }
     425    if (to->buffer.blend)
     426    {
     427        pState->diff_api.Enable(GL_BLEND);
     428    }
     429    if (to->buffer.logicOp)
     430    {
     431        pState->diff_api.Enable(GL_COLOR_LOGIC_OP);
     432    }
     433    if (to->buffer.depthTest)
     434    {
     435        pState->diff_api.Enable(GL_DEPTH_TEST);
     436    }
     437    if (to->stencil.stencilTest)
     438    {
     439        pState->diff_api.Enable(GL_STENCIL_TEST);
     440    }
     441
     442    pState->diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, unpack.skipRows);
     443    pState->diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, unpack.skipPixels);
     444    pState->diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, unpack.alignment);
     445    pState->diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, unpack.rowLength);
     446    pState->diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, unpack.imageHeight);
     447    pState->diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, unpack.skipImages);
     448    pState->diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, unpack.swapBytes);
     449    pState->diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, unpack.psLSBFirst);
     450
     451    pState->diff_api.Finish();
    450452}
    451453
    452454void crStateSwitchContext( CRContext *from, CRContext *to )
    453455{
     456    PCRStateTracker pState = from->pStateTracker;
    454457        CRbitvalue *bitID = to->bitid;
    455         CRStateBits *sb = GetCurrentBits();
     458        CRStateBits *sb = GetCurrentBits(pState);
     459
     460    CRASSERT(from->pStateTracker == to->pStateTracker);
    456461
    457462        if (CHECKDIRTY(sb->attrib.dirty, bitID))
     
    590595{
    591596    GLenum err;
    592     while ((err = diff_api.GetError()) != GL_NO_ERROR)
     597    while ((err = ctx->pStateTracker->diff_api.GetError()) != GL_NO_ERROR)
    593598    {
    594599        if (ctx->error != GL_NO_ERROR)
     
    597602}
    598603
    599 GLenum crStateCleanHWErrorState(void)
     604GLenum crStateCleanHWErrorState(PCRStateTracker pState)
    600605{
    601606    GLenum err;
    602     while ((err = diff_api.GetError()) != GL_NO_ERROR)
     607    while ((err = pState->diff_api.GetError()) != GL_NO_ERROR)
    603608    {
    604609        static int cErrPrints = 0;
     
    618623void crStateSwitchPrepare(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO)
    619624{
     625    PCRStateTracker pState = toCtx->pStateTracker ? toCtx->pStateTracker : fromCtx->pStateTracker;
     626
     627    CRASSERT(pState);
     628    CRASSERT(!toCtx || !fromCtx || toCtx->pStateTracker == fromCtx->pStateTracker);
     629
    620630    if (!fromCtx)
    621631        return;
    622632
    623     if (g_bVBoxEnableDiffOnMakeCurrent && toCtx && toCtx != fromCtx)
     633    if (pState->fVBoxEnableDiffOnMakeCurrent && toCtx && toCtx != fromCtx)
    624634        crStateSyncHWErrorState(fromCtx);
    625635
     
    631641void crStateSwitchPostprocess(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO)
    632642{
     643    PCRStateTracker pState = toCtx->pStateTracker ? toCtx->pStateTracker : fromCtx->pStateTracker;
     644
     645    CRASSERT(pState);
     646    CRASSERT(!toCtx || !fromCtx || toCtx->pStateTracker == fromCtx->pStateTracker);
     647
    633648    if (!toCtx)
    634649        return;
     
    638653#endif
    639654
    640     if (g_bVBoxEnableDiffOnMakeCurrent && fromCtx && toCtx != fromCtx)
    641     {
    642         CR_STATE_CLEAN_HW_ERR_WARN("error on make current");
    643     }
    644 }
     655    if (pState->fVBoxEnableDiffOnMakeCurrent && fromCtx && toCtx != fromCtx)
     656    {
     657        CR_STATE_CLEAN_HW_ERR_WARN(pState, "error on make current");
     658    }
     659}
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_enable.c

    r69392 r78375  
    1313                                GLenum cap, GLboolean val)
    1414{
     15    PCRStateTracker pState = g->pStateTracker;
    1516        unsigned int i;
    1617        i = cap - GL_CLIP_PLANE0;
     
    5657                                 * for an example of why). */
    5758
    58                                 crStateCurrentRecover( );
    59                                 crStateColorMaterialRecover( );
     59                                crStateCurrentRecover(pState);
     60                                crStateColorMaterialRecover(pState);
    6061                        }
    6162                        g->lighting.colorMaterial = val;
     
    7172                        }
    7273                        else {
    73                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(GL_COLOR_SUM_EXT) - No support for secondary color!");
     74                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(GL_COLOR_SUM_EXT) - No support for secondary color!");
    7475                                return;
    7576                        }
     
    164165                        }
    165166                        else {
    166                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(GL_REGISTER_COMBINERS_NV) - No support for NV_register_combiners");
     167                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(GL_REGISTER_COMBINERS_NV) - No support for NV_register_combiners");
    167168                                return;
    168169                        }
     
    177178                        }
    178179                        else {
    179                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(GL_PER_STAGE_CONSTANTS_NV) - No support for NV_register_combiners2");
     180                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(GL_PER_STAGE_CONSTANTS_NV) - No support for NV_register_combiners2");
    180181                                return;
    181182                        }
     
    190191                        }
    191192                        else {
    192                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
     193                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
    193194                                return;
    194195                        }
     
    237238                        }
    238239                        else {
    239                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
     240                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
    240241                                return;
    241242                        }
     
    273274                        if (g->texture.curTextureUnit != 0)
    274275                        {
    275                                 crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "Map stuff was enabled while the current texture unit was not GL_TEXTURE0_ARB!" );
     276                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "Map stuff was enabled while the current texture unit was not GL_TEXTURE0_ARB!" );
    276277                                return;
    277278                        }
     
    335336                        }
    336337                        else {
    337                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
     338                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
    338339                                return;
    339340                        }
     
    351352                        }
    352353                        else {
    353                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
     354                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
    354355                                return;
    355356                        }
     
    367368                        }
    368369                        else {
    369                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
     370                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
    370371                                return;
    371372                        }
     
    427428                        }
    428429                        else {
    429                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
     430                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
    430431                                return;
    431432                        }
     
    440441                        }
    441442                        else {
    442                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
     443                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable(0x%x)", cap);
    443444                                return;
    444445                        }
     
    493494#endif
    494495                        if (val)
    495                                 crStateEnableClientState(cap);
     496                                crStateEnableClientState(pState, cap);
    496497                        else
    497                                 crStateDisableClientState(cap);
     498                                crStateDisableClientState(pState, cap);
    498499                        break;
    499500#ifdef CR_EXT_stencil_two_side
     
    505506#endif
    506507                default:
    507                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable called with bogus cap: 0x%x", cap);
     508                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEnable/glDisable called with bogus cap: 0x%x", cap);
    508509                        return;
    509510        }
     
    511512
    512513
    513 void STATE_APIENTRY crStateEnable (GLenum cap)
     514void STATE_APIENTRY crStateEnable (PCRStateTracker pState, GLenum cap)
    514515{
    515         CRContext *g = GetCurrentContext();
    516         CRStateBits *sb = GetCurrentBits();
     516        CRContext *g = GetCurrentContext(pState);
     517        CRStateBits *sb = GetCurrentBits(pState);
    517518
    518519        if (g->current.inBeginEnd)
    519520        {
    520                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glEnable called in begin/end");
     521                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glEnable called in begin/end");
    521522                return;
    522523        }
     
    528529
    529530
    530 void STATE_APIENTRY crStateDisable (GLenum cap)
     531void STATE_APIENTRY crStateDisable (PCRStateTracker pState, GLenum cap)
    531532{
    532         CRContext *g = GetCurrentContext();
    533         CRStateBits *sb = GetCurrentBits();
     533        CRContext *g = GetCurrentContext(pState);
     534        CRStateBits *sb = GetCurrentBits(pState);
    534535
    535536        if (g->current.inBeginEnd)
    536537        {
    537                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDisable called in begin/end");
     538                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glDisable called in begin/end");
    538539                return;
    539540        }
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_error.c

    r78190 r78375  
    55 */
    66
     7#include "state/cr_statetypes.h"
    78#include "state/cr_stateerror.h"
    8 #include "state/cr_statetypes.h"
    99#include "state.h"
    1010#include "cr_error.h"
     
    1414#include <iprt/env.h>
    1515
    16 void crStateError( int line, const char *file, GLenum error, const char *format, ... )
     16void crStateError(PCRStateTracker pState, int line, const char *file, GLenum error, const char *format, ... )
    1717{
    18         CRContext *g = GetCurrentContext();
     18        CRContext *g = GetCurrentContext(pState);
    1919        char errstr[8096];
    2020        va_list args;
     
    7070
    7171
    72 GLenum STATE_APIENTRY crStateGetError(void)
     72GLenum STATE_APIENTRY crStateGetError(PCRStateTracker pState)
    7373{
    74         CRContext *g = GetCurrentContext();
     74        CRContext *g = GetCurrentContext(pState);
    7575        GLenum e = g->error;
    7676
    7777        if (g->current.inBeginEnd)
    7878        {
    79                 crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION,
     79                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    8080                                                                        "glStateGetError() called between glBegin/glEnd" );
    8181                return 0;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_evaluators.c

    r78105 r78375  
    4141{
    4242        CREvaluatorState *e = &ctx->eval;
    43         CRStateBits *sb = GetCurrentBits();
     43        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    4444        CREvaluatorBits *eb = &(sb->eval);
    4545        GLint i;
     
    6363{
    6464        CREvaluatorState *e = &ctx->eval;
    65         CRStateBits *sb = GetCurrentBits();
     65        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    6666        CREvaluatorBits *eb = &(sb->eval);
    6767        GLint i;
     
    111111{
    112112        CREvaluatorState *e = &ctx->eval;
    113         CRStateBits *sb = GetCurrentBits();
     113        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    114114        CREvaluatorBits *eb = &(sb->eval);
    115115        static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
     
    324324 */
    325325static void
    326 map1(GLenum target, GLfloat u1, GLfloat u2, GLint ustride,
     326map1(PCRStateTracker pState, GLenum target, GLfloat u1, GLfloat u2, GLint ustride,
    327327                 GLint uorder, const GLvoid * points, GLenum type)
    328328{
    329         CRContext *g = GetCurrentContext();
     329        CRContext *g = GetCurrentContext(pState);
    330330        CREvaluatorState *e = &(g->eval);
    331         CRStateBits *sb = GetCurrentBits();
     331        CRStateBits *sb = GetCurrentBits(pState);
    332332        CREvaluatorBits *eb = &(sb->eval);
    333333        CRTextureState *t = &(g->texture);
     
    337337
    338338        if (g->current.inBeginEnd) {
    339                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     339                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    340340                                                                 "Map1d called in begin/end");
    341341                return;
     
    347347
    348348        if (u1 == u2) {
    349                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(u1==u2)");
     349                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(u1==u2)");
    350350                return;
    351351        }
    352352        if (uorder < 1 || uorder > MAX_EVAL_ORDER) {
    353                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(bad uorder)");
     353                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(bad uorder)");
    354354                return;
    355355        }
    356356        if (!points) {
    357                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     357                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    358358                                                                 "glMap1d(null points)");
    359359                return;
     
    372372            break;
    373373        default:
    374             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMap1d(bad target)");
     374            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMap1d(bad target)");
    375375            return;
    376376    }
     
    381381
    382382        if (k == 0) {
    383                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMap1d(k=0)");
     383                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMap1d(k=0)");
    384384                return;
    385385        }
    386386
    387387        if (ustride < k) {
    388                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(bad ustride");
     388                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(bad ustride");
    389389                return;
    390390        }
     
    392392        if (t->curTextureUnit != 0) {
    393393                /* See OpenGL 1.2.1 spec, section F.2.13 */
    394                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     394                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    395395                                                                 "glMap1d(current texture unit must be zero)");
    396396                return;
     
    418418
    419419void STATE_APIENTRY
    420 crStateMap1f(GLenum target, GLfloat u1, GLfloat u2,
     420crStateMap1f(PCRStateTracker pState, GLenum target, GLfloat u1, GLfloat u2,
    421421                                                 GLint stride, GLint order, const GLfloat * points)
    422422{
    423         map1(target, u1, u2, stride, order, points, GL_FLOAT);
     423        map1(pState, target, u1, u2, stride, order, points, GL_FLOAT);
    424424}
    425425
    426426void STATE_APIENTRY
    427 crStateMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
     427crStateMap1d(PCRStateTracker pState, GLenum target, GLdouble u1, GLdouble u2, GLint stride,
    428428                                                 GLint order, const GLdouble * points)
    429429{
    430         map1(target, (GLfloat) u1, (GLfloat) u2, stride, order, points, GL_DOUBLE);
     430        map1(pState, target, (GLfloat) u1, (GLfloat) u2, stride, order, points, GL_DOUBLE);
    431431}
    432432
    433433static void
    434 map2(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
     434map2(PCRStateTracker pState, GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
    435435                 GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
    436436                 const GLvoid * points, GLenum type)
    437437{
    438         CRContext *g = GetCurrentContext();
    439         CRStateBits *sb = GetCurrentBits();
     438        CRContext *g = GetCurrentContext(pState);
     439        CRStateBits *sb = GetCurrentBits(pState);
    440440        CREvaluatorState *e = &(g->eval);
    441441        CREvaluatorBits *eb = &(sb->eval);
     
    448448
    449449        if (g->current.inBeginEnd) {
    450                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glMap2d()");
     450                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glMap2d()");
    451451                return;
    452452        }
     
    455455
    456456        if (u1 == u2) {
    457                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
     457                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
    458458                return;
    459459        }
    460460
    461461        if (v1 == v2) {
    462                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
     462                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
    463463                return;
    464464        }
    465465
    466466        if (uorder < 1 || uorder > MAX_EVAL_ORDER) {
    467                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
     467                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
    468468                return;
    469469        }
    470470
    471471        if (vorder < 1 || vorder > MAX_EVAL_ORDER) {
    472                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
     472                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
    473473                return;
    474474        }
     
    486486            break;
    487487        default:
    488             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMap2d()");
     488            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMap2d()");
    489489            return;
    490490    }
     
    500500
    501501        if (k == 0) {
    502                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMap2d()");
     502                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMap2d()");
    503503                return;
    504504        }
    505505
    506506        if (ustride < k) {
    507                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
     507                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
    508508                return;
    509509        }
    510510        if (vstride < k) {
    511                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
     511                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
    512512                return;
    513513        }
     
    520520        if (t->curTextureUnit != 0) {
    521521                /* See OpenGL 1.2.1 spec, section F.2.13 */
    522                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glMap2d()");
     522                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glMap2d()");
    523523                return;
    524524        }
     
    550550
    551551void STATE_APIENTRY
    552 crStateMap2f(GLenum target, GLfloat u1, GLfloat u2,
     552crStateMap2f(PCRStateTracker pState, GLenum target, GLfloat u1, GLfloat u2,
    553553                                                 GLint ustride, GLint uorder,
    554554                                                 GLfloat v1, GLfloat v2,
    555555                                                 GLint vstride, GLint vorder, const GLfloat * points)
    556556{
    557         map2(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder,
    558                          points, GL_FLOAT);
     557        map2(pState, target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points, GL_FLOAT);
    559558}
    560559
    561560
    562561void STATE_APIENTRY
    563 crStateMap2d(GLenum target, GLdouble u1, GLdouble u2,
     562crStateMap2d(PCRStateTracker pState, GLenum target, GLdouble u1, GLdouble u2,
    564563                                                 GLint ustride, GLint uorder,
    565564                                                 GLdouble v1, GLdouble v2,
    566565                                                 GLint vstride, GLint vorder, const GLdouble * points)
    567566{
    568         map2(target, (GLfloat) u1, (GLfloat) u2, ustride, uorder,
    569                          (GLfloat) v1, (GLfloat) v2, vstride, vorder, points, GL_DOUBLE);
     567        map2(pState, target, (GLfloat) u1, (GLfloat) u2, ustride, uorder, (GLfloat) v1, (GLfloat) v2, vstride, vorder, points, GL_DOUBLE);
    570568}
    571569
    572570void STATE_APIENTRY
    573 crStateGetMapdv(GLenum target, GLenum query, GLdouble * v)
    574 {
    575         CRContext *g = GetCurrentContext();
    576         CRStateBits *sb = GetCurrentBits();
     571crStateGetMapdv(PCRStateTracker pState, GLenum target, GLenum query, GLdouble * v)
     572{
     573        CRContext *g = GetCurrentContext(pState);
     574        CRStateBits *sb = GetCurrentBits(pState);
    577575        CREvaluatorState *e = &(g->eval);
    578576        GLint size;
     
    581579
    582580        if (g->current.inBeginEnd) {
    583                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     581                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    584582                                                                 "Map1d called in begin/end");
    585583                return;
     
    594592
    595593                if (i < 0 || i >= GLEVAL_TOT) {
    596                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     594                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    597595                                                                         "GetMapdv: invalid target: %d", target);
    598596                        return;
     
    617615                        break;
    618616                default:
    619                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     617                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    620618                                                                         "GetMapdv: invalid target: %d", target);
    621619                        return;
     
    638636                        break;
    639637                default:
    640                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     638                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    641639                                                                         "GetMapdv: invalid target: %d", target);
    642640                        return;
     
    646644
    647645void STATE_APIENTRY
    648 crStateGetMapfv(GLenum target, GLenum query, GLfloat * v)
    649 {
    650         CRContext *g = GetCurrentContext();
    651         CRStateBits *sb = GetCurrentBits();
     646crStateGetMapfv(PCRStateTracker pState, GLenum target, GLenum query, GLfloat * v)
     647{
     648        CRContext *g = GetCurrentContext(pState);
     649        CRStateBits *sb = GetCurrentBits(pState);
    652650        CREvaluatorState *e = &(g->eval);
    653651        GLint size;
     
    656654
    657655        if (g->current.inBeginEnd) {
    658                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     656                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    659657                                                                 "Map1d called in begin/end");
    660658                return;
     
    667665                i = target - GL_MAP2_COLOR_4;
    668666                if (i < 0 || i >= GLEVAL_TOT) {
    669                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     667                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    670668                                                                         "GetMapfv: invalid target: %d", target);
    671669                        return;
     
    689687                        break;
    690688                default:
    691                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     689                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    692690                                                                         "GetMapfv: invalid target: %d", target);
    693691                        return;
     
    710708                        break;
    711709                default:
    712                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     710                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    713711                                                                         "GetMapfv: invalid target: %d", target);
    714712                        return;
     
    718716
    719717void STATE_APIENTRY
    720 crStateGetMapiv(GLenum target, GLenum query, GLint * v)
    721 {
    722         CRContext *g = GetCurrentContext();
    723         CRStateBits *sb = GetCurrentBits();
     718crStateGetMapiv(PCRStateTracker pState, GLenum target, GLenum query, GLint * v)
     719{
     720        CRContext *g = GetCurrentContext(pState);
     721        CRStateBits *sb = GetCurrentBits(pState);
    724722        CREvaluatorState *e = &(g->eval);
    725723        GLint size;
     
    728726
    729727        if (g->current.inBeginEnd) {
    730                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     728                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    731729                                                                 "Map1d called in begin/end");
    732730                return;
     
    739737                i = target - GL_MAP2_COLOR_4;
    740738                if (i < 0 || i >= GLEVAL_TOT) {
    741                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     739                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    742740                                                                         "GetMapiv: invalid target: %d", target);
    743741                        return;
     
    761759                        break;
    762760                default:
    763                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     761                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    764762                                                                         "GetMapiv: invalid target: %d", target);
    765763                        return;
     
    782780                        break;
    783781                default:
    784                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     782                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    785783                                                                         "GetMapiv: invalid target: %d", target);
    786784                        return;
     
    790788
    791789void STATE_APIENTRY
    792 crStateMapGrid1f(GLint un, GLfloat u1, GLfloat u2)
    793 {
    794         CRContext *g = GetCurrentContext();
    795         CRStateBits *sb = GetCurrentBits();
     790crStateMapGrid1f(PCRStateTracker pState, GLint un, GLfloat u1, GLfloat u2)
     791{
     792        CRContext *g = GetCurrentContext(pState);
     793        CRStateBits *sb = GetCurrentBits(pState);
    796794        CREvaluatorState *e = &(g->eval);
    797795        CREvaluatorBits *eb = &(sb->eval);
    798796
    799797        if (g->current.inBeginEnd) {
    800                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     798                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    801799                                                                 "Map1d called in begin/end");
    802800                return;
     
    806804
    807805        if (un < 1) {
    808                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid1f(bad un)");
     806                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid1f(bad un)");
    809807                return;
    810808        }
     
    819817
    820818void STATE_APIENTRY
    821 crStateMapGrid1d(GLint un, GLdouble u1, GLdouble u2)
    822 {
    823         crStateMapGrid1f(un, (GLfloat) u1, (GLfloat) u2);
     819crStateMapGrid1d(PCRStateTracker pState, GLint un, GLdouble u1, GLdouble u2)
     820{
     821        crStateMapGrid1f(pState, un, (GLfloat) u1, (GLfloat) u2);
    824822}
    825823
    826824
    827825void STATE_APIENTRY
    828 crStateMapGrid2f(GLint un, GLfloat u1, GLfloat u2,
     826crStateMapGrid2f(PCRStateTracker pState, GLint un, GLfloat u1, GLfloat u2,
    829827                                                                 GLint vn, GLfloat v1, GLfloat v2)
    830828{
    831         CRContext *g = GetCurrentContext();
    832         CRStateBits *sb = GetCurrentBits();
     829        CRContext *g = GetCurrentContext(pState);
     830        CRStateBits *sb = GetCurrentBits(pState);
    833831        CREvaluatorState *e = &(g->eval);
    834832        CREvaluatorBits *eb = &(sb->eval);
    835833
    836834        if (g->current.inBeginEnd) {
    837                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     835                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    838836                                                                 "Map1d called in begin/end");
    839837                return;
     
    843841
    844842        if (un < 1) {
    845                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid2f(bad un)");
     843                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid2f(bad un)");
    846844                return;
    847845        }
    848846        if (vn < 1) {
    849                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid2f(bad vn)");
     847                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid2f(bad vn)");
    850848                return;
    851849        }
     
    863861
    864862void STATE_APIENTRY
    865 crStateMapGrid2d(GLint un, GLdouble u1, GLdouble u2,
     863crStateMapGrid2d(PCRStateTracker pState, GLint un, GLdouble u1, GLdouble u2,
    866864                                                                 GLint vn, GLdouble v1, GLdouble v2)
    867865{
    868         crStateMapGrid2f(un, (GLfloat) u1, (GLfloat) u2,
     866        crStateMapGrid2f(pState, un, (GLfloat) u1, (GLfloat) u2,
    869867                                                                         vn, (GLfloat) v1, (GLfloat) v2);
    870868}
     
    874872                                                                                         CRContext *fromCtx, CRContext *toCtx)
    875873{
     874    PCRStateTracker pState = fromCtx->pStateTracker;
    876875        CREvaluatorState *from = &(fromCtx->eval);
    877876        CREvaluatorState *to = &(toCtx->eval);
     
    879878        CRbitvalue nbitID[CR_MAX_BITARRAY];
    880879
     880    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     881
    881882        for (j = 0; j < CR_MAX_BITARRAY; j++)
    882883                nbitID[j] = ~bitID[j];
     
    885886                if (from->autoNormal != to->autoNormal) {
    886887                        glAble able[2];
    887                         able[0] = diff_api.Disable;
    888                         able[1] = diff_api.Enable;
     888                        able[0] = pState->diff_api.Disable;
     889                        able[1] = pState->diff_api.Enable;
    889890                        able[to->autoNormal] (GL_AUTO_NORMAL);
    890891                        FILLDIRTY(e->enable);
     
    902903                                crMemcmp((const void *) from->eval1D[i].coeff,
    903904                                                 (const void *) to->eval1D[i].coeff, size)) {
    904                                 diff_api.Map1f(i + GL_MAP1_COLOR_4, to->eval1D[i].u1,
    905                                                            to->eval1D[i].u2, gleval_sizes[i], to->eval1D[i].order,
    906                                                            to->eval1D[i].coeff);
     905                                pState->diff_api.Map1f(i + GL_MAP1_COLOR_4, to->eval1D[i].u1,
     906                                                                   to->eval1D[i].u2, gleval_sizes[i], to->eval1D[i].order,
     907                                                                   to->eval1D[i].coeff);
    907908                                FILLDIRTY(e->dirty);
    908909                                FILLDIRTY(e->eval1D[i]);
     
    924925                                crMemcmp((const void *) from->eval2D[i].coeff,
    925926                                                 (const void *) to->eval2D[i].coeff, size)) {
    926                                 diff_api.Map2f(i + GL_MAP2_COLOR_4,
    927                                                            to->eval2D[i].u1, to->eval2D[i].u2,
    928                                                            gleval_sizes[i], to->eval2D[i].uorder,
    929                                to->eval2D[i].v1, to->eval2D[i].v2,
    930                                gleval_sizes[i], to->eval2D[i].vorder,
    931                                to->eval2D[i].coeff);
     927                                pState->diff_api.Map2f(i + GL_MAP2_COLOR_4,
     928                                                                   to->eval2D[i].u1, to->eval2D[i].u2,
     929                                                                   gleval_sizes[i], to->eval2D[i].uorder,
     930                                       to->eval2D[i].v1, to->eval2D[i].v2,
     931                                       gleval_sizes[i], to->eval2D[i].vorder,
     932                                       to->eval2D[i].coeff);
    932933                                FILLDIRTY(e->dirty);
    933934                                FILLDIRTY(e->eval2D[i]);
     
    940941                                from->u21D != to->u21D ||
    941942                from->un1D != to->un1D) {
    942                         diff_api.MapGrid1d(to->un1D, to->u11D, to->u21D);
     943                        pState->diff_api.MapGrid1d(to->un1D, to->u11D, to->u21D);
    943944                        FILLDIRTY(e->dirty);
    944945                        FILLDIRTY(e->grid1D);
     
    953954                        from->v22D != to->v22D ||
    954955            from->vn2D != to->vn2D) {
    955                         diff_api.MapGrid2d(to->un2D, to->u12D, to->u22D,
    956                                                            to->vn2D, to->v12D, to->v22D);
     956                        pState->diff_api.MapGrid2d(to->un2D, to->u12D, to->u22D,
     957                                                                   to->vn2D, to->v12D, to->v22D);
    957958                        FILLDIRTY(e->dirty);
    958959                        FILLDIRTY(e->grid1D);
     
    967968                     CRContext *fromCtx, CRContext *toCtx)
    968969{
     970    PCRStateTracker pState = fromCtx->pStateTracker;
    969971        CREvaluatorState *from = &(fromCtx->eval);
    970972        CREvaluatorState *to = &(toCtx->eval);
     
    973975        CRbitvalue nbitID[CR_MAX_BITARRAY];
    974976
     977    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     978
    975979        for (j = 0; j < CR_MAX_BITARRAY; j++)
    976980                nbitID[j] = ~bitID[j];
    977981
    978         able[0] = diff_api.Disable;
    979         able[1] = diff_api.Enable;
     982        able[0] = pState->diff_api.Disable;
     983        able[1] = pState->diff_api.Enable;
    980984
    981985        if (CHECKDIRTY(e->enable, bitID)) {
     
    10021006                                crMemcmp((const void *) from->eval1D[i].coeff,
    10031007                                                 (const void *) to->eval1D[i].coeff, size)) {
    1004                                 diff_api.Map1f(i + GL_MAP1_COLOR_4, to->eval1D[i].u1,
    1005                                                            to->eval1D[i].u2, gleval_sizes[i], to->eval1D[i].order,
    1006                                                            to->eval1D[i].coeff);
     1008                                pState->diff_api.Map1f(i + GL_MAP1_COLOR_4, to->eval1D[i].u1,
     1009                                                                   to->eval1D[i].u2, gleval_sizes[i], to->eval1D[i].order,
     1010                                                                   to->eval1D[i].coeff);
    10071011                                from->eval1D[i].order = to->eval1D[i].order;
    10081012                                from->eval1D[i].u1    = to->eval1D[i].u1;
     
    10341038                                crMemcmp((const void *) from->eval2D[i].coeff,
    10351039                                                 (const void *) to->eval2D[i].coeff, size)) {
    1036                                 diff_api.Map2f(i + GL_MAP2_COLOR_4,
    1037                                                            to->eval2D[i].u1, to->eval2D[i].u2,
    1038                                gleval_sizes[i], to->eval2D[i].uorder,
    1039                                to->eval2D[i].v1, to->eval2D[i].v2,
    1040                                gleval_sizes[i], to->eval2D[i].vorder,
    1041                                to->eval2D[i].coeff);
     1040                                pState->diff_api.Map2f(i + GL_MAP2_COLOR_4,
     1041                                                                   to->eval2D[i].u1, to->eval2D[i].u2,
     1042                                       gleval_sizes[i], to->eval2D[i].uorder,
     1043                                       to->eval2D[i].v1, to->eval2D[i].v2,
     1044                                       gleval_sizes[i], to->eval2D[i].vorder,
     1045                                       to->eval2D[i].coeff);
    10421046                                from->eval2D[i].uorder = to->eval2D[i].uorder;
    10431047                                from->eval2D[i].vorder = to->eval2D[i].vorder;
     
    10561060                        from->u21D != to->u21D ||
    10571061            from->un1D != to->un1D) {
    1058                         diff_api.MapGrid1d(to->un1D, to->u11D, to->u21D);
     1062                        pState->diff_api.MapGrid1d(to->un1D, to->u11D, to->u21D);
    10591063                        from->u11D = to->u11D;
    10601064                        from->u21D = to->u21D;
     
    10701074                                from->v22D != to->v22D ||
    10711075                from->vn2D != to->vn2D) {
    1072                         diff_api.MapGrid2d(to->un2D, to->u12D, to->u22D,
    1073                                                            to->vn2D, to->v12D, to->v22D);
     1076                        pState->diff_api.MapGrid2d(to->un2D, to->u12D, to->u22D,
     1077                                                                   to->vn2D, to->v12D, to->v22D);
    10741078                        from->u12D = to->u12D;
    10751079                        from->u22D = to->u22D;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_feedback.c

    r69392 r78375  
    120120 */
    121121static GLuint
    122 clip_point(const CRVertex *v)
    123 {
    124         CRContext *g = GetCurrentContext();
     122clip_point(CRContext *g, const CRVertex *v)
     123{
    125124        GLuint mask = 0;
    126125        GLuint i;
     
    165164 */
    166165static GLboolean
    167 clip_line(const CRVertex *v0in, const CRVertex *v1in,
     166clip_line(CRContext *g, const CRVertex *v0in, const CRVertex *v1in,
    168167                                        CRVertex *v0new, CRVertex *v1new)
    169168{
     
    174173        /* XXX need to do user-clip planes */
    175174
    176         code0 = clip_point(v0in);
    177         code1 = clip_point(v1in);
     175        code0 = clip_point(g, v0in);
     176        code1 = clip_point(g, v1in);
    178177        if (code0 & code1)
    179178                return GL_FALSE;  /* totally clipped */
     
    462461 */
    463462static void
    464 feedback_vertex(const CRVertex *v)
    465 {
    466         CRContext *g = GetCurrentContext();
     463feedback_vertex(CRContext *g, const CRVertex *v)
     464{
    467465        CRFeedbackState *f = &(g->feedback);
    468466        CRTransformState *t = &(g->transform);
     
    514512
    515513static void
    516 feedback_rasterpos(void)
    517 {
    518         CRContext *g = GetCurrentContext();
     514feedback_rasterpos(CRContext *g)
     515{
    519516        CRVertex *tv = g->vBuffer + g->vCount;
    520517        CRVertex v;
     
    535532        COPY_4V(v.attrib[VERT_ATTRIB_TEX0] , tv->attrib[VERT_ATTRIB_TEX0]);
    536533
    537         feedback_vertex(&v);
     534        feedback_vertex(g, &v);
    538535}
    539536
    540537
    541538static void
    542 feedback_point(const CRVertex *v)
    543 {
    544         CRContext *g = GetCurrentContext();
     539feedback_point(CRContext *g, const CRVertex *v)
     540{
    545541        CRFeedbackState *f = &(g->feedback);
    546         if (clip_point(v) == 0)
     542        if (clip_point(g, v) == 0)
    547543        {
    548544                CRVertex c = *v;
    549545                MAP_POINT(c.winPos, c.clipPos, g->viewport);
    550546                FEEDBACK_TOKEN((GLfloat) GL_POINT_TOKEN);
    551                 feedback_vertex(&c);
     547                feedback_vertex(g, &c);
    552548        }
    553549}
     
    555551
    556552static void
    557 feedback_line(const CRVertex *v0, const CRVertex *v1, GLboolean reset)
    558 {
    559         CRContext *g = GetCurrentContext();
     553feedback_line(CRContext *g, const CRVertex *v0, const CRVertex *v1, GLboolean reset)
     554{
    560555        CRFeedbackState *f = &(g->feedback);
    561556        CRVertex c0, c1;
    562         if (clip_line(v0, v1, &c0, &c1))
     557        if (clip_line(g, v0, v1, &c0, &c1))
    563558        {
    564559                MAP_POINT(c0.winPos, c0.clipPos, g->viewport);
     
    568563                else
    569564                        FEEDBACK_TOKEN((GLfloat) GL_LINE_TOKEN);
    570                 feedback_vertex(&c0);
    571                 feedback_vertex(&c1);
     565                feedback_vertex(g, &c0);
     566                feedback_vertex(g, &c1);
    572567        }
    573568}
     
    575570
    576571static void
    577 feedback_triangle(const CRVertex *v0, const CRVertex *v1, const CRVertex *v2)
    578 {
    579         CRContext *g = GetCurrentContext();
     572feedback_triangle(CRContext *g, const CRVertex *v0, const CRVertex *v1, const CRVertex *v2)
     573{
    580574        CRFeedbackState *f = &(g->feedback);
    581575        CRVertex vlist[3], vclipped[8];
     
    590584        for (i = 0; i < n; i++) {
    591585                MAP_POINT(vclipped[i].winPos, vclipped[i].clipPos, g->viewport);
    592                 feedback_vertex(vclipped + i);
    593         }
    594 }
    595 
    596 
    597 void STATE_APIENTRY
    598 crStateFeedbackVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    599 {
    600         CRContext *g = GetCurrentContext();
     586                feedback_vertex(g, vclipped + i);
     587        }
     588}
     589
     590
     591void STATE_APIENTRY
     592crStateFeedbackVertex4f(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
     593{
     594        CRContext *g = GetCurrentContext(pState);
    601595        CRTransformState *t = &(g->transform);
    602596        CRPolygonState *p = &(g->polygon);
     
    621615        case GL_POINTS:
    622616                CRASSERT(g->vCount == 0);
    623                 feedback_point(v);
     617                feedback_point(g, v);
    624618                break;
    625619        case GL_LINES:
     
    631625                {
    632626                        CRASSERT(g->vCount == 1);
    633                         feedback_line(g->vBuffer + 0, g->vBuffer + 1, g->lineReset);
     627                        feedback_line(g, g->vBuffer + 0, g->vBuffer + 1, g->lineReset);
    634628                        g->vCount = 0;
    635629                }
     
    643637                {
    644638                        CRASSERT(g->vCount == 1);
    645                         feedback_line(g->vBuffer + 0, g->vBuffer + 1, g->lineReset);
     639                        feedback_line(g, g->vBuffer + 0, g->vBuffer + 1, g->lineReset);
    646640                        g->vBuffer[0] = g->vBuffer[1];
    647641                        g->lineReset = GL_FALSE;
     
    657651                else if (g->vCount == 1)
    658652                {
    659                         feedback_line(g->vBuffer + 0, g->vBuffer + 1, g->lineReset);
     653                        feedback_line(g, g->vBuffer + 0, g->vBuffer + 1, g->lineReset);
    660654                        g->lineReset = GL_FALSE;
    661655                        g->lineLoop = GL_TRUE;
     
    667661                        CRASSERT(g->lineReset == GL_FALSE);
    668662                        g->lineLoop = GL_FALSE;
    669                         feedback_line(g->vBuffer + 1, g->vBuffer + 2, g->lineReset);
     663                        feedback_line(g, g->vBuffer + 1, g->vBuffer + 2, g->lineReset);
    670664                        g->vBuffer[1] = g->vBuffer[2];
    671665                        /* leave g->vCount at 2 */
     
    680674                {
    681675                        CRASSERT(g->vCount == 2);
    682                         feedback_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     676                        feedback_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    683677                        g->vCount = 0;
    684678                }
     
    691685                else if (g->vCount == 2)
    692686                {
    693                         feedback_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     687                        feedback_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    694688                        g->vCount = 3;
    695689                }
     
    697691                {
    698692                        CRASSERT(g->vCount == 3);
    699                         feedback_triangle(g->vBuffer + 1, g->vBuffer + 3, g->vBuffer + 2);
     693                        feedback_triangle(g, g->vBuffer + 1, g->vBuffer + 3, g->vBuffer + 2);
    700694                        g->vBuffer[0] = g->vBuffer[2];
    701695                        g->vBuffer[1] = g->vBuffer[3];
     
    711705                {
    712706                        CRASSERT(g->vCount == 2);
    713                         feedback_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     707                        feedback_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    714708                        g->vBuffer[1] = g->vBuffer[2];
    715709                        /* leave g->vCount = 2 */
     
    724718                {
    725719                        CRASSERT(g->vCount == 3);
    726                         feedback_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    727                         feedback_triangle(g->vBuffer + 0, g->vBuffer + 2, g->vBuffer + 3);
     720                        feedback_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     721                        feedback_triangle(g, g->vBuffer + 0, g->vBuffer + 2, g->vBuffer + 3);
    728722                        g->vCount = 0;
    729723                }
     
    737731                {
    738732                        CRASSERT(g->vCount == 3);
    739                         feedback_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    740                         feedback_triangle(g->vBuffer + 1, g->vBuffer + 3, g->vBuffer + 2);
     733                        feedback_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     734                        feedback_triangle(g, g->vBuffer + 1, g->vBuffer + 3, g->vBuffer + 2);
    741735                        g->vBuffer[0] = g->vBuffer[2];
    742736                        g->vBuffer[1] = g->vBuffer[3];
     
    749743                case GL_POINT:
    750744                        CRASSERT(g->vCount == 0);
    751                         feedback_point(v);
     745                        feedback_point(g, v);
    752746                        break;
    753747                case GL_LINE:
     
    759753                        else if (g->vCount == 1)
    760754                        {
    761                                 feedback_line(g->vBuffer + 0, g->vBuffer + 1, g->lineReset);
     755                                feedback_line(g, g->vBuffer + 0, g->vBuffer + 1, g->lineReset);
    762756                                g->lineReset = GL_FALSE;
    763757                                g->lineLoop = GL_TRUE;
     
    769763                                CRASSERT(g->lineReset == GL_FALSE);
    770764                                g->lineLoop = GL_FALSE;
    771                                 feedback_line(g->vBuffer + 1, g->vBuffer + 2, g->lineReset);
     765                                feedback_line(g, g->vBuffer + 1, g->vBuffer + 2, g->lineReset);
    772766                                g->vBuffer[1] = g->vBuffer[2];
    773767                                /* leave g->vCount at 2 */
     
    783777                        {
    784778                                CRASSERT(g->vCount == 2);
    785                                 feedback_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     779                                feedback_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    786780                                g->vBuffer[1] = g->vBuffer[2];
    787781                                /* leave g->vCount = 2 */
     
    799793
    800794void STATE_APIENTRY
    801 crStateFeedbackBegin(GLenum mode)
    802 {
    803         CRContext *g = GetCurrentContext();
    804 
    805         crStateBegin(mode);
     795crStateFeedbackBegin(PCRStateTracker pState, GLenum mode)
     796{
     797        CRContext *g = GetCurrentContext(pState);
     798
     799        crStateBegin(pState, mode);
    806800
    807801        g->vCount = 0;
     
    812806
    813807void STATE_APIENTRY
    814 crStateFeedbackEnd(void)
    815 {
    816         CRContext *g = GetCurrentContext();
     808crStateFeedbackEnd(PCRStateTracker pState)
     809{
     810        CRContext *g = GetCurrentContext(pState);
    817811
    818812        if ( (g->current.mode == GL_LINE_LOOP ||
     
    822816                /* draw the last line segment */
    823817                if (g->lineLoop)
    824                         feedback_line(g->vBuffer + 1, g->vBuffer + 0, GL_FALSE);
     818                        feedback_line(g, g->vBuffer + 1, g->vBuffer + 0, GL_FALSE);
    825819                else
    826                         feedback_line(g->vBuffer + 2, g->vBuffer + 0, GL_FALSE);
    827         }
    828 
    829         crStateEnd();
    830 }
    831 
    832 
    833 void STATE_APIENTRY
    834 crStateFeedbackBuffer(GLsizei size, GLenum type, GLfloat * buffer)
    835 {
    836         CRContext *g = GetCurrentContext();
     820                        feedback_line(g, g->vBuffer + 2, g->vBuffer + 0, GL_FALSE);
     821        }
     822
     823        crStateEnd(pState);
     824}
     825
     826
     827void STATE_APIENTRY
     828crStateFeedbackBuffer(PCRStateTracker pState, GLsizei size, GLenum type, GLfloat * buffer)
     829{
     830        CRContext *g = GetCurrentContext(pState);
    837831        CRFeedbackState *f = &(g->feedback);
    838832
    839833        if (g->current.inBeginEnd)
    840834        {
    841                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     835                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    842836                                                                 "FeedbackBuffer called in begin/end");
    843837                return;
     
    846840        if (g->renderMode == GL_FEEDBACK)
    847841        {
    848                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     842                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    849843                                                                 "Invalid Operation GL_FEEDBACK");
    850844                return;
     
    852846        if (size < 0)
    853847        {
    854                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     848                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    855849                                                                 "Invalid Value size < 0");
    856850                return;
     
    858852        if (!buffer)
    859853        {
    860                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     854                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    861855                                                                 "Invalid Value buffer = NULL");
    862856                f->bufferSize = 0;
     
    884878                break;
    885879        default:
    886                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "invalid type");
     880                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "invalid type");
    887881                return;
    888882        }
     
    896890
    897891void STATE_APIENTRY
    898 crStatePassThrough(GLfloat token)
    899 {
    900         CRContext *g = GetCurrentContext();
     892crStatePassThrough(PCRStateTracker pState, GLfloat token)
     893{
     894        CRContext *g = GetCurrentContext(pState);
    901895        CRFeedbackState *f = &(g->feedback);
    902896
    903897        if (g->current.inBeginEnd)
    904898        {
    905                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     899                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    906900                                                                 "PassThrough called in begin/end");
    907901                return;
     
    923917 */
    924918void STATE_APIENTRY
    925 crStateFeedbackGetBooleanv(GLenum pname, GLboolean * params)
    926 {
    927         CRContext *g = GetCurrentContext();
     919crStateFeedbackGetBooleanv(PCRStateTracker pState, GLenum pname, GLboolean * params)
     920{
     921        CRContext *g = GetCurrentContext(pState);
    928922
    929923        switch (pname)
     
    946940
    947941void STATE_APIENTRY
    948 crStateFeedbackGetDoublev(GLenum pname, GLdouble * params)
    949 {
    950         CRContext *g = GetCurrentContext();
     942crStateFeedbackGetDoublev(PCRStateTracker pState, GLenum pname, GLdouble * params)
     943{
     944        CRContext *g = GetCurrentContext(pState);
    951945
    952946        switch (pname)
     
    969963
    970964void STATE_APIENTRY
    971 crStateFeedbackGetFloatv(GLenum pname, GLfloat * params)
    972 {
    973         CRContext *g = GetCurrentContext();
     965crStateFeedbackGetFloatv(PCRStateTracker pState, GLenum pname, GLfloat * params)
     966{
     967        CRContext *g = GetCurrentContext(pState);
    974968
    975969        switch (pname)
     
    992986
    993987void STATE_APIENTRY
    994 crStateFeedbackGetIntegerv(GLenum pname, GLint * params)
    995 {
    996         CRContext *g = GetCurrentContext();
     988crStateFeedbackGetIntegerv(PCRStateTracker pState, GLenum pname, GLint * params)
     989{
     990        CRContext *g = GetCurrentContext(pState);
    997991
    998992        switch (pname)
     
    10151009
    10161010void STATE_APIENTRY
    1017 crStateFeedbackDrawPixels(GLsizei width, GLsizei height, GLenum format,
     1011crStateFeedbackDrawPixels(PCRStateTracker pState, GLsizei width, GLsizei height, GLenum format,
    10181012                                                                                                        GLenum type, const GLvoid * pixels)
    10191013{
    1020         CRContext *g = GetCurrentContext();
     1014        CRContext *g = GetCurrentContext(pState);
    10211015        CRFeedbackState *f = &(g->feedback);
    10221016
     
    10291023        FEEDBACK_TOKEN((GLfloat) (GLint) GL_DRAW_PIXEL_TOKEN);
    10301024
    1031         feedback_rasterpos();
    1032 }
    1033 
    1034 void STATE_APIENTRY
    1035 crStateFeedbackCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height,
     1025        feedback_rasterpos(g);
     1026}
     1027
     1028void STATE_APIENTRY
     1029crStateFeedbackCopyPixels(PCRStateTracker pState, GLint x, GLint y, GLsizei width, GLsizei height,
    10361030                                                                                                        GLenum type)
    10371031{
    1038         CRContext *g = GetCurrentContext();
     1032        CRContext *g = GetCurrentContext(pState);
    10391033        CRFeedbackState *f = &(g->feedback);
    10401034
     
    10461040
    10471041        FEEDBACK_TOKEN((GLfloat) (GLint) GL_COPY_PIXEL_TOKEN);
    1048         feedback_rasterpos();
    1049 }
    1050 
    1051 void STATE_APIENTRY
    1052 crStateFeedbackBitmap(GLsizei width, GLsizei height, GLfloat xorig,
     1042        feedback_rasterpos(g);
     1043}
     1044
     1045void STATE_APIENTRY
     1046crStateFeedbackBitmap(PCRStateTracker pState, GLsizei width, GLsizei height, GLfloat xorig,
    10531047                                                                                        GLfloat yorig, GLfloat xmove, GLfloat ymove,
    10541048                                                                                        const GLubyte * bitmap)
    10551049{
    1056         CRContext *g = GetCurrentContext();
     1050        CRContext *g = GetCurrentContext(pState);
    10571051        CRFeedbackState *f = &(g->feedback);
    10581052
     
    10651059        FEEDBACK_TOKEN((GLfloat) (GLint) GL_BITMAP_TOKEN);
    10661060
    1067         feedback_rasterpos();
     1061        feedback_rasterpos(g);
    10681062
    10691063        if (g->current.rasterValid)
     
    10761070
    10771071void STATE_APIENTRY
    1078 crStateFeedbackVertex4fv(const GLfloat * v)
    1079 {
    1080         crStateFeedbackVertex4f(v[0], v[1], v[2], v[3]);
    1081 }
    1082 
    1083 void STATE_APIENTRY
    1084 crStateFeedbackVertex4s(GLshort v0, GLshort v1, GLshort v2, GLshort v3)
    1085 {
    1086         crStateFeedbackVertex4f((GLfloat) v0, (GLfloat) v1, (GLfloat) v2,
     1072crStateFeedbackVertex4fv(PCRStateTracker pState, const GLfloat * v)
     1073{
     1074        crStateFeedbackVertex4f(pState, v[0], v[1], v[2], v[3]);
     1075}
     1076
     1077void STATE_APIENTRY
     1078crStateFeedbackVertex4s(PCRStateTracker pState, GLshort v0, GLshort v1, GLshort v2, GLshort v3)
     1079{
     1080        crStateFeedbackVertex4f(pState, (GLfloat) v0, (GLfloat) v1, (GLfloat) v2,
    10871081                                                                                                        (GLfloat) v3);
    10881082}
    10891083
    10901084void STATE_APIENTRY
    1091 crStateFeedbackVertex4sv(const GLshort * v)
    1092 {
    1093         crStateFeedbackVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2],
     1085crStateFeedbackVertex4sv(PCRStateTracker pState, const GLshort * v)
     1086{
     1087        crStateFeedbackVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2],
    10941088                                                                                                        (GLfloat) v[3]);
    10951089}
    10961090
    10971091void STATE_APIENTRY
    1098 crStateFeedbackVertex4i(GLint v0, GLint v1, GLint v2, GLint v3)
    1099 {
    1100         crStateFeedbackVertex4f((GLfloat) v0, (GLfloat) v1, (GLfloat) v2,
     1092crStateFeedbackVertex4i(PCRStateTracker pState, GLint v0, GLint v1, GLint v2, GLint v3)
     1093{
     1094        crStateFeedbackVertex4f(pState, (GLfloat) v0, (GLfloat) v1, (GLfloat) v2,
    11011095                                                                                                        (GLfloat) v3);
    11021096}
    11031097
    11041098void STATE_APIENTRY
    1105 crStateFeedbackVertex4iv(const GLint * v)
    1106 {
    1107         crStateFeedbackVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2],
     1099crStateFeedbackVertex4iv(PCRStateTracker pState, const GLint * v)
     1100{
     1101        crStateFeedbackVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2],
    11081102                                                                                                        (GLfloat) v[3]);
    11091103}
    11101104
    11111105void STATE_APIENTRY
    1112 crStateFeedbackVertex4d(GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3)
    1113 {
    1114         crStateFeedbackVertex4f((GLfloat) v0, (GLfloat) v1, (GLfloat) v2,
     1106crStateFeedbackVertex4d(PCRStateTracker pState, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3)
     1107{
     1108        crStateFeedbackVertex4f(pState, (GLfloat) v0, (GLfloat) v1, (GLfloat) v2,
    11151109                                                                                                        (GLfloat) v3);
    11161110}
    11171111
    11181112void STATE_APIENTRY
    1119 crStateFeedbackVertex4dv(const GLdouble * v)
    1120 {
    1121         crStateFeedbackVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2],
     1113crStateFeedbackVertex4dv(PCRStateTracker pState, const GLdouble * v)
     1114{
     1115        crStateFeedbackVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2],
    11221116                                                                                                        (GLfloat) v[3]);
    11231117}
    11241118
    11251119void STATE_APIENTRY
    1126 crStateFeedbackVertex2i(GLint v0, GLint v1)
    1127 {
    1128         crStateFeedbackVertex4f((GLfloat) v0, (GLfloat) v1, 0.0f, 1.0f);
    1129 }
    1130 
    1131 void STATE_APIENTRY
    1132 crStateFeedbackVertex2iv(const GLint * v)
    1133 {
    1134         crStateFeedbackVertex4f((GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
    1135 }
    1136 
    1137 void STATE_APIENTRY
    1138 crStateFeedbackVertex2s(GLshort v0, GLshort v1)
    1139 {
    1140         crStateFeedbackVertex4f((GLfloat) v0, (GLfloat) v1, 0.0f, 1.0f);
    1141 }
    1142 
    1143 void STATE_APIENTRY
    1144 crStateFeedbackVertex2sv(const GLshort * v)
    1145 {
    1146         crStateFeedbackVertex4f((GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
    1147 }
    1148 
    1149 void STATE_APIENTRY
    1150 crStateFeedbackVertex2f(GLfloat v0, GLfloat v1)
    1151 {
    1152         crStateFeedbackVertex4f(v0, v1, 0.0f, 1.0f);
    1153 }
    1154 
    1155 void STATE_APIENTRY
    1156 crStateFeedbackVertex2fv(const GLfloat * v)
    1157 {
    1158         crStateFeedbackVertex4f(v[0], v[1], 0.0f, 1.0f);
    1159 }
    1160 
    1161 void STATE_APIENTRY
    1162 crStateFeedbackVertex2d(GLdouble v0, GLdouble v1)
    1163 {
    1164         crStateFeedbackVertex4f((GLfloat) v0, (GLfloat) v1, 0.0f, 1.0f);
    1165 }
    1166 
    1167 void STATE_APIENTRY
    1168 crStateFeedbackVertex2dv(const GLdouble * v)
    1169 {
    1170         crStateFeedbackVertex4f((GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
    1171 }
    1172 
    1173 void STATE_APIENTRY
    1174 crStateFeedbackVertex3i(GLint v0, GLint v1, GLint v2)
    1175 {
    1176         crStateFeedbackVertex4f((GLfloat) v0, (GLfloat) v1, (GLfloat) v2, 1.0f);
    1177 }
    1178 
    1179 void STATE_APIENTRY
    1180 crStateFeedbackVertex3iv(const GLint * v)
    1181 {
    1182         crStateFeedbackVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
    1183 }
    1184 
    1185 void STATE_APIENTRY
    1186 crStateFeedbackVertex3s(GLshort v0, GLshort v1, GLshort v2)
    1187 {
    1188         crStateFeedbackVertex4f((GLfloat) v0, (GLfloat) v1, (GLfloat) v2, 1.0f);
    1189 }
    1190 
    1191 void STATE_APIENTRY
    1192 crStateFeedbackVertex3sv(const GLshort * v)
    1193 {
    1194         crStateFeedbackVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2],
     1120crStateFeedbackVertex2i(PCRStateTracker pState, GLint v0, GLint v1)
     1121{
     1122        crStateFeedbackVertex4f(pState, (GLfloat) v0, (GLfloat) v1, 0.0f, 1.0f);
     1123}
     1124
     1125void STATE_APIENTRY
     1126crStateFeedbackVertex2iv(PCRStateTracker pState, const GLint * v)
     1127{
     1128        crStateFeedbackVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
     1129}
     1130
     1131void STATE_APIENTRY
     1132crStateFeedbackVertex2s(PCRStateTracker pState, GLshort v0, GLshort v1)
     1133{
     1134        crStateFeedbackVertex4f(pState, (GLfloat) v0, (GLfloat) v1, 0.0f, 1.0f);
     1135}
     1136
     1137void STATE_APIENTRY
     1138crStateFeedbackVertex2sv(PCRStateTracker pState, const GLshort * v)
     1139{
     1140        crStateFeedbackVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
     1141}
     1142
     1143void STATE_APIENTRY
     1144crStateFeedbackVertex2f(PCRStateTracker pState, GLfloat v0, GLfloat v1)
     1145{
     1146        crStateFeedbackVertex4f(pState, v0, v1, 0.0f, 1.0f);
     1147}
     1148
     1149void STATE_APIENTRY
     1150crStateFeedbackVertex2fv(PCRStateTracker pState, const GLfloat * v)
     1151{
     1152        crStateFeedbackVertex4f(pState, v[0], v[1], 0.0f, 1.0f);
     1153}
     1154
     1155void STATE_APIENTRY
     1156crStateFeedbackVertex2d(PCRStateTracker pState, GLdouble v0, GLdouble v1)
     1157{
     1158        crStateFeedbackVertex4f(pState, (GLfloat) v0, (GLfloat) v1, 0.0f, 1.0f);
     1159}
     1160
     1161void STATE_APIENTRY
     1162crStateFeedbackVertex2dv(PCRStateTracker pState, const GLdouble * v)
     1163{
     1164        crStateFeedbackVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
     1165}
     1166
     1167void STATE_APIENTRY
     1168crStateFeedbackVertex3i(PCRStateTracker pState, GLint v0, GLint v1, GLint v2)
     1169{
     1170        crStateFeedbackVertex4f(pState, (GLfloat) v0, (GLfloat) v1, (GLfloat) v2, 1.0f);
     1171}
     1172
     1173void STATE_APIENTRY
     1174crStateFeedbackVertex3iv(PCRStateTracker pState, const GLint * v)
     1175{
     1176        crStateFeedbackVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
     1177}
     1178
     1179void STATE_APIENTRY
     1180crStateFeedbackVertex3s(PCRStateTracker pState, GLshort v0, GLshort v1, GLshort v2)
     1181{
     1182        crStateFeedbackVertex4f(pState, (GLfloat) v0, (GLfloat) v1, (GLfloat) v2, 1.0f);
     1183}
     1184
     1185void STATE_APIENTRY
     1186crStateFeedbackVertex3sv(PCRStateTracker pState, const GLshort * v)
     1187{
     1188        crStateFeedbackVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2],
    11951189                                                                                                        1.0f);
    11961190}
    11971191
    11981192void STATE_APIENTRY
    1199 crStateFeedbackVertex3f(GLfloat v0, GLfloat v1, GLfloat v2)
    1200 {
    1201         crStateFeedbackVertex4f(v0, v1, v2, 1.0f);
    1202 }
    1203 
    1204 void STATE_APIENTRY
    1205 crStateFeedbackVertex3fv(const GLfloat * v)
    1206 {
    1207         crStateFeedbackVertex4f(v[0], v[1], v[2], 1.0f);
    1208 }
    1209 
    1210 void STATE_APIENTRY
    1211 crStateFeedbackVertex3d(GLdouble v0, GLdouble v1, GLdouble v2)
    1212 {
    1213         crStateFeedbackVertex4f((GLfloat) v0, (GLfloat) v1, (GLfloat) v2, 1.0f);
    1214 }
    1215 
    1216 void STATE_APIENTRY
    1217 crStateFeedbackVertex3dv(const GLdouble * v)
    1218 {
    1219         crStateFeedbackVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2],
     1193crStateFeedbackVertex3f(PCRStateTracker pState, GLfloat v0, GLfloat v1, GLfloat v2)
     1194{
     1195        crStateFeedbackVertex4f(pState, v0, v1, v2, 1.0f);
     1196}
     1197
     1198void STATE_APIENTRY
     1199crStateFeedbackVertex3fv(PCRStateTracker pState, const GLfloat * v)
     1200{
     1201        crStateFeedbackVertex4f(pState, v[0], v[1], v[2], 1.0f);
     1202}
     1203
     1204void STATE_APIENTRY
     1205crStateFeedbackVertex3d(PCRStateTracker pState, GLdouble v0, GLdouble v1, GLdouble v2)
     1206{
     1207        crStateFeedbackVertex4f(pState, (GLfloat) v0, (GLfloat) v1, (GLfloat) v2, 1.0f);
     1208}
     1209
     1210void STATE_APIENTRY
     1211crStateFeedbackVertex3dv(PCRStateTracker pState, const GLdouble * v)
     1212{
     1213        crStateFeedbackVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2],
    12201214                                                                                                        1.0f);
    12211215}
    12221216
    12231217void STATE_APIENTRY
    1224 crStateFeedbackTexCoord4f( GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3 )
    1225 {
    1226         CRContext *g = GetCurrentContext();
     1218crStateFeedbackTexCoord4f(PCRStateTracker pState, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3 )
     1219{
     1220        CRContext *g = GetCurrentContext(pState);
    12271221        CRVertex *v = g->vBuffer + g->vCount;
    12281222
     
    12351229 
    12361230void STATE_APIENTRY
    1237 crStateFeedbackTexCoord4fv( const GLfloat *v )
    1238 {
    1239         crStateFeedbackTexCoord4f( v[0], v[1], v[2], v[3] );
    1240 }
    1241 
    1242 void STATE_APIENTRY
    1243 crStateFeedbackTexCoord4s( GLshort v0, GLshort v1, GLshort v2, GLshort v3 )
    1244 {
    1245         crStateFeedbackTexCoord4f( (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, (GLfloat)v3 );
    1246 }
    1247 
    1248 void STATE_APIENTRY
    1249 crStateFeedbackTexCoord4sv( const GLshort *v )
    1250 {
    1251         crStateFeedbackTexCoord4f( (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3] );
    1252 }
    1253 
    1254 void STATE_APIENTRY
    1255 crStateFeedbackTexCoord4i( GLint v0, GLint v1, GLint v2, GLint v3 )
    1256 {
    1257         crStateFeedbackTexCoord4f( (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, (GLfloat)v3 );
    1258 }
    1259 
    1260 void STATE_APIENTRY
    1261 crStateFeedbackTexCoord4iv( const GLint *v )
    1262 {
    1263         crStateFeedbackTexCoord4f( (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3] );
    1264 }
    1265 
    1266 void STATE_APIENTRY
    1267 crStateFeedbackTexCoord4d( GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3 )
    1268 {
    1269         crStateFeedbackTexCoord4f( (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, (GLfloat)v3 );
    1270 }
    1271 
    1272 void STATE_APIENTRY
    1273 crStateFeedbackTexCoord4dv( const GLdouble *v )
    1274 {
    1275         crStateFeedbackTexCoord4f( (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3] );
    1276 }
    1277 
    1278 void STATE_APIENTRY
    1279 crStateFeedbackTexCoord1i( GLint v0 )
    1280 {
    1281         crStateFeedbackTexCoord4f( (GLfloat)v0, 0.0f, 0.0f, 1.0f );
    1282 }
    1283 
    1284 void STATE_APIENTRY
    1285 crStateFeedbackTexCoord1iv( const GLint *v )
    1286 {
    1287         crStateFeedbackTexCoord4f( (GLfloat)v[0], 0.0f, 0.0f, 1.0f );
    1288 }
    1289 
    1290 void STATE_APIENTRY
    1291 crStateFeedbackTexCoord1s( GLshort v0 )
    1292 {
    1293         crStateFeedbackTexCoord4f( (GLfloat)v0, 0.0f, 0.0f, 1.0f );
    1294 }
    1295 
    1296 void STATE_APIENTRY
    1297 crStateFeedbackTexCoord1sv( const GLshort *v )
    1298 {
    1299         crStateFeedbackTexCoord4f( (GLfloat)v[0], 0.0f, 0.0f, 1.0f );
    1300 }
    1301 
    1302 void STATE_APIENTRY
    1303 crStateFeedbackTexCoord1f( GLfloat v0 )
    1304 {
    1305         crStateFeedbackTexCoord4f( v0, 0.0f, 0.0f, 1.0f );
    1306 }
    1307 
    1308 void STATE_APIENTRY
    1309 crStateFeedbackTexCoord1fv( const GLfloat *v )
    1310 {
    1311         crStateFeedbackTexCoord4f( v[0], 0.0f, 0.0f, 1.0f );
    1312 }
    1313 
    1314 void STATE_APIENTRY
    1315 crStateFeedbackTexCoord1d( GLdouble v0 )
    1316 {
    1317         crStateFeedbackTexCoord4f( (GLfloat)v0, 0.0f, 0.0f, 1.0f );
    1318 }
    1319 
    1320 void STATE_APIENTRY
    1321 crStateFeedbackTexCoord1dv( const GLdouble *v )
    1322 {
    1323         crStateFeedbackTexCoord4f( (GLfloat)v[0], 0.0f, 0.0f, 1.0f );
    1324 }
    1325 
    1326 void STATE_APIENTRY
    1327 crStateFeedbackTexCoord2i( GLint v0, GLint v1 )
    1328 {
    1329         crStateFeedbackTexCoord4f( (GLfloat)v0, (GLfloat)v1, 0.0f, 1.0f );
    1330 }
    1331 
    1332 void STATE_APIENTRY
    1333 crStateFeedbackTexCoord2iv( const GLint *v )
    1334 {
    1335         crStateFeedbackTexCoord4f( (GLfloat)v[0], (GLfloat)v[1], 0.0f, 1.0f );
    1336 }
    1337 
    1338 void STATE_APIENTRY
    1339 crStateFeedbackTexCoord2s( GLshort v0, GLshort v1 )
    1340 {
    1341         crStateFeedbackTexCoord4f( (GLfloat)v0, (GLfloat)v1, 0.0f, 1.0f );
    1342 }
    1343 
    1344 void STATE_APIENTRY
    1345 crStateFeedbackTexCoord2sv( const GLshort *v )
    1346 {
    1347         crStateFeedbackTexCoord4f( (GLfloat)v[0], (GLfloat)v[1], 0.0f, 1.0f );
    1348 }
    1349 
    1350 void STATE_APIENTRY
    1351 crStateFeedbackTexCoord2f( GLfloat v0, GLfloat v1 )
    1352 {
    1353         crStateFeedbackTexCoord4f( v0, v1, 0.0f, 1.0f );
    1354 }
    1355 
    1356 void STATE_APIENTRY
    1357 crStateFeedbackTexCoord2fv( const GLfloat *v )
    1358 {
    1359         crStateFeedbackTexCoord4f( v[0], v[1], 0.0f, 1.0f );
    1360 }
    1361 
    1362 void STATE_APIENTRY
    1363 crStateFeedbackTexCoord2d( GLdouble v0, GLdouble v1 )
    1364 {
    1365         crStateFeedbackTexCoord4f( (GLfloat)v0, (GLfloat)v1, 0.0f, 1.0f );
    1366 }
    1367 
    1368 void STATE_APIENTRY
    1369 crStateFeedbackTexCoord2dv( const GLdouble *v )
    1370 {
    1371         crStateFeedbackTexCoord4f( (GLfloat)v[0], (GLfloat)v[1], 0.0f, 1.0f );
    1372 }
    1373 
    1374 void STATE_APIENTRY
    1375 crStateFeedbackTexCoord3i( GLint v0, GLint v1, GLint v2 )
    1376 {
    1377         crStateFeedbackTexCoord4f( (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, 1.0f );
    1378 }
    1379 
    1380 void STATE_APIENTRY
    1381 crStateFeedbackTexCoord3iv( const GLint *v )
    1382 {
    1383         crStateFeedbackTexCoord4f( (GLfloat)v[0], (GLfloat)v[1], 0.0f, 1.0f );
    1384 }
    1385 
    1386 void STATE_APIENTRY
    1387 crStateFeedbackTexCoord3s( GLshort v0, GLshort v1, GLshort v2 )
    1388 {
    1389         crStateFeedbackTexCoord4f( (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, 1.0f );
    1390 }
    1391 
    1392 void STATE_APIENTRY
    1393 crStateFeedbackTexCoord3sv( const GLshort *v )
    1394 {
    1395         crStateFeedbackTexCoord4f( (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], 1.0f );
    1396 }
    1397 
    1398 void STATE_APIENTRY
    1399 crStateFeedbackTexCoord3f( GLfloat v0, GLfloat v1, GLfloat v2 )
    1400 {
    1401         crStateFeedbackTexCoord4f( v0, v1, v2, 1.0f );
    1402 }
    1403 
    1404 void STATE_APIENTRY
    1405 crStateFeedbackTexCoord3fv( const GLfloat *v )
    1406 {
    1407         crStateFeedbackTexCoord4f( v[0], v[1], v[2], 1.0f );
    1408 }
    1409 
    1410 void STATE_APIENTRY
    1411 crStateFeedbackTexCoord3d( GLdouble v0, GLdouble v1, GLdouble v2 )
    1412 {
    1413         crStateFeedbackTexCoord4f( (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, 1.0f );
    1414 }
    1415 
    1416 void STATE_APIENTRY
    1417 crStateFeedbackTexCoord3dv( const GLdouble *v )
    1418 {
    1419         crStateFeedbackTexCoord4f( (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], 1.0f );
    1420 }
    1421 
    1422 void STATE_APIENTRY
    1423 crStateFeedbackRectf(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1)
    1424 {
    1425    crStateFeedbackBegin(GL_QUADS);
    1426    crStateFeedbackVertex2f(x0, y0);
    1427    crStateFeedbackVertex2f(x0, y1);
    1428    crStateFeedbackVertex2f(x1, y1);
    1429    crStateFeedbackVertex2f(x1, y0);
    1430    crStateFeedbackEnd();
    1431 }
    1432 
    1433 void STATE_APIENTRY
    1434 crStateFeedbackRecti(GLint x0, GLint y0, GLint x1, GLint y1)
    1435 {
    1436    crStateFeedbackRectf((GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
    1437 }
    1438 
    1439 void STATE_APIENTRY
    1440 crStateFeedbackRectd(GLdouble x0, GLdouble y0, GLdouble x1, GLdouble y1)
    1441 {
    1442    crStateFeedbackRectf((GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
    1443 }
    1444 
    1445 void STATE_APIENTRY
    1446 crStateFeedbackRects(GLshort x0, GLshort y0, GLshort x1, GLshort y1)
    1447 {
    1448    crStateFeedbackRectf((GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
    1449 }
    1450 
    1451 void STATE_APIENTRY
    1452 crStateFeedbackRectiv(const GLint *v0, const GLint *v1)
    1453 {
    1454    crStateFeedbackRectf((GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
    1455 }
    1456 
    1457 void STATE_APIENTRY
    1458 crStateFeedbackRectfv(const GLfloat *v0, const GLfloat *v1)
    1459 {
    1460    crStateFeedbackRectf(v0[0], v0[1], v1[0], v1[1]);
    1461 }
    1462 
    1463 void STATE_APIENTRY
    1464 crStateFeedbackRectdv(const GLdouble *v0, const GLdouble *v1)
    1465 {
    1466    crStateFeedbackRectf((GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
    1467 }
    1468 
    1469 void STATE_APIENTRY
    1470 crStateFeedbackRectsv(const GLshort *v0, const GLshort *v1)
    1471 {
    1472    crStateFeedbackRectf((GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
     1231crStateFeedbackTexCoord4fv(PCRStateTracker pState, const GLfloat *v )
     1232{
     1233        crStateFeedbackTexCoord4f(pState, v[0], v[1], v[2], v[3] );
     1234}
     1235
     1236void STATE_APIENTRY
     1237crStateFeedbackTexCoord4s(PCRStateTracker pState, GLshort v0, GLshort v1, GLshort v2, GLshort v3 )
     1238{
     1239        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, (GLfloat)v3 );
     1240}
     1241
     1242void STATE_APIENTRY
     1243crStateFeedbackTexCoord4sv(PCRStateTracker pState, const GLshort *v )
     1244{
     1245        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3] );
     1246}
     1247
     1248void STATE_APIENTRY
     1249crStateFeedbackTexCoord4i(PCRStateTracker pState, GLint v0, GLint v1, GLint v2, GLint v3 )
     1250{
     1251        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, (GLfloat)v3 );
     1252}
     1253
     1254void STATE_APIENTRY
     1255crStateFeedbackTexCoord4iv(PCRStateTracker pState, const GLint *v )
     1256{
     1257        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3] );
     1258}
     1259
     1260void STATE_APIENTRY
     1261crStateFeedbackTexCoord4d(PCRStateTracker pState, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3 )
     1262{
     1263        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, (GLfloat)v3 );
     1264}
     1265
     1266void STATE_APIENTRY
     1267crStateFeedbackTexCoord4dv(PCRStateTracker pState, const GLdouble *v )
     1268{
     1269        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3] );
     1270}
     1271
     1272void STATE_APIENTRY
     1273crStateFeedbackTexCoord1i(PCRStateTracker pState, GLint v0 )
     1274{
     1275        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, 0.0f, 0.0f, 1.0f );
     1276}
     1277
     1278void STATE_APIENTRY
     1279crStateFeedbackTexCoord1iv(PCRStateTracker pState, const GLint *v )
     1280{
     1281        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], 0.0f, 0.0f, 1.0f );
     1282}
     1283
     1284void STATE_APIENTRY
     1285crStateFeedbackTexCoord1s(PCRStateTracker pState, GLshort v0 )
     1286{
     1287        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, 0.0f, 0.0f, 1.0f );
     1288}
     1289
     1290void STATE_APIENTRY
     1291crStateFeedbackTexCoord1sv(PCRStateTracker pState, const GLshort *v )
     1292{
     1293        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], 0.0f, 0.0f, 1.0f );
     1294}
     1295
     1296void STATE_APIENTRY
     1297crStateFeedbackTexCoord1f(PCRStateTracker pState, GLfloat v0 )
     1298{
     1299        crStateFeedbackTexCoord4f(pState, v0, 0.0f, 0.0f, 1.0f );
     1300}
     1301
     1302void STATE_APIENTRY
     1303crStateFeedbackTexCoord1fv(PCRStateTracker pState, const GLfloat *v )
     1304{
     1305        crStateFeedbackTexCoord4f(pState, v[0], 0.0f, 0.0f, 1.0f );
     1306}
     1307
     1308void STATE_APIENTRY
     1309crStateFeedbackTexCoord1d(PCRStateTracker pState, GLdouble v0 )
     1310{
     1311        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, 0.0f, 0.0f, 1.0f );
     1312}
     1313
     1314void STATE_APIENTRY
     1315crStateFeedbackTexCoord1dv(PCRStateTracker pState, const GLdouble *v )
     1316{
     1317        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], 0.0f, 0.0f, 1.0f );
     1318}
     1319
     1320void STATE_APIENTRY
     1321crStateFeedbackTexCoord2i(PCRStateTracker pState, GLint v0, GLint v1 )
     1322{
     1323        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, (GLfloat)v1, 0.0f, 1.0f );
     1324}
     1325
     1326void STATE_APIENTRY
     1327crStateFeedbackTexCoord2iv(PCRStateTracker pState, const GLint *v )
     1328{
     1329        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], (GLfloat)v[1], 0.0f, 1.0f );
     1330}
     1331
     1332void STATE_APIENTRY
     1333crStateFeedbackTexCoord2s(PCRStateTracker pState, GLshort v0, GLshort v1 )
     1334{
     1335        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, (GLfloat)v1, 0.0f, 1.0f );
     1336}
     1337
     1338void STATE_APIENTRY
     1339crStateFeedbackTexCoord2sv(PCRStateTracker pState, const GLshort *v )
     1340{
     1341        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], (GLfloat)v[1], 0.0f, 1.0f );
     1342}
     1343
     1344void STATE_APIENTRY
     1345crStateFeedbackTexCoord2f(PCRStateTracker pState, GLfloat v0, GLfloat v1 )
     1346{
     1347        crStateFeedbackTexCoord4f(pState, v0, v1, 0.0f, 1.0f );
     1348}
     1349
     1350void STATE_APIENTRY
     1351crStateFeedbackTexCoord2fv(PCRStateTracker pState, const GLfloat *v )
     1352{
     1353        crStateFeedbackTexCoord4f(pState, v[0], v[1], 0.0f, 1.0f );
     1354}
     1355
     1356void STATE_APIENTRY
     1357crStateFeedbackTexCoord2d(PCRStateTracker pState, GLdouble v0, GLdouble v1 )
     1358{
     1359        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, (GLfloat)v1, 0.0f, 1.0f );
     1360}
     1361
     1362void STATE_APIENTRY
     1363crStateFeedbackTexCoord2dv(PCRStateTracker pState, const GLdouble *v )
     1364{
     1365        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], (GLfloat)v[1], 0.0f, 1.0f );
     1366}
     1367
     1368void STATE_APIENTRY
     1369crStateFeedbackTexCoord3i(PCRStateTracker pState, GLint v0, GLint v1, GLint v2 )
     1370{
     1371        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, 1.0f );
     1372}
     1373
     1374void STATE_APIENTRY
     1375crStateFeedbackTexCoord3iv(PCRStateTracker pState, const GLint *v )
     1376{
     1377        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], (GLfloat)v[1], 0.0f, 1.0f );
     1378}
     1379
     1380void STATE_APIENTRY
     1381crStateFeedbackTexCoord3s(PCRStateTracker pState, GLshort v0, GLshort v1, GLshort v2 )
     1382{
     1383        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, 1.0f );
     1384}
     1385
     1386void STATE_APIENTRY
     1387crStateFeedbackTexCoord3sv(PCRStateTracker pState, const GLshort *v )
     1388{
     1389        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], 1.0f );
     1390}
     1391
     1392void STATE_APIENTRY
     1393crStateFeedbackTexCoord3f(PCRStateTracker pState, GLfloat v0, GLfloat v1, GLfloat v2 )
     1394{
     1395        crStateFeedbackTexCoord4f(pState, v0, v1, v2, 1.0f );
     1396}
     1397
     1398void STATE_APIENTRY
     1399crStateFeedbackTexCoord3fv(PCRStateTracker pState, const GLfloat *v )
     1400{
     1401        crStateFeedbackTexCoord4f(pState, v[0], v[1], v[2], 1.0f );
     1402}
     1403
     1404void STATE_APIENTRY
     1405crStateFeedbackTexCoord3d(PCRStateTracker pState, GLdouble v0, GLdouble v1, GLdouble v2 )
     1406{
     1407        crStateFeedbackTexCoord4f(pState, (GLfloat)v0, (GLfloat)v1, (GLfloat)v2, 1.0f );
     1408}
     1409
     1410void STATE_APIENTRY
     1411crStateFeedbackTexCoord3dv(PCRStateTracker pState, const GLdouble *v )
     1412{
     1413        crStateFeedbackTexCoord4f(pState, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], 1.0f );
     1414}
     1415
     1416void STATE_APIENTRY
     1417crStateFeedbackRectf(PCRStateTracker pState, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1)
     1418{
     1419   crStateFeedbackBegin(pState, GL_QUADS);
     1420   crStateFeedbackVertex2f(pState, x0, y0);
     1421   crStateFeedbackVertex2f(pState, x0, y1);
     1422   crStateFeedbackVertex2f(pState, x1, y1);
     1423   crStateFeedbackVertex2f(pState, x1, y0);
     1424   crStateFeedbackEnd(pState);
     1425}
     1426
     1427void STATE_APIENTRY
     1428crStateFeedbackRecti(PCRStateTracker pState, GLint x0, GLint y0, GLint x1, GLint y1)
     1429{
     1430   crStateFeedbackRectf(pState, (GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
     1431}
     1432
     1433void STATE_APIENTRY
     1434crStateFeedbackRectd(PCRStateTracker pState, GLdouble x0, GLdouble y0, GLdouble x1, GLdouble y1)
     1435{
     1436   crStateFeedbackRectf(pState, (GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
     1437}
     1438
     1439void STATE_APIENTRY
     1440crStateFeedbackRects(PCRStateTracker pState, GLshort x0, GLshort y0, GLshort x1, GLshort y1)
     1441{
     1442   crStateFeedbackRectf(pState, (GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
     1443}
     1444
     1445void STATE_APIENTRY
     1446crStateFeedbackRectiv(PCRStateTracker pState, const GLint *v0, const GLint *v1)
     1447{
     1448   crStateFeedbackRectf(pState, (GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
     1449}
     1450
     1451void STATE_APIENTRY
     1452crStateFeedbackRectfv(PCRStateTracker pState, const GLfloat *v0, const GLfloat *v1)
     1453{
     1454   crStateFeedbackRectf(pState, v0[0], v0[1], v1[0], v1[1]);
     1455}
     1456
     1457void STATE_APIENTRY
     1458crStateFeedbackRectdv(PCRStateTracker pState, const GLdouble *v0, const GLdouble *v1)
     1459{
     1460   crStateFeedbackRectf(pState, (GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
     1461}
     1462
     1463void STATE_APIENTRY
     1464crStateFeedbackRectsv(PCRStateTracker pState, const GLshort *v0, const GLshort *v1)
     1465{
     1466   crStateFeedbackRectf(pState, (GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
    14731467}
    14741468
     
    14791473
    14801474void STATE_APIENTRY
    1481 crStateSelectBuffer(GLsizei size, GLuint * buffer)
    1482 {
    1483         CRContext *g = GetCurrentContext();
     1475crStateSelectBuffer(PCRStateTracker pState, GLsizei size, GLuint * buffer)
     1476{
     1477        CRContext *g = GetCurrentContext(pState);
    14841478        CRSelectionState *se = &(g->selection);
    14851479
    14861480        if (g->current.inBeginEnd)
    14871481        {
    1488                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1482                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    14891483                                                                 "SelectBuffer called in begin/end");
    14901484                return;
     
    14931487        if (g->renderMode == GL_SELECT)
    14941488        {
    1495                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1489                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    14961490                                                                 "SelectBuffer called with RenderMode = GL_SELECT");
    14971491                return;
     
    15451539
    15461540void STATE_APIENTRY
    1547 crStateInitNames(void)
    1548 {
    1549         CRContext *g = GetCurrentContext();
     1541crStateInitNames(PCRStateTracker pState)
     1542{
     1543        CRContext *g = GetCurrentContext(pState);
    15501544        CRSelectionState *se = &(g->selection);
    15511545
    15521546        if (g->current.inBeginEnd)
    15531547        {
    1554                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1548                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    15551549                                                                 "InitNames called in begin/end");
    15561550                return;
     
    15761570
    15771571void STATE_APIENTRY
    1578 crStateLoadName(GLuint name)
    1579 {
    1580         CRContext *g = GetCurrentContext();
     1572crStateLoadName(PCRStateTracker pState, GLuint name)
     1573{
     1574        CRContext *g = GetCurrentContext(pState);
    15811575        CRSelectionState *se = &(g->selection);
    15821576
    15831577        if (g->current.inBeginEnd)
    15841578        {
    1585                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1579                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    15861580                                                                 "LoadName called in begin/end");
    15871581                return;
     
    15961590        if (se->nameStackDepth == 0)
    15971591        {
    1598                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1592                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    15991593                                                                 "nameStackDepth = 0");
    16001594                return;
     
    16191613
    16201614void STATE_APIENTRY
    1621 crStatePushName(GLuint name)
    1622 {
    1623         CRContext *g = GetCurrentContext();
     1615crStatePushName(PCRStateTracker pState, GLuint name)
     1616{
     1617        CRContext *g = GetCurrentContext(pState);
    16241618        CRSelectionState *se = &(g->selection);
    16251619
    16261620        if (g->current.inBeginEnd)
    16271621        {
    1628                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1622                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    16291623                                                                 "PushName called in begin/end");
    16301624                return;
     
    16451639        if (se->nameStackDepth >= MAX_NAME_STACK_DEPTH)
    16461640        {
    1647                 crStateError(__LINE__, __FILE__, GL_STACK_OVERFLOW,
     1641                crStateError(pState, __LINE__, __FILE__, GL_STACK_OVERFLOW,
    16481642                                                                 "nameStackDepth overflow");
    16491643        }
     
    16531647
    16541648void STATE_APIENTRY
    1655 crStatePopName(void)
    1656 {
    1657         CRContext *g = GetCurrentContext();
     1649crStatePopName(PCRStateTracker pState)
     1650{
     1651        CRContext *g = GetCurrentContext(pState);
    16581652        CRSelectionState *se = &(g->selection);
    16591653
    16601654        if (g->current.inBeginEnd)
    16611655        {
    1662                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1656                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    16631657                                                                 "PopName called in begin/end");
    16641658                return;
     
    16791673        if (se->nameStackDepth == 0)
    16801674        {
    1681                 crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW,
     1675                crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW,
    16821676                                                                 "nameStackDepth underflow");
    16831677        }
     
    16881682
    16891683static void
    1690 update_hitflag(GLfloat z)
    1691 {
    1692         CRContext *g = GetCurrentContext();
     1684update_hitflag(CRContext *g, GLfloat z)
     1685{
    16931686        CRSelectionState *se = &(g->selection);
    16941687
     
    17041697
    17051698static void
    1706 select_rasterpos(void)
    1707 {
    1708         CRContext *g = GetCurrentContext();
    1709    
     1699select_rasterpos(CRContext *g)
     1700{
    17101701        if (g->current.rasterValid)
    1711                 update_hitflag(g->current.rasterAttrib[VERT_ATTRIB_POS][2]);
     1702                update_hitflag(g, g->current.rasterAttrib[VERT_ATTRIB_POS][2]);
    17121703}
    17131704
    17141705static void
    1715 select_point(const CRVertex *v)
    1716 {
    1717         CRContext *g = GetCurrentContext();
    1718         if (clip_point(v) == 0)
     1706select_point(CRContext *g, const CRVertex *v)
     1707{
     1708        if (clip_point(g, v) == 0)
    17191709        {
    17201710                CRVertex c = *v;
    17211711                MAP_POINT(c.winPos, c.clipPos, g->viewport);
    1722                 update_hitflag(c.winPos.z);
     1712                update_hitflag(g, c.winPos.z);
    17231713        }
    17241714}
     
    17261716
    17271717static void
    1728 select_line(const CRVertex *v0, const CRVertex *v1)
    1729 {
    1730         CRContext *g = GetCurrentContext();
     1718select_line(CRContext *g, const CRVertex *v0, const CRVertex *v1)
     1719{
    17311720        CRVertex c0, c1;
    1732         if (clip_line(v0, v1, &c0, &c1))
     1721        if (clip_line(g, v0, v1, &c0, &c1))
    17331722        {
    17341723                MAP_POINT(c0.winPos, c0.clipPos, g->viewport);
    17351724                MAP_POINT(c1.winPos, c1.clipPos, g->viewport);
    1736                 update_hitflag(c0.winPos.z);
    1737                 update_hitflag(c1.winPos.z);
     1725                update_hitflag(g, c0.winPos.z);
     1726                update_hitflag(g, c1.winPos.z);
    17381727        }
    17391728}
     
    17411730
    17421731static void
    1743 select_triangle(const CRVertex *v0,
     1732select_triangle(CRContext *g, const CRVertex *v0,
    17441733                                                                const CRVertex *v1,
    17451734                                                                const CRVertex *v2)
    17461735{
    1747         CRContext *g = GetCurrentContext();
    17481736        CRVertex vlist[3], vclipped[8];
    17491737        GLuint i, n;
     
    17551743        for (i = 0; i < n; i++) {
    17561744                MAP_POINT(vclipped[i].winPos, vclipped[i].clipPos, g->viewport);
    1757                 update_hitflag(vclipped[i].winPos.z);
    1758         }
    1759 }
    1760 
    1761 
    1762 void STATE_APIENTRY
    1763 crStateSelectVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    1764 {
    1765         CRContext *g = GetCurrentContext();
     1745                update_hitflag(g, vclipped[i].winPos.z);
     1746        }
     1747}
     1748
     1749
     1750void STATE_APIENTRY
     1751crStateSelectVertex4f(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
     1752{
     1753        CRContext *g = GetCurrentContext(pState);
    17661754        CRTransformState *t = &(g->transform);
    17671755        CRVertex *v = g->vBuffer + g->vCount;
     
    17851773        case GL_POINTS:
    17861774                CRASSERT(g->vCount == 0);
    1787                 select_point(v);
     1775                select_point(g, v);
    17881776                break;
    17891777        case GL_LINES:
     
    17951783                {
    17961784                        CRASSERT(g->vCount == 1);
    1797                         select_line(g->vBuffer + 0, g->vBuffer + 1);
     1785                        select_line(g, g->vBuffer + 0, g->vBuffer + 1);
    17981786                        g->vCount = 0;
    17991787                }
     
    18071795                {
    18081796                        CRASSERT(g->vCount == 1);
    1809                         select_line(g->vBuffer + 0, g->vBuffer + 1);
     1797                        select_line(g, g->vBuffer + 0, g->vBuffer + 1);
    18101798                        g->vBuffer[0] = g->vBuffer[1];
    18111799                        /* leave g->vCount at 1 */
     
    18201808                else if (g->vCount == 1)
    18211809                {
    1822                         select_line(g->vBuffer + 0, g->vBuffer + 1);
     1810                        select_line(g, g->vBuffer + 0, g->vBuffer + 1);
    18231811                        g->lineLoop = GL_TRUE;
    18241812                        g->vCount = 2;
     
    18281816                        CRASSERT(g->vCount == 2);
    18291817                        g->lineLoop = GL_FALSE;
    1830                         select_line(g->vBuffer + 1, g->vBuffer + 2);
     1818                        select_line(g, g->vBuffer + 1, g->vBuffer + 2);
    18311819                        g->vBuffer[1] = g->vBuffer[2];
    18321820                        /* leave g->vCount at 2 */
     
    18411829                {
    18421830                        CRASSERT(g->vCount == 2);
    1843                         select_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     1831                        select_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    18441832                        g->vCount = 0;
    18451833                }
     
    18521840                else if (g->vCount == 2)
    18531841                {
    1854                         select_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     1842                        select_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    18551843                        g->vCount = 3;
    18561844                }
     
    18581846                {
    18591847                        CRASSERT(g->vCount == 3);
    1860                         select_triangle(g->vBuffer + 1, g->vBuffer + 3, g->vBuffer + 2);
     1848                        select_triangle(g, g->vBuffer + 1, g->vBuffer + 3, g->vBuffer + 2);
    18611849                        g->vBuffer[0] = g->vBuffer[2];
    18621850                        g->vBuffer[1] = g->vBuffer[3];
     
    18721860                {
    18731861                        CRASSERT(g->vCount == 2);
    1874                         select_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     1862                        select_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    18751863                        g->vBuffer[1] = g->vBuffer[2];
    18761864                        /* leave g->vCount = 2 */
     
    18851873                {
    18861874                        CRASSERT(g->vCount == 3);
    1887                         select_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    1888                         select_triangle(g->vBuffer + 0, g->vBuffer + 2, g->vBuffer + 3);
     1875                        select_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     1876                        select_triangle(g, g->vBuffer + 0, g->vBuffer + 2, g->vBuffer + 3);
    18891877                        g->vCount = 0;
    18901878                }
     
    18981886                {
    18991887                        CRASSERT(g->vCount == 3);
    1900                         select_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    1901                         select_triangle(g->vBuffer + 1, g->vBuffer + 3, g->vBuffer + 2);
     1888                        select_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     1889                        select_triangle(g, g->vBuffer + 1, g->vBuffer + 3, g->vBuffer + 2);
    19021890                        g->vBuffer[0] = g->vBuffer[2];
    19031891                        g->vBuffer[1] = g->vBuffer[3];
     
    19141902                {
    19151903                        CRASSERT(g->vCount == 2);
    1916                         select_triangle(g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
     1904                        select_triangle(g, g->vBuffer + 0, g->vBuffer + 1, g->vBuffer + 2);
    19171905                        g->vBuffer[1] = g->vBuffer[2];
    19181906                        /* leave g->vCount = 2 */
     
    19251913
    19261914void STATE_APIENTRY
    1927 crStateSelectRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    1928 {
    1929         crStateRasterPos4f( x, y, z, w );
    1930 
    1931         select_rasterpos();
    1932 }
    1933 
    1934 void STATE_APIENTRY
    1935 crStateSelectBegin(GLenum mode)
    1936 {
    1937         CRContext *g = GetCurrentContext();
    1938 
    1939         crStateBegin(mode);
     1915crStateSelectRasterPos4f(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
     1916{
     1917        CRContext *g = GetCurrentContext(pState);
     1918        crStateRasterPos4f(pState, x, y, z, w );
     1919
     1920        select_rasterpos(g);
     1921}
     1922
     1923void STATE_APIENTRY
     1924crStateSelectBegin(PCRStateTracker pState, GLenum mode)
     1925{
     1926        CRContext *g = GetCurrentContext(pState);
     1927
     1928        crStateBegin(pState, mode);
    19401929
    19411930        g->vCount = 0;
     
    19461935
    19471936void STATE_APIENTRY
    1948 crStateSelectEnd(void)
    1949 {
    1950         CRContext *g = GetCurrentContext();
     1937crStateSelectEnd(PCRStateTracker pState)
     1938{
     1939        CRContext *g = GetCurrentContext(pState);
    19511940
    19521941        if (g->current.mode == GL_LINE_LOOP && g->vCount == 2)
    19531942        {
    19541943                /* draw the last line segment */
    1955                 select_line(g->vBuffer + 1, g->vBuffer + 0);
    1956         }
    1957 
    1958         crStateEnd();
    1959 }
    1960 
    1961 void STATE_APIENTRY
    1962 crStateSelectVertex2d(GLdouble x, GLdouble y)
    1963 {
    1964         crStateSelectVertex4f((GLfloat) x, (GLfloat) y, 0.0, 1.0);
    1965 }
    1966 
    1967 void STATE_APIENTRY
    1968 crStateSelectVertex2dv(const GLdouble * v)
    1969 {
    1970         crStateSelectVertex4f((GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
    1971 }
    1972 
    1973 void STATE_APIENTRY
    1974 crStateSelectVertex2f(GLfloat x, GLfloat y)
    1975 {
    1976         crStateSelectVertex4f(x, y, 0.0, 1.0);
    1977 }
    1978 
    1979 void STATE_APIENTRY
    1980 crStateSelectVertex2fv(const GLfloat * v)
    1981 {
    1982         crStateSelectVertex4f(v[0], v[1], 0.0, 1.0);
    1983 }
    1984 
    1985 void STATE_APIENTRY
    1986 crStateSelectVertex2i(GLint x, GLint y)
    1987 {
    1988         crStateSelectVertex4f((GLfloat) x, (GLfloat) y, 0.0, 1.0);
    1989 }
    1990 
    1991 void STATE_APIENTRY
    1992 crStateSelectVertex2iv(const GLint * v)
    1993 {
    1994         crStateSelectVertex4f((GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
    1995 }
    1996 
    1997 void STATE_APIENTRY
    1998 crStateSelectVertex2s(GLshort x, GLshort y)
    1999 {
    2000         crStateSelectVertex4f((GLfloat) x, (GLfloat) y, 0.0, 1.0);
    2001 }
    2002 
    2003 void STATE_APIENTRY
    2004 crStateSelectVertex2sv(const GLshort * v)
    2005 {
    2006         crStateSelectVertex4f((GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
    2007 }
    2008 
    2009 void STATE_APIENTRY
    2010 crStateSelectVertex3d(GLdouble x, GLdouble y, GLdouble z)
    2011 {
    2012         crStateSelectVertex4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
    2013 }
    2014 
    2015 void STATE_APIENTRY
    2016 crStateSelectVertex3dv(const GLdouble * v)
    2017 {
    2018         crStateSelectVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0);
    2019 }
    2020 
    2021 void STATE_APIENTRY
    2022 crStateSelectVertex3f(GLfloat x, GLfloat y, GLfloat z)
    2023 {
    2024         crStateSelectVertex4f(x, y, z, 1.0);
    2025 }
    2026 
    2027 void STATE_APIENTRY
    2028 crStateSelectVertex3fv(const GLfloat * v)
    2029 {
    2030         crStateSelectVertex4f(v[0], v[1], v[2], 1.0);
    2031 }
    2032 
    2033 void STATE_APIENTRY
    2034 crStateSelectVertex3i(GLint x, GLint y, GLint z)
    2035 {
    2036         crStateSelectVertex4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
    2037 }
    2038 
    2039 void STATE_APIENTRY
    2040 crStateSelectVertex3iv(const GLint * v)
    2041 {
    2042         crStateSelectVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0);
    2043 }
    2044 
    2045 void STATE_APIENTRY
    2046 crStateSelectVertex3s(GLshort x, GLshort y, GLshort z)
    2047 {
    2048         crStateSelectVertex4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
    2049 }
    2050 
    2051 void STATE_APIENTRY
    2052 crStateSelectVertex3sv(const GLshort * v)
    2053 {
    2054         crStateSelectVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0);
    2055 }
    2056 
    2057 void STATE_APIENTRY
    2058 crStateSelectVertex4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
    2059 {
    2060         crStateSelectVertex4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    2061 }
    2062 
    2063 void STATE_APIENTRY
    2064 crStateSelectVertex4dv(const GLdouble * v)
    2065 {
    2066         crStateSelectVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
    2067 }
    2068 
    2069 void STATE_APIENTRY
    2070 crStateSelectVertex4fv(const GLfloat * v)
    2071 {
    2072         crStateSelectVertex4f(v[0], v[1], v[2], v[3]);
    2073 }
    2074 
    2075 void STATE_APIENTRY
    2076 crStateSelectVertex4i(GLint x, GLint y, GLint z, GLint w)
    2077 {
    2078         crStateSelectVertex4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    2079 }
    2080 
    2081 void STATE_APIENTRY
    2082 crStateSelectVertex4iv(const GLint * v)
    2083 {
    2084         crStateSelectVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
    2085 }
    2086 
    2087 void STATE_APIENTRY
    2088 crStateSelectVertex4s(GLshort x, GLshort y, GLshort z, GLshort w)
    2089 {
    2090         crStateSelectVertex4f(x, y, z, w);
    2091 }
    2092 
    2093 void STATE_APIENTRY
    2094 crStateSelectVertex4sv(const GLshort * v)
    2095 {
    2096         crStateSelectVertex4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
    2097 }
    2098 
    2099 void STATE_APIENTRY
    2100 crStateSelectRasterPos2d(GLdouble x, GLdouble y)
    2101 {
    2102         crStateSelectRasterPos4f((GLfloat) x, (GLfloat) y, 0.0, 1.0);
    2103 }
    2104 
    2105 void STATE_APIENTRY
    2106 crStateSelectRasterPos2dv(const GLdouble * v)
    2107 {
    2108         crStateSelectRasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
    2109 }
    2110 
    2111 void STATE_APIENTRY
    2112 crStateSelectRasterPos2f(GLfloat x, GLfloat y)
    2113 {
    2114         crStateSelectRasterPos4f(x, y, 0.0, 1.0);
    2115 }
    2116 
    2117 void STATE_APIENTRY
    2118 crStateSelectRasterPos2fv(const GLfloat * v)
    2119 {
    2120         crStateSelectRasterPos4f(v[0], v[1], 0.0, 1.0);
    2121 }
    2122 
    2123 void STATE_APIENTRY
    2124 crStateSelectRasterPos2i(GLint x, GLint y)
    2125 {
    2126         crStateSelectRasterPos4f((GLfloat) x, (GLfloat) y, 0.0, 1.0);
    2127 }
    2128 
    2129 void STATE_APIENTRY
    2130 crStateSelectRasterPos2iv(const GLint * v)
    2131 {
    2132         crStateSelectRasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
    2133 }
    2134 
    2135 void STATE_APIENTRY
    2136 crStateSelectRasterPos2s(GLshort x, GLshort y)
    2137 {
    2138         crStateSelectRasterPos4f((GLfloat) x, (GLfloat) y, 0.0, 1.0);
    2139 }
    2140 
    2141 void STATE_APIENTRY
    2142 crStateSelectRasterPos2sv(const GLshort * v)
    2143 {
    2144         crStateSelectRasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
    2145 }
    2146 
    2147 void STATE_APIENTRY
    2148 crStateSelectRasterPos3d(GLdouble x, GLdouble y, GLdouble z)
    2149 {
    2150         crStateSelectRasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
    2151 }
    2152 
    2153 void STATE_APIENTRY
    2154 crStateSelectRasterPos3dv(const GLdouble * v)
    2155 {
    2156         crStateSelectRasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , 1.0);
    2157 }
    2158 
    2159 void STATE_APIENTRY
    2160 crStateSelectRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
    2161 {
    2162         crStateSelectRasterPos4f(x, y, z, 1.0);
    2163 }
    2164 
    2165 void STATE_APIENTRY
    2166 crStateSelectRasterPos3fv(const GLfloat * v)
    2167 {
    2168         crStateSelectRasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , 1.0);
    2169 }
    2170 
    2171 void STATE_APIENTRY
    2172 crStateSelectRasterPos3i(GLint x, GLint y, GLint z)
    2173 {
    2174         crStateSelectRasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
    2175 }
    2176 
    2177 void STATE_APIENTRY
    2178 crStateSelectRasterPos3iv(const GLint * v)
    2179 {
    2180         crStateSelectRasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , 1.0);
    2181 }
    2182 
    2183 void STATE_APIENTRY
    2184 crStateSelectRasterPos3s(GLshort x, GLshort y, GLshort z)
    2185 {
    2186         crStateSelectRasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
    2187 }
    2188 
    2189 void STATE_APIENTRY
    2190 crStateSelectRasterPos3sv(const GLshort * v)
    2191 {
    2192         crStateSelectRasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , 1.0);
    2193 }
    2194 
    2195 void STATE_APIENTRY
    2196 crStateSelectRasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
    2197 {
    2198         crStateSelectRasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    2199 }
    2200 
    2201 void STATE_APIENTRY
    2202 crStateSelectRasterPos4dv(const GLdouble * v)
    2203 {
    2204         crStateSelectRasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , (GLfloat) v[3]);
    2205 }
    2206 
    2207 void STATE_APIENTRY
    2208 crStateSelectRasterPos4fv(const GLfloat * v)
    2209 {
    2210         crStateSelectRasterPos4f(v[0], v[1], v[2], v[3]);
    2211 }
    2212 
    2213 void STATE_APIENTRY
    2214 crStateSelectRasterPos4i(GLint x, GLint y, GLint z, GLint w)
    2215 {
    2216         crStateSelectRasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    2217 }
    2218 
    2219 void STATE_APIENTRY
    2220 crStateSelectRasterPos4iv(const GLint * v)
    2221 {
    2222         crStateSelectRasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
    2223 }
    2224 
    2225 void STATE_APIENTRY
    2226 crStateSelectRasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
    2227 {
    2228         crStateSelectRasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    2229 }
    2230 
    2231 void STATE_APIENTRY
    2232 crStateSelectRasterPos4sv(const GLshort * v)
    2233 {
    2234         crStateSelectRasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , (GLfloat) v[3]);
    2235 }
    2236 
    2237 void STATE_APIENTRY
    2238 crStateSelectRectf(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1)
    2239 {
    2240    crStateSelectBegin(GL_QUADS);
    2241    crStateSelectVertex2f(x0, y0);
    2242    crStateSelectVertex2f(x0, y1);
    2243    crStateSelectVertex2f(x1, y1);
    2244    crStateSelectVertex2f(x1, y0);
    2245    crStateSelectEnd();
    2246 }
    2247 
    2248 void STATE_APIENTRY
    2249 crStateSelectRecti(GLint x0, GLint y0, GLint x1, GLint y1)
    2250 {
    2251    crStateSelectRectf((GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
    2252 }
    2253 
    2254 void STATE_APIENTRY
    2255 crStateSelectRectd(GLdouble x0, GLdouble y0, GLdouble x1, GLdouble y1)
    2256 {
    2257    crStateSelectRectf((GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
    2258 }
    2259 
    2260 void STATE_APIENTRY
    2261 crStateSelectRects(GLshort x0, GLshort y0, GLshort x1, GLshort y1)
    2262 {
    2263    crStateSelectRectf((GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
    2264 }
    2265 
    2266 void STATE_APIENTRY
    2267 crStateSelectRectiv(const GLint *v0, const GLint *v1)
    2268 {
    2269    crStateSelectRectf((GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
    2270 }
    2271 
    2272 void STATE_APIENTRY
    2273 crStateSelectRectfv(const GLfloat *v0, const GLfloat *v1)
    2274 {
    2275    crStateSelectRectf(v0[0], v0[1], v1[0], v1[1]);
    2276 }
    2277 
    2278 void STATE_APIENTRY
    2279 crStateSelectRectdv(const GLdouble *v0, const GLdouble *v1)
    2280 {
    2281    crStateSelectRectf((GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
    2282 }
    2283 
    2284 void STATE_APIENTRY
    2285 crStateSelectRectsv(const GLshort *v0, const GLshort *v1)
    2286 {
    2287    crStateSelectRectf((GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
     1944                select_line(g, g->vBuffer + 1, g->vBuffer + 0);
     1945        }
     1946
     1947        crStateEnd(pState);
     1948}
     1949
     1950void STATE_APIENTRY
     1951crStateSelectVertex2d(PCRStateTracker pState, GLdouble x, GLdouble y)
     1952{
     1953        crStateSelectVertex4f(pState, (GLfloat) x, (GLfloat) y, 0.0, 1.0);
     1954}
     1955
     1956void STATE_APIENTRY
     1957crStateSelectVertex2dv(PCRStateTracker pState, const GLdouble * v)
     1958{
     1959        crStateSelectVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
     1960}
     1961
     1962void STATE_APIENTRY
     1963crStateSelectVertex2f(PCRStateTracker pState, GLfloat x, GLfloat y)
     1964{
     1965        crStateSelectVertex4f(pState, x, y, 0.0, 1.0);
     1966}
     1967
     1968void STATE_APIENTRY
     1969crStateSelectVertex2fv(PCRStateTracker pState, const GLfloat * v)
     1970{
     1971        crStateSelectVertex4f(pState, v[0], v[1], 0.0, 1.0);
     1972}
     1973
     1974void STATE_APIENTRY
     1975crStateSelectVertex2i(PCRStateTracker pState, GLint x, GLint y)
     1976{
     1977        crStateSelectVertex4f(pState, (GLfloat) x, (GLfloat) y, 0.0, 1.0);
     1978}
     1979
     1980void STATE_APIENTRY
     1981crStateSelectVertex2iv(PCRStateTracker pState, const GLint * v)
     1982{
     1983        crStateSelectVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
     1984}
     1985
     1986void STATE_APIENTRY
     1987crStateSelectVertex2s(PCRStateTracker pState, GLshort x, GLshort y)
     1988{
     1989        crStateSelectVertex4f(pState, (GLfloat) x, (GLfloat) y, 0.0, 1.0);
     1990}
     1991
     1992void STATE_APIENTRY
     1993crStateSelectVertex2sv(PCRStateTracker pState, const GLshort * v)
     1994{
     1995        crStateSelectVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
     1996}
     1997
     1998void STATE_APIENTRY
     1999crStateSelectVertex3d(PCRStateTracker pState, GLdouble x, GLdouble y, GLdouble z)
     2000{
     2001        crStateSelectVertex4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
     2002}
     2003
     2004void STATE_APIENTRY
     2005crStateSelectVertex3dv(PCRStateTracker pState, const GLdouble * v)
     2006{
     2007        crStateSelectVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0);
     2008}
     2009
     2010void STATE_APIENTRY
     2011crStateSelectVertex3f(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z)
     2012{
     2013        crStateSelectVertex4f(pState, x, y, z, 1.0);
     2014}
     2015
     2016void STATE_APIENTRY
     2017crStateSelectVertex3fv(PCRStateTracker pState, const GLfloat * v)
     2018{
     2019        crStateSelectVertex4f(pState, v[0], v[1], v[2], 1.0);
     2020}
     2021
     2022void STATE_APIENTRY
     2023crStateSelectVertex3i(PCRStateTracker pState, GLint x, GLint y, GLint z)
     2024{
     2025        crStateSelectVertex4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
     2026}
     2027
     2028void STATE_APIENTRY
     2029crStateSelectVertex3iv(PCRStateTracker pState, const GLint * v)
     2030{
     2031        crStateSelectVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0);
     2032}
     2033
     2034void STATE_APIENTRY
     2035crStateSelectVertex3s(PCRStateTracker pState, GLshort x, GLshort y, GLshort z)
     2036{
     2037        crStateSelectVertex4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
     2038}
     2039
     2040void STATE_APIENTRY
     2041crStateSelectVertex3sv(PCRStateTracker pState, const GLshort * v)
     2042{
     2043        crStateSelectVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0);
     2044}
     2045
     2046void STATE_APIENTRY
     2047crStateSelectVertex4d(PCRStateTracker pState, GLdouble x, GLdouble y, GLdouble z, GLdouble w)
     2048{
     2049        crStateSelectVertex4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     2050}
     2051
     2052void STATE_APIENTRY
     2053crStateSelectVertex4dv(PCRStateTracker pState, const GLdouble * v)
     2054{
     2055        crStateSelectVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
     2056}
     2057
     2058void STATE_APIENTRY
     2059crStateSelectVertex4fv(PCRStateTracker pState, const GLfloat * v)
     2060{
     2061        crStateSelectVertex4f(pState, v[0], v[1], v[2], v[3]);
     2062}
     2063
     2064void STATE_APIENTRY
     2065crStateSelectVertex4i(PCRStateTracker pState, GLint x, GLint y, GLint z, GLint w)
     2066{
     2067        crStateSelectVertex4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     2068}
     2069
     2070void STATE_APIENTRY
     2071crStateSelectVertex4iv(PCRStateTracker pState, const GLint * v)
     2072{
     2073        crStateSelectVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
     2074}
     2075
     2076void STATE_APIENTRY
     2077crStateSelectVertex4s(PCRStateTracker pState, GLshort x, GLshort y, GLshort z, GLshort w)
     2078{
     2079        crStateSelectVertex4f(pState, x, y, z, w);
     2080}
     2081
     2082void STATE_APIENTRY
     2083crStateSelectVertex4sv(PCRStateTracker pState, const GLshort * v)
     2084{
     2085        crStateSelectVertex4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
     2086}
     2087
     2088void STATE_APIENTRY
     2089crStateSelectRasterPos2d(PCRStateTracker pState, GLdouble x, GLdouble y)
     2090{
     2091        crStateSelectRasterPos4f(pState, (GLfloat) x, (GLfloat) y, 0.0, 1.0);
     2092}
     2093
     2094void STATE_APIENTRY
     2095crStateSelectRasterPos2dv(PCRStateTracker pState, const GLdouble * v)
     2096{
     2097        crStateSelectRasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
     2098}
     2099
     2100void STATE_APIENTRY
     2101crStateSelectRasterPos2f(PCRStateTracker pState, GLfloat x, GLfloat y)
     2102{
     2103        crStateSelectRasterPos4f(pState, x, y, 0.0, 1.0);
     2104}
     2105
     2106void STATE_APIENTRY
     2107crStateSelectRasterPos2fv(PCRStateTracker pState, const GLfloat * v)
     2108{
     2109        crStateSelectRasterPos4f(pState, v[0], v[1], 0.0, 1.0);
     2110}
     2111
     2112void STATE_APIENTRY
     2113crStateSelectRasterPos2i(PCRStateTracker pState, GLint x, GLint y)
     2114{
     2115        crStateSelectRasterPos4f(pState, (GLfloat) x, (GLfloat) y, 0.0, 1.0);
     2116}
     2117
     2118void STATE_APIENTRY
     2119crStateSelectRasterPos2iv(PCRStateTracker pState, const GLint * v)
     2120{
     2121        crStateSelectRasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
     2122}
     2123
     2124void STATE_APIENTRY
     2125crStateSelectRasterPos2s(PCRStateTracker pState, GLshort x, GLshort y)
     2126{
     2127        crStateSelectRasterPos4f(pState, (GLfloat) x, (GLfloat) y, 0.0, 1.0);
     2128}
     2129
     2130void STATE_APIENTRY
     2131crStateSelectRasterPos2sv(PCRStateTracker pState, const GLshort * v)
     2132{
     2133        crStateSelectRasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0, 1.0);
     2134}
     2135
     2136void STATE_APIENTRY
     2137crStateSelectRasterPos3d(PCRStateTracker pState, GLdouble x, GLdouble y, GLdouble z)
     2138{
     2139        crStateSelectRasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
     2140}
     2141
     2142void STATE_APIENTRY
     2143crStateSelectRasterPos3dv(PCRStateTracker pState, const GLdouble * v)
     2144{
     2145        crStateSelectRasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , 1.0);
     2146}
     2147
     2148void STATE_APIENTRY
     2149crStateSelectRasterPos3f(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z)
     2150{
     2151        crStateSelectRasterPos4f(pState, x, y, z, 1.0);
     2152}
     2153
     2154void STATE_APIENTRY
     2155crStateSelectRasterPos3fv(PCRStateTracker pState, const GLfloat * v)
     2156{
     2157        crStateSelectRasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , 1.0);
     2158}
     2159
     2160void STATE_APIENTRY
     2161crStateSelectRasterPos3i(PCRStateTracker pState, GLint x, GLint y, GLint z)
     2162{
     2163        crStateSelectRasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
     2164}
     2165
     2166void STATE_APIENTRY
     2167crStateSelectRasterPos3iv(PCRStateTracker pState, const GLint * v)
     2168{
     2169        crStateSelectRasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , 1.0);
     2170}
     2171
     2172void STATE_APIENTRY
     2173crStateSelectRasterPos3s(PCRStateTracker pState, GLshort x, GLshort y, GLshort z)
     2174{
     2175        crStateSelectRasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0);
     2176}
     2177
     2178void STATE_APIENTRY
     2179crStateSelectRasterPos3sv(PCRStateTracker pState, const GLshort * v)
     2180{
     2181        crStateSelectRasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , 1.0);
     2182}
     2183
     2184void STATE_APIENTRY
     2185crStateSelectRasterPos4d(PCRStateTracker pState, GLdouble x, GLdouble y, GLdouble z, GLdouble w)
     2186{
     2187        crStateSelectRasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     2188}
     2189
     2190void STATE_APIENTRY
     2191crStateSelectRasterPos4dv(PCRStateTracker pState, const GLdouble * v)
     2192{
     2193        crStateSelectRasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , (GLfloat) v[3]);
     2194}
     2195
     2196void STATE_APIENTRY
     2197crStateSelectRasterPos4fv(PCRStateTracker pState, const GLfloat * v)
     2198{
     2199        crStateSelectRasterPos4f(pState, v[0], v[1], v[2], v[3]);
     2200}
     2201
     2202void STATE_APIENTRY
     2203crStateSelectRasterPos4i(PCRStateTracker pState, GLint x, GLint y, GLint z, GLint w)
     2204{
     2205        crStateSelectRasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     2206}
     2207
     2208void STATE_APIENTRY
     2209crStateSelectRasterPos4iv(PCRStateTracker pState, const GLint * v)
     2210{
     2211        crStateSelectRasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
     2212}
     2213
     2214void STATE_APIENTRY
     2215crStateSelectRasterPos4s(PCRStateTracker pState, GLshort x, GLshort y, GLshort z, GLshort w)
     2216{
     2217        crStateSelectRasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     2218}
     2219
     2220void STATE_APIENTRY
     2221crStateSelectRasterPos4sv(PCRStateTracker pState, const GLshort * v)
     2222{
     2223        crStateSelectRasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2] , (GLfloat) v[3]);
     2224}
     2225
     2226void STATE_APIENTRY
     2227crStateSelectRectf(PCRStateTracker pState, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1)
     2228{
     2229   crStateSelectBegin(pState, GL_QUADS);
     2230   crStateSelectVertex2f(pState, x0, y0);
     2231   crStateSelectVertex2f(pState, x0, y1);
     2232   crStateSelectVertex2f(pState, x1, y1);
     2233   crStateSelectVertex2f(pState, x1, y0);
     2234   crStateSelectEnd(pState);
     2235}
     2236
     2237void STATE_APIENTRY
     2238crStateSelectRecti(PCRStateTracker pState, GLint x0, GLint y0, GLint x1, GLint y1)
     2239{
     2240   crStateSelectRectf(pState, (GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
     2241}
     2242
     2243void STATE_APIENTRY
     2244crStateSelectRectd(PCRStateTracker pState, GLdouble x0, GLdouble y0, GLdouble x1, GLdouble y1)
     2245{
     2246   crStateSelectRectf(pState, (GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
     2247}
     2248
     2249void STATE_APIENTRY
     2250crStateSelectRects(PCRStateTracker pState, GLshort x0, GLshort y0, GLshort x1, GLshort y1)
     2251{
     2252   crStateSelectRectf(pState, (GLfloat) x0, (GLfloat) y0, (GLfloat) x1, (GLfloat) y1);
     2253}
     2254
     2255void STATE_APIENTRY
     2256crStateSelectRectiv(PCRStateTracker pState, const GLint *v0, const GLint *v1)
     2257{
     2258   crStateSelectRectf(pState, (GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
     2259}
     2260
     2261void STATE_APIENTRY
     2262crStateSelectRectfv(PCRStateTracker pState, const GLfloat *v0, const GLfloat *v1)
     2263{
     2264   crStateSelectRectf(pState, v0[0], v0[1], v1[0], v1[1]);
     2265}
     2266
     2267void STATE_APIENTRY
     2268crStateSelectRectdv(PCRStateTracker pState, const GLdouble *v0, const GLdouble *v1)
     2269{
     2270   crStateSelectRectf(pState, (GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
     2271}
     2272
     2273void STATE_APIENTRY
     2274crStateSelectRectsv(PCRStateTracker pState, const GLshort *v0, const GLshort *v1)
     2275{
     2276   crStateSelectRectf(pState, (GLfloat) v0[0], (GLfloat) v0[1], (GLfloat) v1[0], (GLfloat) v1[1]);
    22882277}
    22892278
    22902279
    22912280GLint STATE_APIENTRY
    2292 crStateRenderMode(GLenum mode)
    2293 {
    2294         CRContext *g = GetCurrentContext();
     2281crStateRenderMode(PCRStateTracker pState, GLenum mode)
     2282{
     2283        CRContext *g = GetCurrentContext(pState);
    22952284        CRFeedbackState *f = &(g->feedback);
    22962285        CRSelectionState *se = &(g->selection);
     
    22992288        if (g->current.inBeginEnd)
    23002289        {
    2301                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2290                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    23022291                                                                 "RenderMode called in begin/end");
    23032292                return 0;
     
    23432332                break;
    23442333        default:
    2345                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "invalid rendermode");
     2334                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "invalid rendermode");
    23462335                return 0;
    23472336        }
     
    23552344                {
    23562345                        /* haven't called glSelectBuffer yet */
    2357                         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2346                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    23582347                                                                         "buffersize = 0");
    23592348                }
     
    23632352                {
    23642353                        /* haven't called glFeedbackBuffer yet */
    2365                         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2354                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    23662355                                                                         "buffersize = 0");
    23672356                }
    23682357                break;
    23692358        default:
    2370                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "invalid rendermode");
     2359                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "invalid rendermode");
    23712360                return 0;
    23722361        }
     
    23792368
    23802369void STATE_APIENTRY
    2381 crStateSelectDrawPixels(GLsizei width, GLsizei height, GLenum format,
     2370crStateSelectDrawPixels(PCRStateTracker pState, GLsizei width, GLsizei height, GLenum format,
    23822371                                                                                                GLenum type, const GLvoid * pixels)
    23832372{
     2373        CRContext *g = GetCurrentContext(pState);
    23842374        (void) width;
    23852375        (void) height;
     
    23872377        (void) type;
    23882378        (void) pixels;
    2389         select_rasterpos();
    2390 }
    2391 
    2392 void STATE_APIENTRY
    2393 crStateSelectCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height,
     2379        select_rasterpos(g);
     2380}
     2381
     2382void STATE_APIENTRY
     2383crStateSelectCopyPixels(PCRStateTracker pState, GLint x, GLint y, GLsizei width, GLsizei height,
    23942384                                                                                                GLenum type)
    23952385{
     2386        CRContext *g = GetCurrentContext(pState);
    23962387        (void) x;
    23972388        (void) y;
     
    23992390        (void) height;
    24002391        (void) type;
    2401         select_rasterpos();
    2402 }
    2403 
    2404 void STATE_APIENTRY
    2405 crStateSelectBitmap(GLsizei width, GLsizei height, GLfloat xorig,
     2392        select_rasterpos(g);
     2393}
     2394
     2395void STATE_APIENTRY
     2396crStateSelectBitmap(PCRStateTracker pState, GLsizei width, GLsizei height, GLfloat xorig,
    24062397                                                                                GLfloat yorig, GLfloat xmove, GLfloat ymove,
    24072398                                                                                const GLubyte * bitmap)
    24082399{
    2409         CRContext *g = GetCurrentContext();
     2400        CRContext *g = GetCurrentContext(pState);
    24102401        (void) width;
    24112402        (void) height;
     
    24142405        (void) bitmap;
    24152406
    2416         select_rasterpos();
     2407        select_rasterpos(g);
    24172408        if (g->current.rasterValid)
    24182409        {
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_fence.c

    r69392 r78375  
    1111
    1212
    13 void APIENTRY crStateGenFencesNV(GLsizei n, GLuint *fences)
     13void APIENTRY crStateGenFencesNV(PCRStateTracker pState, GLsizei n, GLuint *fences)
    1414{
    15     (void)n; (void)fences;
     15    RT_NOREF(pState, n, fences);
    1616}
    1717
    1818
    19 void APIENTRY crStateDeleteFencesNV(GLsizei n, const GLuint *fences)
     19void APIENTRY crStateDeleteFencesNV(PCRStateTracker pState, GLsizei n, const GLuint *fences)
    2020{
    21     (void)n; (void)fences;
     21    RT_NOREF(pState, n, fences);
    2222}
    2323
    24 void APIENTRY crStateSetFenceNV(GLuint fence, GLenum condition)
     24void APIENTRY crStateSetFenceNV(PCRStateTracker pState, GLuint fence, GLenum condition)
    2525{
    26     (void)fence; (void)condition;
     26    RT_NOREF(pState, fence, condition);
    2727}
    2828
    29 GLboolean APIENTRY crStateTestFenceNV(GLuint fence)
     29GLboolean APIENTRY crStateTestFenceNV(PCRStateTracker pState, GLuint fence)
    3030{
    31     (void)fence;
     31    RT_NOREF(pState, fence);
    3232    return GL_FALSE;
    3333}
    3434
    35 void APIENTRY crStateFinishFenceNV(GLuint fence)
     35void APIENTRY crStateFinishFenceNV(PCRStateTracker pState, GLuint fence)
    3636{
    37     (void)fence;
     37    RT_NOREF(pState, fence);
    3838}
    3939
    40 GLboolean APIENTRY crStateIsFenceNV(GLuint fence)
     40GLboolean APIENTRY crStateIsFenceNV(PCRStateTracker pState, GLuint fence)
    4141{
    42     (void)fence;
     42    RT_NOREF(pState, fence);
    4343    return GL_FALSE;
    4444}
    4545
    46 void APIENTRY crStateGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
     46void APIENTRY crStateGetFenceivNV(PCRStateTracker pState, GLuint fence, GLenum pname, GLint *params)
    4747{
    48     (void)fence; (void)pname; (void)params;
     48    RT_NOREF(pState, fence, pname, params);
    4949}
    5050
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_flush.c

    r69392 r78375  
    88#include "cr_spu.h"
    99
    10 SPUDispatchTable diff_api;
    11 
    12 void crStateFlushFunc( CRStateFlushFunc func )
     10void crStateFlushFunc(PCRStateTracker pState, CRStateFlushFunc func )
    1311{
    14         CRContext *g = GetCurrentContext();
     12        CRContext *g = GetCurrentContext(pState);
    1513
    1614        g->flush_func = func;
    1715}
    1816
    19 void crStateFlushArg( void *arg )
     17void crStateFlushArg(PCRStateTracker pState, void *arg )
    2018{
    21         CRContext *g = GetCurrentContext();
     19        CRContext *g = GetCurrentContext(pState);
    2220
    2321        g->flush_arg = arg;
    2422}
    2523
    26 void crStateDiffAPI( SPUDispatchTable *api )
     24void crStateDiffAPI(PCRStateTracker pState, SPUDispatchTable *api )
    2725{
    28         if (!diff_api.AlphaFunc)
     26        if (!pState->diff_api.AlphaFunc)
    2927        {
    3028                /* Called when starting up Chromium */
    31                 crSPUInitDispatchTable( &(diff_api) );
     29                crSPUInitDispatchTable( &pState->diff_api );
    3230        }
    33         crSPUCopyDispatchTable( &(diff_api), api );
     31        crSPUCopyDispatchTable( &pState->diff_api, api );
    3432}
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_fog.c

    r69392 r78375  
    1313{
    1414        CRFogState *f = &ctx->fog;
    15         CRStateBits *sb = GetCurrentBits();
     15        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    1616        CRFogBits *fb = &(sb->fog);
    1717        GLcolorf black = {0.0f, 0.0f, 0.0f, 0.0f};
     
    4343}
    4444
    45 void STATE_APIENTRY crStateFogf(GLenum pname, GLfloat param)
     45void STATE_APIENTRY crStateFogf(PCRStateTracker pState, GLenum pname, GLfloat param)
    4646{
    47         crStateFogfv( pname, &param );
     47        crStateFogfv(pState, pname, &param );
    4848}
    4949
    50 void STATE_APIENTRY crStateFogi(GLenum pname, GLint param)
     50void STATE_APIENTRY crStateFogi(PCRStateTracker pState, GLenum pname, GLint param)
    5151{
    5252        GLfloat f_param = (GLfloat) param;
    53         crStateFogfv( pname, &f_param );
     53        crStateFogfv(pState, pname, &f_param );
    5454}
    5555
    56 void STATE_APIENTRY crStateFogiv(GLenum pname, const GLint *param)
     56void STATE_APIENTRY crStateFogiv(PCRStateTracker pState, GLenum pname, const GLint *param)
    5757{
    5858        GLcolor f_color;
     
    6666                case GL_FOG_INDEX:
    6767                        f_param = (GLfloat) (*param);
    68                         crStateFogfv( pname, &f_param );
     68                        crStateFogfv(pState, pname, &f_param );
    6969                        break;
    7070                case GL_FOG_COLOR:
     
    7373                        f_color.b = ((GLfloat) param[2]) / ((GLfloat) CR_MAXINT);
    7474                        f_color.a = ((GLfloat) param[3]) / ((GLfloat) CR_MAXINT);
    75                         crStateFogfv( pname, (GLfloat *) &f_color );
     75                        crStateFogfv(pState, pname, (GLfloat *) &f_color );
    7676                        break;
    7777#ifdef CR_NV_fog_distance
    7878                case GL_FOG_DISTANCE_MODE_NV:
    7979                        f_param = (GLfloat) (*param);
    80                         crStateFogfv( pname, &f_param );
     80                        crStateFogfv(pState, pname, &f_param );
    8181                        break;
    8282#endif
     
    8484                case GL_FOG_COORDINATE_SOURCE_EXT:
    8585                        f_param = (GLfloat) (*param);
    86                         crStateFogfv( pname, &f_param );
     86                        crStateFogfv(pState, pname, &f_param );
    8787                        break;
    8888#endif
    8989                default:
    90                         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Invalid glFog Param: %d", param);
     90                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Invalid glFog Param: %d", param);
    9191                        return;
    9292        }
    9393}
    9494
    95 void STATE_APIENTRY crStateFogfv(GLenum pname, const GLfloat *param)
     95void STATE_APIENTRY crStateFogfv(PCRStateTracker pState, GLenum pname, const GLfloat *param)
    9696{
    97         CRContext *g = GetCurrentContext();
     97        CRContext *g = GetCurrentContext(pState);
    9898        CRFogState *f = &(g->fog);
    99         CRStateBits *sb = GetCurrentBits();
     99        CRStateBits *sb = GetCurrentBits(pState);
    100100        CRFogBits *fb = &(sb->fog);
    101101
    102102        if (g->current.inBeginEnd)
    103103        {
    104                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glFogfv called in Begin/End");
     104                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glFogfv called in Begin/End");
    105105                return;
    106106        }
     
    115115                                if (e != GL_LINEAR && e != GL_EXP && e != GL_EXP2)
    116116                                {
    117                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid param for glFog: %d", e);
     117                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid param for glFog: %d", e);
    118118                                        return;
    119119                                }
     
    157157                                        param[0] != GL_EYE_PLANE_ABSOLUTE_NV )
    158158                                {
    159                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     159                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    160160                                                "Fogfv: GL_FOG_DISTANCE_MODE_NV called with illegal parameter: 0x%x", (GLenum) param[0]);
    161161                                        return;
     
    166166                        else
    167167                        {
    168                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Invalid glFog Param: %d", param);
     168                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Invalid glFog Param: %d", param);
    169169                                return;
    170170                        }
     
    178178                                                (GLenum) param[0] != GL_FRAGMENT_DEPTH_EXT)
    179179                                {
    180                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     180                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    181181                                                "Fogfv: GL_FOG_COORDINATE_SOURCE_EXT called with illegal parameter: 0x%x", (GLenum) param[0]);
    182182                                        return;
     
    187187                        else
    188188                        {
    189                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Invalid glFog Param: 0x%x", (GLint) param[0]);
     189                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Invalid glFog Param: 0x%x", (GLint) param[0]);
    190190                                return;
    191191                        }
     
    193193#endif
    194194                default:
    195                         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Invalid glFog Param: %d", param);
     195                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Invalid glFog Param: %d", param);
    196196                        return;
    197197        }
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_framebuffer.c

    r76553 r78375  
    3434}
    3535
    36 void STATE_APIENTRY crStateGenFramebuffersEXT(GLsizei n, GLuint *buffers)
    37 {
    38     CRContext *g = GetCurrentContext();
     36void STATE_APIENTRY crStateGenFramebuffersEXT(PCRStateTracker pState, GLsizei n, GLuint *buffers)
     37{
     38    CRContext *g = GetCurrentContext(pState);
    3939    crStateGenNames(g, g->shared->fbTable, n, buffers);
    4040}
    4141
    42 void STATE_APIENTRY crStateGenRenderbuffersEXT(GLsizei n, GLuint *buffers)
    43 {
    44     CRContext *g = GetCurrentContext();
     42void STATE_APIENTRY crStateGenRenderbuffersEXT(PCRStateTracker pState, GLsizei n, GLuint *buffers)
     43{
     44    CRContext *g = GetCurrentContext(pState);
    4545    crStateGenNames(g, g->shared->rbTable, n, buffers);
    4646}
    4747
    48 void crStateRegFramebuffers(GLsizei n, GLuint *buffers)
    49 {
    50     CRContext *g = GetCurrentContext();
     48void crStateRegFramebuffers(PCRStateTracker pState, GLsizei n, GLuint *buffers)
     49{
     50    CRContext *g = GetCurrentContext(pState);
    5151    crStateRegNames(g, g->shared->fbTable, n, buffers);
    5252}
    5353
    54 void crStateRegRenderbuffers(GLsizei n, GLuint *buffers)
    55 {
    56     CRContext *g = GetCurrentContext();
     54void crStateRegRenderbuffers(PCRStateTracker pState, GLsizei n, GLuint *buffers)
     55{
     56    CRContext *g = GetCurrentContext(pState);
    5757    crStateRegNames(g, g->shared->rbTable, n, buffers);
    5858}
     
    6363crStateFramebufferAllocate(CRContext *ctx, GLuint name)
    6464{
     65    PCRStateTracker pState = ctx->pStateTracker;
    6566    CRFramebufferObject *buffer = (CRFramebufferObject*) crCalloc(sizeof(CRFramebufferObject));
    6667    CRSTATE_CHECKERR_RET(!buffer, GL_OUT_OF_MEMORY, "crStateFramebufferAllocate", NULL);
    6768    buffer->id = name;
    6869#ifndef IN_GUEST
    69     diff_api.GenFramebuffersEXT(1, &buffer->hwid);
     70    ctx->pStateTracker->diff_api.GenFramebuffersEXT(1, &buffer->hwid);
    7071    if (!buffer->hwid)
    7172    {
     
    8889crStateRenderbufferAllocate(CRContext *ctx, GLuint name)
    8990{
     91    PCRStateTracker pState = ctx->pStateTracker;
    9092    CRRenderbufferObject *buffer = (CRRenderbufferObject*) crCalloc(sizeof(CRRenderbufferObject));
    9193    CRSTATE_CHECKERR_RET(!buffer, GL_OUT_OF_MEMORY, "crStateRenderbufferAllocate", NULL);
    9294    buffer->id = name;
    9395#ifndef IN_GUEST
    94     diff_api.GenRenderbuffersEXT(1, &buffer->hwid);
     96    ctx->pStateTracker->diff_api.GenRenderbuffersEXT(1, &buffer->hwid);
    9597    if (!buffer->hwid)
    9698    {
     
    110112}
    111113
    112 void crStateFreeFBO(void *data)
    113 {
     114void crStateFreeFBO(void *data, void *pvUser)
     115{
     116    PCRStateTracker pState = (PCRStateTracker)pvUser;
    114117    CRFramebufferObject *pObj = (CRFramebufferObject *)data;
    115118
    116119#ifndef IN_GUEST
    117     if (diff_api.DeleteFramebuffersEXT)
    118     {
    119         diff_api.DeleteFramebuffersEXT(1, &pObj->hwid);
    120     }
     120    if (pState->diff_api.DeleteFramebuffersEXT)
     121    {
     122        pState->diff_api.DeleteFramebuffersEXT(1, &pObj->hwid);
     123    }
     124#else
     125    RT_NOREF(pState);
    121126#endif
    122127
     
    124129}
    125130
    126 void crStateFreeRBO(void *data)
    127 {
     131void crStateFreeRBO(void *data, void *pvUser)
     132{
     133    PCRStateTracker pState = (PCRStateTracker)pvUser;
    128134    CRRenderbufferObject *pObj = (CRRenderbufferObject *)data;
    129135
    130136#ifndef IN_GUEST
    131     if (diff_api.DeleteRenderbuffersEXT)
    132     {
    133         diff_api.DeleteRenderbuffersEXT(1, &pObj->hwid);
    134     }
     137    if (pState->diff_api.DeleteRenderbuffersEXT)
     138    {
     139        pState->diff_api.DeleteRenderbuffersEXT(1, &pObj->hwid);
     140    }
     141#else
     142    RT_NOREF(pState);
    135143#endif
    136144
     
    149157
    150158DECLEXPORT(void) STATE_APIENTRY
    151 crStateBindRenderbufferEXT(GLenum target, GLuint renderbuffer)
    152 {
    153     CRContext *g = GetCurrentContext();
     159crStateBindRenderbufferEXT(PCRStateTracker pState, GLenum target, GLuint renderbuffer)
     160{
     161    CRContext *g = GetCurrentContext(pState);
    154162    CRFramebufferObjectState *fbo = &g->framebufferobject;
    155163
     
    170178}
    171179
    172 static void crStateCheckFBOAttachments(CRFramebufferObject *pFBO, GLuint rbo, GLenum target)
     180static void crStateCheckFBOAttachments(PCRStateTracker pState, CRFramebufferObject *pFBO, GLuint rbo, GLenum target)
    173181{
    174182    CRFBOAttachmentPoint *ap;
     
    183191        if (ap->type==GL_RENDERBUFFER_EXT && ap->name==rbo)
    184192        {
    185             crStateFramebufferRenderbufferEXT(target, u+GL_COLOR_ATTACHMENT0_EXT, 0, 0);
     193            crStateFramebufferRenderbufferEXT(pState, target, u+GL_COLOR_ATTACHMENT0_EXT, 0, 0);
    186194#ifdef IN_GUEST
    187195            pFBO->status = GL_FRAMEBUFFER_UNDEFINED;
     
    193201    if (ap->type==GL_RENDERBUFFER_EXT && ap->name==rbo)
    194202    {
    195         crStateFramebufferRenderbufferEXT(target, GL_DEPTH_ATTACHMENT_EXT, 0, 0);
     203        crStateFramebufferRenderbufferEXT(pState, target, GL_DEPTH_ATTACHMENT_EXT, 0, 0);
    196204#ifdef IN_GUEST
    197205        pFBO->status = GL_FRAMEBUFFER_UNDEFINED;
     
    201209    if (ap->type==GL_RENDERBUFFER_EXT && ap->name==rbo)
    202210    {
    203         crStateFramebufferRenderbufferEXT(target, GL_STENCIL_ATTACHMENT_EXT, 0, 0);
     211        crStateFramebufferRenderbufferEXT(pState, target, GL_STENCIL_ATTACHMENT_EXT, 0, 0);
    204212#ifdef IN_GUEST
    205213        pFBO->status = GL_FRAMEBUFFER_UNDEFINED;
     
    218226
    219227    /* check the attachments of current framebuffers */
    220     crStateCheckFBOAttachments(fbo->readFB, fboId, GL_READ_FRAMEBUFFER);
    221     crStateCheckFBOAttachments(fbo->drawFB, fboId, GL_DRAW_FRAMEBUFFER);
     228    crStateCheckFBOAttachments(g->pStateTracker, fbo->readFB, fboId, GL_READ_FRAMEBUFFER);
     229    crStateCheckFBOAttachments(g->pStateTracker, fbo->drawFB, fboId, GL_DRAW_FRAMEBUFFER);
    222230
    223231    CR_STATE_SHAREDOBJ_USAGE_CLEAR(rbo, g);
     
    225233
    226234DECLEXPORT(void) STATE_APIENTRY
    227 crStateDeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers)
    228 {
    229     CRContext *g = GetCurrentContext();
     235crStateDeleteRenderbuffersEXT(PCRStateTracker pState, GLsizei n, const GLuint *renderbuffers)
     236{
     237    CRContext *g = GetCurrentContext(pState);
    230238    /*CRFramebufferObjectState *fbo = &g->framebufferobject; - unused */
    231239    int i;
     
    251259                     * This is why g_pAvailableContexts[j] could be NULL
    252260                     * also g_pAvailableContexts[0] will hold default context, which we should discard */
    253                     CRContext *ctx = g_pAvailableContexts[j];
     261                    CRContext *ctx = pState->apAvailableContexts[j];
    254262                    if (j && ctx)
    255263                    {
     
    265273                        CR_STATE_SHAREDOBJ_USAGE_CLEAR_IDX(rbo, j);
    266274                }
    267                 crHashtableDelete(g->shared->rbTable, renderbuffers[i], crStateFreeRBO);
     275                crHashtableDeleteEx(g->shared->rbTable, renderbuffers[i], crStateFreeRBO, pState);
    268276            }
    269277        }
     
    272280
    273281DECLEXPORT(void) STATE_APIENTRY
    274 crStateRenderbufferStorageEXT(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
    275 {
    276     CRContext *g = GetCurrentContext();
     282crStateRenderbufferStorageEXT(PCRStateTracker pState, GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
     283{
     284    CRContext *g = GetCurrentContext(pState);
    277285    CRFramebufferObjectState *fbo = &g->framebufferobject;
    278286    CRRenderbufferObject *rb = fbo->renderbuffer;
     
    288296
    289297DECLEXPORT(void) STATE_APIENTRY
    290 crStateGetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params)
    291 {
    292     CRContext *g = GetCurrentContext();
     298crStateGetRenderbufferParameterivEXT(PCRStateTracker pState, GLenum target, GLenum pname, GLint *params)
     299{
     300    CRContext *g = GetCurrentContext(pState);
    293301    CRFramebufferObjectState *fbo = &g->framebufferobject;
    294302    CRRenderbufferObject *rb = fbo->renderbuffer;
     
    371379
    372380DECLEXPORT(void) STATE_APIENTRY
    373 crStateBindFramebufferEXT(GLenum target, GLuint framebuffer)
    374 {
    375     CRContext *g = GetCurrentContext();
     381crStateBindFramebufferEXT(PCRStateTracker pState, GLenum target, GLuint framebuffer)
     382{
     383    CRContext *g = GetCurrentContext(pState);
    376384    CRFramebufferObjectState *fbo = &g->framebufferobject;
    377385    CRFramebufferObject *pFBO=NULL;
     
    430438
    431439DECLEXPORT(void) STATE_APIENTRY
    432 crStateDeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers)
    433 {
    434     CRContext *g = GetCurrentContext();
     440crStateDeleteFramebuffersEXT(PCRStateTracker pState, GLsizei n, const GLuint *framebuffers)
     441{
     442    CRContext *g = GetCurrentContext(pState);
    435443    int i;
    436444
     
    456464                     * This is why g_pAvailableContexts[j] could be NULL
    457465                     * also g_pAvailableContexts[0] will hold default context, which we should discard */
    458                     CRContext *ctx = g_pAvailableContexts[j];
     466                    CRContext *ctx = pState->apAvailableContexts[j];
    459467                    if (j && ctx)
    460468                    {
     
    473481                        CR_STATE_SHAREDOBJ_USAGE_CLEAR_IDX(fb, j);
    474482                }
    475                 crHashtableDelete(g->shared->fbTable, framebuffers[i], crStateFreeFBO);
     483                crHashtableDeleteEx(g->shared->fbTable, framebuffers[i], crStateFreeFBO, pState);
    476484            }
    477485        }
     
    523531}
    524532
    525 static GLuint crStateFramebufferTextureCheck(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level,
     533static GLuint crStateFramebufferTextureCheck(CRContext *g, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level,
    526534                    CRFBOAttachmentPoint **aap, CRTextureObj **tobj)
    527535{
    528     CRContext *g = GetCurrentContext();
     536    PCRStateTracker pState = g->pStateTracker;
    529537    CRFramebufferObjectState *fbo = &g->framebufferobject;
    530538    CRFramebufferObject *apFBOs[2];
     
    565573        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
    566574            maxtexsizelog2 = crLog2Floor(g->limits.maxCubeMapTextureSize);
    567             *tobj = crStateTextureGet(GL_TEXTURE_CUBE_MAP_ARB, texture);
     575            *tobj = crStateTextureGet(pState, GL_TEXTURE_CUBE_MAP_ARB, texture);
    568576            break;
    569577        case GL_TEXTURE_RECTANGLE_ARB:
    570578            maxtexsizelog2 = 0;
    571             *tobj = crStateTextureGet(textarget, texture);
     579            *tobj = crStateTextureGet(pState, textarget, texture);
    572580            break;
    573581        case GL_TEXTURE_3D:
    574582            maxtexsizelog2 = crLog2Floor(g->limits.max3DTextureSize);
    575             *tobj = crStateTextureGet(textarget, texture);
     583            *tobj = crStateTextureGet(pState, textarget, texture);
    576584            break;
    577585        case GL_TEXTURE_2D:
    578586        case GL_TEXTURE_1D:
    579587            maxtexsizelog2 = crLog2Floor(g->limits.maxTextureSize);
    580             *tobj = crStateTextureGet(textarget, texture);
     588            *tobj = crStateTextureGet(pState, textarget, texture);
    581589            break;
    582590        default:
     
    611619
    612620DECLEXPORT(void) STATE_APIENTRY
    613 crStateFramebufferTexture1DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
    614 {
    615     CRContext *g = GetCurrentContext();
     621crStateFramebufferTexture1DEXT(PCRStateTracker pState, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
     622{
     623    CRContext *g = GetCurrentContext(pState);
    616624    /*CRFramebufferObjectState *fbo = &g->framebufferobject; - unused */
    617625    CRFBOAttachmentPoint *aap[2];
     
    619627    CRTextureObj *tobj;
    620628
    621     cap = crStateFramebufferTextureCheck(target, attachment, textarget, texture, level, aap, &tobj);
     629    cap = crStateFramebufferTextureCheck(g, target, attachment, textarget, texture, level, aap, &tobj);
    622630    if (!cap) return;
    623631
     
    645653
    646654DECLEXPORT(void) STATE_APIENTRY
    647 crStateFramebufferTexture2DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
    648 {
    649     CRContext *g = GetCurrentContext();
     655crStateFramebufferTexture2DEXT(PCRStateTracker pState, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
     656{
     657    CRContext *g = GetCurrentContext(pState);
    650658    /* CRFramebufferObjectState *fbo = &g->framebufferobject; - unused */
    651659    CRFBOAttachmentPoint *aap[2];
     
    653661    CRTextureObj *tobj;
    654662
    655     cap = crStateFramebufferTextureCheck(target, attachment, textarget, texture, level, aap, &tobj);
     663    cap = crStateFramebufferTextureCheck(g, target, attachment, textarget, texture, level, aap, &tobj);
    656664    if (!cap) return;
    657665
     
    683691
    684692DECLEXPORT(void) STATE_APIENTRY
    685 crStateFramebufferTexture3DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset)
    686 {
    687     CRContext *g = GetCurrentContext();
     693crStateFramebufferTexture3DEXT(PCRStateTracker pState, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset)
     694{
     695    CRContext *g = GetCurrentContext(pState);
    688696    /* CRFramebufferObjectState *fbo = &g->framebufferobject; - unused */
    689697    CRFBOAttachmentPoint *aap[2];
     
    691699    CRTextureObj *tobj;
    692700
    693     cap = crStateFramebufferTextureCheck(target, attachment, textarget, texture, level, aap, &tobj);
     701    cap = crStateFramebufferTextureCheck(g, target, attachment, textarget, texture, level, aap, &tobj);
    694702    if (!cap) return;
    695703
     
    719727
    720728DECLEXPORT(void) STATE_APIENTRY
    721 crStateFramebufferRenderbufferEXT(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
    722 {
    723     CRContext *g = GetCurrentContext();
     729crStateFramebufferRenderbufferEXT(PCRStateTracker pState, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
     730{
     731    CRContext *g = GetCurrentContext(pState);
    724732    CRFramebufferObjectState *fbo = &g->framebufferobject;
    725733    CRFramebufferObject *apFBOs[2];
     
    783791
    784792DECLEXPORT(void) STATE_APIENTRY
    785 crStateGetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, GLenum pname, GLint *params)
    786 {
    787     CRContext *g = GetCurrentContext();
     793crStateGetFramebufferAttachmentParameterivEXT(PCRStateTracker pState, GLenum target, GLenum attachment, GLenum pname, GLint *params)
     794{
     795    CRContext *g = GetCurrentContext(pState);
    788796    CRFramebufferObjectState *fbo = &g->framebufferobject;
    789797    CRFramebufferObject *apFBOs[2];
     
    839847}
    840848
    841 DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsFramebufferEXT( GLuint framebuffer )
    842 {
    843     CRContext *g = GetCurrentContext();
     849DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsFramebufferEXT(PCRStateTracker pState, GLuint framebuffer )
     850{
     851    CRContext *g = GetCurrentContext(pState);
    844852
    845853    FLUSH();
    846854
    847855    if (g->current.inBeginEnd) {
    848         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     856        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    849857                                 "glIsFramebufferEXT called in begin/end");
    850858        return GL_FALSE;
     
    854862}
    855863
    856 DECLEXPORT(GLboolean)  STATE_APIENTRY crStateIsRenderbufferEXT( GLuint renderbuffer )
    857 {
    858     CRContext *g = GetCurrentContext();
     864DECLEXPORT(GLboolean)  STATE_APIENTRY crStateIsRenderbufferEXT(PCRStateTracker pState, GLuint renderbuffer )
     865{
     866    CRContext *g = GetCurrentContext(pState);
    859867
    860868
     
    862870
    863871    if (g->current.inBeginEnd) {
    864         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     872        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    865873                                 "glIsRenderbufferEXT called in begin/end");
    866874        return GL_FALSE;
     
    871879
    872880DECLEXPORT(void) STATE_APIENTRY
    873 crStateGenerateMipmapEXT(GLenum target)
    874 {
     881crStateGenerateMipmapEXT(PCRStateTracker pState, GLenum target)
     882{
     883    RT_NOREF(pState);
    875884    (void)target;
    876885    /** @todo */
     
    879888static void crStateSyncRenderbuffersCB(unsigned long key, void *data1, void *data2)
    880889{
     890    PCRStateTracker pState = (PCRStateTracker)data2;
    881891    CRRenderbufferObject *pRBO = (CRRenderbufferObject*) data1;
    882     (void)key; (void)data2;
    883 
    884     diff_api.GenRenderbuffersEXT(1, &pRBO->hwid);
     892    (void)key;
     893
     894    pState->diff_api.GenRenderbuffersEXT(1, &pRBO->hwid);
    885895
    886896    if (pRBO->width && pRBO->height)
    887897    {
    888         diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, pRBO->hwid);
    889         diff_api.RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, pRBO->internalformat, pRBO->width, pRBO->height);
     898        pState->diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, pRBO->hwid);
     899        pState->diff_api.RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, pRBO->internalformat, pRBO->width, pRBO->height);
    890900    }
    891901}
     
    893903static void crStateSyncAP(CRFBOAttachmentPoint *pAP, GLenum ap, CRContext *ctx)
    894904{
     905    PCRStateTracker pState = ctx->pStateTracker;
    895906    CRRenderbufferObject *pRBO;
    896907    CRTextureObj *tobj;
     
    909920                {
    910921                    case GL_TEXTURE_1D:
    911                         diff_api.FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, ap, tobj->target, crStateGetTextureObjHWID(tobj), pAP->level);
     922                        pState->diff_api.FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, ap, tobj->target, crStateGetTextureObjHWID(pState, tobj), pAP->level);
    912923                        break;
    913924                    case GL_TEXTURE_2D:
    914925                    case GL_TEXTURE_RECTANGLE_ARB:
    915                         diff_api.FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ap, tobj->target, crStateGetTextureObjHWID(tobj), pAP->level);
     926                        pState->diff_api.FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ap, tobj->target, crStateGetTextureObjHWID(pState, tobj), pAP->level);
    916927                        break;
    917928                    case GL_TEXTURE_CUBE_MAP_ARB:
    918                         diff_api.FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ap, pAP->face, crStateGetTextureObjHWID(tobj), pAP->level);
     929                        pState->diff_api.FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ap, pAP->face, crStateGetTextureObjHWID(pState, tobj), pAP->level);
    919930                        break;
    920931                    case GL_TEXTURE_3D:
    921                         diff_api.FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, ap, tobj->target, crStateGetTextureObjHWID(tobj), pAP->level, pAP->zoffset);
     932                        pState->diff_api.FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, ap, tobj->target, crStateGetTextureObjHWID(pState, tobj), pAP->level, pAP->zoffset);
    922933                        break;
    923934                    default:
     
    932943        case GL_RENDERBUFFER_EXT:
    933944            pRBO = (CRRenderbufferObject*) crHashtableSearch(ctx->shared->rbTable, pAP->name);
    934             diff_api.FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, ap, GL_RENDERBUFFER_EXT, pRBO->hwid);
     945            pState->diff_api.FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, ap, GL_RENDERBUFFER_EXT, pRBO->hwid);
    935946            break;
    936947        case GL_NONE:
     
    945956    CRFramebufferObject *pFBO = (CRFramebufferObject*) data1;
    946957    CRContext *ctx = (CRContext*) data2;
     958    PCRStateTracker pState = ctx->pStateTracker;
    947959    GLint i;
    948960    (void)key;
    949961
    950     diff_api.GenFramebuffersEXT(1, &pFBO->hwid);
    951 
    952     diff_api.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, pFBO->hwid);
     962    pState->diff_api.GenFramebuffersEXT(1, &pFBO->hwid);
     963
     964    pState->diff_api.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, pFBO->hwid);
    953965
    954966    for (i=0; i<CR_MAX_COLOR_ATTACHMENTS; ++i)
     
    964976crStateFramebufferObjectSwitch(CRContext *from, CRContext *to)
    965977{
     978    PCRStateTracker pState = to->pStateTracker;
     979
    966980    if (to->shared->bFBOResyncNeeded)
    967981    {
    968982        to->shared->bFBOResyncNeeded = GL_FALSE;
    969983
    970         crHashtableWalk(to->shared->rbTable, crStateSyncRenderbuffersCB, NULL);
     984        crHashtableWalk(to->shared->rbTable, crStateSyncRenderbuffersCB, pState);
    971985        crHashtableWalk(to->shared->fbTable, crStateSyncFramebuffersCB, to);
    972986
    973987        if (to->framebufferobject.drawFB==to->framebufferobject.readFB)
    974988        {
    975             diff_api.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, to->framebufferobject.drawFB?
     989            pState->diff_api.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, to->framebufferobject.drawFB?
    976990                to->framebufferobject.drawFB->hwid:0);
    977991        }
    978992        else
    979993        {
    980             diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, to->framebufferobject.drawFB?
     994            pState->diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, to->framebufferobject.drawFB?
    981995                to->framebufferobject.drawFB->hwid:0);
    982996
    983             diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, to->framebufferobject.readFB?
     997            pState->diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, to->framebufferobject.readFB?
    984998                to->framebufferobject.readFB->hwid:0);
    985999        }
    9861000
    987         diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, to->framebufferobject.renderbuffer?
     1001        pState->diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, to->framebufferobject.renderbuffer?
    9881002            to->framebufferobject.renderbuffer->hwid:0);
    9891003    }
     
    9951009            if (to->framebufferobject.drawFB==to->framebufferobject.readFB)
    9961010            {
    997                 diff_api.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, to->framebufferobject.drawFB?
     1011                pState->diff_api.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, to->framebufferobject.drawFB?
    9981012                    to->framebufferobject.drawFB->hwid:0);
    9991013            }
    10001014            else
    10011015            {
    1002                 diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, to->framebufferobject.drawFB?
     1016                pState->diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, to->framebufferobject.drawFB?
    10031017                    to->framebufferobject.drawFB->hwid:0);
    10041018
    1005                 diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, to->framebufferobject.readFB?
     1019                pState->diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, to->framebufferobject.readFB?
    10061020                    to->framebufferobject.readFB->hwid:0);
    10071021            }
    10081022
    1009             diff_api.DrawBuffer(to->framebufferobject.drawFB?to->framebufferobject.drawFB->drawbuffer[0]:to->buffer.drawBuffer);
    1010             diff_api.ReadBuffer(to->framebufferobject.readFB?to->framebufferobject.readFB->readbuffer:to->buffer.readBuffer);
     1023            pState->diff_api.DrawBuffer(to->framebufferobject.drawFB?to->framebufferobject.drawFB->drawbuffer[0]:to->buffer.drawBuffer);
     1024            pState->diff_api.ReadBuffer(to->framebufferobject.readFB?to->framebufferobject.readFB->readbuffer:to->buffer.readBuffer);
    10111025        }
    10121026
    10131027        if (to->framebufferobject.renderbuffer!=from->framebufferobject.renderbuffer)
    10141028        {
    1015             diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, to->framebufferobject.renderbuffer?
     1029            pState->diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, to->framebufferobject.renderbuffer?
    10161030                to->framebufferobject.renderbuffer->hwid:0);
    10171031        }
     
    10221036crStateFramebufferObjectDisableHW(CRContext *ctx, GLuint idDrawFBO, GLuint idReadFBO)
    10231037{
     1038    PCRStateTracker pState = ctx->pStateTracker;
    10241039    GLenum idDrawBuffer = 0, idReadBuffer = 0;
    10251040
    10261041    if (ctx->framebufferobject.drawFB || idDrawFBO)
    10271042    {
    1028         diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
     1043        pState->diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
    10291044        idDrawBuffer = ctx->buffer.drawBuffer;
    10301045    }
     
    10321047    if (ctx->framebufferobject.readFB || idReadFBO)
    10331048    {
    1034         diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, 0);
     1049        pState->diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, 0);
    10351050        idReadBuffer = ctx->buffer.readBuffer;
    10361051    }
    10371052
    10381053    if (idDrawBuffer)
    1039         diff_api.DrawBuffer(idDrawBuffer);
     1054        pState->diff_api.DrawBuffer(idDrawBuffer);
    10401055    if (idReadBuffer)
    1041         diff_api.ReadBuffer(idReadBuffer);
     1056        pState->diff_api.ReadBuffer(idReadBuffer);
    10421057
    10431058    if (ctx->framebufferobject.renderbuffer)
    1044         diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
     1059        pState->diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
    10451060}
    10461061
     
    10481063crStateFramebufferObjectReenableHW(CRContext *fromCtx, CRContext *toCtx, GLuint idDrawFBO, GLuint idReadFBO)
    10491064{
     1065    PCRStateTracker pState = fromCtx ? fromCtx->pStateTracker : toCtx->pStateTracker;
    10501066    GLuint idReadBuffer = 0, idDrawBuffer = 0;
    10511067    if (!fromCtx)
     
    10551071            && fromCtx->framebufferobject.drawFB == toCtx->framebufferobject.drawFB)  /* .. and it was NOT restored properly in crStateFramebufferObjectSwitch */
    10561072    {
    1057         diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, toCtx->framebufferobject.drawFB->hwid);
     1073        pState->diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, toCtx->framebufferobject.drawFB->hwid);
    10581074        idDrawBuffer = toCtx->framebufferobject.drawFB->drawbuffer[0];
    10591075    }
    10601076    else if (idDrawFBO && !toCtx->framebufferobject.drawFB)
    10611077    {
    1062         diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, idDrawFBO);
     1078        pState->diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, idDrawFBO);
    10631079        idDrawBuffer = GL_COLOR_ATTACHMENT0;
    10641080    }
     
    10671083            && fromCtx->framebufferobject.readFB == toCtx->framebufferobject.readFB) /* .. and it was NOT restored properly in crStateFramebufferObjectSwitch */
    10681084    {
    1069         diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, toCtx->framebufferobject.readFB->hwid);
     1085        pState->diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, toCtx->framebufferobject.readFB->hwid);
    10701086        idReadBuffer = toCtx->framebufferobject.readFB->readbuffer;
    10711087    }
    10721088    else if (idReadFBO && !toCtx->framebufferobject.readFB)
    10731089    {
    1074         diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, idReadFBO);
     1090        pState->diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, idReadFBO);
    10751091        idReadBuffer = GL_COLOR_ATTACHMENT0;
    10761092    }
    10771093
    10781094    if (idDrawBuffer)
    1079         diff_api.DrawBuffer(idDrawBuffer);
     1095        pState->diff_api.DrawBuffer(idDrawBuffer);
    10801096    if (idReadBuffer)
    1081         diff_api.ReadBuffer(idReadBuffer);
     1097        pState->diff_api.ReadBuffer(idReadBuffer);
    10821098
    10831099    if (fromCtx->framebufferobject.renderbuffer /* <- the FBO state was reset in crStateFramebufferObjectDisableHW */
    10841100            && fromCtx->framebufferobject.renderbuffer==toCtx->framebufferobject.renderbuffer) /* .. and it was NOT restored properly in crStateFramebufferObjectSwitch */
    10851101    {
    1086         diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, toCtx->framebufferobject.renderbuffer->hwid);
    1087     }
    1088 }
    1089 
    1090 
    1091 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetFramebufferHWID(GLuint id)
    1092 {
    1093     CRContext *g = GetCurrentContext();
     1102        pState->diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, toCtx->framebufferobject.renderbuffer->hwid);
     1103    }
     1104}
     1105
     1106
     1107DECLEXPORT(GLuint) STATE_APIENTRY crStateGetFramebufferHWID(PCRStateTracker pState, GLuint id)
     1108{
     1109    CRContext *g = GetCurrentContext(pState);
    10941110    CRFramebufferObject *pFBO = (CRFramebufferObject*) crHashtableSearch(g->shared->fbTable, id);
    10951111#if 0 /*def DEBUG_misha*/
     
    10991115}
    11001116
    1101 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetRenderbufferHWID(GLuint id)
    1102 {
    1103     CRContext *g = GetCurrentContext();
     1117DECLEXPORT(GLuint) STATE_APIENTRY crStateGetRenderbufferHWID(PCRStateTracker pState, GLuint id)
     1118{
     1119    CRContext *g = GetCurrentContext(pState);
    11041120    CRRenderbufferObject *pRBO = (CRRenderbufferObject*) crHashtableSearch(g->shared->rbTable, id);
    11051121
     
    11271143}
    11281144
    1129 DECLEXPORT(GLuint) STATE_APIENTRY crStateFBOHWIDtoID(GLuint hwid)
    1130 {
    1131     CRContext *g = GetCurrentContext();
     1145DECLEXPORT(GLuint) STATE_APIENTRY crStateFBOHWIDtoID(PCRStateTracker pState, GLuint hwid)
     1146{
     1147    CRContext *g = GetCurrentContext(pState);
    11321148    crCheckIDHWID_t parms;
    11331149
     
    11391155}
    11401156
    1141 DECLEXPORT(GLuint) STATE_APIENTRY crStateRBOHWIDtoID(GLuint hwid)
    1142 {
    1143     CRContext *g = GetCurrentContext();
     1157DECLEXPORT(GLuint) STATE_APIENTRY crStateRBOHWIDtoID(PCRStateTracker pState, GLuint hwid)
     1158{
     1159    CRContext *g = GetCurrentContext(pState);
    11441160    crCheckIDHWID_t parms;
    11451161
     
    11521168
    11531169#ifdef IN_GUEST
    1154 DECLEXPORT(GLenum) STATE_APIENTRY crStateCheckFramebufferStatusEXT(GLenum target)
     1170DECLEXPORT(GLenum) STATE_APIENTRY crStateCheckFramebufferStatusEXT(PCRStateTracker pState, GLenum target)
    11551171{
    11561172    GLenum status = GL_FRAMEBUFFER_UNDEFINED;
    1157     CRContext *g = GetCurrentContext();
     1173    CRContext *g = GetCurrentContext(pState);
    11581174    CRFramebufferObjectState *fbo = &g->framebufferobject;
    11591175    CRFramebufferObject *pFBO=NULL;
     
    11771193}
    11781194
    1179 DECLEXPORT(GLenum) STATE_APIENTRY crStateSetFramebufferStatus(GLenum target, GLenum status)
    1180 {
    1181     CRContext *g = GetCurrentContext();
     1195DECLEXPORT(GLenum) STATE_APIENTRY crStateSetFramebufferStatus(PCRStateTracker pState, GLenum target, GLenum status)
     1196{
     1197    CRContext *g = GetCurrentContext(pState);
    11821198    CRFramebufferObjectState *fbo = &g->framebufferobject;
    11831199    CRFramebufferObject *pFBO=NULL;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_funcs.py

    r78116 r78375  
    3434#endif
    3535
    36 #define STATE_UNUSED(x) ((void)x)""")
     36#define STATE_UNUSED(x) ((void)x)
     37
     38/** Forward declaration of the stae tracker. */
     39typedef struct CRStateTracker *PCRStateTracker;""")
    3740
    3841
     
    4144        return_type = apiutil.ReturnType(func_name)
    4245        params = apiutil.Parameters(func_name)
    43         print('DECLEXPORT(%s) STATE_APIENTRY crState%s(%s);' % (return_type, func_name, apiutil.MakeDeclarationStringForDispatcher(params)))
     46        if len(params) == 0:
     47                print('DECLEXPORT(%s) STATE_APIENTRY crState%s(PCRStateTracker pState);' % (return_type, func_name))
     48        else:
     49                print('DECLEXPORT(%s) STATE_APIENTRY crState%s(PCRStateTracker pState, %s);' % (return_type, func_name, apiutil.MakeDeclarationStringForDispatcher(params)))
    4450
    4551for func_name in apiutil.AllSpecials( "state_feedback" ):
    4652        return_type = apiutil.ReturnType(func_name)
    4753        params = apiutil.Parameters(func_name)
    48         print('DECLEXPORT(%s) STATE_APIENTRY crStateFeedback%s(%s);' % (return_type, func_name, apiutil.MakeDeclarationStringForDispatcher(params)))
     54        if len(params) == 0:
     55                print('DECLEXPORT(%s) STATE_APIENTRY crStateFeedback%s(PCRStateTracker pState);' % (return_type, func_name))
     56        else:
     57                print('DECLEXPORT(%s) STATE_APIENTRY crStateFeedback%s(PCRStateTracker pState, %s);' % (return_type, func_name, apiutil.MakeDeclarationStringForDispatcher(params)))
    4958
    5059for func_name in apiutil.AllSpecials( "state_select" ):
    5160        return_type = apiutil.ReturnType(func_name)
    5261        params = apiutil.Parameters(func_name)
    53         print('DECLEXPORT(%s) STATE_APIENTRY crStateSelect%s(%s);' % (return_type, func_name, apiutil.MakeDeclarationStringForDispatcher(params)))
    54 
     62        if len(params) == 0:
     63                print('DECLEXPORT(%s) STATE_APIENTRY crStateSelect%s(PCRStateTracker pState);' % (return_type, func_name))
     64        else:
     65                print('DECLEXPORT(%s) STATE_APIENTRY crStateSelect%s(PCRStateTracker pState, %s);' % (return_type, func_name, apiutil.MakeDeclarationStringForDispatcher(params)))
    5566
    5667print("""
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_get.py

    r69392 r78375  
    146146header = """
    147147{
    148         CRContext *g = GetCurrentContext();
     148        CRContext *g = GetCurrentContext(pState);
    149149
    150150        if (g->current.inBeginEnd)
    151151        {
    152                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     152                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    153153                        "glGet called in Begin/End");
    154154                return;
     
    162162        {
    163163#if 0
    164                 crStateError(__LINE__,__FILE__, GL_INVALID_OPERATION,
     164                crStateError(pState, __LINE__,__FILE__, GL_INVALID_OPERATION,
    165165                        "Unimplemented glGet of a 'current' value" );
    166166#else
    167                 crStateCurrentRecover();/* &g->current, &sb->current, g->bitID );*/
     167                crStateCurrentRecover(pState);/* &g->current, &sb->current, g->bitID );*/
    168168               
    169169#endif
     
    175175for rettype in types:
    176176        print('')
    177         print('void STATE_APIENTRY crStateGet%sv( GLenum pname, %s *params )' % ( rettype, ctypes[rettype] ))
     177        print('void STATE_APIENTRY crStateGet%sv(PCRStateTracker pState, GLenum pname, %s *params )' % ( rettype, ctypes[rettype] ))
    178178        print(header)
    179179
     
    189189                                i += 1
    190190                except:
    191                         print('\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented glGet!");')
     191                        print('\t\t\tcrStateError(pState, __LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented glGet!");')
    192192                print("\t\t\tbreak;")
    193193
     
    216216                                i += 1
    217217                except:
    218                         print('\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented glGet!");')
     218                        print('\t\t\tcrStateError(pState, __LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented glGet!");')
    219219                if ext != 'OPENGL_VERSION_1_2':
    220220                        print("\t\t\t}")
    221221                        print("\t\t\telse {")
    222                         print('\t\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_ENUM, "glGet%sv");' % rettype)
     222                        print('\t\t\t\tcrStateError(pState, __LINE__,__FILE__,GL_INVALID_ENUM, "glGet%sv");' % rettype)
    223223                        print("\t\t\t}")
    224224                print("\t\t\tbreak;")
     
    227227
    228228        print('\t\tdefault:')
    229         print('\t\t\tcrStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGet: Unknown enum: 0x%x", pname);')
     229        print('\t\t\tcrStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGet: Unknown enum: 0x%x", pname);')
    230230        print('\t\t\treturn;')
    231231        print('\t}')
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_getstring.c

    r69392 r78375  
    1414
    1515
    16 const GLubyte * STATE_APIENTRY crStateGetString( GLenum name )
     16const GLubyte * STATE_APIENTRY crStateGetString(PCRStateTracker pState, GLenum name )
    1717{
    18         CRContext *g = GetCurrentContext();
     18        CRContext *g = GetCurrentContext(pState);
    1919        if (!g)
    2020                return NULL;
     
    4747#endif
    4848                default:
    49                         crStateError( __LINE__, __FILE__, GL_INVALID_ENUM,
     49                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    5050                                                                        "calling glGetString() with invalid name" );
    5151                        return NULL;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_glsl.c

    r78341 r78375  
    2626#include <stdio.h> /*sprintf*/
    2727
    28 static CRGLSLShader* crStateGetShaderObj(GLuint id)
    29 {
    30     CRContext *g = GetCurrentContext();
    31 
     28/**
     29 * Helper for walking the shaders hash table.
     30 */
     31typedef struct CRStateGLSLShaderWalkArgs
     32{
     33    CRGLSLProgram *pProgram;
     34    PCRStateTracker pState;
     35} CRStateGLSLShaderWalkArgs;
     36typedef CRStateGLSLShaderWalkArgs *PCRStateGLSLShaderWalkArgs;
     37
     38static CRGLSLShader* crStateGetShaderObj(CRContext *g, GLuint id)
     39{
    3240    if (!g)
    3341    {
     
    3846}
    3947
    40 static CRGLSLProgram* crStateGetProgramObj(GLuint id)
    41 {
    42     CRContext *g = GetCurrentContext();
    43 
     48static CRGLSLProgram* crStateGetProgramObj(CRContext *g, GLuint id)
     49{
    4450    if (!g)
    4551    {
     
    118124}
    119125
    120 static void crStateShaderDecRefCount(void *data)
    121 {
     126static void crStateShaderDecRefCount(void *data, void *pvUser)
     127{
     128    CRContext *g = (CRContext *)pvUser;
    122129    CRGLSLShader *pShader = (CRGLSLShader *) data;
    123130
     
    127134
    128135    if (0==pShader->refCount && pShader->deleted)
    129     {
    130         CRContext *g = GetCurrentContext();
    131136        crHashtableDelete(g->glsl.shaders, pShader->id, crStateFreeGLSLShader);
    132     }
    133137}
    134138
     
    140144    (void) key; (void)ctx;
    141145
    142     pRealShader = crStateGetShaderObj(pShader->id);
     146    pRealShader = crStateGetShaderObj(ctx, pShader->id);
    143147
    144148    if (pRealShader)
    145149    {
    146         crStateShaderDecRefCount(pRealShader);
     150        crStateShaderDecRefCount(pRealShader, ctx);
    147151    }
    148152    else
     
    152156}
    153157
    154 static void crStateFreeGLSLProgram(void *data)
    155 {
     158static void crStateFreeGLSLProgram(void *data, void *pvUser)
     159{
     160    CRContext *pCtx = (CRContext *)pvUser;
    156161    CRGLSLProgram* pProgram = (CRGLSLProgram *) data;
    157162
    158     crFreeHashtable(pProgram->currentState.attachedShaders, crStateShaderDecRefCount);
     163    crFreeHashtableEx(pProgram->currentState.attachedShaders, crStateShaderDecRefCount, pCtx);
    159164
    160165    if (pProgram->activeState.attachedShaders)
    161166    {
    162         CRContext *g = GetCurrentContext();
    163         crHashtableWalk(pProgram->activeState.attachedShaders, crStateFakeDecRefCountCB, g);
     167        crHashtableWalk(pProgram->activeState.attachedShaders, crStateFakeDecRefCountCB, pCtx);
    164168        crFreeHashtable(pProgram->activeState.attachedShaders, crStateFreeGLSLShader);
    165169    }
     
    188192DECLEXPORT(void) STATE_APIENTRY crStateGLSLDestroy(CRContext *ctx)
    189193{
    190     CRContext *g = GetCurrentContext();
     194    CRContext *g = GetCurrentContext(ctx->pStateTracker);
    191195
    192196    /** @todo hack to allow crStateFreeGLSLProgram to work correctly,
     
    196200    if (g)
    197201        VBoxTlsRefAddRef(g); /* <- ensure the g is not destroyed by the following SetCurrentContext call */
    198     SetCurrentContext(ctx);
    199 
    200     crFreeHashtable(ctx->glsl.programs, crStateFreeGLSLProgram);
     202    SetCurrentContext(ctx->pStateTracker, ctx);
     203
     204    crFreeHashtableEx(ctx->glsl.programs, crStateFreeGLSLProgram, ctx);
    201205    crFreeHashtable(ctx->glsl.shaders, crStateFreeGLSLShader);
    202206
    203     SetCurrentContext(g);
     207    SetCurrentContext(ctx->pStateTracker, g);
    204208    if (g)
    205209        VBoxTlsRefRelease(g);
     
    207211}
    208212
    209 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetShaderHWID(GLuint id)
    210 {
    211     CRGLSLShader *pShader = crStateGetShaderObj(id);
     213DECLEXPORT(GLuint) STATE_APIENTRY crStateGetShaderHWID(PCRStateTracker pState, GLuint id)
     214{
     215    CRContext *g = GetCurrentContext(pState);
     216    CRGLSLShader *pShader = crStateGetShaderObj(g, id);
    212217#ifdef IN_GUEST
    213218    CRASSERT(!pShader || pShader->hwid == id);
     
    216221}
    217222
    218 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetProgramHWID(GLuint id)
    219 {
    220     CRGLSLProgram *pProgram = crStateGetProgramObj(id);
     223DECLEXPORT(GLuint) STATE_APIENTRY crStateGetProgramHWID(PCRStateTracker pState, GLuint id)
     224{
     225    CRContext *g = GetCurrentContext(pState);
     226    CRGLSLProgram *pProgram = crStateGetProgramObj(g, id);
    221227#ifdef IN_GUEST
    222228    CRASSERT(!pProgram || pProgram->hwid == id);
     
    245251}
    246252
    247 DECLEXPORT(GLuint) STATE_APIENTRY crStateGLSLShaderHWIDtoID(GLuint hwid)
    248 {
    249     CRContext *g = GetCurrentContext();
     253DECLEXPORT(GLuint) STATE_APIENTRY crStateGLSLShaderHWIDtoID(PCRStateTracker pState, GLuint hwid)
     254{
     255    CRContext *g = GetCurrentContext(pState);
    250256    crCheckIDHWID_t parms;
    251257
     
    257263}
    258264
    259 DECLEXPORT(GLuint) STATE_APIENTRY crStateGLSLProgramHWIDtoID(GLuint hwid)
    260 {
    261     CRContext *g = GetCurrentContext();
     265DECLEXPORT(GLuint) STATE_APIENTRY crStateGLSLProgramHWIDtoID(PCRStateTracker pState, GLuint hwid)
     266{
     267    CRContext *g = GetCurrentContext(pState);
    262268    crCheckIDHWID_t parms;
    263269
     
    269275}
    270276
    271 DECLEXPORT(GLuint) STATE_APIENTRY crStateDeleteObjectARB( VBoxGLhandleARB obj )
    272 {
    273     GLuint hwId = crStateGetProgramHWID(obj);
     277DECLEXPORT(GLuint) STATE_APIENTRY crStateDeleteObjectARB(PCRStateTracker pState, VBoxGLhandleARB obj )
     278{
     279    GLuint hwId = crStateGetProgramHWID(pState, obj);
    274280    if (hwId)
    275281    {
    276         crStateDeleteProgram(obj);
     282        crStateDeleteProgram(pState, obj);
    277283    }
    278284    else
    279285    {
    280         hwId = crStateGetShaderHWID(obj);
    281         crStateDeleteShader(obj);
     286        hwId = crStateGetShaderHWID(pState, obj);
     287        crStateDeleteShader(pState, obj);
    282288    }
    283289    return hwId;
    284290}
    285291
    286 DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateShader(GLuint hwid, GLenum type)
     292DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateShader(PCRStateTracker pState, GLuint hwid, GLenum type)
    287293{
    288294    CRGLSLShader *pShader;
    289     CRContext *g = GetCurrentContext();
     295    CRContext *g = GetCurrentContext(pState);
    290296    GLuint stateId = hwid;
    291297
    292298#ifdef IN_GUEST
    293     CRASSERT(!crStateGetShaderObj(stateId));
     299    CRASSERT(!crStateGetShaderObj(g, stateId));
    294300#else
    295301    /* the proogram and shader names must not intersect because DeleteObjectARB must distinguish between them
     
    303309    }
    304310
    305     Assert((pShader = crStateGetShaderObj(stateId)) == NULL);
     311    Assert((pShader = crStateGetShaderObj(g, stateId)) == NULL);
    306312#endif
    307313
     
    326332}
    327333
    328 DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateProgram(GLuint hwid)
     334DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateProgram(PCRStateTracker pState, GLuint hwid)
    329335{
    330336    CRGLSLProgram *pProgram;
    331     CRContext *g = GetCurrentContext();
     337    CRContext *g = GetCurrentContext(pState);
    332338    GLuint stateId = hwid;
    333339
    334340#ifdef IN_GUEST
    335     pProgram = crStateGetProgramObj(stateId);
     341    pProgram = crStateGetProgramObj(g, stateId);
    336342    if (pProgram)
    337343    {
    338344        crWarning("Program object %d already exists!", stateId);
    339         crStateDeleteProgram(stateId);
    340         CRASSERT(!crStateGetProgramObj(stateId));
     345        crStateDeleteProgram(pState, stateId);
     346        CRASSERT(!crStateGetProgramObj(g, stateId));
    341347    }
    342348#else
     
    385391}
    386392
    387 DECLEXPORT(void) STATE_APIENTRY crStateCompileShader(GLuint shader)
    388 {
    389     CRGLSLShader *pShader = crStateGetShaderObj(shader);
     393DECLEXPORT(void) STATE_APIENTRY crStateCompileShader(PCRStateTracker pState, GLuint shader)
     394{
     395    CRContext *g = GetCurrentContext(pState);
     396    CRGLSLShader *pShader = crStateGetShaderObj(g, shader);
    390397    if (!pShader)
    391398    {
     
    403410}
    404411
    405 DECLEXPORT(void) STATE_APIENTRY crStateDeleteShader(GLuint shader)
    406 {
    407     CRGLSLShader *pShader = crStateGetShaderObj(shader);
     412DECLEXPORT(void) STATE_APIENTRY crStateDeleteShader(PCRStateTracker pState, GLuint shader)
     413{
     414    CRContext *g = GetCurrentContext(pState);
     415    CRGLSLShader *pShader = crStateGetShaderObj(g, shader);
    408416    if (!pShader)
    409417    {
     
    416424    if (0==pShader->refCount)
    417425    {
    418         CRContext *g = GetCurrentContext();
    419426        crHashtableDelete(g->glsl.shaders, shader, crStateFreeGLSLShader);
    420427        /* since we use programs table for key allocation key allocation, we need to
     
    425432}
    426433
    427 DECLEXPORT(void) STATE_APIENTRY crStateAttachShader(GLuint program, GLuint shader)
    428 {
    429     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     434DECLEXPORT(void) STATE_APIENTRY crStateAttachShader(PCRStateTracker pState, GLuint program, GLuint shader)
     435{
     436    CRContext *g = GetCurrentContext(pState);
     437    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    430438    CRGLSLShader *pShader;
    431439
     
    442450    }
    443451
    444     pShader = crStateGetShaderObj(shader);
     452    pShader = crStateGetShaderObj(g, shader);
    445453
    446454    if (!pShader)
     
    455463}
    456464
    457 DECLEXPORT(void) STATE_APIENTRY crStateDetachShader(GLuint program, GLuint shader)
    458 {
    459     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     465DECLEXPORT(void) STATE_APIENTRY crStateDetachShader(PCRStateTracker pState, GLuint program, GLuint shader)
     466{
     467    CRContext *g = GetCurrentContext(pState);
     468    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    460469    CRGLSLShader *pShader;
    461470
     
    479488
    480489    if (0==pShader->refCount)
    481     {
    482         CRContext *g = GetCurrentContext();
    483490        crHashtableDelete(g->glsl.shaders, shader, crStateFreeGLSLShader);
    484     }
    485 }
    486 
    487 DECLEXPORT(void) STATE_APIENTRY crStateUseProgram(GLuint program)
    488 {
    489     CRContext *g = GetCurrentContext();
     491}
     492
     493DECLEXPORT(void) STATE_APIENTRY crStateUseProgram(PCRStateTracker pState, GLuint program)
     494{
     495    CRContext *g = GetCurrentContext(pState);
    490496
    491497    if (program>0)
    492498    {
    493         CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     499        CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    494500
    495501        if (!pProgram)
     
    507513}
    508514
    509 DECLEXPORT(void) STATE_APIENTRY crStateDeleteProgram(GLuint program)
    510 {
    511     CRContext *g = GetCurrentContext();
    512     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     515DECLEXPORT(void) STATE_APIENTRY crStateDeleteProgram(PCRStateTracker pState, GLuint program)
     516{
     517    CRContext *g = GetCurrentContext(pState);
     518    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    513519
    514520    if (!pProgram)
     
    523529    }
    524530
    525     crHashtableDelete(g->glsl.programs, program, crStateFreeGLSLProgram);
    526 }
    527 
    528 DECLEXPORT(void) STATE_APIENTRY crStateValidateProgram(GLuint program)
    529 {
    530     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     531    crHashtableDeleteEx(g->glsl.programs, program, crStateFreeGLSLProgram, g);
     532}
     533
     534DECLEXPORT(void) STATE_APIENTRY crStateValidateProgram(PCRStateTracker pState, GLuint program)
     535{
     536    CRContext *g = GetCurrentContext(pState);
     537    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    531538
    532539    if (!pProgram)
     
    542549{
    543550    CRGLSLShader *pRealShader = (CRGLSLShader *) data1;
    544     CRGLSLProgram *pProgram = (CRGLSLProgram *) data2;
     551    PCRStateGLSLShaderWalkArgs pArgs = (PCRStateGLSLShaderWalkArgs)data2;
     552    PCRStateTracker pState = pArgs->pState;
    545553    CRGLSLShader *pShader;
    546554    GLint sLen=0;
     
    558566    crMemcpy(pShader, pRealShader, sizeof(*pShader));
    559567
    560     diff_api.GetShaderiv(pShader->hwid, GL_SHADER_SOURCE_LENGTH, &sLen);
     568    pState->diff_api.GetShaderiv(pShader->hwid, GL_SHADER_SOURCE_LENGTH, &sLen);
    561569    if (sLen>0)
    562570    {
    563571        pShader->source = (GLchar*) crAlloc(sLen);
    564         diff_api.GetShaderSource(pShader->hwid, sLen, NULL, pShader->source);
    565     }
    566 
    567     crHashtableAdd(pProgram->activeState.attachedShaders, key, pShader);
    568 }
    569 
    570 DECLEXPORT(void) STATE_APIENTRY crStateLinkProgram(GLuint program)
    571 {
    572     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     572        pState->diff_api.GetShaderSource(pShader->hwid, sLen, NULL, pShader->source);
     573    }
     574
     575    crHashtableAdd(pArgs->pProgram->activeState.attachedShaders, key, pShader);
     576}
     577
     578DECLEXPORT(void) STATE_APIENTRY crStateLinkProgram(PCRStateTracker pState, GLuint program)
     579{
     580    CRContext *g = GetCurrentContext(pState);
     581    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    573582    GLuint i;
     583    CRStateGLSLShaderWalkArgs Args;
    574584
    575585    if (!pProgram)
     
    584594    if (pProgram->activeState.attachedShaders)
    585595    {
    586         crHashtableWalk(pProgram->activeState.attachedShaders, crStateFakeDecRefCountCB, NULL);
     596        crHashtableWalk(pProgram->activeState.attachedShaders, crStateFakeDecRefCountCB, g);
    587597        crFreeHashtable(pProgram->activeState.attachedShaders, crStateFreeGLSLShader);
    588598        pProgram->activeState.attachedShaders = NULL;
     
    603613        return;
    604614    }
    605     crHashtableWalk(pProgram->currentState.attachedShaders, crStateCopyShaderCB, pProgram);
     615    Args.pProgram = pProgram;
     616    Args.pState   = pState;
     617    crHashtableWalk(pProgram->currentState.attachedShaders, crStateCopyShaderCB, &Args);
    606618
    607619    /*that's not a bug, note the memcpy above*/
     
    624636}
    625637
    626 DECLEXPORT(void) STATE_APIENTRY crStateBindAttribLocation(GLuint program, GLuint index, const char * name)
    627 {
    628     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     638DECLEXPORT(void) STATE_APIENTRY crStateBindAttribLocation(PCRStateTracker pState, GLuint program, GLuint index, const char * name)
     639{
     640    CRContext *g = GetCurrentContext(pState);
     641    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    629642    GLuint i;
    630643    CRGLSLAttrib *pAttribs;
     
    670683}
    671684
    672 DECLEXPORT(GLint) STATE_APIENTRY crStateGetUniformSize(GLenum type)
     685DECLEXPORT(GLint) STATE_APIENTRY crStateGetUniformSize(PCRStateTracker pState, GLenum type)
    673686{
    674687    GLint size;
     688
     689    RT_NOREF(pState);
    675690
    676691    switch (type)
     
    760775}
    761776
    762 DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsIntUniform(GLenum type)
    763 {
     777DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsIntUniform(PCRStateTracker pState, GLenum type)
     778{
     779    RT_NOREF(pState);
     780
    764781    if (GL_INT==type
    765782        || GL_INT_VEC2==type
     
    784801}
    785802
    786 DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramUniformsCached(GLuint program)
    787 {
    788     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     803DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramUniformsCached(PCRStateTracker pState, GLuint program)
     804{
     805    CRContext *g = GetCurrentContext(pState);
     806    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    789807
    790808    if (!pProgram)
     
    802820}
    803821
    804 DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramAttribsCached(GLuint program)
    805 {
    806     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     822DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramAttribsCached(PCRStateTracker pState, GLuint program)
     823{
     824    CRContext *g = GetCurrentContext(pState);
     825    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    807826
    808827    if (!pProgram)
     
    824843#ifdef IN_GUEST
    825844DECLEXPORT(void) STATE_APIENTRY
    826 crStateGLSLProgramCacheUniforms(GLuint program, GLsizei cbData, GLvoid *pData)
    827 {
    828     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     845crStateGLSLProgramCacheUniforms(PCRStateTracker pState, GLuint program, GLsizei cbData, GLvoid *pData)
     846{
     847    CRContext *g = GetCurrentContext(pState);
     848    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    829849    char *pCurrent = pData;
    830850    GLsizei cbRead, cbName;
     
    900920
    901921DECLEXPORT(void) STATE_APIENTRY
    902 crStateGLSLProgramCacheAttribs(GLuint program, GLsizei cbData, GLvoid *pData)
    903 {
    904     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     922crStateGLSLProgramCacheAttribs(PCRStateTracker pState, GLuint program, GLsizei cbData, GLvoid *pData)
     923{
     924    CRContext *g = GetCurrentContext(pState);
     925    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    905926    char *pCurrent = pData;
    906927    GLsizei cbRead, cbName;
     
    9981019
    9991020DECLEXPORT(void) STATE_APIENTRY
    1000 crStateGLSLProgramCacheUniforms(GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData)
    1001 {
    1002     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     1021crStateGLSLProgramCacheUniforms(PCRStateTracker pState, GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData)
     1022{
     1023    CRContext *g = GetCurrentContext(pState);
     1024    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    10031025    GLint maxUniformLen = 0, activeUniforms=0, fakeUniformsCount, i, j;
    10041026    char *pCurrent = pData;
     
    10151037     * "If no active uniform variable exist, 0 is returned."
    10161038     */
    1017     diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLen);
     1039    pState->diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLen);
    10181040    if (maxUniformLen > 0)
    1019         diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORMS, &activeUniforms);
     1041        pState->diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORMS, &activeUniforms);
    10201042
    10211043    *cbData = 0;
     
    10501072        for (i=0; i<activeUniforms; ++i)
    10511073        {
    1052             diff_api.GetActiveUniform(pProgram->hwid, i, maxUniformLen, &cbName, &size, &type, name);
    1053             location = diff_api.GetUniformLocation(pProgram->hwid, name);
     1074            pState->diff_api.GetActiveUniform(pProgram->hwid, i, maxUniformLen, &cbName, &size, &type, name);
     1075            location = pState->diff_api.GetUniformLocation(pProgram->hwid, name);
    10541076
    10551077            if (!crStateGLSLProgramCacheOneUniform(location, cbName, name, &pCurrent, &cbWritten, maxcbData))
     
    10881110                    cbName = crStrlen(name);
    10891111
    1090                     location = diff_api.GetUniformLocation(pProgram->hwid, name);
     1112                    location = pState->diff_api.GetUniformLocation(pProgram->hwid, name);
    10911113
    10921114                    if (!crStateGLSLProgramCacheOneUniform(location, cbName, name, &pCurrent, &cbWritten, maxcbData))
     
    11341156
    11351157DECLEXPORT(void) STATE_APIENTRY
    1136 crStateGLSLProgramCacheAttribs(GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData)
    1137 {
    1138     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     1158crStateGLSLProgramCacheAttribs(PCRStateTracker pState, GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData)
     1159{
     1160    CRContext *g = GetCurrentContext(pState);
     1161    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    11391162    GLint maxAttribLen, activeAttribs=0, fakeAttribsCount, i, j;
    11401163    char *pCurrent = pData;
     
    11471170    }
    11481171
    1149     diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttribLen);
    1150     diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_ATTRIBUTES, &activeAttribs);
     1172    pState->diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttribLen);
     1173    pState->diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_ATTRIBUTES, &activeAttribs);
    11511174
    11521175    *cbData = 0;
     
    11811204        for (i=0; i<activeAttribs; ++i)
    11821205        {
    1183             diff_api.GetActiveAttrib(pProgram->hwid, i, maxAttribLen, &cbName, &size, &type, name);
    1184             location = diff_api.GetAttribLocation(pProgram->hwid, name);
     1206            pState->diff_api.GetActiveAttrib(pProgram->hwid, i, maxAttribLen, &cbName, &size, &type, name);
     1207            location = pState->diff_api.GetAttribLocation(pProgram->hwid, name);
    11851208
    11861209            if (!crStateGLSLProgramCacheOneAttrib(location, cbName, name, &pCurrent, &cbWritten, maxcbData))
     
    12191242                    cbName = crStrlen(name);
    12201243
    1221                     location = diff_api.GetAttribLocation(pProgram->hwid, name);
     1244                    location = pState->diff_api.GetAttribLocation(pProgram->hwid, name);
    12221245
    12231246                    if (!crStateGLSLProgramCacheOneAttrib(location, cbName, name, &pCurrent, &cbWritten, maxcbData))
     
    12421265#endif
    12431266
    1244 DECLEXPORT(GLint) STATE_APIENTRY crStateGetUniformLocation(GLuint program, const char * name)
     1267DECLEXPORT(GLint) STATE_APIENTRY crStateGetUniformLocation(PCRStateTracker pState, GLuint program, const char * name)
    12451268{
    12461269#ifdef IN_GUEST
    1247     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     1270    CRContext *g = GetCurrentContext(pState);
     1271    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    12481272    GLint result=-1;
    12491273    GLuint i;
     
    12721296    return result;
    12731297#else
    1274     RT_NOREF(program, name);
     1298    RT_NOREF(pState, program, name);
    12751299    crWarning("crStateGetUniformLocation called on host side!!");
    12761300    return -1;
     
    12781302}
    12791303
    1280 DECLEXPORT(GLint) STATE_APIENTRY crStateGetAttribLocation(GLuint program, const char * name)
     1304DECLEXPORT(GLint) STATE_APIENTRY crStateGetAttribLocation(PCRStateTracker pState, GLuint program, const char * name)
    12811305{
    12821306#ifdef IN_GUEST
    1283     CRGLSLProgram *pProgram = crStateGetProgramObj(program);
     1307    CRContext *g = GetCurrentContext(pState);
     1308    CRGLSLProgram *pProgram = crStateGetProgramObj(g, program);
    12841309    GLint result=-1;
    12851310    GLuint i;
     
    13081333    return result;
    13091334#else
    1310     RT_NOREF(program, name);
     1335    RT_NOREF(pState, program, name);
    13111336    crWarning("crStateGetAttribLocation called on host side!!");
    13121337    return -1;
     
    13181343    CRGLSLShader *pShader = (CRGLSLShader*) data1;
    13191344    CRContext *ctx = (CRContext *) data2;
     1345    PCRStateTracker pState = ctx->pStateTracker;
    13201346    (void)ctx; (void)key;
    13211347
    1322     pShader->hwid = diff_api.CreateShader(pShader->type);
     1348    pShader->hwid = pState->diff_api.CreateShader(pShader->type);
    13231349}
    13241350
     
    13381364{
    13391365    CRGLSLShader *pShader = (CRGLSLShader*) data1;
     1366    PCRStateTracker pState = (PCRStateTracker)data2;
    13401367    (void) key;
    1341     (void) data2;
    13421368
    13431369    if (pShader->source)
    13441370    {
    1345         diff_api.ShaderSource(pShader->hwid, 1, (const char**)&pShader->source, NULL);
     1371        pState->diff_api.ShaderSource(pShader->hwid, 1, (const char**)&pShader->source, NULL);
    13461372        if (pShader->compiled)
    1347             diff_api.CompileShader(pShader->hwid);
     1373            pState->diff_api.CompileShader(pShader->hwid);
    13481374        crFree(pShader->source);
    13491375        pShader->source = NULL;
     
    13511377
    13521378    if (pShader->deleted)
    1353         diff_api.DeleteShader(pShader->hwid);
     1379        pState->diff_api.DeleteShader(pShader->hwid);
    13541380}
    13551381
     
    13571383{
    13581384    CRGLSLShader *pShader = (CRGLSLShader*) data1;
    1359     CRGLSLProgram *pProgram = (CRGLSLProgram *) data2;
     1385    PCRStateGLSLShaderWalkArgs pArgs = (PCRStateGLSLShaderWalkArgs)data2;
     1386    PCRStateTracker pState = pArgs->pState;
    13601387    (void) key;
    13611388
    13621389    if (pShader->source)
    13631390    {
    1364         diff_api.ShaderSource(pShader->hwid, 1, (const char**)&pShader->source, NULL);
     1391        pState->diff_api.ShaderSource(pShader->hwid, 1, (const char**)&pShader->source, NULL);
    13651392        if (pShader->compiled)
    1366             diff_api.CompileShader(pShader->hwid);
    1367     }
    1368 
    1369     diff_api.AttachShader(pProgram->hwid, pShader->hwid);
     1393            pState->diff_api.CompileShader(pShader->hwid);
     1394    }
     1395
     1396    pState->diff_api.AttachShader(pArgs->pProgram->hwid, pShader->hwid);
    13701397}
    13711398
     
    13731400{
    13741401    CRGLSLShader *pShader = (CRGLSLShader*) data1;
    1375     CRGLSLProgram *pProgram = (CRGLSLProgram *) data2;
     1402    PCRStateGLSLShaderWalkArgs pArgs = (PCRStateGLSLShaderWalkArgs)data2;
    13761403    (void) key;
    13771404
    1378     diff_api.DetachShader(pProgram->hwid, pShader->hwid);
     1405    pArgs->pState->diff_api.DetachShader(pArgs->pProgram->hwid, pShader->hwid);
    13791406}
    13801407
     
    13831410    CRGLSLProgram *pProgram = (CRGLSLProgram*) data1;
    13841411    CRContext *ctx = (CRContext *) data2;
     1412    PCRStateTracker pState = ctx->pStateTracker;
    13851413    GLuint i;
     1414    CRStateGLSLShaderWalkArgs Args;
     1415
     1416    Args.pProgram = pProgram;
     1417    Args.pState   = pState;
     1418
    13861419    (void)key;
    13871420
    1388     pProgram->hwid = diff_api.CreateProgram();
     1421    pProgram->hwid = pState->diff_api.CreateProgram();
    13891422
    13901423    if (pProgram->linked)
     
    13931426
    13941427        crHashtableWalk(pProgram->activeState.attachedShaders, crStateFixAttachedShaderHWIDsCB, ctx);
    1395         crHashtableWalk(pProgram->activeState.attachedShaders, crStateAttachShaderCB, pProgram);
     1428        crHashtableWalk(pProgram->activeState.attachedShaders, crStateAttachShaderCB, &Args);
    13961429
    13971430        for (i=0; i<pProgram->activeState.cAttribs; ++i)
    13981431        {
    1399             diff_api.BindAttribLocation(pProgram->hwid, pProgram->activeState.pAttribs[i].index, pProgram->activeState.pAttribs[i].name);
     1432            pState->diff_api.BindAttribLocation(pProgram->hwid, pProgram->activeState.pAttribs[i].index, pProgram->activeState.pAttribs[i].name);
    14001433        }
    14011434
    14021435        if (pProgram->validated)
    1403             diff_api.ValidateProgram(pProgram->hwid);
    1404 
    1405         diff_api.LinkProgram(pProgram->hwid);
    1406     }
    1407 
    1408     diff_api.UseProgram(pProgram->hwid);
     1436            pState->diff_api.ValidateProgram(pProgram->hwid);
     1437
     1438        pState->diff_api.LinkProgram(pProgram->hwid);
     1439    }
     1440
     1441    pState->diff_api.UseProgram(pProgram->hwid);
    14091442
    14101443    for (i=0; i<pProgram->cUniforms; ++i)
     
    14141447        GLint *pIdata = (GLint*)pProgram->pUniforms[i].data;
    14151448
    1416         location = diff_api.GetUniformLocation(pProgram->hwid, pProgram->pUniforms[i].name);
     1449        location = pState->diff_api.GetUniformLocation(pProgram->hwid, pProgram->pUniforms[i].name);
    14171450        switch (pProgram->pUniforms[i].type)
    14181451        {
    14191452            case GL_FLOAT:
    1420                 diff_api.Uniform1fv(location, 1, pFdata);
     1453                pState->diff_api.Uniform1fv(location, 1, pFdata);
    14211454                break;
    14221455            case GL_FLOAT_VEC2:
    1423                 diff_api.Uniform2fv(location, 1, pFdata);
     1456                pState->diff_api.Uniform2fv(location, 1, pFdata);
    14241457                break;
    14251458            case GL_FLOAT_VEC3:
    1426                 diff_api.Uniform3fv(location, 1, pFdata);
     1459                pState->diff_api.Uniform3fv(location, 1, pFdata);
    14271460                break;
    14281461            case GL_FLOAT_VEC4:
    1429                 diff_api.Uniform4fv(location, 1, pFdata);
     1462                pState->diff_api.Uniform4fv(location, 1, pFdata);
    14301463                break;
    14311464            case GL_INT:
    14321465            case GL_BOOL:
    1433                 diff_api.Uniform1iv(location, 1, pIdata);
     1466                pState->diff_api.Uniform1iv(location, 1, pIdata);
    14341467                break;
    14351468            case GL_INT_VEC2:
    14361469            case GL_BOOL_VEC2:
    1437                 diff_api.Uniform2iv(location, 1, pIdata);
     1470                pState->diff_api.Uniform2iv(location, 1, pIdata);
    14381471                break;
    14391472            case GL_INT_VEC3:
    14401473            case GL_BOOL_VEC3:
    1441                 diff_api.Uniform3iv(location, 1, pIdata);
     1474                pState->diff_api.Uniform3iv(location, 1, pIdata);
    14421475                break;
    14431476            case GL_INT_VEC4:
    14441477            case GL_BOOL_VEC4:
    1445                 diff_api.Uniform4iv(location, 1, pIdata);
     1478                pState->diff_api.Uniform4iv(location, 1, pIdata);
    14461479                break;
    14471480            case GL_FLOAT_MAT2:
    1448                 diff_api.UniformMatrix2fv(location, 1, GL_FALSE, pFdata);
     1481                pState->diff_api.UniformMatrix2fv(location, 1, GL_FALSE, pFdata);
    14491482                break;
    14501483            case GL_FLOAT_MAT3:
    1451                 diff_api.UniformMatrix3fv(location, 1, GL_FALSE, pFdata);
     1484                pState->diff_api.UniformMatrix3fv(location, 1, GL_FALSE, pFdata);
    14521485                break;
    14531486            case GL_FLOAT_MAT4:
    1454                 diff_api.UniformMatrix4fv(location, 1, GL_FALSE, pFdata);
     1487                pState->diff_api.UniformMatrix4fv(location, 1, GL_FALSE, pFdata);
    14551488                break;
    14561489            case GL_SAMPLER_1D:
     
    14621495            case GL_SAMPLER_2D_RECT_ARB:
    14631496            case GL_SAMPLER_2D_RECT_SHADOW_ARB:
    1464                 diff_api.Uniform1iv(location, 1, pIdata);
     1497                pState->diff_api.Uniform1iv(location, 1, pIdata);
    14651498                break;
    14661499#ifdef CR_OPENGL_VERSION_2_1
    14671500            case GL_FLOAT_MAT2x3:
    1468                 diff_api.UniformMatrix2x3fv(location, 1, GL_FALSE, pFdata);
     1501                pState->diff_api.UniformMatrix2x3fv(location, 1, GL_FALSE, pFdata);
    14691502                break;
    14701503            case GL_FLOAT_MAT2x4:
    1471                 diff_api.UniformMatrix2x4fv(location, 1, GL_FALSE, pFdata);
     1504                pState->diff_api.UniformMatrix2x4fv(location, 1, GL_FALSE, pFdata);
    14721505                break;
    14731506            case GL_FLOAT_MAT3x2:
    1474                 diff_api.UniformMatrix3x2fv(location, 1, GL_FALSE, pFdata);
     1507                pState->diff_api.UniformMatrix3x2fv(location, 1, GL_FALSE, pFdata);
    14751508                break;
    14761509            case GL_FLOAT_MAT3x4:
    1477                 diff_api.UniformMatrix3x4fv(location, 1, GL_FALSE, pFdata);
     1510                pState->diff_api.UniformMatrix3x4fv(location, 1, GL_FALSE, pFdata);
    14781511                break;
    14791512            case GL_FLOAT_MAT4x2:
    1480                 diff_api.UniformMatrix4x2fv(location, 1, GL_FALSE, pFdata);
     1513                pState->diff_api.UniformMatrix4x2fv(location, 1, GL_FALSE, pFdata);
    14811514                break;
    14821515            case GL_FLOAT_MAT4x3:
    1483                 diff_api.UniformMatrix4x3fv(location, 1, GL_FALSE, pFdata);
     1516                pState->diff_api.UniformMatrix4x3fv(location, 1, GL_FALSE, pFdata);
    14841517                break;
    14851518#endif
     
    14961529
    14971530    crHashtableWalk(pProgram->activeState.attachedShaders, crStateDetachShaderCB, pProgram);
    1498     crHashtableWalk(pProgram->currentState.attachedShaders, crStateAttachShaderCB, pProgram);
     1531    crHashtableWalk(pProgram->currentState.attachedShaders, crStateAttachShaderCB, &Args);
    14991532}
    15001533
    15011534DECLEXPORT(void) STATE_APIENTRY crStateGLSLSwitch(CRContext *from, CRContext *to)
    15021535{
     1536    PCRStateTracker pState = to->pStateTracker;
    15031537    GLboolean fForceUseProgramSet = GL_FALSE;
    15041538    if (to->glsl.bResyncNeeded)
     
    15131547        fForceUseProgramSet = GL_TRUE;
    15141548
    1515         crHashtableWalk(to->glsl.shaders, crStateGLSLSyncShadersCB, NULL);
     1549        crHashtableWalk(to->glsl.shaders, crStateGLSLSyncShadersCB, pState);
    15161550    }
    15171551
    15181552    if (to->glsl.activeProgram != from->glsl.activeProgram || fForceUseProgramSet)
    15191553    {
    1520         diff_api.UseProgram(to->glsl.activeProgram ? to->glsl.activeProgram->hwid : 0);
    1521     }
    1522 }
     1554        pState->diff_api.UseProgram(to->glsl.activeProgram ? to->glsl.activeProgram->hwid : 0);
     1555    }
     1556}
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_hint.c

    r69392 r78375  
    1313{
    1414        CRHintState *h = &ctx->hint;
    15         CRStateBits *sb = GetCurrentBits();
     15        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    1616        CRHintBits *hb = &(sb->hint);
    1717
     
    4141}
    4242
    43 void STATE_APIENTRY crStateHint(GLenum target, GLenum mode)
     43void STATE_APIENTRY crStateHint(PCRStateTracker pState, GLenum target, GLenum mode)
    4444{
    45         CRContext *g = GetCurrentContext();
     45        CRContext *g = GetCurrentContext(pState);
    4646        CRHintState *h = &(g->hint);
    47         CRStateBits *sb = GetCurrentBits();
     47        CRStateBits *sb = GetCurrentBits(pState);
    4848        CRHintBits *hb = &(sb->hint);
    4949
    5050        if (g->current.inBeginEnd)
    5151        {
    52                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     52                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    5353                                         "glHint called in Begin/End");
    5454                return;
     
    5858
    5959        if (mode != GL_FASTEST && mode != GL_NICEST && mode != GL_DONT_CARE) {
    60                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     60                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    6161                                         "glHint(mode)");
    6262                return;
     
    9191                }
    9292                else {
    93                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     93                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    9494                                                 "glHint(target)");
    9595                        return;
     
    104104                }
    105105                else {
    106                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     106                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    107107                                                 "glHint(target)");
    108108                        return;
     
    117117                }
    118118                else {
    119                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     119                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    120120                                                 "glHint(target)");
    121121                        return;
     
    124124#endif
    125125        default:
    126                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     126                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    127127                                         "glHint(target)");
    128128                return;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c

    r78341 r78375  
    1111
    1212#include <iprt/asm.h>
    13 
    14 static bool __isContextTLSInited = false;
    15 CRtsd __contextTSD;
    16 
    17 CRStateBits *__currentBits = NULL;
    18 CRContext *g_pAvailableContexts[CR_MAX_CONTEXTS];
    19 uint32_t g_cContexts = 0;
    20 
    21 static CRSharedState *gSharedState=NULL;
    22 
    23 static CRContext *defaultContext = NULL;
    24 
    25 GLboolean g_bVBoxEnableDiffOnMakeCurrent = GL_TRUE;
    26 
    2713
    2814/**
     
    5036 */
    5137DECLEXPORT(void)
    52 crStateDeleteTextureCallback(void *texObj)
    53 {
     38crStateDeleteTextureCallback(void *texObj, void *pvUser)
     39{
     40    PCRStateTracker pState = (PCRStateTracker)pvUser;
     41
    5442#ifndef IN_GUEST
    55     diff_api.DeleteTextures(1, &((CRTextureObj *)texObj)->hwid);
     43    pState->diff_api.DeleteTextures(1, &((CRTextureObj *)texObj)->hwid);
    5644#endif
    5745    crStateDeleteTextureObject((CRTextureObj *) texObj);
     
    6048typedef struct CR_STATE_RELEASEOBJ
    6149{
    62     CRContext *pCtx;
    63     CRSharedState *s;
     50    PCRStateTracker pState;
     51    CRContext       *pCtx;
     52    CRSharedState   *s;
    6453} CR_STATE_RELEASEOBJ, *PCR_STATE_RELEASEOBJ;
    6554
    66 void crStateOnTextureUsageRelease(CRSharedState *pS, CRTextureObj *pObj)
     55void crStateOnTextureUsageRelease(PCRStateTracker pState, CRSharedState *pS, CRTextureObj *pObj)
    6756{
    6857    if (!pObj->pinned)
    69         crHashtableDelete(pS->textureTable, pObj->id, crStateDeleteTextureCallback);
     58        crHashtableDeleteEx(pS->textureTable, pObj->id, crStateDeleteTextureCallback, pState);
    7059    else
    7160        Assert(crHashtableSearch(pS->textureTable, pObj->id));
     
    7968        return;
    8069
    81     crStateOnTextureUsageRelease(pS, pObj);
     70    crStateOnTextureUsageRelease(pCtx->pStateTracker, pS, pObj);
    8271}
    8372
     
    8978        return;
    9079
    91     if (!gSharedState)
     80    if (!pCtx->pStateTracker->pSharedState)
    9281    {
    9382        WARN(("no global shared"));
     
    9584    }
    9685
    97     crStateOnTextureUsageRelease(gSharedState, pObj);
     86    crStateOnTextureUsageRelease(pCtx->pStateTracker, pCtx->pStateTracker->pSharedState, pObj);
    9887}
    9988
     
    10392    CR_STATE_SHAREDOBJ_USAGE_CLEAR(pObj, pCtx);
    10493    if (!CR_STATE_SHAREDOBJ_USAGE_IS_USED(pObj))
    105         crHashtableDelete(pS->buffersTable, pObj->id, crStateFreeBufferObject);
     94        crHashtableDeleteEx(pS->buffersTable, pObj->id, crStateFreeBufferObject, pCtx->pStateTracker);
    10695}
    10796
     
    111100    CR_STATE_SHAREDOBJ_USAGE_CLEAR(pObj, pCtx);
    112101    if (!CR_STATE_SHAREDOBJ_USAGE_IS_USED(pObj))
    113         crHashtableDelete(pS->fbTable, pObj->id, crStateFreeFBO);
     102        crHashtableDeleteEx(pS->fbTable, pObj->id, crStateFreeFBO, pCtx->pStateTracker);
    114103}
    115104
     
    119108    CR_STATE_SHAREDOBJ_USAGE_CLEAR(pObj, pCtx);
    120109    if (!CR_STATE_SHAREDOBJ_USAGE_IS_USED(pObj))
    121         crHashtableDelete(pS->rbTable, pObj->id, crStateFreeRBO);
     110        crHashtableDeleteEx(pS->rbTable, pObj->id, crStateFreeRBO, pCtx->pStateTracker);
    122111}
    123112
     
    159148 */
    160149#ifndef IN_GUEST
    161 DECLEXPORT(void) crStateFreeShared(CRContext *pContext, CRSharedState *s)
     150DECLEXPORT(void) crStateFreeShared(PCRStateTracker pState, CRContext *pContext, CRSharedState *s)
    162151#else
    163 static void crStateFreeShared(CRContext *pContext, CRSharedState *s)
     152static void crStateFreeShared(PCRStateTracker pState, CRContext *pContext, CRSharedState *s)
    164153#endif
    165154{
     
    168157    Assert(refCount >= 0);
    169158    if (refCount <= 0) {
    170         if (s==gSharedState)
    171         {
    172             gSharedState = NULL;
    173         }
    174         crFreeHashtable(s->textureTable, crStateDeleteTextureCallback);
     159        if (s == pState->pSharedState)
     160            pState->pSharedState = NULL;
     161        crFreeHashtableEx(s->textureTable, crStateDeleteTextureCallback, pState);
    175162        crFreeHashtable(s->dlistTable, crFree); /* call crFree for each entry */
    176         crFreeHashtable(s->buffersTable, crStateFreeBufferObject);
    177         crFreeHashtable(s->fbTable, crStateFreeFBO);
    178         crFreeHashtable(s->rbTable, crStateFreeRBO);
     163        crFreeHashtableEx(s->buffersTable, crStateFreeBufferObject, pState);
     164        crFreeHashtableEx(s->fbTable, crStateFreeFBO, pState);
     165        crFreeHashtableEx(s->rbTable, crStateFreeRBO, pState);
    179166        crFree(s);
    180167    }
     
    183170        /* evaluate usage bits*/
    184171        CR_STATE_RELEASEOBJ CbData;
    185         CbData.pCtx = pContext;
    186         CbData.s = s;
     172        CbData.pState = pState;
     173        CbData.pCtx   = pContext;
     174        CbData.s      = s;
    187175        crHashtableWalk(s->textureTable, ReleaseTextureCallback, &CbData);
    188176        crHashtableWalk(s->buffersTable, ReleaseBufferObjectCallback , &CbData);
     
    194182#ifndef IN_GUEST
    195183
    196 DECLEXPORT(CRSharedState *) crStateGlobalSharedAcquire(void)
    197 {
    198     if (!gSharedState)
     184DECLEXPORT(CRSharedState *) crStateGlobalSharedAcquire(PCRStateTracker pState)
     185{
     186    if (!pState->pSharedState)
    199187    {
    200188        crWarning("No Global Shared State!");
    201189        return NULL;
    202190    }
    203     ASMAtomicIncS32(&gSharedState->refCount);
    204     return gSharedState;
    205 }
    206 
    207 DECLEXPORT(void) crStateGlobalSharedRelease(void)
    208 {
    209     crStateFreeShared(NULL, gSharedState);
     191    ASMAtomicIncS32(&pState->pSharedState->refCount);
     192    return pState->pSharedState;
     193}
     194
     195DECLEXPORT(void) crStateGlobalSharedRelease(PCRStateTracker pState)
     196{
     197    crStateFreeShared(pState, NULL, pState->pSharedState);
    210198}
    211199
    212200#endif /* IN_GUEST */
    213201
    214 DECLEXPORT(void) STATE_APIENTRY
    215 crStateShareContext(GLboolean value)
    216 {
    217     CRContext *pCtx = GetCurrentContext();
     202DECLEXPORT(void) STATE_APIENTRY crStateShareContext(PCRStateTracker pState, GLboolean value)
     203{
     204    CRContext *pCtx = GetCurrentContext(pState);
    218205    CRASSERT(pCtx && pCtx->shared);
    219206
    220207    if (value)
    221208    {
    222         if (pCtx->shared == gSharedState)
     209        if (pCtx->shared == pState->pSharedState)
    223210        {
    224211            return;
     
    227214        crDebug("Context(%i) shared", pCtx->id);
    228215
    229         if (!gSharedState)
    230         {
    231             gSharedState = pCtx->shared;
     216        if (!pState->pSharedState)
     217        {
     218            pState->pSharedState = pCtx->shared;
    232219        }
    233220        else
    234221        {
    235             crStateFreeShared(pCtx, pCtx->shared);
    236             pCtx->shared = gSharedState;
    237             ASMAtomicIncS32(&gSharedState->refCount);
     222            crStateFreeShared(pState, pCtx, pCtx->shared);
     223            pCtx->shared = pState->pSharedState;
     224            ASMAtomicIncS32(&pState->pSharedState->refCount);
    238225        }
    239226    }
    240227    else
    241228    {
    242         if (pCtx->shared != gSharedState)
     229        if (pCtx->shared != pState->pSharedState)
    243230        {
    244231            return;
     
    247234        crDebug("Context(%i) unshared", pCtx->id);
    248235
    249         if (gSharedState->refCount==1)
    250         {
    251             gSharedState = NULL;
     236        if (pState->pSharedState->refCount==1)
     237        {
     238            pState->pSharedState = NULL;
    252239        }
    253240        else
     
    255242            pCtx->shared = crStateAllocShared();
    256243            pCtx->shared->id = pCtx->id;
    257             crStateFreeShared(pCtx, gSharedState);
    258         }
    259     }
    260 }
    261 
    262 DECLEXPORT(void) STATE_APIENTRY
    263 crStateShareLists(CRContext *pContext1, CRContext *pContext2)
     244            crStateFreeShared(pState, pCtx, pState->pSharedState);
     245        }
     246    }
     247}
     248
     249DECLEXPORT(void) STATE_APIENTRY crStateShareLists(CRContext *pContext1, CRContext *pContext2)
    264250{
    265251    CRASSERT(pContext1->shared);
     
    271257    }
    272258
    273     crStateFreeShared(pContext1, pContext1->shared);
     259    crStateFreeShared(pContext1->pStateTracker, pContext1, pContext1->shared);
    274260    pContext1->shared = pContext2->shared;
    275261    ASMAtomicIncS32(&pContext2->shared->refCount);
    276262}
    277263
    278 DECLEXPORT(GLboolean) STATE_APIENTRY
    279 crStateContextIsShared(CRContext *pCtx)
    280 {
    281     return pCtx->shared==gSharedState;
    282 }
    283 
    284 DECLEXPORT(void) STATE_APIENTRY
    285 crStateSetSharedContext(CRContext *pCtx)
    286 {
    287     if (gSharedState)
    288     {
    289         crWarning("crStateSetSharedContext: shared is being changed from %p to %p", gSharedState, pCtx->shared);
    290     }
    291 
    292     gSharedState = pCtx->shared;
     264DECLEXPORT(GLboolean) STATE_APIENTRY crStateContextIsShared(CRContext *pCtx)
     265{
     266    return pCtx->shared == pCtx->pStateTracker->pSharedState;
     267}
     268
     269DECLEXPORT(void) STATE_APIENTRY crStateSetSharedContext(CRContext *pCtx)
     270{
     271    PCRStateTracker pState = pCtx->pStateTracker;
     272
     273    if (pState->pSharedState)
     274    {
     275        crWarning("crStateSetSharedContext: shared is being changed from %p to %p", pState->pSharedState, pCtx->shared);
     276    }
     277
     278    pState->pSharedState = pCtx->shared;
    293279}
    294280
     
    304290 */
    305291static CRContext *
    306 crStateCreateContextId(int i, const CRLimitsState *limits, GLint visBits, CRContext *shareCtx)
     292crStateCreateContextId(PCRStateTracker pState, int i, const CRLimitsState *limits, GLint visBits, CRContext *shareCtx)
    307293{
    308294    CRContext *ctx;
     
    312298    (void)limits;
    313299
    314     if (g_pAvailableContexts[i] != NULL)
     300    if (pState->apAvailableContexts[i] != NULL)
    315301    {
    316302        crWarning("trying to create context with used id");
     
    324310        return NULL;
    325311    }
    326     g_pAvailableContexts[i] = ctx;
    327     ++g_cContexts;
    328     CRASSERT(g_cContexts < RT_ELEMENTS(g_pAvailableContexts));
     312    pState->apAvailableContexts[i] = ctx;
     313    pState->cContexts++;
     314    CRASSERT(pState->cContexts < RT_ELEMENTS(pState->apAvailableContexts));
    329315    ctx->id = i;
     316    ctx->pStateTracker = pState;
    330317    VBoxTlsRefInit(ctx, crStateContextDtor);
    331318    ctx->flush_func = NULL;
     
    432419crStateFreeContext(CRContext *ctx)
    433420{
     421    PCRStateTracker pState = ctx->pStateTracker;
     422
    434423#ifndef DEBUG_misha
    435     CRASSERT(g_pAvailableContexts[ctx->id] == ctx);
     424    CRASSERT(pState->apAvailableContexts[ctx->id] == ctx);
    436425#endif
    437     if (g_pAvailableContexts[ctx->id] == ctx)
    438     {
    439         g_pAvailableContexts[ctx->id] = NULL;
    440         --g_cContexts;
    441         CRASSERT(g_cContexts < RT_ELEMENTS(g_pAvailableContexts));
     426    if (pState->apAvailableContexts[ctx->id] == ctx)
     427    {
     428        pState->apAvailableContexts[ctx->id] = NULL;
     429        pState->cContexts--;
     430        CRASSERT(pState->cContexts < RT_ELEMENTS(pState->apAvailableContexts));
    442431    }
    443432    else
     
    458447    crStateTextureDestroy( ctx );
    459448    crStateTransformDestroy( ctx );
    460     crStateFreeShared(ctx, ctx->shared);
     449    crStateFreeShared(pState, ctx, ctx->shared);
    461450    crStateFramebufferObjectDestroy(ctx);
    462451    crStateGLSLDestroy(ctx);
     
    483472 * pointer somewhere.
    484473 */
    485 void crStateInit(void)
     474void crStateInit(PCRStateTracker pState)
    486475{
    487476    unsigned int i;
    488477
    489478    /* Purely initialize the context bits */
    490     if (!__currentBits) {
    491         __currentBits = (CRStateBits *) crCalloc( sizeof(CRStateBits) );
    492         crStateClientInitBits( &(__currentBits->client) );
    493         crStateLightingInitBits( &(__currentBits->lighting) );
     479    if (!pState->pCurrentBits) {
     480        pState->fVBoxEnableDiffOnMakeCurrent = GL_TRUE;
     481        pState->pCurrentBits = (CRStateBits *) crCalloc( sizeof(CRStateBits) );
     482        crStateClientInitBits( &(pState->pCurrentBits->client) );
     483        crStateLightingInitBits( &(pState->pCurrentBits->lighting) );
    494484    } else
    495485    {
     
    500490
    501491    for (i=0;i<CR_MAX_CONTEXTS;i++)
    502         g_pAvailableContexts[i] = NULL;
    503     g_cContexts = 0;
    504 
    505     if (!__isContextTLSInited)
     492        pState->apAvailableContexts[i] = NULL;
     493    pState->cContexts = 0;
     494
     495    if (!pState->fContextTLSInit)
    506496    {
    507497# ifndef RT_OS_WINDOWS
    508498        /* tls destructor is implemented for all platforms except windows*/
    509         crInitTSDF(&__contextTSD, crStateThreadTlsDtor);
     499        crInitTSDF(&pState->contextTSD, crStateThreadTlsDtor);
    510500# else
    511501        /* windows should do cleanup via DllMain THREAD_DETACH notification */
    512         crInitTSD(&__contextTSD);
     502        crInitTSD(&pState->contextTSD);
    513503# endif
    514         __isContextTLSInited = 1;
    515     }
    516 
    517     if (defaultContext) {
     504        pState->fContextTLSInit = true;
     505    }
     506
     507    if (pState->pDefaultContext) {
    518508        /* Free the default/NULL context.
    519509         * Ensures context bits are reset */
    520         SetCurrentContext(NULL);
    521         VBoxTlsRefRelease(defaultContext);
     510        SetCurrentContext(pState, NULL);
     511        VBoxTlsRefRelease(pState->pDefaultContext);
    522512    }
    523513
    524514    /* Reset diff_api */
    525     crMemZero(&diff_api, sizeof(SPUDispatchTable));
    526 
    527     Assert(!gSharedState);
    528     gSharedState = NULL;
     515    crMemZero(&pState->diff_api, sizeof(SPUDispatchTable));
     516
     517    Assert(!pState->pSharedState);
     518    pState->pSharedState = NULL;
    529519
    530520    /* Allocate the default/NULL context */
    531     CRASSERT(g_pAvailableContexts[0] == NULL);
    532     defaultContext = crStateCreateContextId(0, NULL, CR_RGB_BIT, NULL);
    533     CRASSERT(g_pAvailableContexts[0] == defaultContext);
    534     CRASSERT(g_cContexts == 1);
    535     SetCurrentContext(defaultContext);
    536 }
    537 
    538 void crStateDestroy(void)
     521    CRASSERT(pState->apAvailableContexts[0] == NULL);
     522    pState->pDefaultContext = crStateCreateContextId(pState, 0, NULL, CR_RGB_BIT, NULL);
     523    CRASSERT(pState->apAvailableContexts[0] == pState->pDefaultContext);
     524    CRASSERT(pState->cContexts == 1);
     525    SetCurrentContext(pState, pState->pDefaultContext);
     526}
     527
     528void crStateDestroy(PCRStateTracker pState)
    539529{
    540530    int i;
    541     if (__currentBits)
    542     {
    543         crStateClientDestroyBits(&(__currentBits->client));
    544         crStateLightingDestroyBits(&(__currentBits->lighting));
    545         crFree(__currentBits);
    546         __currentBits = NULL;
    547     }
    548 
    549     SetCurrentContext(NULL);
     531    if (pState->pCurrentBits)
     532    {
     533        crStateClientDestroyBits(&(pState->pCurrentBits->client));
     534        crStateLightingDestroyBits(&(pState->pCurrentBits->lighting));
     535        crFree(pState->pCurrentBits);
     536        pState->pCurrentBits = NULL;
     537    }
     538
     539    SetCurrentContext(pState, NULL);
    550540
    551541    for (i = CR_MAX_CONTEXTS-1; i >= 0; i--)
    552542    {
    553         if (g_pAvailableContexts[i])
    554         {
    555             if (VBoxTlsRefIsFunctional(g_pAvailableContexts[i]))
    556                 VBoxTlsRefRelease(g_pAvailableContexts[i]);
     543        if (pState->apAvailableContexts[i])
     544        {
     545            if (VBoxTlsRefIsFunctional(pState->apAvailableContexts[i]))
     546                VBoxTlsRefRelease(pState->apAvailableContexts[i]);
    557547        }
    558548    }
    559549
    560550    /* default context was stored in g_pAvailableContexts[0], so it was destroyed already */
    561     defaultContext = NULL;
    562 
    563 
    564     crFreeTSD(&__contextTSD);
    565     __isContextTLSInited = 0;
     551    pState->pDefaultContext = NULL;
     552
     553
     554    crFreeTSD(&pState->contextTSD);
     555    pState->fContextTLSInit = false;
    566556}
    567557
     
    610600
    611601CRContext *
    612 crStateCreateContext(const CRLimitsState *limits, GLint visBits, CRContext *share)
    613 {
    614     return crStateCreateContextEx(limits, visBits, share, -1);
     602crStateCreateContext(PCRStateTracker pState, const CRLimitsState *limits, GLint visBits, CRContext *share)
     603{
     604    return crStateCreateContextEx(pState, limits, visBits, share, -1);
    615605}
    616606
    617607CRContext *
    618 crStateCreateContextEx(const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID)
     608crStateCreateContextEx(PCRStateTracker pState, const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID)
    619609{
    620610    /* Must have created the default context via crStateInit() first */
    621     CRASSERT(defaultContext);
     611    CRASSERT(pState->pDefaultContext);
    622612
    623613    if (presetID>0)
    624614    {
    625         if(g_pAvailableContexts[presetID])
     615        if(pState->apAvailableContexts[presetID])
    626616        {
    627617            crWarning("requesting to create context with already allocated id");
     
    635625        for (i = 1 ; i < CR_MAX_CONTEXTS ; i++)
    636626        {
    637             if (!g_pAvailableContexts[i])
     627            if (!pState->apAvailableContexts[i])
    638628            {
    639629                presetID = i;
     
    651641    }
    652642
    653     return crStateCreateContextId(presetID, limits, visBits, share);
    654 }
    655 
    656 void crStateDestroyContext( CRContext *ctx )
    657 {
    658     CRContext *current = GetCurrentContext();
     643    return crStateCreateContextId(pState, presetID, limits, visBits, share);
     644}
     645
     646void crStateDestroyContext(PCRStateTracker pState, CRContext *ctx )
     647{
     648    CRContext *current = GetCurrentContext(pState);
    659649
    660650    if (current == ctx) {
    661651        /* destroying the current context - have to be careful here */
    662         CRASSERT(defaultContext);
     652        CRASSERT(pState->pDefaultContext);
    663653        /* Check to see if the differencer exists first,
    664654           we may not have one, aka the packspu */
    665         if (diff_api.AlphaFunc)
    666             crStateSwitchContext(current, defaultContext);
    667 
    668         SetCurrentContext(defaultContext);
     655        if (pState->diff_api.AlphaFunc)
     656            crStateSwitchContext(current, pState->pDefaultContext);
     657
     658        SetCurrentContext(pState, pState->pDefaultContext);
    669659        /* ensure matrix state is also current */
    670         crStateMatrixMode(defaultContext->transform.matrixMode);
     660        crStateMatrixMode(pState, pState->pDefaultContext->transform.matrixMode);
    671661    }
    672662
    673663    VBoxTlsRefMarkDestroy(ctx);
    674664# ifdef IN_GUEST
    675     if (VBoxTlsRefCountGet(ctx) > 1 && ctx->shared == gSharedState)
     665    if (VBoxTlsRefCountGet(ctx) > 1 && ctx->shared == pState->pSharedState)
    676666    {
    677667        /* we always need to free the global shared state to prevent the situation when guest thinks the shared objects are still valid, while host destroys them */
    678         crStateFreeShared(ctx, ctx->shared);
     668        crStateFreeShared(pState, ctx, ctx->shared);
    679669        ctx->shared = crStateAllocShared();
    680670    }
     
    683673}
    684674
    685 GLboolean crStateEnableDiffOnMakeCurrent(GLboolean fEnable)
    686 {
    687     GLboolean bOld = g_bVBoxEnableDiffOnMakeCurrent;
    688     g_bVBoxEnableDiffOnMakeCurrent = fEnable;
     675GLboolean crStateEnableDiffOnMakeCurrent(PCRStateTracker pState, GLboolean fEnable)
     676{
     677    GLboolean bOld = pState->fVBoxEnableDiffOnMakeCurrent;
     678    pState->fVBoxEnableDiffOnMakeCurrent = fEnable;
    689679    return bOld;
    690680}
    691681
    692 void crStateMakeCurrent( CRContext *ctx )
    693 {
    694     CRContext *current = GetCurrentContext();
     682void crStateMakeCurrent(PCRStateTracker pState, CRContext *ctx )
     683{
     684    CRContext *current = GetCurrentContext(pState);
    695685    CRContext *pLocalCtx = ctx;
    696686
    697687    if (pLocalCtx == NULL)
    698         pLocalCtx = defaultContext;
     688        pLocalCtx = pState->pDefaultContext;
    699689
    700690    if (current == pLocalCtx)
     
    703693    CRASSERT(pLocalCtx);
    704694
    705     if (g_bVBoxEnableDiffOnMakeCurrent && current) {
     695    if (pState->fVBoxEnableDiffOnMakeCurrent && current) {
    706696        /* Check to see if the differencer exists first,
    707697           we may not have one, aka the packspu */
    708         if (diff_api.AlphaFunc)
    709             crStateSwitchContext( current, pLocalCtx );
    710     }
    711 
    712     SetCurrentContext(pLocalCtx);
     698        if (pState->diff_api.AlphaFunc)
     699            crStateSwitchContext(current, pLocalCtx );
     700    }
     701
     702    SetCurrentContext(pState, pLocalCtx);
    713703
    714704    /* ensure matrix state is also current */
    715     crStateMatrixMode(pLocalCtx->transform.matrixMode);
     705    crStateMatrixMode(pState, pLocalCtx->transform.matrixMode);
    716706}
    717707
     
    720710 * As above, but don't call crStateSwitchContext().
    721711 */
    722 static void crStateSetCurrentEx( CRContext *ctx, GLboolean fCleanupDefault )
    723 {
    724     CRContext *current = GetCurrentContext();
     712static void crStateSetCurrentEx(PCRStateTracker pState, CRContext *ctx, GLboolean fCleanupDefault )
     713{
     714    CRContext *current = GetCurrentContext(pState);
    725715    CRContext *pLocalCtx = ctx;
    726716
    727717    if (pLocalCtx == NULL && !fCleanupDefault)
    728         pLocalCtx = defaultContext;
     718        pLocalCtx = pState->pDefaultContext;
    729719
    730720    if (current == pLocalCtx)
    731721        return; /* no-op */
    732722
    733     SetCurrentContext(pLocalCtx);
     723    SetCurrentContext(pState, pLocalCtx);
    734724    if (pLocalCtx)
    735725    {
    736726        /* ensure matrix state is also current */
    737         crStateMatrixMode(pLocalCtx->transform.matrixMode);
    738     }
    739 }
    740 
    741 void crStateSetCurrent( CRContext *ctx )
    742 {
    743     crStateSetCurrentEx( ctx, GL_FALSE );
    744 }
    745 
    746 void crStateCleanupCurrent(void)
    747 {
    748     crStateSetCurrentEx( NULL, GL_TRUE );
    749 }
    750 
    751 
    752 CRContext *crStateGetCurrent(void)
    753 {
    754     return GetCurrentContext();
    755 }
    756 
    757 
    758 void crStateUpdateColorBits(void)
     727        crStateMatrixMode(pState, pLocalCtx->transform.matrixMode);
     728    }
     729}
     730
     731void crStateSetCurrent(PCRStateTracker pState, CRContext *ctx )
     732{
     733    crStateSetCurrentEx(pState, ctx, GL_FALSE );
     734}
     735
     736void crStateCleanupCurrent(PCRStateTracker pState)
     737{
     738    crStateSetCurrentEx(pState, NULL, GL_TRUE );
     739}
     740
     741
     742CRContext *crStateGetCurrent(PCRStateTracker pState)
     743{
     744    return GetCurrentContext(pState);
     745}
     746
     747
     748void crStateUpdateColorBits(PCRStateTracker pState)
    759749{
    760750    /* This is a hack to force updating the 'current' attribs */
    761     CRStateBits *sb = GetCurrentBits();
     751    CRStateBits *sb = GetCurrentBits(pState);
    762752    FILLDIRTY(sb->current.dirty);
    763753    FILLDIRTY(sb->current.vertexAttrib[VERT_ATTRIB_COLOR0]);
     
    766756
    767757void STATE_APIENTRY
    768 crStateChromiumParameteriCR( GLenum target, GLint value )
     758crStateChromiumParameteriCR(PCRStateTracker pState, GLenum target, GLint value )
    769759{
    770760    /* This no-op function helps smooth code-gen */
     761    RT_NOREF(pState);
    771762    (void)target; (void)value;
    772763}
    773764
    774765void STATE_APIENTRY
    775 crStateChromiumParameterfCR( GLenum target, GLfloat value )
     766crStateChromiumParameterfCR(PCRStateTracker pState, GLenum target, GLfloat value )
    776767{
    777768    /* This no-op function helps smooth code-gen */
     769    RT_NOREF(pState);
    778770    (void)target; (void)value;
    779771}
    780772
    781773void STATE_APIENTRY
    782 crStateChromiumParametervCR( GLenum target, GLenum type, GLsizei count, const GLvoid *values )
     774crStateChromiumParametervCR(PCRStateTracker pState, GLenum target, GLenum type, GLsizei count, const GLvoid *values )
    783775{
    784776    /* This no-op function helps smooth code-gen */
     777    RT_NOREF(pState);
    785778    (void)target; (void)type; (void)count; (void)values;
    786779}
    787780
    788781void STATE_APIENTRY
    789 crStateGetChromiumParametervCR( GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values )
     782crStateGetChromiumParametervCR(PCRStateTracker pState, GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values )
    790783{
    791784    /* This no-op function helps smooth code-gen */
     785    RT_NOREF(pState);
    792786    (void)target; (void)index; (void)type; (void)count; (void)values;
    793787}
    794788
    795789void STATE_APIENTRY
    796 crStateReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
    797                                      GLenum format, GLenum type, GLvoid *pixels )
     790crStateReadPixels(PCRStateTracker pState, GLint x, GLint y, GLsizei width, GLsizei height,
     791                  GLenum format, GLenum type, GLvoid *pixels )
    798792{
    799793    /* This no-op function helps smooth code-gen */
     794    RT_NOREF(pState);
    800795    (void)x; (void)y; (void)width; (void)height; (void)format; (void)type; (void)pixels;
    801796}
    802797
    803 void crStateVBoxDetachThread(void)
     798void crStateVBoxDetachThread(PCRStateTracker pState)
    804799{
    805800    /* release the context ref so that it can be freed */
    806     SetCurrentContext(NULL);
    807 }
    808 
    809 
    810 void crStateVBoxAttachThread(void)
    811 {
     801    SetCurrentContext(pState, NULL);
     802}
     803
     804
     805void crStateVBoxAttachThread(PCRStateTracker pState)
     806{
     807    RT_NOREF(pState);
    812808}
    813809
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_isenabled.py

    r69392 r78375  
    4444#include "state/cr_statetypes.h"
    4545
    46 GLboolean STATE_APIENTRY crStateIsEnabled( GLenum pname )
     46GLboolean STATE_APIENTRY crStateIsEnabled(PCRStateTracker pState, GLenum pname )
    4747{
    48         CRContext *g = GetCurrentContext();
     48        CRContext *g = GetCurrentContext(pState);
    4949
    5050        if (g->current.inBeginEnd)
    5151        {
    52                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glGet called in Begin/End");
     52                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glGet called in Begin/End");
    5353                return 0;
    5454        }
     
    7070        print('#endif /* CR_%s */' % ext)
    7171print("\tdefault:")
    72 print("\t\tcrStateError(__LINE__, __FILE__, GL_INVALID_ENUM, \"glIsEnabled: Unknown enum: %d\", pname);")
     72print("\t\tcrStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, \"glIsEnabled: Unknown enum: %d\", pname);")
    7373print("\t\treturn 0;")
    7474print("\t}")
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_lighting.c

    r69392 r78375  
    2929{
    3030        CRLightingState *l = &ctx->lighting;
    31         CRStateBits *sb = GetCurrentBits();
     31        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    3232        CRLightingBits *lb = &(sb->lighting);
    3333        int i;
     
    110110}
    111111
    112 void STATE_APIENTRY crStateShadeModel (GLenum mode)
    113 {
    114         CRContext *g = GetCurrentContext();
     112void STATE_APIENTRY crStateShadeModel (PCRStateTracker pState, GLenum mode)
     113{
     114        CRContext *g = GetCurrentContext(pState);
    115115        CRLightingState *l = &(g->lighting);
    116         CRStateBits *sb = GetCurrentBits();
     116        CRStateBits *sb = GetCurrentBits(pState);
    117117        CRLightingBits *lb = &(sb->lighting);
    118118
    119119        if (g->current.inBeginEnd)
    120120        {
    121                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "ShadeModel called in begin/end");
     121                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "ShadeModel called in begin/end");
    122122                return;
    123123        }
     
    128128                        mode != GL_FLAT)
    129129        {
    130                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "ShadeModel: Bogus mode 0x%x", mode);
     130                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "ShadeModel: Bogus mode 0x%x", mode);
    131131                return;
    132132        }
     
    137137}
    138138
    139 void STATE_APIENTRY crStateColorMaterial (GLenum face, GLenum mode)
    140 {
    141         CRContext *g = GetCurrentContext();
     139void STATE_APIENTRY crStateColorMaterial (PCRStateTracker pState, GLenum face, GLenum mode)
     140{
     141        CRContext *g = GetCurrentContext(pState);
    142142        CRLightingState *l = &(g->lighting);
    143         CRStateBits *sb = GetCurrentBits();
     143        CRStateBits *sb = GetCurrentBits(pState);
    144144        CRLightingBits *lb = &(sb->lighting);
    145145
    146146        if (g->current.inBeginEnd)
    147147        {
    148                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "ColorMaterial called in begin/end");
     148                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "ColorMaterial called in begin/end");
    149149                return;
    150150        }
     
    156156                        face != GL_FRONT_AND_BACK)
    157157        {
    158                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "ColorMaterial: Bogus face &d", face);
     158                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "ColorMaterial: Bogus face &d", face);
    159159                return;
    160160        }
     
    166166                        mode != GL_AMBIENT_AND_DIFFUSE)
    167167        {
    168                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "ColorMaterial: Bogus mode &d", mode);
     168                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "ColorMaterial: Bogus mode &d", mode);
    169169                return;
    170170        }
     
    180180}
    181181
    182 void STATE_APIENTRY crStateLightModelfv (GLenum pname, const GLfloat *param)
    183 {
    184         CRContext *g = GetCurrentContext();
     182void STATE_APIENTRY crStateLightModelfv (PCRStateTracker pState, GLenum pname, const GLfloat *param)
     183{
     184        CRContext *g = GetCurrentContext(pState);
    185185        CRLightingState *l = &(g->lighting);
    186         CRStateBits *sb = GetCurrentBits();
     186        CRStateBits *sb = GetCurrentBits(pState);
    187187        CRLightingBits *lb = &(sb->lighting);
    188188
    189189        if (g->current.inBeginEnd)
    190190        {
    191                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "LightModelfv called in begin/end");
     191                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "LightModelfv called in begin/end");
    192192                return;
    193193        }
     
    217217                        else
    218218                        {
    219                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "LightModel: Invalid param for LIGHT_MODEL_COLOR_CONTROL: 0x%x", param[0]);
     219                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "LightModel: Invalid param for LIGHT_MODEL_COLOR_CONTROL: 0x%x", param[0]);
    220220                                return;
    221221                        }
     
    232232                                else
    233233                                {
    234                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "LightModel: Invalid param for LIGHT_MODEL_COLOR_CONTROL: 0x%x", param[0]);
     234                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "LightModel: Invalid param for LIGHT_MODEL_COLOR_CONTROL: 0x%x", param[0]);
    235235                                        return;
    236236                                }
     
    238238                        else
    239239                        {
    240                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "LightModel( LIGHT_MODEL_COLOR_CONTROL, ...) - EXT_separate_specular_color is unavailable.");
     240                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "LightModel( LIGHT_MODEL_COLOR_CONTROL, ...) - EXT_separate_specular_color is unavailable.");
    241241                                return;
    242242                        }
     
    245245#endif
    246246                default:
    247                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "LightModelfv: Invalid pname: 0x%x", pname);
     247                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "LightModelfv: Invalid pname: 0x%x", pname);
    248248                        return;
    249249        }
     
    252252}
    253253
    254 void STATE_APIENTRY crStateLightModeliv (GLenum pname, const GLint *param)
     254void STATE_APIENTRY crStateLightModeliv (PCRStateTracker pState, GLenum pname, const GLint *param)
    255255{
    256256        GLfloat f_param;
    257257        GLcolor f_color;
    258258#ifndef CR_OPENGL_VERSION_1_2
    259         CRContext *g = GetCurrentContext();
     259        CRContext *g = GetCurrentContext(pState);
    260260#endif
    261261
     
    265265                case GL_LIGHT_MODEL_TWO_SIDE:
    266266                        f_param = (GLfloat) (*param);
    267                         crStateLightModelfv(pname, &f_param);
     267                        crStateLightModelfv(pState, pname, &f_param);
    268268                        break;
    269269                case GL_LIGHT_MODEL_AMBIENT:
     
    272272                        f_color.b = ((GLfloat)param[2])/CR_MAXINT;
    273273                        f_color.a = ((GLfloat)param[3])/CR_MAXINT;
    274                         crStateLightModelfv(pname, (GLfloat *) &f_color);
     274                        crStateLightModelfv(pState, pname, (GLfloat *) &f_color);
    275275                        break;
    276276#if defined(CR_OPENGL_VERSION_1_2)
    277277                case GL_LIGHT_MODEL_COLOR_CONTROL:
    278278                        f_param = (GLfloat) (*param);
    279                         crStateLightModelfv(pname, &f_param);
     279                        crStateLightModelfv(pState, pname, &f_param);
    280280                        break;
    281281#else
     
    284284                        if (g->extensions.EXT_separate_specular_color) {
    285285                                f_param = (GLfloat) (*param);
    286                                 crStateLightModelfv(pname, &f_param);
     286                                crStateLightModelfv(pState, pname, &f_param);
    287287                        } else {
    288                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "LightModeliv(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, ...) - EXT_separate_specular_color not enabled!");
     288                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "LightModeliv(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, ...) - EXT_separate_specular_color not enabled!");
    289289                                return;
    290290                        }
     
    293293#endif
    294294                default:
    295                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "LightModeliv: Invalid pname: 0x%x", pname);
     295                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "LightModeliv: Invalid pname: 0x%x", pname);
    296296                        return;
    297297        }
    298298}
    299299
    300 void STATE_APIENTRY crStateLightModelf (GLenum pname, GLfloat param)
    301 {
    302         crStateLightModelfv(pname, &param);
    303 }
    304 
    305 void STATE_APIENTRY crStateLightModeli (GLenum pname, GLint param)
     300void STATE_APIENTRY crStateLightModelf (PCRStateTracker pState, GLenum pname, GLfloat param)
     301{
     302        crStateLightModelfv(pState, pname, &param);
     303}
     304
     305void STATE_APIENTRY crStateLightModeli (PCRStateTracker pState, GLenum pname, GLint param)
    306306{
    307307        GLfloat f_param = (GLfloat) param;
    308         crStateLightModelfv(pname, &f_param);
    309 }
    310 
    311 void STATE_APIENTRY crStateLightfv (GLenum light, GLenum pname, const GLfloat *param)
    312 {
    313         CRContext *g = GetCurrentContext();
     308        crStateLightModelfv(pState, pname, &f_param);
     309}
     310
     311void STATE_APIENTRY crStateLightfv (PCRStateTracker pState, GLenum light, GLenum pname, const GLfloat *param)
     312{
     313        CRContext *g = GetCurrentContext(pState);
    314314        CRLightingState *l = &(g->lighting);
    315315        CRTransformState *t = &(g->transform);
     
    319319        CRmatrix inv;
    320320        CRmatrix *mat;
    321         CRStateBits *sb = GetCurrentBits();
     321        CRStateBits *sb = GetCurrentBits(pState);
    322322        CRLightingBits *lb = &(sb->lighting);
    323323        CRLightBits *ltb;
     
    325325        if (g->current.inBeginEnd)
    326326        {
    327                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glLightfv called in begin/end");
     327                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glLightfv called in begin/end");
    328328                return;
    329329        }
     
    334334        if (i>=g->limits.maxLights)
    335335        {
    336                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glLight: invalid light specified: 0x%x", light);
     336                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glLight: invalid light specified: 0x%x", light);
    337337                return;
    338338        }
     
    405405                        if (*param < 0.0f || *param > 180.0f)
    406406                        {
    407                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLight: spot exponent out of range: %f", *param);
     407                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glLight: spot exponent out of range: %f", *param);
    408408                                return;
    409409                        }
     
    414414                        if ((*param < 0.0f || *param > 90.0f) && *param != 180.0f)
    415415                        {
    416                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLight: spot cutoff out of range: %f", *param);
     416                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glLight: spot cutoff out of range: %f", *param);
    417417                                return;
    418418                        }
     
    423423                        if (*param < 0.0f)
    424424                        {
    425                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLight: constant Attenuation negative: %f", *param);
     425                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glLight: constant Attenuation negative: %f", *param);
    426426                                return;
    427427                        }
     
    432432                        if (*param < 0.0f)
    433433                        {
    434                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLight: linear Attenuation negative: %f", *param);
     434                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glLight: linear Attenuation negative: %f", *param);
    435435                                return;
    436436                        }
     
    441441                        if (*param < 0.0f)
    442442                        {
    443                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLight: quadratic Attenuation negative: %f", *param);
     443                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glLight: quadratic Attenuation negative: %f", *param);
    444444                                return;
    445445                        }
     
    448448                        break;
    449449                default:
    450                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glLight: invalid pname: 0x%x", pname);
     450                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glLight: invalid pname: 0x%x", pname);
    451451                        return;
    452452        }
     
    455455}
    456456
    457 void STATE_APIENTRY crStateLightiv (GLenum light, GLenum pname, const GLint *param)
     457void STATE_APIENTRY crStateLightiv (PCRStateTracker pState, GLenum light, GLenum pname, const GLint *param)
    458458{
    459459        GLfloat f_param;
     
    470470                        f_color.b = ((GLfloat)param[2])/CR_MAXINT;
    471471                        f_color.a = ((GLfloat)param[3])/CR_MAXINT;
    472                         crStateLightfv(light, pname, (GLfloat *) &f_color);
     472                        crStateLightfv(pState, light, pname, (GLfloat *) &f_color);
    473473                        break;
    474474                case GL_POSITION:
     
    478478                        f_vector.z = (GLfloat) param[2];
    479479                        f_vector.w = (GLfloat) param[3];
    480                         crStateLightfv(light, pname, (GLfloat *) &f_vector);
     480                        crStateLightfv(pState, light, pname, (GLfloat *) &f_vector);
    481481                        break;
    482482                case GL_SPOT_EXPONENT:
     
    486486                case GL_QUADRATIC_ATTENUATION:
    487487                        f_param = (GLfloat) (*param);
    488                         crStateLightfv(light, pname, &f_param);
     488                        crStateLightfv(pState, light, pname, &f_param);
    489489                        break;
    490490                default:
    491                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glLight: invalid pname: 0x%x", pname);
     491                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glLight: invalid pname: 0x%x", pname);
    492492                        return;
    493493        }
    494494}
    495495
    496 void STATE_APIENTRY crStateLightf (GLenum light, GLenum pname, GLfloat param)
    497 {
    498         crStateLightfv(light, pname, &param);
    499 }
    500 
    501 void STATE_APIENTRY crStateLighti (GLenum light, GLenum pname, GLint param)
     496void STATE_APIENTRY crStateLightf (PCRStateTracker pState, GLenum light, GLenum pname, GLfloat param)
     497{
     498        crStateLightfv(pState, light, pname, &param);
     499}
     500
     501void STATE_APIENTRY crStateLighti (PCRStateTracker pState, GLenum light, GLenum pname, GLint param)
    502502{
    503503        GLfloat f_param = (GLfloat) param;
    504         crStateLightfv(light, pname, &f_param);
    505 }
    506 
    507 void STATE_APIENTRY crStateMaterialfv (GLenum face, GLenum pname, const GLfloat *param)
    508 {
    509         CRContext *g = GetCurrentContext();
     504        crStateLightfv(pState, light, pname, &f_param);
     505}
     506
     507void STATE_APIENTRY crStateMaterialfv (PCRStateTracker pState, GLenum face, GLenum pname, const GLfloat *param)
     508{
     509        CRContext *g = GetCurrentContext(pState);
    510510        CRLightingState *l = &(g->lighting);
    511         CRStateBits *sb = GetCurrentBits();
     511        CRStateBits *sb = GetCurrentBits(pState);
    512512        CRLightingBits *lb = &(sb->lighting);
    513513
     
    541541                                        break;
    542542                                default:
    543                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
     543                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
    544544                                        return;
    545545                        }
     
    567567                                        break;
    568568                                default:
    569                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
     569                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
    570570                                        return;
    571571                        }
     
    593593                                        break;
    594594                                default:
    595                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
     595                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
    596596                                        return;
    597597                        }
     
    619619                                        break;
    620620                                default:
    621                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
     621                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
    622622                                        return;
    623623                        }
     
    645645                                        break;
    646646                                default:
    647                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
     647                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
    648648                                        return;
    649649                        }
     
    652652                        if (*param > 180.0f || *param < 0.0f)
    653653                        {
    654                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMaterialfv: param out of range: %f", param);
     654                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMaterialfv: param out of range: %f", param);
    655655                                return;
    656656                        }
     
    668668                                        break;
    669669                                default:
    670                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
     670                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
    671671                                        return;
    672672                        }
     
    691691                                        break;
    692692                                default:
    693                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
     693                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
    694694                                        return;
    695695                        }
    696696                        break;
    697697                default:
    698                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad pname: 0x%x", pname);
     698                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad pname: 0x%x", pname);
    699699                        return;
    700700        }
     
    703703}
    704704
    705 void STATE_APIENTRY crStateMaterialiv (GLenum face, GLenum pname, const GLint *param)
     705void STATE_APIENTRY crStateMaterialiv (PCRStateTracker pState, GLenum face, GLenum pname, const GLint *param)
    706706{
    707707        GLfloat f_param;
     
    719719                        f_color.b = ((GLfloat) param[2]) / ((GLfloat) CR_MAXINT);
    720720                        f_color.a = ((GLfloat) param[3]) / ((GLfloat) CR_MAXINT);
    721                         crStateMaterialfv(face, pname, (GLfloat *) &f_color);
     721                        crStateMaterialfv(pState, face, pname, (GLfloat *) &f_color);
    722722                        break;
    723723                case GL_SHININESS:
    724724                        f_param = (GLfloat) (*param);
    725                         crStateMaterialfv(face, pname, (GLfloat *) &f_param);
     725                        crStateMaterialfv(pState, face, pname, (GLfloat *) &f_param);
    726726                        break;
    727727                case GL_COLOR_INDEXES :
    728728                        f_param = (GLfloat) (*param);
    729                         crStateMaterialfv(face, pname, (GLfloat *) &f_param);
     729                        crStateMaterialfv(pState, face, pname, (GLfloat *) &f_param);
    730730                        break;
    731731                default:
    732                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialiv: bad pname: 0x%x", pname);
     732                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialiv: bad pname: 0x%x", pname);
    733733                        return;
    734734        }
    735735}
    736736
    737 void STATE_APIENTRY crStateMaterialf (GLenum face, GLenum pname, GLfloat param)
    738 {
    739         crStateMaterialfv(face, pname, &param);
    740 }
    741 
    742 void STATE_APIENTRY crStateMateriali (GLenum face, GLenum pname, GLint param)
     737void STATE_APIENTRY crStateMaterialf (PCRStateTracker pState, GLenum face, GLenum pname, GLfloat param)
     738{
     739        crStateMaterialfv(pState, face, pname, &param);
     740}
     741
     742void STATE_APIENTRY crStateMateriali (PCRStateTracker pState, GLenum face, GLenum pname, GLint param)
    743743{
    744744        GLfloat f_param = (GLfloat) param;
    745         crStateMaterialfv(face, pname, &f_param);
    746 }
    747 
    748 void STATE_APIENTRY crStateGetLightfv (GLenum light, GLenum pname, GLfloat *param)
    749 {
    750         CRContext *g = GetCurrentContext();
     745        crStateMaterialfv(pState, face, pname, &f_param);
     746}
     747
     748void STATE_APIENTRY crStateGetLightfv (PCRStateTracker pState, GLenum light, GLenum pname, GLfloat *param)
     749{
     750        CRContext *g = GetCurrentContext(pState);
    751751        CRLightingState *l = &(g->lighting);
    752752        CRLight *lt;
     
    755755        if (g->current.inBeginEnd)
    756756        {
    757                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     757                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    758758                                "glGetLightfv called in begin/end");
    759759                return;
     
    763763        if (i>=g->limits.maxLights)
    764764        {
    765                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     765                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    766766                                "glGetLight: invalid light specified: 0x%x", light);
    767767                return;
     
    823823                        break;
    824824                default:
    825                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     825                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    826826                                        "glGetLight: invalid pname: 0x%x", pname);
    827827                        return;
     
    829829}
    830830
    831 void STATE_APIENTRY crStateGetLightiv (GLenum light, GLenum pname, GLint *param)
    832 {
    833         CRContext *g = GetCurrentContext();
     831void STATE_APIENTRY crStateGetLightiv (PCRStateTracker pState, GLenum light, GLenum pname, GLint *param)
     832{
     833        CRContext *g = GetCurrentContext(pState);
    834834        CRLightingState *l = &(g->lighting);
    835835        CRLight *lt;
     
    838838        if (g->current.inBeginEnd)
    839839        {
    840                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     840                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    841841                                "glGetLightiv called in begin/end");
    842842                return;
     
    846846        if (i>=g->limits.maxLights)
    847847        {
    848                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     848                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    849849                                "glGetLight: invalid light specified: 0x%x", light);
    850850                return;
     
    906906                        break;
    907907                default:
    908                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     908                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    909909                                        "glGetLight: invalid pname: 0x%x", pname);
    910910                        return;
     
    912912}
    913913
    914 void STATE_APIENTRY crStateGetMaterialfv (GLenum face, GLenum pname, GLfloat *param)
    915 {
    916         CRContext *g = GetCurrentContext();
     914void STATE_APIENTRY crStateGetMaterialfv (PCRStateTracker pState, GLenum face, GLenum pname, GLfloat *param)
     915{
     916        CRContext *g = GetCurrentContext(pState);
    917917        CRLightingState *l = &(g->lighting);
    918918
    919919        if (g->current.inBeginEnd)
    920920        {
    921                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     921                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    922922                                "glGetMaterialfv called in begin/end");
    923923                return;
     
    942942                                        break;
    943943                                default:
    944                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     944                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    945945                                                        "glGetMaterialfv: bad face: 0x%x", face);
    946946                                        return;
     
    963963                                        break;
    964964                                default:
    965                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     965                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    966966                                                        "glGetMaterialfv: bad face: 0x%x", face);
    967967                                        return;
     
    984984                                        break;
    985985                                default:
    986                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     986                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    987987                                                        "glGetMaterialfv: bad face: 0x%x", face);
    988988                                        return;
     
    10051005                                        break;
    10061006                                default:
    1007                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1007                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    10081008                                                        "glGetMaterialfv: bad face: 0x%x", face);
    10091009                                        return;
     
    10201020                                        break;
    10211021                                default:
    1022                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1022                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    10231023                                                        "glGetMaterialfv: bad face: 0x%x", face);
    10241024                                        return;
     
    10391039                                        break;
    10401040                                default:
    1041                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1041                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    10421042                                                        "glGetMaterialfv: bad face: 0x%x", face);
    10431043                                        return;
     
    10451045                        return;
    10461046                default:
    1047                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1047                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    10481048                                        "glGetMaterialfv: bad pname: 0x%x", pname);
    10491049                        return;
     
    10521052
    10531053
    1054 void STATE_APIENTRY crStateGetMaterialiv (GLenum face, GLenum pname, GLint *param)
    1055 {
    1056         CRContext *g = GetCurrentContext();
     1054void STATE_APIENTRY crStateGetMaterialiv (PCRStateTracker pState, GLenum face, GLenum pname, GLint *param)
     1055{
     1056        CRContext *g = GetCurrentContext(pState);
    10571057        CRLightingState *l = &(g->lighting);
    10581058
    10591059        if (g->current.inBeginEnd)
    10601060        {
    1061                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1061                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    10621062                                "glGetMaterialiv called in begin/end");
    10631063                return;
     
    10821082                                        break;
    10831083                                default:
    1084                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1084                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    10851085                                                        "glGetMaterialiv: bad face: 0x%x", face);
    10861086                                        return;
     
    11031103                                        break;
    11041104                                default:
    1105                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1105                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11061106                                                        "glGetMaterialiv: bad face: 0x%x", face);
    11071107                                        return;
     
    11241124                                        break;
    11251125                                default:
    1126                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1126                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11271127                                                        "glGetMaterialiv: bad face: 0x%x", face);
    11281128                                        return;
     
    11451145                                        break;
    11461146                                default:
    1147                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1147                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11481148                                                        "glGetMaterialiv: bad face: 0x%x", face);
    11491149                                        return;
     
    11591159                                        break;
    11601160                                default:
    1161                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1161                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11621162                                                        "glGetMaterialiv: bad face: 0x%x", face);
    11631163                                        return;
     
    11781178                                        break;
    11791179                                default:
    1180                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1180                                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11811181                                                        "glGetMaterialiv: bad face: 0x%x", face);
    11821182                                        return;
     
    11841184                        return;
    11851185                default:
    1186                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1186                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11871187                                        "glGetMaterialiv: bad pname: 0x%x", pname);
    11881188                        return;
     
    11901190}
    11911191
    1192 void crStateColorMaterialRecover(void)
    1193 {
    1194         CRContext *g = GetCurrentContext();
     1192void crStateColorMaterialRecover(PCRStateTracker pState)
     1193{
     1194        CRContext *g = GetCurrentContext(pState);
    11951195        CRLightingState *l = &(g->lighting);
    11961196        CRCurrentState *c = &(g->current);
     
    12061206                 * short time.  Without this, kirchner_colormaterial fails.
    12071207                 */
    1208                 crStateFlushFunc(NULL);
    1209 
    1210                 crStateMaterialfv(l->colorMaterialFace, l->colorMaterialMode, &(c->vertexAttrib[VERT_ATTRIB_COLOR0][0]));
    1211         }
    1212 }
     1208                crStateFlushFunc(pState, NULL);
     1209
     1210                crStateMaterialfv(pState, l->colorMaterialFace, l->colorMaterialMode, &(c->vertexAttrib[VERT_ATTRIB_COLOR0][0]));
     1211        }
     1212}
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_lighting.txt

    r15532 r78375  
    99:shadeModel:shadeModel:ShadeModel
    1010:lightModel:lightModelAmbient|r,g,b,a:LightModelfv,GL_LIGHT_MODEL_AMBIENT
    11 :lightModel:lightModelLocalViewer:*diff_api.LightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, to->lightModelLocalViewer==GL_TRUE);
    12 :lightModel:lightModelTwoSide:*diff_api.LightModeli(GL_LIGHT_MODEL_TWO_SIDE, to->lightModelTwoSide==GL_TRUE);
    13 :lightModel:lightModelColorControlEXT:*diff_api.LightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, to->lightModelColorControlEXT);
     11:lightModel:lightModelLocalViewer:*pState->diff_api.LightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, to->lightModelLocalViewer==GL_TRUE);
     12:lightModel:lightModelTwoSide:*pState->diff_api.LightModeli(GL_LIGHT_MODEL_TWO_SIDE, to->lightModelTwoSide==GL_TRUE);
     13:lightModel:lightModelColorControlEXT:*pState->diff_api.LightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, to->lightModelColorControlEXT);
    1414%flush
    1515:material:ambient[0]|r,g,b,a:Materialfv, GL_FRONT, GL_AMBIENT
     
    4141:attenuation:linearAttenuation:Lightf, GL_LIGHT0+i, GL_LINEAR_ATTENUATION
    4242:attenuation:quadraticAttenuation:Lightf, GL_LIGHT0+i, GL_QUADRATIC_ATTENUATION
    43 :position:*diff_api.MatrixMode(GL_MODELVIEW);
    44 :position:*diff_api.PushMatrix();
    45 :position:*diff_api.LoadIdentity();
     43:position:*pState->diff_api.MatrixMode(GL_MODELVIEW);
     44:position:*pState->diff_api.PushMatrix();
     45:position:*pState->diff_api.LoadIdentity();
    4646:position:position|x,y,z,w:Lightfv, GL_LIGHT0+i, GL_POSITION
    47 :position:*diff_api.PopMatrix();
    48 :position:*diff_api.MatrixMode(toCtx->transform.matrixMode);
    49 :spot:*diff_api.MatrixMode(GL_MODELVIEW);
    50 :spot:*diff_api.PushMatrix();
    51 :spot:*diff_api.LoadIdentity();
     47:position:*pState->diff_api.PopMatrix();
     48:position:*pState->diff_api.MatrixMode(toCtx->transform.matrixMode);
     49:spot:*pState->diff_api.MatrixMode(GL_MODELVIEW);
     50:spot:*pState->diff_api.PushMatrix();
     51:spot:*pState->diff_api.LoadIdentity();
    5252:spot:spotDirection|x,y,z:Lightfv, GL_LIGHT0+i, GL_SPOT_DIRECTION
    5353:spot:spotExponent:Lightf, GL_LIGHT0+i, GL_SPOT_EXPONENT
    5454:spot:spotCutoff:Lightf, GL_LIGHT0+i, GL_SPOT_CUTOFF
    55 :spot:*diff_api.PopMatrix();
    56 :spot:*diff_api.MatrixMode(toCtx->transform.matrixMode);
     55:spot:*pState->diff_api.PopMatrix();
     56:spot:*pState->diff_api.MatrixMode(toCtx->transform.matrixMode);
    5757%flush
    5858>CLEARDIRTY(lb->dirty, nbitID);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_line.c

    r69392 r78375  
    1313{
    1414        CRLineState *l = &ctx->line;
    15         CRStateBits *sb = GetCurrentBits();
     15        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    1616        CRLineBits *lb = &(sb->line);
    1717
     
    3535}
    3636
    37 void STATE_APIENTRY crStateLineWidth(GLfloat width)
     37void STATE_APIENTRY crStateLineWidth(PCRStateTracker pState, GLfloat width)
    3838{
    39         CRContext *g = GetCurrentContext();
     39        CRContext *g = GetCurrentContext(pState);
    4040        CRLineState *l = &(g->line);
    41         CRStateBits *sb = GetCurrentBits();
     41        CRStateBits *sb = GetCurrentBits(pState);
    4242        CRLineBits *lb = &(sb->line);
    4343
    4444        if (g->current.inBeginEnd)
    4545        {
    46                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glLineWidth called in begin/end");
     46                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glLineWidth called in begin/end");
    4747                return;
    4848        }
     
    5252        if (width <= 0.0f)
    5353        {
    54                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLineWidth called with size <= 0.0: %f", width);
     54                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glLineWidth called with size <= 0.0: %f", width);
    5555                return;
    5656        }
     
    6161}
    6262
    63 void STATE_APIENTRY crStateLineStipple(GLint factor, GLushort pattern)
     63void STATE_APIENTRY crStateLineStipple(PCRStateTracker pState, GLint factor, GLushort pattern)
    6464{
    65         CRContext *g = GetCurrentContext();
     65        CRContext *g = GetCurrentContext(pState);
    6666        CRLineState *l = &(g->line);
    67         CRStateBits *sb = GetCurrentBits();
     67        CRStateBits *sb = GetCurrentBits(pState);
    6868        CRLineBits *lb = &(sb->line);
    6969
    7070        if (g->current.inBeginEnd)
    7171        {
    72                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     72                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    7373                        "glLineStipple called in begin/end");
    7474                return;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_lists.c

    r78263 r78375  
    2020{
    2121    CRListsState *l = &ctx->lists;
    22     CRStateBits *sb = GetCurrentBits();
     22    CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    2323    CRListsBits *lb = &(sb->lists);
    2424
     
    5757#endif
    5858
    59 #define CRSTATE_SET_ENABLED(state, cap) CRSTATE_SET_CAP(state, diff_api.IsEnabled(cap), "%u")
    60 
    61 #define CRSTATE_SET_ENUM(state, cap) {GLenum _e=g->state; diff_api.GetIntegerv(cap, (GLint *)&_e); CRSTATE_SET_CAP(state, _e, "%#x");}
    62 #define CRSTATE_SET_FLOAT(state, cap) {GLfloat _f=g->state; diff_api.GetFloatv(cap, &_f); CRSTATE_SET_CAP(state, _f, "%f");}
    63 #define CRSTATE_SET_INT(state, cap) {GLint _i=g->state; diff_api.GetIntegerv(cap, &_i); CRSTATE_SET_CAP(state, _i, "%i");}
    64 #define CRSTATE_SET_BOOL(state, cap) {GLboolean _b=g->state; diff_api.GetBooleanv(cap, &_b); CRSTATE_SET_CAP(state, _b, "%u");}
     59#define CRSTATE_SET_ENABLED(state, cap) CRSTATE_SET_CAP(state, pState->diff_api.IsEnabled(cap), "%u")
     60
     61#define CRSTATE_SET_ENUM(state, cap) {GLenum _e=g->state; pState->diff_api.GetIntegerv(cap, (GLint *)&_e); CRSTATE_SET_CAP(state, _e, "%#x");}
     62#define CRSTATE_SET_FLOAT(state, cap) {GLfloat _f=g->state; pState->diff_api.GetFloatv(cap, &_f); CRSTATE_SET_CAP(state, _f, "%f");}
     63#define CRSTATE_SET_INT(state, cap) {GLint _i=g->state; pState->diff_api.GetIntegerv(cap, &_i); CRSTATE_SET_CAP(state, _i, "%i");}
     64#define CRSTATE_SET_BOOL(state, cap) {GLboolean _b=g->state; pState->diff_api.GetBooleanv(cap, &_b); CRSTATE_SET_CAP(state, _b, "%u");}
    6565
    6666#define CRSTATE_SET_COLORF(state, cap)              \
     
    7171        value[2]=g->state.b;                        \
    7272        value[3]=g->state.a;                        \
    73         diff_api.GetFloatv(cap, &value[0]);        \
     73        pState->diff_api.GetFloatv(cap, &value[0]); \
    7474        CRSTATE_SET_CAP(state.r, value[0], "%f");   \
    7575        CRSTATE_SET_CAP(state.g, value[1], "%f");   \
     
    8181    {                                                                                       \
    8282        GLint _stex, _hwtex;                                                                \
    83         _stex = _hwtex = crStateGetTextureObjHWID(g->state);                                \
    84         diff_api.GetIntegerv(cap, &_hwtex);                                                 \
     83        _stex = _hwtex = crStateGetTextureObjHWID(pState, g->state);                        \
     84        pState->diff_api.GetIntegerv(cap, &_hwtex);                                         \
    8585        if (_stex!=_hwtex)                                                                  \
    8686        {                                                                                   \
    8787            CR_STATE_SETTEX_MSG(#state, _stex, _hwtex);                                     \
    88             crStateBindTexture(target, crStateTextureHWIDtoID(_hwtex));                     \
     88            crStateBindTexture(pState, target, crStateTextureHWIDtoID(pState, _hwtex));     \
    8989        }                                                                                   \
    9090    }
     
    9797        value[2]=g->state.b;                        \
    9898        value[3]=g->state.a;                        \
    99         diff_api.func(p1, p2, &value[0]);           \
     99        pState->diff_api.func(p1, p2, &value[0]);   \
    100100        CRSTATE_SET_CAP(state.r, value[0], "%f");   \
    101101        CRSTATE_SET_CAP(state.g, value[1], "%f");   \
     
    111111        value[2]=g->state.z;                        \
    112112        value[3]=g->state.w;                        \
    113         diff_api.func(p1, p2, &value[0]);           \
     113        pState->diff_api.func(p1, p2, &value[0]);   \
    114114        CRSTATE_SET_CAP(state.x, value[0], "%f");   \
    115115        CRSTATE_SET_CAP(state.y, value[1], "%f");   \
     
    119119
    120120#define CRSTATE_SET_TEXGEN_4F(state, coord, pname) _CRSTATE_SET_4F_XYZW(state, coord, pname, GetTexGenfv)
    121 #define CRSTATE_SET_TEXGEN_I(state, coord, pname) {GLint _i=g->state; diff_api.GetTexGeniv(coord, pname, &_i); CRSTATE_SET_CAP(state, _i, "%i");}
    122 
    123 #define CRSTATE_SET_TEXENV_I(state, target, pname) {GLint _i=g->state; diff_api.GetTexEnviv(target, pname, &_i); CRSTATE_SET_CAP(state, _i, "%i");}
    124 #define CRSTATE_SET_TEXENV_F(state, target, pname) {GLfloat _f=g->state; diff_api.GetTexEnvfv(target, pname, &_f); CRSTATE_SET_CAP(state, _f, "%f");}
     121#define CRSTATE_SET_TEXGEN_I(state, coord, pname) {GLint _i=g->state; pState->diff_api.GetTexGeniv(coord, pname, &_i); CRSTATE_SET_CAP(state, _i, "%i");}
     122
     123#define CRSTATE_SET_TEXENV_I(state, target, pname) {GLint _i=g->state; pState->diff_api.GetTexEnviv(target, pname, &_i); CRSTATE_SET_CAP(state, _i, "%i");}
     124#define CRSTATE_SET_TEXENV_F(state, target, pname) {GLfloat _f=g->state; pState->diff_api.GetTexEnvfv(target, pname, &_f); CRSTATE_SET_CAP(state, _f, "%f");}
    125125#define CRSTATE_SET_TEXENV_COLOR(state, target, pname) _CRSTATE_SET_4F_RGBA(state, target, pname, GetTexEnvfv)
    126126
    127127#define CRSTATE_SET_MATERIAL_COLOR(state, face, pname) _CRSTATE_SET_4F_RGBA(state, face, pname, GetMaterialfv)
    128 #define CRSTATE_SET_MATERIAL_F(state, face, pname) {GLfloat _f=g->state; diff_api.GetMaterialfv(face, pname, &_f); CRSTATE_SET_CAP(state, _f, "%f");}
     128#define CRSTATE_SET_MATERIAL_F(state, face, pname) {GLfloat _f=g->state; pState->diff_api.GetMaterialfv(face, pname, &_f); CRSTATE_SET_CAP(state, _f, "%f");}
    129129
    130130#define CRSTATE_SET_LIGHT_COLOR(state, light, pname) _CRSTATE_SET_4F_RGBA(state, light, pname, GetLightfv)
    131 #define CRSTATE_SET_LIGHT_F(state, light, pname) {GLfloat _f=g->state; diff_api.GetLightfv(light, pname, &_f); CRSTATE_SET_CAP(state, _f, "%f");}
     131#define CRSTATE_SET_LIGHT_F(state, light, pname) {GLfloat _f=g->state; pState->diff_api.GetLightfv(light, pname, &_f); CRSTATE_SET_CAP(state, _f, "%f");}
    132132#define CRSTATE_SET_LIGHT_4F(state, light, pname) _CRSTATE_SET_4F_XYZW(state, light, pname, GetLightfv)
    133133#define CRSTATE_SET_LIGHT_3F(state, light, pname)       \
     
    137137        value[1]=g->state.y;                            \
    138138        value[2]=g->state.z;                            \
    139         diff_api.GetLightfv(light, pname, &value[0]);  \
     139        pState->diff_api.GetLightfv(light, pname, &value[0]); \
    140140        CRSTATE_SET_CAP(state.x, value[0], "%f");       \
    141141        CRSTATE_SET_CAP(state.y, value[1], "%f");       \
     
    150150        value[2]=g->state.z;                        \
    151151        value[3]=g->state.w;                        \
    152         diff_api.GetClipPlane(plane, &value[0]);    \
     152        pState->diff_api.GetClipPlane(plane, &value[0]); \
    153153        CRSTATE_SET_CAP(state.x, value[0], "%G");   \
    154154        CRSTATE_SET_CAP(state.y, value[1], "%G");   \
     
    162162        crMatrixGetFloats(&f[0], g->state);                 \
    163163        crMemcpy(&sm[0], &f[0], 16*sizeof(GLfloat));        \
    164         diff_api.GetFloatv(cap, &f[0]);                     \
     164        pState->diff_api.GetFloatv(cap, &f[0]);             \
    165165        if (crMemcmp(&f[0], &sm[0], 16*sizeof(GLfloat)))    \
    166166        {                                                   \
     
    170170    }
    171171
    172 void STATE_APIENTRY crStateQueryHWState(GLuint fbFbo, GLuint bbFbo)
     172void STATE_APIENTRY crStateQueryHWState(PCRStateTracker pState, GLuint fbFbo, GLuint bbFbo)
    173173{
    174     CRContext *g = GetCurrentContext();
    175     CRStateBits *sb = GetCurrentBits();
     174    CRContext *g = GetCurrentContext(pState);
     175    CRStateBits *sb = GetCurrentBits(pState);
    176176    CRbitvalue /* *bitID=g->bitid, */ *negbitID=g->neg_bitid;
    177177
    178     CRASSERT(g_bVBoxEnableDiffOnMakeCurrent);
     178    CRASSERT(pState->fVBoxEnableDiffOnMakeCurrent);
    179179
    180180    crStateSyncHWErrorState(g);
     
    224224        {
    225225            GLuint buf = 0;
    226             diff_api.GetIntegerv(GL_DRAW_BUFFER, (GLint *)&buf);
     226            pState->diff_api.GetIntegerv(GL_DRAW_BUFFER, (GLint *)&buf);
    227227
    228228            if (buf == GL_COLOR_ATTACHMENT0_EXT && (bbFbo || fbFbo))
    229229            {
    230230                GLuint binding = 0;
    231                 diff_api.GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, (GLint *)&binding);
     231                pState->diff_api.GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, (GLint *)&binding);
    232232                if (!binding)
    233233                {
     
    257257        {
    258258            GLuint buf = 0;
    259             diff_api.GetIntegerv(GL_READ_BUFFER, (GLint *)&buf);
     259            pState->diff_api.GetIntegerv(GL_READ_BUFFER, (GLint *)&buf);
    260260
    261261            if (buf == GL_COLOR_ATTACHMENT0_EXT && (bbFbo || fbFbo))
    262262            {
    263263                GLuint binding = 0;
    264                 diff_api.GetIntegerv(GL_READ_FRAMEBUFFER_BINDING, (GLint *)&binding);
     264                pState->diff_api.GetIntegerv(GL_READ_FRAMEBUFFER_BINDING, (GLint *)&binding);
    265265                if (!binding)
    266266                {
     
    299299            value[2]=g->buffer.colorWriteMask.b;
    300300            value[3]=g->buffer.colorWriteMask.a;
    301             diff_api.GetBooleanv(GL_COLOR_WRITEMASK, &value[0]);
     301            pState->diff_api.GetBooleanv(GL_COLOR_WRITEMASK, &value[0]);
    302302
    303303            CRSTATE_SET_CAP(buffer.colorWriteMask.r, value[0], "%u");
     
    397397            if (activeFace == GL_BACK)
    398398            {
    399                 diff_api.ActiveStencilFaceEXT(GL_FRONT);
     399                pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    400400                activeFace = GL_FRONT;
    401401            }
     
    409409            if (activeFace == GL_BACK)
    410410            {
    411                 diff_api.ActiveStencilFaceEXT(GL_FRONT);
     411                pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    412412                activeFace = GL_FRONT;
    413413            }
     
    420420            if (activeFace == GL_BACK)
    421421            {
    422                 diff_api.ActiveStencilFaceEXT(GL_FRONT);
     422                pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    423423                activeFace = GL_FRONT;
    424424            }
     
    440440            if (activeFace == GL_BACK)
    441441            {
    442                 diff_api.ActiveStencilFaceEXT(GL_FRONT);
     442                pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    443443                activeFace = GL_FRONT;
    444444            }
     
    452452            if (activeFace == GL_BACK)
    453453            {
    454                 diff_api.ActiveStencilFaceEXT(GL_FRONT);
     454                pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    455455                activeFace = GL_FRONT;
    456456            }
     
    463463            if (activeFace == GL_BACK)
    464464            {
    465                 diff_api.ActiveStencilFaceEXT(GL_FRONT);
     465                pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    466466                activeFace = GL_FRONT;
    467467            }
     
    496496                if (i!=activeUnit)
    497497                {
    498                     diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
     498                    pState->diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
    499499                    activeUnit=i;
    500500                }
     
    527527                if (i!=activeUnit)
    528528                {
    529                     diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
     529                    pState->diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
    530530                    activeUnit=i;
    531531                }
     
    554554                if (i!=activeUnit)
    555555                {
    556                     diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
     556                    pState->diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
    557557                    activeUnit=i;
    558558                }
     
    568568                if (i!=activeUnit)
    569569                {
    570                     diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
     570                    pState->diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
    571571                    activeUnit=i;
    572572                }
     
    582582                if (i!=activeUnit)
    583583                {
    584                     diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
     584                    pState->diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
    585585                    activeUnit=i;
    586586                }
     
    596596                if (i!=activeUnit)
    597597                {
    598                     diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
     598                    pState->diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
    599599                    activeUnit=i;
    600600                }
     
    622622        if (activeUnit!=g->texture.curTextureUnit)
    623623        {
    624             diff_api.ActiveTextureARB(g->texture.curTextureUnit + GL_TEXTURE0_ARB);
     624            pState->diff_api.ActiveTextureARB(g->texture.curTextureUnit + GL_TEXTURE0_ARB);
    625625        }
    626626    }
     
    754754            for (i=0; i<g->limits.maxTextureUnits; i++)
    755755            {
    756                 diff_api.ActiveTextureARB(GL_TEXTURE0_ARB+i);
     756                pState->diff_api.ActiveTextureARB(GL_TEXTURE0_ARB+i);
    757757                CRSTATE_SET_MATRIX(transform.textureStack[i].top, GL_TEXTURE_MATRIX);
    758758            }
    759             diff_api.ActiveTextureARB(g->texture.curTextureUnit + GL_TEXTURE0_ARB);
     759            pState->diff_api.ActiveTextureARB(g->texture.curTextureUnit + GL_TEXTURE0_ARB);
    760760        }
    761761
     
    785785            value[2] = g->viewport.scissorW;
    786786            value[3] = g->viewport.scissorH;
    787             diff_api.GetIntegerv(GL_SCISSOR_BOX, &value[0]);
     787            pState->diff_api.GetIntegerv(GL_SCISSOR_BOX, &value[0]);
    788788            CRSTATE_SET_CAP(viewport.scissorX, value[0], "%i");
    789789            CRSTATE_SET_CAP(viewport.scissorY, value[1], "%i");
     
    799799            value[2] = g->viewport.viewportW;
    800800            value[3] = g->viewport.viewportH;
    801             diff_api.GetIntegerv(GL_VIEWPORT, &value[0]);
     801            pState->diff_api.GetIntegerv(GL_VIEWPORT, &value[0]);
    802802            CRSTATE_SET_CAP(viewport.viewportX, value[0], "%i");
    803803            CRSTATE_SET_CAP(viewport.viewportY, value[1], "%i");
     
    811811            value[0] = g->viewport.nearClip;
    812812            value[1] = g->viewport.farClip;
    813             diff_api.GetFloatv(GL_DEPTH_RANGE, &value[0]);
     813            pState->diff_api.GetFloatv(GL_DEPTH_RANGE, &value[0]);
    814814            CRSTATE_SET_CAP(viewport.nearClip, value[0], "%f");
    815815            CRSTATE_SET_CAP(viewport.farClip, value[1], "%f");
     
    847847                uval[0] = g->eval.eval1D[i].u1;
    848848                uval[1] = g->eval.eval1D[i].u2;
    849                 diff_api.GetMapiv(i + GL_MAP1_COLOR_4, GL_ORDER, &order);
    850                 diff_api.GetMapfv(i + GL_MAP1_COLOR_4, GL_DOMAIN, &uval[0]);
     849                pState->diff_api.GetMapiv(i + GL_MAP1_COLOR_4, GL_ORDER, &order);
     850                pState->diff_api.GetMapfv(i + GL_MAP1_COLOR_4, GL_DOMAIN, &uval[0]);
    851851                if (order>0)
    852852                {
     
    857857                        continue;
    858858                    }
    859                     diff_api.GetMapfv(i + GL_MAP1_COLOR_4, GL_COEFF, coeffs);
     859                    pState->diff_api.GetMapfv(i + GL_MAP1_COLOR_4, GL_COEFF, coeffs);
    860860                }
    861861
     
    886886                uval[2] = g->eval.eval2D[i].v1;
    887887                uval[3] = g->eval.eval2D[i].v2;
    888                 diff_api.GetMapiv(i + GL_MAP2_COLOR_4, GL_ORDER, &order[0]);
    889                 diff_api.GetMapfv(i + GL_MAP2_COLOR_4, GL_DOMAIN, &uval[0]);
     888                pState->diff_api.GetMapiv(i + GL_MAP2_COLOR_4, GL_ORDER, &order[0]);
     889                pState->diff_api.GetMapfv(i + GL_MAP2_COLOR_4, GL_DOMAIN, &uval[0]);
    890890                if (order[0]>0 && order[1]>0)
    891891                {
     
    896896                        continue;
    897897                    }
    898                     diff_api.GetMapfv(i + GL_MAP1_COLOR_4, GL_COEFF, coeffs);
     898                    pState->diff_api.GetMapfv(i + GL_MAP1_COLOR_4, GL_COEFF, coeffs);
    899899                }
    900900                CRSTATE_SET_CAP(eval.eval2D[i].uorder, order[0], "%i");
     
    927927            value[0] = g->eval.u11D;
    928928            value[1] = g->eval.u21D;
    929             diff_api.GetFloatv(GL_MAP1_GRID_DOMAIN, &value[0]);
     929            pState->diff_api.GetFloatv(GL_MAP1_GRID_DOMAIN, &value[0]);
    930930            CRSTATE_SET_CAP(eval.u11D, value[0], "%f");
    931931            CRSTATE_SET_CAP(eval.u21D, value[1], "%f");
     
    938938            iv[0] = g->eval.un2D;
    939939            iv[1] = g->eval.vn2D;
    940             diff_api.GetIntegerv(GL_MAP1_GRID_SEGMENTS, &iv[0]);
     940            pState->diff_api.GetIntegerv(GL_MAP1_GRID_SEGMENTS, &iv[0]);
    941941            CRSTATE_SET_CAP(eval.un2D, iv[0], "%i");
    942942            CRSTATE_SET_CAP(eval.vn2D, iv[1], "%i");
     
    945945            value[2] = g->eval.v12D;
    946946            value[3] = g->eval.v22D;
    947             diff_api.GetFloatv(GL_MAP2_GRID_DOMAIN, &value[0]);
     947            pState->diff_api.GetFloatv(GL_MAP2_GRID_DOMAIN, &value[0]);
    948948            CRSTATE_SET_CAP(eval.u12D, value[0], "%f");
    949949            CRSTATE_SET_CAP(eval.u22D, value[1], "%f");
     
    11221122            value[1] = g->point.distanceAttenuation[1];
    11231123            value[2] = g->point.distanceAttenuation[2];
    1124             diff_api.GetFloatv(GL_POINT_DISTANCE_ATTENUATION, &value[0]);
     1124            pState->diff_api.GetFloatv(GL_POINT_DISTANCE_ATTENUATION, &value[0]);
    11251125            CRSTATE_SET_CAP(point.distanceAttenuation[0], value[0], "%f");
    11261126            CRSTATE_SET_CAP(point.distanceAttenuation[1], value[1], "%f");
     
    11431143                    if (activeUnit!=i)
    11441144                    {
    1145                         diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
     1145                        pState->diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB);
    11461146                        activeUnit=i;
    11471147                    }
    1148                     diff_api.GetTexEnviv(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, &val);
     1148                    pState->diff_api.GetTexEnviv(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, &val);
    11491149                    CRSTATE_SET_CAP(point.coordReplacement[i], val, "%i");
    11501150                }
     
    11531153            if (activeUnit!=g->texture.curTextureUnit)
    11541154            {
    1155                 diff_api.ActiveTextureARB(g->texture.curTextureUnit + GL_TEXTURE0_ARB);
     1155                pState->diff_api.ActiveTextureARB(g->texture.curTextureUnit + GL_TEXTURE0_ARB);
    11561156            }
    11571157        }
     
    11841184            val[0] = g->polygon.frontMode;
    11851185            val[1] = g->polygon.backMode;
    1186             diff_api.GetIntegerv(GL_POLYGON_MODE, &val[0]);
     1186            pState->diff_api.GetIntegerv(GL_POLYGON_MODE, &val[0]);
    11871187            CRSTATE_SET_CAP(polygon.frontMode, val[0], "%#x");
    11881188            CRSTATE_SET_CAP(polygon.backMode, val[1], "%#x");
     
    11951195            GLint stipple[32];
    11961196            crMemcpy(&stipple[0], &g->polygon.stipple[0], sizeof(stipple));
    1197             diff_api.GetPolygonStipple((GLubyte*) &stipple[0]);
     1197            pState->diff_api.GetPolygonStipple((GLubyte*) &stipple[0]);
    11981198            if (crMemcmp(&stipple[0], &g->polygon.stipple[0], sizeof(stipple)))
    11991199            {
     
    12081208    }
    12091209
    1210     CR_STATE_CLEAN_HW_ERR_WARN("error on hw sync");
     1210    CR_STATE_CLEAN_HW_ERR_WARN(pState, "error on hw sync");
    12111211}
    12121212
    1213 void STATE_APIENTRY crStateNewList (GLuint list, GLenum mode)
     1213void STATE_APIENTRY crStateNewList (PCRStateTracker pState, GLuint list, GLenum mode)
    12141214{
    1215     CRContext *g = GetCurrentContext();
     1215    CRContext *g = GetCurrentContext(pState);
    12161216    CRListsState *l = &(g->lists);
    12171217
    12181218    if (g->current.inBeginEnd)
    12191219    {
    1220         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glNewList called in Begin/End");
     1220        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glNewList called in Begin/End");
    12211221        return;
    12221222    }
     
    12241224    if (list == 0)
    12251225    {
    1226         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glNewList(list=0)");
     1226        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glNewList(list=0)");
    12271227        return;
    12281228    }
     
    12311231    {
    12321232        /* already building a list */
    1233         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glNewList called inside display list");
     1233        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glNewList called inside display list");
    12341234        return;
    12351235    }
     
    12371237    if (mode != GL_COMPILE && mode != GL_COMPILE_AND_EXECUTE)
    12381238    {
    1239         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glNewList invalid mode");
     1239        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glNewList invalid mode");
    12401240        return;
    12411241    }
     
    12561256}
    12571257
    1258 void STATE_APIENTRY crStateEndList (void)
     1258void STATE_APIENTRY crStateEndList (PCRStateTracker pState)
    12591259{
    1260     CRContext *g = GetCurrentContext();
     1260    CRContext *g = GetCurrentContext(pState);
    12611261    CRListsState *l = &(g->lists);
    12621262
    12631263    if (g->current.inBeginEnd)
    12641264    {
    1265         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glEndList called in Begin/End");
     1265        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glEndList called in Begin/End");
    12661266        return;
    12671267    }
     
    12691269    if (!l->currentIndex)
    12701270    {
    1271         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glEndList called outside display list");
     1271        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glEndList called outside display list");
    12721272        return;
    12731273    }
     
    12771277}
    12781278
    1279 GLuint STATE_APIENTRY crStateGenLists(GLsizei range)
     1279GLuint STATE_APIENTRY crStateGenLists(PCRStateTracker pState, GLsizei range)
    12801280{
    1281     CRContext *g = GetCurrentContext();
     1281    CRContext *g = GetCurrentContext(pState);
    12821282    GLuint start;
    12831283
    12841284    if (g->current.inBeginEnd)
    12851285    {
    1286         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glGenLists called in Begin/End");
     1286        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glGenLists called in Begin/End");
    12871287        return 0;
    12881288    }
     
    12901290    if (range < 0)
    12911291    {
    1292         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative range passed to glGenLists: %d", range);
     1292        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative range passed to glGenLists: %d", range);
    12931293        return 0;
    12941294    }
     
    13001300}
    13011301   
    1302 void STATE_APIENTRY crStateDeleteLists (GLuint list, GLsizei range)
     1302void STATE_APIENTRY crStateDeleteLists (PCRStateTracker pState, GLuint list, GLsizei range)
    13031303{
    1304     CRContext *g = GetCurrentContext();
     1304    CRContext *g = GetCurrentContext(pState);
    13051305
    13061306    if (g->current.inBeginEnd)
    13071307    {
    1308         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDeleteLists called in Begin/End");
     1308        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glDeleteLists called in Begin/End");
    13091309        return;
    13101310    }
     
    13121312    if (range < 0)
    13131313    {
    1314         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "Negative range passed to glDeleteLists: %d", range);
     1314        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative range passed to glDeleteLists: %d", range);
    13151315        return;
    13161316    }
     
    13191319}
    13201320
    1321 GLboolean STATE_APIENTRY crStateIsList(GLuint list)
     1321GLboolean STATE_APIENTRY crStateIsList(PCRStateTracker pState, GLuint list)
    13221322{
    1323     CRContext *g = GetCurrentContext();
     1323    CRContext *g = GetCurrentContext(pState);
    13241324
    13251325    if (g->current.inBeginEnd)
    13261326    {
    1327         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1327        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    13281328            "GenLists called in Begin/End");
    13291329        return GL_FALSE;
     
    13361336}
    13371337   
    1338 void STATE_APIENTRY crStateListBase (GLuint base)
     1338void STATE_APIENTRY crStateListBase (PCRStateTracker pState, GLuint base)
    13391339{
    1340     CRContext *g = GetCurrentContext();
     1340    CRContext *g = GetCurrentContext(pState);
    13411341    CRListsState *l = &(g->lists);
    1342     CRStateBits *sb = GetCurrentBits();
     1342    CRStateBits *sb = GetCurrentBits(pState);
    13431343    CRListsBits *lb = &(sb->lists);
    13441344
    13451345    if (g->current.inBeginEnd)
    13461346    {
    1347         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1347        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    13481348            "ListBase called in Begin/End");
    13491349        return;
     
    13611361                                    CRContext *fromCtx, CRContext *toCtx )
    13621362{
     1363    PCRStateTracker pState = fromCtx->pStateTracker;
    13631364    CRListsState *from = &(fromCtx->lists);
    13641365    CRListsState *to = &(toCtx->lists);
     
    13661367    CRbitvalue nbitID[CR_MAX_BITARRAY];
    13671368
     1369    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     1370
    13681371    for (j=0;j<CR_MAX_BITARRAY;j++)
    13691372        nbitID[j] = ~bitID[j];
     
    13721375    {
    13731376        if (from->base != to->base) {
    1374             diff_api.ListBase(to->base);
     1377            pState->diff_api.ListBase(to->base);
    13751378            from->base = to->base;
    13761379        }
     
    13861389                                        CRContext *fromCtx, CRContext *toCtx )
    13871390{
     1391    PCRStateTracker pState = fromCtx->pStateTracker;
    13881392    CRListsState *from = &(fromCtx->lists);
    13891393    CRListsState *to = &(toCtx->lists);
     
    13911395    CRbitvalue nbitID[CR_MAX_BITARRAY];
    13921396
     1397    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     1398
    13931399    for (j=0;j<CR_MAX_BITARRAY;j++)
    13941400        nbitID[j] = ~bitID[j];
     
    13971403    {
    13981404        if (from->base != to->base) {
    1399             diff_api.ListBase(to->base);
     1405            pState->diff_api.ListBase(to->base);
    14001406            FILLDIRTY(b->base);
    14011407            FILLDIRTY(b->dirty);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_multisample.c

    r69392 r78375  
    1313{
    1414        CRMultisampleState *m = &ctx->multisample;
    15         CRStateBits *sb       = GetCurrentBits();
     15        CRStateBits *sb       = GetCurrentBits(ctx->pStateTracker);
    1616        CRMultisampleBits *mb = &(sb->multisample);
    1717
     
    2929}
    3030
    31 void STATE_APIENTRY crStateSampleCoverageARB(GLclampf value, GLboolean invert)
     31void STATE_APIENTRY crStateSampleCoverageARB(PCRStateTracker pState, GLclampf value, GLboolean invert)
    3232{
    33         CRContext *g          = GetCurrentContext();
     33        CRContext *g          = GetCurrentContext(pState);
    3434        CRMultisampleState *m = &(g->multisample);
    35         CRStateBits *sb       = GetCurrentBits();
     35        CRStateBits *sb       = GetCurrentBits(pState);
    3636        CRMultisampleBits *mb = &(sb->multisample);
    3737
    3838        if (g->current.inBeginEnd)
    3939        {
    40                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glStateSampleCoverageARB called in begin/end");
     40                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glStateSampleCoverageARB called in begin/end");
    4141                return;
    4242        }
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_occlude.c

    r78190 r78375  
    4444
    4545void STATE_APIENTRY
    46 crStateDeleteQueriesARB(GLsizei n, const GLuint *ids)
    47 {
    48         CRContext *g = GetCurrentContext();
     46crStateDeleteQueriesARB(PCRStateTracker pState, GLsizei n, const GLuint *ids)
     47{
     48        CRContext *g = GetCurrentContext(pState);
    4949        CROcclusionState *o = &(g->occlusion);
    5050        /*CRStateBits *sb = GetCurrentBits();*/
     
    5555
    5656        if (g->current.inBeginEnd) {
    57                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     57                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    5858                                                                 "glDeleteQueriesARB called in Begin/End");
    5959                return;
     
    7373
    7474void STATE_APIENTRY
    75 crStateGenQueriesARB(GLsizei n, GLuint * queries)
    76 {
    77         CRContext *g = GetCurrentContext();
     75crStateGenQueriesARB(PCRStateTracker pState, GLsizei n, GLuint * queries)
     76{
     77        CRContext *g = GetCurrentContext(pState);
    7878        CROcclusionState *o = &(g->occlusion);
    7979        GLint start;
     
    8282
    8383        if (g->current.inBeginEnd) {
    84                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     84                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    8585                                                                 "glGenQueriesARB called in Begin/End");
    8686                return;
     
    8888
    8989        if (n < 0) {
    90                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     90                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    9191                                                                 "glGenQueriesARB(n < 0)");
    9292                return;
     
    100100        }
    101101        else {
    102                 crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glGenQueriesARB");
     102                crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY, "glGenQueriesARB");
    103103        }
    104104}
     
    106106
    107107GLboolean STATE_APIENTRY
    108 crStateIsQueryARB(GLuint id)
    109 {
    110         CRContext *g = GetCurrentContext();
    111         CROcclusionState *o = &(g->occlusion);
    112 
    113         FLUSH();
    114 
    115         if (g->current.inBeginEnd) {
    116                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     108crStateIsQueryARB(PCRStateTracker pState, GLuint id)
     109{
     110        CRContext *g = GetCurrentContext(pState);
     111        CROcclusionState *o = &(g->occlusion);
     112
     113        FLUSH();
     114
     115        if (g->current.inBeginEnd) {
     116                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    117117                                                                 "glIsQueryARB called in begin/end");
    118118                return GL_FALSE;
     
    127127
    128128void STATE_APIENTRY
    129 crStateGetQueryivARB(GLenum target, GLenum pname, GLint *params)
    130 {
    131         CRContext *g = GetCurrentContext();
     129crStateGetQueryivARB(PCRStateTracker pState, GLenum target, GLenum pname, GLint *params)
     130{
     131        CRContext *g = GetCurrentContext(pState);
    132132        CROcclusionState *o = &(g->occlusion);
    133133        (void)target;
     
    136136
    137137        if (g->current.inBeginEnd) {
    138                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     138                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    139139                                                                 "glGetGetQueryivARB called in begin/end");
    140140                return;
     
    149149                 break;
    150150        default:
    151                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     151                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    152152                                                                 "glGetGetQueryivARB(pname)");
    153153                return;
     
    157157
    158158void STATE_APIENTRY
    159 crStateGetQueryObjectivARB(GLuint id, GLenum pname, GLint *params)
    160 {
    161         CRContext *g = GetCurrentContext();
     159crStateGetQueryObjectivARB(PCRStateTracker pState, GLuint id, GLenum pname, GLint *params)
     160{
     161        CRContext *g = GetCurrentContext(pState);
    162162        CROcclusionState *o = &(g->occlusion);
    163163        CROcclusionObject *q;
     
    166166
    167167        if (g->current.inBeginEnd) {
    168                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     168                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    169169                                                                 "glGetGetQueryObjectivARB called in begin/end");
    170170                return;
     
    173173        q = (CROcclusionObject *) crHashtableSearch(o->objects, id);
    174174        if (!q || q->active) {
    175                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     175                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    176176                                                                "glGetQueryObjectivARB");
    177177                return;
     
    186186                break;
    187187        default:
    188                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     188                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    189189                                                                 "glGetQueryObjectivARB(pname)");
    190190                return;
     
    194194
    195195void STATE_APIENTRY
    196 crStateGetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
    197 {
    198         CRContext *g = GetCurrentContext();
     196crStateGetQueryObjectuivARB(PCRStateTracker pState, GLuint id, GLenum pname, GLuint *params)
     197{
     198        CRContext *g = GetCurrentContext(pState);
    199199        CROcclusionState *o = &(g->occlusion);
    200200        CROcclusionObject *q;
     
    203203
    204204        if (g->current.inBeginEnd) {
    205                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     205                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    206206                                                                 "glGetGetQueryObjectuivARB called in begin/end");
    207207                return;
     
    210210        q = (CROcclusionObject *) crHashtableSearch(o->objects, id);
    211211        if (!q || q->active) {
    212                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     212                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    213213                                                                "glGetQueryObjectuivARB");
    214214                return;
     
    224224                break;
    225225        default:
    226                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     226                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    227227                                                                 "glGetQueryObjectuivARB(pname)");
    228228                return;
     
    232232
    233233void STATE_APIENTRY
    234 crStateBeginQueryARB(GLenum target, GLuint id)
    235 {
    236         CRContext *g = GetCurrentContext();
     234crStateBeginQueryARB(PCRStateTracker pState, GLenum target, GLuint id)
     235{
     236        CRContext *g = GetCurrentContext(pState);
    237237        CROcclusionState *o = &(g->occlusion);
    238238        CROcclusionObject *q;
     
    241241
    242242        if (g->current.inBeginEnd) {
    243                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     243                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    244244                                                                 "glGetGetQueryObjectuivARB called in begin/end");
    245245                return;
     
    247247
    248248        if (target != GL_SAMPLES_PASSED_ARB) {
    249                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     249                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    250250                                                                 "glBeginQueryARB(target)");
    251251                return;
     
    253253
    254254        if (o->currentQueryObject) {
    255                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     255                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    256256                                                                 "glBeginQueryARB(target)");
    257257                return;
     
    260260        q = (CROcclusionObject *) crHashtableSearch(o->objects, id);
    261261        if (q && q->active) {
    262                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glBeginQueryARB");
     262                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glBeginQueryARB");
    263263                return;
    264264        }
     
    266266                q = NewQueryObject(target, id);
    267267                if (!q) {
    268                         crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glBeginQueryARB");
     268                        crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY, "glBeginQueryARB");
    269269                        return;
    270270                }
     
    281281
    282282void STATE_APIENTRY
    283 crStateEndQueryARB(GLenum target)
    284 {
    285         CRContext *g = GetCurrentContext();
     283crStateEndQueryARB(PCRStateTracker pState, GLenum target)
     284{
     285        CRContext *g = GetCurrentContext(pState);
    286286        CROcclusionState *o = &(g->occlusion);
    287287        CROcclusionObject *q;
     
    290290
    291291        if (g->current.inBeginEnd) {
    292                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     292                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    293293                                                                 "glGetGetQueryObjectuivARB called in begin/end");
    294294                return;
     
    296296
    297297        if (target != GL_SAMPLES_PASSED_ARB) {
    298                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEndQueryARB(target)");
     298                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glEndQueryARB(target)");
    299299                return;
    300300        }
     
    302302        q = (CROcclusionObject *) crHashtableSearch(o->objects, o->currentQueryObject);
    303303        if (!q || !q->active) {
    304                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     304                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    305305                                                                 "glEndQueryARB with glBeginQueryARB");
    306306                return;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_pixel.c

    r74890 r78375  
    1414{
    1515    CRPixelState *p = &ctx->pixel;
    16     CRStateBits *sb = GetCurrentBits();
     16    CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    1717    CRPixelBits *pb = &(sb->pixel);
    1818    GLcolorf zero_color = {0.0f, 0.0f, 0.0f, 0.0f};
     
    5858}
    5959
    60 void STATE_APIENTRY crStatePixelTransferi (GLenum pname, GLint param)
    61 {
    62     crStatePixelTransferf( pname, (GLfloat) param );
    63 }
    64 
    65 void STATE_APIENTRY crStatePixelTransferf (GLenum pname, GLfloat param)
    66 {
    67     CRContext *g = GetCurrentContext();
     60void STATE_APIENTRY crStatePixelTransferi (PCRStateTracker pState, GLenum pname, GLint param)
     61{
     62    crStatePixelTransferf(pState, pname, (GLfloat) param );
     63}
     64
     65void STATE_APIENTRY crStatePixelTransferf (PCRStateTracker pState, GLenum pname, GLfloat param)
     66{
     67    CRContext *g = GetCurrentContext(pState);
    6868    CRPixelState *p = &(g->pixel);
    69     CRStateBits *sb = GetCurrentBits();
     69    CRStateBits *sb = GetCurrentBits(pState);
    7070    CRPixelBits *pb = &(sb->pixel);
    7171
    7272    if (g->current.inBeginEnd)
    7373    {
    74         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "PixelTransfer{if} called in Begin/End");
     74        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "PixelTransfer{if} called in Begin/End");
    7575        return;
    7676    }
     
    123123            break;
    124124        default:
    125             crStateError( __LINE__, __FILE__, GL_INVALID_VALUE, "Unknown glPixelTransfer pname: %d", pname );
     125            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Unknown glPixelTransfer pname: %d", pname );
    126126            return;
    127127    }
     
    130130}
    131131
    132 void STATE_APIENTRY crStatePixelZoom (GLfloat xfactor, GLfloat yfactor)
    133 {
    134     CRContext *g = GetCurrentContext();
     132void STATE_APIENTRY crStatePixelZoom (PCRStateTracker pState, GLfloat xfactor, GLfloat yfactor)
     133{
     134    CRContext *g = GetCurrentContext(pState);
    135135    CRPixelState *p = &(g->pixel);
    136     CRStateBits *sb = GetCurrentBits();
     136    CRStateBits *sb = GetCurrentBits(pState);
    137137    CRPixelBits *pb = &(sb->pixel);
    138138
    139139    if (g->current.inBeginEnd)
    140140    {
    141         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "PixelZoom called in Begin/End");
     141        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "PixelZoom called in Begin/End");
    142142        return;
    143143    }
     
    152152
    153153
    154 void STATE_APIENTRY crStateBitmap( GLsizei width, GLsizei height,
     154void STATE_APIENTRY crStateBitmap(PCRStateTracker pState, GLsizei width, GLsizei height,
    155155        GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
    156156        const GLubyte *bitmap)
    157157{
    158     CRContext *g = GetCurrentContext();
     158    CRContext *g = GetCurrentContext(pState);
    159159    CRCurrentState *c = &(g->current);
    160     CRStateBits *sb = GetCurrentBits();
     160    CRStateBits *sb = GetCurrentBits(pState);
    161161    CRCurrentBits *cb = &(sb->current);
    162162
     
    170170    if (g->current.inBeginEnd)
    171171    {
    172         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     172        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    173173            "Bitmap called in begin/end");
    174174        return;
     
    177177    if (width < 0 || height < 0)
    178178    {
    179         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     179        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    180180            "Bitmap called with neg dims: %dx%d", width, height);
    181181        return;
     
    201201#define CLAMP(x, min, max)  ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
    202202
    203 void STATE_APIENTRY crStatePixelMapfv (GLenum map, GLint mapsize, const GLfloat * values)
    204 {
    205     CRContext *g = GetCurrentContext();
     203void STATE_APIENTRY crStatePixelMapfv (PCRStateTracker pState, GLenum map, GLint mapsize, const GLfloat * values)
     204{
     205    CRContext *g = GetCurrentContext(pState);
    206206    CRPixelState *p = &(g->pixel);
    207     CRStateBits *sb = GetCurrentBits();
     207    CRStateBits *sb = GetCurrentBits(pState);
    208208    CRPixelBits *pb = &(sb->pixel);
    209209    GLint i;
    210     GLboolean unpackbuffer = crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
     210    GLboolean unpackbuffer = crStateIsBufferBound(pState, GL_PIXEL_UNPACK_BUFFER_ARB);
    211211
    212212    if (g->current.inBeginEnd) {
    213         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "PixelMap called in Begin/End");
     213        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "PixelMap called in Begin/End");
    214214        return;
    215215    }
     
    218218
    219219    if (mapsize < 0 || mapsize > CR_MAX_PIXEL_MAP_TABLE) {
    220        crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "PixelMap(mapsize)");
     220       crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "PixelMap(mapsize)");
    221221       return;
    222222    }
     
    302302        break;
    303303    default:
    304         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "PixelMap(map)");
     304        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "PixelMap(map)");
    305305        return;
    306306    }
     
    310310}
    311311
    312 void STATE_APIENTRY crStatePixelMapuiv (GLenum map, GLint mapsize, const GLuint * values)
     312void STATE_APIENTRY crStatePixelMapuiv (PCRStateTracker pState, GLenum map, GLint mapsize, const GLuint * values)
    313313{
    314314    if (mapsize < 0 || mapsize > CR_MAX_PIXEL_MAP_TABLE)
     
    318318    }
    319319
    320     if (!crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     320    if (!crStateIsBufferBound(pState, GL_PIXEL_UNPACK_BUFFER_ARB))
    321321    {
    322322        GLfloat fvalues[CR_MAX_PIXEL_MAP_TABLE];
     
    333333           }
    334334        }
    335         crStatePixelMapfv(map, mapsize, fvalues);
     335        crStatePixelMapfv(pState, map, mapsize, fvalues);
    336336    }
    337337    else
    338338    {
    339         crStatePixelMapfv(map, mapsize, (const GLfloat*) values);
     339        crStatePixelMapfv(pState, map, mapsize, (const GLfloat*) values);
    340340    }
    341341}
    342342 
    343 void STATE_APIENTRY crStatePixelMapusv (GLenum map, GLint mapsize, const GLushort * values)
     343void STATE_APIENTRY crStatePixelMapusv (PCRStateTracker pState, GLenum map, GLint mapsize, const GLushort * values)
    344344{
    345345    if (mapsize < 0 || mapsize > CR_MAX_PIXEL_MAP_TABLE)
     
    349349    }
    350350
    351     if (!crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     351    if (!crStateIsBufferBound(pState, GL_PIXEL_UNPACK_BUFFER_ARB))
    352352    {
    353353        GLfloat fvalues[CR_MAX_PIXEL_MAP_TABLE];
     
    364364           }
    365365        }
    366         crStatePixelMapfv(map, mapsize, fvalues);
     366        crStatePixelMapfv(pState, map, mapsize, fvalues);
    367367    }
    368368    else
    369369    {
    370         crStatePixelMapfv(map, mapsize, (const GLfloat*) values);
     370        crStatePixelMapfv(pState, map, mapsize, (const GLfloat*) values);
    371371    }
    372372}
    373373
    374374 
    375 void STATE_APIENTRY crStateGetPixelMapfv (GLenum map, GLfloat * values)
    376 {
    377     CRContext *g = GetCurrentContext();
     375void STATE_APIENTRY crStateGetPixelMapfv (PCRStateTracker pState, GLenum map, GLfloat * values)
     376{
     377    CRContext *g = GetCurrentContext(pState);
    378378    CRPixelState *p = &(g->pixel);
    379379    GLint i;
    380380
    381381    if (g->current.inBeginEnd) {
    382         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     382        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    383383                     "GetPixelMapfv called in Begin/End");
    384384        return;
     
    421421        break;
    422422    default:
    423         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "GetPixelMap(map)");
     423        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "GetPixelMap(map)");
    424424        return;
    425425    }
    426426}
    427427 
    428 void STATE_APIENTRY crStateGetPixelMapuiv (GLenum map, GLuint * values)
    429 {
    430     CRContext *g = GetCurrentContext();
     428void STATE_APIENTRY crStateGetPixelMapuiv (PCRStateTracker pState, GLenum map, GLuint * values)
     429{
     430    CRContext *g = GetCurrentContext(pState);
    431431    const GLfloat maxUint = 4294967295.0F;
    432432    CRPixelState *p = &(g->pixel);
     
    434434
    435435    if (g->current.inBeginEnd) {
    436         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     436        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    437437                     "GetPixelMapuiv called in Begin/End");
    438438        return;
     
    491491        break;
    492492    default:
    493         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "GetPixelMapuiv(map)");
     493        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "GetPixelMapuiv(map)");
    494494        return;
    495495    }
    496496}
    497497 
    498 void STATE_APIENTRY crStateGetPixelMapusv (GLenum map, GLushort * values)
    499 {
    500     CRContext *g = GetCurrentContext();
     498void STATE_APIENTRY crStateGetPixelMapusv (PCRStateTracker pState, GLenum map, GLushort * values)
     499{
     500    CRContext *g = GetCurrentContext(pState);
    501501    const GLfloat maxUshort = 65535.0F;
    502502    CRPixelState *p = &(g->pixel);
     
    504504
    505505    if (g->current.inBeginEnd) {
    506         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     506        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    507507                     "GetPixelMapusv called in Begin/End");
    508508        return;
     
    561561        break;
    562562    default:
    563         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "GetPixelMapusv(map)");
     563        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "GetPixelMapusv(map)");
    564564        return;
    565565    }
     
    569569                      CRContext *fromCtx, CRContext *toCtx)
    570570{
     571    PCRStateTracker pState = fromCtx->pStateTracker;
    571572    CRPixelState *from = &(fromCtx->pixel);
    572573    CRPixelState *to = &(toCtx->pixel);
    573574    int j, i;
    574575    CRbitvalue nbitID[CR_MAX_BITARRAY];
     576
     577    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     578
    575579    for (j=0;j<CR_MAX_BITARRAY;j++)
    576580        nbitID[j] = ~bitID[j];
     
    580584        if (from->mapColor != to->mapColor)
    581585        {           
    582             diff_api.PixelTransferi (GL_MAP_COLOR, to->mapColor);
     586            pState->diff_api.PixelTransferi (GL_MAP_COLOR, to->mapColor);
    583587            from->mapColor = to->mapColor;
    584588        }
    585589        if (from->mapStencil != to->mapStencil)
    586590        {
    587             diff_api.PixelTransferi (GL_MAP_STENCIL, to->mapStencil);
     591            pState->diff_api.PixelTransferi (GL_MAP_STENCIL, to->mapStencil);
    588592            from->mapStencil = to->mapStencil;
    589593        }
    590594        if (from->indexOffset != to->indexOffset)
    591595        {
    592             diff_api.PixelTransferi (GL_INDEX_OFFSET, to->indexOffset);
     596            pState->diff_api.PixelTransferi (GL_INDEX_OFFSET, to->indexOffset);
    593597            from->indexOffset = to->indexOffset;
    594598        }
    595599        if (from->indexShift != to->indexShift)
    596600        {
    597             diff_api.PixelTransferi (GL_INDEX_SHIFT, to->indexShift);
     601            pState->diff_api.PixelTransferi (GL_INDEX_SHIFT, to->indexShift);
    598602            from->indexShift = to->indexShift;
    599603        }
    600604        if (from->scale.r != to->scale.r)
    601605        {
    602             diff_api.PixelTransferf (GL_RED_SCALE, to->scale.r);
     606            pState->diff_api.PixelTransferf (GL_RED_SCALE, to->scale.r);
    603607            from->scale.r = to->scale.r;
    604608        }
    605609        if (from->scale.g != to->scale.g)
    606610        {
    607             diff_api.PixelTransferf (GL_GREEN_SCALE, to->scale.g);
     611            pState->diff_api.PixelTransferf (GL_GREEN_SCALE, to->scale.g);
    608612            from->scale.g = to->scale.g;
    609613        }
    610614        if (from->scale.b != to->scale.b)
    611615        {
    612             diff_api.PixelTransferf (GL_BLUE_SCALE, to->scale.b);
     616            pState->diff_api.PixelTransferf (GL_BLUE_SCALE, to->scale.b);
    613617            from->scale.b = to->scale.b;
    614618        }
    615619        if (from->scale.a != to->scale.a)
    616620        {
    617             diff_api.PixelTransferf (GL_ALPHA_SCALE, to->scale.a);
     621            pState->diff_api.PixelTransferf (GL_ALPHA_SCALE, to->scale.a);
    618622            from->scale.a = to->scale.a;
    619623        }
    620624        if (from->bias.r != to->bias.r)
    621625        {
    622             diff_api.PixelTransferf (GL_RED_BIAS, to->bias.r);
     626            pState->diff_api.PixelTransferf (GL_RED_BIAS, to->bias.r);
    623627            from->bias.r = to->bias.r;
    624628        }
    625629        if (from->bias.g != to->bias.g)
    626630        {
    627             diff_api.PixelTransferf (GL_GREEN_BIAS, to->bias.g);
     631            pState->diff_api.PixelTransferf (GL_GREEN_BIAS, to->bias.g);
    628632            from->bias.g = to->bias.g;
    629633        }
    630634        if (from->bias.b != to->bias.b)
    631635        {
    632             diff_api.PixelTransferf (GL_BLUE_BIAS, to->bias.b);
     636            pState->diff_api.PixelTransferf (GL_BLUE_BIAS, to->bias.b);
    633637            from->bias.b = to->bias.b;
    634638        }
    635639        if (from->bias.a != to->bias.a)
    636640        {
    637             diff_api.PixelTransferf (GL_ALPHA_BIAS, to->bias.a);
     641            pState->diff_api.PixelTransferf (GL_ALPHA_BIAS, to->bias.a);
    638642            from->bias.a = to->bias.a;
    639643        }
    640644        if (from->depthScale != to->depthScale)
    641645        {
    642             diff_api.PixelTransferf (GL_DEPTH_SCALE, to->depthScale);
     646            pState->diff_api.PixelTransferf (GL_DEPTH_SCALE, to->depthScale);
    643647            from->depthScale = to->depthScale;
    644648        }
    645649        if (from->depthBias != to->depthBias)
    646650        {
    647             diff_api.PixelTransferf (GL_DEPTH_BIAS, to->depthBias);
     651            pState->diff_api.PixelTransferf (GL_DEPTH_BIAS, to->depthBias);
    648652            from->depthBias = to->depthBias;
    649653        }
     
    655659            from->yZoom != to->yZoom)
    656660        {
    657             diff_api.PixelZoom (to->xZoom,
    658                 to->yZoom);
     661            pState->diff_api.PixelZoom (to->xZoom, to->yZoom);
    659662            from->xZoom = to->xZoom;
    660663            from->yZoom = to->yZoom;
     
    665668    {
    666669        if (crMemcmp(to->mapStoS, from->mapStoS, CR_MAX_PIXEL_MAP_TABLE*sizeof(GLfloat)))
    667             diff_api.PixelMapfv(GL_PIXEL_MAP_S_TO_S,to->mapStoSsize,(GLfloat*)to->mapStoS);
     670            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_S_TO_S,to->mapStoSsize,(GLfloat*)to->mapStoS);
    668671        if (crMemcmp(to->mapItoI, from->mapItoI, CR_MAX_PIXEL_MAP_TABLE*sizeof(GLfloat)))
    669             diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_I,to->mapItoIsize,(GLfloat*)to->mapItoI);
     672            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_I,to->mapItoIsize,(GLfloat*)to->mapItoI);
    670673        if (crMemcmp(to->mapItoR, from->mapItoR, CR_MAX_PIXEL_MAP_TABLE*sizeof(GLfloat)))
    671             diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_R,to->mapItoRsize,(GLfloat*)to->mapItoR);
     674            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_R,to->mapItoRsize,(GLfloat*)to->mapItoR);
    672675        if (crMemcmp(to->mapItoG, from->mapItoG, CR_MAX_PIXEL_MAP_TABLE*sizeof(GLfloat)))
    673             diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_G,to->mapItoGsize,(GLfloat*)to->mapItoG);
     676            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_G,to->mapItoGsize,(GLfloat*)to->mapItoG);
    674677        if (crMemcmp(to->mapItoB, from->mapItoB, CR_MAX_PIXEL_MAP_TABLE*sizeof(GLfloat)))
    675             diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_B,to->mapItoBsize,(GLfloat*)to->mapItoB);
     678            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_B,to->mapItoBsize,(GLfloat*)to->mapItoB);
    676679        if (crMemcmp(to->mapItoA, from->mapItoA, CR_MAX_PIXEL_MAP_TABLE*sizeof(GLfloat)))
    677             diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_A,to->mapItoAsize,(GLfloat*)to->mapItoA);
     680            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_A,to->mapItoAsize,(GLfloat*)to->mapItoA);
    678681        if (crMemcmp(to->mapRtoR, from->mapRtoR, CR_MAX_PIXEL_MAP_TABLE*sizeof(GLfloat)))
    679             diff_api.PixelMapfv(GL_PIXEL_MAP_R_TO_R,to->mapRtoRsize,(GLfloat*)to->mapRtoR);
     682            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_R_TO_R,to->mapRtoRsize,(GLfloat*)to->mapRtoR);
    680683        if (crMemcmp(to->mapGtoG, from->mapGtoG, CR_MAX_PIXEL_MAP_TABLE*sizeof(GLfloat)))
    681             diff_api.PixelMapfv(GL_PIXEL_MAP_G_TO_G,to->mapGtoGsize,(GLfloat*)to->mapGtoG);
     684            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_G_TO_G,to->mapGtoGsize,(GLfloat*)to->mapGtoG);
    682685        if (crMemcmp(to->mapBtoB, from->mapBtoB, CR_MAX_PIXEL_MAP_TABLE*sizeof(GLfloat)))
    683             diff_api.PixelMapfv(GL_PIXEL_MAP_B_TO_B,to->mapBtoBsize,(GLfloat*)to->mapBtoB);
     686            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_B_TO_B,to->mapBtoBsize,(GLfloat*)to->mapBtoB);
    684687        if (crMemcmp(to->mapAtoA, from->mapAtoA, CR_MAX_PIXEL_MAP_TABLE*sizeof(GLfloat)))
    685             diff_api.PixelMapfv(GL_PIXEL_MAP_A_TO_A,to->mapAtoAsize,(GLfloat*)to->mapAtoA);
     688            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_A_TO_A,to->mapAtoAsize,(GLfloat*)to->mapAtoA);
    686689        CLEARDIRTY(b->maps, nbitID);
    687690    }
     
    692695                      CRContext *fromCtx, CRContext *toCtx)
    693696{
     697    PCRStateTracker pState = fromCtx->pStateTracker;
    694698    CRPixelState *from = &(fromCtx->pixel);
    695699    CRPixelState *to = &(toCtx->pixel);
    696700    int j, i;
    697701    CRbitvalue nbitID[CR_MAX_BITARRAY];
     702
     703    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     704
    698705    for (j=0;j<CR_MAX_BITARRAY;j++)
    699706        nbitID[j] = ~bitID[j];
     
    703710        if (from->mapColor != to->mapColor)
    704711        {
    705             diff_api.PixelTransferi (GL_MAP_COLOR, to->mapColor);
     712            pState->diff_api.PixelTransferi (GL_MAP_COLOR, to->mapColor);
    706713            FILLDIRTY(b->transfer);
    707714            FILLDIRTY(b->dirty);
     
    709716        if (from->mapStencil != to->mapStencil)
    710717        {
    711             diff_api.PixelTransferi (GL_MAP_STENCIL, to->mapStencil);
     718            pState->diff_api.PixelTransferi (GL_MAP_STENCIL, to->mapStencil);
    712719            FILLDIRTY(b->transfer);
    713720            FILLDIRTY(b->dirty);
     
    715722        if (from->indexOffset != to->indexOffset)
    716723        {
    717             diff_api.PixelTransferi (GL_INDEX_OFFSET, to->indexOffset);
     724            pState->diff_api.PixelTransferi (GL_INDEX_OFFSET, to->indexOffset);
    718725            FILLDIRTY(b->transfer);
    719726            FILLDIRTY(b->dirty);
     
    721728        if (from->indexShift != to->indexShift)
    722729        {
    723             diff_api.PixelTransferi (GL_INDEX_SHIFT, to->indexShift);
     730            pState->diff_api.PixelTransferi (GL_INDEX_SHIFT, to->indexShift);
    724731            FILLDIRTY(b->transfer);
    725732            FILLDIRTY(b->dirty);
     
    727734        if (from->scale.r != to->scale.r)
    728735        {
    729             diff_api.PixelTransferf (GL_RED_SCALE, to->scale.r);
     736            pState->diff_api.PixelTransferf (GL_RED_SCALE, to->scale.r);
    730737            FILLDIRTY(b->transfer);
    731738            FILLDIRTY(b->dirty);
     
    733740        if (from->scale.g != to->scale.g)
    734741        {
    735             diff_api.PixelTransferf (GL_GREEN_SCALE, to->scale.g);
     742            pState->diff_api.PixelTransferf (GL_GREEN_SCALE, to->scale.g);
    736743            FILLDIRTY(b->transfer);
    737744            FILLDIRTY(b->dirty);
     
    739746        if (from->scale.b != to->scale.b)
    740747        {
    741             diff_api.PixelTransferf (GL_BLUE_SCALE, to->scale.b);
     748            pState->diff_api.PixelTransferf (GL_BLUE_SCALE, to->scale.b);
    742749            FILLDIRTY(b->transfer);
    743750            FILLDIRTY(b->dirty);
     
    745752        if (from->scale.a != to->scale.a)
    746753        {
    747             diff_api.PixelTransferf (GL_ALPHA_SCALE, to->scale.a);
     754            pState->diff_api.PixelTransferf (GL_ALPHA_SCALE, to->scale.a);
    748755            FILLDIRTY(b->transfer);
    749756            FILLDIRTY(b->dirty);
     
    751758        if (from->bias.r != to->bias.r)
    752759        {
    753             diff_api.PixelTransferf (GL_RED_BIAS, to->bias.r);
     760            pState->diff_api.PixelTransferf (GL_RED_BIAS, to->bias.r);
    754761            FILLDIRTY(b->transfer);
    755762            FILLDIRTY(b->dirty);
     
    757764        if (from->bias.g != to->bias.g)
    758765        {
    759             diff_api.PixelTransferf (GL_GREEN_BIAS, to->bias.g);
     766            pState->diff_api.PixelTransferf (GL_GREEN_BIAS, to->bias.g);
    760767            FILLDIRTY(b->transfer);
    761768            FILLDIRTY(b->dirty);
     
    763770        if (from->bias.b != to->bias.b)
    764771        {
    765             diff_api.PixelTransferf (GL_BLUE_BIAS, to->bias.b);
     772            pState->diff_api.PixelTransferf (GL_BLUE_BIAS, to->bias.b);
    766773            FILLDIRTY(b->transfer);
    767774            FILLDIRTY(b->dirty);
     
    769776        if (from->bias.a != to->bias.a)
    770777        {
    771             diff_api.PixelTransferf (GL_ALPHA_BIAS, to->bias.a);
     778            pState->diff_api.PixelTransferf (GL_ALPHA_BIAS, to->bias.a);
    772779            FILLDIRTY(b->transfer);
    773780            FILLDIRTY(b->dirty);
     
    775782        if (from->depthScale != to->depthScale)
    776783        {
    777             diff_api.PixelTransferf (GL_DEPTH_SCALE, to->depthScale);
     784            pState->diff_api.PixelTransferf (GL_DEPTH_SCALE, to->depthScale);
    778785            FILLDIRTY(b->transfer);
    779786            FILLDIRTY(b->dirty);
     
    781788        if (from->depthBias != to->depthBias)
    782789        {
    783             diff_api.PixelTransferf (GL_DEPTH_BIAS, to->depthBias);
     790            pState->diff_api.PixelTransferf (GL_DEPTH_BIAS, to->depthBias);
    784791            FILLDIRTY(b->transfer);
    785792            FILLDIRTY(b->dirty);
     
    792799            from->yZoom != to->yZoom)
    793800        {
    794             diff_api.PixelZoom (to->xZoom,
    795                 to->yZoom);
     801            pState->diff_api.PixelZoom (to->xZoom, to->yZoom);
    796802            FILLDIRTY(b->zoom);
    797803            FILLDIRTY(b->dirty);
     
    802808    {
    803809        if (crMemcmp(to->mapStoS, from->mapStoS, CR_MAX_PIXEL_MAP_TABLE)) {
    804             diff_api.PixelMapfv(GL_PIXEL_MAP_S_TO_S,to->mapStoSsize,(GLfloat*)to->mapStoS);
     810            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_S_TO_S,to->mapStoSsize,(GLfloat*)to->mapStoS);
    805811            FILLDIRTY(b->maps);
    806812            FILLDIRTY(b->dirty);
    807813        }
    808814        if (crMemcmp(to->mapItoI, from->mapItoI, CR_MAX_PIXEL_MAP_TABLE)) {
    809             diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_I,to->mapItoIsize,(GLfloat*)to->mapItoI);
     815            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_I,to->mapItoIsize,(GLfloat*)to->mapItoI);
    810816            FILLDIRTY(b->maps);
    811817            FILLDIRTY(b->dirty);
    812818        }
    813819        if (crMemcmp(to->mapItoR, from->mapItoR, CR_MAX_PIXEL_MAP_TABLE)) {
    814             diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_R,to->mapItoRsize,(GLfloat*)to->mapItoR);
     820            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_R,to->mapItoRsize,(GLfloat*)to->mapItoR);
    815821            FILLDIRTY(b->maps);
    816822            FILLDIRTY(b->dirty);
    817823        }
    818824        if (crMemcmp(to->mapItoG, from->mapItoG, CR_MAX_PIXEL_MAP_TABLE)) {
    819             diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_G,to->mapItoGsize,(GLfloat*)to->mapItoG);
     825            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_G,to->mapItoGsize,(GLfloat*)to->mapItoG);
    820826            FILLDIRTY(b->maps);
    821827            FILLDIRTY(b->dirty);
    822828        }
    823829        if (crMemcmp(to->mapItoB, from->mapItoB, CR_MAX_PIXEL_MAP_TABLE)) {
    824             diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_B,to->mapItoBsize,(GLfloat*)to->mapItoB);
     830            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_B,to->mapItoBsize,(GLfloat*)to->mapItoB);
    825831            FILLDIRTY(b->maps);
    826832            FILLDIRTY(b->dirty);
    827833        }
    828834        if (crMemcmp(to->mapItoA, from->mapItoA, CR_MAX_PIXEL_MAP_TABLE)) {
    829             diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_A,to->mapItoAsize,(GLfloat*)to->mapItoA);
     835            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_I_TO_A,to->mapItoAsize,(GLfloat*)to->mapItoA);
    830836            FILLDIRTY(b->maps);
    831837            FILLDIRTY(b->dirty);
    832838        }
    833839        if (crMemcmp(to->mapRtoR, from->mapRtoR, CR_MAX_PIXEL_MAP_TABLE)) {
    834             diff_api.PixelMapfv(GL_PIXEL_MAP_R_TO_R,to->mapRtoRsize,(GLfloat*)to->mapRtoR);
     840            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_R_TO_R,to->mapRtoRsize,(GLfloat*)to->mapRtoR);
    835841            FILLDIRTY(b->maps);
    836842            FILLDIRTY(b->dirty);
    837843        }
    838844        if (crMemcmp(to->mapGtoG, from->mapGtoG, CR_MAX_PIXEL_MAP_TABLE)) {
    839             diff_api.PixelMapfv(GL_PIXEL_MAP_G_TO_G,to->mapGtoGsize,(GLfloat*)to->mapGtoG);
     845            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_G_TO_G,to->mapGtoGsize,(GLfloat*)to->mapGtoG);
    840846            FILLDIRTY(b->maps);
    841847            FILLDIRTY(b->dirty);
    842848        }
    843849        if (crMemcmp(to->mapBtoB, from->mapBtoB, CR_MAX_PIXEL_MAP_TABLE)) {
    844             diff_api.PixelMapfv(GL_PIXEL_MAP_B_TO_B,to->mapBtoBsize,(GLfloat*)to->mapBtoB);
     850            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_B_TO_B,to->mapBtoBsize,(GLfloat*)to->mapBtoB);
    845851            FILLDIRTY(b->maps);
    846852            FILLDIRTY(b->dirty);
    847853        }
    848854        if (crMemcmp(to->mapAtoA, from->mapAtoA, CR_MAX_PIXEL_MAP_TABLE)) {
    849             diff_api.PixelMapfv(GL_PIXEL_MAP_A_TO_A,to->mapAtoAsize,(GLfloat*)to->mapAtoA);
     855            pState->diff_api.PixelMapfv(GL_PIXEL_MAP_A_TO_A,to->mapAtoAsize,(GLfloat*)to->mapAtoA);
    850856            FILLDIRTY(b->maps);
    851857            FILLDIRTY(b->dirty);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_point.c

    r69392 r78375  
    1212{
    1313        CRPointState *p = &ctx->point;
    14         CRStateBits *sb = GetCurrentBits();
     14        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    1515        CRPointBits *pb = &(sb->point);
    1616        int i;
     
    5656}
    5757
    58 void STATE_APIENTRY crStatePointSize(GLfloat size)
    59 {
    60         CRContext *g = GetCurrentContext();
     58void STATE_APIENTRY crStatePointSize(PCRStateTracker pState, GLfloat size)
     59{
     60        CRContext *g = GetCurrentContext(pState);
    6161        CRPointState *p = &(g->point);
    62         CRStateBits *sb = GetCurrentBits();
     62        CRStateBits *sb = GetCurrentBits(pState);
    6363        CRPointBits *pb = &(sb->point);
    6464
    6565        if (g->current.inBeginEnd)
    6666        {
    67                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glPointSize called in begin/end");
     67                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glPointSize called in begin/end");
    6868                return;
    6969        }
     
    7373        if (size <= 0.0f)
    7474        {
    75                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glPointSize called with size <= 0.0: %f", size);
     75                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glPointSize called with size <= 0.0: %f", size);
    7676                return;
    7777        }
     
    8282}
    8383
    84 void STATE_APIENTRY crStatePointParameterfARB(GLenum pname, GLfloat param)
    85 {
    86         CRContext *g = GetCurrentContext();
     84void STATE_APIENTRY crStatePointParameterfARB(PCRStateTracker pState, GLenum pname, GLfloat param)
     85{
     86        CRContext *g = GetCurrentContext(pState);
    8787
    8888        if (g->current.inBeginEnd)
    8989        {
    90                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glPointParameterfARB called in begin/end");
     90                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glPointParameterfARB called in begin/end");
    9191                return;
    9292        }
     
    9494        FLUSH();
    9595
    96         crStatePointParameterfvARB(pname, &param);
    97 }
    98 
    99 void STATE_APIENTRY crStatePointParameterfvARB(GLenum pname, const GLfloat *params)
    100 {
    101         CRContext *g = GetCurrentContext();
     96        crStatePointParameterfvARB(pState, pname, &param);
     97}
     98
     99void STATE_APIENTRY crStatePointParameterfvARB(PCRStateTracker pState, GLenum pname, const GLfloat *params)
     100{
     101        CRContext *g = GetCurrentContext(pState);
    102102        CRPointState *p = &(g->point);
    103         CRStateBits *sb = GetCurrentBits();
     103        CRStateBits *sb = GetCurrentBits(pState);
    104104        CRPointBits *pb = &(sb->point);
    105105
    106106        if (g->current.inBeginEnd)
    107107        {
    108                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glPointParameterfvARB called in begin/end");
     108                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glPointParameterfvARB called in begin/end");
    109109                return;
    110110        }
     
    122122                else
    123123                {
    124                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
     124                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
    125125                        return;
    126126                }
     
    129129                if (g->extensions.ARB_point_parameters) {
    130130                        if (params[0] < 0.0F) {
    131                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid value: %f", params[0]);
     131                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid value: %f", params[0]);
    132132                                return;
    133133                        }
     
    137137                else
    138138                {
    139                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
     139                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
    140140                        return;
    141141                }
     
    144144                if (g->extensions.ARB_point_parameters) {
    145145                        if (params[0] < 0.0F) {
    146                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid value: %f", params[0]);
     146                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid value: %f", params[0]);
    147147                                return;
    148148                        }
     
    152152                else
    153153                {
    154                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
     154                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
    155155                        return;
    156156                }
     
    159159                if (g->extensions.ARB_point_parameters) {
    160160                        if (params[0] < 0.0F) {
    161                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid value: %f", params[0]);
     161                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid value: %f", params[0]);
    162162                                return;
    163163                        }
     
    167167                else
    168168                {
    169                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
     169                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
    170170                        return;
    171171                }
     
    175175            GLenum enmVal = (GLenum)params[0];
    176176        if (enmVal != GL_LOWER_LEFT && enmVal != GL_UPPER_LEFT) {
    177             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid GL_POINT_SPRITE_COORD_ORIGIN value: %f", params[0]);
     177            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid GL_POINT_SPRITE_COORD_ORIGIN value: %f", params[0]);
    178178            return;
    179179        }
     
    183183        }
    184184        default:
    185                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
     185                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
    186186                return;
    187187        }
     
    190190}
    191191
    192 void STATE_APIENTRY crStatePointParameteri(GLenum pname, GLint param)
     192void STATE_APIENTRY crStatePointParameteri(PCRStateTracker pState, GLenum pname, GLint param)
    193193{
    194194        GLfloat f_param = (GLfloat) param;
    195         crStatePointParameterfvARB( pname, &f_param );
    196 }
    197 
    198 void STATE_APIENTRY crStatePointParameteriv(GLenum pname, const GLint *params)
     195        crStatePointParameterfvARB(pState, pname, &f_param );
     196}
     197
     198void STATE_APIENTRY crStatePointParameteriv(PCRStateTracker pState, GLenum pname, const GLint *params)
    199199{
    200200        GLfloat f_param = (GLfloat) (*params);
    201         crStatePointParameterfvARB( pname, &f_param );
     201        crStatePointParameterfvARB(pState, pname, &f_param );
    202202}
    203203
     
    205205        CRContext *fromCtx, CRContext *toCtx)
    206206{
     207    PCRStateTracker pState = fromCtx->pStateTracker;
    207208    CRPointState *from = &(fromCtx->point);
    208209    CRPointState *to = &(toCtx->point);
    209210    unsigned int j, i;
    210211    CRbitvalue nbitID[CR_MAX_BITARRAY];
    211     Assert(0);
     212    Assert(0); /** @todo Is this never called? */
     213
     214    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     215
    212216    for (j=0;j<CR_MAX_BITARRAY;j++)
    213217        nbitID[j] = ~bitID[j];
     
    216220    {
    217221        glAble able[2];
    218         able[0] = diff_api.Disable;
    219         able[1] = diff_api.Enable;
     222        able[0] = pState->diff_api.Disable;
     223        able[1] = pState->diff_api.Enable;
    220224        if (from->pointSmooth != to->pointSmooth)
    221225        {
     
    229233        if (from->pointSize != to->pointSize)
    230234        {
    231             diff_api.PointSize (to->pointSize);
     235            pState->diff_api.PointSize (to->pointSize);
    232236            from->pointSize = to->pointSize;
    233237        }
     
    238242        if (from->minSize != to->minSize)
    239243        {
    240             diff_api.PointParameterfARB (GL_POINT_SIZE_MIN_ARB, to->minSize);
     244            pState->diff_api.PointParameterfARB (GL_POINT_SIZE_MIN_ARB, to->minSize);
    241245            from->minSize = to->minSize;
    242246        }
     
    247251        if (from->maxSize != to->maxSize)
    248252        {
    249             diff_api.PointParameterfARB (GL_POINT_SIZE_MAX_ARB, to->maxSize);
     253            pState->diff_api.PointParameterfARB (GL_POINT_SIZE_MAX_ARB, to->maxSize);
    250254            from->maxSize = to->maxSize;
    251255        }
     
    256260        if (from->fadeThresholdSize != to->fadeThresholdSize)
    257261        {
    258             diff_api.PointParameterfARB (GL_POINT_FADE_THRESHOLD_SIZE_ARB, to->fadeThresholdSize);
     262            pState->diff_api.PointParameterfARB (GL_POINT_FADE_THRESHOLD_SIZE_ARB, to->fadeThresholdSize);
    259263            from->fadeThresholdSize = to->fadeThresholdSize;
    260264        }
     
    265269        if (from->spriteCoordOrigin != to->spriteCoordOrigin)
    266270        {
    267             diff_api.PointParameterfARB (GL_POINT_SPRITE_COORD_ORIGIN, to->spriteCoordOrigin);
     271            pState->diff_api.PointParameterfARB (GL_POINT_SPRITE_COORD_ORIGIN, to->spriteCoordOrigin);
    268272            from->spriteCoordOrigin = to->spriteCoordOrigin;
    269273        }
     
    273277    {
    274278        if (from->distanceAttenuation[0] != to->distanceAttenuation[0] || from->distanceAttenuation[1] != to->distanceAttenuation[1] || from->distanceAttenuation[2] != to->distanceAttenuation[2]) {
    275             diff_api.PointParameterfvARB (GL_POINT_DISTANCE_ATTENUATION_ARB, to->distanceAttenuation);
     279            pState->diff_api.PointParameterfvARB (GL_POINT_DISTANCE_ATTENUATION_ARB, to->distanceAttenuation);
    276280            from->distanceAttenuation[0] = to->distanceAttenuation[0];
    277281            from->distanceAttenuation[1] = to->distanceAttenuation[1];
     
    283287    {
    284288        glAble able[2];
    285         able[0] = diff_api.Disable;
    286         able[1] = diff_api.Enable;
     289        able[0] = pState->diff_api.Disable;
     290        able[1] = pState->diff_api.Enable;
    287291        if (from->pointSprite != to->pointSprite)
    288292        {
     
    299303                GLint replacement = to->coordReplacement[i];
    300304                if (activeUnit != i) {
    301                      diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB );
     305                     pState->diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB );
    302306                     activeUnit = i;
    303307                }
    304                 diff_api.TexEnviv(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, &replacement);
     308                pState->diff_api.TexEnviv(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, &replacement);
    305309                from->coordReplacement[i] = to->coordReplacement[i];
    306310                CLEARDIRTY(b->coordReplacement[i], nbitID);
     
    308312        }
    309313        if (activeUnit != toCtx->texture.curTextureUnit)
    310            diff_api.ActiveTextureARB(GL_TEXTURE0 + toCtx->texture.curTextureUnit);
     314           pState->diff_api.ActiveTextureARB(GL_TEXTURE0 + toCtx->texture.curTextureUnit);
    311315    }
    312316    CLEARDIRTY(b->dirty, nbitID);
     
    316320        CRContext *fromCtx, CRContext *toCtx)
    317321{
     322    PCRStateTracker pState = fromCtx->pStateTracker;
    318323    CRPointState *from = &(fromCtx->point);
    319324    CRPointState *to = &(toCtx->point);
     
    321326    GLboolean fEnabled;
    322327    CRbitvalue nbitID[CR_MAX_BITARRAY];
     328
     329    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     330
    323331    for (j=0;j<CR_MAX_BITARRAY;j++)
    324332        nbitID[j] = ~bitID[j];
     
    327335    {
    328336        glAble able[2];
    329         able[0] = diff_api.Disable;
    330         able[1] = diff_api.Enable;
     337        able[0] = pState->diff_api.Disable;
     338        able[1] = pState->diff_api.Enable;
    331339        if (from->pointSmooth != to->pointSmooth)
    332340        {
     
    341349        if (from->pointSize != to->pointSize)
    342350        {
    343             diff_api.PointSize (to->pointSize);
     351            pState->diff_api.PointSize (to->pointSize);
    344352            FILLDIRTY(b->size);
    345353            FILLDIRTY(b->dirty);
     
    351359        if (from->minSize != to->minSize)
    352360        {
    353             diff_api.PointParameterfARB (GL_POINT_SIZE_MIN_ARB, to->minSize);
     361            pState->diff_api.PointParameterfARB (GL_POINT_SIZE_MIN_ARB, to->minSize);
    354362            FILLDIRTY(b->minSize);
    355363            FILLDIRTY(b->dirty);
     
    361369        if (from->maxSize != to->maxSize)
    362370        {
    363             diff_api.PointParameterfARB (GL_POINT_SIZE_MAX_ARB, to->maxSize);
     371            pState->diff_api.PointParameterfARB (GL_POINT_SIZE_MAX_ARB, to->maxSize);
    364372            FILLDIRTY(b->maxSize);
    365373            FILLDIRTY(b->dirty);
     
    371379        if (from->fadeThresholdSize != to->fadeThresholdSize)
    372380        {
    373             diff_api.PointParameterfARB (GL_POINT_FADE_THRESHOLD_SIZE_ARB, to->fadeThresholdSize);
     381            pState->diff_api.PointParameterfARB (GL_POINT_FADE_THRESHOLD_SIZE_ARB, to->fadeThresholdSize);
    374382            FILLDIRTY(b->fadeThresholdSize);
    375383            FILLDIRTY(b->dirty);
     
    381389        if (from->spriteCoordOrigin != to->spriteCoordOrigin)
    382390        {
    383             diff_api.PointParameterfARB (GL_POINT_SPRITE_COORD_ORIGIN, to->spriteCoordOrigin);
     391            pState->diff_api.PointParameterfARB (GL_POINT_SPRITE_COORD_ORIGIN, to->spriteCoordOrigin);
    384392            FILLDIRTY(b->spriteCoordOrigin);
    385393            FILLDIRTY(b->dirty);
     
    390398    {
    391399        if (from->distanceAttenuation[0] != to->distanceAttenuation[0] || from->distanceAttenuation[1] != to->distanceAttenuation[1] || from->distanceAttenuation[2] != to->distanceAttenuation[2]) {
    392             diff_api.PointParameterfvARB (GL_POINT_DISTANCE_ATTENUATION_ARB, to->distanceAttenuation);
     400            pState->diff_api.PointParameterfvARB (GL_POINT_DISTANCE_ATTENUATION_ARB, to->distanceAttenuation);
    393401            FILLDIRTY(b->distanceAttenuation);
    394402            FILLDIRTY(b->dirty);
     
    404412                if (!fEnabled)
    405413                {
    406                     diff_api.Enable(GL_POINT_SPRITE_ARB);
     414                    pState->diff_api.Enable(GL_POINT_SPRITE_ARB);
    407415                    fEnabled = GL_TRUE;
    408416                }
     
    422430        }
    423431        if (activeUnit != toCtx->texture.curTextureUnit)
    424            diff_api.ActiveTextureARB(GL_TEXTURE0 + toCtx->texture.curTextureUnit);
     432           pState->diff_api.ActiveTextureARB(GL_TEXTURE0 + toCtx->texture.curTextureUnit);
    425433    }
    426434    if (CHECKDIRTY(b->enableSprite, bitID))
    427435    {
    428436        glAble able[2];
    429         able[0] = diff_api.Disable;
    430         able[1] = diff_api.Enable;
     437        able[0] = pState->diff_api.Disable;
     438        able[1] = pState->diff_api.Enable;
    431439        if (fEnabled != to->pointSprite)
    432440        {
     
    440448    {
    441449        glAble able[2];
    442         able[0] = diff_api.Disable;
    443         able[1] = diff_api.Enable;
     450        able[0] = pState->diff_api.Disable;
     451        able[1] = pState->diff_api.Enable;
    444452        able[to->pointSprite](GL_POINT_SPRITE_ARB);
    445453    }
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_polygon.c

    r69392 r78375  
    1414{
    1515    CRPolygonState *p = &ctx->polygon;
    16         CRStateBits *sb = GetCurrentBits();
     16        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    1717    CRPolygonBits *pb = &(sb->polygon);
    1818    int i;
     
    4343}
    4444
    45 void STATE_APIENTRY crStateCullFace(GLenum mode)
    46 {
    47     CRContext *g = GetCurrentContext();
    48     CRPolygonState *p = &(g->polygon);
    49         CRStateBits *sb = GetCurrentBits();
    50     CRPolygonBits *pb = &(sb->polygon);
    51 
    52     if (g->current.inBeginEnd)
    53     {
    54         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     45void STATE_APIENTRY crStateCullFace(PCRStateTracker pState, GLenum mode)
     46{
     47    CRContext *g = GetCurrentContext(pState);
     48    CRPolygonState *p = &(g->polygon);
     49        CRStateBits *sb = GetCurrentBits(pState);
     50    CRPolygonBits *pb = &(sb->polygon);
     51
     52    if (g->current.inBeginEnd)
     53    {
     54        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    5555                "glCullFace called in begin/end");
    5656        return;
     
    6161    if (mode != GL_FRONT && mode != GL_BACK && mode != GL_FRONT_AND_BACK)
    6262    {
    63         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     63        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    6464                "glCullFace called with bogus mode: 0x%x", mode);
    6565        return;
     
    7171}
    7272
    73 void STATE_APIENTRY crStateFrontFace (GLenum mode)
    74 {
    75     CRContext *g = GetCurrentContext();
    76     CRPolygonState *p = &(g->polygon);
    77         CRStateBits *sb = GetCurrentBits();
    78     CRPolygonBits *pb = &(sb->polygon);
    79 
    80     if (g->current.inBeginEnd)
    81     {
    82         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     73void STATE_APIENTRY crStateFrontFace (PCRStateTracker pState, GLenum mode)
     74{
     75    CRContext *g = GetCurrentContext(pState);
     76    CRPolygonState *p = &(g->polygon);
     77        CRStateBits *sb = GetCurrentBits(pState);
     78    CRPolygonBits *pb = &(sb->polygon);
     79
     80    if (g->current.inBeginEnd)
     81    {
     82        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    8383                "glFrontFace called in begin/end");
    8484        return;
     
    8989    if (mode != GL_CW && mode != GL_CCW)
    9090    {
    91         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     91        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    9292                "glFrontFace called with bogus mode: 0x%x", mode);
    9393        return;
     
    9999}
    100100
    101 void  STATE_APIENTRY crStatePolygonMode (GLenum face, GLenum mode)
    102 {
    103     CRContext *g = GetCurrentContext();
    104     CRPolygonState *p = &(g->polygon);
    105         CRStateBits *sb = GetCurrentBits();
    106     CRPolygonBits *pb = &(sb->polygon);
    107 
    108     if (g->current.inBeginEnd)
    109     {
    110         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     101void  STATE_APIENTRY crStatePolygonMode (PCRStateTracker pState, GLenum face, GLenum mode)
     102{
     103    CRContext *g = GetCurrentContext(pState);
     104    CRPolygonState *p = &(g->polygon);
     105        CRStateBits *sb = GetCurrentBits(pState);
     106    CRPolygonBits *pb = &(sb->polygon);
     107
     108    if (g->current.inBeginEnd)
     109    {
     110        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    111111                "glPolygonMode called in begin/end");
    112112        return;
     
    117117    if (mode != GL_POINT && mode != GL_LINE && mode != GL_FILL)
    118118    {
    119         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     119        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    120120                "glPolygonMode called with bogus mode: 0x%x", mode);
    121121        return;
     
    133133            break;
    134134        default:
    135             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     135            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    136136                    "glPolygonMode called with bogus face: 0x%x", face);
    137137            return;
     
    141141}
    142142
    143 void STATE_APIENTRY crStatePolygonOffset (GLfloat factor, GLfloat units)
    144 {
    145     CRContext *g = GetCurrentContext();
    146     CRPolygonState *p = &(g->polygon);
    147         CRStateBits *sb = GetCurrentBits();
    148     CRPolygonBits *pb = &(sb->polygon);
    149 
    150     if (g->current.inBeginEnd)
    151     {
    152         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     143void STATE_APIENTRY crStatePolygonOffset (PCRStateTracker pState, GLfloat factor, GLfloat units)
     144{
     145    CRContext *g = GetCurrentContext(pState);
     146    CRPolygonState *p = &(g->polygon);
     147        CRStateBits *sb = GetCurrentBits(pState);
     148    CRPolygonBits *pb = &(sb->polygon);
     149
     150    if (g->current.inBeginEnd)
     151    {
     152        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    153153                "glPolygonOffset called in begin/end");
    154154        return;
     
    164164}
    165165
    166 void STATE_APIENTRY crStatePolygonStipple (const GLubyte *p)
    167 {
    168     CRContext *g = GetCurrentContext();
     166void STATE_APIENTRY crStatePolygonStipple (PCRStateTracker pState, const GLubyte *p)
     167{
     168    CRContext *g = GetCurrentContext(pState);
    169169    CRPolygonState *poly = &(g->polygon);
    170         CRStateBits *sb = GetCurrentBits();
    171     CRPolygonBits *pb = &(sb->polygon);
    172 
    173     if (g->current.inBeginEnd)
    174     {
    175         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     170        CRStateBits *sb = GetCurrentBits(pState);
     171    CRPolygonBits *pb = &(sb->polygon);
     172
     173    if (g->current.inBeginEnd)
     174    {
     175        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    176176                "glPolygonStipple called in begin/end");
    177177        return;
     
    180180    FLUSH();
    181181
    182     if (!p && !crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     182    if (!p && !crStateIsBufferBound(pState, GL_PIXEL_UNPACK_BUFFER_ARB))
    183183    {
    184184        crDebug("Void pointer passed to PolygonStipple");
     
    187187
    188188    /** @todo track mask if buffer is bound?*/
    189     if (!crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     189    if (!crStateIsBufferBound(pState, GL_PIXEL_UNPACK_BUFFER_ARB))
    190190    {
    191191        crMemcpy((char*)poly->stipple, (char*)p, 128);
     
    196196}
    197197
    198 void STATE_APIENTRY crStateGetPolygonStipple( GLubyte *b )
    199 {
    200     CRContext *g = GetCurrentContext();
     198void STATE_APIENTRY crStateGetPolygonStipple(PCRStateTracker pState, GLubyte *b )
     199{
     200    CRContext *g = GetCurrentContext(pState);
    201201    CRPolygonState *poly = &(g->polygon);
    202202
    203203    if (g->current.inBeginEnd)
    204204    {
    205         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     205        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    206206                "glGetPolygonStipple called in begin/end");
    207207        return;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_polygon.txt

    r63199 r78375  
    1414:mode:backMode:PolygonMode,GL_BACK
    1515:mode:frontMode:PolygonMode,GL_FRONT
    16 -:stipple:stipple:*diff_api.PolygonStipple ((GLubyte *) to->stipple);
     16-:stipple:stipple:*pState->diff_api.PolygonStipple ((GLubyte *) to->stipple);
    1717+:stipple:*int iStripple;
    18 +:stipple:*diff_api.PolygonStipple ((GLubyte *) to->stipple);
     18+:stipple:*pState->diff_api.PolygonStipple ((GLubyte *) to->stipple);
    1919+:stipple:*for (iStripple=0; iStripple<32; iStripple++)
    2020+:stipple:*{
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_program.c

    r71903 r78375  
    132132 */
    133133static CRProgram *
    134 BindProgram(GLenum target, GLuint id,
     134BindProgram(PCRStateTracker pState, GLenum target, GLuint id,
    135135                        GLenum vertexTarget, GLenum fragmentTarget)
    136136{
    137     CRContext *g = GetCurrentContext();
    138     CRProgramState *p = &(g->program);
    139     CRStateBits *sb = GetCurrentBits();
     137    CRContext *g = GetCurrentContext(pState);
     138    CRProgramState *p = &(g->program);
     139    CRStateBits *sb = GetCurrentBits(pState);
    140140    CRProgramBits *pb = &(sb->program);
    141141    CRProgram *prog;
    142142
    143143    if (g->current.inBeginEnd) {
    144         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     144        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    145145                                 "glBindProgram called in Begin/End");
    146146        return NULL;
     
    155155        }
    156156        else {
    157             crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     157            crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    158158                                     "glBindProgram(bad target)");
    159159            return NULL;
     
    165165
    166166    if (!prog) {
    167         crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glBindProgram");
     167        crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY, "glBindProgram");
    168168        return NULL;
    169169    }
    170170    else if (prog->target != target) {
    171         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     171        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    172172                                 "glBindProgram target mismatch");
    173173        return NULL;
     
    190190
    191191
    192 void STATE_APIENTRY crStateBindProgramNV(GLenum target, GLuint id)
    193 {
    194     CRProgram *prog = BindProgram(target, id, GL_VERTEX_PROGRAM_NV,
     192void STATE_APIENTRY crStateBindProgramNV(PCRStateTracker pState, GLenum target, GLuint id)
     193{
     194    CRProgram *prog = BindProgram(pState, target, id, GL_VERTEX_PROGRAM_NV,
    195195                                  GL_FRAGMENT_PROGRAM_NV);
    196196    if (prog) {
     
    200200
    201201
    202 void STATE_APIENTRY crStateBindProgramARB(GLenum target, GLuint id)
    203 {
    204     CRProgram *prog = BindProgram(target, id, GL_VERTEX_PROGRAM_ARB,
     202void STATE_APIENTRY crStateBindProgramARB(PCRStateTracker pState, GLenum target, GLuint id)
     203{
     204    CRProgram *prog = BindProgram(pState, target, id, GL_VERTEX_PROGRAM_ARB,
    205205                                  GL_FRAGMENT_PROGRAM_ARB);
    206206    if (prog) {
     
    210210
    211211
    212 void STATE_APIENTRY crStateDeleteProgramsARB(GLsizei n, const GLuint *ids)
    213 {
    214     CRContext *g = GetCurrentContext();
    215     CRProgramState *p = &(g->program);
    216     CRStateBits *sb = GetCurrentBits();
     212void STATE_APIENTRY crStateDeleteProgramsARB(PCRStateTracker pState, GLsizei n, const GLuint *ids)
     213{
     214    CRContext *g = GetCurrentContext(pState);
     215    CRProgramState *p = &(g->program);
     216    CRStateBits *sb = GetCurrentBits(pState);
    217217    CRProgramBits *pb = &(sb->program);
    218218    GLint i;
    219219
    220220    if (g->current.inBeginEnd) {
    221         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     221        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    222222                                 "glDeleteProgramsNV called in Begin/End");
    223223        return;
     
    226226    if (n < 0)
    227227    {
    228         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glDeleteProgramsNV(n)");
     228        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glDeleteProgramsNV(n)");
    229229        return;
    230230    }
     
    253253
    254254
    255 void STATE_APIENTRY crStateExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
     255void STATE_APIENTRY crStateExecuteProgramNV(PCRStateTracker pState, GLenum target, GLuint id, const GLfloat *params)
    256256{
    257257    /* Hmmm, this is really hard to do if we don't actually execute
    258258     * the program in a software simulation.
    259259     */
     260    RT_NOREF(pState);
    260261    (void)params;
    261262    (void)target;
     
    264265
    265266
    266 void STATE_APIENTRY crStateGenProgramsNV(GLsizei n, GLuint *ids)
    267 {
    268     CRContext *g = GetCurrentContext();
     267void STATE_APIENTRY crStateGenProgramsNV(PCRStateTracker pState, GLsizei n, GLuint *ids)
     268{
     269    CRContext *g = GetCurrentContext(pState);
    269270    CRProgramState *p = &(g->program);
    270271
     
    272273}
    273274
    274 void STATE_APIENTRY crStateGenProgramsARB(GLsizei n, GLuint *ids)
    275 {
    276     crStateGenProgramsNV(n, ids);
    277 }
    278 
    279 
    280 GLboolean STATE_APIENTRY crStateIsProgramARB(GLuint id)
    281 {
    282     CRContext *g = GetCurrentContext();
     275void STATE_APIENTRY crStateGenProgramsARB(PCRStateTracker pState, GLsizei n, GLuint *ids)
     276{
     277    crStateGenProgramsNV(pState, n, ids);
     278}
     279
     280
     281GLboolean STATE_APIENTRY crStateIsProgramARB(PCRStateTracker pState, GLuint id)
     282{
     283    CRContext *g = GetCurrentContext(pState);
    283284    CRProgramState *p = &(g->program);
    284285    CRProgram *prog;
    285286
    286287    if (g->current.inBeginEnd) {
    287         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     288        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    288289                                 "glIsProgram called in Begin/End");
    289290        return GL_FALSE;
     
    291292
    292293    if (id == 0) {
    293         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     294        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    294295                                     "glIsProgram(id==0)");
    295296        return GL_FALSE;
     
    304305
    305306
    306 GLboolean STATE_APIENTRY crStateAreProgramsResidentNV(GLsizei n, const GLuint *ids, GLboolean *residences)
    307 {
    308     CRContext *g = GetCurrentContext();
     307GLboolean STATE_APIENTRY crStateAreProgramsResidentNV(PCRStateTracker pState, GLsizei n, const GLuint *ids, GLboolean *residences)
     308{
     309    CRContext *g = GetCurrentContext(pState);
    309310    CRProgramState *p = &(g->program);
    310311    int i;
     
    312313
    313314    if (n < 0) {
    314         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     315        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    315316                                 "glAreProgramsResidentNV(n)");
    316317        return GL_FALSE;
     
    321322
    322323        if (ids[i] == 0) {
    323             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     324            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    324325                                     "glAreProgramsResidentNV(id)");
    325326            return GL_FALSE;
     
    328329        prog = (CRProgram *) crHashtableSearch(p->programHash, ids[i]);
    329330        if (!prog) {
    330             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     331            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    331332                                     "glAreProgramsResidentNV(id)");
    332333            return GL_FALSE;
     
    351352
    352353
    353 void STATE_APIENTRY crStateRequestResidentProgramsNV(GLsizei n, const GLuint *ids)
    354 {
    355     CRContext *g = GetCurrentContext();
     354void STATE_APIENTRY crStateRequestResidentProgramsNV(PCRStateTracker pState, GLsizei n, const GLuint *ids)
     355{
     356    CRContext *g = GetCurrentContext(pState);
    356357    CRProgramState *p = &(g->program);
    357358    GLint i;
    358359
    359360    if (g->current.inBeginEnd) {
    360         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     361        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    361362                                 "glRequestResidentProgramsNV called in Begin/End");
    362363        return;
     
    364365
    365366    if (n < 0) {
    366         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     367        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    367368                                     "glRequestResidentProgramsNV(n<0)");
    368369        return;
     
    377378
    378379
    379 void STATE_APIENTRY crStateLoadProgramNV(GLenum target, GLuint id, GLsizei len,
     380void STATE_APIENTRY crStateLoadProgramNV(PCRStateTracker pState, GLenum target, GLuint id, GLsizei len,
    380381                                                                                 const GLubyte *program)
    381382{
    382     CRContext *g = GetCurrentContext();
    383     CRProgramState *p = &(g->program);
    384     CRStateBits *sb = GetCurrentBits();
     383    CRContext *g = GetCurrentContext(pState);
     384    CRProgramState *p = &(g->program);
     385    CRStateBits *sb = GetCurrentBits(pState);
    385386    CRProgramBits *pb = &(sb->program);
    386387    CRProgram *prog;
     
    388389
    389390    if (g->current.inBeginEnd) {
    390         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     391        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    391392                                 "glLoadProgramNV called in Begin/End");
    392393        return;
     
    394395
    395396    if (id == 0) {
    396         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     397        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    397398                                 "glLoadProgramNV(id==0)");
    398399        return;
     
    402403
    403404    if (!prog) {
    404         crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glLoadProgramNV");
     405        crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY, "glLoadProgramNV");
    405406        return;
    406407    }
    407408    else if (prog && prog->target != target) {
    408         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     409        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    409410                                 "glLoadProgramNV(target)");
    410411        return;
     
    413414    progCopy = crAlloc(len);
    414415    if (!progCopy) {
    415             crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glLoadProgramNV");
     416            crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY, "glLoadProgramNV");
    416417            return;
    417418    }
     
    422423     && crStrncmp((const char *) program,"!!VP2.0", 7) != 0
    423424     && crStrncmp((const char *) program,"!!VSP1.0", 8) != 0) {
    424             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLoadProgramNV");
     425            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glLoadProgramNV");
    425426            crDebug("program = (%s)\n",program);
    426427            return;
     
    439440
    440441
    441 void STATE_APIENTRY crStateProgramStringARB(GLenum target, GLenum format,
     442void STATE_APIENTRY crStateProgramStringARB(PCRStateTracker pState, GLenum target, GLenum format,
    442443                                                                                        GLsizei len, const GLvoid *string)
    443444{
    444     CRContext *g = GetCurrentContext();
    445     CRProgramState *p = &(g->program);
    446     CRStateBits *sb = GetCurrentBits();
     445    CRContext *g = GetCurrentContext(pState);
     446    CRProgramState *p = &(g->program);
     447    CRStateBits *sb = GetCurrentBits(pState);
    447448    CRProgramBits *pb = &(sb->program);
    448449    CRProgram *prog;
     
    450451
    451452    if (g->current.inBeginEnd) {
    452         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     453        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    453454                                 "glProgramStringARB called in Begin/End");
    454455        return;
     
    456457
    457458    if (format != GL_PROGRAM_FORMAT_ASCII_ARB) {
    458         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     459        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    459460                                 "glProgramStringARB(format)");
    460461        return;
     
    470471    }
    471472    else {
    472         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     473        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    473474                                 "glProgramStringARB(target)");
    474475        return;
     
    480481    progCopy = crAlloc(len);
    481482    if (!progCopy) {
    482         crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glProgramStringARB");
     483        crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY, "glProgramStringARB");
    483484        return;
    484485    }
    485486    if (crStrncmp(string,"!!ARBvp1.0", 10) !=  0
    486487     && crStrncmp(string,"!!ARBfp1.0", 10) != 0) {
    487             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glProgramStringARB");
     488            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glProgramStringARB");
    488489            return;
    489490    }
     
    502503
    503504
    504 void STATE_APIENTRY crStateGetProgramivNV(GLuint id, GLenum pname, GLint *params)
    505 {
    506     CRContext *g = GetCurrentContext();
     505void STATE_APIENTRY crStateGetProgramivNV(PCRStateTracker pState, GLuint id, GLenum pname, GLint *params)
     506{
     507    CRContext *g = GetCurrentContext(pState);
    507508    CRProgramState *p = &(g->program);
    508509    CRProgram *prog;
    509510
    510511    if (g->current.inBeginEnd) {
    511         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     512        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    512513                                 "glGetProgramivNV called in Begin/End");
    513514        return;
     
    515516
    516517    if (id == 0) {
    517         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     518        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    518519                                 "glGetProgramivNV(bad id)");
    519520        return;
     
    522523    prog = (CRProgram *) crHashtableSearch(p->programHash, id);
    523524    if (!prog) {
    524         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     525        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    525526                                 "glGetProgramivNV(bad id)");
    526527        return;
     
    538539        return;
    539540    default:
    540         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     541        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    541542                                 "glGetProgramivNV(pname)");
    542543        return;
     
    545546
    546547
    547 void STATE_APIENTRY crStateGetProgramStringNV(GLuint id, GLenum pname, GLubyte *program)
    548 {
    549     CRContext *g = GetCurrentContext();
     548void STATE_APIENTRY crStateGetProgramStringNV(PCRStateTracker pState, GLuint id, GLenum pname, GLubyte *program)
     549{
     550    CRContext *g = GetCurrentContext(pState);
    550551    CRProgramState *p = &(g->program);
    551552    CRProgram *prog;
    552553
    553554    if (pname != GL_PROGRAM_STRING_NV) {
    554         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     555        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    555556                                 "glGetProgramStringNV(pname)");
    556557        return;
     
    558559
    559560    if (g->current.inBeginEnd) {
    560         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     561        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    561562                                 "glGetProgramStringNV called in Begin/End");
    562563        return;
     
    564565
    565566    if (id == 0) {
    566         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     567        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    567568                                 "glGetProgramStringNV(bad id)");
    568569        return;
     
    571572    prog = (CRProgram *) crHashtableSearch(p->programHash, id);
    572573    if (!prog) {
    573         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     574        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    574575                                 "glGetProgramStringNV(bad id)");
    575576        return;
     
    580581
    581582
    582 void STATE_APIENTRY crStateGetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
    583 {
    584     CRContext *g = GetCurrentContext();
     583void STATE_APIENTRY crStateGetProgramStringARB(PCRStateTracker pState, GLenum target, GLenum pname, GLvoid *string)
     584{
     585    CRContext *g = GetCurrentContext(pState);
    585586    CRProgramState *p = &(g->program);
    586587    CRProgram *prog;
     
    593594    }
    594595    else {
    595         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     596        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    596597                                 "glGetProgramStringNV(target)");
    597598        return;
     
    599600
    600601    if (pname != GL_PROGRAM_STRING_NV) {
    601         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     602        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    602603                                 "glGetProgramStringNV(pname)");
    603604        return;
     
    605606
    606607    if (g->current.inBeginEnd) {
    607         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     608        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    608609                                 "glGetProgramStringNV called in Begin/End");
    609610        return;
     
    614615
    615616
    616 void STATE_APIENTRY crStateProgramParameter4dNV(GLenum target, GLuint index,
    617                                 GLdouble x, GLdouble y, GLdouble z, GLdouble w)
    618 {
    619     crStateProgramParameter4fNV(target, index, (GLfloat) x, (GLfloat) y,
     617void STATE_APIENTRY crStateProgramParameter4dNV(PCRStateTracker pState, GLenum target, GLuint index,
     618                                                GLdouble x, GLdouble y, GLdouble z, GLdouble w)
     619{
     620    crStateProgramParameter4fNV(pState, target, index, (GLfloat) x, (GLfloat) y,
    620621                                                            (GLfloat) z, (GLfloat) w);
    621622}
    622623
    623624
    624 void STATE_APIENTRY crStateProgramParameter4dvNV(GLenum target, GLuint index,
    625                                  const GLdouble *params)
    626 {
    627     crStateProgramParameter4fNV(target, index,
    628                                                             (GLfloat) params[0], (GLfloat) params[1],
    629                                                             (GLfloat) params[2], (GLfloat) params[3]);
    630 }
    631 
    632 
    633 void STATE_APIENTRY crStateProgramParameter4fNV(GLenum target, GLuint index,
    634                                                                  GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    635 {
    636     CRContext *g = GetCurrentContext();
    637     CRProgramState *p = &(g->program);
    638     CRStateBits *sb = GetCurrentBits();
     625void STATE_APIENTRY crStateProgramParameter4dvNV(PCRStateTracker pState, GLenum target, GLuint index,
     626                                                 const GLdouble *params)
     627{
     628    crStateProgramParameter4fNV(pState, target, index, (GLfloat) params[0], (GLfloat) params[1],
     629                                (GLfloat) params[2], (GLfloat) params[3]);
     630}
     631
     632
     633void STATE_APIENTRY crStateProgramParameter4fNV(PCRStateTracker pState, GLenum target, GLuint index,
     634                                                GLfloat x, GLfloat y, GLfloat z, GLfloat w)
     635{
     636    CRContext *g = GetCurrentContext(pState);
     637    CRProgramState *p = &(g->program);
     638    CRStateBits *sb = GetCurrentBits(pState);
    639639    CRProgramBits *pb = &(sb->program);
    640640
    641641    if (g->current.inBeginEnd) {
    642         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     642        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    643643                                 "glProgramParameterNV called in Begin/End");
    644644        return;
     
    656656        }
    657657        else {
    658             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     658            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    659659                                     "glProgramParameterNV(index=%d)", index);
    660660            return;
     
    662662    }
    663663    else {
    664         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     664        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    665665                                 "glProgramParameterNV(target)");
    666666        return;
     
    669669
    670670
    671 void STATE_APIENTRY crStateProgramParameter4fvNV(GLenum target, GLuint index,
    672                                  const GLfloat *params)
    673 {
    674     crStateProgramParameter4fNV(target, index,
    675                                                             params[0], params[1], params[2], params[3]);
    676 }
    677 
    678 
    679 void STATE_APIENTRY crStateProgramParameters4dvNV(GLenum target, GLuint index,
    680                                   GLuint num, const GLdouble *params)
    681 {
    682     CRContext *g = GetCurrentContext();
    683     CRProgramState *p = &(g->program);
    684     CRStateBits *sb = GetCurrentBits();
     671void STATE_APIENTRY crStateProgramParameter4fvNV(PCRStateTracker pState, GLenum target, GLuint index,
     672                                                 const GLfloat *params)
     673{
     674    crStateProgramParameter4fNV(pState, target, index, params[0], params[1], params[2], params[3]);
     675}
     676
     677
     678void STATE_APIENTRY crStateProgramParameters4dvNV(PCRStateTracker pState, GLenum target, GLuint index,
     679                                                  GLuint num, const GLdouble *params)
     680{
     681    CRContext *g = GetCurrentContext(pState);
     682    CRProgramState *p = &(g->program);
     683    CRStateBits *sb = GetCurrentBits(pState);
    685684    CRProgramBits *pb = &(sb->program);
    686685
    687686    if (g->current.inBeginEnd) {
    688         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     687        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    689688                                 "glProgramParameters4dvNV called in Begin/End");
    690689        return;
     
    693692    if (target == GL_VERTEX_PROGRAM_NV) {
    694693        if (index >= UINT32_MAX - num) {
    695             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     694            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    696695                "glProgramParameters4dvNV(index+num) integer overflow");
    697696            return;
     
    710709        }
    711710        else {
    712             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     711            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    713712                                     "glProgramParameters4dvNV(index+num)");
    714713            return;
     
    716715    }
    717716    else {
    718         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     717        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    719718                                 "glProgramParameterNV(target)");
    720719        return;
     
    723722
    724723
    725 void STATE_APIENTRY crStateProgramParameters4fvNV(GLenum target, GLuint index,
    726                                   GLuint num, const GLfloat *params)
    727 {
    728     CRContext *g = GetCurrentContext();
    729     CRProgramState *p = &(g->program);
    730     CRStateBits *sb = GetCurrentBits();
     724void STATE_APIENTRY crStateProgramParameters4fvNV(PCRStateTracker pState, GLenum target, GLuint index,
     725                                                  GLuint num, const GLfloat *params)
     726{
     727    CRContext *g = GetCurrentContext(pState);
     728    CRProgramState *p = &(g->program);
     729    CRStateBits *sb = GetCurrentBits(pState);
    731730    CRProgramBits *pb = &(sb->program);
    732731
    733732    if (g->current.inBeginEnd) {
    734         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     733        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    735734                                 "glProgramParameters4dvNV called in Begin/End");
    736735        return;
     
    739738    if (target == GL_VERTEX_PROGRAM_NV) {
    740739        if (index >= UINT32_MAX - num) {
    741             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     740            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    742741                "glProgramParameters4dvNV(index+num) integer overflow");
    743742            return;
     
    756755        }
    757756        else {
    758             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     757            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    759758                                     "glProgramParameters4dvNV(index+num)");
    760759            return;
     
    762761    }
    763762    else {
    764         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     763        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    765764                                 "glProgramParameterNV(target)");
    766765        return;
     
    769768
    770769
    771 void STATE_APIENTRY crStateGetProgramParameterfvNV(GLenum target, GLuint index,
    772                                                                         GLenum pname, GLfloat *params)
    773 {
    774     CRContext *g = GetCurrentContext();
    775     CRProgramState *p = &(g->program);
    776 
    777     if (g->current.inBeginEnd) {
    778         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     770void STATE_APIENTRY crStateGetProgramParameterfvNV(PCRStateTracker pState, GLenum target, GLuint index,
     771                                                   GLenum pname, GLfloat *params)
     772{
     773    CRContext *g = GetCurrentContext(pState);
     774    CRProgramState *p = &(g->program);
     775
     776    if (g->current.inBeginEnd) {
     777        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    779778                                 "glGetProgramParameterfvNV called in Begin/End");
    780779        return;
     
    790789            }
    791790            else {
    792                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     791                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    793792                                         "glGetProgramParameterfvNV(index)");
    794793                return;
     
    796795        }
    797796        else {
    798             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     797            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    799798                                     "glGetProgramParameterfvNV(pname)");
    800799            return;
     
    802801    }
    803802    else {
    804         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     803        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    805804                                 "glGetProgramParameterfvNV(target)");
    806805        return;
     
    809808
    810809
    811 void STATE_APIENTRY crStateGetProgramParameterdvNV(GLenum target, GLuint index,
    812                                    GLenum pname, GLdouble *params)
    813 {
    814     CRContext *g = GetCurrentContext();
    815     CRProgramState *p = &(g->program);
    816 
    817     if (g->current.inBeginEnd) {
    818         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     810void STATE_APIENTRY crStateGetProgramParameterdvNV(PCRStateTracker pState, GLenum target, GLuint index,
     811                                                   GLenum pname, GLdouble *params)
     812{
     813    CRContext *g = GetCurrentContext(pState);
     814    CRProgramState *p = &(g->program);
     815
     816    if (g->current.inBeginEnd) {
     817        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    819818                                 "glGetProgramParameterdvNV called in Begin/End");
    820819        return;
     
    830829            }
    831830            else {
    832                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     831                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    833832                                         "glGetProgramParameterdvNV(index)");
    834833                return;
     
    836835        }
    837836        else {
    838             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     837            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    839838                                     "glGetProgramParameterdvNV(pname)");
    840839            return;
     
    842841    }
    843842    else {
    844         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     843        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    845844                                 "glGetProgramParameterdvNV(target)");
    846845        return;
     
    849848
    850849
    851 void STATE_APIENTRY crStateTrackMatrixNV(GLenum target, GLuint address,
    852                          GLenum matrix, GLenum transform)
    853 {
    854     CRContext *g = GetCurrentContext();
    855     CRProgramState *p = &(g->program);
    856     CRStateBits *sb = GetCurrentBits();
     850void STATE_APIENTRY crStateTrackMatrixNV(PCRStateTracker pState, GLenum target, GLuint address,
     851                                         GLenum matrix, GLenum transform)
     852{
     853    CRContext *g = GetCurrentContext(pState);
     854    CRProgramState *p = &(g->program);
     855    CRStateBits *sb = GetCurrentBits(pState);
    857856    CRProgramBits *pb = &(sb->program);
    858857
    859858    if (g->current.inBeginEnd) {
    860         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     859        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    861860                                 "glGetTrackMatrixivNV called in Begin/End");
    862861        return;
     
    865864    if (target == GL_VERTEX_PROGRAM_NV) {
    866865        if (address & 0x3 || address >= g->limits.maxVertexProgramEnvParams) {
    867             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     866            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    868867                                     "glTrackMatrixNV(address)");
    869868            return;
     
    896895            break;
    897896        default:
    898             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     897            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    899898                                     "glTrackMatrixNV(matrix = %x)",matrix);
    900899            return;
     
    909908            break;
    910909        default:
    911             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     910            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    912911                                     "glTrackMatrixNV(transform = %x)",transform);
    913912            return;
     
    920919    }
    921920    else {
    922         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     921        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    923922                                 "glTrackMatrixNV(target = %x)",target);
    924923    }
     
    926925
    927926
    928 void STATE_APIENTRY crStateGetTrackMatrixivNV(GLenum target, GLuint address,
    929                                                              GLenum pname, GLint *params)
    930 {
    931     CRContext *g = GetCurrentContext();
    932     CRProgramState *p = &(g->program);
    933 
    934     if (g->current.inBeginEnd) {
    935         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     927void STATE_APIENTRY crStateGetTrackMatrixivNV(PCRStateTracker pState, GLenum target, GLuint address,
     928                                              GLenum pname, GLint *params)
     929{
     930    CRContext *g = GetCurrentContext(pState);
     931    CRProgramState *p = &(g->program);
     932
     933    if (g->current.inBeginEnd) {
     934        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    936935                                 "glGetTrackMatrixivNV called in Begin/End");
    937936        return;
     
    940939    if (target == GL_VERTEX_PROGRAM_NV) {
    941940        if ((address & 0x3) || address >= g->limits.maxVertexProgramEnvParams) {
    942             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     941            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    943942                                     "glGetTrackMatrixivNV(address)");
    944943            return;
     
    951950        }
    952951        else {
    953             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     952            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    954953                                     "glGetTrackMatrixivNV(pname)");
    955954            return;
     
    957956    }
    958957    else {
    959         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     958        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    960959                                 "glGetTrackMatrixivNV(target)");
    961960        return;
     
    964963
    965964
    966 void STATE_APIENTRY crStateGetVertexAttribdvNV(GLuint index, GLenum pname, GLdouble *params)
     965void STATE_APIENTRY crStateGetVertexAttribdvNV(PCRStateTracker pState, GLuint index, GLenum pname, GLdouble *params)
    967966{
    968967     /* init vars to prevent compiler warnings/errors */
    969968     GLfloat floatParams[4] = { 0.0, 0.0, 0.0, 0.0 };
    970      crStateGetVertexAttribfvNV(index, pname, floatParams);
     969     crStateGetVertexAttribfvNV(pState, index, pname, floatParams);
    971970     params[0] = floatParams[0];
    972971     if (pname == GL_CURRENT_ATTRIB_NV) {
     
    978977
    979978
    980 void STATE_APIENTRY crStateGetVertexAttribfvNV(GLuint index, GLenum pname, GLfloat *params)
    981 {
    982     CRContext *g = GetCurrentContext();
    983 
    984     if (g->current.inBeginEnd) {
    985         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     979void STATE_APIENTRY crStateGetVertexAttribfvNV(PCRStateTracker pState, GLuint index, GLenum pname, GLfloat *params)
     980{
     981    CRContext *g = GetCurrentContext(pState);
     982
     983    if (g->current.inBeginEnd) {
     984        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    986985                                 "glGetVertexAttribfvNV called in Begin/End");
    987986        return;
     
    989988
    990989    if (index >= CR_MAX_VERTEX_ATTRIBS) {
    991         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     990        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    992991                                 "glGetVertexAttribfvNV(index)");
    993992        return;
     
    10051004        break;
    10061005    case GL_CURRENT_ATTRIB_NV:
    1007         crStateCurrentRecover();
     1006        crStateCurrentRecover(pState);
    10081007        COPY_4V(params , g->current.vertexAttrib[index]);
    10091008        break;
    10101009    default:
    1011         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetVertexAttribfvNV");
    1012         return;
    1013     }
    1014 }
    1015 
    1016 
    1017 void STATE_APIENTRY crStateGetVertexAttribivNV(GLuint index, GLenum pname, GLint *params)
     1010        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetVertexAttribfvNV");
     1011        return;
     1012    }
     1013}
     1014
     1015
     1016void STATE_APIENTRY crStateGetVertexAttribivNV(PCRStateTracker pState, GLuint index, GLenum pname, GLint *params)
    10181017{
    10191018     /* init vars to prevent compiler warnings/errors */
    10201019     GLfloat floatParams[4] = { 0.0, 0.0, 0.0, 0.0 };
    1021      crStateGetVertexAttribfvNV(index, pname, floatParams);
     1020     crStateGetVertexAttribfvNV(pState, index, pname, floatParams);
    10221021     params[0] = (GLint) floatParams[0];
    10231022     if (pname == GL_CURRENT_ATTRIB_NV) {
     
    10301029
    10311030
    1032 void STATE_APIENTRY crStateGetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
    1033 {
    1034     CRContext *g = GetCurrentContext();
    1035 
    1036     if (g->current.inBeginEnd) {
    1037         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1031void STATE_APIENTRY crStateGetVertexAttribfvARB(PCRStateTracker pState, GLuint index, GLenum pname, GLfloat *params)
     1032{
     1033    CRContext *g = GetCurrentContext(pState);
     1034
     1035    if (g->current.inBeginEnd) {
     1036        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    10381037                                 "glGetVertexAttribfvARB called in Begin/End");
    10391038        return;
     
    10411040
    10421041    if (index >= CR_MAX_VERTEX_ATTRIBS) {
    1043         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1042        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    10441043                                 "glGetVertexAttribfvARB(index)");
    10451044        return;
     
    10631062        break;
    10641063    case GL_CURRENT_VERTEX_ATTRIB_ARB:
    1065         crStateCurrentRecover();
     1064        crStateCurrentRecover(pState);
    10661065        COPY_4V(params , g->current.vertexAttrib[index]);
    10671066        break;
    10681067    default:
    1069         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetVertexAttribfvARB");
    1070         return;
    1071     }
    1072 }
    1073 
    1074 
    1075 void STATE_APIENTRY crStateGetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
     1068        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetVertexAttribfvARB");
     1069        return;
     1070    }
     1071}
     1072
     1073
     1074void STATE_APIENTRY crStateGetVertexAttribivARB(PCRStateTracker pState, GLuint index, GLenum pname, GLint *params)
    10761075{
    10771076     /* init vars to prevent compiler warnings/errors */
    10781077     GLfloat floatParams[4] = { 0.0, 0.0, 0.0, 0.0 };
    1079      crStateGetVertexAttribfvARB(index, pname, floatParams);
     1078     crStateGetVertexAttribfvARB(pState, index, pname, floatParams);
    10801079     params[0] = (GLint) floatParams[0];
    10811080     if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
     
    10871086
    10881087
    1089 void STATE_APIENTRY crStateGetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
     1088void STATE_APIENTRY crStateGetVertexAttribdvARB(PCRStateTracker pState, GLuint index, GLenum pname, GLdouble *params)
    10901089{
    10911090     /* init vars to prevent compiler warnings/errors */
    10921091     GLfloat floatParams[4] = { 0.0, 0.0, 0.0, 0.0 };
    1093      crStateGetVertexAttribfvARB(index, pname, floatParams);
     1092     crStateGetVertexAttribfvARB(pState, index, pname, floatParams);
    10941093     params[0] = floatParams[0];
    10951094     if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
     
    11071106 */
    11081107
    1109 void STATE_APIENTRY crStateProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    1110 {
    1111     CRContext *g = GetCurrentContext();
     1108void STATE_APIENTRY crStateProgramNamedParameter4fNV(PCRStateTracker pState, GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
     1109{
     1110    CRContext *g = GetCurrentContext(pState);
    11121111    CRProgramState *p = &(g->program);
    11131112    CRProgram *prog;
    1114     CRStateBits *sb = GetCurrentBits();
     1113    CRStateBits *sb = GetCurrentBits(pState);
    11151114    CRProgramBits *pb = &(sb->program);
    11161115
    11171116    if (g->current.inBeginEnd) {
    1118         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1117        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    11191118                                 "glProgramNamedParameterfNV called in Begin/End");
    11201119        return;
     
    11231122    prog = (CRProgram *) crHashtableSearch(p->programHash, id);
    11241123    if (!prog) {
    1125         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1124        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    11261125                                 "glProgramNamedParameterNV(bad id %d)", id);
    11271126        return;
     
    11291128
    11301129    if (prog->target != GL_FRAGMENT_PROGRAM_NV) {
    1131         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1130        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    11321131                                 "glProgramNamedParameterNV(target)");
    11331132        return;
     
    11401139
    11411140
    1142 void STATE_APIENTRY crStateProgramNamedParameter4dNV(GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w)
    1143 {
    1144     crStateProgramNamedParameter4fNV(id, len, name, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    1145 }
    1146 
    1147 
    1148 void STATE_APIENTRY crStateProgramNamedParameter4fvNV(GLuint id, GLsizei len, const GLubyte *name, const GLfloat v[])
    1149 {
    1150     crStateProgramNamedParameter4fNV(id, len, name, v[0], v[1], v[2], v[3]);
    1151 }
    1152 
    1153 
    1154 void STATE_APIENTRY crStateProgramNamedParameter4dvNV(GLuint id, GLsizei len, const GLubyte *name, const GLdouble v[])
    1155 {
    1156     crStateProgramNamedParameter4fNV(id, len, name, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
    1157 }
    1158 
    1159 
    1160 void STATE_APIENTRY crStateGetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name, GLfloat *params)
    1161 {
    1162     CRContext *g = GetCurrentContext();
     1141void STATE_APIENTRY crStateProgramNamedParameter4dNV(PCRStateTracker pState, GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w)
     1142{
     1143    crStateProgramNamedParameter4fNV(pState, id, len, name, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     1144}
     1145
     1146
     1147void STATE_APIENTRY crStateProgramNamedParameter4fvNV(PCRStateTracker pState, GLuint id, GLsizei len, const GLubyte *name, const GLfloat v[])
     1148{
     1149    crStateProgramNamedParameter4fNV(pState, id, len, name, v[0], v[1], v[2], v[3]);
     1150}
     1151
     1152
     1153void STATE_APIENTRY crStateProgramNamedParameter4dvNV(PCRStateTracker pState, GLuint id, GLsizei len, const GLubyte *name, const GLdouble v[])
     1154{
     1155    crStateProgramNamedParameter4fNV(pState, id, len, name, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
     1156}
     1157
     1158
     1159void STATE_APIENTRY crStateGetProgramNamedParameterfvNV(PCRStateTracker pState, GLuint id, GLsizei len, const GLubyte *name, GLfloat *params)
     1160{
     1161    CRContext *g = GetCurrentContext(pState);
    11631162    CRProgramState *p = &(g->program);
    11641163    const CRProgram *prog;
     
    11661165
    11671166    if (g->current.inBeginEnd) {
    1168         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1167        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    11691168                                 "glGetProgramNamedParameterfNV called in Begin/End");
    11701169        return;
     
    11731172    prog = (const CRProgram *) crHashtableSearch(p->programHash, id);
    11741173    if (!prog) {
    1175         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1174        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    11761175                                 "glGetProgramNamedParameterNV(bad id)");
    11771176        return;
     
    11791178
    11801179    if (prog->target != GL_FRAGMENT_PROGRAM_NV) {
    1181         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1180        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    11821181                                 "glGetProgramNamedParameterNV(target)");
    11831182        return;
     
    11861185    value = GetProgramSymbol(prog, (const char *)name, len);
    11871186    if (!value) {
    1188         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1187        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    11891188                                 "glGetProgramNamedParameterNV(name)");
    11901189        return;
     
    11981197
    11991198
    1200 void STATE_APIENTRY crStateGetProgramNamedParameterdvNV(GLuint id, GLsizei len, const GLubyte *name, GLdouble *params)
     1199void STATE_APIENTRY crStateGetProgramNamedParameterdvNV(PCRStateTracker pState, GLuint id, GLsizei len, const GLubyte *name, GLdouble *params)
    12011200{
    12021201    GLfloat floatParams[4];
    1203     crStateGetProgramNamedParameterfvNV(id, len, name, floatParams);
     1202    crStateGetProgramNamedParameterfvNV(pState, id, len, name, floatParams);
    12041203    params[0] = floatParams[0];
    12051204    params[1] = floatParams[1];
     
    12091208
    12101209
    1211 void STATE_APIENTRY crStateProgramLocalParameter4dARB(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w)
    1212 {
    1213     crStateProgramLocalParameter4fARB(target, index, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    1214 }
    1215 
    1216 
    1217 void STATE_APIENTRY crStateProgramLocalParameter4dvARB(GLenum target, GLuint index, const GLdouble *params)
    1218 {
    1219     crStateProgramLocalParameter4fARB(target, index, (GLfloat) params[0], (GLfloat) params[1],
     1210void STATE_APIENTRY crStateProgramLocalParameter4dARB(PCRStateTracker pState, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w)
     1211{
     1212    crStateProgramLocalParameter4fARB(pState, target, index, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     1213}
     1214
     1215
     1216void STATE_APIENTRY crStateProgramLocalParameter4dvARB(PCRStateTracker pState, GLenum target, GLuint index, const GLdouble *params)
     1217{
     1218    crStateProgramLocalParameter4fARB(pState, target, index, (GLfloat) params[0], (GLfloat) params[1],
    12201219                                                                        (GLfloat) params[2], (GLfloat) params[3]);
    12211220}
    12221221
    12231222
    1224 void STATE_APIENTRY crStateProgramLocalParameter4fARB(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    1225 {
    1226     CRContext *g = GetCurrentContext();
     1223void STATE_APIENTRY crStateProgramLocalParameter4fARB(PCRStateTracker pState, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
     1224{
     1225    CRContext *g = GetCurrentContext(pState);
    12271226    CRProgramState *p = &(g->program);
    12281227    CRProgram *prog;
    1229     CRStateBits *sb = GetCurrentBits();
     1228    CRStateBits *sb = GetCurrentBits(pState);
    12301229    CRProgramBits *pb = &(sb->program);
    12311230
    12321231    if (g->current.inBeginEnd) {
    1233         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1232        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    12341233                                 "glProgramLocalParameterARB called in Begin/End");
    12351234        return;
     
    12381237    if (target == GL_FRAGMENT_PROGRAM_ARB || target == GL_FRAGMENT_PROGRAM_NV) {
    12391238        if (index >= CR_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMS) {
    1240             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1239            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    12411240                                     "glProgramLocalParameterARB(index)");
    12421241            return;
     
    12461245    else if (target == GL_VERTEX_PROGRAM_ARB) {
    12471246        if (index >= CR_MAX_VERTEX_PROGRAM_LOCAL_PARAMS) {
    1248             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1247            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    12491248                                     "glProgramLocalParameterARB(index)");
    12501249            return;
     
    12531252    }
    12541253    else {
    1255         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1254        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    12561255                                 "glProgramLocalParameterARB(target)");
    12571256        return;
     
    12701269
    12711270
    1272 void STATE_APIENTRY crStateProgramLocalParameter4fvARB(GLenum target, GLuint index, const GLfloat *params)
    1273 {
    1274     crStateProgramLocalParameter4fARB(target, index, params[0], params[1], params[2], params[3]);
    1275 }
    1276 
    1277 
    1278 void STATE_APIENTRY crStateGetProgramLocalParameterfvARB(GLenum target, GLuint index, GLfloat *params)
    1279 {
    1280     CRContext *g = GetCurrentContext();
     1271void STATE_APIENTRY crStateProgramLocalParameter4fvARB(PCRStateTracker pState, GLenum target, GLuint index, const GLfloat *params)
     1272{
     1273    crStateProgramLocalParameter4fARB(pState, target, index, params[0], params[1], params[2], params[3]);
     1274}
     1275
     1276
     1277void STATE_APIENTRY crStateGetProgramLocalParameterfvARB(PCRStateTracker pState, GLenum target, GLuint index, GLfloat *params)
     1278{
     1279    CRContext *g = GetCurrentContext(pState);
    12811280    CRProgramState *p = &(g->program);
    12821281    const CRProgram *prog = NULL;
    12831282
    12841283    if (g->current.inBeginEnd) {
    1285         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1284        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    12861285                                 "glGetProgramLocalParameterARB called in Begin/End");
    12871286        return;
     
    12911290        prog = p->currentFragmentProgram;
    12921291        if (index >= g->limits.maxFragmentProgramLocalParams) {
    1293             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1292            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    12941293                                     "glGetProgramLocalParameterARB(index)");
    12951294            return;
     
    13031302        prog = p->currentVertexProgram;
    13041303        if (index >= g->limits.maxVertexProgramLocalParams) {
    1305             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1304            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    13061305                                     "glGetProgramLocalParameterARB(index)");
    13071306            return;
     
    13091308    }
    13101309    else {
    1311         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1310        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    13121311                                 "glGetProgramLocalParameterARB(target)");
    13131312        return;
    13141313    }
    13151314    if (!prog) {
    1316         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1315        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    13171316                                 "glGetProgramLocalParameterARB(no program)");
    13181317        return;
     
    13201319
    13211320    if (!prog) {
    1322         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1321        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    13231322                                 "glGetProgramLocalParameterARB(no program)");
    13241323        return;
     
    13341333
    13351334
    1336 void STATE_APIENTRY crStateGetProgramLocalParameterdvARB(GLenum target, GLuint index, GLdouble *params)
     1335void STATE_APIENTRY crStateGetProgramLocalParameterdvARB(PCRStateTracker pState, GLenum target, GLuint index, GLdouble *params)
    13371336{
    13381337    GLfloat floatParams[4];
    1339     crStateGetProgramLocalParameterfvARB(target, index, floatParams);
     1338    crStateGetProgramLocalParameterfvARB(pState, target, index, floatParams);
    13401339    params[0] = floatParams[0];
    13411340    params[1] = floatParams[1];
     
    13461345
    13471346
    1348 void STATE_APIENTRY crStateGetProgramivARB(GLenum target, GLenum pname, GLint *params)
     1347void STATE_APIENTRY crStateGetProgramivARB(PCRStateTracker pState, GLenum target, GLenum pname, GLint *params)
    13491348{
    13501349    CRProgram *prog;
    1351     CRContext *g = GetCurrentContext();
    1352     CRProgramState *p = &(g->program);
    1353 
    1354     if (g->current.inBeginEnd) {
    1355         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1350    CRContext *g = GetCurrentContext(pState);
     1351    CRProgramState *p = &(g->program);
     1352
     1353    if (g->current.inBeginEnd) {
     1354        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    13561355                                 "glGetProgramivARB called in Begin/End");
    13571356        return;
     
    13651364    }
    13661365    else {
    1367         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1366        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    13681367                                 "glGetProgramivARB(target)");
    13691368        return;
     
    15021501    case GL_PROGRAM_ALU_INSTRUCTIONS_ARB:
    15031502        if (target != GL_FRAGMENT_PROGRAM_ARB || !g->extensions.ARB_fragment_program) {
    1504             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1503            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15051504                                     "crStateGetProgramivARB(target or pname)");
    15061505            return;
     
    15101509    case GL_PROGRAM_TEX_INSTRUCTIONS_ARB:
    15111510        if (target != GL_FRAGMENT_PROGRAM_ARB || !g->extensions.ARB_fragment_program) {
    1512             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1511            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15131512                                     "crStateGetProgramivARB(target or pname)");
    15141513            return;
     
    15181517    case GL_PROGRAM_TEX_INDIRECTIONS_ARB:
    15191518        if (target != GL_FRAGMENT_PROGRAM_ARB || !g->extensions.ARB_fragment_program) {
    1520             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1519            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15211520                                     "crStateGetProgramivARB(target or pname)");
    15221521            return;
     
    15271526        /* XXX same as GL_PROGRAM_ALU_INSTRUCTIONS_ARB? */
    15281527        if (target != GL_FRAGMENT_PROGRAM_ARB || !g->extensions.ARB_fragment_program) {
    1529             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1528            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15301529                                     "crStateGetProgramivARB(target or pname)");
    15311530            return;
     
    15361535        /* XXX same as GL_PROGRAM_ALU_INSTRUCTIONS_ARB? */
    15371536        if (target != GL_FRAGMENT_PROGRAM_ARB || !g->extensions.ARB_fragment_program) {
    1538             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1537            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15391538                                     "crStateGetProgramivARB(target or pname)");
    15401539            return;
     
    15441543    case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
    15451544        if (target != GL_FRAGMENT_PROGRAM_ARB || !g->extensions.ARB_fragment_program) {
    1546             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1545            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15471546                                     "crStateGetProgramivARB(target or pname)");
    15481547            return;
     
    15531552    case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
    15541553        if (target != GL_FRAGMENT_PROGRAM_ARB || !g->extensions.ARB_fragment_program) {
    1555             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1554            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15561555                                     "crStateGetProgramivARB(target or pname)");
    15571556            return;
     
    15621561    case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
    15631562        if (target != GL_FRAGMENT_PROGRAM_ARB || !g->extensions.ARB_fragment_program) {
    1564             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1563            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15651564                                     "crStateGetProgramivARB(target or pname)");
    15661565            return;
     
    15711570    case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
    15721571        if (target != GL_FRAGMENT_PROGRAM_ARB || !g->extensions.ARB_fragment_program) {
    1573             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1572            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15741573                                     "crStateGetProgramivARB(target or pname)");
    15751574            return;
     
    15781577        break;
    15791578    default:
    1580         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1579        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15811580                                 "crStateGetProgramivARB(pname)");
    15821581        return;
     
    15861585
    15871586/* XXX maybe move these two functions into state_client.c? */
    1588 void STATE_APIENTRY crStateDisableVertexAttribArrayARB(GLuint index)
    1589 {
    1590     CRContext *g = GetCurrentContext();
     1587void STATE_APIENTRY crStateDisableVertexAttribArrayARB(PCRStateTracker pState, GLuint index)
     1588{
     1589    CRContext *g = GetCurrentContext(pState);
    15911590    CRClientState *c = &(g->client);
    1592     CRStateBits *sb = GetCurrentBits();
     1591    CRStateBits *sb = GetCurrentBits(pState);
    15931592    CRClientBits *cb = &(sb->client);
    15941593
    15951594    if (index >= g->limits.maxVertexProgramAttribs) {
    1596         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1595        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    15971596                                 "glDisableVertexAttribArrayARB(index)");
    15981597        return;
     
    16041603
    16051604
    1606 void STATE_APIENTRY crStateEnableVertexAttribArrayARB(GLuint index)
    1607 {
    1608     CRContext *g = GetCurrentContext();
     1605void STATE_APIENTRY crStateEnableVertexAttribArrayARB(PCRStateTracker pState, GLuint index)
     1606{
     1607    CRContext *g = GetCurrentContext(pState);
    16091608    CRClientState *c = &(g->client);
    1610     CRStateBits *sb = GetCurrentBits();
     1609    CRStateBits *sb = GetCurrentBits(pState);
    16111610    CRClientBits *cb = &(sb->client);
    16121611
    16131612    if (index >= g->limits.maxVertexProgramAttribs) {
    1614         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1613        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    16151614                                 "glEnableVertexAttribArrayARB(index)");
    16161615        return;
     
    16221621
    16231622
    1624 void STATE_APIENTRY crStateGetProgramEnvParameterdvARB(GLenum target, GLuint index, GLdouble *params)
     1623void STATE_APIENTRY crStateGetProgramEnvParameterdvARB(PCRStateTracker pState, GLenum target, GLuint index, GLdouble *params)
    16251624{
    16261625     GLfloat fparams[4];
    1627      crStateGetProgramEnvParameterfvARB(target, index, fparams);
     1626     crStateGetProgramEnvParameterfvARB(pState, target, index, fparams);
    16281627     params[0] = fparams[0];
    16291628     params[1] = fparams[1];
     
    16321631}
    16331632
    1634 void STATE_APIENTRY crStateGetProgramEnvParameterfvARB(GLenum target, GLuint index, GLfloat *params)
    1635 {
    1636     CRContext *g = GetCurrentContext();
    1637     CRProgramState *p = &(g->program);
    1638 
    1639     if (g->current.inBeginEnd) {
    1640         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1633void STATE_APIENTRY crStateGetProgramEnvParameterfvARB(PCRStateTracker pState, GLenum target, GLuint index, GLfloat *params)
     1634{
     1635    CRContext *g = GetCurrentContext(pState);
     1636    CRProgramState *p = &(g->program);
     1637
     1638    if (g->current.inBeginEnd) {
     1639        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    16411640                                 "glGetProgramEnvParameterARB called in Begin/End");
    16421641        return;
     
    16451644    if (target == GL_FRAGMENT_PROGRAM_ARB || target == GL_FRAGMENT_PROGRAM_NV) {
    16461645        if (index >= g->limits.maxFragmentProgramEnvParams) {
    1647             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1646            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    16481647                                     "glGetProgramEnvParameterARB(index)");
    16491648            return;
     
    16601659             ) {
    16611660        if (index >= g->limits.maxVertexProgramEnvParams) {
    1662             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1661            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    16631662                                     "glGetProgramEnvParameterARB(index)");
    16641663            return;
     
    16701669    }
    16711670    else {
    1672         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1671        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    16731672                                 "glGetProgramEnvParameterARB(target)");
    16741673        return;
     
    16771676
    16781677
    1679 void STATE_APIENTRY crStateProgramEnvParameter4dARB(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w)
    1680 {
    1681      crStateProgramEnvParameter4fARB(target, index, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    1682 }
    1683 
    1684 void STATE_APIENTRY crStateProgramEnvParameter4dvARB(GLenum target, GLuint index, const GLdouble *params)
    1685 {
    1686      crStateProgramEnvParameter4fARB(target, index, (GLfloat) params[0], (GLfloat) params[1], (GLfloat) params[2], (GLfloat) params[3]);
    1687 }
    1688 
    1689 void STATE_APIENTRY crStateProgramEnvParameter4fARB(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    1690 {
    1691     CRContext *g = GetCurrentContext();
    1692     CRProgramState *p = &(g->program);
    1693     CRStateBits *sb = GetCurrentBits();
     1678void STATE_APIENTRY crStateProgramEnvParameter4dARB(PCRStateTracker pState, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w)
     1679{
     1680     crStateProgramEnvParameter4fARB(pState, target, index, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     1681}
     1682
     1683void STATE_APIENTRY crStateProgramEnvParameter4dvARB(PCRStateTracker pState, GLenum target, GLuint index, const GLdouble *params)
     1684{
     1685     crStateProgramEnvParameter4fARB(pState, target, index, (GLfloat) params[0], (GLfloat) params[1], (GLfloat) params[2], (GLfloat) params[3]);
     1686}
     1687
     1688void STATE_APIENTRY crStateProgramEnvParameter4fARB(PCRStateTracker pState, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
     1689{
     1690    CRContext *g = GetCurrentContext(pState);
     1691    CRProgramState *p = &(g->program);
     1692    CRStateBits *sb = GetCurrentBits(pState);
    16941693    CRProgramBits *pb = &(sb->program);
    16951694
    16961695    if (g->current.inBeginEnd) {
    1697         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1696        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    16981697                                 "glProgramEnvParameterARB called in Begin/End");
    16991698        return;
     
    17021701    if (target == GL_FRAGMENT_PROGRAM_ARB || target == GL_FRAGMENT_PROGRAM_NV) {
    17031702        if (index >= g->limits.maxFragmentProgramEnvParams) {
    1704             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1703            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    17051704                                     "glProgramEnvParameterARB(index)");
    17061705            return;
     
    17191718             ) {
    17201719        if (index >= g->limits.maxVertexProgramEnvParams) {
    1721             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1720            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    17221721                                     "glProgramEnvParameterARB(index)");
    17231722            return;
     
    17311730    }
    17321731    else {
    1733         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1732        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    17341733                                 "glProgramEnvParameterARB(target)");
    17351734        return;
     
    17391738}
    17401739
    1741 void STATE_APIENTRY crStateProgramEnvParameter4fvARB(GLenum target, GLuint index, const GLfloat *params)
    1742 {
    1743      crStateProgramEnvParameter4fARB(target, index, params[0], params[1], params[2], params[3]);
     1740void STATE_APIENTRY crStateProgramEnvParameter4fvARB(PCRStateTracker pState, GLenum target, GLuint index, const GLfloat *params)
     1741{
     1742     crStateProgramEnvParameter4fARB(pState, target, index, params[0], params[1], params[2], params[3]);
    17441743}
    17451744
     
    17511750{
    17521751    CRProgramState *p = &(ctx->program);
    1753     CRStateBits *sb = GetCurrentBits();
     1752    CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    17541753    CRProgramBits *pb = &(sb->program);
    17551754    GLuint i;
     
    18191818                                     CRContext *fromCtx, CRContext *toCtx)
    18201819{
     1820    PCRStateTracker pState = fromCtx->pStateTracker;
    18211821    CRProgramState *from = &(fromCtx->program);
    18221822    CRProgramState *to = &(toCtx->program);
     
    18241824    CRbitvalue nbitID[CR_MAX_BITARRAY];
    18251825
     1826    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     1827
    18261828    CRASSERT(from->currentVertexProgram);
    18271829    CRASSERT(to->currentVertexProgram);
     
    18371839        CRProgram *toProg = to->currentVertexProgram;
    18381840
    1839         able[0] = diff_api.Disable;
    1840         able[1] = diff_api.Enable;
     1841        able[0] = pState->diff_api.Disable;
     1842        able[1] = pState->diff_api.Enable;
    18411843        if (from->vpEnabled != to->vpEnabled) {
    18421844            if (toProg->isARBprogram)
     
    18601862    if (CHECKDIRTY(b->fpEnable, bitID)) {
    18611863        glAble able[2];
    1862         able[0] = diff_api.Disable;
    1863         able[1] = diff_api.Enable;
     1864        able[0] = pState->diff_api.Disable;
     1865        able[1] = pState->diff_api.Enable;
    18641866        if (from->fpEnabled != to->fpEnabled) {
    18651867            able[to->fpEnabled](GL_FRAGMENT_PROGRAM_NV);
     
    18791881                if (from->TrackMatrix[i] != to->TrackMatrix[i] ||
    18801882                        from->TrackMatrixTransform[i] != to->TrackMatrixTransform[i])   {
    1881                     diff_api.TrackMatrixNV(GL_VERTEX_PROGRAM_NV, i * 4,
     1883                    pState->diff_api.TrackMatrixNV(GL_VERTEX_PROGRAM_NV, i * 4,
    18821884                                                                 to->TrackMatrix[i],
    18831885                                                                 to->TrackMatrixTransform[i]);
     
    18981900            if (fromProg->id != toProg->id) {
    18991901                if (toProg->isARBprogram)
    1900                     diff_api.BindProgramARB(GL_VERTEX_PROGRAM_ARB, toProg->id);
     1902                    pState->diff_api.BindProgramARB(GL_VERTEX_PROGRAM_ARB, toProg->id);
    19011903                else
    1902                     diff_api.BindProgramNV(GL_VERTEX_PROGRAM_NV, toProg->id);
     1904                    pState->diff_api.BindProgramNV(GL_VERTEX_PROGRAM_NV, toProg->id);
    19031905                from->currentVertexProgram = toProg;
    19041906            }
     
    19101912            if (CHECKDIRTY(toProg->dirtyProgram, bitID)) {
    19111913                if (toProg->isARBprogram) {
    1912                     diff_api.ProgramStringARB( GL_VERTEX_PROGRAM_ARB, toProg->format, toProg->length, toProg->string );
     1914                    pState->diff_api.ProgramStringARB( GL_VERTEX_PROGRAM_ARB, toProg->format, toProg->length, toProg->string );
    19131915                }
    19141916                else {
    1915                     diff_api.LoadProgramNV( GL_VERTEX_PROGRAM_NV, toProg->id, toProg->length, toProg->string );
     1917                    pState->diff_api.LoadProgramNV( GL_VERTEX_PROGRAM_NV, toProg->id, toProg->length, toProg->string );
    19161918                }
    19171919                CLEARDIRTY(toProg->dirtyProgram, nbitID);
     
    19231925                    if (CHECKDIRTY(b->vertexEnvParameter[i], bitID)) {
    19241926                        if (toProg->isARBprogram)
    1925                             diff_api.ProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i,
     1927                            pState->diff_api.ProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i,
    19261928                                                                                                 to->vertexParameters[i]);
    19271929                        else
    1928                             diff_api.ProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, i,
     1930                            pState->diff_api.ProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, i,
    19291931                                                                                         to->vertexParameters[i]);
    19301932                        if (fromProg) {
     
    19431945                    if (CHECKDIRTY(toProg->dirtyParam[i], bitID)) {
    19441946                        if (toProg->isARBprogram)
    1945                             diff_api.ProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i, toProg->parameters[i]);
     1947                            pState->diff_api.ProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i, toProg->parameters[i]);
    19461948                        else
    1947                             diff_api.ProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_NV, i, toProg->parameters[i]);
     1949                            pState->diff_api.ProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_NV, i, toProg->parameters[i]);
    19481950                        CLEARDIRTY(toProg->dirtyParam[i], nbitID);
    19491951                    }
     
    19631965        if (CHECKDIRTY(b->fpBinding, bitID)) {
    19641966            if (fromProg->id != toProg->id) {
    1965                 diff_api.BindProgramNV(GL_FRAGMENT_PROGRAM_NV, toProg->id);
     1967                pState->diff_api.BindProgramNV(GL_FRAGMENT_PROGRAM_NV, toProg->id);
    19661968                from->currentFragmentProgram = toProg;
    19671969            }
     
    19721974            /* fragment program text */
    19731975            if (CHECKDIRTY(toProg->dirtyProgram, bitID)) {
    1974                 diff_api.LoadProgramNV( GL_FRAGMENT_PROGRAM_NV, toProg->id,
     1976                pState->diff_api.LoadProgramNV( GL_FRAGMENT_PROGRAM_NV, toProg->id,
    19751977                                                                toProg->length, toProg->string );
    19761978                CLEARDIRTY(toProg->dirtyProgram, nbitID);
     
    19811983                for (i = 0; i < toCtx->limits.maxFragmentProgramEnvParams; i++) {
    19821984                    if (CHECKDIRTY(b->fragmentEnvParameter[i], bitID)) {
    1983                         diff_api.ProgramParameter4fvNV(GL_FRAGMENT_PROGRAM_NV, i,
     1985                        pState->diff_api.ProgramParameter4fvNV(GL_FRAGMENT_PROGRAM_NV, i,
    19841986                                                                                     to->fragmentParameters[i]);
    19851987                        if (fromProg) {
     
    19992001                    if (CHECKDIRTY(symbol->dirty, bitID)) {
    20002002                        GLint len = crStrlen(symbol->name);
    2001                         diff_api.ProgramNamedParameter4fvNV(toProg->id, len,
     2003                        pState->diff_api.ProgramNamedParameter4fvNV(toProg->id, len,
    20022004                                                            (const GLubyte *) symbol->name,
    20032005                                                            symbol->value);
     
    20172019                for (i = 0; i < CR_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMS; i++) {
    20182020                    if (CHECKDIRTY(toProg->dirtyParam[i], bitID)) {
    2019                         diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_NV, i,
     2021                        pState->diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_NV, i,
    20202022                                                                                                 toProg->parameters[i]);
    20212023                        if (fromProg) {
     
    20352037        if (CHECKDIRTY(b->fpBinding, bitID)) {
    20362038            if (fromProg->id != toProg->id) {
    2037                 diff_api.BindProgramARB(GL_FRAGMENT_PROGRAM_ARB, toProg->id);
     2039                pState->diff_api.BindProgramARB(GL_FRAGMENT_PROGRAM_ARB, toProg->id);
    20382040                from->currentFragmentProgram = toProg;
    20392041            }
     
    20442046            /* fragment program text */
    20452047            if (CHECKDIRTY(toProg->dirtyProgram, bitID)) {
    2046                 diff_api.ProgramStringARB( GL_FRAGMENT_PROGRAM_ARB, toProg->format,
     2048                pState->diff_api.ProgramStringARB( GL_FRAGMENT_PROGRAM_ARB, toProg->format,
    20472049                                                                         toProg->length, toProg->string );
    20482050                CLEARDIRTY(toProg->dirtyProgram, nbitID);
     
    20532055                for (i = 0; i < toCtx->limits.maxFragmentProgramEnvParams; i++) {
    20542056                    if (CHECKDIRTY(b->fragmentEnvParameter[i], bitID)) {
    2055                         diff_api.ProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i,
     2057                        pState->diff_api.ProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i,
    20562058                                                                                             to->fragmentParameters[i]);
    20572059                        if (fromProg) {
     
    20692071                for (i = 0; i < CR_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMS; i++) {
    20702072                    if (CHECKDIRTY(toProg->dirtyParam[i], bitID)) {
    2071                         diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i,
     2073                        pState->diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i,
    20722074                                                                                                 toProg->parameters[i]);
    20732075                        if (fromProg) {
     
    20902092                                         CRContext *fromCtx, CRContext *toCtx)
    20912093{
     2094    PCRStateTracker pState = fromCtx->pStateTracker;
    20922095    CRProgramState *from = &(fromCtx->program);
    20932096    CRProgramState *to = &(toCtx->program);
     
    20962099    GLenum whichVert = fromCtx->extensions.ARB_vertex_program && toCtx->extensions.ARB_vertex_program  ? GL_VERTEX_PROGRAM_ARB : GL_VERTEX_PROGRAM_NV;
    20972100
     2101    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
    20982102
    20992103    for (j=0;j<CR_MAX_BITARRAY;j++)
     
    21032107    if (CHECKDIRTY(b->vpEnable, bitID)) {
    21042108        glAble able[2];
    2105         able[0] = diff_api.Disable;
    2106         able[1] = diff_api.Enable;
     2109        able[0] = pState->diff_api.Disable;
     2110        able[1] = pState->diff_api.Enable;
    21072111        if (from->vpEnabled != to->vpEnabled) {
    21082112            able[to->vpEnabled](whichVert);
     
    21202124    if (CHECKDIRTY(b->fpEnable, bitID)) {
    21212125        glAble able[2];
    2122         able[0] = diff_api.Disable;
    2123         able[1] = diff_api.Enable;
     2126        able[0] = pState->diff_api.Disable;
     2127        able[1] = pState->diff_api.Enable;
    21242128        if (from->fpEnabled != to->fpEnabled) {
    21252129            able[to->fpEnabled](GL_FRAGMENT_PROGRAM_NV);
     
    21362140            if (CHECKDIRTY(b->trackMatrix[i], bitID))   {
    21372141                if (from->TrackMatrix[i] != to->TrackMatrix[i]) {
    2138                     diff_api.TrackMatrixNV(GL_VERTEX_PROGRAM_NV, i * 4,
     2142                    pState->diff_api.TrackMatrixNV(GL_VERTEX_PROGRAM_NV, i * 4,
    21392143                                                                 to->TrackMatrix[i],
    21402144                                                                 to->TrackMatrixTransform[i]);
     
    21522156            if (fromProg->id != toProg->id) {
    21532157                if (toProg->isARBprogram)
    2154                     diff_api.BindProgramARB(GL_VERTEX_PROGRAM_ARB, toProg->id);
     2158                    pState->diff_api.BindProgramARB(GL_VERTEX_PROGRAM_ARB, toProg->id);
    21552159                else
    2156                     diff_api.BindProgramNV(GL_VERTEX_PROGRAM_NV, toProg->id);
     2160                    pState->diff_api.BindProgramNV(GL_VERTEX_PROGRAM_NV, toProg->id);
    21572161            }
    21582162            DIRTY(b->vpBinding, nbitID);
     
    21632167            if (CHECKDIRTY(toProg->dirtyProgram, bitID)) {
    21642168                if (toProg->isARBprogram)
    2165                     diff_api.ProgramStringARB(GL_VERTEX_PROGRAM_ARB, toProg->format, toProg->length, toProg->string);
     2169                    pState->diff_api.ProgramStringARB(GL_VERTEX_PROGRAM_ARB, toProg->format, toProg->length, toProg->string);
    21662170                else
    2167                     diff_api.LoadProgramNV(GL_VERTEX_PROGRAM_NV, toProg->id, toProg->length, toProg->string);
     2171                    pState->diff_api.LoadProgramNV(GL_VERTEX_PROGRAM_NV, toProg->id, toProg->length, toProg->string);
    21682172
    21692173                DIRTY(toProg->dirtyProgram, nbitID);
     
    21752179                    if (CHECKDIRTY(b->vertexEnvParameter[i], bitID)) {
    21762180                        if (toProg->isARBprogram)
    2177                             diff_api.ProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i, to->vertexParameters[i]);
     2181                            pState->diff_api.ProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i, to->vertexParameters[i]);
    21782182                        else
    2179                             diff_api.ProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, i, to->vertexParameters[i]);
     2183                            pState->diff_api.ProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, i, to->vertexParameters[i]);
    21802184
    21812185                        DIRTY(b->vertexEnvParameter[i], nbitID);
     
    21922196
    21932197                        if (toProg->isARBprogram)
    2194                             diff_api.ProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i, toProg->parameters[i]);
     2198                            pState->diff_api.ProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i, toProg->parameters[i]);
    21952199                        else
    2196                             diff_api.ProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_NV, i, toProg->parameters[i]);
     2200                            pState->diff_api.ProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_NV, i, toProg->parameters[i]);
    21972201                    }
    21982202                }
     
    22112215        if (CHECKDIRTY(b->fpBinding, bitID)) {
    22122216            if (fromProg->id != toProg->id) {
    2213                 diff_api.BindProgramNV(GL_FRAGMENT_PROGRAM_NV, toProg->id);
     2217                pState->diff_api.BindProgramNV(GL_FRAGMENT_PROGRAM_NV, toProg->id);
    22142218            }
    22152219            DIRTY(b->fpBinding, nbitID);
     
    22192223            /* fragment program text */
    22202224            if (CHECKDIRTY(toProg->dirtyProgram, bitID)) {
    2221                 diff_api.LoadProgramNV(GL_FRAGMENT_PROGRAM_NV, toProg->id, toProg->length, toProg->string);
     2225                pState->diff_api.LoadProgramNV(GL_FRAGMENT_PROGRAM_NV, toProg->id, toProg->length, toProg->string);
    22222226                DIRTY(toProg->dirtyProgram, nbitID);
    22232227            }
     
    22272231                for (i = 0; i < toCtx->limits.maxFragmentProgramEnvParams; i++) {
    22282232                    if (CHECKDIRTY(b->fragmentEnvParameter[i], bitID)) {
    2229                         diff_api.ProgramParameter4fvNV(GL_FRAGMENT_PROGRAM_NV, i,
     2233                        pState->diff_api.ProgramParameter4fvNV(GL_FRAGMENT_PROGRAM_NV, i,
    22302234                                                       to->fragmentParameters[i]);
    22312235                        DIRTY(b->fragmentEnvParameter[i], nbitID);
     
    22412245                    if (CHECKDIRTY(symbol->dirty, bitID)) {
    22422246                        GLint len = crStrlen(symbol->name);
    2243                         diff_api.ProgramNamedParameter4fvNV(toProg->id, len,
     2247                        pState->diff_api.ProgramNamedParameter4fvNV(toProg->id, len,
    22442248                                                            (const GLubyte *) symbol->name,
    22452249                                                            symbol->value);
     
    22552259                    if (CHECKDIRTY(toProg->dirtyParam[i], bitID)) {
    22562260                        if (toProg->isARBprogram)
    2257                             diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i, toProg->parameters[i]);
     2261                            pState->diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i, toProg->parameters[i]);
    22582262                        else
    2259                             diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_NV, i, toProg->parameters[i]);
     2263                            pState->diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_NV, i, toProg->parameters[i]);
    22602264                    }
    22612265                }
     
    22702274        if (CHECKDIRTY(b->fpBinding, bitID)) {
    22712275            if (fromProg->id != toProg->id) {
    2272                 diff_api.BindProgramARB(GL_FRAGMENT_PROGRAM_ARB, toProg->id);
     2276                pState->diff_api.BindProgramARB(GL_FRAGMENT_PROGRAM_ARB, toProg->id);
    22732277            }
    22742278            DIRTY(b->fpBinding, nbitID);
     
    22782282            /* fragment program text */
    22792283            if (CHECKDIRTY(toProg->dirtyProgram, bitID)) {
    2280                 diff_api.ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, toProg->format, toProg->length, toProg->string);
     2284                pState->diff_api.ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, toProg->format, toProg->length, toProg->string);
    22812285                DIRTY(toProg->dirtyProgram, nbitID);
    22822286            }
     
    22862290                for (i = 0; i < toCtx->limits.maxFragmentProgramEnvParams; i++) {
    22872291                    if (CHECKDIRTY(b->fragmentEnvParameter[i], bitID)) {
    2288                         diff_api.ProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i, to->fragmentParameters[i]);
     2292                        pState->diff_api.ProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i, to->fragmentParameters[i]);
    22892293                        DIRTY(b->fragmentEnvParameter[i], nbitID);
    22902294                    }
     
    22972301                for (i = 0; i < CR_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMS; i++) {
    22982302                    if (CHECKDIRTY(toProg->dirtyParam[i], bitID)) {
    2299                         diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i, toProg->parameters[i]);
     2303                        pState->diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i, toProg->parameters[i]);
    23002304                        DIRTY(toProg->dirtyParam[i], nbitID);
    23012305                    }
     
    23222326{
    23232327    CRContext *pContext = (CRContext *) pCtx;
     2328    PCRStateTracker pState = pContext->pStateTracker;
    23242329    CRProgram *pProgram = (CRProgram *) pProg;
    23252330    uint32_t i;
     
    23282333    if (pProgram->isARBprogram)
    23292334    {
    2330         diff_api.BindProgramARB(pProgram->target, pProgram->id);
    2331         diff_api.ProgramStringARB(pProgram->target, pProgram->format, pProgram->length, pProgram->string);
     2335        pState->diff_api.BindProgramARB(pProgram->target, pProgram->id);
     2336        pState->diff_api.ProgramStringARB(pProgram->target, pProgram->format, pProgram->length, pProgram->string);
    23322337
    23332338        if (GL_VERTEX_PROGRAM_ARB == pProgram->target)
     
    23362341            for (i = 0; i < pContext->limits.maxVertexProgramEnvParams; i++)
    23372342            {
    2338                 diff_api.ProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i, pContext->program.vertexParameters[i]);
     2343                pState->diff_api.ProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i, pContext->program.vertexParameters[i]);
    23392344            }
    23402345            /* vertex program local parameters */
    23412346            for (i = 0; i < pContext->limits.maxVertexProgramLocalParams; i++)
    23422347            {
    2343                 diff_api.ProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i, pProgram->parameters[i]);
     2348                pState->diff_api.ProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, i, pProgram->parameters[i]);
    23442349            }
    23452350        }
     
    23492354            for (i = 0; i < pContext->limits.maxFragmentProgramEnvParams; i++)
    23502355            {
    2351                 diff_api.ProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i, pContext->program.fragmentParameters[i]);
     2356                pState->diff_api.ProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i, pContext->program.fragmentParameters[i]);
    23522357            }
    23532358            /* vertex program local parameters */
    23542359            for (i = 0; i < CR_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMS; i++)
    23552360            {
    2356                 diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i, pProgram->parameters[i]);
     2361                pState->diff_api.ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, i, pProgram->parameters[i]);
    23572362            }
    23582363        }
     
    23642369    else
    23652370    {
    2366         diff_api.BindProgramNV(pProgram->target, pProgram->id);
     2371        pState->diff_api.BindProgramNV(pProgram->target, pProgram->id);
    23672372    }
    23682373}
     
    23702375void crStateDiffAllPrograms(CRContext *g, CRbitvalue *bitID, GLboolean bForceUpdate)
    23712376{
     2377    PCRStateTracker pState = g->pStateTracker;
    23722378    CRProgram *pOrigVP, *pOrigFP;
    23732379
     
    23822388    /* restore original bindings */
    23832389    if (pOrigVP->isARBprogram)
    2384         diff_api.BindProgramARB(pOrigVP->target, pOrigVP->id);
     2390        pState->diff_api.BindProgramARB(pOrigVP->target, pOrigVP->id);
    23852391    else
    2386         diff_api.BindProgramNV(pOrigVP->target, pOrigVP->id);
     2392        pState->diff_api.BindProgramNV(pOrigVP->target, pOrigVP->id);
    23872393
    23882394    if (pOrigFP->isARBprogram)
    2389         diff_api.BindProgramARB(pOrigFP->target, pOrigFP->id);
     2395        pState->diff_api.BindProgramARB(pOrigFP->target, pOrigFP->id);
    23902396    else
    2391         diff_api.BindProgramNV(pOrigFP->target, pOrigFP->id);
    2392 }
     2397        pState->diff_api.BindProgramNV(pOrigFP->target, pOrigFP->id);
     2398}
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_rasterpos.c

    r69392 r78375  
    1717 */
    1818void
    19 crStateRasterPosUpdate(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    20 {
    21         CRContext *g = GetCurrentContext();
     19crStateRasterPosUpdate(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
     20{
     21        CRContext *g = GetCurrentContext(pState);
    2222        CRCurrentState *c = &(g->current);
    2323        CRTransformState *t = &(g->transform);
     
    2828        if (g->current.inBeginEnd)
    2929        {
    30                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "RasterPos called in Begin/End");
     30                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "RasterPos called in Begin/End");
    3131                return;
    3232        }
     
    3535
    3636        /* update current color, texcoord, etc from the CurrentStatePointers */
    37         crStateCurrentRecover();
     37        crStateCurrentRecover(pState);
    3838
    3939        p.x = x;
     
    8282
    8383/* As above, but set dirty flags */
    84 static void RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    85 {
    86         CRContext *g = GetCurrentContext();
    87         CRStateBits *sb = GetCurrentBits();
     84static void RasterPos4f(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
     85{
     86        CRContext *g = GetCurrentContext(pState);
     87        CRStateBits *sb = GetCurrentBits(pState);
    8888        CRCurrentBits *cb = &(sb->current);
    8989
    90         crStateRasterPosUpdate(x, y, z, w);
     90        crStateRasterPosUpdate(pState, x, y, z, w);
    9191
    9292        DIRTY(cb->dirty, g->neg_bitid);
     
    9494}
    9595
    96 void STATE_APIENTRY crStateRasterPos2d(GLdouble x, GLdouble y)
    97 {
    98         RasterPos4f((GLfloat) x, (GLfloat) y, 0.0f, 1.0f);
    99 }
    100 
    101 void STATE_APIENTRY crStateRasterPos2f(GLfloat x, GLfloat y)
    102 {
    103         RasterPos4f(x, y, 0.0f, 1.0f);
    104 }
    105 
    106 void STATE_APIENTRY crStateRasterPos2i(GLint x, GLint y)
    107 {
    108         RasterPos4f((GLfloat) x, (GLfloat) y, 0.0f, 1.0f);
    109 }
    110 
    111 void STATE_APIENTRY crStateRasterPos2s(GLshort x, GLshort y)
    112 {
    113         RasterPos4f((GLfloat) x, (GLfloat) y, 0.0f, 1.0f);
    114 }
    115 
    116 void STATE_APIENTRY crStateRasterPos3d(GLdouble x, GLdouble y, GLdouble z)
    117 {
    118         RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0f);
    119 }
    120 
    121 void STATE_APIENTRY crStateRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
    122 {
    123         RasterPos4f(x, y, z, 1.0f);
    124 }
    125 
    126 void STATE_APIENTRY crStateRasterPos3i(GLint x, GLint y, GLint z)
    127 {
    128         RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0f);
    129 }
    130 
    131 void STATE_APIENTRY crStateRasterPos3s(GLshort x, GLshort y, GLshort z)
    132 {
    133         RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0f);
    134 }
    135 
    136 void STATE_APIENTRY crStateRasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
    137 {
    138         RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    139 }
    140 
    141 void STATE_APIENTRY crStateRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    142 {
    143         RasterPos4f(x, y, z, w);
    144 }
    145 
    146 void STATE_APIENTRY crStateRasterPos4i(GLint x, GLint y, GLint z, GLint w)
    147 {
    148         RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    149 }
    150 
    151 void STATE_APIENTRY crStateRasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
    152 {
    153         RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
    154 }
    155 
    156 void STATE_APIENTRY crStateRasterPos2dv(const GLdouble *v)
    157 {
    158         RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
    159 }
    160 
    161 void STATE_APIENTRY crStateRasterPos2fv(const GLfloat *v)
    162 {
    163         RasterPos4f(v[0], v[1], 0.0f, 1.0f);
    164 }
    165 
    166 void STATE_APIENTRY crStateRasterPos2iv(const GLint *v)
    167 {
    168         RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
    169 }
    170 
    171 void STATE_APIENTRY crStateRasterPos2sv(const GLshort *v)
    172 {
    173         RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
    174 }
    175 
    176 void STATE_APIENTRY crStateRasterPos3dv(const GLdouble *v)
    177 {
    178         RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
    179 }
    180 
    181 void STATE_APIENTRY crStateRasterPos3fv(const GLfloat *v)
    182 {
    183         RasterPos4f(v[0], v[1], v[2], 1.0f);
    184 }
    185 
    186 void STATE_APIENTRY crStateRasterPos3iv(const GLint *v)
    187 {
    188         RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
    189 }
    190 
    191 void STATE_APIENTRY crStateRasterPos3sv(const GLshort *v)
    192 {
    193         RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
    194 }
    195 
    196 void STATE_APIENTRY crStateRasterPos4dv(const GLdouble *v)
    197 {
    198         RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
    199 }
    200 
    201 void STATE_APIENTRY crStateRasterPos4fv(const GLfloat *v)
    202 {
    203         RasterPos4f(v[0], v[1], v[2], v[3]);
    204 }
    205 
    206 void STATE_APIENTRY crStateRasterPos4iv(const GLint *v)
    207 {
    208         RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
    209 }
    210 
    211 void STATE_APIENTRY crStateRasterPos4sv(const GLshort *v)
    212 {
    213         RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
     96void STATE_APIENTRY crStateRasterPos2d(PCRStateTracker pState, GLdouble x, GLdouble y)
     97{
     98        RasterPos4f(pState, (GLfloat) x, (GLfloat) y, 0.0f, 1.0f);
     99}
     100
     101void STATE_APIENTRY crStateRasterPos2f(PCRStateTracker pState, GLfloat x, GLfloat y)
     102{
     103        RasterPos4f(pState, x, y, 0.0f, 1.0f);
     104}
     105
     106void STATE_APIENTRY crStateRasterPos2i(PCRStateTracker pState, GLint x, GLint y)
     107{
     108        RasterPos4f(pState, (GLfloat) x, (GLfloat) y, 0.0f, 1.0f);
     109}
     110
     111void STATE_APIENTRY crStateRasterPos2s(PCRStateTracker pState, GLshort x, GLshort y)
     112{
     113        RasterPos4f(pState, (GLfloat) x, (GLfloat) y, 0.0f, 1.0f);
     114}
     115
     116void STATE_APIENTRY crStateRasterPos3d(PCRStateTracker pState, GLdouble x, GLdouble y, GLdouble z)
     117{
     118        RasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0f);
     119}
     120
     121void STATE_APIENTRY crStateRasterPos3f(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z)
     122{
     123        RasterPos4f(pState, x, y, z, 1.0f);
     124}
     125
     126void STATE_APIENTRY crStateRasterPos3i(PCRStateTracker pState, GLint x, GLint y, GLint z)
     127{
     128        RasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0f);
     129}
     130
     131void STATE_APIENTRY crStateRasterPos3s(PCRStateTracker pState, GLshort x, GLshort y, GLshort z)
     132{
     133        RasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0f);
     134}
     135
     136void STATE_APIENTRY crStateRasterPos4d(PCRStateTracker pState, GLdouble x, GLdouble y, GLdouble z, GLdouble w)
     137{
     138        RasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     139}
     140
     141void STATE_APIENTRY crStateRasterPos4f(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
     142{
     143        RasterPos4f(pState, x, y, z, w);
     144}
     145
     146void STATE_APIENTRY crStateRasterPos4i(PCRStateTracker pState, GLint x, GLint y, GLint z, GLint w)
     147{
     148        RasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     149}
     150
     151void STATE_APIENTRY crStateRasterPos4s(PCRStateTracker pState, GLshort x, GLshort y, GLshort z, GLshort w)
     152{
     153        RasterPos4f(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
     154}
     155
     156void STATE_APIENTRY crStateRasterPos2dv(PCRStateTracker pState, const GLdouble *v)
     157{
     158        RasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
     159}
     160
     161void STATE_APIENTRY crStateRasterPos2fv(PCRStateTracker pState, const GLfloat *v)
     162{
     163        RasterPos4f(pState, v[0], v[1], 0.0f, 1.0f);
     164}
     165
     166void STATE_APIENTRY crStateRasterPos2iv(PCRStateTracker pState, const GLint *v)
     167{
     168        RasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
     169}
     170
     171void STATE_APIENTRY crStateRasterPos2sv(PCRStateTracker pState, const GLshort *v)
     172{
     173        RasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
     174}
     175
     176void STATE_APIENTRY crStateRasterPos3dv(PCRStateTracker pState, const GLdouble *v)
     177{
     178        RasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
     179}
     180
     181void STATE_APIENTRY crStateRasterPos3fv(PCRStateTracker pState, const GLfloat *v)
     182{
     183        RasterPos4f(pState, v[0], v[1], v[2], 1.0f);
     184}
     185
     186void STATE_APIENTRY crStateRasterPos3iv(PCRStateTracker pState, const GLint *v)
     187{
     188        RasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
     189}
     190
     191void STATE_APIENTRY crStateRasterPos3sv(PCRStateTracker pState, const GLshort *v)
     192{
     193        RasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
     194}
     195
     196void STATE_APIENTRY crStateRasterPos4dv(PCRStateTracker pState, const GLdouble *v)
     197{
     198        RasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
     199}
     200
     201void STATE_APIENTRY crStateRasterPos4fv(PCRStateTracker pState, const GLfloat *v)
     202{
     203        RasterPos4f(pState, v[0], v[1], v[2], v[3]);
     204}
     205
     206void STATE_APIENTRY crStateRasterPos4iv(PCRStateTracker pState, const GLint *v)
     207{
     208        RasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
     209}
     210
     211void STATE_APIENTRY crStateRasterPos4sv(PCRStateTracker pState, const GLshort *v)
     212{
     213        RasterPos4f(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
    214214}
    215215
     
    219219
    220220static void
    221 crStateWindowPosUpdate(GLfloat x, GLfloat y, GLfloat z)
    222 {
    223         CRContext *g = GetCurrentContext();
     221crStateWindowPosUpdate(PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z)
     222{
     223        CRContext *g = GetCurrentContext(pState);
    224224        CRCurrentState *c = &(g->current);
    225         CRStateBits *sb = GetCurrentBits();
     225        CRStateBits *sb = GetCurrentBits(pState);
    226226        CRCurrentBits *cb = &(sb->current);
    227227        int i;
     
    229229        if (g->current.inBeginEnd)
    230230        {
    231                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "WindowPos called in Begin/End");
     231                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "WindowPos called in Begin/End");
    232232                return;
    233233        }
     
    246246
    247247
    248 void STATE_APIENTRY crStateWindowPos2dARB (GLdouble x, GLdouble y)
    249 {
    250         crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, 0.0);
    251 }
    252 
    253 void STATE_APIENTRY crStateWindowPos2dvARB (const GLdouble *v)
    254 {
    255         crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], 0.0);
    256 }
    257 
    258 void STATE_APIENTRY crStateWindowPos2fARB (GLfloat x, GLfloat y)
    259 {
    260         crStateWindowPosUpdate(x, y, 0.0);
    261 }
    262 
    263 void STATE_APIENTRY crStateWindowPos2fvARB (const GLfloat *v)
    264 {
    265         crStateWindowPosUpdate(v[0], v[1], 0.0);
    266 }
    267 
    268 void STATE_APIENTRY crStateWindowPos2iARB (GLint x, GLint y)
    269 {
    270         crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, 0.0);
    271 }
    272 
    273 void STATE_APIENTRY crStateWindowPos2ivARB (const GLint *v)
    274 {
    275         crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], 0.0);
    276 }
    277 
    278 void STATE_APIENTRY crStateWindowPos2sARB (GLshort x, GLshort y)
    279 {
    280         crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, 0.0);
    281 }
    282 
    283 void STATE_APIENTRY crStateWindowPos2svARB (const GLshort *v)
    284 {
    285         crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], 0.0);
    286 }
    287 
    288 void STATE_APIENTRY crStateWindowPos3dARB (GLdouble x, GLdouble y, GLdouble z)
    289 {
    290         crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, (GLfloat) z);
    291 }
    292 
    293 void STATE_APIENTRY crStateWindowPos3dvARB (const GLdouble *v)
    294 {
    295         crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2]);
    296 }
    297 
    298 void STATE_APIENTRY crStateWindowPos3fARB (GLfloat x, GLfloat y, GLfloat z)
    299 {
    300         crStateWindowPosUpdate(x, y, z);
    301 }
    302 
    303 void STATE_APIENTRY crStateWindowPos3fvARB (const GLfloat *v)
    304 {
    305         crStateWindowPosUpdate(v[0], v[1], v[2]);
    306 }
    307 
    308 void STATE_APIENTRY crStateWindowPos3iARB (GLint x, GLint y, GLint z)
    309 {
    310         crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, (GLfloat) z);
    311 }
    312 
    313 void STATE_APIENTRY crStateWindowPos3ivARB (const GLint *v)
    314 {
    315         crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2]);
    316 }
    317 
    318 void STATE_APIENTRY crStateWindowPos3sARB (GLshort x, GLshort y, GLshort z)
    319 {
    320         crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, (GLfloat) z);
    321 }
    322 
    323 void STATE_APIENTRY crStateWindowPos3svARB (const GLshort *v)
    324 {
    325         crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2]);
    326 }
    327 
     248void STATE_APIENTRY crStateWindowPos2dARB (PCRStateTracker pState, GLdouble x, GLdouble y)
     249{
     250        crStateWindowPosUpdate(pState, (GLfloat) x, (GLfloat) y, 0.0);
     251}
     252
     253void STATE_APIENTRY crStateWindowPos2dvARB (PCRStateTracker pState, const GLdouble *v)
     254{
     255        crStateWindowPosUpdate(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0);
     256}
     257
     258void STATE_APIENTRY crStateWindowPos2fARB (PCRStateTracker pState, GLfloat x, GLfloat y)
     259{
     260        crStateWindowPosUpdate(pState, x, y, 0.0);
     261}
     262
     263void STATE_APIENTRY crStateWindowPos2fvARB (PCRStateTracker pState, const GLfloat *v)
     264{
     265        crStateWindowPosUpdate(pState, v[0], v[1], 0.0);
     266}
     267
     268void STATE_APIENTRY crStateWindowPos2iARB (PCRStateTracker pState, GLint x, GLint y)
     269{
     270        crStateWindowPosUpdate(pState, (GLfloat) x, (GLfloat) y, 0.0);
     271}
     272
     273void STATE_APIENTRY crStateWindowPos2ivARB (PCRStateTracker pState, const GLint *v)
     274{
     275        crStateWindowPosUpdate(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0);
     276}
     277
     278void STATE_APIENTRY crStateWindowPos2sARB (PCRStateTracker pState, GLshort x, GLshort y)
     279{
     280        crStateWindowPosUpdate(pState, (GLfloat) x, (GLfloat) y, 0.0);
     281}
     282
     283void STATE_APIENTRY crStateWindowPos2svARB (PCRStateTracker pState, const GLshort *v)
     284{
     285        crStateWindowPosUpdate(pState, (GLfloat) v[0], (GLfloat) v[1], 0.0);
     286}
     287
     288void STATE_APIENTRY crStateWindowPos3dARB (PCRStateTracker pState, GLdouble x, GLdouble y, GLdouble z)
     289{
     290        crStateWindowPosUpdate(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z);
     291}
     292
     293void STATE_APIENTRY crStateWindowPos3dvARB (PCRStateTracker pState, const GLdouble *v)
     294{
     295        crStateWindowPosUpdate(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2]);
     296}
     297
     298void STATE_APIENTRY crStateWindowPos3fARB (PCRStateTracker pState, GLfloat x, GLfloat y, GLfloat z)
     299{
     300        crStateWindowPosUpdate(pState, x, y, z);
     301}
     302
     303void STATE_APIENTRY crStateWindowPos3fvARB (PCRStateTracker pState, const GLfloat *v)
     304{
     305        crStateWindowPosUpdate(pState, v[0], v[1], v[2]);
     306}
     307
     308void STATE_APIENTRY crStateWindowPos3iARB (PCRStateTracker pState, GLint x, GLint y, GLint z)
     309{
     310        crStateWindowPosUpdate(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z);
     311}
     312
     313void STATE_APIENTRY crStateWindowPos3ivARB (PCRStateTracker pState, const GLint *v)
     314{
     315        crStateWindowPosUpdate(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2]);
     316}
     317
     318void STATE_APIENTRY crStateWindowPos3sARB (PCRStateTracker pState, GLshort x, GLshort y, GLshort z)
     319{
     320        crStateWindowPosUpdate(pState, (GLfloat) x, (GLfloat) y, (GLfloat) z);
     321}
     322
     323void STATE_APIENTRY crStateWindowPos3svARB (PCRStateTracker pState, const GLshort *v)
     324{
     325        crStateWindowPosUpdate(pState, (GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2]);
     326}
     327
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_regcombiner.c

    r69392 r78375  
    1515{
    1616        CRRegCombinerState *reg = &ctx->regcombiner;
    17         CRStateBits *sb = GetCurrentBits();
     17        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    1818        CRRegCombinerBits *rb = &(sb->regcombiner);
    1919#ifndef CR_NV_register_combiners
     
    117117}
    118118
    119 void STATE_APIENTRY crStateCombinerParameterfvNV( GLenum pname, const GLfloat *params )
    120 {
    121         CRContext *g = GetCurrentContext();
     119void STATE_APIENTRY crStateCombinerParameterfvNV(PCRStateTracker pState, GLenum pname, const GLfloat *params )
     120{
     121        CRContext *g = GetCurrentContext(pState);
    122122        CRRegCombinerState *r = &(g->regcombiner);
    123         CRStateBits *sb = GetCurrentBits();
     123        CRStateBits *sb = GetCurrentBits(pState);
    124124        CRRegCombinerBits *rb = &(sb->regcombiner);
    125125
     
    143143                        if( *params < 1 || *params > g->limits.maxGeneralCombiners )
    144144                        {
    145                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "CombinerParameter passed invalid NUM_GENERAL_COMBINERS param: %d", (GLint)*params );
     145                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "CombinerParameter passed invalid NUM_GENERAL_COMBINERS param: %d", (GLint)*params );
    146146                                return;
    147147                        }
     
    154154                        break;
    155155                default:
    156                         crStateError( __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerParameter passed bogus pname: 0x%x", pname );
     156                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerParameter passed bogus pname: 0x%x", pname );
    157157                        return;
    158158        }
     
    161161}
    162162
    163 void STATE_APIENTRY crStateCombinerParameterivNV( GLenum pname, const GLint *params )
     163void STATE_APIENTRY crStateCombinerParameterivNV(PCRStateTracker pState, GLenum pname, const GLint *params )
    164164{
    165165        GLfloat fparams[4];
     
    178178                *fparams = (GLfloat) *params;
    179179        }
    180         crStateCombinerParameterfvNV( pname, fparams );
    181 }
    182 
    183 void STATE_APIENTRY crStateCombinerParameterfNV( GLenum pname, GLfloat param )
     180        crStateCombinerParameterfvNV(pState, pname, fparams );
     181}
     182
     183void STATE_APIENTRY crStateCombinerParameterfNV(PCRStateTracker pState, GLenum pname, GLfloat param )
    184184{
    185185        GLfloat fparam[1];
     
    187187        if( pname == GL_CONSTANT_COLOR0_NV || pname == GL_CONSTANT_COLOR1_NV )
    188188        {
    189                 crStateError( __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid pname (CONSTANT_COLOR%d) passed to CombinerParameterfNV: 0x%x", (GLint)param-GL_CONSTANT_COLOR0_NV, pname );
    190                 return;
    191         }
    192         crStateCombinerParameterfvNV( pname, fparam );
    193 }
    194 
    195 void STATE_APIENTRY crStateCombinerParameteriNV( GLenum pname, GLint param )
     189                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid pname (CONSTANT_COLOR%d) passed to CombinerParameterfNV: 0x%x", (GLint)param-GL_CONSTANT_COLOR0_NV, pname );
     190                return;
     191        }
     192        crStateCombinerParameterfvNV(pState, pname, fparam );
     193}
     194
     195void STATE_APIENTRY crStateCombinerParameteriNV(PCRStateTracker pState, GLenum pname, GLint param )
    196196{
    197197        GLfloat fparam[1];
     
    199199        if( pname == GL_CONSTANT_COLOR0_NV || pname == GL_CONSTANT_COLOR1_NV )
    200200        {
    201                 crStateError( __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid pname (CONSTANT_COLOR%d) passed to CombinerParameteriNV: 0x%x", param-GL_CONSTANT_COLOR0_NV, pname );
    202                 return;
    203         }
    204         crStateCombinerParameterfvNV( pname, fparam );
    205 }
    206 
    207 void STATE_APIENTRY crStateCombinerInputNV( GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage )
    208 {
    209         CRContext *g = GetCurrentContext();
     201                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid pname (CONSTANT_COLOR%d) passed to CombinerParameteriNV: 0x%x", param-GL_CONSTANT_COLOR0_NV, pname );
     202                return;
     203        }
     204        crStateCombinerParameterfvNV(pState, pname, fparam );
     205}
     206
     207void STATE_APIENTRY crStateCombinerInputNV(PCRStateTracker pState, GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage )
     208{
     209        CRContext *g = GetCurrentContext(pState);
    210210        CRRegCombinerState *r = &(g->regcombiner);
    211         CRStateBits *sb = GetCurrentBits();
     211        CRStateBits *sb = GetCurrentBits(pState);
    212212        CRRegCombinerBits *rb = &(sb->regcombiner);
    213213
    214214        if( stage < GL_COMBINER0_NV || stage >= GL_COMBINER0_NV + g->limits.maxGeneralCombiners )
    215215        {
    216                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus stage: 0x%x", stage );
     216                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus stage: 0x%x", stage );
    217217                return;
    218218        }
    219219        if( input != GL_ZERO && input != GL_CONSTANT_COLOR0_NV && input != GL_CONSTANT_COLOR1_NV && input != GL_FOG && input != GL_PRIMARY_COLOR_NV && input != GL_SECONDARY_COLOR_NV && input != GL_SPARE0_NV && input != GL_SPARE1_NV && ( input < GL_TEXTURE0_ARB || input >= GL_TEXTURE0_ARB + g->limits.maxTextureUnits ))
    220220        {
    221                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus input: 0x%x", input );
     221                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus input: 0x%x", input );
    222222                return;
    223223        }
    224224        if( mapping != GL_UNSIGNED_IDENTITY_NV && mapping != GL_UNSIGNED_INVERT_NV && mapping != GL_EXPAND_NORMAL_NV && mapping != GL_EXPAND_NEGATE_NV && mapping != GL_HALF_BIAS_NORMAL_NV && mapping != GL_HALF_BIAS_NEGATE_NV && mapping != GL_SIGNED_IDENTITY_NV && mapping != GL_SIGNED_NEGATE_NV )
    225225        {
    226                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus mapping: 0x%x", mapping );
     226                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus mapping: 0x%x", mapping );
    227227                return;
    228228        }
    229229        if( componentUsage != GL_RGB && componentUsage != GL_ALPHA && componentUsage != GL_BLUE )
    230230        {
    231                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus componentUsage: 0x%x", componentUsage );
     231                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus componentUsage: 0x%x", componentUsage );
    232232                return;
    233233        }
     
    235235        if(( componentUsage == GL_RGB && portion == GL_ALPHA )||( componentUsage == GL_BLUE && portion == GL_RGB ))
    236236        {
    237                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "Incompatible portion and componentUsage passed to CombinerInputNV: portion = 0x%x, componentUsage = 0x%x", portion, componentUsage );
     237                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "Incompatible portion and componentUsage passed to CombinerInputNV: portion = 0x%x, componentUsage = 0x%x", portion, componentUsage );
    238238                return;
    239239        }
    240240        if( componentUsage == GL_ALPHA && input == GL_FOG )
    241241        {
    242                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerInputNV can not have input of GL_FOG if componentUsage is GL_ALPHA" );
     242                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerInputNV can not have input of GL_FOG if componentUsage is GL_ALPHA" );
    243243                return;
    244244        }
     
    270270                                break;
    271271                        default:
    272                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus variable: 0x%x", variable );
     272                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus variable: 0x%x", variable );
    273273                                return;
    274274                }
     
    299299                                break;
    300300                        default:
    301                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus variable: 0x%x", variable );
     301                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus variable: 0x%x", variable );
    302302                                return;
    303303                }
     
    305305        else
    306306        {
    307                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus portion: 0x%x", portion );
     307                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerInputNV passed bogus portion: 0x%x", portion );
    308308                return;
    309309        }
     
    313313}
    314314
    315 void STATE_APIENTRY crStateCombinerOutputNV( GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum )
    316 {
    317         CRContext *g = GetCurrentContext();
     315void STATE_APIENTRY crStateCombinerOutputNV(PCRStateTracker pState, GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum )
     316{
     317        CRContext *g = GetCurrentContext(pState);
    318318        CRRegCombinerState *r = &(g->regcombiner);
    319         CRStateBits *sb = GetCurrentBits();
     319        CRStateBits *sb = GetCurrentBits(pState);
    320320        CRRegCombinerBits *rb = &(sb->regcombiner);
    321321
     
    330330        if( stage < GL_COMBINER0_NV || stage >= GL_COMBINER0_NV + g->limits.maxGeneralCombiners )
    331331        {
    332                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus stage: 0x%x", stage );
     332                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus stage: 0x%x", stage );
    333333                return;
    334334        }
    335335        if( abOutput != GL_DISCARD_NV && abOutput != GL_PRIMARY_COLOR_NV && abOutput != GL_SECONDARY_COLOR_NV && abOutput != GL_SPARE0_NV && abOutput != GL_SPARE1_NV && ( abOutput < GL_TEXTURE0_ARB || abOutput >= g->limits.maxTextureUnits + GL_TEXTURE0_ARB ))
    336336        {
    337                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus abOutput: 0x%x", abOutput );
     337                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus abOutput: 0x%x", abOutput );
    338338                return;
    339339        }
    340340        if( cdOutput != GL_DISCARD_NV && cdOutput != GL_PRIMARY_COLOR_NV && cdOutput != GL_SECONDARY_COLOR_NV && cdOutput != GL_SPARE0_NV && cdOutput != GL_SPARE1_NV && ( cdOutput < GL_TEXTURE0_ARB || cdOutput >= g->limits.maxTextureUnits + GL_TEXTURE0_ARB ))
    341341        {
    342                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus cdOutput: 0x%x", cdOutput );
     342                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus cdOutput: 0x%x", cdOutput );
    343343                return;
    344344        }
    345345        if( sumOutput != GL_DISCARD_NV && sumOutput != GL_PRIMARY_COLOR_NV && sumOutput != GL_SECONDARY_COLOR_NV && sumOutput != GL_SPARE0_NV && sumOutput != GL_SPARE1_NV && sumOutput != GL_TEXTURE0_ARB && sumOutput != GL_TEXTURE1_ARB )
    346346        {
    347                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus sumOutput: 0x%x", sumOutput );
     347                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus sumOutput: 0x%x", sumOutput );
    348348                return;
    349349        }
    350350        if( scale != GL_NONE && scale != GL_SCALE_BY_TWO_NV && scale != GL_SCALE_BY_FOUR_NV && scale != GL_SCALE_BY_ONE_HALF_NV )
    351351        {
    352                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerOutputNV passed bogus scale: 0x%x", scale );
     352                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerOutputNV passed bogus scale: 0x%x", scale );
    353353                return;
    354354        }
    355355        if( bias != GL_NONE && bias != GL_BIAS_BY_NEGATIVE_ONE_HALF_NV )
    356356        {
    357                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerOutputNV passed bogus bias: 0x%x", bias );
     357                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerOutputNV passed bogus bias: 0x%x", bias );
    358358                return;
    359359        }
     
    361361        if( bias == GL_BIAS_BY_NEGATIVE_ONE_HALF_NV && ( scale == GL_SCALE_BY_ONE_HALF_NV || scale == GL_SCALE_BY_FOUR_NV ))
    362362        {
    363                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerOutputNV can't accept bias of -1/2 if scale is by 1/2 or 4" );
     363                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerOutputNV can't accept bias of -1/2 if scale is by 1/2 or 4" );
    364364                return;
    365365        }
    366366        if(( abOutput == cdOutput && abOutput != GL_DISCARD_NV )||( abOutput == sumOutput && abOutput != GL_DISCARD_NV )||( cdOutput == sumOutput && cdOutput != GL_DISCARD_NV ))
    367367        {
    368                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerOutputNV register output names must be unique unless discarded: abOutput = 0x%x, cdOutput = 0x%x, sumOutput = 0x%x", abOutput, cdOutput, sumOutput );
     368                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerOutputNV register output names must be unique unless discarded: abOutput = 0x%x, cdOutput = 0x%x, sumOutput = 0x%x", abOutput, cdOutput, sumOutput );
    369369                return;
    370370        }
     
    373373                if( portion == GL_ALPHA )
    374374                {
    375                         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "CombinerOutputNV can not do Dot Products when portion = GL_ALPHA" );
     375                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "CombinerOutputNV can not do Dot Products when portion = GL_ALPHA" );
    376376                        return;
    377377                }
    378378                if( sumOutput != GL_DISCARD_NV )
    379379                {
    380                         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerOutputNV can not do Dot Products when sumOutput is not discarded" );
     380                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "CombinerOutputNV can not do Dot Products when sumOutput is not discarded" );
    381381                        return;
    382382                }
     
    408408        else
    409409        {
    410                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus portion: 0x%x", portion );
     410                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus portion: 0x%x", portion );
    411411                return;
    412412        }
     
    416416}
    417417
    418 void STATE_APIENTRY crStateFinalCombinerInputNV( GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage )
    419 {
    420         CRContext *g = GetCurrentContext();
     418void STATE_APIENTRY crStateFinalCombinerInputNV(PCRStateTracker pState, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage )
     419{
     420        CRContext *g = GetCurrentContext(pState);
    421421        CRRegCombinerState *r = &(g->regcombiner);
    422         CRStateBits *sb = GetCurrentBits();
     422        CRStateBits *sb = GetCurrentBits(pState);
    423423        CRRegCombinerBits *rb = &(sb->regcombiner);
    424424
    425425        if( input != GL_ZERO && input != GL_CONSTANT_COLOR0_NV && input != GL_CONSTANT_COLOR1_NV && input != GL_FOG && input != GL_PRIMARY_COLOR_NV && input != GL_SECONDARY_COLOR_NV && input != GL_SPARE0_NV && input != GL_SPARE1_NV && ( input < GL_TEXTURE0_ARB || input >= GL_TEXTURE0_ARB + g->limits.maxTextureUnits ) && input != GL_E_TIMES_F_NV && input != GL_SPARE0_PLUS_SECONDARY_COLOR_NV )
    426426        {
    427                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "FinalCombinerInputNV passed bogus input: 0x%x", input );
     427                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "FinalCombinerInputNV passed bogus input: 0x%x", input );
    428428                return;
    429429        }
    430430        if( mapping != GL_UNSIGNED_IDENTITY_NV && mapping != GL_UNSIGNED_INVERT_NV && mapping != GL_EXPAND_NORMAL_NV && mapping != GL_EXPAND_NEGATE_NV && mapping != GL_HALF_BIAS_NORMAL_NV && mapping != GL_HALF_BIAS_NEGATE_NV && mapping != GL_SIGNED_IDENTITY_NV && mapping != GL_SIGNED_NEGATE_NV )
    431431        {
    432                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "FinalCombinerInputNV passed bogus mapping: 0x%x", mapping );
     432                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "FinalCombinerInputNV passed bogus mapping: 0x%x", mapping );
    433433                return;
    434434        }
    435435        if( componentUsage != GL_RGB && componentUsage != GL_ALPHA && componentUsage != GL_BLUE )
    436436        {
    437                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "FinalCombinerInputNV passed bogus componentUsage: 0x%x", componentUsage );
     437                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "FinalCombinerInputNV passed bogus componentUsage: 0x%x", componentUsage );
    438438                return;
    439439        }
     
    441441        if( componentUsage == GL_ALPHA && ( input == GL_E_TIMES_F_NV || input == GL_SPARE0_PLUS_SECONDARY_COLOR_NV ))
    442442        {
    443                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "FinalCombinerInputNV does not allow componentUsage of ALPHA when input is E_TIMES_F or SPARE0_PLUS_SECONDARY_COLOR" );
     443                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "FinalCombinerInputNV does not allow componentUsage of ALPHA when input is E_TIMES_F or SPARE0_PLUS_SECONDARY_COLOR" );
    444444                return;
    445445        }
     
    480480                        if( componentUsage != GL_ALPHA )
    481481                        {
    482                                 crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "FinalCombinerInputNV can not have variable G when componentUsage is RGB or BLUE" );
     482                                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "FinalCombinerInputNV can not have variable G when componentUsage is RGB or BLUE" );
    483483                                return;
    484484                        }
     
    488488                        break;
    489489                default:
    490                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus variable: 0x%x", variable );
     490                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerOutputNV passed bogus variable: 0x%x", variable );
    491491                        return;
    492492        }
     
    498498
    499499/* XXX Unfinished RegCombiner State functions */
    500 void STATE_APIENTRY crStateGetCombinerOutputParameterfvNV( GLenum stage, GLenum portion, GLenum pname, GLfloat *params )
    501 {
     500void STATE_APIENTRY crStateGetCombinerOutputParameterfvNV(PCRStateTracker pState, GLenum stage, GLenum portion, GLenum pname, GLfloat *params )
     501{
     502    RT_NOREF(pState);
    502503        (void) stage;
    503504        (void) portion;
     
    506507}
    507508
    508 void STATE_APIENTRY crStateGetCombinerOutputParameterivNV( GLenum stage, GLenum portion, GLenum pname, GLint *params )
    509 {
     509void STATE_APIENTRY crStateGetCombinerOutputParameterivNV(PCRStateTracker pState, GLenum stage, GLenum portion, GLenum pname, GLint *params )
     510{
     511    RT_NOREF(pState);
    510512        (void) stage;
    511513        (void) portion;
     
    514516}
    515517
    516 void STATE_APIENTRY crStateGetFinalCombinerInputParameterfvNV( GLenum variable, GLenum pname, GLfloat *params )
    517 {
     518void STATE_APIENTRY crStateGetFinalCombinerInputParameterfvNV(PCRStateTracker pState, GLenum variable, GLenum pname, GLfloat *params )
     519{
     520    RT_NOREF(pState);
    518521        (void) variable;
    519522        (void) pname;
     
    521524}
    522525
    523 void STATE_APIENTRY crStateGetFinalCombinerInputParameterivNV( GLenum variable, GLenum pname, GLint *params )
    524 {
     526void STATE_APIENTRY crStateGetFinalCombinerInputParameterivNV(PCRStateTracker pState, GLenum variable, GLenum pname, GLint *params )
     527{
     528    RT_NOREF(pState);
    525529        (void) variable;
    526530        (void) pname;
     
    529533
    530534
    531 void STATE_APIENTRY crStateGetCombinerInputParameterivNV( GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params )
    532 {
    533         CRContext *g = GetCurrentContext();
     535void STATE_APIENTRY crStateGetCombinerInputParameterivNV(PCRStateTracker pState, GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params )
     536{
     537        CRContext *g = GetCurrentContext(pState);
    534538        CRRegCombinerState *r = &(g->regcombiner);
    535539        int i = stage - GL_COMBINER0_NV;
     
    538542        if (g->current.inBeginEnd)
    539543        {
    540                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     544                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    541545                                "glGetCombinerParameterivNV called in begin/end");
    542546                return;
     
    544548
    545549        if (i < 0 || i >= CR_MAX_GENERAL_COMBINERS) {
    546                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     550                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    547551                                                                 "GetCombinerInputParameterivNV(stage=0x%x)", stage);
    548552                return;
     
    572576                        break;
    573577                default:
    574                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     578                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    575579                                                                         "glGetCombinerInputParameterivNV(variable=0x%x)", variable);
    576580                        return;
     
    600604                        break;
    601605                default:
    602                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     606                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    603607                                                                         "glGetCombinerInputParameterivNV(variable=0x%x)", variable);
    604608                        return;
     
    606610        }
    607611        else {
    608                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     612                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    609613                                                                 "glGetCombinerInputParameterivNV(portion=0x%x)", portion);
    610614        }
     
    620624                return;
    621625        default:
    622                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     626                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    623627                                                                 "glGetCombinerInputParameterivNV(pname=0x%x)", pname);
    624628                return;
     
    627631
    628632
    629 void STATE_APIENTRY crStateGetCombinerInputParameterfvNV( GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params )
     633void STATE_APIENTRY crStateGetCombinerInputParameterfvNV(PCRStateTracker pState, GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params )
    630634{
    631635                GLint iparams;
    632                 crStateGetCombinerInputParameterivNV(stage, portion, variable, pname, &iparams);
     636                crStateGetCombinerInputParameterivNV(pState, stage, portion, variable, pname, &iparams);
    633637                *params = (GLfloat) iparams;
    634638}
    635639
    636640
    637 void STATE_APIENTRY crStateCombinerStageParameterfvNV( GLenum stage, GLenum pname, const GLfloat *params )
    638 {
    639         CRContext *g = GetCurrentContext();
     641void STATE_APIENTRY crStateCombinerStageParameterfvNV(PCRStateTracker pState, GLenum stage, GLenum pname, const GLfloat *params )
     642{
     643        CRContext *g = GetCurrentContext(pState);
    640644        CRRegCombinerState *r = &(g->regcombiner);
    641         CRStateBits *sb = GetCurrentBits();
     645        CRStateBits *sb = GetCurrentBits(pState);
    642646        CRRegCombinerBits *rb = &(sb->regcombiner);
    643647       
     
    645649        if( stage >= g->limits.maxGeneralCombiners )
    646650        {
    647                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "CombinerStageParameterfvNV passed bogus stage: 0x%x", stage+GL_COMBINER0_NV );
     651                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerStageParameterfvNV passed bogus stage: 0x%x", stage+GL_COMBINER0_NV );
    648652                return;
    649653        }
     
    666670                        break;
    667671                default:
    668                         crStateError( __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerStageParameter passed bogus pname: 0x%x", pname );
     672                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "CombinerStageParameter passed bogus pname: 0x%x", pname );
    669673                        return;
    670674        }
     
    673677}
    674678
    675 void STATE_APIENTRY crStateGetCombinerStageParameterfvNV( GLenum stage, GLenum pname, GLfloat *params )
    676 {
    677         CRContext *g = GetCurrentContext();
     679void STATE_APIENTRY crStateGetCombinerStageParameterfvNV(PCRStateTracker pState, GLenum stage, GLenum pname, GLfloat *params )
     680{
     681        CRContext *g = GetCurrentContext(pState);
    678682        CRRegCombinerState *r = &(g->regcombiner);
    679683
     
    681685        if( stage >= g->limits.maxGeneralCombiners )
    682686        {
    683                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "GetCombinerStageParameterfvNV passed bogus stage: 0x%x", stage+GL_COMBINER0_NV );
     687                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "GetCombinerStageParameterfvNV passed bogus stage: 0x%x", stage+GL_COMBINER0_NV );
    684688                return;
    685689        }
     
    699703                        break;
    700704                default:
    701                         crStateError( __LINE__, __FILE__, GL_INVALID_ENUM, "GetCombinerStageParameter passed bogus pname: 0x%x", pname );
     705                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "GetCombinerStageParameter passed bogus pname: 0x%x", pname );
    702706                        return;
    703707        }
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_regcombiner.txt

    r15532 r78375  
    1414:regCombinerStageColor0[i]:stageConstantColor0[i]|r,g,b,a:CombinerStageParameterfvNV, GL_COMBINER0_NV+i, GL_CONSTANT_COLOR0_NV
    1515:regCombinerStageColor1[i]:stageConstantColor1[i]|r,g,b,a:CombinerStageParameterfvNV, GL_COMBINER0_NV+i, GL_CONSTANT_COLOR1_NV
    16 :regCombinerInput[i]:rgb[i].a,rgb[i].aMapping,rgb[i].aPortion:*diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_RGB, GL_VARIABLE_A_NV, to->rgb[i].a, to->rgb[i].aMapping, to->rgb[i].aPortion );
    17 :regCombinerInput[i]:rgb[i].b,rgb[i].bMapping,rgb[i].bPortion:*diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_RGB, GL_VARIABLE_B_NV, to->rgb[i].b, to->rgb[i].bMapping, to->rgb[i].bPortion );
    18 :regCombinerInput[i]:rgb[i].c,rgb[i].cMapping,rgb[i].cPortion:*diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_RGB, GL_VARIABLE_C_NV, to->rgb[i].c, to->rgb[i].cMapping, to->rgb[i].cPortion );
    19 :regCombinerInput[i]:rgb[i].d,rgb[i].dMapping,rgb[i].dPortion:*diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_RGB, GL_VARIABLE_D_NV, to->rgb[i].d, to->rgb[i].dMapping, to->rgb[i].dPortion );
    20 :regCombinerInput[i]:alpha[i].a,alpha[i].aMapping,alpha[i].aPortion:*diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_ALPHA, GL_VARIABLE_A_NV, to->alpha[i].a, to->alpha[i].aMapping, to->alpha[i].aPortion );
    21 :regCombinerInput[i]:alpha[i].b,alpha[i].bMapping,alpha[i].bPortion:*diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_ALPHA, GL_VARIABLE_B_NV, to->alpha[i].b, to->alpha[i].bMapping, to->alpha[i].bPortion );
    22 :regCombinerInput[i]:alpha[i].c,alpha[i].cMapping,alpha[i].cPortion:*diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_ALPHA, GL_VARIABLE_C_NV, to->alpha[i].c, to->alpha[i].cMapping, to->alpha[i].cPortion );
    23 :regCombinerInput[i]:alpha[i].d,alpha[i].dMapping,alpha[i].dPortion:*diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_ALPHA, GL_VARIABLE_D_NV, to->alpha[i].d, to->alpha[i].dMapping, to->alpha[i].dPortion );
    24 :regCombinerOutput[i]:rgb[i]|abOutput,cdOutput,sumOutput,scale,bias,abDotProduct,cdDotProduct,muxSum:*diff_api.CombinerOutputNV( GL_COMBINER0_NV+i, GL_RGB, to->rgb[i].abOutput, to->rgb[i].cdOutput, to->rgb[i].sumOutput, to->rgb[i].scale, to->rgb[i].bias, to->rgb[i].abDotProduct, to->rgb[i].cdDotProduct, to->rgb[i].muxSum );
    25 :regCombinerOutput[i]:alpha[i]|abOutput,cdOutput,sumOutput,scale,bias,abDotProduct,cdDotProduct,muxSum:*diff_api.CombinerOutputNV( GL_COMBINER0_NV+i, GL_ALPHA, to->alpha[i].abOutput, to->alpha[i].cdOutput, to->alpha[i].sumOutput, to->alpha[i].scale, to->alpha[i].bias, to->alpha[i].abDotProduct, to->alpha[i].cdDotProduct, to->alpha[i].muxSum );
     16:regCombinerInput[i]:rgb[i].a,rgb[i].aMapping,rgb[i].aPortion:*pState->diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_RGB, GL_VARIABLE_A_NV, to->rgb[i].a, to->rgb[i].aMapping, to->rgb[i].aPortion );
     17:regCombinerInput[i]:rgb[i].b,rgb[i].bMapping,rgb[i].bPortion:*pState->diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_RGB, GL_VARIABLE_B_NV, to->rgb[i].b, to->rgb[i].bMapping, to->rgb[i].bPortion );
     18:regCombinerInput[i]:rgb[i].c,rgb[i].cMapping,rgb[i].cPortion:*pState->diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_RGB, GL_VARIABLE_C_NV, to->rgb[i].c, to->rgb[i].cMapping, to->rgb[i].cPortion );
     19:regCombinerInput[i]:rgb[i].d,rgb[i].dMapping,rgb[i].dPortion:*pState->diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_RGB, GL_VARIABLE_D_NV, to->rgb[i].d, to->rgb[i].dMapping, to->rgb[i].dPortion );
     20:regCombinerInput[i]:alpha[i].a,alpha[i].aMapping,alpha[i].aPortion:*pState->diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_ALPHA, GL_VARIABLE_A_NV, to->alpha[i].a, to->alpha[i].aMapping, to->alpha[i].aPortion );
     21:regCombinerInput[i]:alpha[i].b,alpha[i].bMapping,alpha[i].bPortion:*pState->diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_ALPHA, GL_VARIABLE_B_NV, to->alpha[i].b, to->alpha[i].bMapping, to->alpha[i].bPortion );
     22:regCombinerInput[i]:alpha[i].c,alpha[i].cMapping,alpha[i].cPortion:*pState->diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_ALPHA, GL_VARIABLE_C_NV, to->alpha[i].c, to->alpha[i].cMapping, to->alpha[i].cPortion );
     23:regCombinerInput[i]:alpha[i].d,alpha[i].dMapping,alpha[i].dPortion:*pState->diff_api.CombinerInputNV( GL_COMBINER0_NV+i, GL_ALPHA, GL_VARIABLE_D_NV, to->alpha[i].d, to->alpha[i].dMapping, to->alpha[i].dPortion );
     24:regCombinerOutput[i]:rgb[i]|abOutput,cdOutput,sumOutput,scale,bias,abDotProduct,cdDotProduct,muxSum:*pState->diff_api.CombinerOutputNV( GL_COMBINER0_NV+i, GL_RGB, to->rgb[i].abOutput, to->rgb[i].cdOutput, to->rgb[i].sumOutput, to->rgb[i].scale, to->rgb[i].bias, to->rgb[i].abDotProduct, to->rgb[i].cdDotProduct, to->rgb[i].muxSum );
     25:regCombinerOutput[i]:alpha[i]|abOutput,cdOutput,sumOutput,scale,bias,abDotProduct,cdDotProduct,muxSum:*pState->diff_api.CombinerOutputNV( GL_COMBINER0_NV+i, GL_ALPHA, to->alpha[i].abOutput, to->alpha[i].cdOutput, to->alpha[i].sumOutput, to->alpha[i].scale, to->alpha[i].bias, to->alpha[i].abDotProduct, to->alpha[i].cdDotProduct, to->alpha[i].muxSum );
    2626%flush
    2727>}
    28 :regCombinerFinalInput:a,aMapping,aPortion:*diff_api.FinalCombinerInputNV( GL_VARIABLE_A_NV, to->a, to->aMapping, to->aPortion );
    29 :regCombinerFinalInput:b,bMapping,bPortion:*diff_api.FinalCombinerInputNV( GL_VARIABLE_B_NV, to->b, to->bMapping, to->bPortion );
    30 :regCombinerFinalInput:c,cMapping,cPortion:*diff_api.FinalCombinerInputNV( GL_VARIABLE_C_NV, to->c, to->cMapping, to->cPortion );
    31 :regCombinerFinalInput:d,dMapping,dPortion:*diff_api.FinalCombinerInputNV( GL_VARIABLE_D_NV, to->d, to->dMapping, to->dPortion );
    32 :regCombinerFinalInput:e,eMapping,ePortion:*diff_api.FinalCombinerInputNV( GL_VARIABLE_E_NV, to->e, to->eMapping, to->ePortion );
    33 :regCombinerFinalInput:f,fMapping,fPortion:*diff_api.FinalCombinerInputNV( GL_VARIABLE_F_NV, to->f, to->fMapping, to->fPortion );
    34 :regCombinerFinalInput:g,gMapping,gPortion:*diff_api.FinalCombinerInputNV( GL_VARIABLE_G_NV, to->g, to->gMapping, to->gPortion );
     28:regCombinerFinalInput:a,aMapping,aPortion:*pState->diff_api.FinalCombinerInputNV( GL_VARIABLE_A_NV, to->a, to->aMapping, to->aPortion );
     29:regCombinerFinalInput:b,bMapping,bPortion:*pState->diff_api.FinalCombinerInputNV( GL_VARIABLE_B_NV, to->b, to->bMapping, to->bPortion );
     30:regCombinerFinalInput:c,cMapping,cPortion:*pState->diff_api.FinalCombinerInputNV( GL_VARIABLE_C_NV, to->c, to->cMapping, to->cPortion );
     31:regCombinerFinalInput:d,dMapping,dPortion:*pState->diff_api.FinalCombinerInputNV( GL_VARIABLE_D_NV, to->d, to->dMapping, to->dPortion );
     32:regCombinerFinalInput:e,eMapping,ePortion:*pState->diff_api.FinalCombinerInputNV( GL_VARIABLE_E_NV, to->e, to->eMapping, to->ePortion );
     33:regCombinerFinalInput:f,fMapping,fPortion:*pState->diff_api.FinalCombinerInputNV( GL_VARIABLE_F_NV, to->f, to->fMapping, to->fPortion );
     34:regCombinerFinalInput:g,gMapping,gPortion:*pState->diff_api.FinalCombinerInputNV( GL_VARIABLE_G_NV, to->g, to->gMapping, to->gPortion );
    3535%flush
    3636%target=to
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c

    r78263 r78375  
    5151 */
    5252
     53/**
     54 * Helper for walking the hash tables.
     55 */
     56typedef struct CRStateSnapshotWalkArgs
     57{
     58    PSSMHANDLE      pSSM;
     59    PCRStateTracker pState;
     60} CRStateSnapshotWalkArgs;
     61typedef CRStateSnapshotWalkArgs *PCRStateSnapshotWalkArgs;
     62
    5363static int32_t crStateAllocAndSSMR3GetMem(PSSMHANDLE pSSM, void **pBuffer, size_t cbBuffer)
    5464{
     
    396406}
    397407
    398 static int32_t crStateSaveTextureObjData(CRTextureObj *pTexture, PSSMHANDLE pSSM)
     408static int32_t crStateSaveTextureObjData(PCRStateTracker pState, CRTextureObj *pTexture, PSSMHANDLE pSSM)
    399409{
    400410    int32_t rc, face, i;
     
    433443                {
    434444                    GLenum getEnum;
    435                     diff_api.BindTexture(pTexture->target, pTexture->hwid);
     445                    pState->diff_api.BindTexture(pTexture->target, pTexture->hwid);
    436446                    bound = 1;
    437447
     
    465475                    {
    466476                        GLint curTex;
    467                         diff_api.GetIntegerv(getEnum, &curTex);
     477                        pState->diff_api.GetIntegerv(getEnum, &curTex);
    468478                        if ((GLuint)curTex != pTexture->hwid)
    469479                        {
     
    506516                        crDebug("get image: compressed %i, face %i, level %i, width %i, height %i, bytes %i",
    507517                                ptl->compressed, face, i, ptl->width, ptl->height, ptl->bytes);
    508                         diff_api.GetTexLevelParameteriv(target, i, GL_TEXTURE_WIDTH, &w);
    509                         diff_api.GetTexLevelParameteriv(target, i, GL_TEXTURE_HEIGHT, &h);
     518                        pState->diff_api.GetTexLevelParameteriv(target, i, GL_TEXTURE_WIDTH, &w);
     519                        pState->diff_api.GetTexLevelParameteriv(target, i, GL_TEXTURE_HEIGHT, &h);
    510520                        if (w!=ptl->width || h!=ptl->height)
    511521                        {
     
    523533                        if (!ptl->compressed)
    524534                        {
    525                             diff_api.GetTexImage(target, i, ptl->format, ptl->type, pImg);
     535                            pState->diff_api.GetTexImage(target, i, ptl->format, ptl->type, pImg);
    526536                        }
    527537                        else
    528538                        {
    529                             diff_api.GetCompressedTexImageARB(target, i, pImg);
     539                            pState->diff_api.GetCompressedTexImageARB(target, i, pImg);
    530540                        }
    531541                    }
     
    602612{
    603613    CRTextureObj *pTexture = (CRTextureObj *) data1;
    604     PSSMHANDLE pSSM = (PSSMHANDLE) data2;
     614    PCRStateSnapshotWalkArgs pArgs = (PCRStateSnapshotWalkArgs)data2;
     615    PCRStateTracker pState = pArgs->pState;
     616    PSSMHANDLE pSSM = pArgs->pSSM;
    605617    int32_t rc;
    606618
     
    611623    rc = SSMR3PutMem(pSSM, pTexture, sizeof(*pTexture));
    612624    CRASSERT(rc == VINF_SUCCESS);
    613     rc = crStateSaveTextureObjData(pTexture, pSSM);
     625    rc = crStateSaveTextureObjData(pState, pTexture, pSSM);
    614626    CRASSERT(rc == VINF_SUCCESS);
    615627}
     
    857869{
    858870    CRBufferObject *pBufferObj = (CRBufferObject *) data1;
    859     PSSMHANDLE pSSM = (PSSMHANDLE) data2;
     871    PCRStateSnapshotWalkArgs pArgs = (PCRStateSnapshotWalkArgs)data2;
     872    PCRStateTracker pState = pArgs->pState;
     873    PSSMHANDLE pSSM = pArgs->pSSM;
    860874    int32_t rc;
    861875
     
    877891    else if (pBufferObj->id!=0 && pBufferObj->size>0)
    878892    {
    879         diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pBufferObj->hwid);
    880         pBufferObj->pointer = diff_api.MapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_ONLY_ARB);
     893        pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pBufferObj->hwid);
     894        pBufferObj->pointer = pState->diff_api.MapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_ONLY_ARB);
    881895        rc = SSMR3PutMem(pSSM, &pBufferObj->pointer, sizeof(pBufferObj->pointer));
    882896        CRASSERT(rc == VINF_SUCCESS);
     
    886900            CRASSERT(rc == VINF_SUCCESS);
    887901        }
    888         diff_api.UnmapBufferARB(GL_ARRAY_BUFFER_ARB);
     902        pState->diff_api.UnmapBufferARB(GL_ARRAY_BUFFER_ARB);
    889903        pBufferObj->pointer = NULL;
    890904    }
     
    10491063{
    10501064    CRGLSLShader *pShader = (CRGLSLShader*) data1;
    1051     PSSMHANDLE pSSM = (PSSMHANDLE) data2;
     1065    PCRStateSnapshotWalkArgs pArgs = (PCRStateSnapshotWalkArgs)data2;
     1066    PCRStateTracker pState = pArgs->pState;
     1067    PSSMHANDLE pSSM = pArgs->pSSM;
    10521068    int32_t rc;
    10531069
     
    10671083        GLchar *source=NULL;
    10681084
    1069         diff_api.GetShaderiv(pShader->hwid, GL_SHADER_SOURCE_LENGTH, &sLen);
     1085        pState->diff_api.GetShaderiv(pShader->hwid, GL_SHADER_SOURCE_LENGTH, &sLen);
    10701086        if (sLen>0)
    10711087        {
    10721088            source = (GLchar*) crAlloc(sLen);
    1073             diff_api.GetShaderSource(pShader->hwid, sLen, NULL, source);
     1089            pState->diff_api.GetShaderSource(pShader->hwid, sLen, NULL, source);
    10741090        }
    10751091
     
    11281144{
    11291145    CRGLSLProgram *pProgram = (CRGLSLProgram*) data1;
    1130     PSSMHANDLE pSSM = (PSSMHANDLE) data2;
     1146    PCRStateSnapshotWalkArgs pArgs = (PCRStateSnapshotWalkArgs)data2;
     1147    PCRStateTracker pState = pArgs->pState;
     1148    PSSMHANDLE pSSM = pArgs->pSSM;
    11311149    int32_t rc;
    11321150    uint32_t ui32;
     
    11531171        rc = SSMR3PutU32(pSSM, ui32);
    11541172        CRASSERT(rc == VINF_SUCCESS);
    1155         crHashtableWalk(pProgram->currentState.attachedShaders, crStateSaveGLSLShaderCB, pSSM);
     1173        crHashtableWalk(pProgram->currentState.attachedShaders, crStateSaveGLSLShaderCB, pArgs);
    11561174    }
    11571175
     
    11591177    crStateSaveGLSLProgramAttribs(&pProgram->activeState, pSSM);
    11601178
    1161     diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLen);
    1162     diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORMS, &activeUniforms);
     1179    pState->diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLen);
     1180    pState->diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORMS, &activeUniforms);
    11631181
    11641182    if (!maxUniformLen)
     
    11841202    for (i=0; i<activeUniforms; ++i)
    11851203    {
    1186         diff_api.GetActiveUniform(pProgram->hwid, i, maxUniformLen, NULL, &size, &type, name);
     1204        pState->diff_api.GetActiveUniform(pProgram->hwid, i, maxUniformLen, NULL, &size, &type, name);
    11871205        uniformsCount += size;
    11881206    }
     
    12001218        for (i=0; i<activeUniforms; ++i)
    12011219        {
    1202             diff_api.GetActiveUniform(pProgram->hwid, i, maxUniformLen, NULL, &size, &type, name);
     1220            pState->diff_api.GetActiveUniform(pProgram->hwid, i, maxUniformLen, NULL, &size, &type, name);
    12031221
    12041222            if (size>1)
     
    12171235                    sprintf(pIndexStr, "[%i]", j);
    12181236                }
    1219                 location = diff_api.GetUniformLocation(pProgram->hwid, name);
     1237                location = pState->diff_api.GetUniformLocation(pProgram->hwid, name);
    12201238
    12211239                rc = SSMR3PutMem(pSSM, &type, sizeof(type));
     
    12241242                crStateSaveString(name, pSSM);
    12251243
    1226                 if (crStateIsIntUniform(type))
     1244                if (crStateIsIntUniform(pState, type))
    12271245                {
    1228                     diff_api.GetUniformiv(pProgram->hwid, location, &idata[0]);
    1229                     rc = SSMR3PutMem(pSSM, &idata[0], crStateGetUniformSize(type)*sizeof(idata[0]));
     1246                    pState->diff_api.GetUniformiv(pProgram->hwid, location, &idata[0]);
     1247                    rc = SSMR3PutMem(pSSM, &idata[0], crStateGetUniformSize(pState, type)*sizeof(idata[0]));
    12301248                    CRASSERT(rc == VINF_SUCCESS);
    12311249                }
    12321250                else
    12331251                {
    1234                     diff_api.GetUniformfv(pProgram->hwid, location, &fdata[0]);
    1235                     rc = SSMR3PutMem(pSSM, &fdata[0], crStateGetUniformSize(type)*sizeof(fdata[0]));
     1252                    pState->diff_api.GetUniformfv(pProgram->hwid, location, &fdata[0]);
     1253                    rc = SSMR3PutMem(pSSM, &fdata[0], crStateGetUniformSize(pState, type)*sizeof(fdata[0]));
    12361254                    CRASSERT(rc == VINF_SUCCESS);
    12371255                }
     
    14731491int32_t crStateSaveContext(CRContext *pContext, PSSMHANDLE pSSM)
    14741492{
     1493    PCRStateTracker pState = pContext->pStateTracker;
    14751494    int32_t rc, i;
    14761495    uint32_t ui32, j;
    14771496    GLboolean bSaveShared = GL_TRUE;
     1497    CRStateSnapshotWalkArgs Args;
     1498
     1499    Args.pSSM = pSSM;
     1500    Args.pState = pState;
    14781501
    14791502    CRASSERT(pContext && pSSM);
     
    15391562
    15401563    /* Save textures */
    1541     rc = crStateSaveTextureObjData(&pContext->texture.base1D, pSSM);
    1542     AssertRCReturn(rc, rc);
    1543     rc = crStateSaveTextureObjData(&pContext->texture.base2D, pSSM);
    1544     AssertRCReturn(rc, rc);
    1545     rc = crStateSaveTextureObjData(&pContext->texture.base3D, pSSM);
    1546     AssertRCReturn(rc, rc);
    1547     rc = crStateSaveTextureObjData(&pContext->texture.proxy1D, pSSM);
    1548     AssertRCReturn(rc, rc);
    1549     rc = crStateSaveTextureObjData(&pContext->texture.proxy2D, pSSM);
    1550     AssertRCReturn(rc, rc);
    1551     rc = crStateSaveTextureObjData(&pContext->texture.proxy3D, pSSM);
     1564    rc = crStateSaveTextureObjData(pState, &pContext->texture.base1D, pSSM);
     1565    AssertRCReturn(rc, rc);
     1566    rc = crStateSaveTextureObjData(pState, &pContext->texture.base2D, pSSM);
     1567    AssertRCReturn(rc, rc);
     1568    rc = crStateSaveTextureObjData(pState, &pContext->texture.base3D, pSSM);
     1569    AssertRCReturn(rc, rc);
     1570    rc = crStateSaveTextureObjData(pState, &pContext->texture.proxy1D, pSSM);
     1571    AssertRCReturn(rc, rc);
     1572    rc = crStateSaveTextureObjData(pState, &pContext->texture.proxy2D, pSSM);
     1573    AssertRCReturn(rc, rc);
     1574    rc = crStateSaveTextureObjData(pState, &pContext->texture.proxy3D, pSSM);
    15521575#ifdef CR_ARB_texture_cube_map
    1553     rc = crStateSaveTextureObjData(&pContext->texture.baseCubeMap, pSSM);
    1554     AssertRCReturn(rc, rc);
    1555     rc = crStateSaveTextureObjData(&pContext->texture.proxyCubeMap, pSSM);
     1576    rc = crStateSaveTextureObjData(pState, &pContext->texture.baseCubeMap, pSSM);
     1577    AssertRCReturn(rc, rc);
     1578    rc = crStateSaveTextureObjData(pState, &pContext->texture.proxyCubeMap, pSSM);
    15561579    AssertRCReturn(rc, rc);
    15571580#endif
    15581581#ifdef CR_NV_texture_rectangle
    1559     rc = crStateSaveTextureObjData(&pContext->texture.baseRect, pSSM);
    1560     AssertRCReturn(rc, rc);
    1561     rc = crStateSaveTextureObjData(&pContext->texture.proxyRect, pSSM);
     1582    rc = crStateSaveTextureObjData(pState, &pContext->texture.baseRect, pSSM);
     1583    AssertRCReturn(rc, rc);
     1584    rc = crStateSaveTextureObjData(pState, &pContext->texture.proxyRect, pSSM);
    15621585    AssertRCReturn(rc, rc);
    15631586#endif
     
    15821605            pTexUnit = &pContext->texture.unit[pContext->texture.curTextureUnit];
    15831606
    1584             diff_api.BindTexture(GL_TEXTURE_1D, pTexUnit->currentTexture1D->hwid);
    1585             diff_api.BindTexture(GL_TEXTURE_2D, pTexUnit->currentTexture2D->hwid);
    1586             diff_api.BindTexture(GL_TEXTURE_3D, pTexUnit->currentTexture3D->hwid);
     1607            pState->diff_api.BindTexture(GL_TEXTURE_1D, pTexUnit->currentTexture1D->hwid);
     1608            pState->diff_api.BindTexture(GL_TEXTURE_2D, pTexUnit->currentTexture2D->hwid);
     1609            pState->diff_api.BindTexture(GL_TEXTURE_3D, pTexUnit->currentTexture3D->hwid);
    15871610#ifdef CR_ARB_texture_cube_map
    1588             diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, pTexUnit->currentTextureCubeMap->hwid);
     1611            pState->diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, pTexUnit->currentTextureCubeMap->hwid);
    15891612#endif
    15901613#ifdef CR_NV_texture_rectangle
    1591             diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, pTexUnit->currentTextureRect->hwid);
     1614            pState->diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, pTexUnit->currentTextureRect->hwid);
    15921615#endif
    15931616        }
     
    16761699
    16771700    /* Save default one*/
    1678     crStateSaveBufferObjectCB(0, pContext->bufferobject.nullBuffer, pSSM);
     1701    crStateSaveBufferObjectCB(0, pContext->bufferobject.nullBuffer, &Args);
    16791702
    16801703    if (bSaveShared)
    16811704    {
    16821705        /* Save all the rest */
    1683         crHashtableWalk(pContext->shared->buffersTable, crStateSaveBufferObjectCB, pSSM);
     1706        crHashtableWalk(pContext->shared->buffersTable, crStateSaveBufferObjectCB, &Args);
    16841707    }
    16851708
    16861709    /* Restore binding */
    1687     diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pContext->bufferobject.arrayBuffer->hwid);
     1710    pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pContext->bufferobject.arrayBuffer->hwid);
    16881711
    16891712    /* Save pointers */
     
    17941817}
    17951818
    1796 int32_t crStateSaveGlobals(PSSMHANDLE pSSM)
     1819int32_t crStateSaveGlobals(PCRStateTracker pState, PSSMHANDLE pSSM)
    17971820{
    17981821    /* don't need that for now */
     
    18121835#undef CRSTATE_BITS_OP
    18131836#else
    1814     RT_NOREF(pSSM);
     1837    RT_NOREF(pState, pSSM);
    18151838#endif
    18161839    return VINF_SUCCESS;
    18171840}
    18181841
    1819 int32_t crStateLoadGlobals(PSSMHANDLE pSSM, uint32_t u32Version)
     1842int32_t crStateLoadGlobals(PCRStateTracker pState, PSSMHANDLE pSSM, uint32_t u32Version)
    18201843{
    18211844    CRStateBits *pBits;
    18221845    int rc;
    1823     CRASSERT(g_cContexts >= 1);
    1824     if (g_cContexts <= 1)
     1846    CRASSERT(pState->cContexts >= 1);
     1847    if (pState->cContexts <= 1)
    18251848        return VINF_SUCCESS;
    18261849
    1827     pBits = GetCurrentBits();
     1850    pBits = GetCurrentBits(pState);
    18281851
    18291852    if (u32Version >= SHCROGL_SSM_VERSION_WITH_STATE_BITS)
     
    18791902int32_t crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM, uint32_t u32Version)
    18801903{
     1904    PCRStateTracker pState = pContext->pStateTracker;
    18811905    CRContext* pTmpContext;
    18821906    int32_t rc, i, j;
     
    20402064            CRASSERT(pContext->shared->refCount==1);
    20412065            bLoadShared = GL_FALSE;
    2042             crStateFreeShared(pContext, pContext->shared);
     2066            crStateFreeShared(pState, pContext, pContext->shared);
    20432067            pContext->shared = NULL;
    20442068            pTmpContext->shared->refCount++;
     
    26572681                pProgram->pUniforms[k].name = crStateLoadString(pSSM);
    26582682
    2659                 if (crStateIsIntUniform(pProgram->pUniforms[k].type))
     2683                if (crStateIsIntUniform(pState, pProgram->pUniforms[k].type))
    26602684                {
    26612685                    itemsize = sizeof(GLint);
    26622686                } else itemsize = sizeof(GLfloat);
    26632687
    2664                 datasize = crStateGetUniformSize(pProgram->pUniforms[k].type)*itemsize;
     2688                datasize = crStateGetUniformSize(pState, pProgram->pUniforms[k].type)*itemsize;
    26652689                pProgram->pUniforms[k].data = crAlloc((unsigned int /* this case is just so stupid */)datasize);
    26662690                if (!pProgram->pUniforms[k].data) return VERR_NO_MEMORY;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_stencil.c

    r69392 r78375  
    1111
    1212
    13 static GLint crStateStencilBufferGetIdxAndCount(CRStencilState *s, GLenum face, GLint *pIdx, GLint *pBitsIdx)
     13static GLint crStateStencilBufferGetIdxAndCount(PCRStateTracker pState, CRStencilState *s, GLenum face, GLint *pIdx, GLint *pBitsIdx)
    1414{
    1515    switch (face)
     
    3939            return 1;
    4040        default:
    41             crStateError(__LINE__,__FILE__,GL_INVALID_ENUM, "crStateStencilBufferGetIdxAndCount");
     41            crStateError(pState, __LINE__,__FILE__,GL_INVALID_ENUM, "crStateStencilBufferGetIdxAndCount");
    4242            return 0;
    4343    }
     
    6868{
    6969        CRStencilState *s = &ctx->stencil;
    70         CRStateBits *stateb = GetCurrentBits();
     70        CRStateBits *stateb = GetCurrentBits(ctx->pStateTracker);
    7171        CRStencilBits *sb = &(stateb->stencil);
    7272        int i;
     
    108108}
    109109
    110 static void crStateStencilFuncPerform(GLenum face, GLenum func, GLint ref, GLuint mask)
    111 {
    112     CRContext *g = GetCurrentContext();
     110static void crStateStencilFuncPerform(PCRStateTracker pState, GLenum face, GLenum func, GLint ref, GLuint mask)
     111{
     112    CRContext *g = GetCurrentContext(pState);
    113113    CRStencilState *s = &(g->stencil);
    114     CRStateBits *stateb = GetCurrentBits();
     114    CRStateBits *stateb = GetCurrentBits(pState);
    115115    CRStencilBits *sb = &(stateb->stencil);
    116116    GLint idx, bitsIdx, count, i;
     
    119119    if (g->current.inBeginEnd)
    120120    {
    121         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     121        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    122122            "glStencilFunc called in begin/end");
    123123        return;
     
    135135        func != GL_ALWAYS)
    136136    {
    137         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     137        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    138138            "glStencilFunc called with bogu func: %d", func);
    139139        return;
    140140    }
    141141
    142     count = crStateStencilBufferGetIdxAndCount(s, face, &idx, &bitsIdx);
     142    count = crStateStencilBufferGetIdxAndCount(pState, s, face, &idx, &bitsIdx);
    143143    if (count)
    144144    {
     
    153153}
    154154
    155 void STATE_APIENTRY crStateStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
     155void STATE_APIENTRY crStateStencilFuncSeparate(PCRStateTracker pState, GLenum face, GLenum func, GLint ref, GLuint mask)
    156156{
    157157    if (!face)
     
    159159        /* crStateStencilFuncPerform accepts 0 value, while glStencilFuncSeparate does not,
    160160         * filter it out here */
    161         crStateError(__LINE__,__FILE__,GL_INVALID_ENUM, "crStateStencilFuncSeparate");
     161        crStateError(pState, __LINE__,__FILE__,GL_INVALID_ENUM, "crStateStencilFuncSeparate");
    162162        return;
    163163    }
    164     crStateStencilFuncPerform(face, func, ref, mask);
    165 }
    166 
    167 void STATE_APIENTRY crStateStencilFunc(GLenum func, GLint ref, GLuint mask)
    168 {
    169     crStateStencilFuncPerform(0, func, ref, mask);
     164    crStateStencilFuncPerform(pState, face, func, ref, mask);
     165}
     166
     167void STATE_APIENTRY crStateStencilFunc(PCRStateTracker pState, GLenum func, GLint ref, GLuint mask)
     168{
     169    crStateStencilFuncPerform(pState, 0, func, ref, mask);
    170170}
    171171
     
    178178}
    179179
    180 static void crStateStencilOpPerform (GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
    181 {
    182         CRContext *g = GetCurrentContext();
     180static void crStateStencilOpPerform (PCRStateTracker pState, GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
     181{
     182        CRContext *g = GetCurrentContext(pState);
    183183        CRStencilState *s = &(g->stencil);
    184         CRStateBits *stateb = GetCurrentBits();
     184        CRStateBits *stateb = GetCurrentBits(pState);
    185185        CRStencilBits *sb = &(stateb->stencil);
    186186    GLint idx, bitsIdx, count, i;
     
    188188        if (g->current.inBeginEnd)
    189189        {
    190                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     190                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    191191                        "glStencilOp called in begin/end");
    192192                return;
     
    208208                break;
    209209        default:
    210                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     210                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    211211                        "glStencilOp called with bogus fail: %d", fail);
    212212                return;
     
    226226                break;
    227227        default:
    228                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     228                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    229229                        "glStencilOp called with bogus zfail: %d", zfail);
    230230                return;
     
    244244                break;
    245245        default:
    246                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     246                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    247247                        "glStencilOp called with bogus zpass: %d", zpass);
    248248                return;
    249249        }
    250250
    251     count = crStateStencilBufferGetIdxAndCount(s, face, &idx, &bitsIdx);
     251    count = crStateStencilBufferGetIdxAndCount(pState, s, face, &idx, &bitsIdx);
    252252    if (count)
    253253    {
     
    263263}
    264264
    265 void STATE_APIENTRY crStateStencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
     265void STATE_APIENTRY crStateStencilOpSeparate (PCRStateTracker pState, GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
    266266{
    267267    if (!face)
     
    269269        /* crStateStencilOpPerform accepts 0 value, while glStencilOpSeparate does not,
    270270         * filter it out here */
    271         crStateError(__LINE__,__FILE__,GL_INVALID_ENUM, "crStateStencilOpSeparate");
     271        crStateError(pState, __LINE__,__FILE__,GL_INVALID_ENUM, "crStateStencilOpSeparate");
    272272        return;
    273273    }
    274     crStateStencilOpPerform (0, fail, zfail, zpass);
    275 }
    276 
    277 void STATE_APIENTRY crStateStencilOp (GLenum fail, GLenum zfail, GLenum zpass)
    278 {
    279     crStateStencilOpPerform (0, fail, zfail, zpass);
    280 }
    281 
    282 void STATE_APIENTRY crStateClearStencil (GLint c)
    283 {
    284         CRContext *g = GetCurrentContext();
     274    crStateStencilOpPerform (pState, 0, fail, zfail, zpass);
     275}
     276
     277void STATE_APIENTRY crStateStencilOp (PCRStateTracker pState, GLenum fail, GLenum zfail, GLenum zpass)
     278{
     279    crStateStencilOpPerform (pState, 0, fail, zfail, zpass);
     280}
     281
     282void STATE_APIENTRY crStateClearStencil (PCRStateTracker pState, GLint c)
     283{
     284        CRContext *g = GetCurrentContext(pState);
    285285        CRStencilState *s = &(g->stencil);
    286         CRStateBits *stateb = GetCurrentBits();
     286        CRStateBits *stateb = GetCurrentBits(pState);
    287287        CRStencilBits *sb = &(stateb->stencil);
    288288
    289289        if (g->current.inBeginEnd)
    290290        {
    291                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     291                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    292292                        "glClearStencil called in begin/end");
    293293                return;
     
    302302}
    303303
    304 void STATE_APIENTRY crStateStencilMask (GLuint mask)
    305 {
    306         CRContext *g = GetCurrentContext();
     304void STATE_APIENTRY crStateStencilMask (PCRStateTracker pState, GLuint mask)
     305{
     306        CRContext *g = GetCurrentContext(pState);
    307307        CRStencilState *s = &(g->stencil);
    308         CRStateBits *stateb = GetCurrentBits();
     308        CRStateBits *stateb = GetCurrentBits(pState);
    309309        CRStencilBits *sb = &(stateb->stencil);
    310310
    311311        if (g->current.inBeginEnd)
    312312        {
    313                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     313                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    314314                        "glStencilMask called in begin/end");
    315315                return;
     
    324324}
    325325
    326 void STATE_APIENTRY crStateActiveStencilFaceEXT (GLenum face)
    327 {
    328     CRContext *g = GetCurrentContext();
     326void STATE_APIENTRY crStateActiveStencilFaceEXT (PCRStateTracker pState, GLenum face)
     327{
     328    CRContext *g = GetCurrentContext(pState);
    329329    CRStencilState *s = &(g->stencil);
    330     CRStateBits *stateb = GetCurrentBits();
     330    CRStateBits *stateb = GetCurrentBits(pState);
    331331    CRStencilBits *sb = &(stateb->stencil);
    332332
     
    338338        break;
    339339    default:
    340         crStateError(__LINE__,__FILE__,GL_INVALID_ENUM, "crStateActiveStencilFaceEXT");
     340        crStateError(pState, __LINE__,__FILE__,GL_INVALID_ENUM, "crStateActiveStencilFaceEXT");
    341341        return;
    342342    }
     
    348348#ifdef CRSTATE_DEBUG_STENCIL_ERR
    349349#define CRSTATE_CLEARERR() do { \
    350             while (diff_api.GetError() != GL_NO_ERROR) {} \
     350            while (pState->diff_api.GetError() != GL_NO_ERROR) {} \
    351351        } while (0)
    352352
     
    355355            CRSTATE_CLEARERR(); \
    356356            _op; \
    357             while ((_glErr = diff_api.GetError()) != GL_NO_ERROR) { Assert(0);} \
     357            while ((_glErr = pState->diff_api.GetError()) != GL_NO_ERROR) { Assert(0);} \
    358358        }while (0)
    359359#else
     
    388388        CRContext *fromCtx, CRContext *toCtx)
    389389{
     390    PCRStateTracker pState = fromCtx->pStateTracker;
    390391    CRStencilState *from = &(fromCtx->stencil);
    391392    CRStencilState *to = &(toCtx->stencil);
     
    395396    GLchar frontMatch = -1, backMatch = -1, toFrontBackMatch = -1;
    396397    CRbitvalue nbitID[CR_MAX_BITARRAY];
     398
     399    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     400
    397401    for (j=0;j<CR_MAX_BITARRAY;j++)
    398402        nbitID[j] = ~bitID[j];
     
    402406    {
    403407        glAble able[2];
    404         able[0] = diff_api.Disable;
    405         able[1] = diff_api.Enable;
     408        able[0] = pState->diff_api.Disable;
     409        able[1] = pState->diff_api.Enable;
    406410        if (from->stencilTest != to->stencilTest)
    407411        {
     
    415419    {
    416420        glAble able[2];
    417         able[0] = diff_api.Disable;
    418         able[1] = diff_api.Enable;
     421        able[0] = pState->diff_api.Disable;
     422        able[1] = pState->diff_api.Enable;
    419423        if (from->stencilTwoSideEXT != to->stencilTwoSideEXT)
    420424        {
     
    429433        if (from->clearValue != to->clearValue)
    430434        {
    431             diff_api.ClearStencil (to->clearValue);
     435            pState->diff_api.ClearStencil (to->clearValue);
    432436            from->clearValue = to->clearValue;
    433437        }
     
    466470                if (activeFace == GL_BACK)
    467471                {
    468                     diff_api.ActiveStencilFaceEXT(GL_FRONT);
     472                    pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    469473                    activeFace = GL_FRONT;
    470474                }
    471475
    472                 diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     476                pState->diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    473477                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    474478                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask);
     
    483487                if (activeFace == GL_BACK)
    484488                {
    485                     diff_api.ActiveStencilFaceEXT(GL_FRONT);
     489                    pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    486490                    activeFace = GL_FRONT;
    487491                }
    488492
    489                 diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     493                pState->diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    490494                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    491495                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask);
     
    498502                if (activeFace == GL_BACK)
    499503                {
    500                     diff_api.ActiveStencilFaceEXT(GL_FRONT);
     504                    pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    501505                    activeFace = GL_FRONT;
    502506                }
    503507
    504                 diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
     508                pState->diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
    505509                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].ref,
    506510                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].mask);
     
    525529                    if (activeFace == GL_BACK)
    526530                    {
    527                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    528                         activeFace = GL_FRONT;
    529                     }
    530 
    531                     diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     531                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     532                        activeFace = GL_FRONT;
     533                    }
     534
     535                    pState->diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    532536                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    533537                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask);
     
    546550                    if (activeFace == GL_BACK)
    547551                    {
    548                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    549                         activeFace = GL_FRONT;
    550                     }
    551 
    552                     diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     552                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     553                        activeFace = GL_FRONT;
     554                    }
     555
     556                    pState->diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    553557                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    554558                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask);
     
    564568                    if (activeFace == GL_BACK)
    565569                    {
    566                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    567                         activeFace = GL_FRONT;
    568                     }
    569 
    570                     diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
     570                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     571                        activeFace = GL_FRONT;
     572                    }
     573
     574                    pState->diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
    571575                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].ref,
    572576                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].mask);
     
    590594                    if (activeFace == GL_BACK)
    591595                    {
    592                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    593                         activeFace = GL_FRONT;
    594                     }
    595 
    596                     diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     596                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     597                        activeFace = GL_FRONT;
     598                    }
     599
     600                    pState->diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    597601                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    598602                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask);
     
    611615                    if (activeFace == GL_BACK)
    612616                    {
    613                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    614                         activeFace = GL_FRONT;
    615                     }
    616 
    617                     diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     617                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     618                        activeFace = GL_FRONT;
     619                    }
     620
     621                    pState->diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    618622                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    619623                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask);
     
    629633                    if (activeFace == GL_BACK)
    630634                    {
    631                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    632                         activeFace = GL_FRONT;
    633                     }
    634 
    635                     diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
     635                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     636                        activeFace = GL_FRONT;
     637                    }
     638
     639                    pState->diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
    636640                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].ref,
    637641                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].mask);
     
    650654            if (activeFace == GL_FRONT)
    651655            {
    652                 diff_api.ActiveStencilFaceEXT(GL_BACK);
     656                pState->diff_api.ActiveStencilFaceEXT(GL_BACK);
    653657                activeFace = GL_BACK;
    654658            }
    655659
    656             diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].func,
     660            pState->diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].func,
    657661                to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].ref,
    658662                to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].mask);
     
    697701                if (activeFace == GL_BACK)
    698702                {
    699                     diff_api.ActiveStencilFaceEXT(GL_FRONT);
     703                    pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    700704                    activeFace = GL_FRONT;
    701705                }
    702706
    703                 diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     707                pState->diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    704708                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    705709                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass);
     
    715719                if (activeFace == GL_BACK)
    716720                {
    717                     diff_api.ActiveStencilFaceEXT(GL_FRONT);
     721                    pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    718722                    activeFace = GL_FRONT;
    719723                }
    720724
    721                 diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     725                pState->diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    722726                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    723727                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass);
     
    729733                if (activeFace == GL_BACK)
    730734                {
    731                     diff_api.ActiveStencilFaceEXT(GL_FRONT);
     735                    pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    732736                    activeFace = GL_FRONT;
    733737                }
    734738
    735                 diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
     739                pState->diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
    736740                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthFail,
    737741                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthPass);
     
    754758                    if (activeFace == GL_BACK)
    755759                    {
    756                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    757                         activeFace = GL_FRONT;
    758                     }
    759 
    760                     diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     760                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     761                        activeFace = GL_FRONT;
     762                    }
     763
     764                    pState->diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    761765                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    762766                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass);
     
    775779                    if (activeFace == GL_BACK)
    776780                    {
    777                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    778                         activeFace = GL_FRONT;
    779                     }
    780 
    781                     diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     781                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     782                        activeFace = GL_FRONT;
     783                    }
     784
     785                    pState->diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    782786                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    783787                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass);
     
    794798                    if (activeFace == GL_BACK)
    795799                    {
    796                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    797                         activeFace = GL_FRONT;
    798                     }
    799 
    800                     diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
     800                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     801                        activeFace = GL_FRONT;
     802                    }
     803
     804                    pState->diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
    801805                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthFail,
    802806                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthPass);
     
    820824                    if (activeFace == GL_BACK)
    821825                    {
    822                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    823                         activeFace = GL_FRONT;
    824                     }
    825 
    826                     diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     826                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     827                        activeFace = GL_FRONT;
     828                    }
     829
     830                    pState->diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    827831                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    828832                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass);
     
    841845                    if (activeFace == GL_BACK)
    842846                    {
    843                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    844                         activeFace = GL_FRONT;
    845                     }
    846 
    847                     diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     847                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     848                        activeFace = GL_FRONT;
     849                    }
     850
     851                    pState->diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    848852                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    849853                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass);
     
    860864                    if (activeFace == GL_BACK)
    861865                    {
    862                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    863                         activeFace = GL_FRONT;
    864                     }
    865 
    866                     diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
     866                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     867                        activeFace = GL_FRONT;
     868                    }
     869
     870                    pState->diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
    867871                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthFail,
    868872                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthPass);
     
    881885            if (activeFace == GL_FRONT)
    882886            {
    883                 diff_api.ActiveStencilFaceEXT(GL_BACK);
     887                pState->diff_api.ActiveStencilFaceEXT(GL_BACK);
    884888                activeFace = GL_BACK;
    885889            }
    886890
    887             diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].fail,
     891            pState->diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].fail,
    888892                                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].passDepthFail,
    889893                                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].passDepthPass);
     
    900904    if (activeFace != to->activeStencilFace)
    901905    {
    902         diff_api.ActiveStencilFaceEXT(activeFace);
     906        pState->diff_api.ActiveStencilFaceEXT(activeFace);
    903907    }
    904908
     
    918922        if (from->writeMask != to->writeMask)
    919923        {
    920             diff_api.StencilMask (to->writeMask);
     924            pState->diff_api.StencilMask (to->writeMask);
    921925            from->writeMask = to->writeMask;
    922926        }
     
    929933        CRContext *fromCtx, CRContext *toCtx)
    930934{
     935    PCRStateTracker pState = fromCtx->pStateTracker;
    931936    CRStencilState *from = &(fromCtx->stencil);
    932937    CRStencilState *to = &(toCtx->stencil);
     
    936941    GLchar frontMatch = -1, backMatch = -1, toFrontBackMatch = -1;
    937942    CRbitvalue nbitID[CR_MAX_BITARRAY];
     943
     944    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     945
    938946    for (j=0;j<CR_MAX_BITARRAY;j++)
    939947        nbitID[j] = ~bitID[j];
     
    943951    {
    944952        glAble able[2];
    945         able[0] = diff_api.Disable;
    946         able[1] = diff_api.Enable;
     953        able[0] = pState->diff_api.Disable;
     954        able[1] = pState->diff_api.Enable;
    947955        if (from->stencilTest != to->stencilTest)
    948956        {
     
    956964    {
    957965        glAble able[2];
    958         able[0] = diff_api.Disable;
    959         able[1] = diff_api.Enable;
     966        able[0] = pState->diff_api.Disable;
     967        able[1] = pState->diff_api.Enable;
    960968        if (from->stencilTwoSideEXT != to->stencilTwoSideEXT)
    961969        {
     
    970978        if (from->clearValue != to->clearValue)
    971979        {
    972             CRSTATE_CHECKGLERR(diff_api.ClearStencil (to->clearValue));
     980            CRSTATE_CHECKGLERR(pState->diff_api.ClearStencil (to->clearValue));
    973981            FILLDIRTY(b->clearValue);
    974982            FILLDIRTY(b->dirty);
     
    10071015                if (activeFace == GL_BACK)
    10081016                {
    1009                     diff_api.ActiveStencilFaceEXT(GL_FRONT);
     1017                    pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    10101018                    activeFace = GL_FRONT;
    10111019                }
    10121020
    1013                 CRSTATE_CHECKGLERR(diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     1021                CRSTATE_CHECKGLERR(pState->diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    10141022                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    10151023                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask));
     
    10221030                if (activeFace == GL_BACK)
    10231031                {
    1024                     diff_api.ActiveStencilFaceEXT(GL_FRONT);
     1032                    pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    10251033                    activeFace = GL_FRONT;
    10261034                }
    10271035
    1028                 CRSTATE_CHECKGLERR(diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     1036                CRSTATE_CHECKGLERR(pState->diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    10291037                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    10301038                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask));
     
    10351043                if (activeFace == GL_BACK)
    10361044                {
    1037                     diff_api.ActiveStencilFaceEXT(GL_FRONT);
     1045                    pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
    10381046                    activeFace = GL_FRONT;
    10391047                }
    10401048
    1041                 CRSTATE_CHECKGLERR(diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
     1049                CRSTATE_CHECKGLERR(pState->diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
    10421050                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].ref,
    10431051                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].mask));
     
    10611069                    if (activeFace == GL_BACK)
    10621070                    {
    1063                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    1064                         activeFace = GL_FRONT;
    1065                     }
    1066 
    1067                     CRSTATE_CHECKGLERR(diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     1071                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     1072                        activeFace = GL_FRONT;
     1073                    }
     1074
     1075                    CRSTATE_CHECKGLERR(pState->diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    10681076                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    10691077                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask));
     
    10791087                    if (activeFace == GL_BACK)
    10801088                    {
    1081                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    1082                         activeFace = GL_FRONT;
    1083                     }
    1084 
    1085                     CRSTATE_CHECKGLERR(diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     1089                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     1090                        activeFace = GL_FRONT;
     1091                    }
     1092
     1093                    CRSTATE_CHECKGLERR(pState->diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    10861094                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    10871095                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask));
     
    10951103                    if (activeFace == GL_BACK)
    10961104                    {
    1097                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    1098                         activeFace = GL_FRONT;
    1099                     }
    1100 
    1101                     CRSTATE_CHECKGLERR(diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
     1105                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     1106                        activeFace = GL_FRONT;
     1107                    }
     1108
     1109                    CRSTATE_CHECKGLERR(pState->diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
    11021110                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].ref,
    11031111                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].mask));
     
    11221130                    if (activeFace == GL_BACK)
    11231131                    {
    1124                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    1125                         activeFace = GL_FRONT;
    1126                     }
    1127 
    1128                     CRSTATE_CHECKGLERR(diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     1132                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     1133                        activeFace = GL_FRONT;
     1134                    }
     1135
     1136                    CRSTATE_CHECKGLERR(pState->diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    11291137                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    11301138                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask));
     
    11401148                    if (activeFace == GL_BACK)
    11411149                    {
    1142                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    1143                         activeFace = GL_FRONT;
    1144                     }
    1145 
    1146                     CRSTATE_CHECKGLERR(diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
     1150                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     1151                        activeFace = GL_FRONT;
     1152                    }
     1153
     1154                    CRSTATE_CHECKGLERR(pState->diff_api.StencilFuncSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].func,
    11471155                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].ref,
    11481156                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].mask));
     
    11561164                    if (activeFace == GL_BACK)
    11571165                    {
    1158                         diff_api.ActiveStencilFaceEXT(GL_FRONT);
    1159                         activeFace = GL_FRONT;
    1160                     }
    1161 
    1162                     CRSTATE_CHECKGLERR(diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
     1166                        pState->diff_api.ActiveStencilFaceEXT(GL_FRONT);
     1167                        activeFace = GL_FRONT;
     1168                    }
     1169
     1170                    CRSTATE_CHECKGLERR(pState->diff_api.StencilFuncSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].func,
    11631171                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].ref,
    11641172                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].mask));
     
    11781186            if (activeFace == GL_FRONT)
    11791187            {
    1180                 CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_BACK));
     1188                CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_BACK));
    11811189                activeFace = GL_BACK;
    11821190            }
    11831191
    1184             CRSTATE_CHECKGLERR(diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].func,
     1192            CRSTATE_CHECKGLERR(pState->diff_api.StencilFunc (to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].func,
    11851193                to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].ref,
    11861194                to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].mask));
     
    12271235                if (activeFace == GL_BACK)
    12281236                {
    1229                     CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_FRONT));
     1237                    CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_FRONT));
    12301238                    activeFace = GL_FRONT;
    12311239                }
    12321240
    1233                 CRSTATE_CHECKGLERR(diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     1241                CRSTATE_CHECKGLERR(pState->diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    12341242                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    12351243                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass));
     
    12421250                if (activeFace == GL_BACK)
    12431251                {
    1244                     CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_FRONT));
     1252                    CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_FRONT));
    12451253                    activeFace = GL_FRONT;
    12461254                }
    12471255
    1248                 CRSTATE_CHECKGLERR(diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     1256                CRSTATE_CHECKGLERR(pState->diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    12491257                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    12501258                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass));
     
    12551263                if (activeFace == GL_BACK)
    12561264                {
    1257                     CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_FRONT));
     1265                    CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_FRONT));
    12581266                    activeFace = GL_FRONT;
    12591267                }
    12601268
    1261                 CRSTATE_CHECKGLERR(diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
     1269                CRSTATE_CHECKGLERR(pState->diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
    12621270                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthFail,
    12631271                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthPass));
     
    12811289                    if (activeFace == GL_BACK)
    12821290                    {
    1283                         CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_FRONT));
    1284                         activeFace = GL_FRONT;
    1285                     }
    1286 
    1287                     CRSTATE_CHECKGLERR(diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     1291                        CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_FRONT));
     1292                        activeFace = GL_FRONT;
     1293                    }
     1294
     1295                    CRSTATE_CHECKGLERR(pState->diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    12881296                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    12891297                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass));
     
    12991307                    if (activeFace == GL_BACK)
    13001308                    {
    1301                         CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_FRONT));
    1302                         activeFace = GL_FRONT;
    1303                     }
    1304 
    1305                     CRSTATE_CHECKGLERR(diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     1309                        CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_FRONT));
     1310                        activeFace = GL_FRONT;
     1311                    }
     1312
     1313                    CRSTATE_CHECKGLERR(pState->diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    13061314                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    13071315                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass));
     
    13151323                    if (activeFace == GL_BACK)
    13161324                    {
    1317                         CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_FRONT));
    1318                         activeFace = GL_FRONT;
    1319                     }
    1320 
    1321                     CRSTATE_CHECKGLERR(diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
     1325                        CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_FRONT));
     1326                        activeFace = GL_FRONT;
     1327                    }
     1328
     1329                    CRSTATE_CHECKGLERR(pState->diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
    13221330                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthFail,
    13231331                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthPass));
     
    13431351                    if (activeFace == GL_BACK)
    13441352                    {
    1345                         CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_FRONT));
    1346                         activeFace = GL_FRONT;
    1347                     }
    1348 
    1349                     CRSTATE_CHECKGLERR(diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     1353                        CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_FRONT));
     1354                        activeFace = GL_FRONT;
     1355                    }
     1356
     1357                    CRSTATE_CHECKGLERR(pState->diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    13501358                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    13511359                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass));
     
    13611369                    if (activeFace == GL_BACK)
    13621370                    {
    1363                         CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_FRONT));
    1364                         activeFace = GL_FRONT;
    1365                     }
    1366 
    1367                     CRSTATE_CHECKGLERR(diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
     1371                        CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_FRONT));
     1372                        activeFace = GL_FRONT;
     1373                    }
     1374
     1375                    CRSTATE_CHECKGLERR(pState->diff_api.StencilOpSeparate (GL_FRONT, to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].fail,
    13681376                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthFail,
    13691377                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_FRONT].passDepthPass));
     
    13771385                    if (activeFace == GL_BACK)
    13781386                    {
    1379                         CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_FRONT));
    1380                         activeFace = GL_FRONT;
    1381                     }
    1382 
    1383                     CRSTATE_CHECKGLERR(diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
     1387                        CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_FRONT));
     1388                        activeFace = GL_FRONT;
     1389                    }
     1390
     1391                    CRSTATE_CHECKGLERR(pState->diff_api.StencilOpSeparate (GL_BACK, to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].fail,
    13841392                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthFail,
    13851393                        to->buffers[CRSTATE_STENCIL_BUFFER_ID_BACK].passDepthPass));
     
    14001408            if (activeFace == GL_FRONT)
    14011409            {
    1402                 CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(GL_BACK));
     1410                CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(GL_BACK));
    14031411                activeFace = GL_BACK;
    14041412            }
    14051413
    1406             CRSTATE_CHECKGLERR(diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].fail,
     1414            CRSTATE_CHECKGLERR(pState->diff_api.StencilOp (to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].fail,
    14071415                                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].passDepthFail,
    14081416                                    to->buffers[CRSTATE_STENCIL_BUFFER_ID_TWO_SIDE_BACK].passDepthPass));
     
    14201428    if (activeFace != to->activeStencilFace)
    14211429    {
    1422         CRSTATE_CHECKGLERR(diff_api.ActiveStencilFaceEXT(activeFace));
     1430        CRSTATE_CHECKGLERR(pState->diff_api.ActiveStencilFaceEXT(activeFace));
    14231431    }
    14241432
     
    14391447        if (from->writeMask != to->writeMask)
    14401448        {
    1441             CRSTATE_CHECKGLERR(diff_api.StencilMask (to->writeMask));
     1449            CRSTATE_CHECKGLERR(pState->diff_api.StencilMask (to->writeMask));
    14421450            FILLDIRTY(b->writeMask);
    14431451            FILLDIRTY(b->dirty);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texdiff.c

    r69392 r78375  
    1515
    1616
    17 #define UNIMPLEMENTED() crStateError(__LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented something or other" )
     17#define UNIMPLEMENTED() crStateError(pState, __LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented something or other" )
    1818
    1919
     
    9898                                                     CRContext *fromCtx, CRContext *toCtx )
    9999{
     100    PCRStateTracker pState = fromCtx->pStateTracker;
    100101    CRTextureState *from = &(fromCtx->texture);
    101102    const CRTextureState *to = &(toCtx->texture);
     
    105106    unsigned int activeUnit = (unsigned int) -1;
    106107
     108    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     109
    107110    for (j=0;j<CR_MAX_BITARRAY;j++)
    108111        nbitID[j] = ~bitID[j];
    109     able[0] = diff_api.Disable;
    110     able[1] = diff_api.Enable;
     112    able[0] = pState->diff_api.Disable;
     113    able[1] = pState->diff_api.Enable;
    111114
    112115    for (i = 0; i < fromCtx->limits.maxTextureUnits; i++)
     
    115118        {
    116119            if (activeUnit != i) {
    117                 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
     120                pState->diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
    118121                activeUnit = i;
    119122            }
     
    182185        {
    183186            if (activeUnit != i) {
    184                 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
     187                pState->diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
    185188                activeUnit = i;
    186189            }
    187190            if (from->unit[i].currentTexture1D->hwid != to->unit[i].currentTexture1D->hwid)
    188191            {
    189                 diff_api.BindTexture(GL_TEXTURE_1D, crStateGetTextureObjHWID(to->unit[i].currentTexture1D));
     192                pState->diff_api.BindTexture(GL_TEXTURE_1D, crStateGetTextureObjHWID(pState, to->unit[i].currentTexture1D));
    190193                FILLDIRTY(tb->current[i]);
    191194                FILLDIRTY(tb->dirty);
     
    193196            if (from->unit[i].currentTexture2D->hwid != to->unit[i].currentTexture2D->hwid)
    194197            {
    195                 diff_api.BindTexture(GL_TEXTURE_2D, crStateGetTextureObjHWID(to->unit[i].currentTexture2D));
     198                pState->diff_api.BindTexture(GL_TEXTURE_2D, crStateGetTextureObjHWID(pState, to->unit[i].currentTexture2D));
    196199                FILLDIRTY(tb->current[i]);
    197200                FILLDIRTY(tb->dirty);
     
    200203            if (from->unit[i].currentTexture3D->hwid != to->unit[i].currentTexture3D->hwid)
    201204            {
    202                 diff_api.BindTexture(GL_TEXTURE_3D, crStateGetTextureObjHWID(to->unit[i].currentTexture3D));
     205                pState->diff_api.BindTexture(GL_TEXTURE_3D, crStateGetTextureObjHWID(pState, to->unit[i].currentTexture3D));
    203206                FILLDIRTY(tb->current[i]);
    204207                FILLDIRTY(tb->dirty);
     
    209212                from->unit[i].currentTextureCubeMap->hwid != to->unit[i].currentTextureCubeMap->hwid)
    210213            {
    211                 diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, crStateGetTextureObjHWID(to->unit[i].currentTextureCubeMap));
     214                pState->diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, crStateGetTextureObjHWID(pState, to->unit[i].currentTextureCubeMap));
    212215                FILLDIRTY(tb->current[i]);
    213216                FILLDIRTY(tb->dirty);
     
    218221                from->unit[i].currentTextureRect->hwid != to->unit[i].currentTextureRect->hwid)
    219222            {
    220                 diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, crStateGetTextureObjHWID(to->unit[i].currentTextureRect));
     223                pState->diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, crStateGetTextureObjHWID(pState, to->unit[i].currentTextureRect));
    221224                FILLDIRTY(tb->current[i]);
    222225                FILLDIRTY(tb->dirty);
     
    229232        {
    230233            if (activeUnit != i) {
    231                 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
     234                pState->diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
    232235                activeUnit = i;
    233236            }
     
    242245                f[2] = to->unit[i].objSCoeff.z;
    243246                f[3] = to->unit[i].objSCoeff.w;
    244                 diff_api.TexGenfv (GL_S, GL_OBJECT_PLANE, (const GLfloat *) f);
     247                pState->diff_api.TexGenfv (GL_S, GL_OBJECT_PLANE, (const GLfloat *) f);
    245248                FILLDIRTY(tb->objGen[i]);
    246249                FILLDIRTY(tb->dirty);
     
    255258                f[2] = to->unit[i].objTCoeff.z;
    256259                f[3] = to->unit[i].objTCoeff.w;
    257                 diff_api.TexGenfv (GL_T, GL_OBJECT_PLANE, (const GLfloat *) f);
     260                pState->diff_api.TexGenfv (GL_T, GL_OBJECT_PLANE, (const GLfloat *) f);
    258261                FILLDIRTY(tb->objGen[i]);
    259262                FILLDIRTY(tb->dirty);
     
    268271                f[2] = to->unit[i].objRCoeff.z;
    269272                f[3] = to->unit[i].objRCoeff.w;
    270                 diff_api.TexGenfv (GL_R, GL_OBJECT_PLANE, (const GLfloat *) f);
     273                pState->diff_api.TexGenfv (GL_R, GL_OBJECT_PLANE, (const GLfloat *) f);
    271274                FILLDIRTY(tb->objGen[i]);
    272275                FILLDIRTY(tb->dirty);
     
    281284                f[2] = to->unit[i].objQCoeff.z;
    282285                f[3] = to->unit[i].objQCoeff.w;
    283                 diff_api.TexGenfv (GL_Q, GL_OBJECT_PLANE, (const GLfloat *) f);
     286                pState->diff_api.TexGenfv (GL_Q, GL_OBJECT_PLANE, (const GLfloat *) f);
    284287                FILLDIRTY(tb->objGen[i]);
    285288                FILLDIRTY(tb->dirty);
     
    290293        {
    291294            if (activeUnit != i) {
    292                 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
     295                pState->diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
    293296                activeUnit = i;
    294297            }
    295             diff_api.MatrixMode(GL_MODELVIEW);
    296             diff_api.PushMatrix();
    297             diff_api.LoadIdentity();
     298            pState->diff_api.MatrixMode(GL_MODELVIEW);
     299            pState->diff_api.PushMatrix();
     300            pState->diff_api.LoadIdentity();
    298301            if (from->unit[i].eyeSCoeff.x != to->unit[i].eyeSCoeff.x ||
    299302                from->unit[i].eyeSCoeff.y != to->unit[i].eyeSCoeff.y ||
     
    305308                f[2] = to->unit[i].eyeSCoeff.z;
    306309                f[3] = to->unit[i].eyeSCoeff.w;
    307                 diff_api.TexGenfv (GL_S, GL_EYE_PLANE, (const GLfloat *) f);
     310                pState->diff_api.TexGenfv (GL_S, GL_EYE_PLANE, (const GLfloat *) f);
    308311                FILLDIRTY(tb->eyeGen[i]);
    309312                FILLDIRTY(tb->dirty);
     
    318321                f[2] = to->unit[i].eyeTCoeff.z;
    319322                f[3] = to->unit[i].eyeTCoeff.w;
    320                 diff_api.TexGenfv (GL_T, GL_EYE_PLANE, (const GLfloat *) f);
     323                pState->diff_api.TexGenfv (GL_T, GL_EYE_PLANE, (const GLfloat *) f);
    321324                FILLDIRTY(tb->eyeGen[i]);
    322325                FILLDIRTY(tb->dirty);
     
    331334                f[2] = to->unit[i].eyeRCoeff.z;
    332335                f[3] = to->unit[i].eyeRCoeff.w;
    333                 diff_api.TexGenfv (GL_R, GL_EYE_PLANE, (const GLfloat *) f);
     336                pState->diff_api.TexGenfv (GL_R, GL_EYE_PLANE, (const GLfloat *) f);
    334337                FILLDIRTY(tb->eyeGen[i]);
    335338                FILLDIRTY(tb->dirty);
     
    344347                f[2] = to->unit[i].eyeQCoeff.z;
    345348                f[3] = to->unit[i].eyeQCoeff.w;
    346                 diff_api.TexGenfv (GL_Q, GL_EYE_PLANE, (const GLfloat *) f);
     349                pState->diff_api.TexGenfv (GL_Q, GL_EYE_PLANE, (const GLfloat *) f);
    347350                FILLDIRTY(tb->eyeGen[i]);
    348351                FILLDIRTY(tb->dirty);
    349352            }
    350             diff_api.PopMatrix();
     353            pState->diff_api.PopMatrix();
    351354            CLEARDIRTY(tb->eyeGen[i], nbitID);
    352355        }
     
    354357        {
    355358            if (activeUnit != i) {
    356                 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
     359                pState->diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
    357360                activeUnit = i;
    358361            }
     
    362365                from->unit[i].gen.q != to->unit[i].gen.q)
    363366            {
    364                 diff_api.TexGeni (GL_S, GL_TEXTURE_GEN_MODE, to->unit[i].gen.s);
    365                 diff_api.TexGeni (GL_T, GL_TEXTURE_GEN_MODE, to->unit[i].gen.t);
    366                 diff_api.TexGeni (GL_R, GL_TEXTURE_GEN_MODE, to->unit[i].gen.r);
    367                 diff_api.TexGeni (GL_Q, GL_TEXTURE_GEN_MODE, to->unit[i].gen.q);   
     367                pState->diff_api.TexGeni (GL_S, GL_TEXTURE_GEN_MODE, to->unit[i].gen.s);
     368                pState->diff_api.TexGeni (GL_T, GL_TEXTURE_GEN_MODE, to->unit[i].gen.t);
     369                pState->diff_api.TexGeni (GL_R, GL_TEXTURE_GEN_MODE, to->unit[i].gen.r);
     370                pState->diff_api.TexGeni (GL_Q, GL_TEXTURE_GEN_MODE, to->unit[i].gen.q);   
    368371                FILLDIRTY(tb->genMode[i]);
    369372                FILLDIRTY(tb->dirty);
     
    377380        {
    378381            if (activeUnit != i) {
    379                 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
     382                pState->diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
    380383                activeUnit = i;
    381384            }
    382385            if (from->unit[i].envMode != to->unit[i].envMode)
    383386            {
    384                 diff_api.TexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, to->unit[i].envMode);
     387                pState->diff_api.TexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, to->unit[i].envMode);
    385388                FILLDIRTY(tb->envBit[i]);
    386389                FILLDIRTY(tb->dirty);
     
    396399                f[2] = to->unit[i].envColor.b;
    397400                f[3] = to->unit[i].envColor.a;
    398                 diff_api.TexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, (const GLfloat *) f);
     401                pState->diff_api.TexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, (const GLfloat *) f);
    399402                FILLDIRTY(tb->envBit[i]);
    400403                FILLDIRTY(tb->dirty);
     
    402405            if (from->unit[i].combineModeRGB != to->unit[i].combineModeRGB)
    403406            {
    404                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, to->unit[i].combineModeRGB);
     407                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, to->unit[i].combineModeRGB);
    405408                FILLDIRTY(tb->envBit[i]);
    406409                FILLDIRTY(tb->dirty);
     
    408411            if (from->unit[i].combineModeA != to->unit[i].combineModeA)
    409412            {
    410                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, to->unit[i].combineModeA);
     413                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, to->unit[i].combineModeA);
    411414                FILLDIRTY(tb->envBit[i]);
    412415                FILLDIRTY(tb->dirty);
     
    414417            if (from->unit[i].combineSourceRGB[0] != to->unit[i].combineSourceRGB[0])
    415418            {
    416                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, to->unit[i].combineSourceRGB[0]);
     419                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, to->unit[i].combineSourceRGB[0]);
    417420                FILLDIRTY(tb->envBit[i]);
    418421                FILLDIRTY(tb->dirty);
     
    420423            if (from->unit[i].combineSourceRGB[1] != to->unit[i].combineSourceRGB[1])
    421424            {
    422                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, to->unit[i].combineSourceRGB[1]);
     425                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, to->unit[i].combineSourceRGB[1]);
    423426                FILLDIRTY(tb->envBit[i]);
    424427                FILLDIRTY(tb->dirty);
     
    426429            if (from->unit[i].combineSourceRGB[2] != to->unit[i].combineSourceRGB[2])
    427430            {
    428                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, to->unit[i].combineSourceRGB[2]);
     431                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, to->unit[i].combineSourceRGB[2]);
    429432                FILLDIRTY(tb->envBit[i]);
    430433                FILLDIRTY(tb->dirty);
     
    432435            if (from->unit[i].combineSourceA[0] != to->unit[i].combineSourceA[0])
    433436            {
    434                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, to->unit[i].combineSourceA[0]);
     437                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, to->unit[i].combineSourceA[0]);
    435438                FILLDIRTY(tb->envBit[i]);
    436439                FILLDIRTY(tb->dirty);
     
    438441            if (from->unit[i].combineSourceA[1] != to->unit[i].combineSourceA[1])
    439442            {
    440                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, to->unit[i].combineSourceA[1]);
     443                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, to->unit[i].combineSourceA[1]);
    441444                FILLDIRTY(tb->envBit[i]);
    442445                FILLDIRTY(tb->dirty);
     
    444447            if (from->unit[i].combineSourceA[2] != to->unit[i].combineSourceA[2])
    445448            {
    446                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, to->unit[i].combineSourceA[2]);
     449                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, to->unit[i].combineSourceA[2]);
    447450                FILLDIRTY(tb->envBit[i]);
    448451                FILLDIRTY(tb->dirty);
     
    450453            if (from->unit[i].combineOperandRGB[0] != to->unit[i].combineOperandRGB[0])
    451454            {
    452                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, to->unit[i].combineOperandRGB[0]);
     455                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, to->unit[i].combineOperandRGB[0]);
    453456                FILLDIRTY(tb->envBit[i]);
    454457                FILLDIRTY(tb->dirty);
     
    456459            if (from->unit[i].combineOperandRGB[1] != to->unit[i].combineOperandRGB[1])
    457460            {
    458                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, to->unit[i].combineOperandRGB[1]);
     461                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, to->unit[i].combineOperandRGB[1]);
    459462                FILLDIRTY(tb->envBit[i]);
    460463                FILLDIRTY(tb->dirty);
     
    462465            if (from->unit[i].combineOperandRGB[2] != to->unit[i].combineOperandRGB[2])
    463466            {
    464                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, to->unit[i].combineOperandRGB[2]);
     467                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, to->unit[i].combineOperandRGB[2]);
    465468                FILLDIRTY(tb->envBit[i]);
    466469                FILLDIRTY(tb->dirty);
     
    468471            if (from->unit[i].combineOperandA[0] != to->unit[i].combineOperandA[0])
    469472            {
    470                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, to->unit[i].combineOperandA[0]);
     473                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, to->unit[i].combineOperandA[0]);
    471474                FILLDIRTY(tb->envBit[i]);
    472475                FILLDIRTY(tb->dirty);
     
    474477            if (from->unit[i].combineOperandA[1] != to->unit[i].combineOperandA[1])
    475478            {
    476                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, to->unit[i].combineOperandA[1]);
     479                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, to->unit[i].combineOperandA[1]);
    477480                FILLDIRTY(tb->envBit[i]);
    478481                FILLDIRTY(tb->dirty);
     
    480483            if (from->unit[i].combineOperandA[2] != to->unit[i].combineOperandA[2])
    481484            {
    482                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, to->unit[i].combineOperandA[2]);
     485                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, to->unit[i].combineOperandA[2]);
    483486                FILLDIRTY(tb->envBit[i]);
    484487                FILLDIRTY(tb->dirty);
     
    486489            if (from->unit[i].combineScaleRGB != to->unit[i].combineScaleRGB)
    487490            {
    488                 diff_api.TexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, to->unit[i].combineScaleRGB);
     491                pState->diff_api.TexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, to->unit[i].combineScaleRGB);
    489492                FILLDIRTY(tb->envBit[i]);
    490493                FILLDIRTY(tb->dirty);
     
    492495            if (from->unit[i].combineScaleA != to->unit[i].combineScaleA)
    493496            {
    494                 diff_api.TexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, to->unit[i].combineScaleA);
     497                pState->diff_api.TexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, to->unit[i].combineScaleA);
    495498                FILLDIRTY(tb->envBit[i]);
    496499                FILLDIRTY(tb->dirty);
     
    510513    /* After possible fiddling put them back now */
    511514    if (activeUnit != toCtx->texture.curTextureUnit) {
    512         diff_api.ActiveTextureARB( toCtx->texture.curTextureUnit + GL_TEXTURE0_ARB );
     515        pState->diff_api.ActiveTextureARB( toCtx->texture.curTextureUnit + GL_TEXTURE0_ARB );
    513516    }
    514     diff_api.MatrixMode(toCtx->transform.matrixMode);
     517    pState->diff_api.MatrixMode(toCtx->transform.matrixMode);
    515518}
    516519
     
    523526int crStateTextureCheckDirtyImages(CRContext *from, CRContext *to, GLenum target, int textureUnit)
    524527{
    525     CRContext *g         = GetCurrentContext();
     528    CRContext *g         = GetCurrentContext(from->pStateTracker);
    526529    CRTextureState *tsto;
    527530    CRbitvalue *bitID;
     
    532535    CRASSERT(to);
    533536    CRASSERT(from);
     537    CRASSERT(from->pStateTracker == to->pStateTracker);
    534538
    535539    tsto = &(to->texture);
     
    601605                         CRTextureObj *tobj, GLboolean alwaysDirty)
    602606{
     607    PCRStateTracker pState = fromCtx->pStateTracker;
    603608    CRTextureState *from = &(fromCtx->texture);
    604609    glAble able[2];
    605610    int u = 0; /* always use texture unit 0 for diff'ing */
    606     GLuint hwid = crStateGetTextureObjHWID(tobj);
     611    GLuint hwid = crStateGetTextureObjHWID(pState, tobj);
    607612
    608613    if (!hwid)
    609614        return;
    610615
    611     able[0] = diff_api.Disable;
    612     able[1] = diff_api.Enable;
     616    able[0] = pState->diff_api.Disable;
     617    able[1] = pState->diff_api.Enable;
    613618
    614619#if 0
     
    619624    /* Set active texture unit, and bind this texture object */
    620625    if (from->curTextureUnit != u) {
    621         diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
     626        pState->diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
    622627        from->curTextureUnit = u;
    623628    }
    624629#endif
    625630
    626     diff_api.BindTexture(tobj->target, hwid);
     631    pState->diff_api.BindTexture(tobj->target, hwid);
    627632
    628633    if (alwaysDirty || CHECKDIRTY(tobj->paramsBit[u], bitID))
     
    633638        f[2] = tobj->borderColor.b;
    634639        f[3] = tobj->borderColor.a;
    635         diff_api.TexParameteri(tobj->target, GL_TEXTURE_BASE_LEVEL, tobj->baseLevel);
    636         diff_api.TexParameteri(tobj->target, GL_TEXTURE_MAX_LEVEL, tobj->maxLevel);
    637         diff_api.TexParameteri(tobj->target, GL_TEXTURE_MIN_FILTER, tobj->minFilter);
    638         diff_api.TexParameteri(tobj->target, GL_TEXTURE_MAG_FILTER, tobj->magFilter);
    639         diff_api.TexParameteri(tobj->target, GL_TEXTURE_WRAP_S, tobj->wrapS);
    640         diff_api.TexParameteri(tobj->target, GL_TEXTURE_WRAP_T, tobj->wrapT);
     640        pState->diff_api.TexParameteri(tobj->target, GL_TEXTURE_BASE_LEVEL, tobj->baseLevel);
     641        pState->diff_api.TexParameteri(tobj->target, GL_TEXTURE_MAX_LEVEL, tobj->maxLevel);
     642        pState->diff_api.TexParameteri(tobj->target, GL_TEXTURE_MIN_FILTER, tobj->minFilter);
     643        pState->diff_api.TexParameteri(tobj->target, GL_TEXTURE_MAG_FILTER, tobj->magFilter);
     644        pState->diff_api.TexParameteri(tobj->target, GL_TEXTURE_WRAP_S, tobj->wrapS);
     645        pState->diff_api.TexParameteri(tobj->target, GL_TEXTURE_WRAP_T, tobj->wrapT);
    641646#ifdef CR_OPENGL_VERSION_1_2
    642         diff_api.TexParameteri(tobj->target, GL_TEXTURE_WRAP_R, tobj->wrapR);
    643         diff_api.TexParameterf(tobj->target, GL_TEXTURE_PRIORITY, tobj->priority);
    644 #endif
    645         diff_api.TexParameterfv(tobj->target, GL_TEXTURE_BORDER_COLOR, (const GLfloat *) f);
     647        pState->diff_api.TexParameteri(tobj->target, GL_TEXTURE_WRAP_R, tobj->wrapR);
     648        pState->diff_api.TexParameterf(tobj->target, GL_TEXTURE_PRIORITY, tobj->priority);
     649#endif
     650        pState->diff_api.TexParameterfv(tobj->target, GL_TEXTURE_BORDER_COLOR, (const GLfloat *) f);
    646651#ifdef CR_EXT_texture_filter_anisotropic
    647652        if (fromCtx->extensions.EXT_texture_filter_anisotropic) {
    648             diff_api.TexParameterf(tobj->target, GL_TEXTURE_MAX_ANISOTROPY_EXT, tobj->maxAnisotropy);
     653            pState->diff_api.TexParameterf(tobj->target, GL_TEXTURE_MAX_ANISOTROPY_EXT, tobj->maxAnisotropy);
    649654        }
    650655#endif
    651656#ifdef CR_ARB_depth_texture
    652657        if (fromCtx->extensions.ARB_depth_texture)
    653             diff_api.TexParameteri(tobj->target, GL_DEPTH_TEXTURE_MODE_ARB, tobj->depthMode);
     658            pState->diff_api.TexParameteri(tobj->target, GL_DEPTH_TEXTURE_MODE_ARB, tobj->depthMode);
    654659#endif
    655660#ifdef CR_ARB_shadow
    656661        if (fromCtx->extensions.ARB_shadow) {
    657             diff_api.TexParameteri(tobj->target, GL_TEXTURE_COMPARE_MODE_ARB, tobj->compareMode);
    658             diff_api.TexParameteri(tobj->target, GL_TEXTURE_COMPARE_FUNC_ARB, tobj->compareFunc);
     662            pState->diff_api.TexParameteri(tobj->target, GL_TEXTURE_COMPARE_MODE_ARB, tobj->compareMode);
     663            pState->diff_api.TexParameteri(tobj->target, GL_TEXTURE_COMPARE_FUNC_ARB, tobj->compareFunc);
    659664        }
    660665#endif
    661666#ifdef CR_ARB_shadow_ambient
    662667        if (fromCtx->extensions.ARB_shadow_ambient) {
    663             diff_api.TexParameterf(tobj->target, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, tobj->compareFailValue);
     668            pState->diff_api.TexParameterf(tobj->target, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, tobj->compareFailValue);
    664669        }
    665670#endif
    666671#ifdef CR_SGIS_generate_mipmap
    667672        if (fromCtx->extensions.SGIS_generate_mipmap) {
    668             diff_api.TexParameteri(tobj->target, GL_GENERATE_MIPMAP_SGIS, tobj->generateMipmap);
     673            pState->diff_api.TexParameteri(tobj->target, GL_GENERATE_MIPMAP_SGIS, tobj->generateMipmap);
    669674        }
    670675#endif
     
    688693                    {
    689694                        if (tl->generateMipmap) {
    690                             diff_api.TexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, 1);
     695                            pState->diff_api.TexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, 1);
    691696                        }
    692697                        if (tl->width)
    693698                        {
    694699                            if (tl->compressed) {
    695                                 diff_api.CompressedTexImage1DARB(GL_TEXTURE_1D, lvl,
     700                                pState->diff_api.CompressedTexImage1DARB(GL_TEXTURE_1D, lvl,
    696701                                                                 tl->internalFormat, tl->width,
    697702                                                                 tl->border, tl->bytes, tl->img);
     
    699704                            else {
    700705                                /* alignment must be one */
    701                                 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    702                                 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    703                                 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    704                                 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
     706                                pState->diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
     707                                pState->diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
     708                                pState->diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
     709                                pState->diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
    705710                                if (tl->generateMipmap) {
    706                                     diff_api.TexParameteri(GL_TEXTURE_1D, GL_GENERATE_MIPMAP_SGIS, 1);
     711                                    pState->diff_api.TexParameteri(GL_TEXTURE_1D, GL_GENERATE_MIPMAP_SGIS, 1);
    707712                                }
    708                                 diff_api.TexImage1D(GL_TEXTURE_1D, lvl,
     713                                pState->diff_api.TexImage1D(GL_TEXTURE_1D, lvl,
    709714                                                    tl->internalFormat,
    710715                                                    tl->width, tl->border,
     
    733738                    {
    734739                        if (tl->generateMipmap) {
    735                             diff_api.TexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, 1);
     740                            pState->diff_api.TexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, 1);
    736741                        }
    737742
     
    739744                        {
    740745                            if (tl->compressed) {
    741                                 diff_api.CompressedTexImage2DARB(GL_TEXTURE_2D, lvl,
     746                                pState->diff_api.CompressedTexImage2DARB(GL_TEXTURE_2D, lvl,
    742747                                         tl->internalFormat, tl->width,
    743748                                         tl->height, tl->border,
     
    746751                            else {
    747752                                /* alignment must be one */
    748                                 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    749                                 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    750                                 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    751                                 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
    752                                 diff_api.TexImage2D(GL_TEXTURE_2D, lvl,
     753                                pState->diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
     754                                pState->diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
     755                                pState->diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
     756                                pState->diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
     757                                pState->diff_api.TexImage2D(GL_TEXTURE_2D, lvl,
    753758                                                    tl->internalFormat,
    754759                                                    tl->width, tl->height, tl->border,
     
    779784                    {
    780785                        if (tl->generateMipmap) {
    781                             diff_api.TexParameteri(GL_TEXTURE_3D, GL_GENERATE_MIPMAP_SGIS, 1);
     786                            pState->diff_api.TexParameteri(GL_TEXTURE_3D, GL_GENERATE_MIPMAP_SGIS, 1);
    782787                        }
    783788
     
    785790                        {
    786791                            if (tl->compressed) {
    787                                 diff_api.CompressedTexImage3DARB(GL_TEXTURE_3D, lvl,
     792                                pState->diff_api.CompressedTexImage3DARB(GL_TEXTURE_3D, lvl,
    788793                                                                 tl->internalFormat, tl->width,
    789794                                                                 tl->height, tl->depth,
     
    792797                            else {
    793798                                /* alignment must be one */
    794                                 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    795                                 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    796                                 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    797                                 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
    798                                 diff_api.TexImage3D(GL_TEXTURE_3D, lvl,
     799                                pState->diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
     800                                pState->diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
     801                                pState->diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
     802                                pState->diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
     803                                pState->diff_api.TexImage3D(GL_TEXTURE_3D, lvl,
    799804                                                    tl->internalFormat,
    800805                                                    tl->width, tl->height, tl->depth,
     
    830835                        {
    831836                            if (tl->compressed) {
    832                                 diff_api.CompressedTexImage2DARB(GL_TEXTURE_RECTANGLE_NV, lvl,
     837                                pState->diff_api.CompressedTexImage2DARB(GL_TEXTURE_RECTANGLE_NV, lvl,
    833838                                                                 tl->internalFormat, tl->width,
    834839                                                                 tl->height, tl->border,
     
    837842                            else {
    838843                                /* alignment must be one */
    839                                 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    840                                 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    841                                 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    842                                 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
    843                                 diff_api.TexImage2D(GL_TEXTURE_RECTANGLE_NV, lvl,
     844                                pState->diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
     845                                pState->diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
     846                                pState->diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
     847                                pState->diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
     848                                pState->diff_api.TexImage2D(GL_TEXTURE_RECTANGLE_NV, lvl,
    844849                                                    tl->internalFormat,
    845850                                                    tl->width, tl->height, tl->border,
     
    874879                        {
    875880                            if (tl->generateMipmap) {
    876                                 diff_api.TexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
     881                                pState->diff_api.TexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
    877882                                                       GL_GENERATE_MIPMAP_SGIS, 1);
    878883                            }
     
    881886                            {
    882887                                if (tl->compressed) {
    883                                     diff_api.CompressedTexImage2DARB(target,
     888                                    pState->diff_api.CompressedTexImage2DARB(target,
    884889                                                                     lvl, tl->internalFormat,
    885890                                                                     tl->width, tl->height,
     
    888893                                else {
    889894                                    /* alignment must be one */
    890                                     diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    891                                     diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    892                                     diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    893                                     diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
    894                                     diff_api.TexImage2D(target, lvl,
     895                                    pState->diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
     896                                    pState->diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
     897                                    pState->diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
     898                                    pState->diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
     899                                    pState->diff_api.TexImage2D(target, lvl,
    895900                                                        tl->internalFormat,
    896901                                                        tl->width, tl->height, tl->border,
     
    928933                                        CRContext *fromCtx, CRContext *toCtx )
    929934{
     935    PCRStateTracker pState = fromCtx->pStateTracker;
    930936    CRTextureState *from = &(fromCtx->texture);
    931937    CRTextureState *to = &(toCtx->texture);
     
    935941    const GLboolean haveFragProg = fromCtx->extensions.ARB_fragment_program || fromCtx->extensions.NV_fragment_program;
    936942
     943    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     944
    937945    for (j=0;j<CR_MAX_BITARRAY;j++)
    938946        nbitID[j] = ~bitID[j];
    939947
    940     able[0] = diff_api.Disable;
    941     able[1] = diff_api.Enable;
     948    able[0] = pState->diff_api.Disable;
     949    able[1] = pState->diff_api.Enable;
    942950
    943951    /* loop over texture units */
     
    953961            /* Activate texture unit u if needed */
    954962            if (fromCtx->texture.curTextureUnit != u) {
    955                 diff_api.ActiveTextureARB( GL_TEXTURE0_ARB + u);
     963                pState->diff_api.ActiveTextureARB( GL_TEXTURE0_ARB + u);
    956964                fromCtx->texture.curTextureUnit = u;
    957965            }
     
    10111019        {
    10121020            if (fromCtx->texture.curTextureUnit != u) {
    1013                 diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
     1021                pState->diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
    10141022                fromCtx->texture.curTextureUnit = u;
    10151023            }
     
    10241032                f[2] = to->unit[u].objSCoeff.z;
    10251033                f[3] = to->unit[u].objSCoeff.w;
    1026                 diff_api.TexGenfv (GL_S, GL_OBJECT_PLANE, (const GLfloat *) f);
     1034                pState->diff_api.TexGenfv (GL_S, GL_OBJECT_PLANE, (const GLfloat *) f);
    10271035                from->unit[u].objSCoeff = to->unit[u].objSCoeff;
    10281036            }
     
    10371045                f[2] = to->unit[u].objTCoeff.z;
    10381046                f[3] = to->unit[u].objTCoeff.w;
    1039                 diff_api.TexGenfv (GL_T, GL_OBJECT_PLANE, (const GLfloat *) f);
     1047                pState->diff_api.TexGenfv (GL_T, GL_OBJECT_PLANE, (const GLfloat *) f);
    10401048                from->unit[u].objTCoeff = to->unit[u].objTCoeff;
    10411049            }
     
    10501058                f[2] = to->unit[u].objRCoeff.z;
    10511059                f[3] = to->unit[u].objRCoeff.w;
    1052                 diff_api.TexGenfv (GL_R, GL_OBJECT_PLANE, (const GLfloat *) f);
     1060                pState->diff_api.TexGenfv (GL_R, GL_OBJECT_PLANE, (const GLfloat *) f);
    10531061                from->unit[u].objRCoeff = to->unit[u].objRCoeff;
    10541062            }
     
    10631071                f[2] = to->unit[u].objQCoeff.z;
    10641072                f[3] = to->unit[u].objQCoeff.w;
    1065                 diff_api.TexGenfv (GL_Q, GL_OBJECT_PLANE, (const GLfloat *) f);
     1073                pState->diff_api.TexGenfv (GL_Q, GL_OBJECT_PLANE, (const GLfloat *) f);
    10661074                from->unit[u].objQCoeff = to->unit[u].objQCoeff;
    10671075            }
     
    10711079        {
    10721080            if (fromCtx->texture.curTextureUnit != u) {
    1073                 diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
     1081                pState->diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
    10741082                fromCtx->texture.curTextureUnit = u;
    10751083            }
    10761084            if (fromCtx->transform.matrixMode != GL_MODELVIEW) {
    1077                 diff_api.MatrixMode(GL_MODELVIEW);
     1085                pState->diff_api.MatrixMode(GL_MODELVIEW);
    10781086                fromCtx->transform.matrixMode = GL_MODELVIEW;
    10791087            }
    1080             diff_api.PushMatrix();
    1081             diff_api.LoadIdentity();
     1088            pState->diff_api.PushMatrix();
     1089            pState->diff_api.LoadIdentity();
    10821090            if (from->unit[u].eyeSCoeff.x != to->unit[u].eyeSCoeff.x ||
    10831091                    from->unit[u].eyeSCoeff.y != to->unit[u].eyeSCoeff.y ||
     
    10901098                f[2] = to->unit[u].eyeSCoeff.z;
    10911099                f[3] = to->unit[u].eyeSCoeff.w;
    1092                 diff_api.TexGenfv (GL_S, GL_EYE_PLANE, (const GLfloat *) f);
     1100                pState->diff_api.TexGenfv (GL_S, GL_EYE_PLANE, (const GLfloat *) f);
    10931101                from->unit[u].eyeSCoeff = to->unit[u].eyeSCoeff;
    10941102            }
     
    11031111                f[2] = to->unit[u].eyeTCoeff.z;
    11041112                f[3] = to->unit[u].eyeTCoeff.w;
    1105                 diff_api.TexGenfv (GL_T, GL_EYE_PLANE, (const GLfloat *) f);
     1113                pState->diff_api.TexGenfv (GL_T, GL_EYE_PLANE, (const GLfloat *) f);
    11061114                from->unit[u].eyeTCoeff = to->unit[u].eyeTCoeff;
    11071115            }
     
    11161124                f[2] = to->unit[u].eyeRCoeff.z;
    11171125                f[3] = to->unit[u].eyeRCoeff.w;
    1118                 diff_api.TexGenfv (GL_R, GL_EYE_PLANE, (const GLfloat *) f);
     1126                pState->diff_api.TexGenfv (GL_R, GL_EYE_PLANE, (const GLfloat *) f);
    11191127                from->unit[u].eyeRCoeff = to->unit[u].eyeRCoeff;
    11201128            }
     
    11291137                f[2] = to->unit[u].eyeQCoeff.z;
    11301138                f[3] = to->unit[u].eyeQCoeff.w;
    1131                 diff_api.TexGenfv (GL_Q, GL_EYE_PLANE, (const GLfloat *) f);
     1139                pState->diff_api.TexGenfv (GL_Q, GL_EYE_PLANE, (const GLfloat *) f);
    11321140                from->unit[u].eyeQCoeff = to->unit[u].eyeQCoeff;
    11331141            }
    1134             diff_api.PopMatrix();
     1142            pState->diff_api.PopMatrix();
    11351143            CLEARDIRTY(tb->eyeGen[u], nbitID);
    11361144        }
     
    11381146        {
    11391147            if (fromCtx->texture.curTextureUnit != u) {
    1140                 diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
     1148                pState->diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
    11411149                fromCtx->texture.curTextureUnit = u;
    11421150            }
     
    11461154                    from->unit[u].gen.q != to->unit[u].gen.q)
    11471155            {
    1148                 diff_api.TexGeni (GL_S, GL_TEXTURE_GEN_MODE, to->unit[u].gen.s);
    1149                 diff_api.TexGeni (GL_T, GL_TEXTURE_GEN_MODE, to->unit[u].gen.t);
    1150                 diff_api.TexGeni (GL_R, GL_TEXTURE_GEN_MODE, to->unit[u].gen.r);
    1151                 diff_api.TexGeni (GL_Q, GL_TEXTURE_GEN_MODE, to->unit[u].gen.q);   
     1156                pState->diff_api.TexGeni (GL_S, GL_TEXTURE_GEN_MODE, to->unit[u].gen.s);
     1157                pState->diff_api.TexGeni (GL_T, GL_TEXTURE_GEN_MODE, to->unit[u].gen.t);
     1158                pState->diff_api.TexGeni (GL_R, GL_TEXTURE_GEN_MODE, to->unit[u].gen.r);
     1159                pState->diff_api.TexGeni (GL_Q, GL_TEXTURE_GEN_MODE, to->unit[u].gen.q);   
    11521160                from->unit[u].gen = to->unit[u].gen;
    11531161            }
     
    11601168            if (from->unit[u].envMode != to->unit[u].envMode)
    11611169            {
    1162                 diff_api.TexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, to->unit[u].envMode);
     1170                pState->diff_api.TexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, to->unit[u].envMode);
    11631171                from->unit[u].envMode = to->unit[u].envMode;
    11641172            }
     
    11731181                f[2] = to->unit[u].envColor.b;
    11741182                f[3] = to->unit[u].envColor.a;
    1175                 diff_api.TexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, (const GLfloat *) f);
     1183                pState->diff_api.TexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, (const GLfloat *) f);
    11761184                from->unit[u].envColor = to->unit[u].envColor;
    11771185            }
     
    11791187            if (from->unit[u].combineModeRGB != to->unit[u].combineModeRGB)
    11801188            {
    1181                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, to->unit[u].combineModeRGB);
     1189                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, to->unit[u].combineModeRGB);
    11821190                from->unit[u].combineModeRGB = to->unit[u].combineModeRGB;
    11831191            }
    11841192            if (from->unit[u].combineModeA != to->unit[u].combineModeA)
    11851193            {
    1186                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, to->unit[u].combineModeA);
     1194                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, to->unit[u].combineModeA);
    11871195                from->unit[u].combineModeA = to->unit[u].combineModeA;
    11881196            }
    11891197            if (from->unit[u].combineSourceRGB[0] != to->unit[u].combineSourceRGB[0])
    11901198            {
    1191                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, to->unit[u].combineSourceRGB[0]);
     1199                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, to->unit[u].combineSourceRGB[0]);
    11921200                from->unit[u].combineSourceRGB[0] = to->unit[u].combineSourceRGB[0];
    11931201            }
    11941202            if (from->unit[u].combineSourceRGB[1] != to->unit[u].combineSourceRGB[1])
    11951203            {
    1196                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, to->unit[u].combineSourceRGB[1]);
     1204                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, to->unit[u].combineSourceRGB[1]);
    11971205                from->unit[u].combineSourceRGB[1] = to->unit[u].combineSourceRGB[1];
    11981206            }
    11991207            if (from->unit[u].combineSourceRGB[2] != to->unit[u].combineSourceRGB[2])
    12001208            {
    1201                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, to->unit[u].combineSourceRGB[2]);
     1209                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, to->unit[u].combineSourceRGB[2]);
    12021210                from->unit[u].combineSourceRGB[2] = to->unit[u].combineSourceRGB[2];
    12031211            }
    12041212            if (from->unit[u].combineSourceA[0] != to->unit[u].combineSourceA[0])
    12051213            {
    1206                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, to->unit[u].combineSourceA[0]);
     1214                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, to->unit[u].combineSourceA[0]);
    12071215                from->unit[u].combineSourceA[0] = to->unit[u].combineSourceA[0];
    12081216            }
    12091217            if (from->unit[u].combineSourceA[1] != to->unit[u].combineSourceA[1])
    12101218            {
    1211                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, to->unit[u].combineSourceA[1]);
     1219                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, to->unit[u].combineSourceA[1]);
    12121220                from->unit[u].combineSourceA[1] = to->unit[u].combineSourceA[1];
    12131221            }
    12141222            if (from->unit[u].combineSourceA[2] != to->unit[u].combineSourceA[2])
    12151223            {
    1216                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, to->unit[u].combineSourceA[2]);
     1224                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, to->unit[u].combineSourceA[2]);
    12171225                from->unit[u].combineSourceA[2] = to->unit[u].combineSourceA[2];
    12181226            }
    12191227            if (from->unit[u].combineOperandRGB[0] != to->unit[u].combineOperandRGB[0])
    12201228            {
    1221                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, to->unit[u].combineOperandRGB[0]);
     1229                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, to->unit[u].combineOperandRGB[0]);
    12221230                from->unit[u].combineOperandRGB[0] = to->unit[u].combineOperandRGB[0];
    12231231            }
    12241232            if (from->unit[u].combineOperandRGB[1] != to->unit[u].combineOperandRGB[1])
    12251233            {
    1226                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, to->unit[u].combineOperandRGB[1]);
     1234                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, to->unit[u].combineOperandRGB[1]);
    12271235                from->unit[u].combineOperandRGB[1] = to->unit[u].combineOperandRGB[1];
    12281236            }
    12291237            if (from->unit[u].combineOperandRGB[2] != to->unit[u].combineOperandRGB[2])
    12301238            {
    1231                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, to->unit[u].combineOperandRGB[2]);
     1239                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, to->unit[u].combineOperandRGB[2]);
    12321240                from->unit[u].combineOperandRGB[2] = to->unit[u].combineOperandRGB[2];
    12331241            }
    12341242            if (from->unit[u].combineOperandA[0] != to->unit[u].combineOperandA[0])
    12351243            {
    1236                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, to->unit[u].combineOperandA[0]);
     1244                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, to->unit[u].combineOperandA[0]);
    12371245                from->unit[u].combineOperandA[0] = to->unit[u].combineOperandA[0];
    12381246            }
    12391247            if (from->unit[u].combineOperandA[1] != to->unit[u].combineOperandA[1])
    12401248            {
    1241                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, to->unit[u].combineOperandA[1]);
     1249                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, to->unit[u].combineOperandA[1]);
    12421250                from->unit[u].combineOperandA[1] = to->unit[u].combineOperandA[1];
    12431251            }
    12441252            if (from->unit[u].combineOperandA[2] != to->unit[u].combineOperandA[2])
    12451253            {
    1246                 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, to->unit[u].combineOperandA[2]);
     1254                pState->diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, to->unit[u].combineOperandA[2]);
    12471255                from->unit[u].combineOperandA[2] = to->unit[u].combineOperandA[2];
    12481256            }
    12491257            if (from->unit[u].combineScaleRGB != to->unit[u].combineScaleRGB)
    12501258            {
    1251                 diff_api.TexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, to->unit[u].combineScaleRGB);
     1259                pState->diff_api.TexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, to->unit[u].combineScaleRGB);
    12521260                from->unit[u].combineScaleRGB = to->unit[u].combineScaleRGB;
    12531261            }
    12541262            if (from->unit[u].combineScaleA != to->unit[u].combineScaleA)
    12551263            {
    1256                 diff_api.TexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, to->unit[u].combineScaleA);
     1264                pState->diff_api.TexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, to->unit[u].combineScaleA);
    12571265                from->unit[u].combineScaleA = to->unit[u].combineScaleA;
    12581266            }
     
    12611269            if (from->unit[u].lodBias != to->unit[u].lodBias)
    12621270            {
    1263                 diff_api.TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, to->unit[u].lodBias);
     1271                pState->diff_api.TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, to->unit[u].lodBias);
    12641272                from->unit[u].lodBias = to->unit[u].lodBias;
    12651273            }
     
    13231331            /* Activate texture unit u if needed */
    13241332            if (fromCtx->texture.curTextureUnit != u) {
    1325                 diff_api.ActiveTextureARB( GL_TEXTURE0_ARB + u);
     1333                pState->diff_api.ActiveTextureARB( GL_TEXTURE0_ARB + u);
    13261334                fromCtx->texture.curTextureUnit = u;
    13271335            }
     
    13321340                if (*fromBinding != tobj)
    13331341                {
    1334                     diff_api.BindTexture(tobj->target, crStateGetTextureObjHWID(tobj));
     1342                    pState->diff_api.BindTexture(tobj->target, crStateGetTextureObjHWID(pState, tobj));
    13351343                    *fromBinding = tobj;
    13361344                }
     
    13521360    /* After possible fiddling with the active unit, put it back now */
    13531361    if (fromCtx->texture.curTextureUnit != toCtx->texture.curTextureUnit) {
    1354         diff_api.ActiveTextureARB( toCtx->texture.curTextureUnit + GL_TEXTURE0_ARB );
     1362        pState->diff_api.ActiveTextureARB( toCtx->texture.curTextureUnit + GL_TEXTURE0_ARB );
    13551363        fromCtx->texture.curTextureUnit = toCtx->texture.curTextureUnit;
    13561364    }
    13571365    if (fromCtx->transform.matrixMode != toCtx->transform.matrixMode) {
    1358         diff_api.MatrixMode(toCtx->transform.matrixMode);
     1366        pState->diff_api.MatrixMode(toCtx->transform.matrixMode);
    13591367        fromCtx->transform.matrixMode = toCtx->transform.matrixMode;
    13601368    }
     
    14041412crStateDiffAllTextureObjects( CRContext *g, CRbitvalue *bitID, GLboolean bForceUpdate )
    14051413{
     1414    PCRStateTracker pState = g->pStateTracker;
    14061415    CRbitvalue nbitID[CR_MAX_BITARRAY];
    14071416    struct callback_info info;
     
    14191428    /* save current texture bindings */
    14201429    origUnit = g->texture.curTextureUnit;
    1421     orig1D = crStateGetTextureObjHWID(g->texture.unit[0].currentTexture1D);
    1422     orig2D = crStateGetTextureObjHWID(g->texture.unit[0].currentTexture2D);
    1423     orig3D = crStateGetTextureObjHWID(g->texture.unit[0].currentTexture3D);
     1430    orig1D = crStateGetTextureObjHWID(pState, g->texture.unit[0].currentTexture1D);
     1431    orig2D = crStateGetTextureObjHWID(pState, g->texture.unit[0].currentTexture2D);
     1432    orig3D = crStateGetTextureObjHWID(pState, g->texture.unit[0].currentTexture3D);
    14241433#ifdef CR_ARB_texture_cube_map
    1425     origCube = crStateGetTextureObjHWID(g->texture.unit[0].currentTextureCubeMap);
     1434    origCube = crStateGetTextureObjHWID(pState, g->texture.unit[0].currentTextureCubeMap);
    14261435#endif
    14271436#ifdef CR_NV_texture_rectangle
    1428     origRect = crStateGetTextureObjHWID(g->texture.unit[0].currentTextureRect);
     1437    origRect = crStateGetTextureObjHWID(pState, g->texture.unit[0].currentTextureRect);
    14291438#endif
    14301439
    14311440    /* use texture unit 0 for updates */
    1432     diff_api.ActiveTextureARB(GL_TEXTURE0_ARB);
     1441    pState->diff_api.ActiveTextureARB(GL_TEXTURE0_ARB);
    14331442
    14341443    /* diff all the textures */
     
    14561465    /* restore bindings */
    14571466    /* first restore unit 0 bindings the unit 0 is active currently */
    1458     diff_api.BindTexture(GL_TEXTURE_1D, orig1D);
    1459     diff_api.BindTexture(GL_TEXTURE_2D, orig2D);
    1460     diff_api.BindTexture(GL_TEXTURE_3D, orig3D);
     1467    pState->diff_api.BindTexture(GL_TEXTURE_1D, orig1D);
     1468    pState->diff_api.BindTexture(GL_TEXTURE_2D, orig2D);
     1469    pState->diff_api.BindTexture(GL_TEXTURE_3D, orig3D);
    14611470#ifdef CR_ARB_texture_cube_map
    1462     diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, origCube);
     1471    pState->diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, origCube);
    14631472#endif
    14641473#ifdef CR_NV_texture_rectangle
    1465     diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, origRect);
     1474    pState->diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, origRect);
    14661475#endif
    14671476    /* now restore the proper active unit */
    1468     diff_api.ActiveTextureARB(GL_TEXTURE0_ARB + origUnit);
     1477    pState->diff_api.ActiveTextureARB(GL_TEXTURE0_ARB + origUnit);
    14691478}
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_teximage.c

    r78105 r78375  
    335335 */
    336336static GLboolean
    337 ErrorCheckTexImage(GLuint dims, GLenum target, GLint level,
     337ErrorCheckTexImage(PCRStateTracker pState, GLuint dims, GLenum target, GLint level,
    338338                                     GLsizei width, GLsizei height, GLsizei depth, GLint border)
    339339{
    340     CRContext *g = GetCurrentContext();
     340    CRContext *g = GetCurrentContext(pState);
    341341
    342342    if (g->current.inBeginEnd)
    343343    {
    344         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     344        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    345345                                 "glTexImage%uD called in Begin/End", dims);
    346346        return GL_TRUE;
     
    355355        case GL_PROXY_TEXTURE_1D:
    356356            if (dims != 1) {
    357                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     357                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    358358                                         "glTexImage(invalid target=0x%x)", target);
    359359                return GL_TRUE;
     
    363363        case GL_PROXY_TEXTURE_2D:
    364364            if (dims != 2) {
    365                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     365                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    366366                                         "glTexImage(invalid target=0x%x)", target);
    367367                return GL_TRUE;
     
    371371        case GL_PROXY_TEXTURE_3D:
    372372            if (dims != 3) {
    373                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     373                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    374374                                         "glTexImage(invalid target=0x%x)", target);
    375375                return GL_TRUE;
     
    380380        case GL_PROXY_TEXTURE_RECTANGLE_NV:
    381381            if (dims != 2 || !g->extensions.NV_texture_rectangle) {
    382                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     382                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    383383                                         "glTexImage2D(invalid target=0x%x)", target);
    384384                return GL_TRUE;
     
    395395        case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
    396396            if (dims != 2 || !g->extensions.ARB_texture_cube_map) {
    397                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     397                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    398398                                         "glTexImage2D(invalid target=0x%x)", target);
    399399                return GL_TRUE;
     
    402402#endif
    403403        default:
    404             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     404            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    405405                                     "glTexImage%uD(invalid target=0x%x)", dims, target);
    406406            return GL_TRUE;
     
    412412    if (level < 0 || level > MaxTextureLevel(g, target)) {
    413413        if (!IsProxyTarget(target))
    414             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     414            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    415415                                     "glTexImage%uD(level=%d)", dims, level);
    416416        return GL_TRUE;
     
    422422    if (border != 0 && border != 1) {
    423423        if (!IsProxyTarget(target))
    424             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     424            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    425425                                     "glTexImage%uD(border=%d)", dims, border);
    426426        return GL_TRUE;
     
    430430             target == GL_TEXTURE_RECTANGLE_NV) && border != 0) {
    431431        if (!IsProxyTarget(target))
    432             crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     432            crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    433433                                     "glTexImage2D(border=%d)", border);
    434434        return GL_TRUE;
     
    441441        if (!isLegalSize(g, width - 2 * border, g->limits.maxTextureSize)) {
    442442            if (!IsProxyTarget(target))
    443                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     443                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    444444                                         "glTexImage1D(width=%d)", width);
    445445            return GL_TRUE;
     
    450450                !isLegalSize(g, height - 2 * border, g->limits.maxTextureSize)) {
    451451            if (!IsProxyTarget(target))
    452                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     452                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    453453                                         "glTexImage2D(width=%d, height=%d)", width, height);
    454454            return GL_TRUE;
     
    460460                !isLegalSize(g, depth - 2 * border, g->limits.max3DTextureSize)) {
    461461            if (!IsProxyTarget(target))
    462                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     462                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    463463                                         "glTexImage3D(width=%d, height=%d, depth=%d)",
    464464                                         width, height, depth);
     
    471471                height < 0 || height > (int) g->limits.maxRectTextureSize) {
    472472            if (!IsProxyTarget(target))
    473                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     473                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    474474                                         "glTexImage2D(width=%d, height=%d)", width, height);
    475475            return GL_TRUE;
     
    482482                width != height) {
    483483            if (!IsProxyTarget(target))
    484                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     484                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    485485                                         "glTexImage2D(width=%d, height=%d)", width, height);
    486486            return GL_TRUE;
     
    499499 */
    500500static GLboolean
    501 ErrorCheckTexSubImage(GLuint dims, GLenum target, GLint level,
     501ErrorCheckTexSubImage(PCRStateTracker pState, GLuint dims, GLenum target, GLint level,
    502502                                            GLint xoffset, GLint yoffset, GLint zoffset,
    503503                                            GLsizei width, GLsizei height, GLsizei depth)
    504504{
    505     CRContext *g = GetCurrentContext();
     505    CRContext *g = GetCurrentContext(pState);
    506506    CRTextureObj *tobj;
    507507    CRTextureLevel *tl;
    508508
    509509    if (g->current.inBeginEnd) {
    510         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     510        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    511511                                 "glTexSubImage%uD called in Begin/End", dims);
    512512        return GL_TRUE;
     
    515515    if (dims == 1) {
    516516        if (target != GL_TEXTURE_1D) {
    517             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     517            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    518518                                     "glTexSubImage1D(target=0x%x)", target);
    519519            return GL_TRUE;
     
    529529                target != GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB &&
    530530                target != GL_TEXTURE_RECTANGLE_NV) {
    531             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     531            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    532532                                     "glTexSubImage2D(target=0x%x)", target);
    533533            return GL_TRUE;
     
    536536    else if (dims == 3) {
    537537        if (target != GL_TEXTURE_3D) {
    538             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     538            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    539539                                     "glTexSubImage3D(target=0x%x)", target);
    540540            return GL_TRUE;
     
    544544    /* test level */
    545545    if (level < 0 || level > MaxTextureLevel(g, target)) {
    546         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     546        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    547547                                 "glTexSubImage%uD(level=%d)", dims, level);
    548548        return GL_TRUE;
     
    551551    crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl);
    552552    if (!tobj || !tl) {
    553         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     553        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    554554                                 "glTexSubImage%uD(target or level)", dims);
    555555        return GL_TRUE;
     
    558558    /* test x/y/zoffset and size */
    559559    if (xoffset < -tl->border || xoffset + width > tl->width) {
    560         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     560        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    561561                                 "glTexSubImage%uD(xoffset=%d + width=%d > %d)",
    562562                                 dims, xoffset, width, tl->width);
     
    564564    }
    565565    if (dims > 1 && (yoffset < -tl->border || yoffset + height > tl->height)) {
    566         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     566        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    567567                                 "glTexSubImage%uD(yoffset=%d + height=%d > %d)",
    568568                                 dims, yoffset, height, tl->height);
     
    570570    }
    571571    if (dims > 2 && (zoffset < -tl->border || zoffset + depth > tl->depth)) {
    572         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     572        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    573573                                 "glTexSubImage%uD(zoffset=%d and/or depth=%d)",
    574574                                 dims, zoffset, depth);
     
    583583
    584584void STATE_APIENTRY
    585 crStateTexImage1D(GLenum target, GLint level, GLint internalFormat,
     585crStateTexImage1D(PCRStateTracker pState, GLenum target, GLint level, GLint internalFormat,
    586586                                    GLsizei width, GLint border, GLenum format,
    587587                                    GLenum type, const GLvoid * pixels)
    588588{
    589     CRContext *g = GetCurrentContext();
     589    CRContext *g = GetCurrentContext(pState);
    590590    CRTextureState *t = &(g->texture);
    591591#ifndef CR_STATE_NO_TEXTURE_IMAGE_STORE
     
    594594    CRTextureObj *tobj;
    595595    CRTextureLevel *tl;
    596     CRStateBits *sb = GetCurrentBits();
     596    CRStateBits *sb = GetCurrentBits(pState);
    597597    CRTextureBits *tb = &(sb->texture);
    598598#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
     
    602602    FLUSH();
    603603
    604     if (ErrorCheckTexImage(1, target, level, width, 1, 1, border)) {
     604    if (ErrorCheckTexImage(pState, 1, target, level, width, 1, 1, border)) {
    605605        if (IsProxyTarget(target)) {
    606606            /* clear all state, but don't generate error */
     
    631631        if (!tl->img)
    632632        {
    633             crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY,
     633            crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY,
    634634                         "glTexImage1D out of memory");
    635635            return;
    636636        }
    637637        if (pixels)
    638             crPixelCopy1D((GLvoid *) tl->img, format, type,
     638            crPixelCopy1D(pState, (GLvoid *) tl->img, format, type,
    639639                          pixels, format, type, width, &(c->unpack));
    640640    }
     
    699699
    700700void STATE_APIENTRY
    701 crStateCopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
    702 {
    703     CRContext *g = GetCurrentContext();
     701crStateCopyTexImage2D(PCRStateTracker pState, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
     702{
     703    CRContext *g = GetCurrentContext(pState);
    704704    CRTextureObj *tobj = NULL;
    705705    CRTextureLevel *tl = NULL;
     
    707707
    708708    if (level < 0 || level > MaxTextureLevel(g, target)) {
    709         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     709        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    710710                     "crStateCopyTexImage2D: invalid level: %d", level);
    711711        return;
     
    718718    if (tobj == NULL || tl == NULL)
    719719    {
    720         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     720        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    721721                     "crStateCopyTexImage2D: invalid target: 0x%x", target);
    722722        return;
     
    754754
    755755void STATE_APIENTRY
    756 crStateTexImage2D(GLenum target, GLint level, GLint internalFormat,
     756crStateTexImage2D(PCRStateTracker pState, GLenum target, GLint level, GLint internalFormat,
    757757                  GLsizei width, GLsizei height, GLint border,
    758758                  GLenum format, GLenum type, const GLvoid * pixels)
    759759{
    760     CRContext *g = GetCurrentContext();
     760    CRContext *g = GetCurrentContext(pState);
    761761    CRTextureState *t = &(g->texture);
    762762#ifndef CR_STATE_NO_TEXTURE_IMAGE_STORE
     
    765765    CRTextureObj *tobj = NULL;
    766766    CRTextureLevel *tl = NULL;
    767     CRStateBits *sb = GetCurrentBits();
     767    CRStateBits *sb = GetCurrentBits(pState);
    768768    CRTextureBits *tb = &(sb->texture);
    769769    // Distributed textures are not used by VBox
     
    776776     */
    777777    if (!is_distrib
    778             && ErrorCheckTexImage(2, target, level, width, height, 1, border)) {
     778            && ErrorCheckTexImage(pState, 2, target, level, width, height, 1, border)) {
    779779        if (IsProxyTarget(target)) {
    780780            /* clear all state, but don't generate error */
     
    818818        if (!tl->img)
    819819        {
    820             crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY,
     820            crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY,
    821821                         "glTexImage2D out of memory");
    822822            return;
     
    892892#if defined( CR_OPENGL_VERSION_1_2 ) || defined( GL_EXT_texture3D )
    893893void STATE_APIENTRY
    894 crStateTexImage3D(GLenum target, GLint level,
     894crStateTexImage3D(PCRStateTracker pState, GLenum target, GLint level,
    895895                                    GLint internalFormat,
    896896                                    GLsizei width, GLsizei height,
     
    898898                                    GLenum format, GLenum type, const GLvoid * pixels)
    899899{
    900     CRContext *g = GetCurrentContext();
     900    CRContext *g = GetCurrentContext(pState);
    901901    CRTextureState *t = &(g->texture);
    902902#ifndef CR_STATE_NO_TEXTURE_IMAGE_STORE
     
    905905    CRTextureObj *tobj = NULL;
    906906    CRTextureLevel *tl = NULL;
    907     CRStateBits *sb = GetCurrentBits();
     907    CRStateBits *sb = GetCurrentBits(pState);
    908908    CRTextureBits *tb = &(sb->texture);
    909909    (void)pixels;
     
    911911    FLUSH();
    912912
    913     if (ErrorCheckTexImage(3, target, level, width, height, depth, border)) {
     913    if (ErrorCheckTexImage(pState, 3, target, level, width, height, depth, border)) {
    914914        if (IsProxyTarget(target)) {
    915915            /* clear all state, but don't generate error */
     
    940940        if (!tl->img)
    941941        {
    942             crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY,
     942            crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY,
    943943                         "glTexImage3D out of memory");
    944944            return;
     
    979979#ifdef GL_EXT_texture3D
    980980void STATE_APIENTRY
    981 crStateTexImage3DEXT(GLenum target, GLint level,
     981crStateTexImage3DEXT(PCRStateTracker pState, GLenum target, GLint level,
    982982                                         GLenum internalFormat,
    983983                                         GLsizei width, GLsizei height, GLsizei depth,
     
    985985                                         const GLvoid * pixels)
    986986{
    987     crStateTexImage3D(target, level, (GLint) internalFormat, width, height,
     987    crStateTexImage3D(pState, target, level, (GLint) internalFormat, width, height,
    988988                                        depth, border, format, type, pixels);
    989989}
     
    992992
    993993void STATE_APIENTRY
    994 crStateTexSubImage1D(GLenum target, GLint level, GLint xoffset,
     994crStateTexSubImage1D(PCRStateTracker pState, GLenum target, GLint level, GLint xoffset,
    995995                                         GLsizei width, GLenum format,
    996996                                         GLenum type, const GLvoid * pixels)
    997997{
    998     CRContext *g = GetCurrentContext();
     998    CRContext *g = GetCurrentContext(pState);
    999999    CRTextureState *t = &(g->texture);
    10001000#ifndef CR_STATE_NO_TEXTURE_IMAGE_STORE
    10011001    CRClientState *c = &(g->client);
    10021002#endif
    1003     CRStateBits *sb = GetCurrentBits();
     1003    CRStateBits *sb = GetCurrentBits(pState);
    10041004    CRTextureBits *tb = &(sb->texture);
    10051005    CRTextureUnit *unit = t->unit + t->curTextureUnit;
     
    10101010    FLUSH();
    10111011
    1012     if (ErrorCheckTexSubImage(1, target, level, xoffset, 0, 0,
     1012    if (ErrorCheckTexSubImage(pState, 1, target, level, xoffset, 0, 0,
    10131013                                                        width, 1, 1)) {
    10141014        return; /* GL error state already set */
     
    10251025    xoffset += tl->border;
    10261026
    1027     crPixelCopy1D((void *) (tl->img + xoffset * tl->bytesPerPixel),
     1027    crPixelCopy1D(pState, (void *) (tl->img + xoffset * tl->bytesPerPixel),
    10281028                  tl->format, tl->type,
    10291029                  pixels, format, type, width, &(c->unpack));
     
    10471047
    10481048void STATE_APIENTRY
    1049 crStateTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
     1049crStateTexSubImage2D(PCRStateTracker pState, GLenum target, GLint level, GLint xoffset, GLint yoffset,
    10501050                     GLsizei width, GLsizei height,
    10511051                     GLenum format, GLenum type, const GLvoid * pixels)
    10521052{
    1053     CRContext *g = GetCurrentContext();
    1054     CRStateBits *sb = GetCurrentBits();
     1053    CRContext *g = GetCurrentContext(pState);
     1054    CRStateBits *sb = GetCurrentBits(pState);
    10551055    CRTextureBits *tb = &(sb->texture);
    10561056    CRTextureObj *tobj;
     
    10671067    FLUSH();
    10681068
    1069     if (ErrorCheckTexSubImage(2, target, level, xoffset, yoffset, 0,
     1069    if (ErrorCheckTexSubImage(pState, 2, target, level, xoffset, yoffset, 0,
    10701070                                                        width, height, 1)) {
    10711071        return; /* GL error state already set */
     
    10891089    subimg = (GLubyte *) crAlloc(crImageSize(tl->format, tl->type, width, height));
    10901090
    1091     crPixelCopy2D(width, height, subimg, tl->format, tl->type, NULL,    /* dst */
     1091    crPixelCopy2D(pState, width, height, subimg, tl->format, tl->type, NULL,    /* dst */
    10921092                  pixels, format, type, &(c->unpack));                  /* src */
    10931093
     
    11271127        char *data;
    11281128
    1129         diff_api.GetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &w);
    1130         diff_api.GetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &h);
     1129        pState->diff_api.GetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &w);
     1130        pState->diff_api.GetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &h);
    11311131
    11321132        data = crAlloc(w*h*4);
     
    11411141#if defined( CR_OPENGL_VERSION_1_2 )
    11421142void STATE_APIENTRY
    1143 crStateTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
     1143crStateTexSubImage3D(PCRStateTracker pState, GLenum target, GLint level, GLint xoffset, GLint yoffset,
    11441144                                         GLint zoffset, GLsizei width, GLsizei height,
    11451145                                         GLsizei depth, GLenum format, GLenum type,
    11461146                                         const GLvoid * pixels)
    11471147{
    1148     CRContext *g = GetCurrentContext();
     1148    CRContext *g = GetCurrentContext(pState);
    11491149    CRTextureState *t = &(g->texture);
    1150     CRStateBits *sb = GetCurrentBits();
     1150    CRStateBits *sb = GetCurrentBits(pState);
    11511151    CRTextureBits *tb = &(sb->texture);
    11521152    CRTextureUnit *unit = t->unit + t->curTextureUnit;
     
    11641164    FLUSH();
    11651165
    1166     if (ErrorCheckTexSubImage(3, target, level, xoffset, yoffset, zoffset,
     1166    if (ErrorCheckTexSubImage(pState, 3, target, level, xoffset, yoffset, zoffset,
    11671167                                                        width, height, depth)) {
    11681168        return; /* GL error state already set */
     
    11861186        crAlloc(crTextureSize(tl->format, tl->type, width, height, depth));
    11871187
    1188     crPixelCopy3D(width, height, depth, subimg, tl->format, tl->type, NULL,
     1188    crPixelCopy3D(pState, width, height, depth, subimg, tl->format, tl->type, NULL,
    11891189                  pixels, format, type, &(c->unpack));
    11901190
     
    12241224
    12251225void STATE_APIENTRY
    1226 crStateCompressedTexImage1DARB(GLenum target, GLint level,
     1226crStateCompressedTexImage1DARB(PCRStateTracker pState, GLenum target, GLint level,
    12271227                                                             GLenum internalFormat, GLsizei width,
    12281228                                                             GLint border, GLsizei imageSize,
    12291229                                                             const GLvoid * data)
    12301230{
    1231     CRContext *g = GetCurrentContext();
     1231    CRContext *g = GetCurrentContext(pState);
    12321232    CRTextureState *t = &(g->texture);
    12331233    CRTextureObj *tobj;
    12341234    CRTextureLevel *tl;
    1235     CRStateBits *sb = GetCurrentBits();
     1235    CRStateBits *sb = GetCurrentBits(pState);
    12361236    CRTextureBits *tb = &(sb->texture);
    12371237    (void)data;
     
    12391239    FLUSH();
    12401240
    1241     if (ErrorCheckTexImage(1, target, level, width, 1, 1, border)) {
     1241    if (ErrorCheckTexImage(pState, 1, target, level, width, 1, 1, border)) {
    12421242        if (IsProxyTarget(target)) {
    12431243            /* clear all state, but don't generate error */
     
    12681268        if (!tl->img)
    12691269        {
    1270             crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY,
     1270            crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY,
    12711271                         "glTexImage1D out of memory");
    12721272            return;
     
    13051305
    13061306void STATE_APIENTRY
    1307 crStateCompressedTexImage2DARB(GLenum target, GLint level,
     1307crStateCompressedTexImage2DARB(PCRStateTracker pState, GLenum target, GLint level,
    13081308                               GLenum internalFormat, GLsizei width,
    13091309                               GLsizei height, GLint border,
    13101310                               GLsizei imageSize, const GLvoid * data)
    13111311{
    1312     CRContext *g = GetCurrentContext();
     1312    CRContext *g = GetCurrentContext(pState);
    13131313    CRTextureState *t = &(g->texture);
    13141314    CRTextureObj *tobj = NULL;
    13151315    CRTextureLevel *tl = NULL;
    1316     CRStateBits *sb = GetCurrentBits();
     1316    CRStateBits *sb = GetCurrentBits(pState);
    13171317    CRTextureBits *tb = &(sb->texture);
    13181318    (void)data;
     
    13201320    FLUSH();
    13211321
    1322     if (ErrorCheckTexImage(2, target, level, width, height, 1, border)) {
     1322    if (ErrorCheckTexImage(pState, 2, target, level, width, height, 1, border)) {
    13231323        if (IsProxyTarget(target)) {
    13241324            /* clear all state, but don't generate error */
     
    13491349        if (!tl->img)
    13501350        {
    1351             crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY,
     1351            crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY,
    13521352                         "glTexImage2D out of memory");
    13531353            return;
     
    13871387
    13881388void STATE_APIENTRY
    1389 crStateCompressedTexImage3DARB(GLenum target, GLint level,
     1389crStateCompressedTexImage3DARB(PCRStateTracker pState, GLenum target, GLint level,
    13901390                                                             GLenum internalFormat, GLsizei width,
    13911391                                                             GLsizei height, GLsizei depth, GLint border,
    13921392                                                             GLsizei imageSize, const GLvoid * data)
    13931393{
    1394     CRContext *g = GetCurrentContext();
     1394    CRContext *g = GetCurrentContext(pState);
    13951395    CRTextureState *t = &(g->texture);
    13961396    CRTextureObj *tobj = NULL;
    13971397    CRTextureLevel *tl = NULL;
    1398     CRStateBits *sb = GetCurrentBits();
     1398    CRStateBits *sb = GetCurrentBits(pState);
    13991399    CRTextureBits *tb = &(sb->texture);
    14001400    (void)data;
     
    14021402    FLUSH();
    14031403
    1404     if (ErrorCheckTexImage(3, target, level, width, height, depth, border)) {
     1404    if (ErrorCheckTexImage(pState, 3, target, level, width, height, depth, border)) {
    14051405        if (IsProxyTarget(target)) {
    14061406            /* clear all state, but don't generate error */
     
    14311431        if (!tl->img)
    14321432        {
    1433             crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY,
     1433            crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY,
    14341434                         "glCompressedTexImage3D out of memory");
    14351435            return;
     
    14691469
    14701470void STATE_APIENTRY
    1471 crStateCompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
     1471crStateCompressedTexSubImage1DARB(PCRStateTracker pState, GLenum target, GLint level, GLint xoffset,
    14721472                                                                    GLsizei width, GLenum format,
    14731473                                                                    GLsizei imageSize, const GLvoid * data)
    14741474{
    1475     CRContext *g = GetCurrentContext();
     1475    CRContext *g = GetCurrentContext(pState);
    14761476    CRTextureState *t = &(g->texture);
    1477     CRStateBits *sb = GetCurrentBits();
     1477    CRStateBits *sb = GetCurrentBits(pState);
    14781478    CRTextureBits *tb = &(sb->texture);
    14791479    CRTextureUnit *unit = t->unit + t->curTextureUnit;
     
    14841484    FLUSH();
    14851485
    1486     if (ErrorCheckTexSubImage(1, target, level, xoffset, 0, 0, width, 1, 1)) {
     1486    if (ErrorCheckTexSubImage(pState, 1, target, level, xoffset, 0, 0, width, 1, 1)) {
    14871487        return; /* GL error state already set */
    14881488    }
     
    15261526
    15271527void STATE_APIENTRY
    1528 crStateCompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
     1528crStateCompressedTexSubImage2DARB(PCRStateTracker pState, GLenum target, GLint level, GLint xoffset,
    15291529                                                                    GLint yoffset, GLsizei width,
    15301530                                                                    GLsizei height, GLenum format,
    15311531                                                                    GLsizei imageSize, const GLvoid * data)
    15321532{
    1533     CRContext *g = GetCurrentContext();
     1533    CRContext *g = GetCurrentContext(pState);
    15341534    CRTextureState *t = &(g->texture);
    1535     CRStateBits *sb = GetCurrentBits();
     1535    CRStateBits *sb = GetCurrentBits(pState);
    15361536    CRTextureBits *tb = &(sb->texture);
    15371537    CRTextureUnit *unit = t->unit + t->curTextureUnit;
     
    15501550#endif
    15511551
    1552     if (ErrorCheckTexSubImage(2, target, level, xoffset, yoffset, 0,
     1552    if (ErrorCheckTexSubImage(pState, 2, target, level, xoffset, yoffset, 0,
    15531553                                                        width, height, 1)) {
    15541554        return; /* GL error state already set */
     
    15881588
    15891589void STATE_APIENTRY
    1590 crStateCompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
     1590crStateCompressedTexSubImage3DARB(PCRStateTracker pState, GLenum target, GLint level, GLint xoffset,
    15911591                                                                    GLint yoffset, GLint zoffset, GLsizei width,
    15921592                                                                    GLsizei height, GLsizei depth,
     
    15941594                                                                    const GLvoid * data)
    15951595{
    1596     CRContext *g = GetCurrentContext();
     1596    CRContext *g = GetCurrentContext(pState);
    15971597    CRTextureState *t = &(g->texture);
    1598     CRStateBits *sb = GetCurrentBits();
     1598    CRStateBits *sb = GetCurrentBits(pState);
    15991599    CRTextureBits *tb = &(sb->texture);
    16001600    CRTextureUnit *unit = t->unit + t->curTextureUnit;
     
    16131613#endif
    16141614
    1615     if (ErrorCheckTexSubImage(3, target, level, xoffset, yoffset, zoffset,
     1615    if (ErrorCheckTexSubImage(pState, 3, target, level, xoffset, yoffset, zoffset,
    16161616                                                        width, height, depth)) {
    16171617        return; /* GL error state already set */
     
    16521652
    16531653void STATE_APIENTRY
    1654 crStateGetCompressedTexImageARB(GLenum target, GLint level, GLvoid * img)
    1655 {
    1656     CRContext *g = GetCurrentContext();
     1654crStateGetCompressedTexImageARB(PCRStateTracker pState, GLenum target, GLint level, GLvoid * img)
     1655{
     1656    CRContext *g = GetCurrentContext(pState);
    16571657    CRTextureObj *tobj;
    16581658    CRTextureLevel *tl;
     
    16601660    if (g->current.inBeginEnd)
    16611661    {
    1662         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1662        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    16631663                                 "glGetCompressedTexImage called in begin/end");
    16641664        return;
     
    16671667    crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl);
    16681668    if (!tobj || !tl) {
    1669         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1669        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    16701670                                 "glGetCompressedTexImage(invalid target or level)");
    16711671        return;
     
    16731673
    16741674    if (!tl->compressed) {
    1675         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1675        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    16761676                                 "glGetCompressedTexImage(not a compressed texture)");
    16771677        return;
     
    16881688    crMemcpy(img, tl->img, tl->bytes);
    16891689#else
    1690     diff_api.GetCompressedTexImageARB(target, level, img);
     1690    pState->diff_api.GetCompressedTexImageARB(target, level, img);
    16911691#endif
    16921692}
     
    16941694
    16951695void STATE_APIENTRY
    1696 crStateGetTexImage(GLenum target, GLint level, GLenum format,
     1696crStateGetTexImage(PCRStateTracker pState, GLenum target, GLint level, GLenum format,
    16971697                   GLenum type, GLvoid * pixels)
    16981698{
    1699     CRContext *g = GetCurrentContext();
     1699    CRContext *g = GetCurrentContext(pState);
    17001700#ifndef CR_STATE_NO_TEXTURE_IMAGE_STORE
    17011701    CRClientState *c = &(g->client);
     
    17061706    if (g->current.inBeginEnd)
    17071707    {
    1708         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1708        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    17091709                                 "glGetTexImage called in begin/end");
    17101710        return;
     
    17131713    crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl);
    17141714    if (!tobj || !tl) {
    1715         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1715        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    17161716                                 "glGetTexImage(invalid target or level)");
    17171717        return;
     
    17421742            break;
    17431743        default:
    1744             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1744            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    17451745                                     "glGetTexImage called with bogus format: %d", format);
    17461746            return;
     
    17581758            break;
    17591759        default:
    1760             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1760            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    17611761                                     "glGetTexImage called with bogus type: %d", type);
    17621762            return;
     
    17671767    if (target == GL_TEXTURE_3D)
    17681768    {
    1769         crPixelCopy3D(tl->width, tl->height, tl->depth, (GLvoid *) pixels, format,
     1769        crPixelCopy3D(pState, tl->width, tl->height, tl->depth, (GLvoid *) pixels, format,
    17701770                      type, NULL, (tl->img), format, type, &(c->pack));
    17711771    }
     
    17741774    if ((target == GL_TEXTURE_1D) || (target == GL_TEXTURE_2D))
    17751775    {
    1776         crPixelCopy2D(tl->width, tl->height, (GLvoid *) pixels, format, type, NULL, /* dst */
     1776        crPixelCopy2D(pState, tl->width, tl->height, (GLvoid *) pixels, format, type, NULL, /* dst */
    17771777                      tl->img, format, type, &(c->pack));                           /* src */
    17781778    }
    17791779#else
    1780     diff_api.GetTexImage(target, level, format, type, pixels);
    1781 #endif
    1782 }
     1780    pState->diff_api.GetTexImage(target, level, format, type, pixels);
     1781#endif
     1782}
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texture.c

    r69392 r78375  
    4949    CRLimitsState *limits = &ctx->limits;
    5050    CRTextureState *t = &ctx->texture;
    51     CRStateBits *sb = GetCurrentBits();
     51    CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    5252    CRTextureBits *tb = &(sb->texture);
    5353    unsigned int i;
     
    202202
    203203#ifndef IN_GUEST
    204     crStateGetTextureObjHWID(tobj);
     204    crStateGetTextureObjHWID(ctx->pStateTracker, tobj);
    205205#endif
    206206
     
    520520 */
    521521CRTextureObj *
    522 crStateTextureGet(GLenum target, GLuint name)
    523 {
    524     CRContext *g = GetCurrentContext();
     522crStateTextureGet(PCRStateTracker pState, GLenum target, GLuint name)
     523{
     524    CRContext *g = GetCurrentContext(pState);
    525525    CRTextureState *t = &(g->texture);
    526526    CRTextureObj *tobj;
     
    635635}
    636636
    637 void crStateRegTextures(GLsizei n, GLuint *names)
    638 {
    639     CRContext *g = GetCurrentContext();
     637void crStateRegTextures(PCRStateTracker pState, GLsizei n, GLuint *names)
     638{
     639    CRContext *g = GetCurrentContext(pState);
    640640    crStateRegNames(g, g->shared->textureTable, n, names);
    641641}
     
    643643void crStateGenNames(CRContext *g, CRHashTable *table, GLsizei n, GLuint *names)
    644644{
     645    PCRStateTracker pState = g->pStateTracker;
    645646    GLint start;
    646647
     
    649650    if (g->current.inBeginEnd)
    650651    {
    651         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     652        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    652653                                 "crStateGenNames called in Begin/End");
    653654        return;
     
    656657    if (n < 0)
    657658    {
    658         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     659        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    659660                                 "Negative n passed to crStateGenNames: %d", n);
    660661        return;
     
    670671    else
    671672    {
    672         crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glGenTextures");
    673     }
    674 }
    675 
    676 void STATE_APIENTRY crStateGenTextures(GLsizei n, GLuint *textures)
    677 {
    678     CRContext *g = GetCurrentContext();
     673        crStateError(pState, __LINE__, __FILE__, GL_OUT_OF_MEMORY, "glGenTextures");
     674    }
     675}
     676
     677void STATE_APIENTRY crStateGenTextures(PCRStateTracker pState, GLsizei n, GLuint *textures)
     678{
     679    CRContext *g = GetCurrentContext(pState);
    679680    crStateGenNames(g, g->shared->textureTable, n, textures);
    680681}
    681682
    682 static void crStateTextureCheckFBOAPs(GLenum target, GLuint texture)
     683static void crStateTextureCheckFBOAPs(PCRStateTracker pState, GLenum target, GLuint texture)
    683684{
    684685    GLuint u;
    685686    CRFBOAttachmentPoint *ap;
    686     CRContext *g = GetCurrentContext();
     687    CRContext *g = GetCurrentContext(pState);
    687688    CRFramebufferObjectState *fbo = &g->framebufferobject;
    688689    CRFramebufferObject *pFBO;
     
    696697        if (ap->type==GL_TEXTURE && ap->name==texture)
    697698        {
    698             crStateFramebufferTexture1DEXT(target, u+GL_COLOR_ATTACHMENT0_EXT, 0, 0, 0);
     699            crStateFramebufferTexture1DEXT(pState, target, u+GL_COLOR_ATTACHMENT0_EXT, 0, 0, 0);
    699700        }
    700701    }
     
    703704    if (ap->type==GL_TEXTURE && ap->name==texture)
    704705    {
    705         crStateFramebufferTexture1DEXT(target, GL_DEPTH_ATTACHMENT_EXT, 0, 0, 0);
     706        crStateFramebufferTexture1DEXT(pState, target, GL_DEPTH_ATTACHMENT_EXT, 0, 0, 0);
    706707    }
    707708
     
    709710    if (ap->type==GL_TEXTURE && ap->name==texture)
    710711    {
    711         crStateFramebufferTexture1DEXT(target, GL_STENCIL_ATTACHMENT_EXT, 0, 0, 0);
     712        crStateFramebufferTexture1DEXT(pState, target, GL_STENCIL_ATTACHMENT_EXT, 0, 0, 0);
    712713    }
    713714}
     
    715716static void crStateCleanupTextureRefs(CRContext *g, CRTextureObj *tObj)
    716717{
     718    PCRStateTracker pState = g->pStateTracker;
    717719    CRTextureState *t = &(g->texture);
    718720    GLuint u;
     
    751753
    752754#ifdef CR_EXT_framebuffer_object
    753         crStateTextureCheckFBOAPs(GL_DRAW_FRAMEBUFFER, tObj->id);
    754         crStateTextureCheckFBOAPs(GL_READ_FRAMEBUFFER, tObj->id);
    755 #endif
    756     }
    757 }
    758 
    759 void STATE_APIENTRY crStateDeleteTextures(GLsizei n, const GLuint *textures)
    760 {
    761     CRContext *g = GetCurrentContext();
     755        crStateTextureCheckFBOAPs(pState, GL_DRAW_FRAMEBUFFER, tObj->id);
     756        crStateTextureCheckFBOAPs(pState, GL_READ_FRAMEBUFFER, tObj->id);
     757#endif
     758    }
     759}
     760
     761void STATE_APIENTRY crStateDeleteTextures(PCRStateTracker pState, GLsizei n, const GLuint *textures)
     762{
     763    CRContext *g = GetCurrentContext(pState);
    762764    CRTextureState *t = &(g->texture);
    763     CRStateBits *sb = GetCurrentBits();
     765    CRStateBits *sb = GetCurrentBits(pState);
    764766    CRTextureBits *tb = &(sb->texture);
    765767    int i;
     
    769771    if (g->current.inBeginEnd)
    770772    {
    771         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     773        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    772774                                 "glDeleteTextures called in Begin/End");
    773775        return;
     
    776778    if (n < 0)
    777779    {
    778         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     780        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    779781                                 "Negative n passed to glDeleteTextures: %d", n);
    780782        return;
     
    803805                 * This is why g_pAvailableContexts[j] could be NULL
    804806                 * also g_pAvailableContexts[0] will hold default context, which we should discard */
    805                 CRContext *ctx = g_pAvailableContexts[j];
     807                CRContext *ctx = pState->apAvailableContexts[j];
    806808                if (j && ctx)
    807809                {
     
    831833
    832834
    833 void STATE_APIENTRY crStateClientActiveTextureARB( GLenum texture )
    834 {
    835     CRContext *g = GetCurrentContext();
     835void STATE_APIENTRY crStateClientActiveTextureARB(PCRStateTracker pState, GLenum texture )
     836{
     837    CRContext *g = GetCurrentContext(pState);
    836838    CRClientState *c = &(g->client);
    837839
     
    839841
    840842    if (!g->extensions.ARB_multitexture) {
    841         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     843        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    842844                                 "glClientActiveTextureARB not available");
    843845        return;
     
    846848    if (g->current.inBeginEnd)
    847849    {
    848         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     850        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    849851                                 "glClientActiveTextureARB called in Begin/End");
    850852        return;
     
    854856             texture >= GL_TEXTURE0_ARB + g->limits.maxTextureUnits)
    855857    {
    856         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     858        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    857859                                 "crStateClientActiveTexture: unit = %d (max is %d)",
    858860                                 texture, g->limits.maxTextureUnits );
     
    862864    c->curClientTextureUnit = texture - GL_TEXTURE0_ARB;
    863865
    864     DIRTY(GetCurrentBits()->client.dirty, g->neg_bitid);
    865 }
    866 
    867 void STATE_APIENTRY crStateActiveTextureARB( GLenum texture )
    868 {
    869     CRContext *g = GetCurrentContext();
     866    DIRTY(GetCurrentBits(pState)->client.dirty, g->neg_bitid);
     867}
     868
     869void STATE_APIENTRY crStateActiveTextureARB(PCRStateTracker pState, GLenum texture )
     870{
     871    CRContext *g = GetCurrentContext(pState);
    870872    CRTextureState *t = &(g->texture);
    871873
     
    873875
    874876    if (!g->extensions.ARB_multitexture) {
    875         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     877        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    876878                                 "glActiveTextureARB not available");
    877879        return;
     
    880882    if (g->current.inBeginEnd)
    881883    {
    882         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glActiveTextureARB called in Begin/End");
     884        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glActiveTextureARB called in Begin/End");
    883885        return;
    884886    }
     
    886888    if ( texture < GL_TEXTURE0_ARB || texture >= GL_TEXTURE0_ARB + g->limits.maxTextureUnits)
    887889    {
    888         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "Bad texture unit passed to crStateActiveTexture: %d (max is %d)", texture, g->limits.maxTextureUnits );
     890        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "Bad texture unit passed to crStateActiveTexture: %d (max is %d)", texture, g->limits.maxTextureUnits );
    889891        return;
    890892    }
     
    894896    /* update the current matrix pointer, etc. */
    895897    if (g->transform.matrixMode == GL_TEXTURE) {
    896         crStateMatrixMode(GL_TEXTURE);
     898        crStateMatrixMode(pState, GL_TEXTURE);
    897899    }
    898900}
     
    903905# endif
    904906
    905 DECLEXPORT(void) crStatePinTexture(GLuint texture, GLboolean pin)
     907DECLEXPORT(void) crStatePinTexture(PCRStateTracker pState, GLuint texture, GLboolean pin)
    906908{
    907909    CRTextureObj * pTobj;
    908     CRSharedState *pShared = crStateGlobalSharedAcquire();
     910    CRSharedState *pShared = crStateGlobalSharedAcquire(pState);
    909911    if (pShared)
    910912    {
     
    929931            {
    930932                if (!CR_STATE_SHAREDOBJ_USAGE_IS_USED(pTobj))
    931                     crStateOnTextureUsageRelease(pShared, pTobj);
     933                    crStateOnTextureUsageRelease(pState, pShared, pTobj);
    932934            }
    933935        }
     
    935937            WARN(("texture %d not defined", texture));
    936938
    937         crStateGlobalSharedRelease();
     939        crStateGlobalSharedRelease(pState);
    938940    }
    939941    else
     
    942944#endif
    943945
    944 DECLEXPORT(void) crStateSetTextureUsed(GLuint texture, GLboolean used)
    945 {
    946     CRContext *g = GetCurrentContext();
     946DECLEXPORT(void) crStateSetTextureUsed(PCRStateTracker pState, GLuint texture, GLboolean used)
     947{
     948    CRContext *g = GetCurrentContext(pState);
    947949    CRTextureObj *tobj;
    948950
     
    973975    else
    974976    {
    975         CRStateBits *sb = GetCurrentBits();
     977        CRStateBits *sb = GetCurrentBits(pState);
    976978        CRTextureBits *tb = &(sb->texture);
    977979        CRTextureState *t = &(g->texture);
     
    986988}
    987989
    988 void STATE_APIENTRY crStateBindTexture(GLenum target, GLuint texture)
    989 {
    990     CRContext *g = GetCurrentContext();
     990void STATE_APIENTRY crStateBindTexture(PCRStateTracker pState, GLenum target, GLuint texture)
     991{
     992    CRContext *g = GetCurrentContext(pState);
    991993    CRTextureState *t = &(g->texture);
    992994    CRTextureObj *tobj;
    993     CRStateBits *sb = GetCurrentBits();
     995    CRStateBits *sb = GetCurrentBits(pState);
    994996    CRTextureBits *tb = &(sb->texture);
    995997
     
    9981000    if (g->current.inBeginEnd)
    9991001    {
    1000         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glBindTexture called in Begin/End");
     1002        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glBindTexture called in Begin/End");
    10011003        return;
    10021004    }
     
    10211023            case GL_TEXTURE_CUBE_MAP_ARB:
    10221024                if (!g->extensions.ARB_texture_cube_map) {
    1023                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1025                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    10241026                        "Invalid target passed to glBindTexture: %d", target);
    10251027                    return;
     
    10311033            case GL_TEXTURE_RECTANGLE_NV:
    10321034                if (!g->extensions.NV_texture_rectangle) {
    1033                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1035                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    10341036                        "Invalid target passed to glBindTexture: %d", target);
    10351037                    return;
     
    10391041#endif
    10401042            default:
    1041                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid target passed to glBindTexture: %d", target);
     1043                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid target passed to glBindTexture: %d", target);
    10421044                return;
    10431045        }
     
    10701072    {
    10711073        crWarning( "You called glBindTexture with a target of 0x%x, but the texture you wanted was target 0x%x [1D: %x 2D: %x 3D: %x cube: %x]", (int) target, (int) tobj->target, GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP );
    1072         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "Attempt to bind a texture of different dimensions");
     1074        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "Attempt to bind a texture of different dimensions");
    10731075        return;
    10741076    }
     
    10991101#endif
    11001102        default:
    1101             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1103            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11021104                                     "Invalid target passed to glBindTexture: %d", target);
    11031105            return;
     
    11101112
    11111113void STATE_APIENTRY
    1112 crStateTexParameterfv(GLenum target, GLenum pname, const GLfloat *param)
    1113 {
    1114     CRContext *g = GetCurrentContext();
     1114crStateTexParameterfv(PCRStateTracker pState, GLenum target, GLenum pname, const GLfloat *param)
     1115{
     1116    CRContext *g = GetCurrentContext(pState);
    11151117    CRTextureObj *tobj = NULL;
    11161118    CRTextureLevel *tl = NULL;
    11171119    GLenum e = (GLenum) *param;
    1118     CRStateBits *sb = GetCurrentBits();
     1120    CRStateBits *sb = GetCurrentBits(pState);
    11191121    CRTextureBits *tb = &(sb->texture);
    11201122    unsigned int i;
     
    11241126    if (g->current.inBeginEnd)
    11251127    {
    1126         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1128        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    11271129                    "TexParameterfv called in Begin/End");
    11281130        return;
     
    11311133    crStateGetTextureObjectAndImage(g, target, 0, &tobj, &tl);
    11321134    if (!tobj) {
    1133         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1135        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11341136                    "TexParamterfv(invalid target=0x%x)", target);
    11351137        return;
     
    11461148                    e != GL_LINEAR_MIPMAP_LINEAR)
    11471149            {
    1148                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1150                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11491151                            "TexParamterfv: GL_TEXTURE_MIN_FILTER invalid param: %d", e);
    11501152                return;
     
    11551157            if (e != GL_NEAREST && e != GL_LINEAR)
    11561158            {
    1157                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1159                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11581160                            "TexParamterfv: GL_TEXTURE_MAG_FILTER invalid param: %d", e);
    11591161                return;
     
    11911193#endif
    11921194            else {
    1193                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1195                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    11941196                    "TexParameterfv: GL_TEXTURE_WRAP_S invalid param: 0x%x", e);
    11951197                return;
     
    12261228#endif
    12271229            else {
    1228                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1230                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    12291231                    "TexParameterfv: GL_TEXTURE_WRAP_T invalid param: 0x%x", e);
    12301232                return;
     
    12601262#endif
    12611263            else {
    1262                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1264                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    12631265                    "TexParameterfv: GL_TEXTURE_WRAP_R invalid param: 0x%x", e);
    12641266                return;
     
    12771279            if (e < 0.0f)
    12781280            {
    1279                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1281                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    12801282                    "TexParameterfv: GL_TEXTURE_BASE_LEVEL invalid param: 0x%x", e);
    12811283                return;
     
    12861288            if (e < 0.0f)
    12871289            {
    1288                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1290                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    12891291                    "TexParameterfv: GL_TEXTURE_MAX_LEVEL invalid param: 0x%x", e);
    12901292                return;
     
    13041306                if (param[0] < 1.0f)
    13051307                {
    1306                     crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1308                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    13071309                        "TexParameterfv: GL_TEXTURE_MAX_ANISOTROPY_EXT called with parameter less than 1: %f", param[0]);
    13081310                    return;
     
    13261328                else
    13271329                {
    1328                     crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1330                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    13291331                        "TexParameterfv: GL_DEPTH_TEXTURE_MODE_ARB called with invalid parameter: 0x%x", param[0]);
    13301332                    return;
     
    13421344                else
    13431345                {
    1344                     crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1346                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    13451347                        "TexParameterfv: GL_TEXTURE_COMPARE_MODE_ARB called with invalid parameter: 0x%x", param[0]);
    13461348                    return;
     
    13681370#endif
    13691371            else {
    1370                     crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1372                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    13711373                        "TexParameterfv: GL_TEXTURE_COMPARE_FUNC_ARB called with invalid parameter: 0x%x", param[0]);
    13721374                    return;
     
    13891391#endif
    13901392        default:
    1391             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1393            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    13921394                "TexParamterfv: Invalid pname: %d", pname);
    13931395            return;
     
    14041406
    14051407void STATE_APIENTRY
    1406 crStateTexParameteriv(GLenum target, GLenum pname, const GLint *param)
     1408crStateTexParameteriv(PCRStateTracker pState, GLenum target, GLenum pname, const GLint *param)
    14071409{
    14081410    GLfloat f_param;
     
    14391441#endif
    14401442            f_param = (GLfloat) (*param);
    1441             crStateTexParameterfv( target, pname, &(f_param) );
     1443            crStateTexParameterfv(pState, target, pname, &(f_param) );
    14421444            break;
    14431445        case GL_TEXTURE_BORDER_COLOR:
     
    14461448            f_color.b = ((GLfloat) param[2])/CR_MAXINT;
    14471449            f_color.a = ((GLfloat) param[3])/CR_MAXINT;
    1448             crStateTexParameterfv( target, pname, (const GLfloat *) &(f_color) );
     1450            crStateTexParameterfv(pState, target, pname, (const GLfloat *) &(f_color) );
    14491451            break;
    14501452        default:
    1451             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1453            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    14521454                "TexParamteriv: Invalid pname: %d", pname);
    14531455            return;
     
    14571459
    14581460void STATE_APIENTRY
    1459 crStateTexParameterf(GLenum target, GLenum pname, GLfloat param)
    1460 {
    1461     crStateTexParameterfv( target, pname, &param );
     1461crStateTexParameterf(PCRStateTracker pState, GLenum target, GLenum pname, GLfloat param)
     1462{
     1463    crStateTexParameterfv(pState, target, pname, &param );
    14621464}
    14631465
    14641466
    14651467void STATE_APIENTRY
    1466 crStateTexParameteri(GLenum target, GLenum pname, GLint param) {
     1468crStateTexParameteri(PCRStateTracker pState, GLenum target, GLenum pname, GLint param) {
    14671469    GLfloat f_param = (GLfloat) param;
    1468     crStateTexParameterfv( target, pname, &f_param );
     1470    crStateTexParameterfv(pState, target, pname, &f_param );
    14691471}
    14701472
    14711473
    14721474void STATE_APIENTRY
    1473 crStateTexEnvfv(GLenum target, GLenum pname, const GLfloat *param)
    1474 {
    1475     CRContext *g = GetCurrentContext();
     1475crStateTexEnvfv(PCRStateTracker pState, GLenum target, GLenum pname, const GLfloat *param)
     1476{
     1477    CRContext *g = GetCurrentContext(pState);
    14761478    CRTextureState *t = &(g->texture);
    1477     CRStateBits *sb = GetCurrentBits();
     1479    CRStateBits *sb = GetCurrentBits(pState);
    14781480    CRTextureBits *tb = &(sb->texture);
    14791481    GLenum e;
     
    14871489    if (g->current.inBeginEnd)
    14881490    {
    1489         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1491        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    14901492                    "glTexEnvfv called in begin/end");
    14911493        return;
     
    14951497    if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
    14961498        if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
    1497             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnv");
     1499            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnv");
    14981500        }
    14991501        else {
     
    15091511    if (target == GL_POINT_SPRITE_ARB) {
    15101512        if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
    1511             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnv");
     1513            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnv");
    15121514        }
    15131515        else {
     
    15231525    if (target != GL_TEXTURE_ENV)
    15241526    {
    1525         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1527        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15261528                    "glTexEnvfv: target != GL_TEXTURE_ENV: %d", target);
    15271529        return;
     
    15391541                    e != GL_COMBINE_ARB)
    15401542            {
    1541                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1543                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    15421544                            "glTexEnvfv: invalid param: %f", *param);
    15431545                return;
     
    15831585#endif
    15841586            else {
    1585                  crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv(param=0x%x", e);
     1587                 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv(param=0x%x", e);
    15861588                 return;
    15871589            }
     
    15991601            }
    16001602            else {
    1601                  crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
     1603                 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
    16021604                 return;
    16031605            }
     
    16211623            }
    16221624            else {
    1623                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
     1625                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
    16241626                return;
    16251627            }
     
    16431645            }
    16441646            else {
    1645                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
     1647                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
    16461648                return;
    16471649            }
     
    16601662            }
    16611663            else {
    1662                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
     1664                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
    16631665                return;
    16641666            }
     
    16751677            }
    16761678            else {
    1677                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv(param=0x%x)", e);
     1679                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv(param=0x%x)", e);
    16781680                return;
    16791681            }
     
    16871689            }
    16881690            else {
    1689                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexEnvfv");
     1691                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glTexEnvfv");
    16901692                return;
    16911693            }
     
    16991701            }
    17001702            else {
    1701                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexEnvfv");
     1703                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glTexEnvfv");
    17021704                return;
    17031705            }
     
    17061708
    17071709        default:
    1708             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1710            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    17091711                        "glTexEnvfv: invalid pname: %d", pname);
    17101712            return;
     
    17171719
    17181720void STATE_APIENTRY
    1719 crStateTexEnviv(GLenum target, GLenum pname, const GLint *param)
     1721crStateTexEnviv(PCRStateTracker pState, GLenum target, GLenum pname, const GLint *param)
    17201722{
    17211723    GLfloat f_param;
     
    17251727        case GL_TEXTURE_ENV_MODE:
    17261728            f_param = (GLfloat) (*param);
    1727             crStateTexEnvfv( target, pname, &f_param );
     1729            crStateTexEnvfv(pState, target, pname, &f_param );
    17281730            break;
    17291731        case GL_TEXTURE_ENV_COLOR:
     
    17321734            f_color.b = ((GLfloat) param[2]) / CR_MAXINT;
    17331735            f_color.a = ((GLfloat) param[3]) / CR_MAXINT;
    1734             crStateTexEnvfv( target, pname, (const GLfloat *) &f_color );
     1736            crStateTexEnvfv(pState, target, pname, (const GLfloat *) &f_color );
    17351737            break;
    17361738#ifdef CR_ARB_texture_env_combine
     
    17521754        case GL_ALPHA_SCALE:
    17531755            f_param = (GLfloat) (*param);
    1754             crStateTexEnvfv( target, pname, &f_param );
     1756            crStateTexEnvfv(pState, target, pname, &f_param );
    17551757            break;
    17561758#endif
     
    17581760        case GL_TEXTURE_LOD_BIAS_EXT:
    17591761            f_param = (GLfloat) (*param);
    1760             crStateTexEnvfv( target, pname, &f_param);
     1762            crStateTexEnvfv(pState, target, pname, &f_param);
    17611763            break;
    17621764#endif
     
    17641766        case GL_COORD_REPLACE_ARB:
    17651767            f_param = (GLfloat) *param;
    1766             crStateTexEnvfv( target, pname, &f_param);
     1768            crStateTexEnvfv(pState, target, pname, &f_param);
    17671769            break;
    17681770#endif
    17691771
    17701772        default:
    1771             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1773            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    17721774                        "glTexEnvfv: invalid pname: %d", pname);
    17731775            return;
     
    17771779
    17781780void STATE_APIENTRY
    1779 crStateTexEnvf(GLenum target, GLenum pname, GLfloat param)
    1780 {
    1781     crStateTexEnvfv( target, pname, &param );
     1781crStateTexEnvf(PCRStateTracker pState, GLenum target, GLenum pname, GLfloat param)
     1782{
     1783    crStateTexEnvfv(pState, target, pname, &param );
    17821784}
    17831785
    17841786
    17851787void STATE_APIENTRY
    1786 crStateTexEnvi(GLenum target, GLenum pname, GLint param)
     1788crStateTexEnvi(PCRStateTracker pState, GLenum target, GLenum pname, GLint param)
    17871789{
    17881790    GLfloat f_param = (GLfloat) param;
    1789     crStateTexEnvfv( target, pname, &f_param );
     1791    crStateTexEnvfv(pState, target, pname, &f_param );
    17901792}
    17911793
    17921794
    17931795void STATE_APIENTRY
    1794 crStateGetTexEnvfv(GLenum target, GLenum pname, GLfloat *param)
    1795 {
    1796     CRContext *g = GetCurrentContext();
     1796crStateGetTexEnvfv(PCRStateTracker pState, GLenum target, GLenum pname, GLfloat *param)
     1797{
     1798    CRContext *g = GetCurrentContext(pState);
    17971799    CRTextureState *t = &(g->texture);
    17981800
    17991801    if (g->current.inBeginEnd)
    18001802    {
    1801         crStateError(__LINE__, __FILE__,GL_INVALID_OPERATION,
     1803        crStateError(pState, __LINE__, __FILE__,GL_INVALID_OPERATION,
    18021804                    "glGetTexEnvfv called in begin/end");
    18031805        return;
     
    18071809    if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
    18081810        if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
    1809             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
     1811            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
    18101812        }
    18111813        else {
     
    18191821    if (target == GL_POINT_SPRITE_ARB) {
    18201822        if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
    1821             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
     1823            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
    18221824        }
    18231825        else {
     
    18301832    if (target != GL_TEXTURE_ENV)
    18311833    {
    1832         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1834        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    18331835                    "glGetTexEnvfv: target != GL_TEXTURE_ENV: %d", target);
    18341836        return;
     
    18501852            }
    18511853            else {
    1852                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1854                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    18531855                return;
    18541856            }
     
    18591861            }
    18601862            else {
    1861                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1863                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    18621864                return;
    18631865            }
     
    18681870            }
    18691871            else {
    1870                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1872                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    18711873                return;
    18721874            }
     
    18771879            }
    18781880            else {
    1879                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1881                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    18801882                return;
    18811883            }
     
    18861888            }
    18871889            else {
    1888                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1890                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    18891891                return;
    18901892            }
     
    18951897            }
    18961898            else {
    1897                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1899                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    18981900                return;
    18991901            }
     
    19041906            }
    19051907            else {
    1906                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1908                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    19071909                return;
    19081910            }
     
    19131915            }
    19141916            else {
    1915                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1917                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    19161918                return;
    19171919            }
     
    19221924            }
    19231925            else {
    1924                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1926                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    19251927                return;
    19261928            }
     
    19311933            }
    19321934            else {
    1933                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1935                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    19341936                return;
    19351937            }
     
    19401942            }
    19411943            else {
    1942                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1944                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    19431945                return;
    19441946            }
     
    19491951            }
    19501952            else {
    1951                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1953                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    19521954                return;
    19531955            }
     
    19581960            }
    19591961            else {
    1960                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1962                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    19611963                return;
    19621964            }
     
    19671969            }
    19681970            else {
    1969                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1971                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    19701972                return;
    19711973            }
     
    19761978            }
    19771979            else {
    1978                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1980                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    19791981                return;
    19801982            }
     
    19851987            }
    19861988            else {
    1987                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1989                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    19881990                return;
    19891991            }
    19901992            break;
    19911993        default:
    1992             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1994            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    19931995                        "glGetTexEnvfv: invalid pname: %d", pname);
    19941996            return;
     
    19982000
    19992001void STATE_APIENTRY
    2000 crStateGetTexEnviv(GLenum target, GLenum pname, GLint *param)
    2001 {
    2002     CRContext *g = GetCurrentContext();
     2002crStateGetTexEnviv(PCRStateTracker pState, GLenum target, GLenum pname, GLint *param)
     2003{
     2004    CRContext *g = GetCurrentContext(pState);
    20032005    CRTextureState *t = &(g->texture);
    20042006
    20052007    if (g->current.inBeginEnd)
    20062008    {
    2007         crStateError(__LINE__, __FILE__,GL_INVALID_OPERATION,
     2009        crStateError(pState, __LINE__, __FILE__,GL_INVALID_OPERATION,
    20082010                    "glGetTexEnviv called in begin/end");
    20092011        return;
     
    20132015    if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
    20142016        if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
    2015             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
     2017            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
    20162018        }
    20172019        else {
     
    20252027    if (target == GL_POINT_SPRITE_ARB) {
    20262028        if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
    2027             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
     2029            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
    20282030        }
    20292031        else {
     
    20362038    if (target != GL_TEXTURE_ENV)
    20372039    {
    2038         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2040        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    20392041                    "glGetTexEnviv: target != GL_TEXTURE_ENV: %d", target);
    20402042        return;
     
    20562058            }
    20572059            else {
    2058                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2060                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    20592061                return;
    20602062            }
     
    20652067            }
    20662068            else {
    2067                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2069                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    20682070                return;
    20692071            }
     
    20742076            }
    20752077            else {
    2076                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2078                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    20772079                return;
    20782080            }
     
    20832085            }
    20842086            else {
    2085                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2087                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    20862088                return;
    20872089            }
     
    20922094            }
    20932095            else {
    2094                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2096                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    20952097                return;
    20962098            }
     
    21012103            }
    21022104            else {
    2103                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2105                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21042106                return;
    21052107            }
     
    21102112            }
    21112113            else {
    2112                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2114                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21132115                return;
    21142116            }
     
    21192121            }
    21202122            else {
    2121                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2123                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21222124                return;
    21232125            }
     
    21282130            }
    21292131            else {
    2130                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2132                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21312133                return;
    21322134            }
     
    21372139            }
    21382140            else {
    2139                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2141                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21402142                return;
    21412143            }
     
    21462148            }
    21472149            else {
    2148                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2150                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21492151                return;
    21502152            }
     
    21552157            }
    21562158            else {
    2157                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2159                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21582160                return;
    21592161            }
     
    21642166            }
    21652167            else {
    2166                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2168                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21672169                return;
    21682170            }
     
    21732175            }
    21742176            else {
    2175                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2177                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21762178                return;
    21772179            }
     
    21822184            }
    21832185            else {
    2184                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2186                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21852187                return;
    21862188            }
     
    21912193            }
    21922194            else {
    2193                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2195                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    21942196                return;
    21952197            }
    21962198            break;
    21972199        default:
    2198             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2200            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    21992201                        "glGetTexEnviv: invalid pname: %d", pname);
    22002202            return;
     
    22042206
    22052207void STATE_APIENTRY
    2206 crStateTexGendv(GLenum coord, GLenum pname, const GLdouble *param)
    2207 {
    2208     CRContext *g = GetCurrentContext();
     2208crStateTexGendv(PCRStateTracker pState, GLenum coord, GLenum pname, const GLdouble *param)
     2209{
     2210    CRContext *g = GetCurrentContext(pState);
    22092211    CRTextureState *t = &(g->texture);
    22102212    CRTransformState *trans = &(g->transform);
     
    22122214    GLenum e;
    22132215    CRmatrix inv;
    2214     CRStateBits *sb = GetCurrentBits();
     2216    CRStateBits *sb = GetCurrentBits(pState);
    22152217    CRTextureBits *tb = &(sb->texture);
    22162218
     
    22192221    if (g->current.inBeginEnd)
    22202222    {
    2221         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2223        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    22222224                    "glTexGen called in begin/end");
    22232225        return;
     
    22442246                    }
    22452247                    else {
    2246                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2248                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    22472249                            "glTexGendv called with bad param: %lf", *param);
    22482250                        return;
     
    22702272                    break;
    22712273                default:
    2272                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2274                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    22732275                                "glTexGendv called with bogus pname: %d", pname);
    22742276                    return;
     
    22922294                    }
    22932295                    else {
    2294                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2296                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    22952297                            "glTexGendv called with bad param: %lf", *param);
    22962298                        return;
     
    23182320                    break;
    23192321                default:
    2320                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2322                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    23212323                                "glTexGen called with bogus pname: %d", pname);
    23222324                    return;
     
    23402342                    }
    23412343                    else {
    2342                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2344                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    23432345                            "glTexGen called with bad param: %lf", *param);
    23442346                        return;
     
    23662368                    break;
    23672369                default:
    2368                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2370                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    23692371                                "glTexGen called with bogus pname: %d", pname);
    23702372                    return;
     
    23882390                    }
    23892391                    else {
    2390                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2392                        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    23912393                            "glTexGen called with bad param: %lf", *param);
    23922394                        return;
     
    24142416                    break;
    24152417                default:
    2416                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2418                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    24172419                                "glTexGen called with bogus pname: %d", pname);
    24182420                    return;
     
    24202422            break;
    24212423        default:
    2422             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2424            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    24232425                        "glTexGen called with bogus coord: %d", coord);
    24242426            return;
     
    24282430
    24292431void STATE_APIENTRY
    2430 crStateTexGenfv(GLenum coord, GLenum pname, const GLfloat *param)
     2432crStateTexGenfv(PCRStateTracker pState, GLenum coord, GLenum pname, const GLfloat *param)
    24312433{
    24322434    GLdouble d_param;
     
    24362438        case GL_TEXTURE_GEN_MODE:
    24372439            d_param = (GLdouble) *param;
    2438             crStateTexGendv( coord, pname, &d_param );
     2440            crStateTexGendv(pState, coord, pname, &d_param );
    24392441            break;
    24402442        case GL_OBJECT_PLANE:
     
    24442446            d_vector.z = (GLdouble) param[2];
    24452447            d_vector.w = (GLdouble) param[3];
    2446             crStateTexGendv( coord, pname, (const double *) &d_vector );
     2448            crStateTexGendv(pState, coord, pname, (const double *) &d_vector );
    24472449            break;
    24482450        default:
    2449             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2451            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    24502452                        "glTexGen called with bogus pname: %d", pname);
    24512453            return;
     
    24552457
    24562458void STATE_APIENTRY
    2457 crStateTexGeniv(GLenum coord, GLenum pname, const GLint *param)
     2459crStateTexGeniv(PCRStateTracker pState, GLenum coord, GLenum pname, const GLint *param)
    24582460{
    24592461    GLdouble d_param;
     
    24632465        case GL_TEXTURE_GEN_MODE:
    24642466            d_param = (GLdouble) *param;
    2465             crStateTexGendv( coord, pname, &d_param );
     2467            crStateTexGendv(pState, coord, pname, &d_param );
    24662468            break;
    24672469        case GL_OBJECT_PLANE:
     
    24712473            d_vector.z = (GLdouble) param[2];
    24722474            d_vector.w = (GLdouble) param[3];
    2473             crStateTexGendv( coord, pname, (const double *) &d_vector );
     2475            crStateTexGendv(pState, coord, pname, (const double *) &d_vector );
    24742476            break;
    24752477        default:
    2476             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2478            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    24772479                        "glTexGen called with bogus pname: %d", pname);
    24782480            return;
     
    24822484
    24832485void STATE_APIENTRY
    2484 crStateTexGend (GLenum coord, GLenum pname, GLdouble param)
    2485 {
    2486     crStateTexGendv( coord, pname, &param );
     2486crStateTexGend (PCRStateTracker pState, GLenum coord, GLenum pname, GLdouble param)
     2487{
     2488    crStateTexGendv(pState, coord, pname, &param );
    24872489}
    24882490
    24892491
    24902492void STATE_APIENTRY
    2491 crStateTexGenf(GLenum coord, GLenum pname, GLfloat param)
     2493crStateTexGenf(PCRStateTracker pState, GLenum coord, GLenum pname, GLfloat param)
    24922494{
    24932495    GLdouble d_param = (GLdouble) param;
    2494     crStateTexGendv( coord, pname, &d_param );
     2496    crStateTexGendv(pState, coord, pname, &d_param );
    24952497}
    24962498
    24972499
    24982500void STATE_APIENTRY
    2499 crStateTexGeni(GLenum coord, GLenum pname, GLint param)
     2501crStateTexGeni(PCRStateTracker pState, GLenum coord, GLenum pname, GLint param)
    25002502{
    25012503    GLdouble d_param = (GLdouble) param;
    2502     crStateTexGendv( coord, pname, &d_param );
     2504    crStateTexGendv(pState, coord, pname, &d_param );
    25032505}
    25042506
    25052507
    25062508void STATE_APIENTRY
    2507 crStateGetTexGendv(GLenum coord, GLenum pname, GLdouble *param)
    2508 {
    2509     CRContext *g = GetCurrentContext();
     2509crStateGetTexGendv(PCRStateTracker pState, GLenum coord, GLenum pname, GLdouble *param)
     2510{
     2511    CRContext *g = GetCurrentContext(pState);
    25102512    CRTextureState *t = &(g->texture);
    25112513
    25122514    if (g->current.inBeginEnd)
    25132515    {
    2514         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2516        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    25152517                    "glGetTexGen called in begin/end");
    25162518        return;
     
    25332535                    break;
    25342536                default:
    2535                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2537                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    25362538                                "glGetTexGen called with bogus coord: %d", coord);
    25372539                    return;
     
    25652567                    break;
    25662568                default:
    2567                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2569                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    25682570                                "glGetTexGen called with bogus coord: %d", coord);
    25692571                    return;
     
    25972599                    break;
    25982600                default:
    2599                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2601                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    26002602                                "glGetTexGen called with bogus coord: %d", coord);
    26012603                    return;
     
    26032605            break;
    26042606        default:
    2605             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2607            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    26062608                        "glGetTexGen called with bogus pname: %d", pname);
    26072609            return;
     
    26112613
    26122614void STATE_APIENTRY
    2613 crStateGetTexGenfv(GLenum coord, GLenum pname, GLfloat *param)
    2614 {
    2615     CRContext *g = GetCurrentContext();
     2615crStateGetTexGenfv(PCRStateTracker pState, GLenum coord, GLenum pname, GLfloat *param)
     2616{
     2617    CRContext *g = GetCurrentContext(pState);
    26162618    CRTextureState *t = &(g->texture);
    26172619
    26182620    if (g->current.inBeginEnd)
    26192621    {
    2620         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2622        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    26212623                    "glGetTexGenfv called in begin/end");
    26222624        return;
     
    26392641                    break;
    26402642                default:
    2641                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2643                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    26422644                                "glGetTexGenfv called with bogus coord: %d", coord);
    26432645                    return;
     
    26712673                    break;
    26722674                default:
    2673                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2675                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    26742676                                "glGetTexGenfv called with bogus coord: %d", coord);
    26752677                    return;
     
    27032705                    break;
    27042706                default:
    2705                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2707                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    27062708                                "glGetTexGenfv called with bogus coord: %d", coord);
    27072709                    return;
     
    27092711            break;
    27102712        default:
    2711             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2713            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    27122714                        "glGetTexGenfv called with bogus pname: %d", pname);
    27132715            return;
     
    27172719
    27182720void STATE_APIENTRY
    2719 crStateGetTexGeniv(GLenum coord, GLenum pname, GLint *param)
    2720 {
    2721     CRContext *g = GetCurrentContext();
     2721crStateGetTexGeniv(PCRStateTracker pState, GLenum coord, GLenum pname, GLint *param)
     2722{
     2723    CRContext *g = GetCurrentContext(pState);
    27222724    CRTextureState *t = &(g->texture);
    27232725
    27242726    if (g->current.inBeginEnd)
    27252727    {
    2726         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2728        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    27272729                    "glGetTexGeniv called in begin/end");
    27282730        return;
     
    27452747                    break;
    27462748                default:
    2747                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2749                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    27482750                                "glGetTexGeniv called with bogus coord: %d", coord);
    27492751                    return;
     
    27772779                    break;
    27782780                default:
    2779                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2781                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    27802782                                "glGetTexGeniv called with bogus coord: %d", coord);
    27812783                    return;
     
    28092811                    break;
    28102812                default:
    2811                     crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2813                    crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    28122814                                "glGetTexGeniv called with bogus coord: %d", coord);
    28132815                    return;
     
    28152817            break;
    28162818        default:
    2817             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2819            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    28182820                        "glGetTexGen called with bogus pname: %d", pname);
    28192821            return;
     
    28232825
    28242826void STATE_APIENTRY
    2825 crStateGetTexLevelParameterfv(GLenum target, GLint level,
     2827crStateGetTexLevelParameterfv(PCRStateTracker pState, GLenum target, GLint level,
    28262828                                                            GLenum pname, GLfloat *params)
    28272829{
    2828     CRContext *g = GetCurrentContext();
     2830    CRContext *g = GetCurrentContext(pState);
    28292831    CRTextureState *t = &(g->texture);
    28302832    CRTextureObj *tobj;
     
    28332835    if (g->current.inBeginEnd)
    28342836    {
    2835         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2837        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    28362838            "glGetTexLevelParameterfv called in begin/end");
    28372839        return;
     
    28402842    if (level < 0 || level > t->maxLevel)
    28412843    {
    2842         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     2844        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    28432845            "glGetTexLevelParameterfv: Invalid level: %d", level);
    28442846        return;
     
    28482850    if (!timg)
    28492851    {
    2850         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2852        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    28512853            "GetTexLevelParameterfv: invalid target: 0x%x or level %d",
    28522854            target, level);
     
    29002902#endif
    29012903        default:
    2902             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2904            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    29032905                "GetTexLevelParameterfv: invalid pname: 0x%x",
    29042906                pname);
     
    29092911
    29102912void STATE_APIENTRY
    2911 crStateGetTexLevelParameteriv(GLenum target, GLint level,
     2913crStateGetTexLevelParameteriv(PCRStateTracker pState, GLenum target, GLint level,
    29122914                                                            GLenum pname, GLint *params)
    29132915{
    2914     CRContext *g = GetCurrentContext();
     2916    CRContext *g = GetCurrentContext(pState);
    29152917    CRTextureState *t = &(g->texture);
    29162918    CRTextureObj *tobj;
     
    29192921    if (g->current.inBeginEnd)
    29202922    {
    2921         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2923        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    29222924            "glGetTexLevelParameteriv called in begin/end");
    29232925        return;
     
    29262928    if (level < 0 || level > t->maxLevel)
    29272929    {
    2928         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     2930        crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    29292931            "glGetTexLevelParameteriv: Invalid level: %d", level);
    29302932        return;
     
    29342936    if (!timg)
    29352937    {
    2936         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2938        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    29372939            "GetTexLevelParameteriv: invalid target: 0x%x",
    29382940            target);
     
    29932995#endif
    29942996        default:
    2995             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2997            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    29962998                "GetTexLevelParameteriv: invalid pname: 0x%x",
    29972999                pname);
     
    30023004
    30033005void STATE_APIENTRY
    3004 crStateGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
    3005 {
    3006     CRContext *g = GetCurrentContext();
     3006crStateGetTexParameterfv(PCRStateTracker pState, GLenum target, GLenum pname, GLfloat *params)
     3007{
     3008    CRContext *g = GetCurrentContext(pState);
    30073009    CRTextureObj *tobj;
    30083010    CRTextureLevel *tl;
     
    30103012    if (g->current.inBeginEnd)
    30113013    {
    3012         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     3014        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    30133015                    "glGetTexParameterfv called in begin/end");
    30143016        return;
     
    30183020    if (!tobj)
    30193021    {
    3020         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3022        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    30213023            "glGetTexParameterfv: invalid target: 0x%x", target);
    30223024        return;
     
    30573059            }
    30583060            else {
    3059                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3061                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    30603062                    "glGetTexParameterfv: invalid pname: 0x%x", pname);
    30613063                return;
     
    30693071            }
    30703072            else {
    3071                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3073                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    30723074                    "glGetTexParameter: invalid pname: 0x%x", pname);
    30733075                return;
     
    30813083            }
    30823084            else {
    3083                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3085                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    30843086                    "glGetTexParameter: invalid pname: 0x%x", pname);
    30853087                return;
     
    30913093            }
    30923094            else {
    3093                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3095                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    30943096                    "glGetTexParameter: invalid pname: 0x%x", pname);
    30953097                return;
     
    31033105            }
    31043106            else {
    3105                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3107                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    31063108                    "glGetTexParameter: invalid pname: 0x%x", pname);
    31073109                return;
     
    31153117            }
    31163118            else {
    3117                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3119                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    31183120                    "glGetTexParameter: invalid pname: 0x%x", pname);
    31193121                return;
     
    31463148            break;
    31473149        default:
    3148             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3150            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    31493151                "glGetTexParameterfv: invalid pname: %d", pname);
    31503152            return;
     
    31543156
    31553157void STATE_APIENTRY
    3156 crStateGetTexParameteriv(GLenum target, GLenum pname, GLint *params)
    3157 {
    3158     CRContext *g = GetCurrentContext();
     3158crStateGetTexParameteriv(PCRStateTracker pState, GLenum target, GLenum pname, GLint *params)
     3159{
     3160    CRContext *g = GetCurrentContext(pState);
    31593161    CRTextureObj *tobj;
    31603162    CRTextureLevel *tl;
     
    31623164    if (g->current.inBeginEnd)
    31633165    {
    3164         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     3166        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    31653167                    "glGetTexParameter called in begin/end");
    31663168        return;
     
    31703172    if (!tobj)
    31713173    {
    3172         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3174        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    31733175            "glGetTexParameteriv: invalid target: 0x%x", target);
    31743176        return;
     
    32233225            }
    32243226            else {
    3225                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3227                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    32263228                    "glGetTexParameter: invalid pname: 0x%x", pname);
    32273229                return;
     
    32353237            }
    32363238            else {
    3237                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3239                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    32383240                    "glGetTexParameter: invalid pname: 0x%x", pname);
    32393241                return;
     
    32473249            }
    32483250            else {
    3249                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3251                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    32503252                    "glGetTexParameter: invalid pname: 0x%x", pname);
    32513253                return;
     
    32573259            }
    32583260            else {
    3259                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3261                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    32603262                    "glGetTexParameter: invalid pname: 0x%x", pname);
    32613263                return;
     
    32693271            }
    32703272            else {
    3271                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3273                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    32723274                    "glGetTexParameter: invalid pname: 0x%x", pname);
    32733275                return;
     
    32813283            }
    32823284            else {
    3283                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3285                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    32843286                    "glGetTexParameter: invalid pname: 0x%x", pname);
    32853287                return;
     
    32923294            break;
    32933295        default:
    3294             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3296            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    32953297                "glGetTexParameter: invalid pname: %d", pname);
    32963298            return;
     
    33003302
    33013303void STATE_APIENTRY
    3302 crStatePrioritizeTextures(GLsizei n, const GLuint *textures,
     3304crStatePrioritizeTextures(PCRStateTracker pState, GLsizei n, const GLuint *textures,
    33033305                                                    const GLclampf *priorities)
    33043306{
    3305     CRContext *g = GetCurrentContext();
     3307    CRContext *g = GetCurrentContext(pState);
    33063308    CRTextureObj *tobj;
    33073309    GLsizei i;
     
    33303332
    33313333GLboolean STATE_APIENTRY
    3332 crStateAreTexturesResident(GLsizei n, const GLuint *textures,
     3334crStateAreTexturesResident(PCRStateTracker pState, GLsizei n, const GLuint *textures,
    33333335                                                     GLboolean *residences)
    33343336{
     3337    RT_NOREF(pState);
    33353338    UNUSED(n);
    33363339    UNUSED(textures);
     
    33423345
    33433346GLboolean STATE_APIENTRY
    3344 crStateIsTexture(GLuint texture)
    3345 {
    3346     CRContext *g = GetCurrentContext();
     3347crStateIsTexture(PCRStateTracker pState, GLuint texture)
     3348{
     3349    CRContext *g = GetCurrentContext(pState);
    33473350    CRTextureObj *tobj;
    33483351
     
    33573360    (void) key;
    33583361
    3359     if (crStateGetTextureObjHWID(pTex)==pParms->hwid)
     3362    if (crStateGetTextureObjHWID(pParms->pState, pTex)==pParms->hwid)
    33603363        pParms->id = pTex->id;
    33613364}
    33623365
    3363 DECLEXPORT(GLuint) STATE_APIENTRY crStateTextureHWIDtoID(GLuint hwid)
    3364 {
    3365     CRContext *g = GetCurrentContext();
     3366DECLEXPORT(GLuint) STATE_APIENTRY crStateTextureHWIDtoID(PCRStateTracker pState, GLuint hwid)
     3367{
     3368    CRContext *g = GetCurrentContext(pState);
    33663369    crCheckIDHWID_t parms;
    33673370
    33683371    parms.id = hwid;
    33693372    parms.hwid = hwid;
     3373    parms.pState = pState;
    33703374
    33713375    crHashtableWalk(g->shared->textureTable, crStateCheckTextureHWIDCB, &parms);
     
    33733377}
    33743378
    3375 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureHWID(GLuint id)
    3376 {
    3377     CRContext *g = GetCurrentContext();
     3379DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureHWID(PCRStateTracker pState, GLuint id)
     3380{
     3381    CRContext *g = GetCurrentContext(pState);
    33783382    CRTextureObj *tobj;
    33793383
     
    33963400
    33973401
    3398     return tobj ? crStateGetTextureObjHWID(tobj) : 0;
    3399 }
    3400 
    3401 DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureObjHWID(CRTextureObj *tobj)
     3402    return tobj ? crStateGetTextureObjHWID(pState, tobj) : 0;
     3403}
     3404
     3405DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureObjHWID(PCRStateTracker pState, CRTextureObj *tobj)
    34023406{
    34033407    CRASSERT(tobj);
     
    34063410    if (tobj->id && !tobj->hwid)
    34073411    {
    3408         CRASSERT(diff_api.GenTextures);
    3409         diff_api.GenTextures(1, &tobj->hwid);
     3412        CRASSERT(pState->diff_api.GenTextures);
     3413        pState->diff_api.GenTextures(1, &tobj->hwid);
    34103414#if 0 /*def DEBUG_misha*/
    34113415        crDebug("tex id(%d), hwid(%d)", tobj->id, tobj->hwid);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_transform.c

    r78263 r78375  
    1919 */
    2020static INLINE void
    21 LOADMATRIX( const CRmatrix *a )
     21LOADMATRIX(PCRStateTracker pState, const CRmatrix *a )
    2222{
    2323    if (a->m00 == 1.0F && a->m01 == 0.0F && a->m02 == 0.0F && a->m03 == 0.0F &&
     
    2525            a->m20 == 0.0F && a->m21 == 0.0F && a->m22 == 1.0F && a->m23 == 0.0F &&
    2626            a->m30 == 0.0F && a->m31 == 0.0F && a->m32 == 0.0F && a->m33 == 1.0F) {
    27         diff_api.LoadIdentity();
     27        pState->diff_api.LoadIdentity();
    2828    }
    2929    else {
     
    3333        f[8] = a->m20;  f[9] = a->m21;  f[10] = a->m22; f[11] = a->m23;
    3434        f[12] = a->m30; f[13] = a->m31; f[14] = a->m32; f[15] = a->m33;
    35         diff_api.LoadMatrixf(f);
     35        pState->diff_api.LoadMatrixf(f);
    3636    }
    3737}
     
    116116    CRLimitsState *limits = &ctx->limits;
    117117    CRTransformState *t = &ctx->transform;
    118     CRStateBits *sb = GetCurrentBits();
     118    CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    119119    CRTransformBits *tb = &(sb->transform);
    120120    unsigned int i;
     
    215215}
    216216
    217 void STATE_APIENTRY crStateClipPlane (GLenum plane, const GLdouble *equation)
    218 {
    219     CRContext *g = GetCurrentContext();
     217void STATE_APIENTRY crStateClipPlane (PCRStateTracker pState, GLenum plane, const GLdouble *equation)
     218{
     219    CRContext *g = GetCurrentContext(pState);
    220220    CRTransformState *t = &g->transform;
    221     CRStateBits *sb = GetCurrentBits();
     221    CRStateBits *sb = GetCurrentBits(pState);
    222222    CRTransformBits *tb = &(sb->transform);
    223223    GLvectord e;
     
    232232    if (g->current.inBeginEnd)
    233233    {
    234         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     234        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    235235                     "ClipPlane called in begin/end");
    236236        return;
     
    242242    if (i >= g->limits.maxClipPlanes)
    243243    {
    244         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     244        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    245245                     "ClipPlane called with bad enumerant: %d", plane);
    246246        return;
     
    254254}
    255255
    256 void STATE_APIENTRY crStateMatrixMode(GLenum e)
    257 {
    258     CRContext *g = GetCurrentContext();
     256void STATE_APIENTRY crStateMatrixMode(PCRStateTracker pState, GLenum e)
     257{
     258    CRContext *g = GetCurrentContext(pState);
    259259    CRTransformState *t = &(g->transform);
    260260    CRTextureState *tex = &(g->texture);
    261     CRStateBits *sb = GetCurrentBits();
    262     CRTransformBits *tb = &(sb->transform);
    263 
    264     if (g->current.inBeginEnd)
    265     {
    266         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "MatrixMode called in begin/end");
     261    CRStateBits *sb = GetCurrentBits(pState);
     262    CRTransformBits *tb = &(sb->transform);
     263
     264    if (g->current.inBeginEnd)
     265    {
     266        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "MatrixMode called in begin/end");
    267267        return;
    268268    }
     
    307307            }
    308308            else {
    309                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid matrix mode: %d", e);
     309                crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid matrix mode: %d", e);
    310310                return;
    311311            }
     
    329329            }
    330330            else {
    331                  crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid matrix mode: %d", e);
     331                 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid matrix mode: %d", e);
    332332                 return;
    333333            }
    334334            break;
    335335        default:
    336             crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid matrix mode: %d", e);
     336            crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid matrix mode: %d", e);
    337337            return;
    338338    }
     
    343343}
    344344
    345 void STATE_APIENTRY crStateLoadIdentity(void)
    346 {
    347     CRContext *g = GetCurrentContext();
    348     CRTransformState *t = &(g->transform);
    349     CRStateBits *sb = GetCurrentBits();
    350     CRTransformBits *tb = &(sb->transform);
    351 
    352     if (g->current.inBeginEnd)
    353     {
    354         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     345void STATE_APIENTRY crStateLoadIdentity(PCRStateTracker pState)
     346{
     347    CRContext *g = GetCurrentContext(pState);
     348    CRTransformState *t = &(g->transform);
     349    CRStateBits *sb = GetCurrentBits(pState);
     350    CRTransformBits *tb = &(sb->transform);
     351
     352    if (g->current.inBeginEnd)
     353    {
     354        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    355355                                 "LoadIdentity called in begin/end");
    356356        return;
     
    366366}
    367367
    368 void STATE_APIENTRY crStatePopMatrix(void)
    369 {
    370     CRContext *g = GetCurrentContext();
     368void STATE_APIENTRY crStatePopMatrix(PCRStateTracker pState)
     369{
     370    CRContext *g = GetCurrentContext(pState);
    371371    CRTransformState *t = &g->transform;
    372     CRStateBits *sb = GetCurrentBits();
    373     CRTransformBits *tb = &(sb->transform);
    374 
    375     if (g->current.inBeginEnd)
    376     {
    377         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "PopMatrix called in begin/end");
     372    CRStateBits *sb = GetCurrentBits(pState);
     373    CRTransformBits *tb = &(sb->transform);
     374
     375    if (g->current.inBeginEnd)
     376    {
     377        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "PopMatrix called in begin/end");
    378378        return;
    379379    }
     
    383383    if (t->currentStack->depth == 0)
    384384    {
    385         crStateError(__LINE__, __FILE__, GL_STACK_UNDERFLOW, "PopMatrix of empty stack.");
     385        crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW, "PopMatrix of empty stack.");
    386386        return;
    387387    }
     
    398398}
    399399
    400 void STATE_APIENTRY crStatePushMatrix(void)
    401 {
    402     CRContext *g = GetCurrentContext();
     400void STATE_APIENTRY crStatePushMatrix(PCRStateTracker pState)
     401{
     402    CRContext *g = GetCurrentContext(pState);
    403403    CRTransformState *t = &g->transform;
    404     CRStateBits *sb = GetCurrentBits();
    405     CRTransformBits *tb = &(sb->transform);
    406 
    407     if (g->current.inBeginEnd)
    408     {
    409         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "PushMatrix called in begin/end");
     404    CRStateBits *sb = GetCurrentBits(pState);
     405    CRTransformBits *tb = &(sb->transform);
     406
     407    if (g->current.inBeginEnd)
     408    {
     409        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "PushMatrix called in begin/end");
    410410        return;
    411411    }
     
    415415    if (t->currentStack->depth + 1 >= t->currentStack->maxDepth)
    416416    {
    417         crStateError(__LINE__, __FILE__, GL_STACK_OVERFLOW, "PushMatrix pass the end of allocated stack");
     417        crStateError(pState, __LINE__, __FILE__, GL_STACK_OVERFLOW, "PushMatrix pass the end of allocated stack");
    418418        return;
    419419    }
     
    433433
    434434/* Load a CRMatrix */
    435 void crStateLoadMatrix(const CRmatrix *m)
    436 {
    437     CRContext *g = GetCurrentContext();
    438     CRTransformState *t = &(g->transform);
    439     CRStateBits *sb = GetCurrentBits();
    440     CRTransformBits *tb = &(sb->transform);
    441 
    442     if (g->current.inBeginEnd)
    443     {
    444         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     435void crStateLoadMatrix(PCRStateTracker pState, const CRmatrix *m)
     436{
     437    CRContext *g = GetCurrentContext(pState);
     438    CRTransformState *t = &(g->transform);
     439    CRStateBits *sb = GetCurrentBits(pState);
     440    CRTransformBits *tb = &(sb->transform);
     441
     442    if (g->current.inBeginEnd)
     443    {
     444        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    445445                                 "LoadMatrix called in begin/end");
    446446        return;
     
    458458
    459459
    460 void STATE_APIENTRY crStateLoadMatrixf(const GLfloat *m1)
    461 {
    462     CRContext *g = GetCurrentContext();
    463     CRTransformState *t = &(g->transform);
    464     CRStateBits *sb = GetCurrentBits();
    465     CRTransformBits *tb = &(sb->transform);
    466 
    467     if (g->current.inBeginEnd)
    468     {
    469         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     460void STATE_APIENTRY crStateLoadMatrixf(PCRStateTracker pState, const GLfloat *m1)
     461{
     462    CRContext *g = GetCurrentContext(pState);
     463    CRTransformState *t = &(g->transform);
     464    CRStateBits *sb = GetCurrentBits(pState);
     465    CRTransformBits *tb = &(sb->transform);
     466
     467    if (g->current.inBeginEnd)
     468    {
     469        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    470470                                 "LoadMatrixf called in begin/end");
    471471        return;
     
    481481
    482482
    483 void STATE_APIENTRY crStateLoadMatrixd(const GLdouble *m1)
    484 {
    485     CRContext *g = GetCurrentContext();
    486     CRTransformState *t = &(g->transform);
    487     CRStateBits *sb = GetCurrentBits();
    488     CRTransformBits *tb = &(sb->transform);
    489 
    490     if (g->current.inBeginEnd)
    491     {
    492         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     483void STATE_APIENTRY crStateLoadMatrixd(PCRStateTracker pState, const GLdouble *m1)
     484{
     485    CRContext *g = GetCurrentContext(pState);
     486    CRTransformState *t = &(g->transform);
     487    CRStateBits *sb = GetCurrentBits(pState);
     488    CRTransformBits *tb = &(sb->transform);
     489
     490    if (g->current.inBeginEnd)
     491    {
     492        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    493493                                 "LoadMatrixd called in begin/end");
    494494        return;
     
    504504
    505505
    506 void STATE_APIENTRY crStateLoadTransposeMatrixfARB(const GLfloat *m1)
     506void STATE_APIENTRY crStateLoadTransposeMatrixfARB(PCRStateTracker pState, const GLfloat *m1)
    507507{
    508508   GLfloat tm[16];
    509509   if (!m1) return;
    510510   _math_transposef(tm, m1);
    511    crStateLoadMatrixf(tm);
    512 }
    513 
    514 void STATE_APIENTRY crStateLoadTransposeMatrixdARB(const GLdouble *m1)
     511   crStateLoadMatrixf(pState, tm);
     512}
     513
     514void STATE_APIENTRY crStateLoadTransposeMatrixdARB(PCRStateTracker pState, const GLdouble *m1)
    515515{
    516516   GLdouble tm[16];
    517517   if (!m1) return;
    518518   _math_transposed(tm, m1);
    519    crStateLoadMatrixd(tm);
     519   crStateLoadMatrixd(pState, tm);
    520520}
    521521
     
    527527 ** that this really helps.
    528528 */
    529 void STATE_APIENTRY crStateMultMatrixf(const GLfloat *m1)
    530 {
    531     CRContext *g = GetCurrentContext();
    532     CRTransformState *t = &(g->transform);
    533     CRStateBits *sb = GetCurrentBits();
     529void STATE_APIENTRY crStateMultMatrixf(PCRStateTracker pState, const GLfloat *m1)
     530{
     531    CRContext *g = GetCurrentContext(pState);
     532    CRTransformState *t = &(g->transform);
     533    CRStateBits *sb = GetCurrentBits(pState);
    534534    CRTransformBits *tb = &(sb->transform);
    535535    CRmatrix *m = t->currentStack->top;
     
    570570    if (g->current.inBeginEnd)
    571571    {
    572         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "MultMatrixf called in begin/end");
     572        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "MultMatrixf called in begin/end");
    573573        return;
    574574    }
     
    599599}
    600600
    601 void STATE_APIENTRY crStateMultMatrixd(const GLdouble *m1)
    602 {
    603     CRContext *g = GetCurrentContext();
    604     CRTransformState *t = &(g->transform);
    605     CRStateBits *sb = GetCurrentBits();
     601void STATE_APIENTRY crStateMultMatrixd(PCRStateTracker pState, const GLdouble *m1)
     602{
     603    CRContext *g = GetCurrentContext(pState);
     604    CRTransformState *t = &(g->transform);
     605    CRStateBits *sb = GetCurrentBits(pState);
    606606    CRTransformBits *tb = &(sb->transform);
    607607    CRmatrix *m = t->currentStack->top;
     
    641641    if (g->current.inBeginEnd)
    642642    {
    643         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "MultMatrixd called in begin/end");
     643        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "MultMatrixd called in begin/end");
    644644        return;
    645645    }
     
    670670}
    671671
    672 void STATE_APIENTRY crStateMultTransposeMatrixfARB(const GLfloat *m1)
     672void STATE_APIENTRY crStateMultTransposeMatrixfARB(PCRStateTracker pState, const GLfloat *m1)
    673673{
    674674   GLfloat tm[16];
    675675   if (!m1) return;
    676676   _math_transposef(tm, m1);
    677    crStateMultMatrixf(tm);
    678 }
    679 
    680 void STATE_APIENTRY crStateMultTransposeMatrixdARB(const GLdouble *m1)
     677   crStateMultMatrixf(pState, tm);
     678}
     679
     680void STATE_APIENTRY crStateMultTransposeMatrixdARB(PCRStateTracker pState, const GLdouble *m1)
    681681{
    682682   GLdouble tm[16];
    683683   if (!m1) return;
    684684   _math_transposed(tm, m1);
    685    crStateMultMatrixd(tm);
    686 }
    687 
    688 void STATE_APIENTRY crStateTranslatef(GLfloat x_arg, GLfloat y_arg, GLfloat z_arg)
    689 {
    690     CRContext *g = GetCurrentContext();
    691     CRTransformState *t = &(g->transform);
    692     CRStateBits *sb = GetCurrentBits();
    693     CRTransformBits *tb = &(sb->transform);
    694 
    695     if (g->current.inBeginEnd)
    696     {
    697         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     685   crStateMultMatrixd(pState, tm);
     686}
     687
     688void STATE_APIENTRY crStateTranslatef(PCRStateTracker pState, GLfloat x_arg, GLfloat y_arg, GLfloat z_arg)
     689{
     690    CRContext *g = GetCurrentContext(pState);
     691    CRTransformState *t = &(g->transform);
     692    CRStateBits *sb = GetCurrentBits(pState);
     693    CRTransformBits *tb = &(sb->transform);
     694
     695    if (g->current.inBeginEnd)
     696    {
     697        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    698698                                 "Translatef called in begin/end");
    699699        return;
     
    709709
    710710
    711 void STATE_APIENTRY crStateTranslated(GLdouble x_arg, GLdouble y_arg, GLdouble z_arg)
    712 {
    713     CRContext *g = GetCurrentContext();
    714     CRTransformState *t = &(g->transform);
    715     CRStateBits *sb = GetCurrentBits();
    716     CRTransformBits *tb = &(sb->transform);
    717 
    718     if (g->current.inBeginEnd)
    719     {
    720         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     711void STATE_APIENTRY crStateTranslated(PCRStateTracker pState, GLdouble x_arg, GLdouble y_arg, GLdouble z_arg)
     712{
     713    CRContext *g = GetCurrentContext(pState);
     714    CRTransformState *t = &(g->transform);
     715    CRStateBits *sb = GetCurrentBits(pState);
     716    CRTransformBits *tb = &(sb->transform);
     717
     718    if (g->current.inBeginEnd)
     719    {
     720        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    721721                                 "Translated called in begin/end");
    722722        return;
     
    732732
    733733
    734 void STATE_APIENTRY crStateRotatef(GLfloat ang, GLfloat x, GLfloat y, GLfloat z)
    735 {
    736     CRContext *g = GetCurrentContext();
    737     CRTransformState *t = &(g->transform);
    738     CRStateBits *sb = GetCurrentBits();
    739     CRTransformBits *tb = &(sb->transform);
    740 
    741     if (g->current.inBeginEnd)
    742     {
    743         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     734void STATE_APIENTRY crStateRotatef(PCRStateTracker pState, GLfloat ang, GLfloat x, GLfloat y, GLfloat z)
     735{
     736    CRContext *g = GetCurrentContext(pState);
     737    CRTransformState *t = &(g->transform);
     738    CRStateBits *sb = GetCurrentBits(pState);
     739    CRTransformBits *tb = &(sb->transform);
     740
     741    if (g->current.inBeginEnd)
     742    {
     743        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    744744                                 "Rotatef called in begin/end");
    745745        return;
     
    754754}
    755755
    756 void STATE_APIENTRY crStateRotated(GLdouble ang, GLdouble x, GLdouble y, GLdouble z)
    757 {
    758     CRContext *g = GetCurrentContext();
    759     CRTransformState *t = &(g->transform);
    760     CRStateBits *sb = GetCurrentBits();
    761     CRTransformBits *tb = &(sb->transform);
    762 
    763     if (g->current.inBeginEnd)
    764     {
    765         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     756void STATE_APIENTRY crStateRotated(PCRStateTracker pState, GLdouble ang, GLdouble x, GLdouble y, GLdouble z)
     757{
     758    CRContext *g = GetCurrentContext(pState);
     759    CRTransformState *t = &(g->transform);
     760    CRStateBits *sb = GetCurrentBits(pState);
     761    CRTransformBits *tb = &(sb->transform);
     762
     763    if (g->current.inBeginEnd)
     764    {
     765        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    766766                                 "Rotated called in begin/end");
    767767        return;
     
    776776}   
    777777
    778 void STATE_APIENTRY crStateScalef (GLfloat x_arg, GLfloat y_arg, GLfloat z_arg)
    779 {
    780     CRContext *g = GetCurrentContext();
    781     CRTransformState *t = &(g->transform);
    782     CRStateBits *sb = GetCurrentBits();
    783     CRTransformBits *tb = &(sb->transform);
    784 
    785     if (g->current.inBeginEnd)
    786     {
    787         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     778void STATE_APIENTRY crStateScalef (PCRStateTracker pState, GLfloat x_arg, GLfloat y_arg, GLfloat z_arg)
     779{
     780    CRContext *g = GetCurrentContext(pState);
     781    CRTransformState *t = &(g->transform);
     782    CRStateBits *sb = GetCurrentBits(pState);
     783    CRTransformBits *tb = &(sb->transform);
     784
     785    if (g->current.inBeginEnd)
     786    {
     787        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    788788                                 "Scalef called in begin/end");
    789789        return;
     
    798798}
    799799
    800 void STATE_APIENTRY crStateScaled (GLdouble x_arg, GLdouble y_arg, GLdouble z_arg)
    801 {
    802     CRContext *g = GetCurrentContext();
    803     CRTransformState *t = &(g->transform);
    804     CRStateBits *sb = GetCurrentBits();
    805     CRTransformBits *tb = &(sb->transform);
    806 
    807     if (g->current.inBeginEnd)
    808     {
    809         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     800void STATE_APIENTRY crStateScaled (PCRStateTracker pState, GLdouble x_arg, GLdouble y_arg, GLdouble z_arg)
     801{
     802    CRContext *g = GetCurrentContext(pState);
     803    CRTransformState *t = &(g->transform);
     804    CRStateBits *sb = GetCurrentBits(pState);
     805    CRTransformBits *tb = &(sb->transform);
     806
     807    if (g->current.inBeginEnd)
     808    {
     809        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    810810                                 "Scaled called in begin/end");
    811811        return;
     
    820820}
    821821
    822 void STATE_APIENTRY crStateFrustum(GLdouble left, GLdouble right,
     822void STATE_APIENTRY crStateFrustum(PCRStateTracker pState, GLdouble left, GLdouble right,
    823823                                                                     GLdouble bottom, GLdouble top,
    824824                                                                     GLdouble zNear, GLdouble zFar)
    825825{
    826     CRContext *g = GetCurrentContext();
    827     CRTransformState *t = &(g->transform);
    828     CRStateBits *sb = GetCurrentBits();
    829     CRTransformBits *tb = &(sb->transform);
    830 
    831     if (g->current.inBeginEnd)
    832     {
    833         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     826    CRContext *g = GetCurrentContext(pState);
     827    CRTransformState *t = &(g->transform);
     828    CRStateBits *sb = GetCurrentBits(pState);
     829    CRTransformBits *tb = &(sb->transform);
     830
     831    if (g->current.inBeginEnd)
     832    {
     833        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    834834                                 "Frustum called in begin/end");
    835835        return;
     
    844844}
    845845
    846 void STATE_APIENTRY crStateOrtho(GLdouble left, GLdouble right,
     846void STATE_APIENTRY crStateOrtho(PCRStateTracker pState, GLdouble left, GLdouble right,
    847847                                                                 GLdouble bottom, GLdouble top,
    848848                                                                 GLdouble zNear, GLdouble zFar)
    849849{
    850     CRContext *g = GetCurrentContext();
    851     CRTransformState *t = &(g->transform);
    852     CRStateBits *sb = GetCurrentBits();
    853     CRTransformBits *tb = &(sb->transform);
    854 
    855     if (g->current.inBeginEnd)
    856     {
    857         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     850    CRContext *g = GetCurrentContext(pState);
     851    CRTransformState *t = &(g->transform);
     852    CRStateBits *sb = GetCurrentBits(pState);
     853    CRTransformBits *tb = &(sb->transform);
     854
     855    if (g->current.inBeginEnd)
     856    {
     857        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    858858                                 "Ortho called in begin/end");
    859859        return;
     
    868868}
    869869
    870 void STATE_APIENTRY crStateGetClipPlane(GLenum plane, GLdouble *equation)
    871 {
    872     CRContext *g = GetCurrentContext();
     870void STATE_APIENTRY crStateGetClipPlane(PCRStateTracker pState, GLenum plane, GLdouble *equation)
     871{
     872    CRContext *g = GetCurrentContext(pState);
    873873    CRTransformState *t = &g->transform;
    874874    unsigned int i;
     
    876876    if (g->current.inBeginEnd)
    877877    {
    878         crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     878        crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    879879            "glGetClipPlane called in begin/end");
    880880        return;
     
    884884    if (i >= g->limits.maxClipPlanes)
    885885    {
    886         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     886        crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
    887887            "GetClipPlane called with bad enumerant: %d", plane);
    888888        return;
     
    898898                                                         CRContext *fromCtx, CRContext *toCtx )
    899899{
     900    PCRStateTracker pState = fromCtx->pStateTracker;
    900901    const GLuint maxTextureUnits = toCtx->limits.maxTextureUnits;
    901902    CRTransformState *from = &(fromCtx->transform);
     
    905906    CRbitvalue nbitID[CR_MAX_BITARRAY];
    906907
     908    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     909
    907910    for (j=0;j<CR_MAX_BITARRAY;j++)
    908911        nbitID[j] = ~bitID[j];
     
    911914    {
    912915        glAble able[2];
    913         able[0] = diff_api.Disable;
    914         able[1] = diff_api.Enable;
     916        able[0] = pState->diff_api.Disable;
     917        able[1] = pState->diff_api.Enable;
    915918        if (from->normalize != to->normalize) {
    916919            if (to->normalize == GL_TRUE)
    917                 diff_api.Enable(GL_NORMALIZE);
     920                pState->diff_api.Enable(GL_NORMALIZE);
    918921            else
    919                 diff_api.Disable(GL_NORMALIZE);
     922                pState->diff_api.Disable(GL_NORMALIZE);
    920923            FILLDIRTY(t->enable);
    921924            FILLDIRTY(t->dirty);
     
    943946
    944947    if (CHECKDIRTY(t->clipPlane, bitID)) {
    945         diff_api.MatrixMode(GL_MODELVIEW);
    946         diff_api.PushMatrix();
    947         diff_api.LoadIdentity();
     948        pState->diff_api.MatrixMode(GL_MODELVIEW);
     949        pState->diff_api.PushMatrix();
     950        pState->diff_api.LoadIdentity();
    948951        for (i=0; i<CR_MAX_CLIP_PLANES; i++) {
    949952            if (from->clipPlane[i].x != to->clipPlane[i].x ||
     
    958961                cp[3] = to->clipPlane[i].w;
    959962
    960                 diff_api.ClipPlane(GL_CLIP_PLANE0 + i, (const GLdouble *)(cp));
     963                pState->diff_api.ClipPlane(GL_CLIP_PLANE0 + i, (const GLdouble *)(cp));
    961964
    962965                FILLDIRTY(t->clipPlane);
     
    964967            }
    965968        }
    966         diff_api.PopMatrix();
     969        pState->diff_api.PopMatrix();
    967970        CLEARDIRTY(t->clipPlane, nbitID);
    968971    }
     
    986989                !crMatrixIsEqual(to->modelViewStack.top, from->modelViewStack.top))
    987990        {
    988             diff_api.MatrixMode(GL_MODELVIEW);
     991            pState->diff_api.MatrixMode(GL_MODELVIEW);
    989992
    990993            if (fd > td)
     
    992995                for (i = td; i < fd; i++)
    993996                {
    994                     diff_api.PopMatrix();
     997                    pState->diff_api.PopMatrix();
    995998                }
    996999                fd = td;
     
    9991002            for (i = fd; i <= td; i++)
    10001003            {
    1001                 LOADMATRIX(to->modelViewStack.stack + i);
     1004                LOADMATRIX(pState, to->modelViewStack.stack + i);
    10021005                FILLDIRTY(t->modelviewMatrix);
    10031006                FILLDIRTY(t->dirty);
     
    10051008                /* Don't want to push on the current matrix */
    10061009                if (i != to->modelViewStack.depth)
    1007                     diff_api.PushMatrix();
     1010                    pState->diff_api.PushMatrix();
    10081011            }
    10091012        }
     
    10211024                !crMatrixIsEqual(to->projectionStack.top, from->projectionStack.top)) {
    10221025
    1023             diff_api.MatrixMode(GL_PROJECTION);
     1026            pState->diff_api.MatrixMode(GL_PROJECTION);
    10241027
    10251028            if (fd > td)
     
    10271030                for (i = td; i < fd; i++)
    10281031                {
    1029                     diff_api.PopMatrix();
     1032                    pState->diff_api.PopMatrix();
    10301033                }
    10311034                fd = td;
     
    10341037            for (i = fd; i <= td; i++)
    10351038            {
    1036                 LOADMATRIX(to->projectionStack.stack + i);
     1039                LOADMATRIX(pState, to->projectionStack.stack + i);
    10371040                FILLDIRTY(t->projectionMatrix);
    10381041                FILLDIRTY(t->dirty);
     
    10401043                /* Don't want to push on the current matrix */
    10411044                if (i != to->projectionStack.depth)
    1042                     diff_api.PushMatrix();
     1045                    pState->diff_api.PushMatrix();
    10431046            }
    10441047        }
     
    10611064                    !crMatrixIsEqual(to->textureStack[j].top, from->textureStack[j].top))
    10621065            {
    1063                 diff_api.MatrixMode(GL_TEXTURE);
     1066                pState->diff_api.MatrixMode(GL_TEXTURE);
    10641067
    10651068                if (fd > td)
     
    10671070                    for (i = td; i < fd; i++)
    10681071                    {
    1069                         diff_api.PopMatrix();
     1072                        pState->diff_api.PopMatrix();
    10701073                    }
    10711074                    fd = td;
    10721075                }
    10731076
    1074                 diff_api.ActiveTextureARB( j + GL_TEXTURE0_ARB );
     1077                pState->diff_api.ActiveTextureARB( j + GL_TEXTURE0_ARB );
    10751078                for (i = fd; i <= td; i++)
    10761079                {
    1077                     LOADMATRIX(to->textureStack[j].stack + i);
     1080                    LOADMATRIX(pState, to->textureStack[j].stack + i);
    10781081                    FILLDIRTY(t->textureMatrix);
    10791082                    FILLDIRTY(t->dirty);
     
    10811084                    /* Don't want to push on the current matrix */
    10821085                    if (i != to->textureStack[j].depth)
    1083                         diff_api.PushMatrix();
     1086                        pState->diff_api.PushMatrix();
    10841087                }
    10851088            }
     
    10881091         * proper value now. 
    10891092         */
    1090         diff_api.ActiveTextureARB(GL_TEXTURE0_ARB + toCtx->texture.curTextureUnit);
     1093        pState->diff_api.ActiveTextureARB(GL_TEXTURE0_ARB + toCtx->texture.curTextureUnit);
    10911094        CLEARDIRTY(t->textureMatrix, nbitID);
    10921095    }
     
    11001103        if (td != fd || !crMatrixIsEqual(to->colorStack.top, from->colorStack.top))
    11011104        {
    1102             diff_api.MatrixMode(GL_COLOR);
     1105            pState->diff_api.MatrixMode(GL_COLOR);
    11031106
    11041107            if (fd > td)
     
    11061109                for (i = td; i < fd; i++)
    11071110                {
    1108                     diff_api.PopMatrix();
     1111                    pState->diff_api.PopMatrix();
    11091112                }
    11101113                fd = td;
     
    11131116            for (i = fd; i <= td; i++)
    11141117            {
    1115                 LOADMATRIX(to->colorStack.stack + i);
     1118                LOADMATRIX(pState, to->colorStack.stack + i);
    11161119                FILLDIRTY(t->colorMatrix);
    11171120                FILLDIRTY(t->dirty);
     
    11191122                /* Don't want to push on the current matrix */
    11201123                if (i != to->colorStack.depth)
    1121                     diff_api.PushMatrix();
     1124                    pState->diff_api.PushMatrix();
    11221125            }
    11231126        }
     
    11311134     * set it to the proper value now. 
    11321135     */
    1133     diff_api.MatrixMode(to->matrixMode);
     1136    pState->diff_api.MatrixMode(to->matrixMode);
    11341137
    11351138    /* sanity tests */
     
    11431146                                            CRContext *fromCtx, CRContext *toCtx )
    11441147{
     1148    PCRStateTracker pState = fromCtx->pStateTracker;
    11451149    const GLuint maxTextureUnits = toCtx->limits.maxTextureUnits;
    11461150    CRTransformState *from = &(fromCtx->transform);
     
    11511155    CRbitvalue nbitID[CR_MAX_BITARRAY];
    11521156
     1157    CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
     1158
    11531159    for (j=0;j<CR_MAX_BITARRAY;j++)
    11541160        nbitID[j] = ~bitID[j];
     
    11561162    if (CHECKDIRTY(t->enable, bitID)) {
    11571163        glAble able[2];
    1158         able[0] = diff_api.Disable;
    1159         able[1] = diff_api.Enable;
     1164        able[0] = pState->diff_api.Disable;
     1165        able[1] = pState->diff_api.Enable;
    11601166        for (i=0; i<CR_MAX_CLIP_PLANES; i++) {
    11611167            if (from->clip[i] != to->clip[i]) {
    11621168                if (to->clip[i] == GL_TRUE)
    1163                     diff_api.Enable(GL_CLIP_PLANE0 + i);
     1169                    pState->diff_api.Enable(GL_CLIP_PLANE0 + i);
    11641170                else
    1165                     diff_api.Disable(GL_CLIP_PLANE0 + i);
     1171                    pState->diff_api.Disable(GL_CLIP_PLANE0 + i);
    11661172                from->clip[i] = to->clip[i];
    11671173            }
     
    11691175        if (from->normalize != to->normalize) {
    11701176            if (to->normalize == GL_TRUE)
    1171                 diff_api.Enable(GL_NORMALIZE);
     1177                pState->diff_api.Enable(GL_NORMALIZE);
    11721178            else
    1173                 diff_api.Disable(GL_NORMALIZE);
     1179                pState->diff_api.Disable(GL_NORMALIZE);
    11741180            from->normalize = to->normalize;
    11751181        }
     
    11941200    if (CHECKDIRTY(t->clipPlane, bitID)) {
    11951201        if (from->matrixMode != GL_MODELVIEW) {
    1196             diff_api.MatrixMode(GL_MODELVIEW);
     1202            pState->diff_api.MatrixMode(GL_MODELVIEW);
    11971203            from->matrixMode = GL_MODELVIEW;
    11981204        }
    1199         diff_api.PushMatrix();
    1200         diff_api.LoadIdentity();
     1205        pState->diff_api.PushMatrix();
     1206        pState->diff_api.LoadIdentity();
    12011207        for (i=0; i<CR_MAX_CLIP_PLANES; i++) {
    12021208            if (from->clipPlane[i].x != to->clipPlane[i].x ||
     
    12111217                cp[3] = to->clipPlane[i].w;
    12121218
    1213                 diff_api.ClipPlane(GL_CLIP_PLANE0 + i, (const GLdouble *)(cp));
     1219                pState->diff_api.ClipPlane(GL_CLIP_PLANE0 + i, (const GLdouble *)(cp));
    12141220                from->clipPlane[i] = to->clipPlane[i];
    12151221            }
    12161222        }
    1217         diff_api.PopMatrix();
     1223        pState->diff_api.PopMatrix();
    12181224        CLEARDIRTY(t->clipPlane, nbitID);
    12191225    }
     
    12321238    {
    12331239        if (from->matrixMode != GL_MODELVIEW) {
    1234             diff_api.MatrixMode(GL_MODELVIEW);
     1240            pState->diff_api.MatrixMode(GL_MODELVIEW);
    12351241            from->matrixMode = GL_MODELVIEW;
    12361242        }
     
    12401246            for (i = to->modelViewStack.depth; i < from->modelViewStack.depth; i++)
    12411247            {
    1242                 diff_api.PopMatrix();
     1248                pState->diff_api.PopMatrix();
    12431249            }
    12441250
     
    12481254        for (i = from->modelViewStack.depth; i <= to->modelViewStack.depth; i++)
    12491255        {
    1250             LOADMATRIX(to->modelViewStack.stack + i);
     1256            LOADMATRIX(pState, to->modelViewStack.stack + i);
    12511257            from->modelViewStack.stack[i] = to->modelViewStack.stack[i];
    12521258
    12531259            /* Don't want to push on the current matrix */
    12541260            if (i != to->modelViewStack.depth)
    1255                 diff_api.PushMatrix();
     1261                pState->diff_api.PushMatrix();
    12561262        }
    12571263        from->modelViewStack.depth = to->modelViewStack.depth;
     
    12661272    {
    12671273        if (from->matrixMode != GL_PROJECTION) {
    1268             diff_api.MatrixMode(GL_PROJECTION);
     1274            pState->diff_api.MatrixMode(GL_PROJECTION);
    12691275            from->matrixMode = GL_PROJECTION;
    12701276        }
     
    12741280            for (i = to->projectionStack.depth; i < from->projectionStack.depth; i++)
    12751281            {
    1276                 diff_api.PopMatrix();
     1282                pState->diff_api.PopMatrix();
    12771283            }
    12781284
     
    12821288        for (i = from->projectionStack.depth; i <= to->projectionStack.depth; i++)
    12831289        {
    1284             LOADMATRIX(to->projectionStack.stack + i);
     1290            LOADMATRIX(pState, to->projectionStack.stack + i);
    12851291            from->projectionStack.stack[i] = to->projectionStack.stack[i];
    12861292
    12871293            /* Don't want to push on the current matrix */
    12881294            if (i != to->projectionStack.depth)
    1289                 diff_api.PushMatrix();
     1295                pState->diff_api.PushMatrix();
    12901296        }
    12911297        from->projectionStack.depth = to->projectionStack.depth;
     
    13031309    {
    13041310        if (from->matrixMode != GL_TEXTURE) {
    1305             diff_api.MatrixMode(GL_TEXTURE);
     1311            pState->diff_api.MatrixMode(GL_TEXTURE);
    13061312            from->matrixMode = GL_TEXTURE;
    13071313        }
     
    13111317            {
    13121318                if (textureFrom->curTextureUnit != j) {
    1313                     diff_api.ActiveTextureARB( j + GL_TEXTURE0_ARB );
     1319                    pState->diff_api.ActiveTextureARB( j + GL_TEXTURE0_ARB );
    13141320                    textureFrom->curTextureUnit = j;
    13151321                }
    13161322                for (i = to->textureStack[j].depth; i < from->textureStack[j].depth; i++)
    13171323                {
    1318                     diff_api.PopMatrix();
     1324                    pState->diff_api.PopMatrix();
    13191325                }
    13201326   
     
    13251331            {
    13261332                if (textureFrom->curTextureUnit != j) {
    1327                     diff_api.ActiveTextureARB( j + GL_TEXTURE0_ARB );
     1333                    pState->diff_api.ActiveTextureARB( j + GL_TEXTURE0_ARB );
    13281334                    textureFrom->curTextureUnit = j;
    13291335                }
    1330                 LOADMATRIX(to->textureStack[j].stack + i);
     1336                LOADMATRIX(pState, to->textureStack[j].stack + i);
    13311337                from->textureStack[j].stack[i] = to->textureStack[j].stack[i];
    13321338
    13331339                /* Don't want to push on the current matrix */
    13341340                if (i != to->textureStack[j].depth)
    1335                     diff_api.PushMatrix();
     1341                    pState->diff_api.PushMatrix();
    13361342            }
    13371343            from->textureStack[j].depth = to->textureStack[j].depth;
     
    13411347
    13421348        /* Restore proper active texture unit */
    1343         diff_api.ActiveTextureARB(GL_TEXTURE0_ARB + toCtx->texture.curTextureUnit);
     1349        pState->diff_api.ActiveTextureARB(GL_TEXTURE0_ARB + toCtx->texture.curTextureUnit);
    13441350    }
    13451351
     
    13491355    {
    13501356        if (from->matrixMode != GL_COLOR) {
    1351             diff_api.MatrixMode(GL_COLOR);
     1357            pState->diff_api.MatrixMode(GL_COLOR);
    13521358            from->matrixMode = GL_COLOR;
    13531359        }
     
    13571363            for (i = to->colorStack.depth; i < from->colorStack.depth; i++)
    13581364            {
    1359                 diff_api.PopMatrix();
     1365                pState->diff_api.PopMatrix();
    13601366            }
    13611367
     
    13651371        for (i = to->colorStack.depth; i <= to->colorStack.depth; i++)
    13661372        {
    1367             LOADMATRIX(to->colorStack.stack + i);
     1373            LOADMATRIX(pState, to->colorStack.stack + i);
    13681374            from->colorStack.stack[i] = to->colorStack.stack[i];
    13691375
    13701376            /* Don't want to push on the current matrix */
    13711377            if (i != to->colorStack.depth)
    1372                 diff_api.PushMatrix();
     1378                pState->diff_api.PushMatrix();
    13731379        }
    13741380        from->colorStack.depth = to->colorStack.depth;
     
    13831389    /* update MatrixMode now */
    13841390    if (from->matrixMode != to->matrixMode) {
    1385         diff_api.MatrixMode(to->matrixMode);
     1391        pState->diff_api.MatrixMode(to->matrixMode);
    13861392        from->matrixMode = to->matrixMode;
    13871393    }
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_viewport.c

    r69392 r78375  
    1313{
    1414        CRViewportState *v = &ctx->viewport;
    15         CRStateBits *sb = GetCurrentBits();
     15        CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
    1616        CRViewportBits *vb = &(sb->viewport);
    1717        CRTransformBits *tb = &(sb->transform);
     
    5656}
    5757
    58 void STATE_APIENTRY crStateViewport(GLint x, GLint y, GLsizei width,
     58void STATE_APIENTRY crStateViewport(PCRStateTracker pState, GLint x, GLint y, GLsizei width,
    5959                        GLsizei height)
    6060{
    61         CRContext *g = GetCurrentContext();
     61        CRContext *g = GetCurrentContext(pState);
    6262        CRViewportState *v = &(g->viewport);
    63         CRStateBits *sb = GetCurrentBits();
     63        CRStateBits *sb = GetCurrentBits(pState);
    6464        CRViewportBits *vb = &(sb->viewport);
    6565        CRTransformBits *tb = &(sb->transform);
     
    6767        if (g->current.inBeginEnd)
    6868        {
    69                 crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION,
     69                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    7070                                                                        "calling glViewport() between glBegin/glEnd" );
    7171                return;
     
    7676        if (width < 0 || height < 0)
    7777        {
    78                 crStateError( __LINE__, __FILE__, GL_INVALID_VALUE,
     78                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    7979                                                                        "glViewport(bad width or height)" );
    8080                return;
     
    102102}
    103103
    104 void STATE_APIENTRY crStateDepthRange(GLclampd znear, GLclampd zfar)
     104void STATE_APIENTRY crStateDepthRange(PCRStateTracker pState, GLclampd znear, GLclampd zfar)
    105105{
    106         CRContext *g = GetCurrentContext();
     106        CRContext *g = GetCurrentContext(pState);
    107107        CRViewportState *v = &(g->viewport);
    108         CRStateBits *sb = GetCurrentBits();
     108        CRStateBits *sb = GetCurrentBits(pState);
    109109        CRViewportBits *vb = &(sb->viewport);
    110110        CRTransformBits *tb = &(sb->transform);
     
    112112        if (g->current.inBeginEnd)
    113113        {       
    114                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDepthRange called in Begin/End");
     114                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glDepthRange called in Begin/End");
    115115                return;
    116116        }
     
    130130}
    131131
    132 void STATE_APIENTRY crStateScissor (GLint x, GLint y,
     132void STATE_APIENTRY crStateScissor (PCRStateTracker pState, GLint x, GLint y,
    133133                                         GLsizei width, GLsizei height)
    134134{
    135         CRContext *g = GetCurrentContext();
     135        CRContext *g = GetCurrentContext(pState);
    136136        CRViewportState *v = &(g->viewport);
    137         CRStateBits *sb = GetCurrentBits();
     137        CRStateBits *sb = GetCurrentBits(pState);
    138138        CRViewportBits *vb = &(sb->viewport);
    139139
    140140        if (g->current.inBeginEnd)
    141141        {
    142                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     142                crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
    143143                        "glScissor called in begin/end");
    144144                return;
     
    149149        if (width < 0 || height < 0)
    150150        {
    151                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     151                crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
    152152                        "glScissor called with negative width/height: %d,%d",
    153153                        width, height);
  • trunk/src/VBox/HostServices/SharedOpenGL/crserver/crservice.cpp

    r78267 r78375  
    15821582        case DLL_THREAD_ATTACH:
    15831583        {
    1584             crStateVBoxAttachThread();
     1584            crVBoxServerAttachThread();
    15851585            break;
    15861586        }
     
    15911591        case DLL_THREAD_DETACH:
    15921592        {
    1593             crStateVBoxDetachThread();
     1593            crVBoxServerDetachThread();
    15941594            break;
    15951595        }
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/presenter/server_presenter.cpp

    r78264 r78375  
    975975
    976976        crStateReleaseTexture(cr_server.MainContextInfo.pContext, pTobj);
    977 
    978 
    979         crStateGlobalSharedRelease();
     977        crStateGlobalSharedRelease(&cr_server.StateTracker);
    980978    }
    981979
     
    10261024    }
    10271025
    1028     CRSharedState *pShared = crStateGlobalSharedAcquire();
     1026    CRSharedState *pShared = crStateGlobalSharedAcquire(&cr_server.StateTracker);
    10291027    if (!pShared)
    10301028    {
     
    10371035    {
    10381036        LOG(("pTobj is null!"));
    1039         crStateGlobalSharedRelease();
     1037        crStateGlobalSharedRelease(&cr_server.StateTracker);
    10401038        return NULL;
    10411039    }
     
    10431041    Assert(pTobj->id == idTexture);
    10441042
    1045     GLuint hwid = crStateGetTextureObjHWID(pTobj);
     1043    GLuint hwid = crStateGetTextureObjHWID(&cr_server.StateTracker, pTobj);
    10461044    if (!hwid)
    10471045    {
    10481046        WARN(("hwId is null!"));
    1049         crStateGlobalSharedRelease();
     1047        crStateGlobalSharedRelease(&cr_server.StateTracker);
    10501048        return NULL;
    10511049    }
     
    10611059    {
    10621060        WARN(("crFbTexCreate failed!"));
    1063         crStateGlobalSharedRelease();
     1061        crStateGlobalSharedRelease(&cr_server.StateTracker);
    10641062        return NULL;
    10651063    }
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server.h

    r78263 r78375  
    341341    CRContext *pCurCtx = pCurCtxInfo ? pCurCtxInfo->pContext : NULL;
    342342
    343     CRASSERT(pCurCtx == crStateGetCurrent());
     343    CRASSERT(pCurCtx == crStateGetCurrent(&cr_server.StateTracker));
    344344
    345345    if (pCurrentMural)
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_bufferobject.cpp

    r78263 r78375  
    4646    }
    4747
    48     crStateGenBuffersARB(n, local_buffers);
     48    crStateGenBuffersARB(&cr_server.StateTracker, n, local_buffers);
    4949
    5050    crServerReturnValue( local_buffers, n * sizeof(*local_buffers) );
     
    6060    }
    6161
    62     crStateDeleteBuffersARB( n, buffer );
     62    crStateDeleteBuffersARB(&cr_server.StateTracker, n, buffer );
    6363}
    6464
     
    101101crServerDispatchBindBufferARB(GLenum target, GLuint buffer)
    102102{
    103     crStateBindBufferARB(target, buffer);
    104     cr_server.head_spu->dispatch_table.BindBufferARB(target, crStateGetBufferHWID(buffer));
     103    crStateBindBufferARB(&cr_server.StateTracker, target, buffer);
     104    cr_server.head_spu->dispatch_table.BindBufferARB(target, crStateGetBufferHWID(&cr_server.StateTracker, buffer));
    105105}
    106106
     
    110110    /* since GenBuffersARB issued to host ogl only on bind + some other ops, the host drivers may not know about them
    111111     * so use state data*/
    112     GLboolean retval = crStateIsBufferARB(buffer);
     112    GLboolean retval = crStateIsBufferARB(&cr_server.StateTracker, buffer);
    113113    crServerReturnValue( &retval, sizeof(retval) );
    114114    return retval; /* WILL PROBABLY BE IGNORED */
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_clear.cpp

    r78263 r78375  
    423423                window = 0;
    424424
    425         ctx = crStateGetCurrent();
     425        ctx = crStateGetCurrent(&cr_server.StateTracker);
    426426
    427427        CRASSERT(cr_server.curClient && cr_server.curClient->currentMural == mural);
     
    449449crServerDispatchFlush(void)
    450450{
    451     CRContext *ctx = crStateGetCurrent();
     451    CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    452452    cr_server.head_spu->dispatch_table.Flush();
    453453
     
    470470crServerDispatchFinish(void)
    471471{
    472     CRContext *ctx = crStateGetCurrent();
     472    CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    473473
    474474    cr_server.head_spu->dispatch_table.Finish();
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_context.cpp

    r78263 r78375  
    6363            return -1;
    6464        }
    65         cr_server.MainContextInfo.pContext = crStateCreateContext(&cr_server.limits, visualBits, NULL);
     65        cr_server.MainContextInfo.pContext = crStateCreateContext(&cr_server.StateTracker, &cr_server.limits, visualBits, NULL);
    6666        CRASSERT(cr_server.MainContextInfo.pContext);
    6767        cr_server.firstCallCreateContext = GL_FALSE;
     
    114114        if (pContextInfo->SpuContext < 0) {
    115115            crWarning("crServerDispatchCreateContext() failed.");
    116             crStateEnableDiffOnMakeCurrent(GL_TRUE);
     116            crStateEnableDiffOnMakeCurrent(&cr_server.StateTracker, GL_TRUE);
    117117            cr_server.bUseMultipleContexts = GL_FALSE;
    118118            if (!fFirst)
     
    121121        else if (fFirst)
    122122        {
    123             crStateEnableDiffOnMakeCurrent(GL_FALSE);
     123            crStateEnableDiffOnMakeCurrent(&cr_server.StateTracker, GL_FALSE);
    124124        }
    125125    }
     
    132132     * dispatch function pointers.
    133133     */
    134     newCtx = crStateCreateContextEx(&cr_server.limits, visualBits, NULL, internalID);
     134    newCtx = crStateCreateContextEx(&cr_server.StateTracker, &cr_server.limits, visualBits, NULL, internalID);
    135135    if (newCtx) {
    136         crStateSetCurrentPointers( newCtx, &(cr_server.current) );
     136        crStateSetCurrentPointers(newCtx, &(cr_server.current) );
    137137        crStateResetCurrentPointers(&(cr_server.current));
    138138        retVal = preloadCtxID<0 ? (GLint)crHashtableAllocKeys( cr_server.contextTable, 1 ) : preloadCtxID;
     
    214214    crCtxInfo->currentMural = NULL;
    215215    crHashtableDelete(cr_server.contextTable, ctx, NULL);
    216     crStateDestroyContext( crCtx );
     216    crStateDestroyContext(&cr_server.StateTracker, crCtx);
    217217
    218218    if (crCtxInfo->CreateInfo.pszDpyName)
     
    306306     * crStateSwitchPrepare restores the FBO state to its default values before the context window switch,
    307307     * while crStateSwitchPostprocess restores it back to the original values */
    308     oldCtx = crStateGetCurrent();
     308    oldCtx = crStateGetCurrent(&cr_server.StateTracker);
    309309    if (oldMural && oldMural->fRedirected && crServerSupportRedirMuralFBO())
    310310    {
     
    335335
    336336    /* This is a hack to force updating the 'current' attribs */
    337     crStateUpdateColorBits();
     337    crStateUpdateColorBits(&cr_server.StateTracker);
    338338
    339339    if (ctx)
    340         crStateSetCurrentPointers( ctx, &(cr_server.current) );
     340        crStateSetCurrentPointers(ctx, &(cr_server.current) );
    341341
    342342    /* check if being made current for first time, update viewport */
     
    387387
    388388    /* This used to be earlier, after crStateUpdateColorBits() call */
    389     crStateMakeCurrent( ctx );
     389    crStateMakeCurrent(&cr_server.StateTracker, ctx );
    390390
    391391    if (mural && mural->fRedirected  && crServerSupportRedirMuralFBO())
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_dispatch.py

    r78190 r78375  
    3737    print('void SERVER_DISPATCH_APIENTRY crServerDispatch%s(%s)' % ( func_name, apiutil.MakeDeclarationStringForDispatcher( params ) ))
    3838    print('{')
    39     print('\tcrState%s(%s);' % (func_name, apiutil.MakeCallStringForDispatcher( params ) ))
     39    if len(params) == 0:
     40        print('\tcrState%s(&cr_server.StateTracker);' % (func_name))
     41    else:
     42        print('\tcrState%s(&cr_server.StateTracker, %s);' % (func_name, apiutil.MakeCallStringForDispatcher( params ) ))
    4043    print('\tcr_server.head_spu->dispatch_table.%s(%s);' % (func_name, apiutil.MakeCallStringForDispatcher( params ) ))
    4144    print('}')
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_framebuffer.cpp

    r78190 r78375  
    3838    local_buffers = (GLuint *)crCalloc(n * sizeof(*local_buffers));
    3939
    40     crStateGenFramebuffersEXT(n, local_buffers);
     40    crStateGenFramebuffersEXT(&cr_server.StateTracker, n, local_buffers);
    4141
    4242    crServerReturnValue(local_buffers, n * sizeof(*local_buffers));
     
    5858    local_buffers = (GLuint *)crCalloc(n * sizeof(*local_buffers));
    5959
    60     crStateGenRenderbuffersEXT(n, local_buffers);
     60    crStateGenRenderbuffersEXT(&cr_server.StateTracker, n, local_buffers);
    6161
    6262    crServerReturnValue(local_buffers, n * sizeof(*local_buffers));
     
    6666void SERVER_DISPATCH_APIENTRY crServerDispatchFramebufferTexture1DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
    6767{
    68     crStateFramebufferTexture1DEXT(target, attachment, textarget, texture, level);
    69     cr_server.head_spu->dispatch_table.FramebufferTexture1DEXT(target, attachment, textarget, crStateGetTextureHWID(texture), level);
     68    crStateFramebufferTexture1DEXT(&cr_server.StateTracker, target, attachment, textarget, texture, level);
     69    cr_server.head_spu->dispatch_table.FramebufferTexture1DEXT(target, attachment, textarget, crStateGetTextureHWID(&cr_server.StateTracker, texture), level);
    7070}
    7171
    7272void SERVER_DISPATCH_APIENTRY crServerDispatchFramebufferTexture2DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
    7373{
    74     crStateFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
    75     cr_server.head_spu->dispatch_table.FramebufferTexture2DEXT(target, attachment, textarget, crStateGetTextureHWID(texture), level);
     74    crStateFramebufferTexture2DEXT(&cr_server.StateTracker, target, attachment, textarget, texture, level);
     75    cr_server.head_spu->dispatch_table.FramebufferTexture2DEXT(target, attachment, textarget, crStateGetTextureHWID(&cr_server.StateTracker, texture), level);
    7676}
    7777
    7878void SERVER_DISPATCH_APIENTRY crServerDispatchFramebufferTexture3DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset)
    7979{
    80     crStateFramebufferTexture3DEXT(target, attachment, textarget, texture, level, zoffset);
    81     cr_server.head_spu->dispatch_table.FramebufferTexture3DEXT(target, attachment, textarget, crStateGetTextureHWID(texture), level, zoffset);
     80    crStateFramebufferTexture3DEXT(&cr_server.StateTracker, target, attachment, textarget, texture, level, zoffset);
     81    cr_server.head_spu->dispatch_table.FramebufferTexture3DEXT(target, attachment, textarget, crStateGetTextureHWID(&cr_server.StateTracker, texture), level, zoffset);
    8282}
    8383
     
    8787    GLint rfb = 0, dfb = 0;
    8888#endif
    89         crStateBindFramebufferEXT(target, framebuffer);
     89    crStateBindFramebufferEXT(&cr_server.StateTracker, target, framebuffer);
    9090
    9191    if (0==framebuffer)
    9292    {
    93         CRContext *ctx = crStateGetCurrent();
     93        CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    9494        if (ctx->buffer.drawBuffer == GL_FRONT || ctx->buffer.drawBuffer == GL_FRONT_LEFT || ctx->buffer.drawBuffer == GL_FRONT_RIGHT)
    9595            cr_server.curClient->currentMural->bFbDraw = GL_TRUE;
     
    149149    else
    150150    {
    151         cr_server.head_spu->dispatch_table.BindFramebufferEXT(target, crStateGetFramebufferHWID(framebuffer));
     151        cr_server.head_spu->dispatch_table.BindFramebufferEXT(target, crStateGetFramebufferHWID(&cr_server.StateTracker, framebuffer));
    152152#ifdef DEBUG_misha
    153153        cr_server.head_spu->dispatch_table.GetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &rfb);
     
    155155        if (GL_FRAMEBUFFER_EXT == target)
    156156        {
    157             Assert(rfb == crStateGetFramebufferHWID(framebuffer));
    158             Assert(dfb == crStateGetFramebufferHWID(framebuffer));
     157            Assert(rfb == crStateGetFramebufferHWID(&cr_server.StateTracker, framebuffer));
     158            Assert(dfb == crStateGetFramebufferHWID(&cr_server.StateTracker, framebuffer));
    159159        }
    160160        else if (GL_READ_FRAMEBUFFER_EXT == target)
    161161        {
    162             Assert(rfb == crStateGetFramebufferHWID(framebuffer));
     162            Assert(rfb == crStateGetFramebufferHWID(&cr_server.StateTracker, framebuffer));
    163163        }
    164164        else if (GL_DRAW_FRAMEBUFFER_EXT == target)
    165165        {
    166             Assert(dfb == crStateGetFramebufferHWID(framebuffer));
     166            Assert(dfb == crStateGetFramebufferHWID(&cr_server.StateTracker, framebuffer));
    167167        }
    168168        else
     
    176176void SERVER_DISPATCH_APIENTRY crServerDispatchBindRenderbufferEXT(GLenum target, GLuint renderbuffer)
    177177{
    178         crStateBindRenderbufferEXT(target, renderbuffer);
    179         cr_server.head_spu->dispatch_table.BindRenderbufferEXT(target, crStateGetRenderbufferHWID(renderbuffer));
     178        crStateBindRenderbufferEXT(&cr_server.StateTracker, target, renderbuffer);
     179        cr_server.head_spu->dispatch_table.BindRenderbufferEXT(target, crStateGetRenderbufferHWID(&cr_server.StateTracker, renderbuffer));
    180180}
    181181
     
    188188    }
    189189
    190     crStateDeleteFramebuffersEXT(n, framebuffers);
     190    crStateDeleteFramebuffersEXT(&cr_server.StateTracker, n, framebuffers);
    191191}
    192192
     
    199199    }
    200200
    201     crStateDeleteRenderbuffersEXT(n, renderbuffers);
     201    crStateDeleteRenderbuffersEXT(&cr_server.StateTracker, n, renderbuffers);
    202202}
    203203
     
    205205crServerDispatchFramebufferRenderbufferEXT(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
    206206{
    207         crStateFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, renderbuffer);
    208         cr_server.head_spu->dispatch_table.FramebufferRenderbufferEXT(target, attachment, renderbuffertarget, crStateGetRenderbufferHWID(renderbuffer));
     207        crStateFramebufferRenderbufferEXT(&cr_server.StateTracker, target, attachment, renderbuffertarget, renderbuffer);
     208        cr_server.head_spu->dispatch_table.FramebufferRenderbufferEXT(target, attachment, renderbuffertarget, crStateGetRenderbufferHWID(&cr_server.StateTracker, renderbuffer));
    209209}
    210210
     
    214214        GLint local_params[1];
    215215        (void) params;
    216         crStateGetFramebufferAttachmentParameterivEXT(target, attachment, pname, local_params);
     216        crStateGetFramebufferAttachmentParameterivEXT(&cr_server.StateTracker, target, attachment, pname, local_params);
    217217
    218218        crServerReturnValue(&(local_params[0]), 1*sizeof(GLint));
     
    223223    /* since GenFramebuffers/Renderbuffers issued to host ogl only on bind + some other ops, the host drivers may not know about them
    224224     * so use state data*/
    225     GLboolean retval = crStateIsFramebufferEXT(framebuffer);
     225    GLboolean retval = crStateIsFramebufferEXT(&cr_server.StateTracker, framebuffer);
    226226    crServerReturnValue( &retval, sizeof(retval) );
    227227    return retval; /* WILL PROBABLY BE IGNORED */
     
    232232    /* since GenFramebuffers/Renderbuffers issued to host ogl only on bind + some other ops, the host drivers may not know about them
    233233     * so use state data*/
    234     GLboolean retval = crStateIsRenderbufferEXT(renderbuffer);
     234    GLboolean retval = crStateIsRenderbufferEXT(&cr_server.StateTracker, renderbuffer);
    235235    crServerReturnValue( &retval, sizeof(retval) );
    236236    return retval; /* WILL PROBABLY BE IGNORED */
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_gentextures.cpp

    r78190 r78375  
    3131    }
    3232
    33     crStateGenTextures(n, local_textures);
     33    crStateGenTextures(&cr_server.StateTracker, n, local_textures);
    3434
    3535    crServerReturnValue(local_textures, n*sizeof(*local_textures));
     
    112112    {
    113113        GLuint tID = crServerTranslateProgramID(local_progs[i]);
    114         while (crStateIsProgramARB(tID))
     114        while (crStateIsProgramARB(&cr_server.StateTracker, tID))
    115115        {
    116116            cr_server.head_spu->dispatch_table.GenProgramsARB(1, &tID);
     
    138138    }
    139139
    140     crStateCopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
     140    crStateCopyTexImage2D(&cr_server.StateTracker, target, level, internalFormat, x, y, width, height, border);
    141141    cr_server.head_spu->dispatch_table.CopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
    142142}
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_get.py

    r78105 r78375  
    138138        if func_name in convert_bufferid:
    139139            print('\tif (pname==GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB){')
    140             print('\t\tlocal_params[0]=(%s)crStateBufferHWIDtoID((GLint)local_params[0]);' % (local_argtype))
     140            print('\t\tlocal_params[0]=(%s)crStateBufferHWIDtoID(&cr_server.StateTracker, (GLint)local_params[0]);' % (local_argtype))
    141141            print('\t}')
    142142
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_getpixelmap.cpp

    r78190 r78375  
    6464{
    6565#ifdef CR_ARB_pixel_buffer_object
    66     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     66    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    6767    {
    6868        GLvoid *pbo_offset;
     
    9191{
    9292#ifdef CR_ARB_pixel_buffer_object
    93     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     93    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    9494    {
    9595        GLvoid *pbo_offset;
     
    118118{
    119119#ifdef CR_ARB_pixel_buffer_object
    120     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     120    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    121121    {
    122122        GLvoid *pbo_offset;
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_getshaders.cpp

    r78263 r78375  
    5252    }
    5353
    54     cr_server.head_spu->dispatch_table.GetActiveAttrib(crStateGetProgramHWID(program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
     54    cr_server.head_spu->dispatch_table.GetActiveAttrib(crStateGetProgramHWID(&cr_server.StateTracker, program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
    5555    crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
    5656    crFree(pLocal);
     
    7474    }
    7575
    76     cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
     76    cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(&cr_server.StateTracker, program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
    7777    crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
    7878    crFree(pLocal);
     
    9696    /* initial (fallback )value */
    9797    *pLocal = 0;
    98     cr_server.head_spu->dispatch_table.GetAttachedShaders(crStateGetProgramHWID(program), maxCount, pLocal, (GLuint*)&pLocal[1]);
     98    cr_server.head_spu->dispatch_table.GetAttachedShaders(crStateGetProgramHWID(&cr_server.StateTracker, program), maxCount, pLocal, (GLuint*)&pLocal[1]);
    9999
    100100    {
     
    103103
    104104        for (i=0; i<*pLocal; ++i)
    105           ids[i] = crStateGLSLShaderHWIDtoID(ids[i]);
     105          ids[i] = crStateGLSLShaderHWIDtoID(&cr_server.StateTracker, ids[i]);
    106106    }
    107107
     
    127127    /* initial (fallback )value */
    128128    *pLocal = 0;
    129     cr_server.head_spu->dispatch_table.GetAttachedObjectsARB(crStateGetProgramHWID(containerObj), maxCount, pLocal, (VBoxGLhandleARB*)&pLocal[1]);
     129    cr_server.head_spu->dispatch_table.GetAttachedObjectsARB(crStateGetProgramHWID(&cr_server.StateTracker, containerObj), maxCount, pLocal, (VBoxGLhandleARB*)&pLocal[1]);
    130130
    131131    {
     
    134134
    135135        for (i=0; i<*pLocal; ++i)
    136           ids[i] = crStateGLSLShaderHWIDtoID(ids[i]);
     136          ids[i] = crStateGLSLShaderHWIDtoID(&cr_server.StateTracker, ids[i]);
    137137    }
    138138
     
    162162    *pLocal = 0;
    163163    /** @todo recheck*/
    164     hwid = crStateGetProgramHWID(obj);
    165     if (!hwid) hwid = crStateGetShaderHWID(obj);
     164    hwid = crStateGetProgramHWID(&cr_server.StateTracker, obj);
     165    if (!hwid) hwid = crStateGetShaderHWID(&cr_server.StateTracker, obj);
    166166    cr_server.head_spu->dispatch_table.GetInfoLogARB(hwid, maxLength, pLocal, (char*)&pLocal[1]);
    167167    CRASSERT((*pLocal) <= maxLength);
     
    187187    /* initial (fallback )value */
    188188    *pLocal = 0;
    189     cr_server.head_spu->dispatch_table.GetShaderInfoLog(crStateGetShaderHWID(shader), bufSize, pLocal, (char*)&pLocal[1]);
     189    cr_server.head_spu->dispatch_table.GetShaderInfoLog(crStateGetShaderHWID(&cr_server.StateTracker, shader), bufSize, pLocal, (char*)&pLocal[1]);
    190190    crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
    191191    crFree(pLocal);
     
    209209    /* initial (fallback )value */
    210210    *pLocal = 0;
    211     cr_server.head_spu->dispatch_table.GetProgramInfoLog(crStateGetProgramHWID(program), bufSize, pLocal, (char*)&pLocal[1]);
     211    cr_server.head_spu->dispatch_table.GetProgramInfoLog(crStateGetProgramHWID(&cr_server.StateTracker, program), bufSize, pLocal, (char*)&pLocal[1]);
    212212    CRASSERT(pLocal[0] <= bufSize);
    213213    crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
     
    232232    /* initial (fallback )value */
    233233    *pLocal = 0;
    234     cr_server.head_spu->dispatch_table.GetShaderSource(crStateGetShaderHWID(shader), bufSize, pLocal, (char*)&pLocal[1]);
     234    cr_server.head_spu->dispatch_table.GetShaderSource(crStateGetShaderHWID(&cr_server.StateTracker, shader), bufSize, pLocal, (char*)&pLocal[1]);
    235235    CRASSERT(pLocal[0] <= bufSize);
    236236    crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
     
    258258    /* initial (fallback )value */
    259259    *pLocal = 0;
    260     crStateGLSLProgramCacheUniforms(program, maxcbData, pLocal, (char*)&pLocal[1]);
     260    crStateGLSLProgramCacheUniforms(&cr_server.StateTracker, program, maxcbData, pLocal, (char*)&pLocal[1]);
    261261
    262262    crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
     
    284284    /* initial (fallback )value */
    285285    *pLocal = 0;
    286     crStateGLSLProgramCacheAttribs(program, maxcbData, pLocal, (char*)&pLocal[1]);
     286    crStateGLSLProgramCacheAttribs(&cr_server.StateTracker, program, maxcbData, pLocal, (char*)&pLocal[1]);
    287287
    288288    crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
     
    296296
    297297    /** @todo check if index and location is the same*/
    298     cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(program), location, 0, NULL, &size, &type, NULL);
    299 
    300     return crStateGetUniformSize(type);
     298    cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(&cr_server.StateTracker, program), location, 0, NULL, &size, &type, NULL);
     299
     300    return crStateGetUniformSize(&cr_server.StateTracker, type);
    301301}
    302302
     
    316316    }
    317317
    318     cr_server.head_spu->dispatch_table.GetUniformfv(crStateGetProgramHWID(program), location, pLocal);
     318    cr_server.head_spu->dispatch_table.GetUniformfv(crStateGetProgramHWID(&cr_server.StateTracker, program), location, pLocal);
    319319
    320320    crServerReturnValue(pLocal, size);
     
    337337    }
    338338
    339     cr_server.head_spu->dispatch_table.GetUniformiv(crStateGetProgramHWID(program), location, pLocal);
     339    cr_server.head_spu->dispatch_table.GetUniformiv(crStateGetProgramHWID(&cr_server.StateTracker, program), location, pLocal);
    340340
    341341    crServerReturnValue(pLocal, size);
     
    347347    GLuint retval, hwVal;
    348348    hwVal = cr_server.head_spu->dispatch_table.CreateShader(type);
    349     retval = crStateCreateShader(hwVal, type);
     349    retval = crStateCreateShader(&cr_server.StateTracker, hwVal, type);
    350350    crServerReturnValue(&retval, sizeof(retval));
    351351    return retval; /* ignored */
     
    356356    GLuint retval, hwVal;
    357357    hwVal = cr_server.head_spu->dispatch_table.CreateProgram();
    358     retval = crStateCreateProgram(hwVal);
     358    retval = crStateCreateProgram(&cr_server.StateTracker, hwVal);
    359359    crServerReturnValue(&retval, sizeof(retval));
    360360    return retval; /* ignored */
     
    364364{
    365365    GLboolean retval;
    366     retval = cr_server.head_spu->dispatch_table.IsShader(crStateGetShaderHWID(shader));
     366    retval = cr_server.head_spu->dispatch_table.IsShader(crStateGetShaderHWID(&cr_server.StateTracker, shader));
    367367    crServerReturnValue(&retval, sizeof(retval));
    368368    return retval; /* ignored */
     
    372372{
    373373    GLboolean retval;
    374     retval = cr_server.head_spu->dispatch_table.IsProgram(crStateGetProgramHWID(program));
     374    retval = cr_server.head_spu->dispatch_table.IsProgram(crStateGetProgramHWID(&cr_server.StateTracker, program));
    375375    crServerReturnValue(&retval, sizeof(retval));
    376376    return retval; /* ignored */
     
    380380{
    381381    GLfloat local_params[1] = {0};
    382     GLuint hwid = crStateGetProgramHWID(obj);
     382    GLuint hwid = crStateGetProgramHWID(&cr_server.StateTracker, obj);
    383383    (void) params;
    384384
    385385    if (!hwid)
    386386    {
    387         hwid = crStateGetShaderHWID(obj);
     387        hwid = crStateGetShaderHWID(&cr_server.StateTracker, obj);
    388388        if (!hwid)
    389389        {
     
    399399{
    400400    GLint local_params[1] = {0};
    401     GLuint hwid = crStateGetProgramHWID(obj);
     401    GLuint hwid = crStateGetProgramHWID(&cr_server.StateTracker, obj);
    402402    if (!hwid)
    403403    {
    404         hwid = crStateGetShaderHWID(obj);
     404        hwid = crStateGetShaderHWID(&cr_server.StateTracker, obj);
    405405        if (!hwid)
    406406        {
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_getteximage.cpp

    r78190 r78375  
    2121
    2222#ifdef CR_ARB_pixel_buffer_object
    23     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     23    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    2424    {
    2525        GLvoid *pbo_offset;
     
    104104
    105105#ifdef CR_ARB_pixel_buffer_object
    106     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     106    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    107107    {
    108108        GLvoid *pbo_offset;
     
    136136{
    137137#ifdef CR_ARB_pixel_buffer_object
    138     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     138    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    139139    {
    140140        GLvoid *pbo_offset;
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_glsl.cpp

    r78190 r78375  
    3232    GLenum err = cr_server.head_spu->dispatch_table.GetError();
    3333#endif
    34     cr_server.head_spu->dispatch_table.ShaderSource(crStateGetShaderHWID(shader), count, string, length);
     34    cr_server.head_spu->dispatch_table.ShaderSource(crStateGetShaderHWID(&cr_server.StateTracker, shader), count, string, length);
    3535#ifdef DEBUG_misha
    3636    err = cr_server.head_spu->dispatch_table.GetError();
     
    4545    GLint iCompileStatus = GL_FALSE;
    4646#endif
    47     crStateCompileShader(shader);
    48     cr_server.head_spu->dispatch_table.CompileShader(crStateGetShaderHWID(shader));
    49 #ifdef DEBUG_misha
    50     cr_server.head_spu->dispatch_table.GetShaderiv(crStateGetShaderHWID(shader), GL_COMPILE_STATUS, &iCompileStatus);
     47    crStateCompileShader(&cr_server.StateTracker, shader);
     48    cr_server.head_spu->dispatch_table.CompileShader(crStateGetShaderHWID(&cr_server.StateTracker, shader));
     49#ifdef DEBUG_misha
     50    cr_server.head_spu->dispatch_table.GetShaderiv(crStateGetShaderHWID(&cr_server.StateTracker, shader), GL_COMPILE_STATUS, &iCompileStatus);
    5151    Assert(iCompileStatus == GL_TRUE);
    5252#endif
     
    5656void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteShader(GLuint shader)
    5757{
    58     GLuint shaderHW = crStateGetShaderHWID(shader);
    59     crStateDeleteShader(shader);
     58    GLuint shaderHW = crStateGetShaderHWID(&cr_server.StateTracker, shader);
     59    crStateDeleteShader(&cr_server.StateTracker, shader);
    6060    if (shaderHW)
    6161        cr_server.head_spu->dispatch_table.DeleteShader(shaderHW);
     
    6666void SERVER_DISPATCH_APIENTRY crServerDispatchAttachShader(GLuint program, GLuint shader)
    6767{
    68     crStateAttachShader(program, shader);
    69     cr_server.head_spu->dispatch_table.AttachShader(crStateGetProgramHWID(program), crStateGetShaderHWID(shader));
     68    crStateAttachShader(&cr_server.StateTracker, program, shader);
     69    cr_server.head_spu->dispatch_table.AttachShader(crStateGetProgramHWID(&cr_server.StateTracker, program),
     70                                                    crStateGetShaderHWID(&cr_server.StateTracker, shader));
    7071}
    7172
    7273void SERVER_DISPATCH_APIENTRY crServerDispatchDetachShader(GLuint program, GLuint shader)
    7374{
    74     crStateDetachShader(program, shader);
    75     cr_server.head_spu->dispatch_table.DetachShader(crStateGetProgramHWID(program), crStateGetShaderHWID(shader));
     75    crStateDetachShader(&cr_server.StateTracker, program, shader);
     76    cr_server.head_spu->dispatch_table.DetachShader(crStateGetProgramHWID(&cr_server.StateTracker, program),
     77                                                    crStateGetShaderHWID(&cr_server.StateTracker, shader));
    7678}
    7779
    7880void SERVER_DISPATCH_APIENTRY crServerDispatchLinkProgram(GLuint program)
    7981{
    80     crStateLinkProgram(program);
    81     cr_server.head_spu->dispatch_table.LinkProgram(crStateGetProgramHWID(program));
     82    crStateLinkProgram(&cr_server.StateTracker, program);
     83    cr_server.head_spu->dispatch_table.LinkProgram(crStateGetProgramHWID(&cr_server.StateTracker, program));
    8284    CR_SERVER_DUMP_LINK_PROGRAM(program);
    8385}
     
    8587void SERVER_DISPATCH_APIENTRY crServerDispatchUseProgram(GLuint program)
    8688{
    87     crStateUseProgram(program);
    88     cr_server.head_spu->dispatch_table.UseProgram(crStateGetProgramHWID(program));
     89    crStateUseProgram(&cr_server.StateTracker, program);
     90    cr_server.head_spu->dispatch_table.UseProgram(crStateGetProgramHWID(&cr_server.StateTracker, program));
    8991}
    9092
    9193void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteProgram(GLuint program)
    9294{
    93     GLuint hwId = crStateGetProgramHWID(program);
    94     crStateDeleteProgram(program);
     95    GLuint hwId = crStateGetProgramHWID(&cr_server.StateTracker, program);
     96    crStateDeleteProgram(&cr_server.StateTracker, program);
    9597    if (hwId)
    9698        cr_server.head_spu->dispatch_table.DeleteProgram(hwId);
     
    101103void SERVER_DISPATCH_APIENTRY crServerDispatchValidateProgram(GLuint program)
    102104{
    103     crStateValidateProgram(program);
    104     cr_server.head_spu->dispatch_table.ValidateProgram(crStateGetProgramHWID(program));
     105    crStateValidateProgram(&cr_server.StateTracker, program);
     106    cr_server.head_spu->dispatch_table.ValidateProgram(crStateGetProgramHWID(&cr_server.StateTracker, program));
    105107}
    106108
    107109void SERVER_DISPATCH_APIENTRY crServerDispatchBindAttribLocation(GLuint program, GLuint index, const char * name)
    108110{
    109     crStateBindAttribLocation(program, index, name);
    110     cr_server.head_spu->dispatch_table.BindAttribLocation(crStateGetProgramHWID(program), index, name);
     111    crStateBindAttribLocation(&cr_server.StateTracker, program, index, name);
     112    cr_server.head_spu->dispatch_table.BindAttribLocation(crStateGetProgramHWID(&cr_server.StateTracker, program), index, name);
    111113}
    112114
    113115void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteObjectARB(VBoxGLhandleARB obj)
    114116{
    115     GLuint hwid =  crStateDeleteObjectARB(obj);
     117    GLuint hwid =  crStateDeleteObjectARB(&cr_server.StateTracker, obj);
    116118
    117119    if (hwid)
     
    124126{
    125127    GLint retval;
    126     retval = cr_server.head_spu->dispatch_table.GetAttribLocation(crStateGetProgramHWID(program), name );
     128    retval = cr_server.head_spu->dispatch_table.GetAttribLocation(crStateGetProgramHWID(&cr_server.StateTracker, program), name );
    127129    crServerReturnValue( &retval, sizeof(retval) );
    128130    return retval; /* WILL PROBABLY BE IGNORED */
     
    135137    if (pname==GL_PROGRAM_OBJECT_ARB)
    136138    {
    137         retval = crStateGLSLProgramHWIDtoID(retval);
     139        retval = crStateGLSLProgramHWIDtoID(&cr_server.StateTracker, retval);
    138140    }
    139141    crServerReturnValue( &retval, sizeof(retval) );
     
    144146{
    145147    GLint retval;
    146     retval = cr_server.head_spu->dispatch_table.GetUniformLocation(crStateGetProgramHWID(program), name);
     148    retval = cr_server.head_spu->dispatch_table.GetUniformLocation(crStateGetProgramHWID(&cr_server.StateTracker, program), name);
    147149    crServerReturnValue( &retval, sizeof(retval) );
    148150    return retval; /* WILL PROBABLY BE IGNORED */
     
    153155    GLint local_params[1] = {0};
    154156    (void) params;
    155     cr_server.head_spu->dispatch_table.GetProgramiv(crStateGetProgramHWID(program), pname, local_params);
     157    cr_server.head_spu->dispatch_table.GetProgramiv(crStateGetProgramHWID(&cr_server.StateTracker, program), pname, local_params);
    156158    crServerReturnValue( &(local_params[0]), 1*sizeof(GLint) );
    157159}
     
    161163    GLint local_params[1] = {0};
    162164    (void) params;
    163     cr_server.head_spu->dispatch_table.GetShaderiv( crStateGetShaderHWID(shader), pname, local_params );
     165    cr_server.head_spu->dispatch_table.GetShaderiv( crStateGetShaderHWID(&cr_server.StateTracker, shader), pname, local_params );
    164166    crServerReturnValue( &(local_params[0]), 1*sizeof(GLint) );
    165167}
     
    197199        pLocalProgs[i] = crServerTranslateProgramID(programs[i]);
    198200    }
    199     crStateDeleteProgramsARB(n, pLocalProgs);
     201    crStateDeleteProgramsARB(&cr_server.StateTracker, n, pLocalProgs);
    200202    cr_server.head_spu->dispatch_table.DeleteProgramsARB(n, pLocalProgs);
    201203    crFree(pLocalProgs);
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_lists.cpp

    r78190 r78375  
    6464
    6565    list = TranslateListID( list );
    66     crStateNewList( list, mode );
     66    crStateNewList(&cr_server.StateTracker, list, mode );
    6767    cr_server.head_spu->dispatch_table.NewList( list, mode );
    6868}
     
    8484            fbFbo = bbFbo = 0;
    8585        }
    86         crStateQueryHWState(fbFbo, bbFbo);
     86        crStateQueryHWState(&cr_server.StateTracker, fbFbo, bbFbo);
    8787    }
    8888}
     
    9090void SERVER_DISPATCH_APIENTRY crServerDispatchEndList(void)
    9191{
    92     CRContext *g = crStateGetCurrent();
     92    CRContext *g = crStateGetCurrent(&cr_server.StateTracker);
    9393    CRListsState *l = &(g->lists);
    9494
    9595    cr_server.head_spu->dispatch_table.EndList();
    96     crStateEndList();
     96    crStateEndList(&cr_server.StateTracker);
    9797
    9898#ifndef IN_GUEST
     
    272272{
    273273    list = TranslateListID( list );
    274     crStateDeleteLists( list, range );
     274    crStateDeleteLists(&cr_server.StateTracker, list, range );
    275275    cr_server.head_spu->dispatch_table.DeleteLists( list, range );
    276276}
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.cpp

    r78263 r78375  
    5151 */
    5252CRServer cr_server;
     53DECLHIDDEN(PCRStateTracker) g_pStateTracker;
    5354
    5455int tearingdown = 0; /* can't be static */
     
    124125{
    125126    CRContextInfo *c = (CRContextInfo *) data;
    126     crStateDestroyContext(c->pContext);
     127    crStateDestroyContext(&cr_server.StateTracker, c->pContext);
    127128    if (c->CreateInfo.pszDpyName)
    128129        crFree(c->CreateInfo.pszDpyName);
     
    180181    }
    181182
    182     crStateSetCurrent( NULL );
     183    crStateSetCurrent(&cr_server.StateTracker, NULL);
    183184
    184185    cr_server.curClient = NULL;
     
    218219    if (!fContextsDeleted)
    219220    {
    220         fOldEnableDiff = crStateEnableDiffOnMakeCurrent(GL_FALSE);
     221        fOldEnableDiff = crStateEnableDiffOnMakeCurrent(&cr_server.StateTracker, GL_FALSE);
    221222        if(cr_server.MainContextInfo.pContext)
    222             crStateMakeCurrent(cr_server.MainContextInfo.pContext);
    223         crStateEnableDiffOnMakeCurrent(fOldEnableDiff);
     223            crStateMakeCurrent(&cr_server.StateTracker, cr_server.MainContextInfo.pContext);
     224        crStateEnableDiffOnMakeCurrent(&cr_server.StateTracker, fOldEnableDiff);
    224225    }
    225226
     
    270271#endif
    271272
    272     crStateDestroy();
     273    crStateDestroy(&cr_server.StateTracker);
    273274
    274275    crNetTearDown();
     
    356357    cr_server.programTable = crAllocHashtable();
    357358
    358     crStateInit();
     359    crStateInit(&cr_server.StateTracker);
     360    g_pStateTracker = &cr_server.StateTracker;
    359361
    360362    crStateLimitsInit( &(cr_server.limits) );
     
    393395    if (!cr_server.head_spu)
    394396    {
    395         crStateDestroy();
     397        crStateDestroy(&cr_server.StateTracker);
    396398        return GL_FALSE;
    397399    }
     
    399401    crServerInitDispatch();
    400402    crServerInitTmpCtxDispatch();
    401     crStateDiffAPI( &(cr_server.head_spu->dispatch_table) );
     403    crStateDiffAPI(&cr_server.StateTracker, &(cr_server.head_spu->dispatch_table) );
    402404
    403405#ifdef VBOX_WITH_CRSERVER_DUMPER
     
    410412
    411413    /*Check for PBO support*/
    412     if (crStateGetCurrent()->extensions.ARB_pixel_buffer_object)
     414    if (crStateGetCurrent(&cr_server.StateTracker)->extensions.ARB_pixel_buffer_object)
    413415    {
    414416        cr_server.bUsePBOForReadback=GL_TRUE;
     
    14221424    crVBoxServerBuildSaveStateGlobal(&Data);
    14231425
    1424     rc = crStateSaveGlobals(pSSM);
     1426    rc = crStateSaveGlobals(&cr_server.StateTracker, pSSM);
    14251427    AssertRCReturn(rc, rc);
    14261428
     
    20842086    }
    20852087
    2086     rc = crStateLoadGlobals(pSSM, version);
     2088    rc = crStateLoadGlobals(&cr_server.StateTracker, pSSM, version);
    20872089    AssertLogRelRCReturn(rc, rc);
    20882090
     
    26042606
    26052607    cr_server.head_spu->dispatch_table.MakeCurrent(0, 0, 0);
    2606     crStateCleanupCurrent();
     2608    crStateCleanupCurrent(&cr_server.StateTracker);
    26072609
    26082610    /* note: we need to clean all contexts, since otherwise renderspu leanup won't work,
     
    26122614    {
    26132615        cr_server.head_spu->dispatch_table.DestroyContext(cr_server.MainContextInfo.SpuContext);
    2614         crStateDestroyContext(cr_server.MainContextInfo.pContext);
     2616        crStateDestroyContext(&cr_server.StateTracker, cr_server.MainContextInfo.pContext);
    26152617        if (cr_server.MainContextInfo.CreateInfo.pszDpyName)
    26162618            crFree(cr_server.MainContextInfo.CreateInfo.pszDpyName);
     
    26302632    cr_server.currentMural = NULL;
    26312633
    2632     crStateDestroy();
     2634    crStateDestroy(&cr_server.StateTracker);
    26332635//    crStateCleanupCurrent();
    26342636
     
    26512653
    26522654//    crStateSetCurrent(NULL);
    2653     crStateInit();
    2654     crStateDiffAPI( &(cr_server.head_spu->dispatch_table) );
     2655    crStateInit(&cr_server.StateTracker);
     2656    crStateDiffAPI(&cr_server.StateTracker, &(cr_server.head_spu->dispatch_table) );
    26552657
    26562658    CrPMgrEnable();
     
    38353837}
    38363838
     3839void crVBoxServerDetachThread(void)
     3840{
     3841    crStateVBoxDetachThread(&cr_server.StateTracker);
     3842}
     3843
     3844void crVBoxServerAttachThread(void)
     3845{
     3846    crStateVBoxAttachThread(&cr_server.StateTracker);
     3847}
     3848
     3849
    38373850#endif
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_misc.cpp

    r78263 r78375  
    328328  switch (target) {
    329329    case GL_SHARE_CONTEXT_RESOURCES_CR:
    330         crStateShareContext(value);
     330        crStateShareContext(&cr_server.StateTracker, value);
    331331        break;
    332332    case GL_RCUSAGE_TEXTURE_SET_CR:
    333         crStateSetTextureUsed(value, GL_TRUE);
     333        crStateSetTextureUsed(&cr_server.StateTracker, value, GL_TRUE);
    334334        break;
    335335    case GL_RCUSAGE_TEXTURE_CLEAR_CR:
    336         crStateSetTextureUsed(value, GL_FALSE);
     336        crStateSetTextureUsed(&cr_server.StateTracker, value, GL_FALSE);
    337337        break;
    338338    case GL_PIN_TEXTURE_SET_CR:
    339         crStatePinTexture(value, GL_TRUE);
     339        crStatePinTexture(&cr_server.StateTracker, value, GL_TRUE);
    340340        break;
    341341    case GL_PIN_TEXTURE_CLEAR_CR:
    342         crStatePinTexture(value, GL_FALSE);
     342        crStatePinTexture(&cr_server.StateTracker, value, GL_FALSE);
    343343        break;
    344344    case GL_SHARED_DISPLAY_LISTS_CR:
     
    502502            GLuint tID, fboID;
    503503            GLenum status;
    504             CRContext *ctx = crStateGetCurrent();
     504            CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    505505
    506506            gl->GenTextures(1, &tID);
     
    601601            GLint dRow;
    602602            GLuint pboId, sRow;
    603             CRContext *ctx = crStateGetCurrent();
     603            CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    604604
    605605            gl->GenBuffersARB(1, &pboId);
     
    897897    CR_BLITTER_CONTEXT Ctx;
    898898    CRMuralInfo *mural;
    899     CRContext *ctx = crStateGetCurrent();
     899    CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    900900    PVBOXVR_TEXTURE pDrawTex, pReadTex;
    901901    VBOXVR_TEXTURE DrawTex, ReadTex;
     
    992992                                   GLbitfield mask, GLenum filter)
    993993{
    994     CRContext *ctx = crStateGetCurrent();
     994    CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    995995    bool fTryBlitter = false;
    996996#ifdef CR_CHECK_BLITS
     
    12741274void SERVER_DISPATCH_APIENTRY crServerDispatchDrawBuffer( GLenum mode )
    12751275{
    1276     crStateDrawBuffer( mode );
    1277 
    1278     if (!crStateGetCurrent()->framebufferobject.drawFB)
     1276    crStateDrawBuffer(&cr_server.StateTracker, mode );
     1277
     1278    if (!crStateGetCurrent(&cr_server.StateTracker)->framebufferobject.drawFB)
    12791279    {
    12801280        if (mode == GL_FRONT || mode == GL_FRONT_LEFT || mode == GL_FRONT_RIGHT)
     
    13621362void SERVER_DISPATCH_APIENTRY crServerDispatchReadBuffer( GLenum mode )
    13631363{
    1364     crStateReadBuffer( mode );
     1364    crStateReadBuffer(&cr_server.StateTracker, mode );
    13651365
    13661366    if (crServerIsRedirectedToFBO()
    13671367            && cr_server.curClient->currentMural->aidFBOs[0]
    1368             && !crStateGetCurrent()->framebufferobject.readFB)
     1368            && !crStateGetCurrent(&cr_server.StateTracker)->framebufferobject.readFB)
    13691369    {
    13701370        CRMuralInfo *mural = cr_server.curClient->currentMural;
     
    14331433{
    14341434    GLenum retval, err;
    1435     CRContext *ctx = crStateGetCurrent();
     1435    CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    14361436    retval = ctx->error;
    14371437
     
    14531453crServerMakeTmpCtxCurrent( GLint window, GLint nativeWindow, GLint context )
    14541454{
    1455     CRContext *pCtx = crStateGetCurrent();
     1455    CRContext *pCtx = crStateGetCurrent(&cr_server.StateTracker);
    14561456    CRContext *pCurCtx = NULL;
    14571457    GLuint idDrawFBO = 0, idReadFBO = 0;
     
    18901890GLvoid crServerSpriteCoordReplEnable(GLboolean fEnable)
    18911891{
    1892     CRContext *g = crStateGetCurrent();
     1892    CRContext *g = crStateGetCurrent(&cr_server.StateTracker);
    18931893    CRTextureState *t = &(g->texture);
    18941894    GLuint curTextureUnit = t->curTextureUnit;
     
    19481948void SERVER_DISPATCH_APIENTRY crServerDispatchEnd( void )
    19491949{
    1950     CRContext *g = crStateGetCurrent();
     1950    CRContext *g = crStateGetCurrent(&cr_server.StateTracker);
    19511951    GLenum mode = g->current.mode;
    19521952
    1953     crStateEnd();
     1953    crStateEnd(&cr_server.StateTracker);
    19541954    cr_server.head_spu->dispatch_table.End();
    19551955
     
    19631963{
    19641964#ifdef DEBUG
    1965     CRContext *ctx = crStateGetCurrent();
     1965    CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    19661966    SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
    19671967
     
    20122012    CR_SERVER_DUMP_DRAW_ENTER();
    20132013
    2014     crStateBegin(mode);
     2014    crStateBegin(&cr_server.StateTracker, mode);
    20152015    cr_server.head_spu->dispatch_table.Begin(mode);
    20162016}
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_muralfbo.cpp

    r78263 r78375  
    477477        if (cr_server.curClient && cr_server.curClient->currentMural == mural)
    478478        {
    479             if (!crStateGetCurrent()->framebufferobject.drawFB)
     479            CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
     480
     481            if (!ctx->framebufferobject.drawFB)
    480482            {
    481483                cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, mural->iCurDrawBuffer));
    482484            }
    483             if (!crStateGetCurrent()->framebufferobject.readFB)
     485            if (!ctx->framebufferobject.readFB)
    484486            {
    485487                cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, mural->iCurReadBuffer));
    486488            }
    487489
    488             crStateGetCurrent()->buffer.width = 0;
    489             crStateGetCurrent()->buffer.height = 0;
     490            ctx->buffer.width = 0;
     491            ctx->buffer.height = 0;
    490492        }
    491493    }
     
    494496        if (cr_server.curClient && cr_server.curClient->currentMural == mural)
    495497        {
    496             if (!crStateGetCurrent()->framebufferobject.drawFB)
     498            CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
     499
     500            if (!ctx->framebufferobject.drawFB)
    497501            {
    498502                cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
    499503            }
    500             if (!crStateGetCurrent()->framebufferobject.readFB)
     504            if (!ctx->framebufferobject.readFB)
    501505            {
    502506                cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, 0);
    503507            }
    504508
    505             crStateGetCurrent()->buffer.width = mural->width;
    506             crStateGetCurrent()->buffer.height = mural->height;
     509            ctx->buffer.width = mural->width;
     510            ctx->buffer.height = mural->height;
    507511        }
    508512    }
     
    513517static void crServerCreateMuralFBO(CRMuralInfo *mural)
    514518{
    515     CRContext *ctx = crStateGetCurrent();
     519    CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    516520    GLuint uid, i;
    517521    GLenum status;
     
    540544    /*Color texture*/
    541545
    542     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     546    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    543547    {
    544548        gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
     
    605609    gl->BindFramebufferEXT(GL_READ_FRAMEBUFFER, uid);
    606610
    607     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     611    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    608612    {
    609613        gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, ctx->bufferobject.unpackBuffer->hwid);
    610614    }
    611615
    612     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     616    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    613617    {
    614618        gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
     
    825829void crServerMuralFBOSwapBuffers(CRMuralInfo *mural)
    826830{
    827     CRContext *ctx = crStateGetCurrent();
     831    CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    828832    GLint iOldCurDrawBuffer = mural->iCurDrawBuffer;
    829833    GLint iOldCurReadBuffer = mural->iCurReadBuffer;
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_projmatrix.cpp

    r78263 r78375  
    4444    const GLenum matMode = cr_server.curClient->currentCtxInfo->pContext->transform.matrixMode;
    4545
    46     crStateLoadMatrixf( m );
     46    crStateLoadMatrixf(&cr_server.StateTracker, m );
    4747
    4848    if (matMode == GL_MODELVIEW && cr_server.viewOverride) {
     
    6060    const GLenum matMode = cr_server.curClient->currentCtxInfo->pContext->transform.matrixMode;
    6161
    62     crStateLoadMatrixd( m );
     62    crStateLoadMatrixd(&cr_server.StateTracker, m );
    6363
    6464    if (matMode == GL_MODELVIEW && cr_server.viewOverride) {
     
    7979        /* load the overriding projection matrix */
    8080        int eye = crServerGetCurrentEye();
    81         crStateLoadMatrix( &cr_server.projectionMatrix[eye] );
     81        crStateLoadMatrix(&cr_server.StateTracker, &cr_server.projectionMatrix[eye] );
    8282    }
    8383    else {
    8484        /* the usual case */
    85         crStateMultMatrixf( m );
     85        crStateMultMatrixf(&cr_server.StateTracker, m );
    8686        cr_server.head_spu->dispatch_table.MultMatrixf( m );
    8787    }
     
    9696        /* load the overriding projection matrix */
    9797        int eye = crServerGetCurrentEye();
    98         crStateLoadMatrix( &cr_server.projectionMatrix[eye] );
     98        crStateLoadMatrix(&cr_server.StateTracker, &cr_server.projectionMatrix[eye] );
    9999    }
    100100    else {
    101101        /* the usual case */
    102         crStateMultMatrixd( m );
     102        crStateMultMatrixd(&cr_server.StateTracker, m );
    103103        cr_server.head_spu->dispatch_table.MultMatrixd( m );
    104104    }
     
    111111    const GLenum matMode = cr_server.curClient->currentCtxInfo->pContext->transform.matrixMode;
    112112
    113     crStateLoadIdentity();
     113    crStateLoadIdentity(&cr_server.StateTracker);
    114114
    115115    if (matMode == GL_MODELVIEW && cr_server.viewOverride) {
     
    322322
    323323    /* pass through */
    324     crStateProgramStringARB(target, format, len, string);
     324    crStateProgramStringARB(&cr_server.StateTracker, target, format, len, string);
    325325    cr_server.head_spu->dispatch_table.ProgramStringARB(target, format, len, string);
    326326}
     
    364364
    365365    /* pass through */
    366     crStateLoadProgramNV(target, id, len, string);
     366    crStateLoadProgramNV(&cr_server.StateTracker, target, id, len, string);
    367367    cr_server.head_spu->dispatch_table.LoadProgramNV(target, id, len, string);
    368368}
     
    381381
    382382    /* pass through */
    383     crStateBindProgramARB(target, id);
     383    crStateBindProgramARB(&cr_server.StateTracker, target, id);
    384384    cr_server.head_spu->dispatch_table.BindProgramARB(target, id);
    385385}
     
    395395    }
    396396    /* pass through */
    397     crStateBindProgramNV(target, id);
     397    crStateBindProgramNV(&cr_server.StateTracker, target, id);
    398398    cr_server.head_spu->dispatch_table.BindProgramNV(target, id);
    399399}
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_readpixels.cpp

    r78190 r78375  
    3333
    3434#ifdef CR_ARB_pixel_buffer_object
    35     if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     35    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    3636    {
    3737        GLvoid *pbo_offset;
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_rpw.cpp

    r78263 r78375  
    470470    pContext = cr_server.currentCtxInfo->pContext;
    471471
    472     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     472    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    473473    {
    474474        cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
     
    490490    pEntry->iTexDraw = -pEntry->iTexDraw;
    491491
    492     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     492    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    493493    {
    494494        cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pContext->bufferobject.unpackBuffer->hwid);
     
    504504        }
    505505
    506         if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     506        if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_PACK_BUFFER_ARB))
    507507        {
    508508            cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pContext->bufferobject.packBuffer->hwid);
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_simpleget.py

    r69390 r78375  
    6262        CRASSERT(tablesize/sizeof(%s)==1);
    6363        texid = (GLuint) *get_values;
    64         *get_values = (%s) crStateTextureHWIDtoID(texid);
     64        *get_values = (%s) crStateTextureHWIDtoID(&cr_server.StateTracker, texid);
    6565    }
    6666    else if (GL_CURRENT_PROGRAM==pname)
     
    6969        CRASSERT(tablesize/sizeof(%s)==1);
    7070        programid = (GLuint) *get_values;
    71         *get_values = (%s) crStateGLSLProgramHWIDtoID(programid);
     71        *get_values = (%s) crStateGLSLProgramHWIDtoID(&cr_server.StateTracker, programid);
    7272    }
    7373    else if (GL_FRAMEBUFFER_BINDING_EXT==pname
     
    8585        else
    8686        {
    87                 fboid = crStateFBOHWIDtoID(fboid);
     87                fboid = crStateFBOHWIDtoID(&cr_server.StateTracker, fboid);
    8888        }
    8989        *get_values = (%s) fboid;
     
    9393        if (crServerIsRedirectedToFBO()
    9494            && CR_SERVER_FBO_FOR_IDX(cr_server.curClient->currentMural, cr_server.curClient->currentMural->iCurReadBuffer)
    95             && !crStateGetCurrent()->framebufferobject.readFB)
     95            && !crStateGetCurrent(&cr_server.StateTracker)->framebufferobject.readFB)
    9696        {
    97             *get_values = (%s) crStateGetCurrent()->buffer.readBuffer;
    98             Assert(crStateGetCurrent()->buffer.readBuffer == GL_BACK || crStateGetCurrent()->buffer.readBuffer == GL_FRONT);
     97            *get_values = (%s) crStateGetCurrent(&cr_server.StateTracker)->buffer.readBuffer;
     98            Assert(crStateGetCurrent(&cr_server.StateTracker)->buffer.readBuffer == GL_BACK || crStateGetCurrent(&cr_server.StateTracker)->buffer.readBuffer == GL_FRONT);
    9999        }
    100100    }
     
    103103        if (crServerIsRedirectedToFBO()
    104104            && CR_SERVER_FBO_FOR_IDX(cr_server.curClient->currentMural, cr_server.curClient->currentMural->iCurDrawBuffer)
    105             && !crStateGetCurrent()->framebufferobject.drawFB)
     105            && !crStateGetCurrent(&cr_server.StateTracker)->framebufferobject.drawFB)
    106106        {
    107             *get_values = (%s) crStateGetCurrent()->buffer.drawBuffer;
    108             Assert(crStateGetCurrent()->buffer.drawBuffer == GL_BACK || crStateGetCurrent()->buffer.drawBuffer == GL_FRONT);
     107            *get_values = (%s) crStateGetCurrent(&cr_server.StateTracker)->buffer.drawBuffer;
     108            Assert(crStateGetCurrent(&cr_server.StateTracker)->buffer.drawBuffer == GL_BACK || crStateGetCurrent(&cr_server.StateTracker)->buffer.drawBuffer == GL_FRONT);
    109109        }
    110110    }
     
    114114        CRASSERT(tablesize/sizeof(%s)==1);
    115115        rbid = (GLuint) *get_values;
    116         *get_values = (%s) crStateRBOHWIDtoID(rbid);
     116        *get_values = (%s) crStateRBOHWIDtoID(&cr_server.StateTracker, rbid);
    117117    }
    118118    else if (GL_ARRAY_BUFFER_BINDING_ARB==pname
     
    131131        CRASSERT(tablesize/sizeof(%s)==1);
    132132        bufid = (GLuint) *get_values;
    133         *get_values = (%s) crStateBufferHWIDtoID(bufid);
     133        *get_values = (%s) crStateBufferHWIDtoID(&cr_server.StateTracker, bufid);
    134134    }
    135135    else if (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS==pname)
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_stream.cpp

    r78263 r78375  
    580580        UnpackerState.pDispatchTbl     = &(cr_server.dispatch);
    581581        UnpackerState.rcUnpack         = VINF_SUCCESS;
     582        UnpackerState.pStateTracker    = &cr_server.StateTracker;
    582583
    583584        cr_server.pUnpackerState = &UnpackerState;
     
    695696        UnpackerState.pDispatchTbl     = &(cr_server.dispatch);
    696697        UnpackerState.rcUnpack         = VINF_SUCCESS;
     698        UnpackerState.pStateTracker    = &cr_server.StateTracker;
    697699
    698700        cr_server.pUnpackerState = &UnpackerState;
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_texture.cpp

    r78190 r78375  
    3939#if defined(CR_ARB_pixel_buffer_object)
    4040# define CR_CHECKBUFFER(name, checkptr)                     \
    41     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))   \
     41    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))   \
    4242    {                                                       \
    4343        CR_FIXPTR();                                        \
     
    5353#if defined(CR_ARB_pixel_buffer_object) && !defined(CR_STATE_NO_TEXTURE_IMAGE_STORE)
    5454# define CR_FINISHBUFFER()                                                                  \
    55     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))                                   \
     55    if (crStateIsBufferBound(&cr_server.StateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))          \
    5656    {                                                                                       \
    5757        if (!cr_server.head_spu->dispatch_table.UnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB)) \
     
    6464#endif
    6565
    66 #define CR_FUNC_SUBIMAGE(name, def, call, ptrname)          \
    67 void SERVER_DISPATCH_APIENTRY                               \
    68 crServerDispatch##name def                                  \
    69 {                                                           \
    70     const GLvoid *realptr = ptrname;                        \
    71     CR_CHECKBUFFER(name, CR_CHECKPTR(name))                 \
    72     crState##name call;                                     \
    73     CR_FINISHBUFFER()                                       \
    74     realptr = ptrname;                                      \
    75     cr_server.head_spu->dispatch_table.name call;           \
    76 }
    77 
    78 #define CR_FUNC_IMAGE(name, def, call, ptrname)             \
    79 void SERVER_DISPATCH_APIENTRY                               \
    80 crServerDispatch##name def                                  \
    81 {                                                           \
    82     const GLvoid *realptr = ptrname;                        \
    83     CR_CHECKBUFFER(name, CR_NOTHING())                      \
    84     crState##name call;                                     \
    85     CR_FINISHBUFFER()                                       \
    86     realptr = ptrname;                                      \
    87     cr_server.head_spu->dispatch_table.name call;           \
     66#define CR_FUNC_SUBIMAGE(name, def, state_call, call, ptrname)          \
     67void SERVER_DISPATCH_APIENTRY                                           \
     68crServerDispatch##name def                                              \
     69{                                                                       \
     70    const GLvoid *realptr = ptrname;                                    \
     71    CR_CHECKBUFFER(name, CR_CHECKPTR(name))                             \
     72    crState##name state_call;                                           \
     73    CR_FINISHBUFFER()                                                   \
     74    realptr = ptrname;                                                  \
     75    cr_server.head_spu->dispatch_table.name call;                       \
     76}
     77
     78#define CR_FUNC_IMAGE(name, def, state_call, call, ptrname)             \
     79void SERVER_DISPATCH_APIENTRY                                           \
     80crServerDispatch##name def                                              \
     81{                                                                       \
     82    const GLvoid *realptr = ptrname;                                    \
     83    CR_CHECKBUFFER(name, CR_NOTHING())                                  \
     84    crState##name state_call;                                           \
     85    CR_FINISHBUFFER()                                                   \
     86    realptr = ptrname;                                                  \
     87    cr_server.head_spu->dispatch_table.name call;                       \
    8888}
    8989
     
    9191CR_FUNC_SUBIMAGE(CompressedTexSubImage1DARB,
    9292    (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imagesize, const GLvoid * data),
     93    (&cr_server.StateTracker, target, level, xoffset, width, format, imagesize, realptr),
    9394    (target, level, xoffset, width, format, imagesize, realptr), data)
    9495
    9596CR_FUNC_SUBIMAGE(CompressedTexSubImage2DARB,
    9697    (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid * data),
     98    (&cr_server.StateTracker, target, level, xoffset, yoffset, width, height, format, imagesize, realptr),
    9799    (target, level, xoffset, yoffset, width, height, format, imagesize, realptr), data)
    98100
    99101CR_FUNC_SUBIMAGE(CompressedTexSubImage3DARB,
    100102    (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imagesize, const GLvoid * data),
     103    (&cr_server.StateTracker, target, level, xoffset, yoffset, zoffset, width, height, depth, format, imagesize, realptr),
    101104    (target, level, xoffset, yoffset, zoffset, width, height, depth, format, imagesize, realptr), data)
    102105
    103106CR_FUNC_IMAGE(CompressedTexImage1DARB,
    104107    (GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLint border, GLsizei imagesize, const GLvoid * data),
     108    (&cr_server.StateTracker, target, level, internalFormat, width, border, imagesize, realptr),
    105109    (target, level, internalFormat, width, border, imagesize, realptr), data)
    106110
    107111CR_FUNC_IMAGE(CompressedTexImage2DARB,
    108112    (GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLint border, GLsizei imagesize, const GLvoid * data),
     113    (&cr_server.StateTracker, target, level, internalFormat, width, height, border, imagesize, realptr),
    109114    (target, level, internalFormat, width, height, border, imagesize, realptr), data)
    110115
    111116CR_FUNC_IMAGE(CompressedTexImage3DARB,
    112117    (GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid * data),
     118    (&cr_server.StateTracker, target, level, internalFormat, width, height, depth, border, imagesize, realptr),
    113119    (target, level, internalFormat, width, height, depth, border, imagesize, realptr), data)
    114120#endif
     
    116122CR_FUNC_SUBIMAGE(TexSubImage1D,
    117123    (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid * pixels),
     124    (&cr_server.StateTracker, target, level, xoffset, width, format, type, realptr),
    118125    (target, level, xoffset, width, format, type, realptr), pixels)
    119126
    120127CR_FUNC_SUBIMAGE(TexSubImage2D,
    121128    (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels),
     129    (&cr_server.StateTracker, target, level, xoffset, yoffset, width, height, format, type, realptr),
    122130    (target, level, xoffset, yoffset, width, height, format, type, realptr), pixels)
    123131
    124132CR_FUNC_SUBIMAGE(TexSubImage3D,
    125133    (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid * pixels),
     134    (&cr_server.StateTracker, target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, realptr),
    126135    (target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, realptr), pixels)
    127136
    128137CR_FUNC_IMAGE(TexImage1D,
    129138    (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid * pixels),
     139    (&cr_server.StateTracker, target, level, internalFormat, width, border, format, type, realptr),
    130140    (target, level, internalFormat, width, border, format, type, realptr), pixels)
    131141
    132142CR_FUNC_IMAGE(TexImage2D,
    133143    (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * pixels),
     144    (&cr_server.StateTracker, target, level, internalFormat, width, height, border, format, type, realptr),
    134145    (target, level, internalFormat, width, height, border, format, type, realptr), pixels)
    135146
    136147CR_FUNC_IMAGE(TexImage3D,
    137148    (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid * pixels),
     149    (&cr_server.StateTracker, target, level, internalFormat, width, height, depth, border, format, type, realptr),
    138150    (target, level, internalFormat, width, height, depth, border, format, type, realptr), pixels)
    139151
     
    141153void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnvf( GLenum target, GLenum pname, GLfloat param )
    142154{
    143     crStateTexEnvf( target, pname, param );
     155    crStateTexEnvf(&cr_server.StateTracker, target, pname, param );
    144156    if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
    145157        CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnvf( target, pname, param ););
     
    148160void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnvfv( GLenum target, GLenum pname, const GLfloat * params )
    149161{
    150     crStateTexEnvfv( target, pname, params );
     162    crStateTexEnvfv(&cr_server.StateTracker, target, pname, params );
    151163    if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
    152164        CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnvfv( target, pname, params ););
     
    155167void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnvi( GLenum target, GLenum pname, GLint param )
    156168{
    157     crStateTexEnvi( target, pname, param );
     169    crStateTexEnvi(&cr_server.StateTracker, target, pname, param );
    158170    if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
    159171        CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnvi( target, pname, param ););
     
    162174void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnviv( GLenum target, GLenum pname, const GLint * params )
    163175{
    164     crStateTexEnviv( target, pname, params );
     176    crStateTexEnviv(&cr_server.StateTracker, target, pname, params );
    165177    if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
    166178        CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnviv( target, pname, params ););
     
    175187        cr_server.head_spu->dispatch_table.GetTexEnvfv( target, pname, local_params );
    176188    else
    177         crStateGetTexEnvfv( target, pname, local_params );
     189        crStateGetTexEnvfv(&cr_server.StateTracker, target, pname, local_params );
    178190
    179191    cComponents = RT_MIN(crStateHlpComponentsCount(pname), RT_ELEMENTS(local_params));
     
    189201        cr_server.head_spu->dispatch_table.GetTexEnviv( target, pname, local_params );
    190202    else
    191         crStateGetTexEnviv( target, pname, local_params );
     203        crStateGetTexEnviv(&cr_server.StateTracker, target, pname, local_params );
    192204
    193205    cComponents = RT_MIN(crStateHlpComponentsCount(pname), RT_ELEMENTS(local_params));
     
    197209void SERVER_DISPATCH_APIENTRY crServerDispatchBindTexture( GLenum target, GLuint texture )
    198210{
    199     crStateBindTexture( target, texture );
    200     cr_server.head_spu->dispatch_table.BindTexture(target, crStateGetTextureHWID(texture));
     211    crStateBindTexture(&cr_server.StateTracker, target, texture );
     212    cr_server.head_spu->dispatch_table.BindTexture(target, crStateGetTextureHWID(&cr_server.StateTracker, texture));
    201213}
    202214
     
    223235    for (i = 0; i < n; i++)
    224236    {
    225         newTextures[i] = crStateGetTextureHWID(textures[i]);
     237        newTextures[i] = crStateGetTextureHWID(&cr_server.StateTracker, textures[i]);
    226238    }
    227239
     
    232244
    233245
    234     crStateDeleteTextures(n, textures);
     246    crStateDeleteTextures(&cr_server.StateTracker, n, textures);
    235247    cr_server.head_spu->dispatch_table.DeleteTextures(n, newTextures);
    236248    crFree(newTextures);
     
    257269    }
    258270
    259     crStatePrioritizeTextures(n, textures, priorities);
     271    crStatePrioritizeTextures(&cr_server.StateTracker, n, textures, priorities);
    260272
    261273    for (i = 0; i < n; i++)
    262274    {
    263         newTextures[i] = crStateGetTextureHWID(textures[i]);
     275        newTextures[i] = crStateGetTextureHWID(&cr_server.StateTracker, textures[i]);
    264276    }
    265277
     
    273285{
    274286    GLboolean retval;
    275     retval = cr_server.head_spu->dispatch_table.IsTexture(crStateGetTextureHWID(texture));
     287    retval = cr_server.head_spu->dispatch_table.IsTexture(crStateGetTextureHWID(&cr_server.StateTracker, texture));
    276288    crServerReturnValue( &retval, sizeof(retval) );
    277289    return retval; /* WILL PROBABLY BE IGNORED */
     
    313325    for (i = 0; i < n; i++)
    314326    {
    315         textures2[i] = crStateGetTextureHWID(textures[i]);
     327        textures2[i] = crStateGetTextureHWID(&cr_server.StateTracker, textures[i]);
    316328    }
    317329    retval = cr_server.head_spu->dispatch_table.AreTexturesResident(n, textures2, res);
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_viewport.cpp

    r78263 r78375  
    276276void SERVER_DISPATCH_APIENTRY crServerDispatchViewport( GLint x, GLint y, GLsizei width, GLsizei height )
    277277{
    278         CRContext *ctx = crStateGetCurrent();
     278        CRContext *ctx = crStateGetCurrent(&cr_server.StateTracker);
    279279
    280280        if (ctx->viewport.viewportX != x ||
     
    284284                 /* Note -- If there are tiles, this will be overridden in the
    285285                        * process of decoding the BoundsInfo packet, so no worries. */
    286                  crStateViewport( x, y, width, height );
     286                 crStateViewport(&cr_server.StateTracker, x, y, width, height );
    287287        }
    288288
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_window.cpp

    r78263 r78375  
    351351            && !mural->fRedirected)
    352352    {
    353         crStateGetCurrent()->buffer.width = mural->width;
    354         crStateGetCurrent()->buffer.height = mural->height;
     353        crStateGetCurrent(&cr_server.StateTracker)->buffer.width = mural->width;
     354        crStateGetCurrent(&cr_server.StateTracker)->buffer.height = mural->height;
    355355    }
    356356
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_winpos.cpp

    r78190 r78375  
    99static void crServerWindowPos( GLfloat x, GLfloat y, GLfloat z )
    1010{
    11         crStateWindowPos3fARB(x, y, z);
     11        crStateWindowPos3fARB(&cr_server.StateTracker, x, y, z);
    1212        cr_server.head_spu->dispatch_table.WindowPos3fARB(x, y, z);
    1313}
  • trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack_arrays.cpp

    r78191 r78375  
    88#include "unpack_extend.h"
    99#include "unpacker.h"
    10 #include "cr_glstate.h"
    1110
    1211
     
    292291    int numenabled = READ_DATA(pState, sizeof(int) + 12, int);
    293292
    294     CRContext *g = crStateGetCurrent();
     293    CRContext *g = crStateGetCurrent(pState->pStateTracker);
    295294    CRClientState *c = &g->client;
    296295    CRClientPointer *cp;
     
    364363{
    365364    int i;
    366     CRContext *g = crStateGetCurrent();
     365    CRContext *g = crStateGetCurrent(pState->pStateTracker);
    367366    CRClientState *c = &g->client;
    368367    CRClientPointer *cp;
  • trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack_drawpixels.cpp

    r78190 r78375  
    2222    GLvoid *pixels;
    2323
    24     if (noimagedata && !crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     24    if (noimagedata && !crStateIsBufferBound(pState->pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    2525        return;
    2626
     
    6363    GLubyte *bitmap;
    6464
    65     if (noimagedata && !crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     65    if (noimagedata && !crStateIsBufferBound(pState->pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    6666        return;
    6767
  • trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack_misc.cpp

    r78190 r78375  
    5454    const GLuint *ids = DATA_POINTER(pState, 12, GLuint);
    5555
    56     if (n <= 0 || n >= INT32_MAX / sizeof(GLint) / 4 || !DATA_POINTER_CHECK(pState, 12 + n * sizeof(GLuint)))
     56    if (n < 0 || n >= INT32_MAX / sizeof(GLint) / 4 || !DATA_POINTER_CHECK(pState, 12 + n * sizeof(GLuint)))
    5757    {
    5858        crError("crUnpackExtendDeleteQueriesARB: parameter 'n' is out of range");
  • trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack_pixelmap.cpp

    r78212 r78375  
    1717    GLfloat *values;
    1818
    19     if (nodata && !crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     19    if (nodata && !crStateIsBufferBound(pState->pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    2020        return;
    2121
     
    4747    GLuint *values;
    4848
    49     if (nodata && !crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     49    if (nodata && !crStateIsBufferBound(pState->pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    5050        return;
    5151
     
    7777    GLushort *values;
    7878
    79     if (nodata && !crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     79    if (nodata && !crStateIsBufferBound(pState->pStateTracker, GL_PIXEL_UNPACK_BUFFER_ARB))
    8080        return;
    8181
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