Changeset 73295 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Jul 21, 2018 6:47:11 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 123902
- Location:
- trunk/src/VBox/Devices/Graphics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h
r69922 r73295 540 540 GLuint renderbuffer; 541 541 } oglId; 542 GLenum targetGL; /* GL_TEXTURE_* */ 543 GLenum bindingGL; /* GL_TEXTURE_BINDING_* */ 542 544 #endif 543 545 SVGA3dSurfaceFace faces[SVGA3D_MAX_SURFACE_FACES]; … … 1014 1016 PFNGLENDQUERYPROC glEndQuery; 1015 1017 PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; 1018 PFNGLTEXIMAGE3DPROC glTexImage3D; 1016 1019 } ext; 1017 1020 … … 1219 1222 return Face; 1220 1223 } 1221 #endif /* VMSVGA3D_DIRECT3D */ 1224 #else /* VMSVGA3D_OPENGL */ 1225 DECLINLINE(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 1222 1241 1223 1242 int vmsvga3dOcclusionQueryCreate(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext); -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
r73284 r73295 799 799 GLGETPROCOPT(PFNGLENDQUERYPROC , glEndQuery); 800 800 GLGETPROCOPT(PFNGLGETQUERYOBJECTUIVPROC , glGetQueryObjectuiv); 801 GLGETPROC (PFNGLTEXIMAGE3DPROC , glTexImage3D); 801 802 802 803 #undef GLGETPROCOPT … … 1893 1894 switch (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) 1894 1895 { 1895 case SVGA3D_SURFACE_CUBEMAP:1896 AssertFailed(); /** @todo destroy SVGA3D_SURFACE_CUBEMAP */1897 break;1898 1899 1896 case SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER: 1900 1897 case SVGA3D_SURFACE_HINT_INDEXBUFFER: … … 1907 1904 break; 1908 1905 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. */ 1909 1910 case SVGA3D_SURFACE_HINT_TEXTURE: 1910 1911 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: … … 2071 2072 } 2072 2073 2073 2074 2074 /** 2075 2075 * Create D3D/OpenGL texture object for the specified surface. … … 2086 2086 { 2087 2087 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. */ 2089 2118 uint32_t idPrevCtx = pState->idActiveContext; 2090 2119 pContext = &pState->SharedCtx; … … 2093 2122 glGenTextures(1, &pSurface->oglId.texture); 2094 2123 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); 2098 2127 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 2099 2128 2100 2129 /* 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); 2102 2131 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 2103 2132 … … 2106 2135 vmsvga3dOglSetUnpackParams(pState, pContext, pSurface, &SavedParams); 2107 2136 2137 /** @todo Set the mip map generation filter settings. */ 2138 2108 2139 /* 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); 2110 2141 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); 2112 2143 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 2113 2144 2114 2145 if (pSurface->fDirty) 2115 Log (("vmsvga3dBackCreateTexture:sync dirty texture\n"));2146 LogFunc(("sync dirty texture\n")); 2116 2147 2117 2148 /* 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 2140 2236 pSurface->fDirty = false; 2141 2237 … … 2144 2240 2145 2241 /* Restore the old active texture. */ 2146 glBindTexture( GL_TEXTURE_2D, activeTexture);2242 glBindTexture(target, activeTexture); 2147 2243 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 2148 2244 2149 2245 pSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE; 2246 pSurface->targetGL = target; 2247 pSurface->bindingGL = binding; 2150 2248 2151 2249 if (idPrevCtx < pState->cContexts && pState->papContexts[idPrevCtx]->id == idPrevCtx) … … 2178 2276 { 2179 2277 RT_NOREF(pThis); 2180 RT_NOREF2(uDstFace, uSrcFace); /// @todo2181 2278 2182 2279 /* Activate the read and draw framebuffer objects. */ … … 2187 2284 2188 2285 /* 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, 2190 2292 pSrcSurface->oglId.texture, uSrcMipmap); 2191 2293 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, 2193 2300 pDstSurface->oglId.texture, uDstMipmap); 2194 2301 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); … … 2353 2460 { 2354 2461 RT_NOREF(iBox); 2355 RT_NOREF(uHostFace); /// @todo2356 2462 2357 2463 switch (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) 2358 2464 { 2465 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE: 2466 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 2359 2467 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 2360 2468 case SVGA3D_SURFACE_HINT_TEXTURE: … … 2365 2473 uint32_t offHst; 2366 2474 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 2367 2500 pDoubleBuffer = (uint8_t *)RTMemAlloc(pMipLevel->cbSurface); 2368 2501 AssertReturn(pDoubleBuffer, VERR_NO_MEMORY); … … 2373 2506 2374 2507 /* Must bind texture to the current context in order to read it. */ 2375 glGetIntegerv( GL_TEXTURE_BINDING_2D, &activeTexture);2508 glGetIntegerv(pSurface->bindingGL, &activeTexture); 2376 2509 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 2377 2510 2378 glBindTexture( GL_TEXTURE_2D, pSurface->oglId.texture);2511 glBindTexture(pSurface->targetGL, pSurface->oglId.texture); 2379 2512 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 2380 2513 … … 2383 2516 vmsvga3dOglSetPackParams(pState, pContext, pSurface, &SavedParams); 2384 2517 2385 glGetTexImage( GL_TEXTURE_2D,2518 glGetTexImage(texImageTarget, 2386 2519 uHostMipmap, 2387 2520 pSurface->formatGL, … … 2393 2526 2394 2527 /* Restore the old active texture. */ 2395 glBindTexture( GL_TEXTURE_2D, activeTexture);2528 glBindTexture(pSurface->targetGL, activeTexture); 2396 2529 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 2397 2530 2398 offHst = pBox->x * pSurface->cbBlock + pBox->y* pMipLevel->cbSurfacePitch;2531 offHst = u32HostBlockX * pSurface->cbBlock + u32HostBlockY * pMipLevel->cbSurfacePitch; 2399 2532 cbSurfacePitch = pMipLevel->cbSurfacePitch; 2400 2533 } … … 2403 2536 /* The buffer will contain only the copied rectangle. */ 2404 2537 offHst = 0; 2405 cbSurfacePitch = pBox->w* pSurface->cbBlock;2406 } 2407 2408 uint32_t const offGst = pBox->srcx * pSurface->cbBlock + pBox->srcy * cbGuestPitch; /// @todo compressed fmts2538 cbSurfacePitch = cBlocksX * pSurface->cbBlock; 2539 } 2540 2541 uint32_t const offGst = u32GuestBlockX * pSurface->cbBlock + u32GuestBlockY * cbGuestPitch; 2409 2542 2410 2543 rc = vmsvgaGMRTransfer(pThis, … … 2417 2550 offGst, 2418 2551 cbGuestPitch, 2419 pBox->w* pSurface->cbBlock,2420 pBox->h);2552 cBlocksX * pSurface->cbBlock, 2553 cBlocksY); 2421 2554 AssertRC(rc); 2422 2555 … … 2425 2558 { 2426 2559 GLint activeTexture = 0; 2427 2428 glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture); 2560 glGetIntegerv(pSurface->bindingGL, &activeTexture); 2429 2561 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 2430 2562 2431 2563 /* 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); 2433 2565 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 2434 2566 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)); 2436 2568 2437 2569 /* Set row length and alignment of the input data. */ … … 2439 2571 vmsvga3dOglSetUnpackParams(pState, pContext, pSurface, &SavedParams); /** @todo do we need to set ROW_LENGTH to w here? */ 2440 2572 2441 glTexSubImage2D( GL_TEXTURE_2D,2573 glTexSubImage2D(texImageTarget, 2442 2574 uHostMipmap, 2443 pBox->x,2444 pBox->y,2445 pBox->w,2446 pBox->h,2575 u32HostBlockX, 2576 u32HostBlockY, 2577 cBlocksX, 2578 cBlocksY, 2447 2579 pSurface->formatGL, 2448 2580 pSurface->typeGL, 2449 2581 pDoubleBuffer); 2450 2451 2582 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 2452 2583 … … 2455 2586 2456 2587 /* Restore the old active texture. */ 2457 glBindTexture( GL_TEXTURE_2D, activeTexture);2588 glBindTexture(pSurface->targetGL, activeTexture); 2458 2589 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 2459 2590 } 2460 2591 2461 Log4(("first line:\n%.*Rhxd\n", pBox->w* pSurface->cbBlock, pDoubleBuffer));2592 Log4(("first line:\n%.*Rhxd\n", cBlocksX * pSurface->cbBlock, pDoubleBuffer)); 2462 2593 2463 2594 /* Free the double buffer. */ … … 2474 2605 case SVGA3D_SURFACE_HINT_INDEXBUFFER: 2475 2606 { 2607 /* Buffers are uncompressed. */ 2608 AssertReturn(pSurface->cxBlock == 1 && pSurface->cyBlock == 1, VERR_INTERNAL_ERROR); 2609 2476 2610 /* Caller already clipped pBox and buffers are 1-dimensional. */ 2477 2611 Assert(pBox->y == 0 && pBox->h == 1 && pBox->z == 0 && pBox->d == 1); … … 2623 2757 2624 2758 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); 2629 2762 2630 2763 Assert(filter != SVGA3D_TEX_FILTER_FLATCUBIC); … … 2632 2765 pSurface->autogenFilter = filter; 2633 2766 2634 Log (("vmsvga3dGenerateMipmaps:sid=%x filter=%d\n", sid, filter));2767 LogFunc(("sid=%x filter=%d\n", sid, filter)); 2635 2768 2636 2769 cid = SVGA3D_INVALID_ID; … … 2641 2774 { 2642 2775 /* 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)); 2644 2777 rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface); 2645 2778 AssertRCReturn(rc, rc); … … 2651 2784 } 2652 2785 2653 glGetIntegerv( GL_TEXTURE_BINDING_2D, &activeTexture);2786 glGetIntegerv(pSurface->bindingGL, &activeTexture); 2654 2787 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 2655 2788 2656 2789 /* 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); 2658 2791 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 2659 2792 2660 2793 /* Generate the mip maps. */ 2661 pState->ext.glGenerateMipmap( GL_TEXTURE_2D);2794 pState->ext.glGenerateMipmap(pSurface->targetGL); 2662 2795 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 2663 2796 2664 2797 /* Restore the old texture. */ 2665 glBindTexture( GL_TEXTURE_2D, activeTexture);2798 glBindTexture(pSurface->targetGL, activeTexture); 2666 2799 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 2667 2800 … … 2880 3013 2881 3014 /* Bind the source objects to the right place. */ 3015 Assert(pSurface->targetGL == GL_TEXTURE_2D); 2882 3016 pState->ext.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pSurface->oglId.texture, 0 /* level 0 */); 2883 3017 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); … … 4735 4869 AssertReturn(pState, VERR_NO_MEMORY); 4736 4870 AssertReturn(type < SVGA3D_RT_MAX, VERR_INVALID_PARAMETER); 4737 AssertReturn(target.face == 0, VERR_INVALID_PARAMETER);4738 4871 4739 4872 Log(("vmsvga3dSetRenderTarget cid=%x type=%x surface id=%x\n", cid, type, target.sid)); … … 4850 4983 pRenderTarget->surfaceFlags |= SVGA3D_SURFACE_HINT_RENDERTARGET; 4851 4984 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); 4853 4992 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 4854 4993 … … 5057 5196 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext); 5058 5197 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) 5060 5202 { 5061 5203 GLenum textureType = ~(GLenum)0; … … 5064 5206 #endif 5065 5207 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 5067 5211 /* Record the texture state for vm state saving. */ 5068 5212 if ( pTextureState[i].stage < RT_ELEMENTS(pContext->state.aTextureStates) … … 5072 5216 } 5073 5217 5074 /* Activ e the right texture unit for subsequent texture state changes. */5218 /* Activate the right texture unit for subsequent texture state changes. */ 5075 5219 if (pTextureState[i].stage != currentStage || i == 0) 5076 5220 { … … 5088 5232 continue; 5089 5233 } 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. */ 5090 5242 } 5091 5243 … … 5126 5278 5127 5279 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) 5129 5288 { 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) 5155 5290 { 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); 5158 5310 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 5170 5334 /* Recreate the texture state as glBindTexture resets them all (sigh). */ 5171 5335 for (uint32_t iStage = 0; iStage < RT_ELEMENTS(pContext->state.aTextureStates); iStage++) … … 5181 5345 } 5182 5346 } 5347 5183 5348 pContext->aSidActiveTextures[currentStage] = sid; 5184 5349 } 5350 5185 5351 /* Finished; continue with the next one. */ 5186 5352 continue; 5353 } 5187 5354 5188 5355 case SVGA3D_TS_ADDRESSW: /* SVGA3dTextureAddress */ … … 5240 5407 { 5241 5408 GLfloat color[4]; /* red, green, blue, alpha */ 5242 5243 5409 vmsvgaColor2GLFloatArray(pTextureState[i].value, &color[0], &color[1], &color[2], &color[3]); 5244 5410 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 */ 5246 5421 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 5247 5422 break; … … 5249 5424 5250 5425 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 */ 5252 5437 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 5253 5438 break; 5439 } 5254 5440 5255 5441 case SVGA3D_TS_TEXTURE_MIPMAP_LEVEL: /* uint32_t */ … … 5285 5471 if (textureType != ~(GLenum)0) 5286 5472 { 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); 5288 5483 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 5289 5484 } … … 6388 6583 } 6389 6584 #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) 6391 6587 { 6392 6588 if (pContext->aSidActiveTextures[i] != SVGA3D_INVALID_ID) 6393 6589 { 6394 GLint activeTexture = 0; 6590 PVMSVGA3DSURFACE pTexture; 6591 int rc2 = vmsvga3dSurfaceFromSid(pState, pContext->aSidActiveTextures[i], &pTexture); 6592 AssertContinue(RT_SUCCESS(rc2)); 6593 6395 6594 GLint activeTextureUnit = 0; 6396 6397 6595 glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTextureUnit); 6398 6596 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 6597 6399 6598 pState->ext.glActiveTexture(GL_TEXTURE0 + i); 6400 6599 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 6401 6600 6402 glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture); 6601 GLint activeTexture = 0; 6602 glGetIntegerv(pTexture->bindingGL, &activeTexture); 6403 6603 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 6604 6404 6605 pState->ext.glActiveTexture(activeTextureUnit); 6405 6606 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 6406 6607 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 # else6416 PVMSVGA3DSURFACE pTexture = pState->papSurfaces[pContext->aSidActiveTextures[i]];6417 AssertMsg(pTexture->id == pContext->aSidActiveTextures[i], ("%x vs %x\n", pTexture->id, pContext->aSidActiveTextures[i]));6418 6608 AssertMsg(pTexture->oglId.texture == (GLuint)activeTexture, 6419 6609 ("%x vs %x unit %d (active unit %d) sid=%x\n", pTexture->oglId.texture, activeTexture, i, 6420 6610 activeTextureUnit - GL_TEXTURE0, pContext->aSidActiveTextures[i])); 6421 # endif6422 6611 } 6423 6612 }
Note:
See TracChangeset
for help on using the changeset viewer.