Branimir Karadžić 10 лет назад
Родитель
Сommit
29afb56581
2 измененных файлов с 60 добавлено и 13 удалено
  1. 57 11
      src/renderer_d3d9.cpp
  2. 3 2
      src/renderer_d3d9.h

+ 57 - 11
src/renderer_d3d9.cpp

@@ -535,7 +535,7 @@ namespace bgfx { namespace d3d9
 				| BGFX_CAPS_FRAGMENT_DEPTH
 				| BGFX_CAPS_SWAP_CHAIN
 				| ( (UINT16_MAX < m_caps.MaxVertexIndex) ? BGFX_CAPS_INDEX32 : 0)
-				| BGFX_CAPS_BLIT
+				| ( (m_caps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES) ? BGFX_CAPS_BLIT : 0)
 				);
 			g_caps.maxTextureSize = uint16_t(bx::uint32_min(m_caps.MaxTextureWidth, m_caps.MaxTextureHeight) );
 //			g_caps.maxVertexIndex = m_caps.MaxVertexIndex;
@@ -2291,9 +2291,6 @@ namespace bgfx { namespace d3d9
 
 	void TextureD3D9::createTexture(uint32_t _width, uint32_t _height, uint8_t _numMips)
 	{
-		m_width   = (uint16_t)_width;
-		m_height  = (uint16_t)_height;
-		m_numMips = _numMips;
 		m_type    = Texture2D;
 		const TextureFormat::Enum fmt = (TextureFormat::Enum)m_textureFormat;
 
@@ -2409,11 +2406,27 @@ namespace bgfx { namespace d3d9
 		m_type = TextureCube;
 		const TextureFormat::Enum fmt = (TextureFormat::Enum)m_textureFormat;
 
+		DWORD usage = 0;
+		D3DPOOL pool = s_renderD3D9->m_pool;
+
+		const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK);
+		const bool blit         = 0 != (m_flags&BGFX_TEXTURE_BLIT_DST);
+		if (isDepth(fmt) )
+		{
+			usage = D3DUSAGE_DEPTHSTENCIL;
+			pool  = D3DPOOL_DEFAULT;
+		}
+		else if (renderTarget || blit)
+		{
+			usage = D3DUSAGE_RENDERTARGET;
+			pool  = D3DPOOL_DEFAULT;
+		}
+
 		DX_CHECK(s_renderD3D9->m_device->CreateCubeTexture(_edge
 			, _numMips
-			, 0
+			, usage
 			, s_textureFormat[fmt].m_fmt
-			, s_renderD3D9->m_pool
+			, pool
 			, &m_textureCube
 			, NULL
 			) );
@@ -2573,7 +2586,11 @@ namespace bgfx { namespace d3d9
 			const uint32_t textureWidth  = bx::uint32_max(blockInfo.blockWidth,  imageContainer.m_width >>startLod);
 			const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod);
 
-			m_flags = _flags;
+			m_flags   = _flags;
+			m_width   = textureWidth;
+			m_height  = textureHeight;
+			m_depth   = imageContainer.m_depth;
+			m_numMips = numMips;
 			m_requestedFormat = imageContainer.m_format;
 			m_textureFormat   = imageContainer.m_format;
 
@@ -3320,17 +3337,46 @@ namespace bgfx { namespace d3d9
 						RECT dstRect = { LONG(blit.m_dstX), LONG(blit.m_dstY), LONG(blit.m_dstX + width), LONG(blit.m_dstY + height) };
 
 						IDirect3DSurface9* srcSurface;
-						DX_CHECK(src.m_texture2d->GetSurfaceLevel(blit.m_srcMip, &srcSurface) );
+						switch (src.m_type)
+						{
+						case TextureD3D9::Texture2D:
+							DX_CHECK(src.m_texture2d->GetSurfaceLevel(blit.m_srcMip, &srcSurface) );
+							break;
+
+						case TextureD3D9::Texture3D:
+							BX_CHECK(false, "");
+							break;
+
+						case TextureD3D9::TextureCube:
+							DX_CHECK(src.m_textureCube->GetCubeMapSurface(D3DCUBEMAP_FACES(blit.m_srcZ), blit.m_srcMip, &srcSurface) );
+							break;
+						}
 
 						IDirect3DSurface9* dstSurface;
-						DX_CHECK(dst.m_texture2d->GetSurfaceLevel(blit.m_dstMip, &dstSurface) );
+						switch (src.m_type)
+						{
+						case TextureD3D9::Texture2D:
+							DX_CHECK(dst.m_texture2d->GetSurfaceLevel(blit.m_dstMip, &dstSurface) );
+							break;
+
+						case TextureD3D9::Texture3D:
+							BX_CHECK(false, "");
+							break;
+
+						case TextureD3D9::TextureCube:
+							DX_CHECK(src.m_textureCube->GetCubeMapSurface(D3DCUBEMAP_FACES(blit.m_dstZ), blit.m_dstMip, &dstSurface) );
+							break;
+						}
 
-						DX_CHECK(m_device->StretchRect(srcSurface
+						HRESULT hr = m_device->StretchRect(srcSurface
 							, &srcRect
 							, dstSurface
 							, &dstRect
 							, D3DTEXF_NONE
-							) );
+							);
+						BX_WARN(SUCCEEDED(hr), "StretchRect failed %x.", hr);
+						BX_UNUSED(hr);
+
 						srcSurface->Release();
 						dstSurface->Release();
 					}

+ 3 - 2
src/renderer_d3d9.h

@@ -350,8 +350,9 @@ namespace bgfx { namespace d3d9
 
 		IDirect3DSurface9* m_surface;
 		uint32_t m_flags;
-		uint16_t m_width;
-		uint16_t m_height;
+		uint32_t m_width;
+		uint32_t m_height;
+		uint32_t m_depth;
 		uint8_t m_numMips;
 		uint8_t m_type;
 		uint8_t m_requestedFormat;