VirtualBox

Changeset 23123 in vbox


Ignore:
Timestamp:
Sep 18, 2009 11:21:22 AM (15 years ago)
Author:
vboxsync
Message:

crOpenGL: snapshots support for VBOs

Location:
trunk/src/VBox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_bufferobject.h

    r15532 r23123  
    4646
    4747        CRHashTable *buffers;
     48
     49    GLboolean   bResyncNeeded;
    4850} CRBufferObjectState;
    4951
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_bufferobject.c

    r22832 r23123  
    4848
    4949    b->buffers = crAllocHashtable();
     50
     51    b->bResyncNeeded = GL_FALSE;
    5052}
    5153
     
    7274    crFree(b->nullBuffer);
    7375}
    74 
    7576
    7677void STATE_APIENTRY
     
    750751}
    751752
     753static void crStateBufferObjectSyncCB(unsigned long key, void *data1, void *data2)
     754{
     755    CRBufferObject *pBufferObj = (CRBufferObject *) data1;
     756    CRBufferObjectState *pState = (CRBufferObjectState *) data2;
     757
     758    if (pBufferObj->data)
     759    {
     760        diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pBufferObj->name);
     761        diff_api.BufferDataARB(GL_ARRAY_BUFFER_ARB, pBufferObj->size, pBufferObj->data, pBufferObj->usage);
     762
     763        if (!pState->retainBufferData)
     764        {
     765            crFree(pBufferObj->data);
     766            pBufferObj->data = NULL;
     767        }
     768    }
     769}
    752770
    753771/*
     
    758776{
    759777    const CRBufferObjectState *from = &(fromCtx->bufferobject);
    760     const CRBufferObjectState *to = &(toCtx->bufferobject);
     778    CRBufferObjectState *to = &(toCtx->bufferobject);
     779    int i;
    761780
    762781    if (!HaveBufferObjectExtension())
    763782        return;
     783
     784    if (to->bResyncNeeded)
     785    {
     786        CRClientPointer *cp;
     787
     788        crHashtableWalk(to->buffers, crStateBufferObjectSyncCB, to);
     789        to->bResyncNeeded = GL_FALSE;
     790
     791        /*@todo, move to state_client.c*/
     792
     793        cp = &toCtx->client.array.v;
     794        if (cp->buffer->name)
     795        {
     796            diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->name);
     797            diff_api.VertexPointer(cp->size, cp->type, cp->stride, cp->p);
     798        }
     799
     800        cp = &toCtx->client.array.c;
     801        if (cp->buffer->name)
     802        {
     803            diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->name);
     804            diff_api.ColorPointer(cp->size, cp->type, cp->stride, cp->p);
     805        }
     806
     807        cp = &toCtx->client.array.f;
     808        if (cp->buffer->name)
     809        {
     810            diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->name);
     811            diff_api.FogCoordPointerEXT(cp->type, cp->stride, cp->p);
     812        }
     813
     814        cp = &toCtx->client.array.s;
     815        if (cp->buffer->name)
     816        {
     817            diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->name);
     818            diff_api.SecondaryColorPointerEXT(cp->size, cp->type, cp->stride, cp->p);
     819        }
     820
     821        cp = &toCtx->client.array.e;
     822        if (cp->buffer->name)
     823        {
     824            diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->name);
     825            diff_api.EdgeFlagPointer(cp->stride, cp->p);
     826        }
     827
     828        cp = &toCtx->client.array.i;
     829        if (cp->buffer->name)
     830        {
     831            diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->name);
     832            diff_api.IndexPointer(cp->type, cp->stride, cp->p);
     833        }
     834
     835        cp = &toCtx->client.array.n;
     836        if (cp->buffer->name)
     837        {
     838            diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->name);
     839            diff_api.NormalPointer(cp->type, cp->stride, cp->p);
     840        }
     841
     842        for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++)
     843        {
     844            cp = &toCtx->client.array.t[i];
     845            if (cp->buffer->name)
     846            {
     847                if (diff_api.ActiveTextureARB)
     848                    diff_api.ActiveTextureARB(i+GL_TEXTURE0_ARB);
     849                diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->name);
     850                diff_api.TexCoordPointer(cp->size, cp->type, cp->stride, cp->p);
     851            }
     852        }
     853
     854        if (diff_api.ActiveTextureARB)
     855            diff_api.ActiveTextureARB(toCtx->client.curClientTextureUnit+GL_TEXTURE0_ARB);
     856
     857#ifdef CR_NV_vertex_program
     858        for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
     859        {
     860            cp = &toCtx->client.array.a[i];
     861            if (cp->buffer->name)
     862            {
     863                diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, cp->buffer->name);
     864                diff_api.VertexAttribPointerARB(i, cp->size, cp->type, cp->normalized, cp->stride, cp->p);
     865            }
     866        }
     867#endif
     868        diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, to->arrayBuffer->name);
     869        diff_api.BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, to->elementsBuffer->name);
     870    }
    764871
    765872    /* ARRAY_BUFFER binding */
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_client.c

    r23110 r23123  
    133133    c->array.v.enabled = 0;
    134134#ifdef CR_ARB_vertex_buffer_object
    135     c->array.v.buffer = g->bufferobject.arrayBuffer;
     135    c->array.v.buffer = g ? g->bufferobject.arrayBuffer : NULL;
    136136#endif
    137137#ifdef CR_EXT_compiled_vertex_array
     
    148148    c->array.c.enabled = 0;
    149149#ifdef CR_ARB_vertex_buffer_object
    150     c->array.c.buffer = g->bufferobject.arrayBuffer;
     150    c->array.c.buffer = g ? g->bufferobject.arrayBuffer : NULL;
    151151#endif
    152152#ifdef CR_EXT_compiled_vertex_array
     
    163163    c->array.f.enabled = 0;
    164164#ifdef CR_ARB_vertex_buffer_object
    165     c->array.f.buffer = g->bufferobject.arrayBuffer;
     165    c->array.f.buffer = g ? g->bufferobject.arrayBuffer : NULL;
    166166#endif
    167167#ifdef CR_EXT_compiled_vertex_array
     
    178178    c->array.s.enabled = 0;
    179179#ifdef CR_ARB_vertex_buffer_object
    180     c->array.s.buffer = g->bufferobject.arrayBuffer;
     180    c->array.s.buffer = g ? g->bufferobject.arrayBuffer : NULL;
    181181#endif
    182182#ifdef CR_EXT_compiled_vertex_array
     
    193193    c->array.e.enabled = 0;
    194194#ifdef CR_ARB_vertex_buffer_object
    195     c->array.e.buffer = g->bufferobject.arrayBuffer;
     195    c->array.e.buffer = g ? g->bufferobject.arrayBuffer : NULL;
    196196#endif
    197197#ifdef CR_EXT_compiled_vertex_array
     
    208208    c->array.i.enabled = 0;
    209209#ifdef CR_ARB_vertex_buffer_object
    210     c->array.i.buffer = g->bufferobject.arrayBuffer;
     210    c->array.i.buffer = g ? g->bufferobject.arrayBuffer : NULL;
    211211#endif
    212212#ifdef CR_EXT_compiled_vertex_array
     
    223223    c->array.n.enabled = 0;
    224224#ifdef CR_ARB_vertex_buffer_object
    225     c->array.n.buffer = g->bufferobject.arrayBuffer;
     225    c->array.n.buffer = g ? g->bufferobject.arrayBuffer : NULL;
    226226#endif
    227227#ifdef CR_EXT_compiled_vertex_array
     
    240240        c->array.t[i].enabled = 0;
    241241#ifdef CR_ARB_vertex_buffer_object
    242         c->array.t[i].buffer = g->bufferobject.arrayBuffer;
     242        c->array.t[i].buffer = g ? g->bufferobject.arrayBuffer : NULL;
    243243#endif
    244244#ifdef CR_EXT_compiled_vertex_array
     
    257257        c->array.a[i].stride = 0;
    258258#ifdef CR_ARB_vertex_buffer_object
    259         c->array.a[i].buffer = g->bufferobject.arrayBuffer;
     259        c->array.a[i].buffer = g ? g->bufferobject.arrayBuffer : NULL;
    260260#endif
    261261#ifdef CR_EXT_compiled_vertex_array
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c

    r23094 r23123  
    425425    rc = SSMR3PutMem(pSSM, pBufferObj, sizeof(*pBufferObj));
    426426    CRASSERT(rc == VINF_SUCCESS);
     427
    427428    if (pBufferObj->data)
    428429    {
     430        /*We could get here even though retainBufferData is false on host side, in case when we're taking snapshot
     431          after state load and before this context was ever made current*/
    429432        CRASSERT(pBufferObj->size>0);
    430433        rc = SSMR3PutMem(pSSM, pBufferObj->data, pBufferObj->size);
    431434        CRASSERT(rc == VINF_SUCCESS);
     435    }
     436    else if (pBufferObj->name!=0 && pBufferObj->size>0)
     437    {
     438        diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pBufferObj->name);
     439        pBufferObj->pointer = diff_api.MapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_ONLY_ARB);
     440        rc = SSMR3PutMem(pSSM, &pBufferObj->pointer, sizeof(pBufferObj->pointer));
     441        CRASSERT(rc == VINF_SUCCESS);
     442        if (pBufferObj->pointer)
     443        {
     444            rc = SSMR3PutMem(pSSM, pBufferObj->pointer, pBufferObj->size);
     445            CRASSERT(rc == VINF_SUCCESS);
     446        }
     447        diff_api.UnmapBufferARB(GL_ARRAY_BUFFER_ARB);
     448        pBufferObj->pointer = NULL;
    432449    }
    433450}
     
    715732    /* Save all the rest */
    716733    crHashtableWalk(pContext->bufferobject.buffers, crStateSaveBufferObjectCB, pSSM);
     734    /* Restore binding */
     735    diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, pContext->bufferobject.arrayBuffer->name);
    717736    /* Save pointers */
    718737    rc = SSMR3PutU32(pSSM, pContext->bufferobject.arrayBuffer->name);
     
    720739    rc = SSMR3PutU32(pSSM, pContext->bufferobject.elementsBuffer->name);
    721740    AssertRCReturn(rc, rc);
    722 #endif
     741    /* Save bound array buffers*/ /*@todo vertexArrayStack*/
     742    rc = SSMR3PutU32(pSSM, pContext->client.array.v.buffer->name);
     743    AssertRCReturn(rc, rc);
     744    rc = SSMR3PutU32(pSSM, pContext->client.array.c.buffer->name);
     745    AssertRCReturn(rc, rc);
     746    rc = SSMR3PutU32(pSSM, pContext->client.array.f.buffer->name);
     747    AssertRCReturn(rc, rc);
     748    rc = SSMR3PutU32(pSSM, pContext->client.array.s.buffer->name);
     749    AssertRCReturn(rc, rc);
     750    rc = SSMR3PutU32(pSSM, pContext->client.array.e.buffer->name);
     751    AssertRCReturn(rc, rc);
     752    rc = SSMR3PutU32(pSSM, pContext->client.array.i.buffer->name);
     753    AssertRCReturn(rc, rc);
     754    rc = SSMR3PutU32(pSSM, pContext->client.array.n.buffer->name);
     755    AssertRCReturn(rc, rc);
     756    for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++)
     757    {
     758        rc = SSMR3PutU32(pSSM, pContext->client.array.t[i].buffer->name);
     759        AssertRCReturn(rc, rc);
     760    }
     761# ifdef CR_NV_vertex_program
     762    for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
     763    {
     764        rc = SSMR3PutU32(pSSM, pContext->client.array.a[i].buffer->name);
     765        AssertRCReturn(rc, rc);
     766    }
     767# endif
     768#endif /*CR_ARB_vertex_buffer_object*/
    723769
    724770    /* Save pixel/vertex programs */
     
    804850#endif
    805851
    806     SLC_COPYPTR(client.array.v.p);            /*@todo*/
    807     SLC_COPYPTR(client.array.c.p);            /*@todo*/
    808     SLC_COPYPTR(client.array.f.p);            /*@todo*/
    809     SLC_COPYPTR(client.array.s.p);            /*@todo*/
    810     SLC_COPYPTR(client.array.e.p);            /*@todo*/
    811     SLC_COPYPTR(client.array.i.p);            /*@todo*/
    812     SLC_COPYPTR(client.array.n.p);            /*@todo*/
     852/*@todo, that should be removed probably as those should hold the offset values, so loading should be fine
     853  but better check*/
     854#if 0
     855#ifdef CR_EXT_compiled_vertex_array
     856    SLC_COPYPTR(client.array.v.prevPtr);
     857    SLC_COPYPTR(client.array.c.prevPtr);
     858    SLC_COPYPTR(client.array.f.prevPtr);
     859    SLC_COPYPTR(client.array.s.prevPtr);
     860    SLC_COPYPTR(client.array.e.prevPtr);
     861    SLC_COPYPTR(client.array.i.prevPtr);
     862    SLC_COPYPTR(client.array.n.prevPtr);
    813863    for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
    814864    {
    815         SLC_COPYPTR(client.array.t[i].p);     /*@todo*/
    816     }
    817 
    818 #ifdef CR_ARB_vertex_buffer_object2
    819     SLC_COPYPTR(client.array.v.buffer);       /*@todo*/
    820     SLC_COPYPTR(client.array.c.buffer);       /*@todo*/
    821     SLC_COPYPTR(client.array.f.buffer);       /*@todo*/
    822     SLC_COPYPTR(client.array.s.buffer);       /*@todo*/
    823     SLC_COPYPTR(client.array.e.buffer);       /*@todo*/
    824     SLC_COPYPTR(client.array.i.buffer);       /*@todo*/
    825     SLC_COPYPTR(client.array.n.buffer);       /*@todo*/
     865        SLC_COPYPTR(client.array.t[i].prevPtr);
     866    }
     867
     868# ifdef CR_NV_vertex_program
     869    for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
     870    {
     871        SLC_COPYPTR(client.array.a[i].prevPtr);
     872    }
     873# endif
     874#endif
     875#endif
     876
     877#ifdef CR_ARB_vertex_buffer_object
     878    /*That just sets those pointers to NULL*/
     879    SLC_COPYPTR(client.array.v.buffer);
     880    SLC_COPYPTR(client.array.c.buffer);
     881    SLC_COPYPTR(client.array.f.buffer);
     882    SLC_COPYPTR(client.array.s.buffer);
     883    SLC_COPYPTR(client.array.e.buffer);
     884    SLC_COPYPTR(client.array.i.buffer);
     885    SLC_COPYPTR(client.array.n.buffer);
    826886    for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
    827887    {
    828         SLC_COPYPTR(client.array.t[i].buffer); /*@todo*/
    829     }
    830 #ifdef CR_NV_vertex_program
    831     for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++) {
    832     {
    833         SLC_COPYPTR(client.array.a[i].buffer); /*@todo*/
    834     }
    835 #endif
    836 #endif /*CR_ARB_vertex_buffer_object2*/
     888        SLC_COPYPTR(client.array.t[i].buffer);
     889    }
     890# ifdef CR_NV_vertex_program
     891    for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
     892    {
     893        SLC_COPYPTR(client.array.a[i].buffer);
     894    }
     895# endif
     896#endif /*CR_ARB_vertex_buffer_object*/
    837897
    838898    /*@todo CR_NV_vertex_program*/
     
    10931153            //pBufferObj->dirtyStart = 0;
    10941154            //pBufferObj->dirtyLength = pBufferObj->size;
    1095         }
     1155        }
     1156        else if (pBufferObj->name!=0 && pBufferObj->size>0)
     1157        {
     1158            rc = SSMR3GetMem(pSSM, &pBufferObj->data, sizeof(pBufferObj->data));
     1159            AssertRCReturn(rc, rc);
     1160
     1161            if (pBufferObj->data)
     1162            {
     1163                pBufferObj->data = crAlloc(pBufferObj->size);
     1164                rc = SSMR3GetMem(pSSM, pBufferObj->data, pBufferObj->size);
     1165                AssertRCReturn(rc, rc);
     1166            }
     1167        }
     1168
    10961169
    10971170        if (key!=0)
     
    11001173    //FILLDIRTY(GetCurrentBits()->bufferobject.dirty);
    11011174    /* Load pointers */
     1175#define CRS_GET_BO(name) (((name)==0) ? (pContext->bufferobject.nullBuffer) : crHashtableSearch(pContext->bufferobject.buffers, name))
    11021176    rc = SSMR3GetU32(pSSM, &ui);
    11031177    AssertRCReturn(rc, rc);
    1104     pContext->bufferobject.arrayBuffer = ui==0 ? pContext->bufferobject.nullBuffer
    1105                                                  : crHashtableSearch(pContext->bufferobject.buffers, ui);
     1178    pContext->bufferobject.arrayBuffer = CRS_GET_BO(ui);
    11061179    rc = SSMR3GetU32(pSSM, &ui);
    11071180    AssertRCReturn(rc, rc);
    1108     pContext->bufferobject.elementsBuffer = ui==0 ? pContext->bufferobject.nullBuffer
    1109                                                     : crHashtableSearch(pContext->bufferobject.buffers, ui);
     1181    pContext->bufferobject.elementsBuffer = CRS_GET_BO(ui);
     1182
     1183    /* Load bound array buffers*/
     1184    rc = SSMR3GetU32(pSSM, &ui);
     1185    AssertRCReturn(rc, rc);
     1186    pContext->client.array.v.buffer = CRS_GET_BO(ui);
     1187
     1188    rc = SSMR3GetU32(pSSM, &ui);
     1189    AssertRCReturn(rc, rc);
     1190    pContext->client.array.c.buffer = CRS_GET_BO(ui);
     1191
     1192    rc = SSMR3GetU32(pSSM, &ui);
     1193    AssertRCReturn(rc, rc);
     1194    pContext->client.array.f.buffer = CRS_GET_BO(ui);
     1195
     1196    rc = SSMR3GetU32(pSSM, &ui);
     1197    AssertRCReturn(rc, rc);
     1198    pContext->client.array.s.buffer = CRS_GET_BO(ui);
     1199
     1200    rc = SSMR3GetU32(pSSM, &ui);
     1201    AssertRCReturn(rc, rc);
     1202    pContext->client.array.e.buffer = CRS_GET_BO(ui);
     1203
     1204    rc = SSMR3GetU32(pSSM, &ui);
     1205    AssertRCReturn(rc, rc);
     1206    pContext->client.array.i.buffer = CRS_GET_BO(ui);
     1207
     1208    rc = SSMR3GetU32(pSSM, &ui);
     1209    AssertRCReturn(rc, rc);
     1210    pContext->client.array.n.buffer = CRS_GET_BO(ui);
     1211
     1212    for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++)
     1213    {
     1214        rc = SSMR3GetU32(pSSM, &ui);
     1215        AssertRCReturn(rc, rc);
     1216        pContext->client.array.t[i].buffer = CRS_GET_BO(ui);
     1217    }
     1218# ifdef CR_NV_vertex_program
     1219    for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
     1220    {
     1221        rc = SSMR3GetU32(pSSM, &ui);
     1222        AssertRCReturn(rc, rc);
     1223        pContext->client.array.a[i].buffer = CRS_GET_BO(ui);
     1224    }
     1225# endif
     1226#undef CRS_GET_BO
     1227
     1228    pContext->bufferobject.bResyncNeeded = GL_TRUE;
    11101229#endif
    11111230
  • trunk/src/VBox/HostServices/SharedOpenGL/crserver/crservice.cpp

    r23094 r23123  
    7171
    7272static const char* gszVBoxOGLSSMMagic = "***OpenGL state data***";
    73 #define SHCROGL_SSM_VERSION 7
     73#define SHCROGL_SSM_VERSION 8
    7474
    7575typedef struct
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