VirtualBox

Changeset 73295 in vbox


Ignore:
Timestamp:
Jul 21, 2018 6:47:11 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123902
Message:

DevVGA-SVGA3d-ogl: support for cubemaps, volume and compressed textures (untested).

Location:
trunk/src/VBox/Devices/Graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h

    r69922 r73295  
    540540        GLuint              renderbuffer;
    541541    } oglId;
     542    GLenum                  targetGL;  /* GL_TEXTURE_* */
     543    GLenum                  bindingGL; /* GL_TEXTURE_BINDING_* */
    542544#endif
    543545    SVGA3dSurfaceFace       faces[SVGA3D_MAX_SURFACE_FACES];
     
    10141016        PFNGLENDQUERYPROC                               glEndQuery;
    10151017        PFNGLGETQUERYOBJECTUIVPROC                      glGetQueryObjectuiv;
     1018        PFNGLTEXIMAGE3DPROC                             glTexImage3D;
    10161019    } ext;
    10171020
     
    12191222    return Face;
    12201223}
    1221 #endif /* VMSVGA3D_DIRECT3D */
     1224#else /* VMSVGA3D_OPENGL */
     1225DECLINLINE(GLenum) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)
     1226{
     1227    GLint Face;
     1228    switch (iFace)
     1229    {
     1230        case 0: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_X; break;
     1231        case 1: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; break;
     1232        case 2: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; break;
     1233        case 3: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; break;
     1234        case 4: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; break;
     1235        default:
     1236        case 5: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; break;
     1237    }
     1238    return Face;
     1239}
     1240#endif
    12221241
    12231242int vmsvga3dOcclusionQueryCreate(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp

    r73284 r73295  
    799799        GLGETPROCOPT(PFNGLENDQUERYPROC                         , glEndQuery);
    800800        GLGETPROCOPT(PFNGLGETQUERYOBJECTUIVPROC                , glGetQueryObjectuiv);
     801        GLGETPROC   (PFNGLTEXIMAGE3DPROC                       , glTexImage3D);
    801802
    802803#undef GLGETPROCOPT
     
    18931894    switch (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
    18941895    {
    1895     case SVGA3D_SURFACE_CUBEMAP:
    1896         AssertFailed(); /** @todo destroy SVGA3D_SURFACE_CUBEMAP */
    1897         break;
    1898 
    18991896    case SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER:
    19001897    case SVGA3D_SURFACE_HINT_INDEXBUFFER:
     
    19071904        break;
    19081905
     1906    case SVGA3D_SURFACE_CUBEMAP:
     1907    case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE:
     1908    case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
     1909        /* Cubemap is a texture. */
    19091910    case SVGA3D_SURFACE_HINT_TEXTURE:
    19101911    case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
     
    20712072}
    20722073
    2073 
    20742074/**
    20752075 * Create D3D/OpenGL texture object for the specified surface.
     
    20862086{
    20872087    RT_NOREF(idAssociatedContext);
    2088     GLint activeTexture = 0;
     2088
     2089    uint32_t const numMipLevels = pSurface->faces[0].numMipLevels;
     2090
     2091    /* Fugure out what kind of texture we are creating. */
     2092    GLenum binding;
     2093    GLenum target;
     2094    if (pSurface->surfaceFlags & SVGA3D_SURFACE_CUBEMAP)
     2095    {
     2096        Assert(pSurface->cFaces == 6);
     2097
     2098        binding = GL_TEXTURE_BINDING_CUBE_MAP;
     2099        target = GL_TEXTURE_CUBE_MAP;
     2100    }
     2101    else
     2102    {
     2103        if (pSurface->pMipmapLevels[0].mipmapSize.depth > 1)
     2104        {
     2105            binding = GL_TEXTURE_BINDING_3D;
     2106            target = GL_TEXTURE_3D;
     2107        }
     2108        else
     2109        {
     2110            Assert(pSurface->cFaces == 1);
     2111
     2112            binding = GL_TEXTURE_BINDING_2D;
     2113            target = GL_TEXTURE_2D;
     2114        }
     2115    }
     2116
     2117    /* All textures are created in the SharedCtx. */
    20892118    uint32_t idPrevCtx = pState->idActiveContext;
    20902119    pContext = &pState->SharedCtx;
     
    20932122    glGenTextures(1, &pSurface->oglId.texture);
    20942123    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    2095     /** @todo Set the mip map generation filter settings. */
    2096 
    2097     glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
     2124
     2125    GLint activeTexture = 0;
     2126    glGetIntegerv(binding, &activeTexture);
    20982127    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    20992128
    21002129    /* Must bind texture to the current context in order to change it. */
    2101     glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
     2130    glBindTexture(target, pSurface->oglId.texture);
    21022131    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    21032132
     
    21062135    vmsvga3dOglSetUnpackParams(pState, pContext, pSurface, &SavedParams);
    21072136
     2137    /** @todo Set the mip map generation filter settings. */
     2138
    21082139    /* Set the mipmap base and max level parameters. */
    2109     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
     2140    glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0);
    21102141    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    2111     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, pSurface->faces[0].numMipLevels - 1);
     2142    glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, pSurface->faces[0].numMipLevels - 1);
    21122143    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    21132144
    21142145    if (pSurface->fDirty)
    2115         Log(("vmsvga3dBackCreateTexture: sync dirty texture\n"));
     2146        LogFunc(("sync dirty texture\n"));
    21162147
    21172148    /* Always allocate and initialize all mipmap levels; non-initialized mipmap levels used as render targets cause failures. */
    2118     for (uint32_t i = 0; i < pSurface->faces[0].numMipLevels; i++)
    2119     {
    2120         /* Allocate and initialize texture memory.  Passing the zero filled pSurfaceData avoids
    2121             exposing random host memory to the guest and helps a with the fedora 21 surface
    2122             corruption issues (launchpad, background, search field, login). */
    2123         if (pSurface->pMipmapLevels[i].fDirty)
    2124             Log(("vmsvga3dBackCreateTexture: sync dirty texture mipmap level %d (pitch %x)\n", i, pSurface->pMipmapLevels[i].cbSurfacePitch));
    2125 
    2126         glTexImage2D(GL_TEXTURE_2D,
    2127                         i,
    2128                         pSurface->internalFormatGL,
    2129                         pSurface->pMipmapLevels[i].mipmapSize.width,
    2130                         pSurface->pMipmapLevels[i].mipmapSize.height,
    2131                         0,
    2132                         pSurface->formatGL,
    2133                         pSurface->typeGL,
    2134                         pSurface->pMipmapLevels[i].pSurfaceData);
    2135 
    2136         VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    2137 
    2138         pSurface->pMipmapLevels[i].fDirty = false;
    2139     }
     2149    if (target == GL_TEXTURE_3D)
     2150    {
     2151        for (uint32_t i = 0; i < numMipLevels; ++i)
     2152        {
     2153            /* Allocate and initialize texture memory.  Passing the zero filled pSurfaceData avoids
     2154             * exposing random host memory to the guest and helps a with the fedora 21 surface
     2155             * corruption issues (launchpad, background, search field, login).
     2156             */
     2157            PVMSVGA3DMIPMAPLEVEL pMipLevel = &pSurface->pMipmapLevels[i];
     2158
     2159            if (pMipLevel->fDirty)
     2160                LogFunc(("sync dirty texture mipmap level %d (pitch %x)\n", i, pMipLevel->fDirty, pMipLevel->cbSurfacePitch));
     2161
     2162            pState->ext.glTexImage3D(GL_TEXTURE_3D,
     2163                                     i,
     2164                                     pSurface->internalFormatGL,
     2165                                     pMipLevel->mipmapSize.width,
     2166                                     pMipLevel->mipmapSize.height,
     2167                                     pMipLevel->mipmapSize.depth,
     2168                                     0, /* border */
     2169                                     pSurface->formatGL,
     2170                                     pSurface->typeGL,
     2171                                     pMipLevel->pSurfaceData);
     2172            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     2173
     2174            pMipLevel->fDirty = false;
     2175        }
     2176    }
     2177    else if (target == GL_TEXTURE_CUBE_MAP)
     2178    {
     2179        for (uint32_t iFace = 0; iFace < 6; ++iFace)
     2180        {
     2181            GLenum const Face = vmsvga3dCubemapFaceFromIndex(iFace);
     2182
     2183            for (uint32_t i = 0; i < numMipLevels; ++i)
     2184            {
     2185                PVMSVGA3DMIPMAPLEVEL pMipLevel = &pSurface->pMipmapLevels[iFace * numMipLevels + i];
     2186                Assert(pMipLevel->mipmapSize.width == pMipLevel->mipmapSize.height);
     2187                Assert(pMipLevel->mipmapSize.depth == 1);
     2188
     2189                LogFunc(("sync texture face %d mipmap level %d (dirty %d)\n",
     2190                          iFace, i, pMipLevel->fDirty));
     2191
     2192                glTexImage2D(Face,
     2193                             i,
     2194                             pSurface->internalFormatGL,
     2195                             pMipLevel->mipmapSize.width,
     2196                             pMipLevel->mipmapSize.height,
     2197                             0,
     2198                             pSurface->formatGL,
     2199                             pSurface->typeGL,
     2200                             pMipLevel->pSurfaceData);
     2201                VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     2202
     2203                pMipLevel->fDirty = false;
     2204            }
     2205        }
     2206    }
     2207    else if (target == GL_TEXTURE_2D)
     2208    {
     2209        for (uint32_t i = 0; i < numMipLevels; ++i)
     2210        {
     2211            /* Allocate and initialize texture memory.  Passing the zero filled pSurfaceData avoids
     2212             * exposing random host memory to the guest and helps a with the fedora 21 surface
     2213             * corruption issues (launchpad, background, search field, login).
     2214             */
     2215            PVMSVGA3DMIPMAPLEVEL pMipLevel = &pSurface->pMipmapLevels[i];
     2216            Assert(pMipLevel->mipmapSize.depth == 1);
     2217
     2218            if (pMipLevel->fDirty)
     2219                LogFunc(("sync dirty texture mipmap level %d (pitch %x)\n", i, pMipLevel->fDirty, pMipLevel->cbSurfacePitch));
     2220
     2221            glTexImage2D(GL_TEXTURE_2D,
     2222                         i,
     2223                         pSurface->internalFormatGL,
     2224                         pMipLevel->mipmapSize.width,
     2225                         pMipLevel->mipmapSize.height,
     2226                         0,
     2227                         pSurface->formatGL,
     2228                         pSurface->typeGL,
     2229                         pMipLevel->pSurfaceData);
     2230            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     2231
     2232            pMipLevel->fDirty = false;
     2233        }
     2234    }
     2235
    21402236    pSurface->fDirty = false;
    21412237
     
    21442240
    21452241    /* Restore the old active texture. */
    2146     glBindTexture(GL_TEXTURE_2D, activeTexture);
     2242    glBindTexture(target, activeTexture);
    21472243    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    21482244
    21492245    pSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE;
     2246    pSurface->targetGL = target;
     2247    pSurface->bindingGL = binding;
    21502248
    21512249    if (idPrevCtx < pState->cContexts && pState->papContexts[idPrevCtx]->id == idPrevCtx)
     
    21782276{
    21792277    RT_NOREF(pThis);
    2180     RT_NOREF2(uDstFace, uSrcFace); /// @todo
    21812278
    21822279    /* Activate the read and draw framebuffer objects. */
     
    21872284
    21882285    /* Bind the source and destination objects to the right place. */
    2189     pState->ext.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
     2286    GLenum textarget;
     2287    if (pSrcSurface->surfaceFlags & SVGA3D_SURFACE_CUBEMAP)
     2288        textarget = vmsvga3dCubemapFaceFromIndex(uSrcFace);
     2289    else
     2290        textarget = GL_TEXTURE_2D;
     2291    pState->ext.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textarget,
    21902292                                       pSrcSurface->oglId.texture, uSrcMipmap);
    21912293    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    2192     pState->ext.glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
     2294
     2295    if (pDstSurface->surfaceFlags & SVGA3D_SURFACE_CUBEMAP)
     2296        textarget = vmsvga3dCubemapFaceFromIndex(uDstFace);
     2297    else
     2298        textarget = GL_TEXTURE_2D;
     2299    pState->ext.glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textarget,
    21932300                                       pDstSurface->oglId.texture, uDstMipmap);
    21942301    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     
    23532460{
    23542461    RT_NOREF(iBox);
    2355     RT_NOREF(uHostFace); /// @todo
    23562462
    23572463    switch (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
    23582464    {
     2465    case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE:
     2466    case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
    23592467    case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
    23602468    case SVGA3D_SURFACE_HINT_TEXTURE:
     
    23652473        uint32_t offHst;
    23662474
     2475        uint32_t const u32HostBlockX = pBox->x / pSurface->cxBlock;
     2476        uint32_t const u32HostBlockY = pBox->y / pSurface->cyBlock;
     2477        Assert(u32HostBlockX * pSurface->cxBlock == pBox->x);
     2478        Assert(u32HostBlockY * pSurface->cyBlock == pBox->y);
     2479
     2480        uint32_t const u32GuestBlockX = pBox->srcx / pSurface->cxBlock;
     2481        uint32_t const u32GuestBlockY = pBox->srcy / pSurface->cyBlock;
     2482        Assert(u32GuestBlockX * pSurface->cxBlock == pBox->srcx);
     2483        Assert(u32GuestBlockY * pSurface->cyBlock == pBox->srcy);
     2484
     2485        uint32_t const cBlocksX = (pBox->w + pSurface->cxBlock - 1) / pSurface->cxBlock;
     2486        uint32_t const cBlocksY = (pBox->h + pSurface->cyBlock - 1) / pSurface->cyBlock;
     2487        AssertMsgReturn(cBlocksX && cBlocksY, ("Empty box %dx%d\n", pBox->w, pBox->h), VERR_INTERNAL_ERROR);
     2488
     2489        GLenum texImageTarget;
     2490        if (pSurface->targetGL == GL_TEXTURE_CUBE_MAP)
     2491        {
     2492            texImageTarget = vmsvga3dCubemapFaceFromIndex(uHostFace);
     2493        }
     2494        else
     2495        {
     2496            Assert(pSurface->targetGL == GL_TEXTURE_2D);
     2497            texImageTarget = GL_TEXTURE_2D;
     2498        }
     2499
    23672500        pDoubleBuffer = (uint8_t *)RTMemAlloc(pMipLevel->cbSurface);
    23682501        AssertReturn(pDoubleBuffer, VERR_NO_MEMORY);
     
    23732506
    23742507            /* Must bind texture to the current context in order to read it. */
    2375             glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
     2508            glGetIntegerv(pSurface->bindingGL, &activeTexture);
    23762509            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    23772510
    2378             glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
     2511            glBindTexture(pSurface->targetGL, pSurface->oglId.texture);
    23792512            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    23802513
     
    23832516            vmsvga3dOglSetPackParams(pState, pContext, pSurface, &SavedParams);
    23842517
    2385             glGetTexImage(GL_TEXTURE_2D,
     2518            glGetTexImage(texImageTarget,
    23862519                          uHostMipmap,
    23872520                          pSurface->formatGL,
     
    23932526
    23942527            /* Restore the old active texture. */
    2395             glBindTexture(GL_TEXTURE_2D, activeTexture);
     2528            glBindTexture(pSurface->targetGL, activeTexture);
    23962529            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    23972530
    2398             offHst = pBox->x * pSurface->cbBlock + pBox->y * pMipLevel->cbSurfacePitch;
     2531            offHst = u32HostBlockX * pSurface->cbBlock + u32HostBlockY * pMipLevel->cbSurfacePitch;
    23992532            cbSurfacePitch = pMipLevel->cbSurfacePitch;
    24002533        }
     
    24032536            /* The buffer will contain only the copied rectangle. */
    24042537            offHst = 0;
    2405             cbSurfacePitch = pBox->w * pSurface->cbBlock;
    2406         }
    2407 
    2408         uint32_t const offGst = pBox->srcx * pSurface->cbBlock + pBox->srcy * cbGuestPitch; /// @todo compressed fmts
     2538            cbSurfacePitch = cBlocksX * pSurface->cbBlock;
     2539        }
     2540
     2541        uint32_t const offGst = u32GuestBlockX * pSurface->cbBlock + u32GuestBlockY * cbGuestPitch;
    24092542
    24102543        rc = vmsvgaGMRTransfer(pThis,
     
    24172550                               offGst,
    24182551                               cbGuestPitch,
    2419                                pBox->w * pSurface->cbBlock,
    2420                                pBox->h);
     2552                               cBlocksX * pSurface->cbBlock,
     2553                               cBlocksY);
    24212554        AssertRC(rc);
    24222555
     
    24252558        {
    24262559            GLint activeTexture = 0;
    2427 
    2428             glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
     2560            glGetIntegerv(pSurface->bindingGL, &activeTexture);
    24292561            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    24302562
    24312563            /* Must bind texture to the current context in order to change it. */
    2432             glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
     2564            glBindTexture(pSurface->targetGL, pSurface->oglId.texture);
    24332565            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    24342566
    2435             Log(("vmsvga3dSurfaceDMA: copy texture mipmap level %d (pitch %x)\n", uHostMipmap, pMipLevel->cbSurfacePitch));
     2567            LogFunc(("copy texture mipmap level %d (pitch %x)\n", uHostMipmap, pMipLevel->cbSurfacePitch));
    24362568
    24372569            /* Set row length and alignment of the input data. */
     
    24392571            vmsvga3dOglSetUnpackParams(pState, pContext, pSurface, &SavedParams); /** @todo do we need to set ROW_LENGTH to w here? */
    24402572
    2441             glTexSubImage2D(GL_TEXTURE_2D,
     2573            glTexSubImage2D(texImageTarget,
    24422574                            uHostMipmap,
    2443                             pBox->x,
    2444                             pBox->y,
    2445                             pBox->w,
    2446                             pBox->h,
     2575                            u32HostBlockX,
     2576                            u32HostBlockY,
     2577                            cBlocksX,
     2578                            cBlocksY,
    24472579                            pSurface->formatGL,
    24482580                            pSurface->typeGL,
    24492581                            pDoubleBuffer);
    2450 
    24512582            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    24522583
     
    24552586
    24562587            /* Restore the old active texture. */
    2457             glBindTexture(GL_TEXTURE_2D, activeTexture);
     2588            glBindTexture(pSurface->targetGL, activeTexture);
    24582589            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    24592590        }
    24602591
    2461         Log4(("first line:\n%.*Rhxd\n", pBox->w * pSurface->cbBlock, pDoubleBuffer));
     2592        Log4(("first line:\n%.*Rhxd\n", cBlocksX * pSurface->cbBlock, pDoubleBuffer));
    24622593
    24632594        /* Free the double buffer. */
     
    24742605    case SVGA3D_SURFACE_HINT_INDEXBUFFER:
    24752606    {
     2607        /* Buffers are uncompressed. */
     2608        AssertReturn(pSurface->cxBlock == 1 && pSurface->cyBlock == 1, VERR_INTERNAL_ERROR);
     2609
    24762610        /* Caller already clipped pBox and buffers are 1-dimensional. */
    24772611        Assert(pBox->y == 0 && pBox->h == 1 && pBox->z == 0 && pBox->d == 1);
     
    26232757
    26242758    AssertReturn(pState, VERR_NO_MEMORY);
    2625     AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
    2626     AssertReturn(sid < pState->cSurfaces && pState->papSurfaces[sid]->id == sid, VERR_INVALID_PARAMETER);
    2627 
    2628     pSurface = pState->papSurfaces[sid];
     2759
     2760    rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
     2761    AssertRCReturn(rc, rc);
    26292762
    26302763    Assert(filter != SVGA3D_TEX_FILTER_FLATCUBIC);
     
    26322765    pSurface->autogenFilter = filter;
    26332766
    2634     Log(("vmsvga3dGenerateMipmaps: sid=%x filter=%d\n", sid, filter));
     2767    LogFunc(("sid=%x filter=%d\n", sid, filter));
    26352768
    26362769    cid = SVGA3D_INVALID_ID;
     
    26412774    {
    26422775        /* Unknown surface type; turn it into a texture. */
    2643         Log(("vmsvga3dGenerateMipmaps: unknown src surface id=%x type=%d format=%d -> create texture\n", sid, pSurface->surfaceFlags, pSurface->format));
     2776        LogFunc(("unknown src surface id=%x type=%d format=%d -> create texture\n", sid, pSurface->surfaceFlags, pSurface->format));
    26442777        rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface);
    26452778        AssertRCReturn(rc, rc);
     
    26512784    }
    26522785
    2653     glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
     2786    glGetIntegerv(pSurface->bindingGL, &activeTexture);
    26542787    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    26552788
    26562789    /* Must bind texture to the current context in order to change it. */
    2657     glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
     2790    glBindTexture(pSurface->targetGL, pSurface->oglId.texture);
    26582791    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    26592792
    26602793    /* Generate the mip maps. */
    2661     pState->ext.glGenerateMipmap(GL_TEXTURE_2D);
     2794    pState->ext.glGenerateMipmap(pSurface->targetGL);
    26622795    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    26632796
    26642797    /* Restore the old texture. */
    2665     glBindTexture(GL_TEXTURE_2D, activeTexture);
     2798    glBindTexture(pSurface->targetGL, activeTexture);
    26662799    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    26672800
     
    28803013
    28813014    /* Bind the source objects to the right place. */
     3015    Assert(pSurface->targetGL == GL_TEXTURE_2D);
    28823016    pState->ext.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pSurface->oglId.texture, 0 /* level 0 */);
    28833017    VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
     
    47354869    AssertReturn(pState, VERR_NO_MEMORY);
    47364870    AssertReturn(type < SVGA3D_RT_MAX, VERR_INVALID_PARAMETER);
    4737     AssertReturn(target.face == 0, VERR_INVALID_PARAMETER);
    47384871
    47394872    Log(("vmsvga3dSetRenderTarget cid=%x type=%x surface id=%x\n", cid, type, target.sid));
     
    48504983        pRenderTarget->surfaceFlags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
    48514984
    4852         pState->ext.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + type - SVGA3D_RT_COLOR0, GL_TEXTURE_2D, pRenderTarget->oglId.texture, target.mipmap);
     4985        GLenum textarget;
     4986        if (pRenderTarget->surfaceFlags & SVGA3D_SURFACE_CUBEMAP)
     4987            textarget = vmsvga3dCubemapFaceFromIndex(target.face);
     4988        else
     4989            textarget = GL_TEXTURE_2D;
     4990        pState->ext.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + type - SVGA3D_RT_COLOR0,
     4991                                           textarget, pRenderTarget->oglId.texture, target.mipmap);
    48534992        VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    48544993
     
    50575196    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
    50585197
    5059     for (unsigned i = 0; i < cTextureStates; i++)
     5198    /* Which texture is active for the current stage. Needed to use right OpenGL target when setting parameters. */
     5199    PVMSVGA3DSURFACE pCurrentTextureSurface = NULL;
     5200
     5201    for (uint32_t i = 0; i < cTextureStates; ++i)
    50605202    {
    50615203        GLenum textureType = ~(GLenum)0;
     
    50645206#endif
    50655207
    5066         Log(("vmsvga3dSetTextureState: cid=%x stage=%d type=%s (%x) val=%x\n", cid, pTextureState[i].stage, vmsvga3dTextureStateToString(pTextureState[i].name), pTextureState[i].name, pTextureState[i].value));
     5208        LogFunc(("cid=%x stage=%d type=%s (%x) val=%x\n",
     5209                 cid, pTextureState[i].stage, vmsvga3dTextureStateToString(pTextureState[i].name), pTextureState[i].name, pTextureState[i].value));
     5210
    50675211        /* Record the texture state for vm state saving. */
    50685212        if (    pTextureState[i].stage < RT_ELEMENTS(pContext->state.aTextureStates)
     
    50725216        }
    50735217
    5074         /* Active the right texture unit for subsequent texture state changes. */
     5218        /* Activate the right texture unit for subsequent texture state changes. */
    50755219        if (pTextureState[i].stage != currentStage || i == 0)
    50765220        {
     
    50885232                continue;
    50895233            }
     5234
     5235            if (pContext->aSidActiveTextures[currentStage] != SVGA3D_INVALID_ID)
     5236            {
     5237                int rc = vmsvga3dSurfaceFromSid(pState, pContext->aSidActiveTextures[currentStage], &pCurrentTextureSurface);
     5238                AssertRCReturn(rc, rc);
     5239            }
     5240            else
     5241                pCurrentTextureSurface = NULL; /* Make sure that no stale pointer is used. */
    50905242        }
    50915243
     
    51265278
    51275279        case SVGA3D_TS_BIND_TEXTURE:                /* SVGA3dSurfaceId */
    5128             if (pTextureState[i].value == SVGA3D_INVALID_ID)
     5280        {
     5281            uint32_t const sid = pTextureState[i].value;
     5282
     5283            Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture sid=%x replacing sid=%x\n",
     5284                 currentStage, sid, pContext->aSidActiveTextures[currentStage]));
     5285
     5286            /* Only is texture actually changed. */ /// @todo needs testing.
     5287            if (pContext->aSidActiveTextures[currentStage] != sid)
    51295288            {
    5130                 Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture surface id=%x replacing=%x\n",
    5131                      currentStage, pTextureState[i].value, pContext->aSidActiveTextures[currentStage]));
    5132 
    5133                 pContext->aSidActiveTextures[currentStage] = SVGA3D_INVALID_ID;
    5134                 /* Unselect the currently associated texture. */
    5135                 glBindTexture(GL_TEXTURE_2D, 0);
    5136                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    5137                 /* Necessary for the fixed pipeline. */
    5138                 glDisable(GL_TEXTURE_2D);
    5139                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    5140             }
    5141             else
    5142             {
    5143                 uint32_t sid = pTextureState[i].value;
    5144 
    5145                 AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
    5146                 AssertReturn(sid < pState->cSurfaces && pState->papSurfaces[sid]->id == sid, VERR_INVALID_PARAMETER);
    5147 
    5148                 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
    5149 
    5150                 Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture surface id=%x (%d,%d) replacing=%x\n",
    5151                      currentStage, pTextureState[i].value, pSurface->pMipmapLevels[0].mipmapSize.width,
    5152                      pSurface->pMipmapLevels[0].mipmapSize.height, pContext->aSidActiveTextures[currentStage]));
    5153 
    5154                 if (pSurface->oglId.texture == OPENGL_INVALID_ID)
     5289                if (pCurrentTextureSurface)
    51555290                {
    5156                     Log(("CreateTexture (%d,%d) level=%d\n", pSurface->pMipmapLevels[0].mipmapSize.width, pSurface->pMipmapLevels[0].mipmapSize.height, pSurface->faces[0].numMipLevels));
    5157                     int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface);
     5291                    /* Unselect the currently associated texture. */
     5292                    glBindTexture(pCurrentTextureSurface->targetGL, 0);
     5293                    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     5294
     5295                    /* Necessary for the fixed pipeline. */
     5296                    glDisable(pCurrentTextureSurface->targetGL);
     5297                    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     5298
     5299                    pCurrentTextureSurface = NULL;
     5300                }
     5301
     5302                if (sid == SVGA3D_INVALID_ID)
     5303                {
     5304                    Assert(pCurrentTextureSurface == NULL);
     5305                }
     5306                else
     5307                {
     5308                    PVMSVGA3DSURFACE pSurface;
     5309                    int rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
    51585310                    AssertRCReturn(rc, rc);
    5159                 }
    5160 
    5161                 glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
    5162                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    5163 
    5164                 /* Necessary for the fixed pipeline. */
    5165                 glEnable(GL_TEXTURE_2D);
    5166                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    5167 
    5168                 if (pContext->aSidActiveTextures[currentStage] != sid)
    5169                 {
     5311
     5312                    Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture sid=%x (%d,%d) replacing sid=%x\n",
     5313                         currentStage, sid, pSurface->pMipmapLevels[0].mipmapSize.width,
     5314                         pSurface->pMipmapLevels[0].mipmapSize.height, pContext->aSidActiveTextures[currentStage]));
     5315
     5316                    if (pSurface->oglId.texture == OPENGL_INVALID_ID)
     5317                    {
     5318                        Log(("CreateTexture (%d,%d) levels=%d\n",
     5319                              pSurface->pMipmapLevels[0].mipmapSize.width, pSurface->pMipmapLevels[0].mipmapSize.height, pSurface->faces[0].numMipLevels));
     5320                        rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface);
     5321                        AssertRCReturn(rc, rc);
     5322                    }
     5323
     5324                    glBindTexture(pSurface->targetGL, pSurface->oglId.texture);
     5325                    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     5326
     5327                    /* Necessary for the fixed pipeline. */
     5328                    glEnable(pSurface->targetGL);
     5329                    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     5330
     5331                    /* Remember the currently active texture. */
     5332                    pCurrentTextureSurface = pSurface;
     5333
    51705334                    /* Recreate the texture state as glBindTexture resets them all (sigh). */
    51715335                    for (uint32_t iStage = 0; iStage < RT_ELEMENTS(pContext->state.aTextureStates); iStage++)
     
    51815345                    }
    51825346                }
     5347
    51835348                pContext->aSidActiveTextures[currentStage] = sid;
    51845349            }
     5350
    51855351            /* Finished; continue with the next one. */
    51865352            continue;
     5353        }
    51875354
    51885355        case SVGA3D_TS_ADDRESSW:                    /* SVGA3dTextureAddress */
     
    52405407        {
    52415408            GLfloat color[4]; /* red, green, blue, alpha */
    5242 
    52435409            vmsvgaColor2GLFloatArray(pTextureState[i].value, &color[0], &color[1], &color[2], &color[3]);
    52445410
    5245             glTexParameterfv(GL_TEXTURE_2D /** @todo flexible type */, GL_TEXTURE_BORDER_COLOR, color);   /* Identical; default 0.0 identical too */
     5411            GLenum targetGL;
     5412            if (pCurrentTextureSurface)
     5413                targetGL = pCurrentTextureSurface->targetGL;
     5414            else
     5415            {
     5416                /* No texture bound, assume 2D. */
     5417                targetGL = GL_TEXTURE_2D;
     5418            }
     5419
     5420            glTexParameterfv(targetGL, GL_TEXTURE_BORDER_COLOR, color);   /* Identical; default 0.0 identical too */
    52465421            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    52475422            break;
     
    52495424
    52505425        case SVGA3D_TS_TEXTURE_LOD_BIAS:            /* float */
    5251             glTexParameterf(GL_TEXTURE_2D /** @todo flexible type */, GL_TEXTURE_LOD_BIAS, pTextureState[i].floatValue);   /* Identical; default 0.0 identical too */
     5426        {
     5427            GLenum targetGL;
     5428            if (pCurrentTextureSurface)
     5429                targetGL = pCurrentTextureSurface->targetGL;
     5430            else
     5431            {
     5432                /* No texture bound, assume 2D. */
     5433                targetGL = GL_TEXTURE_2D;
     5434            }
     5435
     5436            glTexParameterf(targetGL, GL_TEXTURE_LOD_BIAS, pTextureState[i].floatValue);   /* Identical; default 0.0 identical too */
    52525437            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    52535438            break;
     5439        }
    52545440
    52555441        case SVGA3D_TS_TEXTURE_MIPMAP_LEVEL:        /* uint32_t */
     
    52855471        if (textureType != ~(GLenum)0)
    52865472        {
    5287             glTexParameteri(GL_TEXTURE_2D /** @todo flexible type */, textureType, val);
     5473            GLenum targetGL;
     5474            if (pCurrentTextureSurface)
     5475                targetGL = pCurrentTextureSurface->targetGL;
     5476            else
     5477            {
     5478                /* No texture bound, assume 2D. */
     5479                targetGL = GL_TEXTURE_2D;
     5480            }
     5481
     5482            glTexParameteri(targetGL, textureType, val);
    52885483            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    52895484        }
     
    63886583    }
    63896584#ifdef DEBUG
    6390     for (uint32_t i = 0; i < RT_ELEMENTS(pContext->aSidActiveTextures); i++)
     6585    /* Check whether 'activeTexture' on texture unit 'i' matches what we expect. */
     6586    for (uint32_t i = 0; i < RT_ELEMENTS(pContext->aSidActiveTextures); ++i)
    63916587    {
    63926588        if (pContext->aSidActiveTextures[i] != SVGA3D_INVALID_ID)
    63936589        {
    6394             GLint activeTexture = 0;
     6590            PVMSVGA3DSURFACE pTexture;
     6591            int rc2 = vmsvga3dSurfaceFromSid(pState, pContext->aSidActiveTextures[i], &pTexture);
     6592            AssertContinue(RT_SUCCESS(rc2));
     6593
    63956594            GLint activeTextureUnit = 0;
    6396 
    63976595            glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTextureUnit);
    63986596            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
     6597
    63996598            pState->ext.glActiveTexture(GL_TEXTURE0 + i);
    64006599            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    64016600
    6402             glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
     6601            GLint activeTexture = 0;
     6602            glGetIntegerv(pTexture->bindingGL, &activeTexture);
    64036603            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
     6604
    64046605            pState->ext.glActiveTexture(activeTextureUnit);
    64056606            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    64066607
    6407 # if 0 /* Aren't we checking whether 'activeTexture' on texture unit 'i' matches what we expected?  This works if only one unit is active, but if both are it _will_ fail for one of them. */
    6408             if (pContext->aSidActiveTextures[activeTextureUnit - GL_TEXTURE0] != SVGA3D_INVALID_ID)
    6409             {
    6410                 PVMSVGA3DSURFACE pTexture;
    6411                 pTexture = pState->papSurfaces[pContext->aSidActiveTextures[activeTextureUnit - GL_TEXTURE0]];
    6412 
    6413                 AssertMsg(pTexture->oglId.texture == (GLuint)activeTexture, ("%x vs %x unit %d - %d\n", pTexture->oglId.texture, activeTexture, i, activeTextureUnit - GL_TEXTURE0));
    6414             }
    6415 # else
    6416             PVMSVGA3DSURFACE pTexture = pState->papSurfaces[pContext->aSidActiveTextures[i]];
    6417             AssertMsg(pTexture->id == pContext->aSidActiveTextures[i], ("%x vs %x\n", pTexture->id, pContext->aSidActiveTextures[i]));
    64186608            AssertMsg(pTexture->oglId.texture == (GLuint)activeTexture,
    64196609                      ("%x vs %x unit %d (active unit %d) sid=%x\n", pTexture->oglId.texture, activeTexture, i,
    64206610                       activeTextureUnit - GL_TEXTURE0, pContext->aSidActiveTextures[i]));
    6421 # endif
    64226611        }
    64236612    }
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