VirtualBox

Ignore:
Timestamp:
Jun 8, 2011 2:48:56 PM (14 years ago)
Author:
vboxsync
Message:

OpenGL-OSX: flush before swapping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m

    r37333 r37382  
    797797        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    798798
    799         glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId);
    800         glReadBuffer(m_FBOAttFrontId);
    801         glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
    802         glDrawBuffer(GL_BACK);
    803 
    804799        DEBUG_MSG(("OVIW(%p): makeCurrent (non shared) %p\n", (void*)self, (void*)m_pGLCtx));
    805800        [m_pGLCtx makeCurrentContext];
     
    953948     * others are also valid, but might incur a costly software translation. */
    954949    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexBackId);
    955     glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, m_FBOTexSize.width, m_FBOTexSize.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
     950    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, m_FBOTexSize.width, m_FBOTexSize.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
    956951    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexFrontId);
    957     glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, m_FBOTexSize.width, m_FBOTexSize.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
     952    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, m_FBOTexSize.width, m_FBOTexSize.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
    958953
    959954    /* Now attach the textures to the FBO as its color destinations */
     
    983978        DEBUG_MSG(("OVIW(%p): Framebuffer Object creation or update failed!\n", (void*)self));
    984979
     980//    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
    985981    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, oldTexId);
    986982    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, (GLuint)oldFBId ? (GLuint)oldFBId : m_FBOId);
     
    11661162{
    11671163    GLint sw     = 0;
     1164    GLint readFBOId = 0;
     1165    GLint drawFBOId = 0;
    11681166    GLint readId = 0;
    11691167    GLint drawId = 0;
     
    11721170
    11731171#ifdef FBO
    1174     glBindFramebufferEXT(GL_FRAMEBUFFER_BINDING_EXT, m_FBOId);
    1175 
    11761172    /* Don't use flush buffers cause we are using FBOs here! */
    11771173
    1178     if ([self isCurrentFBO])
    1179     {
    1180         /* Fetch the current used read and draw buffers. */
    1181         glGetIntegerv(GL_READ_BUFFER, &readId);
    1182         glGetIntegerv(GL_DRAW_BUFFER, &drawId);
    1183 
    1184         /* Do the swapping of our internal ids */
    1185         sw              = m_FBOTexFrontId;
    1186         m_FBOTexFrontId = m_FBOTexBackId;
    1187         m_FBOTexBackId  = sw;
    1188         sw              = m_FBOAttFrontId;
    1189         m_FBOAttFrontId = m_FBOAttBackId;
    1190         m_FBOAttBackId  = sw;
    1191 
    1192         /* We also have to swap the real ids on the current context. */
     1174    /* Before we swap make sure everything is done (This is really
     1175     * important. Don't remove.) */
     1176    glFlush();
     1177
     1178    /* Fetch the current used read and draw buffers. */
     1179    glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFBOId);
     1180    glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFBOId);
     1181    glGetIntegerv(GL_READ_BUFFER, &readId);
     1182    glGetIntegerv(GL_DRAW_BUFFER, &drawId);
     1183
     1184    /* Do the swapping of our internal ids */
     1185    sw              = m_FBOTexFrontId;
     1186    m_FBOTexFrontId = m_FBOTexBackId;
     1187    m_FBOTexBackId  = sw;
     1188    sw              = m_FBOAttFrontId;
     1189    m_FBOAttFrontId = m_FBOAttBackId;
     1190    m_FBOAttBackId  = sw;
     1191
     1192    DEBUG_MSG_1(("read FBO: %d draw FBO: %d readId: %d drawId: %d\n", readFBOId, drawFBOId, readId, drawId));
     1193    /* We also have to swap the real ids on the current context. */
     1194    if ((GLuint)readFBOId == m_FBOId)
     1195    {
    11931196        if ((GLuint)readId == m_FBOAttFrontId)
    1194         {
    1195             glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId);
    11961197            glReadBuffer(m_FBOAttBackId);
    1197         }
     1198        if ((GLuint)readId == m_FBOAttBackId)
     1199            glReadBuffer(m_FBOAttFrontId);
     1200    }
     1201    if ((GLuint)drawFBOId == m_FBOId)
     1202    {
    11981203        if ((GLuint)drawId == m_FBOAttFrontId)
    1199         {
    1200             glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_FBOId);
    12011204            glDrawBuffer(m_FBOAttBackId);
    1202         }
    1203 
    1204         [self tryDraw];
    1205     }
     1205        if ((GLuint)drawId == m_FBOAttBackId)
     1206            glDrawBuffer(m_FBOAttFrontId);
     1207    }
     1208
     1209    [self tryDraw];
    12061210#else
    12071211    [m_pGLCtx flushBuffer];
     
    12121216{
    12131217    GLint drawId = 0;
     1218    GLint FBOId  = 0;
    12141219
    12151220    DEBUG_MSG(("OVIW(%p): flushFBO\n", (void*)self));
     
    12241229    {
    12251230        /* Only reset if we aren't currently front. */
     1231        glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &FBOId);
    12261232        glGetIntegerv(GL_DRAW_BUFFER, &drawId);
    1227         if ((GLuint)drawId != m_FBOAttFrontId)
     1233        if (!(   (GLuint)FBOId  == m_FBOId
     1234              && (GLuint)drawId == m_FBOAttFrontId))
    12281235            m_fFrontDrawing = false;
    12291236        [self tryDraw];
     
    12451252- (void)stateInfo:(GLenum)pname withParams:(GLint*)params
    12461253{
    1247     DEBUG_MSG_1(("StateInfo requested: %d\n", pname));
     1254    GLint test;
     1255//    DEBUG_MSG_1(("StateInfo requested: %d\n", pname));
    12481256
    12491257    glGetIntegerv(pname, params);
     
    12611269        }
    12621270        case GL_READ_BUFFER:
     1271        {
     1272            glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &test);
     1273            if ((GLuint)test == m_FBOId)
     1274            {
     1275                if ((GLuint)*params == m_FBOAttFrontId)
     1276                    *params = GL_FRONT;
     1277                else
     1278                    if ((GLuint)*params == m_FBOAttBackId)
     1279                        *params = GL_BACK;
     1280            }
     1281            break;
     1282        }
    12631283        case GL_DRAW_BUFFER:
    12641284        {
    1265             if ((GLuint)*params == m_FBOAttFrontId)
    1266                 *params = GL_FRONT;
    1267             else
    1268                 if ((GLuint)*params == m_FBOAttBackId)
    1269                     *params = GL_BACK;
     1285            glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &test);
     1286            if ((GLuint)test == m_FBOId)
     1287            {
     1288                if ((GLuint)*params == m_FBOAttFrontId)
     1289                    *params = GL_FRONT;
     1290                else
     1291                    if ((GLuint)*params == m_FBOAttBackId)
     1292                        *params = GL_BACK;
     1293            }
    12701294            break;
    12711295        }
     
    12821306    {
    12831307        if (mode == GL_FRONT)
     1308        {
     1309            glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId);
    12841310            glReadBuffer(m_FBOAttFrontId);
     1311        }
    12851312        else if (mode == GL_BACK)
     1313        {
     1314            glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId);
    12861315            glReadBuffer(m_FBOAttBackId);
     1316        }
    12871317        else
    12881318            glReadBuffer(mode);
     
    13031333        {
    13041334            DEBUG_MSG(("OVIW(%p): front\n", (void*)self));
     1335            glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_FBOId);
    13051336            glDrawBuffer(m_FBOAttFrontId);
    13061337            m_fFrontDrawing = true;
     
    13091340        {
    13101341            DEBUG_MSG(("OVIW(%p): back\n", (void*)self));
     1342            glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_FBOId);
    13111343            glDrawBuffer(m_FBOAttBackId);
    13121344        }
    13131345        else
    13141346        {
    1315             DEBUG_MSG(("OVIW(%p): other\n", (void*)self));
     1347            DEBUG_MSG(("OVIW(%p): other: %d\n", (void*)self, mode));
    13161348            glDrawBuffer(mode);
    13171349        }
     
    13481380
    13491381    /* Fetch the current used read and draw buffers. */
    1350     glGetIntegerv(GL_READ_FRAMEBUFFER_EXT, &oldReadFBOId);
    1351     glGetIntegerv(GL_DRAW_FRAMEBUFFER_EXT, &oldDrawFBOId);
     1382    glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &oldReadFBOId);
     1383    glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &oldDrawFBOId);
    13521384    glGetIntegerv(GL_READ_BUFFER, &oldReadId);
    13531385    glGetIntegerv(GL_DRAW_BUFFER, &oldDrawId);
     
    13931425            glClear(GL_COLOR_BUFFER_BIT);
    13941426
    1395             /* Blit the content of the FBO to the screen. todo: check for
    1396              * optimization with display lists. */
     1427            /* Blit the content of the FBO to the screen. */
    13971428            for (i = 0; i < m_cClipRects; ++i)
    13981429            {
     
    14091440            glFinish();
    14101441            */
     1442            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    14111443            [m_pSharedGLCtx flushBuffer];
    14121444
    14131445            [m_pGLCtx makeCurrentContext];
    14141446            /* Reset to previous buffer bindings. */
    1415             if (   (GLuint)oldReadId == m_FBOAttBackId
    1416                 || (GLuint)oldReadId == m_FBOAttFrontId)
    1417                 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId);
     1447            glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, oldReadFBOId);
    14181448            glReadBuffer(oldReadId);
    1419             if (   (GLuint)oldDrawId == m_FBOAttBackId
    1420                 || (GLuint)oldDrawId == m_FBOAttFrontId)
    1421                 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_FBOId);
     1449            glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, oldDrawFBOId);
    14221450            glDrawBuffer(oldDrawId);
    14231451        }
    14241452    }
     1453#else
     1454    [m_pGLCtx flushBuffer];
    14251455#endif
    14261456}
     
    19391969    NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
    19401970
    1941     DEBUG_MSG_1(("getIntergerv called: %d\n", pname));
     1971//    DEBUG_MSG_1(("getIntergerv called: %d\n", pname));
    19421972
    19431973    performSelectorOnViewTwoArgs(@selector(stateInfo:withParams:), (id)pname, (id)params);
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