third_party/virtualbox/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
/**
 * Destroys a 3d context.
 *
 * @returns VBox status code.
 * @param   pThis           VGA device instance data.
 * @param   pContext        The context to destroy.
 * @param   cid             Context id
 */
Destroys a 3d context.
@returns VBox status code.
@param   pThis           VGA device instance data.
@param   pContext        The context to destroy.
@param   cid             Context id
Destroys a 3d context . @returns VBox status code . @param pThis VGA device instance data . @param pContext The context to destroy . @param cid Context id
static int vmsvga3dContextDestroyOgl(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext, uint32_t cid)
{
    PVMSVGA3DSTATE pState = pThis->svga.p3dState;
    AssertReturn(pState, VERR_NO_MEMORY);
    AssertReturn(pContext, VERR_INVALID_PARAMETER);
    AssertReturn(pContext->id == cid, VERR_INVALID_PARAMETER);
    Log(("vmsvga3dContextDestroyOgl id %x\n", cid));
    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
    for (uint32_t i = 0; i < pContext->cPixelShaders; i++)
    {
        if (pContext->paPixelShader[i].id != SVGA3D_INVALID_ID)
            vmsvga3dShaderDestroy(pThis, pContext->paPixelShader[i].cid, pContext->paPixelShader[i].id, pContext->paPixelShader[i].type);
    }
    if (pContext->paPixelShader)
        RTMemFree(pContext->paPixelShader);
    for (uint32_t i = 0; i < pContext->cVertexShaders; i++)
    {
        if (pContext->paVertexShader[i].id != SVGA3D_INVALID_ID)
            vmsvga3dShaderDestroy(pThis, pContext->paVertexShader[i].cid, pContext->paVertexShader[i].id, pContext->paVertexShader[i].type);
    }
    if (pContext->paVertexShader)
        RTMemFree(pContext->paVertexShader);
    if (pContext->state.paVertexShaderConst)
        RTMemFree(pContext->state.paVertexShaderConst);
    if (pContext->state.paPixelShaderConst)
        RTMemFree(pContext->state.paPixelShaderConst);
    if (pContext->pShaderContext)
    {
        int rc = ShaderContextDestroy(pContext->pShaderContext);
        AssertRC(rc);
    }
    if (pContext->idFramebuffer != OPENGL_INVALID_ID)
    {
        pState->ext.glBindFramebuffer(GL_FRAMEBUFFER, 0 );
        VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
        pState->ext.glDeleteFramebuffers(1, &pContext->idFramebuffer);
        VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
        if (pContext->idReadFramebuffer != OPENGL_INVALID_ID)
        {
            pState->ext.glDeleteFramebuffers(1, &pContext->idReadFramebuffer);
            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
        }
        if (pContext->idDrawFramebuffer != OPENGL_INVALID_ID)
        {
            pState->ext.glDeleteFramebuffers(1, &pContext->idDrawFramebuffer);
            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
        }
    }
    vmsvga3dOcclusionQueryDelete(pState, pContext);
#ifdef RT_OS_WINDOWS
    wglMakeCurrent(pContext->hdc, NULL);
    wglDeleteContext(pContext->hglrc);
    ReleaseDC(pContext->hwnd, pContext->hdc);
    int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_DESTROYWINDOW, (WPARAM)pContext->hwnd, 0);
    AssertRC(rc);
#elif defined(RT_OS_DARWIN)
    vmsvga3dCocoaDestroyViewAndContext(pContext->cocoaView, pContext->cocoaContext);
#elif defined(RT_OS_LINUX)
    glXMakeCurrent(pState->display, None, NULL);
    glXDestroyContext(pState->display, pContext->glxContext);
    XDestroyWindow(pState->display, pContext->window);
