third_party/virtualbox/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
/**
 * Create D3D/OpenGL texture object for the specified surface.
 *
 * Surfaces are created when needed.
 *
 * @param   pState              The VMSVGA3d state.
 * @param   pContext            The context.
 * @param   idAssociatedContext Probably the same as pContext->id.
 * @param   pSurface            The surface to create the texture for.
 */
Create D3D/OpenGL texture object for the specified surface.
Surfaces are created when needed.

@param   pState              The VMSVGA3d state.
@param   pContext            The context.
@param   idAssociatedContext Probably the same as pContext->id.
@param   pSurface            The surface to create the texture for.
Create D3D / OpenGL texture object for the specified surface . Surfaces are created when needed . @param pState The VMSVGA3d state . @param pContext The context . @param idAssociatedContext Probably the same as pContext - > id . @param pSurface The surface to create the texture for .
int vmsvga3dBackCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext,
                              PVMSVGA3DSURFACE pSurface)
{
    RT_NOREF(idAssociatedContext);
    GLint activeTexture = 0;
    uint32_t idPrevCtx = pState->idActiveContext;
    pContext = &pState->SharedCtx;
    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
    glGenTextures(1, &pSurface->oglId.texture);
    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    VMSVGAPACKPARAMS SavedParams;
    vmsvga3dOglSetUnpackParams(pState, pContext, pSurface, &SavedParams);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, pSurface->faces[0].numMipLevels);
    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    if (pSurface->fDirty)
        Log(("vmsvga3dBackCreateTexture: sync dirty texture\n"));
    for (uint32_t i = 0; i < pSurface->faces[0].numMipLevels; i++)
    {
        if (pSurface->pMipmapLevels[i].fDirty)
            Log(("vmsvga3dBackCreateTexture: sync dirty texture mipmap level %d (pitch %x)\n", i, pSurface->pMipmapLevels[i].cbSurfacePitch));
        glTexImage2D(GL_TEXTURE_2D,
                        i,
                        pSurface->internalFormatGL,
                        pSurface->pMipmapLevels[i].mipmapSize.width,
                        pSurface->pMipmapLevels[i].mipmapSize.height,
                        0,
                        pSurface->formatGL,
                        pSurface->typeGL,
                        pSurface->pMipmapLevels[i].pSurfaceData);
        VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
        pSurface->pMipmapLevels[i].fDirty = false;
    }
    pSurface->fDirty = false;
    vmsvga3dOglRestoreUnpackParams(pState, pContext, pSurface, &SavedParams);
    glBindTexture(GL_TEXTURE_2D, activeTexture);
    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    pSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE;
    if (idPrevCtx < pState->cContexts && pState->papContexts[idPrevCtx]->id == idPrevCtx)
        VMSVGA3D_SET_CURRENT_CONTEXT(pState, pState->papContexts[idPrevCtx]);
    return VINF_SUCCESS;
}
int vmsvga3dBackCreateTexture ( PVMSVGA3DSTATE pState , PVMSVGA3DCONTEXT pContext , uint32_t idAssociatedContext , PVMSVGA3DSURFACE pSurface ) { RT_NOREF ( idAssociatedContext ) ; GLint activeTexture = 0 ; uint32_t idPrevCtx = pState -> idActiveContext ; pContext = & pState -> SharedCtx ; VMSVGA3D_SET_CURRENT_CONTEXT ( pState , pContext ) ; glGenTextures ( 1 , & pSurface -> oglId . texture ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; glGetIntegerv ( GL_TEXTURE_BINDING_2D , & activeTexture ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; glBindTexture ( GL_TEXTURE_2D , pSurface -> oglId . texture ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; VMSVGAPACKPARAMS SavedParams ; vmsvga3dOglSetUnpackParams ( pState , pContext , pSurface , & SavedParams ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_BASE_LEVEL , 0 ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAX_LEVEL , pSurface -> faces [ 0 ] . numMipLevels ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; if ( pSurface -> fDirty ) Log ( ( " \n " ) ) ; for ( uint32_t i = 0 ; i < pSurface -> faces [ 0 ] . numMipLevels ; i ++ ) { if ( pSurface -> pMipmapLevels [ i ] . fDirty ) Log ( ( " \n " , i , pSurface -> pMipmapLevels [ i ] . cbSurfacePitch ) ) ; glTexImage2D ( GL_TEXTURE_2D , i , pSurface -> internalFormatGL , pSurface -> pMipmapLevels [ i ] . mipmapSize . width , pSurface -> pMipmapLevels [ i ] . mipmapSize . height , 0 , pSurface -> formatGL , pSurface -> typeGL , pSurface -> pMipmapLevels [ i ] . pSurfaceData ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; pSurface -> pMipmapLevels [ i ] . fDirty = false ; } pSurface -> fDirty = false ; vmsvga3dOglRestoreUnpackParams ( pState , pContext , pSurface , & SavedParams ) ; glBindTexture ( GL_TEXTURE_2D , activeTexture ) ; VMSVGA3D_CHECK_LAST_ERROR ( pState , pContext ) ; pSurface -> surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE ; if ( idPrevCtx < pState -> cContexts && pState -> papContexts [ idPrevCtx ] -> id == idPrevCtx ) VMSVGA3D_SET_CURRENT_CONTEXT ( pState , pState -> papContexts [ idPrevCtx ] ) ; return VINF_SUCCESS ; }
Create D3D/OpenGL texture object for the specified surface.
Create D3D / OpenGL texture object for the specified surface .
/** @todo Set the mip map generation filter settings. */ /* Must bind texture to the current context in order to change it. */ /* Set the unpacking parameters. */ /* Set the mipmap base and max level paramters. */ /* Always allocate and initialize all mipmap levels; non-initialized mipmap levels used as render targets cause failures. */ /* Allocate and initialize texture memory.  Passing the zero filled pSurfaceData avoids
            exposing random host memory to the guest and helps a with the fedora 21 surface
            corruption issues (launchpad, background, search field, login). */ /* Restore unpacking parameters. */ /* Restore the old active texture. */