VirtualBox

Ignore:
Timestamp:
Nov 28, 2012 7:10:56 AM (12 years ago)
Author:
vboxsync
Message:

crOpenGL: double-buffering for offscreen rendering, bugxifes

Location:
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server.h

    r43932 r43980  
    134134int32_t crServerSetOffscreenRenderingMode(GLubyte value);
    135135void crServerRedirMuralFBO(CRMuralInfo *mural, GLubyte redir);
    136 void crServerCreateMuralFBO(CRMuralInfo *mural);
    137136void crServerDeleteMuralFBO(CRMuralInfo *mural);
    138137void crServerPresentFBO(CRMuralInfo *mural);
    139138GLboolean crServerIsRedirectedToFBO();
     139GLuint crServerMuralFBOIdxFromBufferName(CRMuralInfo *mural, GLenum buffer);
     140void crServerMuralFBOSwapBuffers(CRMuralInfo *mural);
     141
     142#define CR_SERVER_FBO_BB_IDX(_mural) ((_mural)->iBbBuffer)
     143#define CR_SERVER_FBO_FB_IDX(_mural) (((_mural)->iBbBuffer + 1) % ((_mural)->cBuffers))
     144
    140145PCR_BLITTER crServerGetFBOPresentBlitter(CRMuralInfo*pMural);
    141146
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_blitter.cpp

    r43945 r43980  
    380380    Assert(CrBltIsEntered(pBlitter));
    381381
     382    if (pBlitter->Flags.SupportsFBO)
     383    {
     384        cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_FRAMEBUFFER, 0);
     385        cr_server.head_spu->dispatch_table.DrawBuffer(GL_BACK);
     386        cr_server.head_spu->dispatch_table.ReadBuffer(GL_BACK);
     387    }
     388
     389    cr_server.head_spu->dispatch_table.Flush();
     390
    382391    if (pBlitter->pRestoreCtxInfo != &pBlitter->CtxInfo)
     392    {
     393        GLuint idDrawFBO, idReadFBO;
     394        CRMuralInfo *pRestoreMural = pBlitter->pRestoreMural;
     395        if (pRestoreMural->fUseFBO && crServerSupportRedirMuralFBO())
     396        {
     397            idDrawFBO = pRestoreMural->aidFBOs[pRestoreMural->iCurDrawBuffer];
     398            idReadFBO = pRestoreMural->aidFBOs[pRestoreMural->iCurReadBuffer];
     399        }
     400        else
     401        {
     402            idDrawFBO = 0;
     403            idReadFBO = 0;
     404        }
     405
    383406        cr_server.head_spu->dispatch_table.MakeCurrent(pBlitter->pRestoreMural->spuWindow, 0,
    384407                pBlitter->pRestoreCtxInfo->SpuContext >= 0
    385408                    ? pBlitter->pRestoreCtxInfo->SpuContext : cr_server.MainContextInfo.SpuContext);
    386     else
     409        crStateSwichPostprocess(pBlitter->pRestoreCtxInfo->pContext, pBlitter->pRestoreCtxInfo->pContext, idDrawFBO, idReadFBO);
     410    }
     411    else
     412    {
     413        Assert(0);
    387414        cr_server.head_spu->dispatch_table.MakeCurrent(0, 0, 0);
     415    }
    388416
    389417    pBlitter->pRestoreCtxInfo = NULL;
     
    404432    }
    405433
    406     pBlitter->pRestoreCtxInfo = pRestoreCtxInfo ? pRestoreCtxInfo : &pBlitter->CtxInfo;
    407     pBlitter->pRestoreMural = pRestoreMural;
     434    if (pRestoreCtxInfo)
     435    {
     436        GLuint idDrawFBO, idReadFBO;
     437        pBlitter->pRestoreCtxInfo = pRestoreCtxInfo;
     438        pBlitter->pRestoreMural = pRestoreMural;
     439
     440        if (pRestoreMural->fUseFBO && crServerSupportRedirMuralFBO())
     441        {
     442            idDrawFBO = pRestoreMural->aidFBOs[pRestoreMural->iCurDrawBuffer];
     443            idReadFBO = pRestoreMural->aidFBOs[pRestoreMural->iCurReadBuffer];
     444        }
     445        else
     446        {
     447            idDrawFBO = 0;
     448            idReadFBO = 0;
     449        }
     450        crStateSwichPrepare(NULL, pRestoreCtxInfo->pContext, idDrawFBO, idReadFBO);
     451
     452        cr_server.head_spu->dispatch_table.Flush();
     453    }
     454    else
     455    {
     456        Assert(0);
     457        pBlitter->pRestoreCtxInfo = &pBlitter->CtxInfo;
     458
     459    }
    408460
    409461    cr_server.head_spu->dispatch_table.MakeCurrent(pBlitter->pCurrentMural->spuWindow, 0, pBlitter->CtxInfo.SpuContext);
     
    435487    RTRECTSIZE DstSize = {pBlitter->pCurrentMural->width, pBlitter->pCurrentMural->height};
    436488
     489    cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
     490
    437491    crBltBlitTexBuf(pBlitter, pSrc, paSrcRects, GL_BACK, &DstSize, paDstRects, cRects, fFlags);
    438492}
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_clear.c

    r41380 r43980  
    434434    if (crServerIsRedirectedToFBO())
    435435    {
     436        crServerMuralFBOSwapBuffers(mural);
    436437        crServerPresentFBO(mural);
    437438    }
     
    453454    if (cr_server.curClient->currentMural->bFbDraw && crServerIsRedirectedToFBO())
    454455    {
    455 #ifdef DEBUG_misha
    456         CRASSERT(0);
    457 #endif
    458456        crServerPresentFBO(cr_server.curClient->currentMural);
    459457    }
     
    473471    if (cr_server.curClient->currentMural->bFbDraw && crServerIsRedirectedToFBO())
    474472    {
    475 #ifdef DEBUG_misha
    476         CRASSERT(0);
    477 #endif
    478473        crServerPresentFBO(cr_server.curClient->currentMural);
    479474    }
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_context.c

    r43932 r43980  
    281281    CRContextInfo *ctxInfo = NULL;
    282282    CRContext *ctx, *oldCtx = NULL;
     283    GLuint idDrawFBO, idReadFBO;
    283284
    284285    if (context >= 0 && window >= 0) {
     
    332333     * crStateSwichPrepare restores the FBO state to its default values before the context window switch,
    333334     * while crStateSwichPostprocess restores it back to the original values */
    334     oldCtx = crStateSwichPrepare(ctx, cr_server.bUseMultipleContexts, oldMural && oldMural->fUseFBO && crServerSupportRedirMuralFBO() ? oldMural->idFBO : 0);
     335    oldCtx = crStateGetCurrent();
     336    if (oldMural && oldMural->fUseFBO && crServerSupportRedirMuralFBO())
     337    {
     338        idDrawFBO = oldMural->aidFBOs[oldMural->iCurDrawBuffer];
     339        idReadFBO = oldMural->aidFBOs[oldMural->iCurReadBuffer];
     340    }
     341    else
     342    {
     343        idDrawFBO = 0;
     344        idReadFBO = 0;
     345    }
     346    crStateSwichPrepare(cr_server.bUseMultipleContexts ? NULL : ctx, oldCtx, idDrawFBO, idReadFBO);
    335347
    336348    /*
     
    395407    crStateMakeCurrent( ctx );
    396408
    397     crStateSwichPostprocess(oldCtx, cr_server.bUseMultipleContexts, mural->fUseFBO && crServerSupportRedirMuralFBO() ? mural->idFBO : 0);
     409    if (mural && mural->fUseFBO && crServerSupportRedirMuralFBO())
     410    {
     411        GLuint id = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.drawBuffer);
     412        if (id != mural->iCurDrawBuffer)
     413        {
     414            crWarning("DBO draw buffer changed on make current");
     415            mural->iCurDrawBuffer = id;
     416        }
     417
     418        id = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.readBuffer);
     419        if (id != mural->iCurReadBuffer)
     420        {
     421            crWarning("DBO read buffer changed on make current");
     422            mural->iCurReadBuffer = id;
     423        }
     424
     425        idDrawFBO = mural->aidFBOs[mural->iCurDrawBuffer];
     426        idReadFBO = mural->aidFBOs[mural->iCurReadBuffer];
     427    }
     428    else
     429    {
     430        idDrawFBO = 0;
     431        idReadFBO = 0;
     432    }
     433    crStateSwichPostprocess(ctx, cr_server.bUseMultipleContexts ? ctx : oldCtx, idDrawFBO, idReadFBO);
    398434
    399435    if (!ctx->framebufferobject.drawFB
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_framebuffer.c

    r41380 r43980  
    7272    {
    7373        CRContext *ctx = crStateGetCurrent();
    74         if (ctx->buffer.drawBuffer == GL_FRONT || ctx->buffer.drawBuffer == GL_FRONT_LEFT)
     74        if (ctx->buffer.drawBuffer == GL_FRONT || ctx->buffer.drawBuffer == GL_FRONT_LEFT || ctx->buffer.drawBuffer == GL_FRONT_RIGHT)
    7575            cr_server.curClient->currentMural->bFbDraw = GL_TRUE;
    7676    }
     
    7878    if (0==framebuffer && crServerIsRedirectedToFBO())
    7979    {
    80         cr_server.head_spu->dispatch_table.BindFramebufferEXT(target, cr_server.curClient->currentMural->idFBO);
     80        if (target == GL_FRAMEBUFFER)
     81        {
     82            GLuint idDrawFBO = cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurDrawBuffer];
     83            GLuint idReadFBO = cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurReadBuffer];
     84            if (idDrawFBO == idReadFBO)
     85                cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_FRAMEBUFFER, idDrawFBO);
     86            else
     87            {
     88                cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, idReadFBO);
     89                cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, idDrawFBO);
     90            }
     91        }
     92        else if (target == GL_READ_FRAMEBUFFER)
     93        {
     94            GLuint idReadFBO = cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurReadBuffer];
     95            cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, idReadFBO);
     96        }
     97        else if (target == GL_DRAW_FRAMEBUFFER)
     98        {
     99            GLuint idDrawFBO = cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurDrawBuffer];
     100            cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, idDrawFBO);
     101        }
     102        else
     103        {
     104            crWarning("unknown target %d", target);
     105        }
    81106#ifdef DEBUG_misha
    82         Assert(0);
    83107        cr_server.head_spu->dispatch_table.GetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &rfb);
    84108        cr_server.head_spu->dispatch_table.GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &dfb);
    85109        if (GL_FRAMEBUFFER_EXT == target)
    86110        {
    87             Assert(rfb == cr_server.curClient->currentMural->idFBO);
    88             Assert(dfb == cr_server.curClient->currentMural->idFBO);
     111            Assert(rfb == cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurReadBuffer]);
     112            Assert(dfb == cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurDrawBuffer]);
    89113        }
    90114        else if (GL_READ_FRAMEBUFFER_EXT == target)
    91115        {
    92             Assert(rfb == cr_server.curClient->currentMural->idFBO);
     116            Assert(rfb == cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurReadBuffer]);
    93117        }
    94118        else if (GL_DRAW_FRAMEBUFFER_EXT == target)
    95119        {
    96             Assert(dfb == cr_server.curClient->currentMural->idFBO);
     120            Assert(dfb == cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurDrawBuffer]);
    97121        }
    98122        else
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_misc.c

    r43966 r43980  
    277277
    278278# ifdef DEBUG_misha
    279 # define CR_CHECK_BLITS
     279//# define CR_CHECK_BLITS
    280280#  include <iprt/assert.h>
    281281#  undef CRASSERT /* iprt assert's int3 are inlined that is why are more convenient to use since they can be easily disabled individually */
     
    869869    if (!crStateGetCurrent()->framebufferobject.drawFB)
    870870    {
    871         if (mode == GL_FRONT || mode == GL_FRONT_LEFT)
     871        if (mode == GL_FRONT || mode == GL_FRONT_LEFT || mode == GL_FRONT_RIGHT)
    872872            cr_server.curClient->currentMural->bFbDraw = GL_TRUE;
    873873
    874874        if (crServerIsRedirectedToFBO()
    875                 && cr_server.curClient->currentMural->idFBO)
    876         {
     875                && cr_server.curClient->currentMural->aidFBOs[0])
     876        {
     877            GLuint iBufferNeeded;
    877878            switch (mode)
    878879            {
    879880                case GL_BACK:
    880881                case GL_BACK_LEFT:
     882                case GL_BACK_RIGHT:
    881883                    mode = GL_COLOR_ATTACHMENT0;
     884                    iBufferNeeded = CR_SERVER_FBO_BB_IDX(cr_server.curClient->currentMural);
    882885                    break;
    883886                case GL_FRONT:
    884887                case GL_FRONT_LEFT:
    885                     crDebug("Setting GL_FRONT with FBO mode! (0x%x)", mode);
     888                case GL_FRONT_RIGHT:
    886889                    mode = GL_COLOR_ATTACHMENT0;
     890                    iBufferNeeded = CR_SERVER_FBO_FB_IDX(cr_server.curClient->currentMural);
    887891                    break;
    888892                default:
    889893                    crWarning("unexpected mode! 0x%x", mode);
     894                    iBufferNeeded = CR_SERVER_FBO_BB_IDX(cr_server.curClient->currentMural);
    890895                    break;
    891896            }
     897
     898            Assert(cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurDrawBuffer]);
     899            if (iBufferNeeded != cr_server.curClient->currentMural->iCurDrawBuffer)
     900            {
     901                cr_server.curClient->currentMural->iCurDrawBuffer = iBufferNeeded;
     902                cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER,
     903                        cr_server.curClient->currentMural->aidFBOs[iBufferNeeded]);
     904            }
    892905        }
    893906    }
     
    901914
    902915    if (crServerIsRedirectedToFBO()
    903             && cr_server.curClient->currentMural->idFBO
     916            && cr_server.curClient->currentMural->aidFBOs[0]
    904917            && !crStateGetCurrent()->framebufferobject.readFB)
    905918    {
     919        GLuint iBufferNeeded;
    906920        switch (mode)
    907921        {
    908922            case GL_BACK:
    909923            case GL_BACK_LEFT:
     924            case GL_BACK_RIGHT:
    910925                mode = GL_COLOR_ATTACHMENT0;
     926                iBufferNeeded = CR_SERVER_FBO_BB_IDX(cr_server.curClient->currentMural);
    911927                break;
    912928            case GL_FRONT:
    913929            case GL_FRONT_LEFT:
    914                 crWarning("GL_FRONT not supported for FBO mode!");
     930            case GL_FRONT_RIGHT:
    915931                mode = GL_COLOR_ATTACHMENT0;
     932                iBufferNeeded = CR_SERVER_FBO_FB_IDX(cr_server.curClient->currentMural);
    916933                break;
    917934            default:
    918935                crWarning("unexpected mode! 0x%x", mode);
     936                iBufferNeeded = CR_SERVER_FBO_BB_IDX(cr_server.curClient->currentMural);
    919937                break;
     938        }
     939
     940        Assert(cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurReadBuffer]);
     941        if (iBufferNeeded != cr_server.curClient->currentMural->iCurReadBuffer)
     942        {
     943            cr_server.curClient->currentMural->iCurReadBuffer = iBufferNeeded;
     944            cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER,
     945                    cr_server.curClient->currentMural->aidFBOs[iBufferNeeded]);
    920946        }
    921947    }
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_muralfbo.c

    r43932 r43980  
    232232}
    233233
     234static void crServerCreateMuralFBO(CRMuralInfo *mural);
     235
    234236void crServerRedirMuralFBO(CRMuralInfo *mural, GLubyte redir)
    235237{
    236238    if (mural->fUseFBO == redir)
    237239    {
    238         crWarning("crServerRedirMuralFBO called with the same redir status %d", redir);
     240        if (redir)
     241            crWarning("crServerRedirMuralFBO called with the same redir status %d", redir);
    239242        return;
    240243    }
     
    253256            cr_server.head_spu->dispatch_table.WindowShow(mural->spuWindow, mural->bVisible);
    254257
    255         if (mural->idFBO==0)
     258        if (mural->aidFBOs[0]==0)
    256259        {
    257260            crServerCreateMuralFBO(mural);
     
    260263        if (!crStateGetCurrent()->framebufferobject.drawFB)
    261264        {
    262             cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, mural->idFBO);
     265            cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, mural->aidFBOs[mural->iCurDrawBuffer]);
    263266        }
    264267        if (!crStateGetCurrent()->framebufferobject.readFB)
    265268        {
    266             cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, mural->idFBO);
     269            cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, mural->aidFBOs[mural->iCurReadBuffer]);
    267270        }
    268271
     
    300303}
    301304
    302 void crServerCreateMuralFBO(CRMuralInfo *mural)
     305static void crServerCreateMuralFBO(CRMuralInfo *mural)
    303306{
    304307    CRContext *ctx = crStateGetCurrent();
    305     GLuint uid;
     308    GLuint uid, i;
    306309    GLenum status;
    307310    SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
    308311
    309     CRASSERT(mural->idFBO==0);
    310 
     312    CRASSERT(mural->aidFBOs[0]==0);
     313    CRASSERT(mural->aidFBOs[1]==0);
     314
     315    mural->cBuffers = 2;
     316    mural->iBbBuffer = 0;
    311317    /*Color texture*/
    312     gl->GenTextures(1, &mural->idColorTex);
    313     gl->BindTexture(GL_TEXTURE_2D, mural->idColorTex);
    314     gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    315     gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    316     gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    317     gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    318     if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
    319     {
    320         gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
    321     }
    322     gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mural->width, mural->height,
    323                    0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
     318    for (i = 0; i < mural->cBuffers; ++i)
     319    {
     320        gl->GenTextures(1, &mural->aidColorTexs[i]);
     321        gl->BindTexture(GL_TEXTURE_2D, mural->aidColorTexs[i]);
     322        gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     323        gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     324        gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
     325        gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
     326        if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     327        {
     328            gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
     329        }
     330        gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mural->width, mural->height,
     331                       0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
     332    }
    324333
    325334    /*Depth&Stencil*/
     
    327336    gl->BindRenderbufferEXT(GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
    328337    gl->RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT,
    329                                mural->width, mural->height);
     338                           mural->width, mural->height);
    330339
    331340    /*FBO*/
    332     gl->GenFramebuffersEXT(1, &mural->idFBO);
    333     gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mural->idFBO);
    334 
    335     gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
    336                                 GL_TEXTURE_2D, mural->idColorTex, 0);
    337     gl->FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
    338                                    GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
    339     gl->FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
    340                                    GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
    341 
    342     status = gl->CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    343     if (status!=GL_FRAMEBUFFER_COMPLETE_EXT)
    344     {
    345         crWarning("FBO status(0x%x) isn't complete", status);
     341    for (i = 0; i < mural->cBuffers; ++i)
     342    {
     343        gl->GenFramebuffersEXT(1, &mural->aidFBOs[i]);
     344        gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mural->aidFBOs[i]);
     345
     346        gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
     347                                    GL_TEXTURE_2D, mural->aidColorTexs[i], 0);
     348        gl->FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
     349                                       GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
     350        gl->FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
     351                                       GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
     352
     353        status = gl->CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
     354        if (status!=GL_FRAMEBUFFER_COMPLETE_EXT)
     355        {
     356            crWarning("FBO status(0x%x) isn't complete", status);
     357        }
    346358    }
    347359
    348360    mural->fboWidth = mural->width;
    349361    mural->fboHeight = mural->height;
     362
     363    mural->iCurDrawBuffer = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.drawBuffer);
     364    mural->iCurReadBuffer = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.readBuffer);
    350365
    351366    /*PBO*/
     
    386401    CRASSERT(!mural->fUseFBO);
    387402
    388     if (mural->idFBO!=0)
    389     {
    390         cr_server.head_spu->dispatch_table.DeleteTextures(1, &mural->idColorTex);
     403    if (mural->aidFBOs[0]!=0)
     404    {
     405        GLuint i;
     406        for (i = 0; i < mural->cBuffers; ++i)
     407        {
     408            cr_server.head_spu->dispatch_table.DeleteTextures(1, &mural->aidColorTexs[i]);
     409            mural->aidColorTexs[i] = 0;
     410        }
     411
    391412        cr_server.head_spu->dispatch_table.DeleteRenderbuffersEXT(1, &mural->idDepthStencilRB);
    392         cr_server.head_spu->dispatch_table.DeleteFramebuffersEXT(1, &mural->idFBO);
    393 
    394         mural->idFBO = 0;
    395         mural->idColorTex = 0;
    396413        mural->idDepthStencilRB = 0;
     414
     415        for (i = 0; i < mural->cBuffers; ++i)
     416        {
     417            cr_server.head_spu->dispatch_table.DeleteFramebuffersEXT(1, &mural->aidFBOs[i]);
     418            mural->aidFBOs[i] = 0;
     419        }
    397420    }
    398421
     
    403426        mural->idPBO = 0;
    404427    }
     428
     429    mural->cBuffers = 0;
    405430}
    406431
     
    503528            Tex.height = mural->height;
    504529            Tex.target = GL_TEXTURE_2D;
    505             Tex.hwid = mural->idColorTex;
     530            Tex.hwid = mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)];
    506531            Rect.xLeft = 0;
    507532            Rect.yTop = 0;
     
    529554    bUsePBO = cr_server.bUsePBOForReadback && mural->idPBO;
    530555
    531     cr_server.head_spu->dispatch_table.BindTexture(GL_TEXTURE_2D, mural->idColorTex);
     556    cr_server.head_spu->dispatch_table.BindTexture(GL_TEXTURE_2D, mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)]);
    532557
    533558    if (bUsePBO)
     
    648673           && cr_server.curClient->currentMural->fUseFBO;
    649674}
     675
     676GLuint crServerMuralFBOIdxFromBufferName(CRMuralInfo *mural, GLenum buffer)
     677{
     678    if (buffer == GL_FRONT
     679            || buffer == GL_FRONT_LEFT
     680            || buffer == GL_FRONT_RIGHT)
     681        return CR_SERVER_FBO_FB_IDX(mural);
     682    return CR_SERVER_FBO_BB_IDX(mural);
     683}
     684
     685void crServerMuralFBOSwapBuffers(CRMuralInfo *mural)
     686{
     687    CRContext *ctx = crStateGetCurrent();
     688    GLuint iOldCurDrawBuffer = mural->iCurDrawBuffer;
     689    GLuint iOldCurReadBuffer = mural->iCurReadBuffer;
     690    mural->iBbBuffer = ((mural->iBbBuffer + 1) % (mural->cBuffers));
     691    mural->iCurDrawBuffer = ((mural->iCurDrawBuffer + 1) % (mural->cBuffers));
     692    mural->iCurReadBuffer = ((mural->iCurReadBuffer + 1) % (mural->cBuffers));
     693    Assert(iOldCurDrawBuffer != mural->iCurDrawBuffer || mural->cBuffers == 1);
     694    Assert(iOldCurReadBuffer != mural->iCurReadBuffer || mural->cBuffers == 1);
     695    if (!ctx->framebufferobject.drawFB && iOldCurDrawBuffer != mural->iCurDrawBuffer)
     696    {
     697        cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, mural->aidFBOs[mural->iCurDrawBuffer]);
     698    }
     699    if (!ctx->framebufferobject.readFB && iOldCurReadBuffer != mural->iCurReadBuffer)
     700    {
     701        cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, mural->aidFBOs[mural->iCurReadBuffer]);
     702    }
     703}
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_simpleget.py

    r43932 r43980  
    7777        fboid = crStateFBOHWIDtoID((GLuint) *get_values);
    7878        if (crServerIsRedirectedToFBO()
    79             && fboid==cr_server.curClient->currentMural->idFBO)
     79            && (fboid==cr_server.curClient->currentMural->aidFBOs[0]
     80            || fboid==cr_server.curClient->currentMural->aidFBOs[1]))
    8081        {
    8182            fboid = 0;
     
    8687    {
    8788        if (crServerIsRedirectedToFBO()
    88             && cr_server.curClient->currentMural->idFBO
     89            && cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurReadBuffer]
    8990            && !crStateGetCurrent()->framebufferobject.readFB)
    9091        {
     
    9596    {
    9697        if (crServerIsRedirectedToFBO()
    97             && cr_server.curClient->currentMural->idFBO
     98            && cr_server.curClient->currentMural->aidFBOs[cr_server.curClient->currentMural->iCurDrawBuffer]
    9899            && !crStateGetCurrent()->framebufferobject.drawFB)
    99100        {
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