#endif
    memset(pContext, 0, sizeof(*pContext));
    pContext->id = SVGA3D_INVALID_ID;
    VMSVGA3D_CLEAR_CURRENT_CONTEXT(pState);
    return VINF_SUCCESS;
}
static int vmsvga3dContextDestroyOgl ( PVGASTATE pThis , PVMSVGA3DCONTEXT pContext , uint32_t cid ) { PVMSVGA3DSTATE pState = pThis -> svga . p3dState ; AssertReturn ( pState , VERR_NO_MEMORY ) ; AssertReturn ( pContext , VERR_INVALID_PARAMETER ) ; AssertReturn ( pContext -> id == cid , VERR_INVALID_PARAMETER ) ; Log ( ( " \n " , cid ) ) ; VMSVGA3D_SET_CURRENT_CONTEXT ( pState , pContext ) ; for ( uint32_t i = 0 ; i < pContext -> cPixelShaders ; i ++ ) { if ( pContext -> paPixelShader [ i ] . id != SVGA3D_INVALID_ID ) vmsvga3dShaderDestroy ( pThis , pContext -> paPixelShader [ i ] . cid , pContext -> paPixelShader [ i ] . id , pContext -> paPixelShader [ i ] . type ) ; } if ( pContext -> paPixelShader ) RTMemFree ( pContext -> paPixelShader ) ; for ( uint32_t i = 0 ; i < pContext -> cVertexShaders ; i ++ ) { if ( pContext -> paVertexShader [ i ] . id != SVGA3D_INVALID_ID ) vmsvga3dShaderDestroy ( pThis , pContext -> paVertexShader [ i ] . cid , pContext -> paVertexShader [ i ] . id , pContext -> paVertexShader [ i ] . type ) ; } if ( pContext -> paVertexShader ) RTMemFree ( pContext -> paVertexShader ) ; if ( pContext -> state . paVertexShaderConst ) RTMemFree ( pContext -> state . paVertexShaderConst ) ; if ( pContext -> state . paPixelShaderConst ) RTMemFree ( pContext -> state . paPixelShaderConst ) ; if ( pContext -> pShaderContext ) { int rc = ShaderContextDestroy ( pContext -> pShaderContext ) ; AssertRC ( rc ) ; } if ( pContext -> idFramebuffer != OPENGL_INVALID_ID ) { pState -> ext . glBindFramebuffer ( GL_FRAMEBUFFER , 0 ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; pState -> ext . glDeleteFramebuffers ( 1 , & pContext -> idFramebuffer ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; if ( pContext -> idReadFramebuffer != OPENGL_INVALID_ID ) { pState -> ext . glDeleteFramebuffers ( 1 , & pContext -> idReadFramebuffer ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; } if ( pContext -> idDrawFramebuffer != OPENGL_INVALID_ID ) { pState -> ext . glDeleteFramebuffers ( 1 , & pContext -> idDrawFramebuffer ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; } } vmsvga3dOcclusionQueryDelete ( pState , pContext ) ; #ifdef RT_OS_WINDOWS wglMakeCurrent ( pContext -> hdc , NULL ) ; wglDeleteContext ( pContext -> hglrc ) ; ReleaseDC ( pContext -> hwnd , pContext -> hdc ) ; int rc = vmsvga3dSendThreadMessage ( pState -> pWindowThread , pState -> WndRequestSem , WM_VMSVGA3D_DESTROYWINDOW , ( WPARAM ) pContext -> hwnd , 0 ) ; AssertRC ( rc ) ; #elif defined ( RT_OS_DARWIN ) vmsvga3dCocoaDestroyViewAndContext ( pContext -> cocoaView , pContext -> cocoaContext ) ; #elif defined ( RT_OS_LINUX ) glXMakeCurrent ( pState -> display , None , NULL ) ; glXDestroyContext ( pState -> display , pContext -> glxContext ) ; XDestroyWindow ( pState -> display , pContext -> window ) ; #endif memset ( pContext , 0 , sizeof ( * pContext ) ) ; pContext -> id = SVGA3D_INVALID_ID ; VMSVGA3D_CLEAR_CURRENT_CONTEXT ( pState ) ; return VINF_SUCCESS ; }
Destroys a 3d context.
Destroys a 3d context .
/* Destroy all leftover pixel shaders. */ /* Destroy all leftover vertex shaders. */ /* Unbind the object from the framebuffer target. */ /* back buffer */ /* Destroy the window we've created. */