diff --git a/include/bgfx/bgfxplatform.h b/include/bgfx/bgfxplatform.h index 73a556643..d4fa61cc1 100644 --- a/include/bgfx/bgfxplatform.h +++ b/include/bgfx/bgfxplatform.h @@ -87,6 +87,9 @@ namespace bgfx /// void setInternal(TextureHandle _handle, uintptr_t _ptr); + /// + uintptr_t setInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE); + } // namespace bgfx #if BX_PLATFORM_ANDROID diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 4cfb63af3..88dab77d0 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -320,6 +320,37 @@ namespace bgfx s_ctx->m_renderCtx->setInternal(_handle, _ptr); } + uintptr_t setInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags) + { + BGFX_CHECK_RENDER_THREAD(); + + uint32_t size = sizeof(uint32_t) + sizeof(TextureCreate); + Memory* mem = const_cast(alloc(size) ); + + bx::StaticMemoryBlockWriter writer(mem->data, mem->size); + uint32_t magic = BGFX_CHUNK_MAGIC_TEX; + bx::write(&writer, magic); + + TextureCreate tc; + tc.m_flags = _flags; + tc.m_width = _width; + tc.m_height = _height; + tc.m_sides = 0; + tc.m_depth = 0; + tc.m_numMips = uint8_t(bx::uint16_max(1, _numMips) ); + tc.m_format = _format; + tc.m_cubeMap = false; + tc.m_mem = NULL; + bx::write(&writer, tc); + + s_ctx->m_renderCtx->destroyTexture(_handle); + s_ctx->m_renderCtx->createTexture(_handle, mem, _flags, 0); + + release(mem); + + return s_ctx->m_renderCtx->getInternal(_handle); + } + void setGraphicsDebuggerPresent(bool _present) { BX_TRACE("Graphics debugger is %spresent.", _present ? "" : "not "); @@ -2841,13 +2872,6 @@ again: ); } - uint32_t size = sizeof(uint32_t)+sizeof(TextureCreate); - const Memory* mem = alloc(size); - - bx::StaticMemoryBlockWriter writer(mem->data, mem->size); - uint32_t magic = BGFX_CHUNK_MAGIC_TEX; - bx::write(&writer, magic); - if (BackbufferRatio::Count != _ratio) { _width = uint16_t(s_ctx->m_resolution.m_width); @@ -2855,6 +2879,13 @@ again: getTextureSizeFromRatio(_ratio, _width, _height); } + uint32_t size = sizeof(uint32_t)+sizeof(TextureCreate); + const Memory* mem = alloc(size); + + bx::StaticMemoryBlockWriter writer(mem->data, mem->size); + uint32_t magic = BGFX_CHUNK_MAGIC_TEX; + bx::write(&writer, magic); + TextureCreate tc; tc.m_flags = _flags; tc.m_width = _width; diff --git a/src/bgfx_p.h b/src/bgfx_p.h index dcd458dba..b08187306 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -2044,6 +2044,7 @@ namespace bgfx virtual void readTexture(TextureHandle _handle, void* _data) = 0; virtual void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) = 0; virtual void setInternal(TextureHandle _handle, uintptr_t _ptr) = 0; + virtual uintptr_t getInternal(TextureHandle _handle) = 0; virtual void destroyTexture(TextureHandle _handle) = 0; virtual void createFrameBuffer(FrameBufferHandle _handle, uint8_t _num, const TextureHandle* _textureHandles) = 0; virtual void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) = 0; diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index cb4251416..953c4a362 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1760,6 +1760,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_textures[_handle.idx].setInternal(_ptr); } + uintptr_t getInternal(TextureHandle _handle) BX_OVERRIDE + { + return uintptr_t(m_textures[_handle.idx].m_ptr); + } + void destroyTexture(TextureHandle _handle) BX_OVERRIDE { m_textures[_handle.idx].destroy(); diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index d365b1a2a..109ef090e 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -1377,6 +1377,12 @@ namespace bgfx { namespace d3d12 BX_UNUSED(_handle, _ptr); } + uintptr_t getInternal(TextureHandle _handle) BX_OVERRIDE + { + BX_UNUSED(_handle); + return 0; + } + void destroyTexture(TextureHandle _handle) BX_OVERRIDE { m_textures[_handle.idx].destroy(); diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index b832a175d..22282efd6 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -1002,6 +1002,11 @@ namespace bgfx { namespace d3d9 BX_UNUSED(_handle, _ptr); } + uintptr_t getInternal(TextureHandle _handle) BX_OVERRIDE + { + return uintptr_t(m_textures[_handle.idx].m_ptr); + } + void destroyTexture(TextureHandle _handle) BX_OVERRIDE { m_textures[_handle.idx].destroy(); diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 8c83c37c0..e09836763 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -2233,6 +2233,11 @@ namespace bgfx { namespace gl BX_UNUSED(_handle, _ptr); } + uintptr_t getInternal(TextureHandle _handle) BX_OVERRIDE + { + return uintptr_t(m_textures[_handle.idx].m_id); + } + void destroyTexture(TextureHandle _handle) BX_OVERRIDE { m_textures[_handle.idx].destroy(); diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 6273f1e7a..e5da431ac 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -683,6 +683,12 @@ namespace bgfx { namespace mtl BX_UNUSED(_handle, _ptr); } + uintptr_t getInternal(TextureHandle _handle) BX_OVERRIDE + { + BX_UNUSED(_handle); + return 0; + } + void destroyTexture(TextureHandle _handle) BX_OVERRIDE { m_textures[_handle.idx].destroy(); diff --git a/src/renderer_null.cpp b/src/renderer_null.cpp index eba54adb0..ff1175398 100644 --- a/src/renderer_null.cpp +++ b/src/renderer_null.cpp @@ -125,6 +125,11 @@ namespace bgfx { namespace noop { } + uintptr_t getInternal(TextureHandle /*_handle*/) BX_OVERRIDE + { + return 0; + } + void destroyTexture(TextureHandle /*_handle*/) BX_OVERRIDE { }