VirtualBox

Ignore:
Timestamp:
Sep 17, 2009 1:48:46 PM (15 years ago)
Author:
vboxsync
Message:

crOpenGL: fix FBO/RBOs support, add snapshots compatibility

Location:
trunk/src/VBox/GuestHost/OpenGL/state_tracker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_diff.c

    r22363 r23094  
    236236#endif
    237237#ifdef CR_EXT_framebuffer_object
     238    /*Note, this should go after crStateTextureSwitch*/
    238239    crStateFramebufferObjectSwitch(from, to);
    239240#endif
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_framebuffer.c

    r22832 r23094  
    4242    fbo->framebuffers = crAllocHashtable();
    4343    fbo->renderbuffers = crAllocHashtable();
     44    fbo->bResyncNeeded = GL_FALSE;
    4445}
    4546
     
    5152    if (diff_api.DeleteFramebuffersEXT)
    5253    {
    53         diff_api.DeleteFramebuffersEXT(1, &pObj->id);
     54        diff_api.DeleteFramebuffersEXT(1, &pObj->hwid);
    5455    }
    5556#endif
     
    6566    if (diff_api.DeleteRenderbuffersEXT)
    6667    {
    67         diff_api.DeleteRenderbuffersEXT(1, &pObj->id);
     68        diff_api.DeleteRenderbuffersEXT(1, &pObj->hwid);
    6869    }
    6970#endif
     
    101102            CRSTATE_FBO_CHECKERR(!fbo->renderbuffer, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT");
    102103            fbo->renderbuffer->id = renderbuffer;
     104            fbo->renderbuffer->hwid = renderbuffer;
    103105            fbo->renderbuffer->internalformat = GL_RGBA;
    104106            crHashtableAdd(fbo->renderbuffers, renderbuffer, fbo->renderbuffer);
     
    158160                }
    159161
    160                 crHashtableDelete(fbo->renderbuffers, renderbuffers[i], crFree);
     162                crHashtableDelete(fbo->renderbuffers, renderbuffers[i], crStateFreeRBO);
    161163            }
    162164        }
     
    173175    CRSTATE_FBO_CHECKERR(g->current.inBeginEnd, GL_INVALID_OPERATION, "called in begin/end");
    174176    CRSTATE_FBO_CHECKERR(target!=GL_RENDERBUFFER_EXT, GL_INVALID_ENUM, "invalid target");
    175     CRSTATE_FBO_CHECKERR(rb, GL_INVALID_OPERATION, "no bound renderbuffer");
     177    CRSTATE_FBO_CHECKERR(!rb, GL_INVALID_OPERATION, "no bound renderbuffer");
    176178
    177179    rb->width = width;
     
    189191    CRSTATE_FBO_CHECKERR(g->current.inBeginEnd, GL_INVALID_OPERATION, "called in begin/end");
    190192    CRSTATE_FBO_CHECKERR(target!=GL_RENDERBUFFER_EXT, GL_INVALID_ENUM, "invalid target");
    191     CRSTATE_FBO_CHECKERR(rb, GL_INVALID_OPERATION, "no bound renderbuffer");
     193    CRSTATE_FBO_CHECKERR(!rb, GL_INVALID_OPERATION, "no bound renderbuffer");
    192194
    193195    switch (pname)
     
    276278            CRSTATE_FBO_CHECKERR(!fbo->framebuffer, GL_OUT_OF_MEMORY, "glBindFramebufferEXT");
    277279            fbo->framebuffer->id = framebuffer;
     280            fbo->framebuffer->hwid = framebuffer;
    278281            crStateInitFrameBuffer(fbo->framebuffer);
    279282            crHashtableAdd(fbo->framebuffers, framebuffer, fbo->framebuffer);
     
    305308                    fbo->framebuffer = NULL;
    306309                }
    307                 crHashtableDelete(fbo->framebuffers, framebuffers[i], crFree);
     310                crHashtableDelete(fbo->framebuffers, framebuffers[i], crStateFreeFBO);
    308311            }
    309312        }
     
    544547}
    545548
     549static void crStateSyncRenderbuffersCB(unsigned long key, void *data1, void *data2)
     550{
     551    CRRenderbufferObject *pRBO = (CRRenderbufferObject*) data1;
     552
     553    diff_api.GenRenderbuffersEXT(1, &pRBO->hwid);
     554
     555    diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, pRBO->hwid);
     556    diff_api.RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, pRBO->internalformat, pRBO->width, pRBO->height);
     557}
     558
     559static void crStateSyncAP(CRFBOAttachmentPoint *pAP, GLenum ap, CRContext *ctx)
     560{
     561    CRRenderbufferObject *pRBO;
     562    CRTextureObj *tobj;
     563
     564    switch (pAP->type)
     565    {
     566        case GL_TEXTURE:
     567            CRASSERT(pAP->name!=0);
     568           
     569            tobj = (CRTextureObj *) crHashtableSearch(ctx->shared->textureTable, pAP->name);
     570            if (tobj)
     571            {
     572                switch (tobj->target)
     573                {
     574                    case GL_TEXTURE_1D:
     575                        diff_api.FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, ap, tobj->target, pAP->name, pAP->level);
     576                        break;
     577                    case GL_TEXTURE_2D:
     578                    case GL_TEXTURE_RECTANGLE_ARB:
     579                        diff_api.FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ap, tobj->target, pAP->name, pAP->level);
     580                        break;
     581                    case GL_TEXTURE_CUBE_MAP_ARB:
     582                        diff_api.FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ap, pAP->face, pAP->name, pAP->level);
     583                        break;
     584                    case GL_TEXTURE_3D:
     585                        diff_api.FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, ap, tobj->target, pAP->name, pAP->level, pAP->zoffset);
     586                        break;
     587                    default:
     588                        crWarning("Unexpected textarget %d", tobj->target);
     589                }
     590            }
     591            else
     592            {
     593                crWarning("Unknown texture id %d", pAP->name);
     594            }
     595            break;
     596        case GL_RENDERBUFFER_EXT:
     597            pRBO = (CRRenderbufferObject*) crHashtableSearch(ctx->framebufferobject.renderbuffers, pAP->name);
     598            diff_api.FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, ap, GL_RENDERBUFFER_EXT, pRBO->hwid);
     599            break;
     600        case GL_NONE:
     601            /* Intentionally left blank */
     602            break;
     603        default: crWarning("Invalid attachment point type %d (ap: %i)", pAP->type, ap);
     604    }
     605}
     606
     607static void crStateSyncFramebuffersCB(unsigned long key, void *data1, void *data2)
     608{
     609    CRFramebufferObject *pFBO = (CRFramebufferObject*) data1;
     610    CRContext *ctx = (CRContext*) data2;
     611    GLint i;
     612
     613    diff_api.GenFramebuffersEXT(1, &pFBO->hwid);
     614
     615    diff_api.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, pFBO->hwid);
     616
     617    for (i=0; i<CR_MAX_COLOR_ATTACHMENTS; ++i)
     618    {
     619        crStateSyncAP(&pFBO->color[i], GL_COLOR_ATTACHMENT0_EXT+i, ctx);
     620    }
     621
     622    crStateSyncAP(&pFBO->depth, GL_DEPTH_ATTACHMENT_EXT, ctx);
     623    crStateSyncAP(&pFBO->stencil, GL_STENCIL_ATTACHMENT_EXT, ctx);
     624}
     625
    546626DECLEXPORT(void) STATE_APIENTRY
    547627crStateFramebufferObjectSwitch(CRContext *from, CRContext *to)
    548628{
    549     if (to->framebufferobject.framebuffer!=from->framebufferobject.framebuffer)
    550     {
     629    if (to->framebufferobject.bResyncNeeded)
     630    {
     631        to->framebufferobject.bResyncNeeded = GL_FALSE;
     632
     633        crHashtableWalk(to->framebufferobject.renderbuffers, crStateSyncRenderbuffersCB, NULL);
     634        crHashtableWalk(to->framebufferobject.framebuffers, crStateSyncFramebuffersCB, to);
     635
    551636        diff_api.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, to->framebufferobject.framebuffer?
    552             to->framebufferobject.framebuffer->id:0);
    553     }
    554 }
     637            to->framebufferobject.framebuffer->hwid:0);
     638
     639        diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, to->framebufferobject.renderbuffer?
     640            to->framebufferobject.renderbuffer->hwid:0);
     641    }
     642    else
     643    {
     644        if (to->framebufferobject.framebuffer!=from->framebufferobject.framebuffer)
     645        {
     646            diff_api.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, to->framebufferobject.framebuffer?
     647                to->framebufferobject.framebuffer->hwid:0);
     648        }
     649
     650        if (to->framebufferobject.renderbuffer!=from->framebufferobject.renderbuffer)
     651        {
     652            diff_api.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, to->framebufferobject.renderbuffer?
     653                to->framebufferobject.renderbuffer->hwid:0);
     654        }
     655    }
     656}
     657
     658DECLEXPORT(GLuint) STATE_APIENTRY crStateGetFramebufferHWID(GLuint id)
     659{
     660    CRContext *g = GetCurrentContext();
     661    CRFramebufferObject *pFBO = (CRFramebufferObject*) crHashtableSearch(g->framebufferobject.framebuffers, id);
     662
     663    return pFBO ? pFBO->hwid : 0;
     664}
     665
     666DECLEXPORT(GLuint) STATE_APIENTRY crStateGetRenderbufferHWID(GLuint id)
     667{
     668    CRContext *g = GetCurrentContext();
     669    CRRenderbufferObject *pRBO = (CRRenderbufferObject*) crHashtableSearch(g->framebufferobject.renderbuffers, id);
     670
     671    return pRBO ? pRBO->hwid : 0;
     672}
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c

    r16970 r23094  
    466466}
    467467
     468static void crStateSaveFramebuffersCB(unsigned long key, void *data1, void *data2)
     469{
     470    CRFramebufferObject *pFBO = (CRFramebufferObject*) data1;
     471    PSSMHANDLE pSSM = (PSSMHANDLE) data2;
     472    int32_t rc;
     473
     474    rc = SSMR3PutMem(pSSM, &key, sizeof(key));
     475    CRASSERT(rc == VINF_SUCCESS);
     476
     477    rc = SSMR3PutMem(pSSM, pFBO, sizeof(*pFBO));
     478    CRASSERT(rc == VINF_SUCCESS);
     479}
     480
     481static void crStateSaveRenderbuffersCB(unsigned long key, void *data1, void *data2)
     482{
     483    CRRenderbufferObject *pRBO = (CRRenderbufferObject*) data1;
     484    PSSMHANDLE pSSM = (PSSMHANDLE) data2;
     485    int32_t rc;
     486
     487    rc = SSMR3PutMem(pSSM, &key, sizeof(key));
     488    CRASSERT(rc == VINF_SUCCESS);
     489
     490    rc = SSMR3PutMem(pSSM, pRBO, sizeof(*pRBO));
     491    CRASSERT(rc == VINF_SUCCESS);
     492}
     493
    468494static int32_t crStateLoadProgram(CRProgram **ppProgram, PSSMHANDLE pSSM)
    469495{
     
    712738    /* This one is unused it seems*/
    713739    CRASSERT(!pContext->program.errorString);
     740
     741#ifdef CR_EXT_framebuffer_object
     742    /* Save FBOs */
     743    ui32 = crHashtableNumElements(pContext->framebufferobject.framebuffers);
     744    rc = SSMR3PutU32(pSSM, ui32);
     745    AssertRCReturn(rc, rc);
     746    crHashtableWalk(pContext->framebufferobject.framebuffers, crStateSaveFramebuffersCB, pSSM);
     747    ui32 = crHashtableNumElements(pContext->framebufferobject.renderbuffers);
     748    rc = SSMR3PutU32(pSSM, ui32);
     749    AssertRCReturn(rc, rc);
     750    crHashtableWalk(pContext->framebufferobject.renderbuffers, crStateSaveRenderbuffersCB, pSSM);
     751    rc = SSMR3PutU32(pSSM, pContext->framebufferobject.framebuffer?pContext->framebufferobject.framebuffer->id:0);
     752    AssertRCReturn(rc, rc);
     753    rc = SSMR3PutU32(pSSM, pContext->framebufferobject.renderbuffer?pContext->framebufferobject.renderbuffer->id:0);
     754    AssertRCReturn(rc, rc);
     755#endif
    714756
    715757    return VINF_SUCCESS;
     
    852894    }
    853895
     896    SLC_COPYPTR(framebufferobject.framebuffers);
     897    SLC_COPYPTR(framebufferobject.renderbuffers);
     898
    854899    /* Have to preserve original context id */
    855900    CRASSERT(pTmpContext->id == pContext->id);
     
    10991144    pContext->program.bResyncNeeded = GL_TRUE;
    11001145
     1146#ifdef CR_EXT_framebuffer_object
     1147    /* Load FBOs */
     1148    rc = SSMR3GetU32(pSSM, &uiNumElems);
     1149    AssertRCReturn(rc, rc);
     1150    for (ui=0; ui<uiNumElems; ++ui)
     1151    {
     1152        CRFramebufferObject *pFBO;
     1153        pFBO = crAlloc(sizeof(*pFBO));
     1154        if (!pFBO) return VERR_NO_MEMORY;
     1155
     1156        rc = SSMR3GetMem(pSSM, &key, sizeof(key));
     1157        AssertRCReturn(rc, rc);
     1158
     1159        rc = SSMR3GetMem(pSSM, pFBO, sizeof(*pFBO));
     1160        AssertRCReturn(rc, rc);
     1161
     1162        crHashtableAdd(pContext->framebufferobject.framebuffers, key, pFBO);
     1163    }
     1164
     1165    rc = SSMR3GetU32(pSSM, &uiNumElems);
     1166    AssertRCReturn(rc, rc);
     1167    for (ui=0; ui<uiNumElems; ++ui)
     1168    {
     1169        CRRenderbufferObject *pRBO;
     1170        pRBO = crAlloc(sizeof(*pRBO));
     1171        if (!pRBO) return VERR_NO_MEMORY;
     1172
     1173        rc = SSMR3GetMem(pSSM, &key, sizeof(key));
     1174        AssertRCReturn(rc, rc);
     1175
     1176        rc = SSMR3GetMem(pSSM, pRBO, sizeof(*pRBO));
     1177        AssertRCReturn(rc, rc);
     1178
     1179        crHashtableAdd(pContext->framebufferobject.renderbuffers, key, pRBO);
     1180    }
     1181
     1182    rc = SSMR3GetU32(pSSM, &ui);
     1183    AssertRCReturn(rc, rc);
     1184    pContext->framebufferobject.framebuffer = ui==0 ? NULL
     1185                                                    : crHashtableSearch(pContext->framebufferobject.framebuffers, ui);
     1186
     1187    rc = SSMR3GetU32(pSSM, &ui);
     1188    AssertRCReturn(rc, rc);
     1189    pContext->framebufferobject.renderbuffer = ui==0 ? NULL
     1190                                                    : crHashtableSearch(pContext->framebufferobject.renderbuffers, ui);
     1191
     1192    /* Mark FBOs/RBOs for resending to GPU */
     1193    pContext->framebufferobject.bResyncNeeded = GL_TRUE;
     1194#endif
     1195
    11011196    return VINF_SUCCESS;
    11021197}
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