VirtualBox

Ignore:
Timestamp:
May 12, 2010 3:20:21 PM (15 years ago)
Author:
vboxsync
Message:

crOpenGL: fix incorrect texture filtering and blank screen after guest 3d window size changes

File:
1 edited

Legend:

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

    r29371 r29427  
    2929//#define SHOW_WINDOW_BACKGROUND 1 /* Define this to see the window background even if the window is clipped */
    3030//#define DEBUG_VERBOSE /* Define this could get some debug info about the messages flow. */
     31//#define DEBUG_poetzsch 1
    3132
    3233#ifdef DEBUG_poetzsch
     
    5657    {
    5758        GLenum g = glGetError();
    58             if (g != GL_NO_ERROR)
     59        if (g != GL_NO_ERROR)
    5960        {
    6061            char *errStr;
     
    509510     * call in the OpenGL thread. */
    510511//    [m_pOverlayView performSelector:@selector(reshape) onThread:m_Thread withObject:nil waitUntilDone:YES];
     512    DEBUG_MSG(("parentWindowFrameChanged\n"));
    511513    [m_pOverlayView reshape];
    512514}
     
    515517{
    516518    [[NSNotificationCenter defaultCenter] removeObserver:self];
     519    DEBUG_MSG(("parentWindowChanged\n"));
    517520    if(pWindow != nil)
    518521    {
     
    530533//        [NSTimer scheduledTimerWithTimeInterval:0.2 target:m_pOverlayView selector:@selector(reshape) userInfo:nil repeats:NO];
    531534        [m_pOverlayView reshape];
    532 
    533535    }
    534536}
     
    554556    m_FBOTexSize = NSZeroSize;
    555557    m_FBODepthStencilPackedId = 0;
     558    m_FBOThumbId = 0;
     559    m_FBOThumbTexId = 0;
    556560    m_cClipRects = 0;
    557561    m_paClipRects = NULL;
     
    650654{
    651655    m_Size = size;
    652     [self reshape];
    653     [self updateFBO];
     656   
     657    if (!m_FBOId)
     658    {
     659        DEBUG_MSG(("Set size (no fbo) %p\n", self));
     660        [self reshape];
     661        [self updateFBO];
     662    }
     663    else
     664    {
     665        DEBUG_MSG(("Set size FBO %p\n", self));
     666        [self reshape];
     667        [self updateFBO];
     668        /* have to rebind GL_TEXTURE_RECTANGLE_ARB as m_FBOTexId could be changed in updateFBO call */
     669        [self updateViewport];
     670    }
    654671}
    655672
     
    661678- (void)updateViewport
    662679{
     680    DEBUG_MSG(("updateViewport %p\n", self));
    663681    if (m_pSharedGLCtx)
    664682    {
    665683        /* Update the viewport for our OpenGL view */
     684        DEBUG_MSG(("MakeCurrent (shared) %X\n", m_pSharedGLCtx));
    666685        [m_pSharedGLCtx makeCurrentContext];
    667686        [m_pSharedGLCtx update];
     
    686705        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId);
    687706
     707        DEBUG_MSG(("MakeCurrent %X\n", m_pGLCtx));
    688708        [m_pGLCtx makeCurrentContext];
    689709    }
     
    692712- (void)reshape
    693713{
     714    DEBUG_MSG(("(%p)reshape %p\n", RTThreadSelf(), self));
    694715    /* Getting the right screen coordinates of the parents frame is a little bit
    695716     * complicated. */
     
    745766
    746767- (void)createFBO
    747 {   
     768{
     769    GLuint fboid = m_FBOId;
     770   
     771    DEBUG_MSG(("createFBO %p\n", self));
    748772    [self deleteFBO];
    749773
     774if (0&&!fboid)
    750775    GL_SAVE_STATE;
    751776
     
    769794        /* & the texture as well the depth/stencil render buffer */
    770795        glGenTextures(1, &m_FBOTexId);
    771         DEBUG_MSG_1(("Create FBO %d %d\n", m_FBOId, m_FBOTexId));
     796        DEBUG_MSG(("Create FBO %d %d\n", m_FBOId, m_FBOTexId));
    772797
    773798        glGenRenderbuffersEXT(1, &m_FBODepthStencilPackedId);
     
    790815    if (m_FBOTexSize.width > maxTexSize || m_FBOTexSize.height > maxTexSize)
    791816    {
    792         filter = GL_NICEST;
     817        filter = GL_LINEAR;
    793818        if (imageAspectRatio > 1)
    794819        {
     
    828853    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
    829854    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     855    glDisable(GL_TEXTURE_RECTANGLE_ARB);
    830856
    831857    /* Is there a dock tile preview enabled in the GUI? If so setup a
     
    843869        /* Initialize FBO Texture */
    844870        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOThumbTexId);
    845         glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NICEST);
    846         glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NICEST);
     871        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     872        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    847873        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
    848874        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
     
    875901    m_paClipRects[2] = m_FBOTexSize.width;
    876902    m_paClipRects[3] = m_FBOTexSize.height;
    877 
     903   
     904if (0&&!fboid)
    878905    GL_RESTORE_STATE;
    879906}
     
    881908- (void)deleteFBO
    882909{
    883     if ([NSOpenGLContext currentContext] != nil)
    884     {
    885         GL_SAVE_STATE;
     910    DEBUG_MSG(("deleteFBO %p\n", self));
     911    if (m_pSharedGLCtx)
     912    {
     913        DEBUG_MSG(("MakeCurrent (shared) %X\n", m_pSharedGLCtx));
     914        [m_pSharedGLCtx makeCurrentContext];
     915        [m_pSharedGLCtx update];
     916
     917        glEnable(GL_TEXTURE_RECTANGLE_ARB);
     918        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
     919    }
     920
     921    if (m_pGLCtx)
     922    {
     923        DEBUG_MSG(("MakeCurrent %X\n", m_pGLCtx));
     924        [m_pGLCtx makeCurrentContext];
    886925
    887926        if (m_FBODepthStencilPackedId > 0)
     
    899938        if (m_FBOId > 0)
    900939        {
    901             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    902 
     940            GLint tmpFB;
     941            glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &tmpFB);
     942
     943            if (tmpFB == m_FBOId)
     944            {
     945                glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     946            }
     947           
    903948            glDeleteFramebuffersEXT(1, &m_FBOId);
    904949            m_FBOId = 0;
    905950        }
    906 
    907         GL_RESTORE_STATE;
    908     }
     951    }
     952
    909953    if (m_DockTileView != nil)
    910954    {
     
    917961- (void)updateFBO
    918962{
     963    DEBUG_MSG(("updateFBO %p\n", self));
    919964    [self makeCurrentFBO];
    920965   
     
    950995//        if ([NSOpenGLContext currentContext] != m_pGLCtx)
    951996        {
     997            DEBUG_MSG(("MakeCurrent %X\n", m_pGLCtx));
    952998            [m_pGLCtx makeCurrentContext];
    953999            CHECK_GL_ERROR();
     
    9721018    glFlush();
    9731019//    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    974         if (tmpFB == m_FBOId)
     1020    if (tmpFB == m_FBOId)
    9751021    {
    9761022        if ([self lockFocusIfCanDraw])
     
    9931039//    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    9941040    DEBUG_MSG_1 (("Flush GetINT %d\n", tmpFB));
    995         if (tmpFB == m_FBOId)
     1041    if (tmpFB == m_FBOId)
    9961042    {
    9971043        if ([self lockFocusIfCanDraw])
     
    10111057        //    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    10121058    DEBUG_MSG_1 (("Finish GetINT %d\n", tmpFB));
    1013         if (tmpFB == m_FBOId)
     1059    if (tmpFB == m_FBOId)
    10141060    {
    10151061        if ([self lockFocusIfCanDraw])
     
    10511097        if (m_FBOTexId > 0)
    10521098        {
     1099            if ([m_pSharedGLCtx view] != self)
     1100            {
     1101                DEBUG_MSG(("renderFBOToView: not currect view of shared ctx!"));
     1102                [m_pSharedGLCtx setView: self];
     1103                [self updateViewport];
     1104            }
     1105
     1106            //DEBUG_MSG(("MakeCurrent (shared) %X\n", m_pSharedGLCtx));
    10531107            [m_pSharedGLCtx makeCurrentContext];
    1054         
     1108       
    10551109            if (m_FBOThumbTexId > 0 &&
    10561110                [m_DockTileView thumbBitmap] != nil)
     
    11461200            glClear(GL_COLOR_BUFFER_BIT);
    11471201
     1202            glEnable(GL_TEXTURE_RECTANGLE_ARB);
     1203            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId);
     1204
    11481205            /* Blit the content of the FBO to the screen. todo: check for
    11491206             * optimization with display lists. */
     
    11661223            glFinish();
    11671224            [m_pSharedGLCtx flushBuffer];
     1225            //DEBUG_MSG(("MakeCurrent %X\n", m_pGLCtx));
    11681226            [m_pGLCtx makeCurrentContext];
    11691227        }
     
    14571515    NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
    14581516
     1517    DEBUG_MSG(("cocoaViewMakeCurrentContext(%p, %p)\n", pView, pCtx));
     1518   
    14591519    [(OverlayView*)pView setGLCtx:pCtx];
    14601520    [(OverlayView*)pView makeCurrentFBO];
     
    15321592    NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
    15331593
    1534     DEBUG_MSG_1(("glRenderspuBindFramebufferEXT called %d\n", framebuffer));
     1594    DEBUG_MSG(("glRenderspuBindFramebufferEXT called %d\n", framebuffer));
    15351595
    15361596#ifdef FBO
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