VirtualBox

Changeset 44053 in vbox for trunk/src/VBox/GuestHost


Ignore:
Timestamp:
Dec 6, 2012 3:21:37 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
82526
Message:

crOpenGL: fix framebuffer state

File:
1 edited

Legend:

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

    r43980 r44053  
    2323#include "cr_mem.h"
    2424
    25 #define CRSTATE_FBO_CHECKERR(expr, result, message)         \
     25#define CRSTATE_FBO_CHECKERR_RET(expr, result, message, ret)         \
    2626    if (expr) {                                             \
    2727        crStateError(__LINE__, __FILE__, result, message);  \
    28         return;                                             \
    29     }
    30    
     28        return ret;                                             \
     29    }
     30
     31#define CRSTATE_NO_RETURN
     32
     33#define CRSTATE_FBO_CHECKERR(expr, result, message) CRSTATE_FBO_CHECKERR_RET(expr, result, message, CRSTATE_NO_RETURN)
     34
    3135DECLEXPORT(void) STATE_APIENTRY
    3236crStateFramebufferObjectInit(CRContext *ctx)
     
    381385}
    382386
    383 static void crStateFramebufferTextureCheck(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level,
    384                                            GLboolean *failed, CRFBOAttachmentPoint **ap, CRTextureObj **tobj)
    385 {
    386     CRContext *g = GetCurrentContext();
    387     CRFramebufferObjectState *fbo = &g->framebufferobject;
    388     CRFramebufferObject *pFBO;
     387static GLuint crStateFramebufferTextureCheck(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level,
     388                    CRFBOAttachmentPoint **aap, CRTextureObj **tobj)
     389{
     390    CRContext *g = GetCurrentContext();
     391    CRFramebufferObjectState *fbo = &g->framebufferobject;
     392    CRFramebufferObject *apFBOs[2];
     393    GLuint cPBOs = 0, i;
    389394    GLuint maxtexsizelog2;
    390395
    391     *failed = GL_TRUE;
    392 
    393     CRSTATE_FBO_CHECKERR(g->current.inBeginEnd, GL_INVALID_OPERATION, "called in begin/end");
    394     CRSTATE_FBO_CHECKERR(((target!=GL_FRAMEBUFFER_EXT) && (target!=GL_READ_FRAMEBUFFER) && (target!=GL_DRAW_FRAMEBUFFER)),
    395                          GL_INVALID_ENUM, "invalid target");
    396     pFBO = GL_READ_FRAMEBUFFER==target ? fbo->readFB : fbo->drawFB;
    397     CRSTATE_FBO_CHECKERR(!pFBO, GL_INVALID_OPERATION, "no fbo bound");
    398     CRSTATE_FBO_CHECKERR(!crStateGetFBOAttachmentPoint(pFBO, attachment, ap), GL_INVALID_ENUM, "invalid attachment");
     396
     397    CRSTATE_FBO_CHECKERR_RET(g->current.inBeginEnd, GL_INVALID_OPERATION, "called in begin/end", 0);
     398    CRSTATE_FBO_CHECKERR_RET(((target!=GL_FRAMEBUFFER_EXT) && (target!=GL_READ_FRAMEBUFFER) && (target!=GL_DRAW_FRAMEBUFFER)),
     399                         GL_INVALID_ENUM, "invalid target", 0);
     400    switch (target)
     401    {
     402        case GL_READ_FRAMEBUFFER:
     403            cPBOs = 1;
     404            apFBOs[0] = fbo->readFB;
     405            break;
     406        case GL_DRAW_FRAMEBUFFER:
     407            cPBOs = 1;
     408            apFBOs[0] = fbo->drawFB;
     409            break;
     410        case GL_FRAMEBUFFER:
     411            if (fbo->readFB == fbo->drawFB)
     412            {
     413                cPBOs = 1;
     414                apFBOs[0] = fbo->readFB;
     415            }
     416            else
     417            {
     418                cPBOs = 2;
     419                apFBOs[0] = fbo->readFB;
     420                apFBOs[1] = fbo->drawFB;
     421            }
     422            break;
     423        default:
     424            crWarning("unexpected dtarget value: 0x%x", target);
     425            CRSTATE_FBO_CHECKERR_RET(1, GL_INVALID_ENUM, "unexpected target", 0);
     426            break;
     427    }
     428
     429    Assert(cPBOs);
     430    Assert(cPBOs <= 2);
     431
     432   for (i = 0; i < cPBOs; ++i)
     433    {
     434        CRSTATE_FBO_CHECKERR_RET(!apFBOs[i], GL_INVALID_OPERATION, "no fbo bound", 0);
     435        CRSTATE_FBO_CHECKERR_RET(!crStateGetFBOAttachmentPoint(apFBOs[i], attachment, &aap[i]), GL_INVALID_ENUM, "invalid attachment", 0);
     436    }
    399437
    400438    if (!texture)
    401439    {
    402         *failed = GL_FALSE;
    403         return;
     440        return cPBOs;
    404441    }
    405442
     
    429466            break;
    430467        default:
    431             CRSTATE_FBO_CHECKERR(GL_TRUE, GL_INVALID_OPERATION, "invalid textarget");
    432     }
    433 
    434     CRSTATE_FBO_CHECKERR(!*tobj, GL_INVALID_OPERATION, "invalid textarget/texture combo");
     468            CRSTATE_FBO_CHECKERR_RET(GL_TRUE, GL_INVALID_OPERATION, "invalid textarget", 0);
     469    }
     470
     471    CRSTATE_FBO_CHECKERR_RET(!*tobj, GL_INVALID_OPERATION, "invalid textarget/texture combo", 0);
    435472
    436473    if (GL_TEXTURE_RECTANGLE_ARB==textarget)
    437474    {
    438         CRSTATE_FBO_CHECKERR(level!=0, GL_INVALID_VALUE, "non zero mipmap level");
    439     }
    440 
    441     CRSTATE_FBO_CHECKERR(level<0, GL_INVALID_VALUE, "level<0");
    442     CRSTATE_FBO_CHECKERR(level>maxtexsizelog2, GL_INVALID_VALUE, "level too big");
    443 
    444     *failed = GL_FALSE;
     475        CRSTATE_FBO_CHECKERR_RET(level!=0, GL_INVALID_VALUE, "non zero mipmap level", 0);
     476    }
     477
     478    CRSTATE_FBO_CHECKERR_RET(level<0, GL_INVALID_VALUE, "level<0", 0);
     479    CRSTATE_FBO_CHECKERR_RET(level>maxtexsizelog2, GL_INVALID_VALUE, "level too big", 0);
    445480
    446481#ifdef IN_GUEST
    447     if ((*ap)->type!=GL_TEXTURE || (*ap)->name!=texture || (*ap)->level!=level)
    448     {
    449         pFBO->status = GL_FRAMEBUFFER_UNDEFINED;
    450     }
    451 #endif
     482    for (i = 0; i < cPBOs; ++i)
     483    {
     484        if ((aap[i])->type!=GL_TEXTURE || (aap[i])->name!=texture || (aap[i])->level!=level)
     485        {
     486            apFBOs[i]->status = GL_FRAMEBUFFER_UNDEFINED;
     487        }
     488    }
     489#endif
     490
     491    Assert(cPBOs);
     492    Assert(cPBOs <= 2);
     493
     494    return cPBOs;
    452495}
    453496
     
    457500    CRContext *g = GetCurrentContext();
    458501    CRFramebufferObjectState *fbo = &g->framebufferobject;
    459     CRFBOAttachmentPoint *ap;
     502    CRFBOAttachmentPoint *aap[2];
     503    GLuint cap, i;
    460504    CRTextureObj *tobj;
    461     GLboolean failed;
    462 
    463     crStateFramebufferTextureCheck(target, attachment, textarget, texture, level, &failed, &ap, &tobj);
    464     if (failed) return;
     505
     506    cap = crStateFramebufferTextureCheck(target, attachment, textarget, texture, level, aap, &tobj);
     507    if (!cap) return;
    465508
    466509    if (!texture)
    467510    {
    468         crStateInitFBOAttachmentPoint(ap);
     511        for (i = 0; i < cap; ++i)
     512        {
     513            crStateInitFBOAttachmentPoint(aap[i]);
     514        }
    469515        return;
    470516    }
     
    476522#endif
    477523
    478     crStateInitFBOAttachmentPoint(ap);
    479     ap->type = GL_TEXTURE;
    480     ap->name = texture;
    481     ap->level = level;
     524    for (i = 0; i < cap; ++i)
     525    {
     526        crStateInitFBOAttachmentPoint(aap[i]);
     527        aap[i]->type = GL_TEXTURE;
     528        aap[i]->name = texture;
     529        aap[i]->level = level;
     530    }
    482531}
    483532
     
    487536    CRContext *g = GetCurrentContext();
    488537    CRFramebufferObjectState *fbo = &g->framebufferobject;
    489     CRFBOAttachmentPoint *ap;
     538    CRFBOAttachmentPoint *aap[2];
     539    GLuint cap, i;
    490540    CRTextureObj *tobj;
    491     GLboolean failed;
    492 
    493     crStateFramebufferTextureCheck(target, attachment, textarget, texture, level, &failed, &ap, &tobj);
    494     if (failed) return;
     541
     542    cap = crStateFramebufferTextureCheck(target, attachment, textarget, texture, level, aap, &tobj);
     543    if (!cap) return;
    495544
    496545    if (!texture)
    497546    {
    498         crStateInitFBOAttachmentPoint(ap);
     547        for (i = 0; i < cap; ++i)
     548        {
     549            crStateInitFBOAttachmentPoint(aap[i]);
     550        }
    499551        return;
    500552    }
     
    506558#endif
    507559
    508     crStateInitFBOAttachmentPoint(ap);
    509     ap->type = GL_TEXTURE;
    510     ap->name = texture;
    511     ap->level = level;
    512     if (textarget!=GL_TEXTURE_2D && textarget!=GL_TEXTURE_RECTANGLE_ARB)
    513     {
    514         ap->face = textarget;
     560    for (i = 0; i < cap; ++i)
     561    {
     562        crStateInitFBOAttachmentPoint(aap[i]);
     563        aap[i]->type = GL_TEXTURE;
     564        aap[i]->name = texture;
     565        aap[i]->level = level;
     566        if (textarget!=GL_TEXTURE_2D && textarget!=GL_TEXTURE_RECTANGLE_ARB)
     567        {
     568            aap[i]->face = textarget;
     569        }
    515570    }
    516571}
     
    521576    CRContext *g = GetCurrentContext();
    522577    CRFramebufferObjectState *fbo = &g->framebufferobject;
    523     CRFBOAttachmentPoint *ap;
     578    CRFBOAttachmentPoint *aap[2];
     579    GLuint cap, i;
    524580    CRTextureObj *tobj;
    525     GLboolean failed;
    526 
    527     crStateFramebufferTextureCheck(target, attachment, textarget, texture, level, &failed, &ap, &tobj);
    528     if (failed) return;
     581
     582    cap = crStateFramebufferTextureCheck(target, attachment, textarget, texture, level, aap, &tobj);
     583    if (!cap) return;
    529584
    530585    if (!texture)
    531586    {
    532         crStateInitFBOAttachmentPoint(ap);
     587        for (i = 0; i < cap; ++i)
     588        {
     589            crStateInitFBOAttachmentPoint(aap[i]);
     590        }
    533591        return;
    534592    }
     
    541599#endif
    542600
    543     crStateInitFBOAttachmentPoint(ap);
    544     ap->type = GL_TEXTURE;
    545     ap->name = texture;
    546     ap->level = level;
    547     ap->zoffset = zoffset;
     601    for (i = 0; i < cap; ++i)
     602    {
     603        crStateInitFBOAttachmentPoint(aap[i]);
     604        aap[i]->type = GL_TEXTURE;
     605        aap[i]->name = texture;
     606        aap[i]->level = level;
     607        aap[i]->zoffset = zoffset;
     608    }
    548609}
    549610
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette