From 76ad2441b06d341c3d87c860fc9d9b691f06cc24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 23 Oct 2015 12:57:04 -0700 Subject: [PATCH] D3D9: Fixed volume texture update. --- examples/08-update/update.cpp | 6 +- include/bgfx/bgfx.h | 8 +- include/bgfx/bgfxdefines.h | 18 ++--- include/bgfx/c99/bgfx.h | 4 +- src/bgfx.cpp | 16 ++-- src/bgfx_p.h | 31 +++++++- src/renderer_d3d11.cpp | 4 +- src/renderer_d3d12.cpp | 4 +- src/renderer_d3d9.cpp | 133 +++++----------------------------- src/renderer_d3d9.h | 4 +- src/renderer_gl.cpp | 4 +- src/renderer_mtl.mm | 4 +- 12 files changed, 85 insertions(+), 151 deletions(-) diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index bb85146a8..3dd5b1203 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -176,17 +176,17 @@ int _main_(int /*_argc*/, char** /*_argv*/) if (texture3DSupported) { - if (0 != (BGFX_CAPS_FORMAT_TEXTURE_COLOR & caps->formats[bgfx::TextureFormat::R8]) ) + if (0 != (BGFX_CAPS_FORMAT_TEXTURE_2D & caps->formats[bgfx::TextureFormat::R8]) ) { textures3d[numTextures3d++] = bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R8, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem8); } - if (0 != (BGFX_CAPS_FORMAT_TEXTURE_COLOR & caps->formats[bgfx::TextureFormat::R16F]) ) + if (0 != (BGFX_CAPS_FORMAT_TEXTURE_2D & caps->formats[bgfx::TextureFormat::R16F]) ) { textures3d[numTextures3d++] = bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R16F, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem16f); } - if (0 != (BGFX_CAPS_FORMAT_TEXTURE_COLOR & caps->formats[bgfx::TextureFormat::R32F]) ) + if (0 != (BGFX_CAPS_FORMAT_TEXTURE_2D & caps->formats[bgfx::TextureFormat::R32F]) ) { textures3d[numTextures3d++] = bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R32F, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem32f); } diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 06a117ad9..f56606580 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -471,10 +471,10 @@ namespace bgfx /// Supported texture formats. /// - `BGFX_CAPS_FORMAT_TEXTURE_NONE` - not supported - /// - `BGFX_CAPS_FORMAT_TEXTURE_COLOR` - supported - /// - `BGFX_CAPS_FORMAT_TEXTURE_EMULATED` - emulated + /// - `BGFX_CAPS_FORMAT_TEXTURE_2D` - supported + /// - `BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED` - emulated /// - `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - supported vertex texture - uint8_t formats[TextureFormat::Count]; + uint16_t formats[TextureFormat::Count]; }; /// Transient index buffer. @@ -1448,7 +1448,7 @@ namespace bgfx /// /// @attention C99 equivalent is `bgfx_create_frame_buffer_from_handles`. /// - FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles, bool _destroyTextures = false); + FrameBufferHandle createFrameBuffer(uint8_t _num, const TextureHandle* _handles, bool _destroyTextures = false); /// Create frame buffer for multiple window rendering. /// diff --git a/include/bgfx/bgfxdefines.h b/include/bgfx/bgfxdefines.h index 9c756c060..3d05fcd66 100644 --- a/include/bgfx/bgfxdefines.h +++ b/include/bgfx/bgfxdefines.h @@ -372,15 +372,15 @@ #define BGFX_CAPS_TEXTURE_READ_BACK UINT64_C(0x0000000000020000) //!< Read-back texture is supported. /// -#define BGFX_CAPS_FORMAT_TEXTURE_NONE UINT8_C(0x00) //!< Texture format is not supported. -#define BGFX_CAPS_FORMAT_TEXTURE_COLOR UINT8_C(0x01) //!< Texture format is supported. -#define BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB UINT8_C(0x02) //!< Texture as sRGB format is supported. -#define BGFX_CAPS_FORMAT_TEXTURE_EMULATED UINT8_C(0x04) //!< Texture format is emulated. -#define BGFX_CAPS_FORMAT_TEXTURE_VERTEX UINT8_C(0x08) //!< Texture format can be used from vertex shader. -#define BGFX_CAPS_FORMAT_TEXTURE_IMAGE UINT8_C(0x10) //!< Texture format can be used as image from compute shader. -#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER UINT8_C(0x20) //!< Texture format can be used as frame buffer. -#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA UINT8_C(0x40) //!< Texture format can be used as MSAA frame buffer. -#define BGFX_CAPS_FORMAT_TEXTURE_MSAA UINT8_C(0x80) //!< Texture can be sampled as MSAA. +#define BGFX_CAPS_FORMAT_TEXTURE_NONE UINT16_C(0x0000) //!< Texture format is not supported. +#define BGFX_CAPS_FORMAT_TEXTURE_2D UINT16_C(0x0001) //!< Texture format is supported. +#define BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB UINT16_C(0x0002) //!< Texture as sRGB format is supported. +#define BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED UINT16_C(0x0004) //!< Texture format is emulated. +#define BGFX_CAPS_FORMAT_TEXTURE_VERTEX UINT16_C(0x0008) //!< Texture format can be used from vertex shader. +#define BGFX_CAPS_FORMAT_TEXTURE_IMAGE UINT16_C(0x0010) //!< Texture format can be used as image from compute shader. +#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER UINT16_C(0x0020) //!< Texture format can be used as frame buffer. +#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA UINT16_C(0x0040) //!< Texture format can be used as MSAA frame buffer. +#define BGFX_CAPS_FORMAT_TEXTURE_MSAA UINT16_C(0x0080) //!< Texture can be sampled as MSAA. /// #define BGFX_VIEW_NONE UINT8_C(0x00) //!< diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 89f401cab..534c13f1f 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -337,7 +337,7 @@ typedef struct bgfx_caps uint16_t deviceId; bgfx_caps_gpu_t gpu[4]; - uint8_t formats[BGFX_TEXTURE_FORMAT_COUNT]; + uint16_t formats[BGFX_TEXTURE_FORMAT_COUNT]; } bgfx_caps_t; @@ -624,7 +624,7 @@ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags); /**/ -BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, bgfx_texture_handle_t* _handles, bool _destroyTextures); +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, const bgfx_texture_handle_t* _handles, bool _destroyTextures); /**/ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat); diff --git a/src/bgfx.cpp b/src/bgfx.cpp index a5fc1d567..a7eceb0dc 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1011,10 +1011,10 @@ namespace bgfx if (TextureFormat::Unknown != ii && TextureFormat::UnknownDepth != ii) { - uint8_t flags = g_caps.formats[ii]; + uint16_t flags = g_caps.formats[ii]; BX_TRACE("\t[%c%c%c%c%c%c%c] %s" - , flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_EMULATED ? '*' : ' ' - , flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB ? 'l' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_2D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED ? '*' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB ? 'l' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE ? 'i' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' ' @@ -1135,9 +1135,9 @@ namespace bgfx for (uint32_t ii = 0; ii < BX_COUNTOF(s_emulatedFormats); ++ii) { - if (0 == (g_caps.formats[s_emulatedFormats[ii] ] & BGFX_CAPS_FORMAT_TEXTURE_COLOR) ) + if (0 == (g_caps.formats[s_emulatedFormats[ii] ] & BGFX_CAPS_FORMAT_TEXTURE_2D) ) { - g_caps.formats[s_emulatedFormats[ii] ] |= BGFX_CAPS_FORMAT_TEXTURE_EMULATED; + g_caps.formats[s_emulatedFormats[ii] ] |= BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED; } } @@ -2946,7 +2946,7 @@ again: return createFrameBuffer(1, &th, true); } - FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles, bool _destroyTextures) + FrameBufferHandle createFrameBuffer(uint8_t _num, const TextureHandle* _handles, bool _destroyTextures) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(_num != 0, "Number of frame buffer attachments can't be 0."); @@ -3872,10 +3872,10 @@ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backb return handle.c; } -BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, bgfx_texture_handle_t* _handles, bool _destroyTextures) +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, const bgfx_texture_handle_t* _handles, bool _destroyTextures) { union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; - handle.cpp = bgfx::createFrameBuffer(_num, (bgfx::TextureHandle*)_handles, _destroyTextures); + handle.cpp = bgfx::createFrameBuffer(_num, (const bgfx::TextureHandle*)_handles, _destroyTextures); return handle.c; } diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 066e0269b..1c5ad9358 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -3076,8 +3076,37 @@ namespace bgfx cmdbuf.write(_mem); } - BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles, bool _destroyTextures) ) + bool checkFrameBuffer(uint8_t _num, const TextureHandle* _handles) const { + uint8_t color = 0; + uint8_t depth = 0; + + for (uint32_t ii = 0; ii < _num; ++ii) + { + TextureHandle texHandle = _handles[ii]; + if (isDepth(TextureFormat::Enum(m_textureRef[texHandle.idx].m_format))) + { + ++depth; + } + else + { + ++color; + } + } + + return color <= g_caps.maxFBAttachments + && depth <= 1 + ; + } + + BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(uint8_t _num, const TextureHandle* _handles, bool _destroyTextures) ) + { + BX_CHECK(checkFrameBuffer(_num, _handles) + , "Too many frame buffer attachments (num attachments: %d, max color attachments %d)!" + , _num + , g_caps.maxFBAttachments + ); + FrameBufferHandle handle = { m_frameBufferHandle.alloc() }; BX_WARN(isValid(handle), "Failed to allocate frame buffer handle."); diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index f749e2d29..feef3559b 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1277,7 +1277,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); | D3D11_FORMAT_SUPPORT_TEXTURE3D | D3D11_FORMAT_SUPPORT_TEXTURECUBE ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_COLOR + ? BGFX_CAPS_FORMAT_TEXTURE_2D : BGFX_CAPS_FORMAT_TEXTURE_NONE ; @@ -1362,7 +1362,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); | D3D11_FORMAT_SUPPORT_TEXTURE3D | D3D11_FORMAT_SUPPORT_TEXTURECUBE ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB + ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE ; } diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 07bafc5d9..b87f20c63 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -910,7 +910,7 @@ namespace bgfx { namespace d3d12 | D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TEXTURECUBE ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_COLOR + ? BGFX_CAPS_FORMAT_TEXTURE_2D : BGFX_CAPS_FORMAT_TEXTURE_NONE ; @@ -995,7 +995,7 @@ namespace bgfx { namespace d3d12 | D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TEXTURECUBE ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB + ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE ; } diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 2bb5fb109..d883afaf9 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -582,14 +582,14 @@ namespace bgfx { namespace d3d9 for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { uint8_t support = 0; - + support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter , m_deviceType , adapterFormat , 0 , D3DRTYPE_TEXTURE , s_textureFormat[ii].m_fmt - ) ) ? BGFX_CAPS_FORMAT_TEXTURE_COLOR : BGFX_CAPS_FORMAT_TEXTURE_NONE; + ) ) ? BGFX_CAPS_FORMAT_TEXTURE_2D : BGFX_CAPS_FORMAT_TEXTURE_NONE; support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter , m_deviceType @@ -597,7 +597,7 @@ namespace bgfx { namespace d3d9 , D3DUSAGE_QUERY_SRGBREAD , D3DRTYPE_TEXTURE , s_textureFormat[ii].m_fmt - ) ) ? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE; + ) ) ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE; support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter , m_deviceType @@ -2426,37 +2426,8 @@ namespace bgfx { namespace d3d9 } else { - const ImageBlockInfo& blockInfo = getBlockInfo(fmt); - const uint32_t blockWidth = blockInfo.blockWidth; - const uint32_t blockHeight = blockInfo.blockHeight; - - for (uint8_t lod = 0, num = _numMips; lod < num; ++lod) - { - if ( (m_width >>lod) < blockWidth - || (m_height>>lod) < blockHeight) - { - break; - } - - uint32_t mipWidth = bx::uint32_max(blockWidth, ( ( (m_width >>lod) + blockWidth - 1) / blockWidth )*blockWidth); - uint32_t mipHeight = bx::uint32_max(blockHeight, ( ( (m_height>>lod) + blockHeight - 1) / blockHeight)*blockHeight); - - IDirect3DSurface9* srcSurface; - DX_CHECK(m_staging2d->GetSurfaceLevel(lod, &srcSurface) ); - IDirect3DSurface9* dstSurface = getSurface(0, lod); - - RECT srcRect = { LONG(0), LONG(0), LONG(mipWidth), LONG(mipHeight) }; - POINT dstPoint = { LONG(0), LONG(0) }; - - DX_CHECK(device->UpdateSurface(srcSurface - , &srcRect - , dstSurface - , &dstPoint - ) ); - - srcSurface->Release(); - dstSurface->Release(); - } + DX_CHECK(m_staging2d->AddDirtyRect(NULL)); + DX_CHECK(device->UpdateTexture(m_staging2d, m_texture2d)); } } @@ -2468,7 +2439,7 @@ namespace bgfx { namespace d3d9 ); } - void TextureD3D9::createVolumeTexture(uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _numMips) + void TextureD3D9::createVolumeTexture(uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips) { m_type = Texture3D; const TextureFormat::Enum fmt = (TextureFormat::Enum)m_textureFormat; @@ -2500,7 +2471,7 @@ namespace bgfx { namespace d3d9 } else { - DX_CHECK(m_texture3d->AddDirtyBox(NULL) ); + DX_CHECK(m_staging3d->AddDirtyBox(NULL) ); DX_CHECK(device->UpdateTexture(m_staging3d, m_texture3d) ); } @@ -2513,7 +2484,7 @@ namespace bgfx { namespace d3d9 ); } - void TextureD3D9::createCubeTexture(uint32_t _edge, uint32_t _numMips) + void TextureD3D9::createCubeTexture(uint32_t _width, uint8_t _numMips) { m_type = TextureCube; const TextureFormat::Enum fmt = (TextureFormat::Enum)m_textureFormat; @@ -2532,7 +2503,7 @@ namespace bgfx { namespace d3d9 } IDirect3DDevice9* device = s_renderD3D9->m_device; - DX_CHECK(device->CreateCubeTexture(_edge + DX_CHECK(device->CreateCubeTexture(_width , _numMips , usage , s_textureFormat[fmt].m_fmt @@ -2545,7 +2516,7 @@ namespace bgfx { namespace d3d9 { if (NULL == m_staging) { - DX_CHECK(device->CreateCubeTexture(_edge + DX_CHECK(device->CreateCubeTexture(_width , _numMips , 0 , s_textureFormat[fmt].m_fmt @@ -2556,45 +2527,16 @@ namespace bgfx { namespace d3d9 } else { - const ImageBlockInfo& blockInfo = getBlockInfo(fmt); - const uint32_t blockWidth = blockInfo.blockWidth; - const uint32_t blockHeight = blockInfo.blockHeight; - - for (uint8_t side = 0, numSides = 6; side < numSides; ++side) + for (uint8_t ii = 0; ii < 6; ++ii) { - for (uint8_t lod = 0, num = _numMips; lod < num; ++lod) - { - if ( (m_width >>lod) < blockWidth - || (m_height>>lod) < blockHeight) - { - break; - } - - uint32_t mipWidth = bx::uint32_max(blockWidth, ( ( (m_width >>lod) + blockWidth - 1) / blockWidth )*blockWidth); - uint32_t mipHeight = bx::uint32_max(blockHeight, ( ( (m_height>>lod) + blockHeight - 1) / blockHeight)*blockHeight); - - IDirect3DSurface9* srcSurface; - DX_CHECK(m_stagingCube->GetCubeMapSurface(D3DCUBEMAP_FACES(side), lod, &srcSurface) ); - IDirect3DSurface9* dstSurface = getSurface(side, lod); - - RECT srcRect = { LONG(0), LONG(0), LONG(mipWidth), LONG(mipHeight) }; - POINT dstPoint = { LONG(0), LONG(0) }; - - DX_CHECK(device->UpdateSurface(srcSurface - , &srcRect - , dstSurface - , &dstPoint - ) ); - - srcSurface->Release(); - dstSurface->Release(); - } + DX_CHECK(m_stagingCube->AddDirtyRect(D3DCUBEMAP_FACES(ii), NULL) ); } + DX_CHECK(device->UpdateTexture(m_stagingCube, m_textureCube) ); } } BGFX_FATAL(NULL != m_textureCube, Fatal::UnableToCreateTexture, "Failed to create cube texture (edge: %d, mips: %d, fmt: %s)." - , _edge + , _width , _numMips , getName(fmt) ); @@ -2668,65 +2610,28 @@ namespace bgfx { namespace d3d9 void TextureD3D9::unlock(uint8_t _side, uint8_t _lod) { + IDirect3DDevice9* device = s_renderD3D9->m_device; + switch (m_type) { case Texture2D: { DX_CHECK(m_staging2d->UnlockRect(_lod) ); - - IDirect3DSurface9* srcSurface; - DX_CHECK(m_staging2d->GetSurfaceLevel(0, &srcSurface) ); - IDirect3DSurface9* dstSurface = getSurface(0, _lod); - - const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(m_textureFormat) ); - uint32_t mipWidth = bx::uint32_max(blockInfo.blockWidth, m_width >>_lod); - uint32_t mipHeight = bx::uint32_max(blockInfo.blockHeight, m_height>>_lod); - - RECT srcRect = { LONG(0), LONG(0), LONG(mipWidth), LONG(mipHeight) }; - POINT dstPoint = { LONG(0), LONG(0) }; - - s_renderD3D9->m_device->UpdateSurface(srcSurface - , &srcRect - , dstSurface - , &dstPoint - ); - - srcSurface->Release(); - dstSurface->Release(); + DX_CHECK(device->UpdateTexture(m_staging2d, m_texture2d) ); } return; case Texture3D: { DX_CHECK(m_staging3d->UnlockBox(_lod) ); - DX_CHECK(m_texture3d->AddDirtyBox(NULL) ); - DX_CHECK(s_renderD3D9->m_device->UpdateTexture(m_staging3d, m_texture3d) ); + DX_CHECK(device->UpdateTexture(m_staging3d, m_texture3d) ); } return; case TextureCube: { DX_CHECK(m_stagingCube->UnlockRect(D3DCUBEMAP_FACES(_side), _lod) ); - - IDirect3DSurface9* srcSurface; - DX_CHECK(m_stagingCube->GetCubeMapSurface(D3DCUBEMAP_FACES(_side), _lod, &srcSurface) ); - IDirect3DSurface9* dstSurface = getSurface(_side, _lod); - - const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(m_textureFormat) ); - uint32_t mipWidth = bx::uint32_max(blockInfo.blockWidth, m_width >>_lod); - uint32_t mipHeight = bx::uint32_max(blockInfo.blockHeight, m_height>>_lod); - - RECT srcRect = { LONG(0), LONG(0), LONG(mipWidth), LONG(mipHeight) }; - POINT dstPoint = { LONG(0), LONG(0) }; - - DX_CHECK(s_renderD3D9->m_device->UpdateSurface(srcSurface - , &srcRect - , dstSurface - , &dstPoint - ) ); - - srcSurface->Release(); - dstSurface->Release(); + DX_CHECK(device->UpdateTexture(m_stagingCube, m_textureCube) ); } return; } diff --git a/src/renderer_d3d9.h b/src/renderer_d3d9.h index 75a782a1b..e7d4ce4be 100644 --- a/src/renderer_d3d9.h +++ b/src/renderer_d3d9.h @@ -316,8 +316,8 @@ namespace bgfx { namespace d3d9 } void createTexture(uint32_t _width, uint32_t _height, uint8_t _numMips); - void createVolumeTexture(uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _numMips); - void createCubeTexture(uint32_t _edge, uint32_t _numMips); + void createVolumeTexture(uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips); + void createCubeTexture(uint32_t _width, uint8_t _numMips); uint8_t* lock(uint8_t _side, uint8_t _lod, uint32_t& _pitch, uint32_t& _slicePitch, const Rect* _rect = NULL); void unlock(uint8_t _side, uint8_t _lod); diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index d331cb24e..3d1614126 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1594,12 +1594,12 @@ namespace bgfx { namespace gl { uint8_t supported = 0; supported |= s_textureFormat[ii].m_supported - ? BGFX_CAPS_FORMAT_TEXTURE_COLOR + ? BGFX_CAPS_FORMAT_TEXTURE_2D : BGFX_CAPS_FORMAT_TEXTURE_NONE ; supported |= isTextureFormatValid(TextureFormat::Enum(ii), true) - ? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB + ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE ; diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 6aa662001..c06e9e392 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -433,12 +433,12 @@ namespace bgfx { namespace mtl uint8_t support = 0; support |= MTLPixelFormatInvalid != s_textureFormat[ii].m_fmt - ? BGFX_CAPS_FORMAT_TEXTURE_COLOR + ? BGFX_CAPS_FORMAT_TEXTURE_2D : BGFX_CAPS_FORMAT_TEXTURE_NONE ; support |= MTLPixelFormatInvalid != s_textureFormat[ii].m_fmtSrgb - ? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB + ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE ;