From cf6ccace77b7e828f445e5ac58a94faa4df65ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 5 Feb 2016 18:41:01 -0800 Subject: [PATCH] Texture override internal now returns 0 to signal that internal texture is not yet created. --- include/bgfx/bgfxdefines.h | 2 +- include/bgfx/bgfxplatform.h | 8 ++++++-- include/bgfx/c99/bgfxplatform.h | 8 ++++---- src/bgfx.cpp | 29 +++++++++++++++++++++-------- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/include/bgfx/bgfxdefines.h b/include/bgfx/bgfxdefines.h index 51ac4c2a8..3c1b3671a 100644 --- a/include/bgfx/bgfxdefines.h +++ b/include/bgfx/bgfxdefines.h @@ -6,7 +6,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(6) +#define BGFX_API_VERSION UINT32_C(7) /// #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write. diff --git a/include/bgfx/bgfxplatform.h b/include/bgfx/bgfxplatform.h index 207582e0c..1b6e336b6 100644 --- a/include/bgfx/bgfxplatform.h +++ b/include/bgfx/bgfxplatform.h @@ -91,11 +91,14 @@ namespace bgfx /// @param[in] _handle Texture handle. /// @param[in] _ptr Native API pointer to texture. /// + /// @returns Native API pointer to texture. If result is 0, texture is not created yet from the + /// main thread. + /// /// @warning Must be called only on render thread. /// /// @attention C99 equivalent is `bgfx_override_internal_texture_ptr`. /// - void overrideInternal(TextureHandle _handle, uintptr_t _ptr); + uintptr_t overrideInternal(TextureHandle _handle, uintptr_t _ptr); /// Override internal texture by creating new texture. Previously created /// internal texture will released. @@ -115,7 +118,8 @@ namespace bgfx /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic /// sampling. /// - /// @returns Native API pointer to texture. + /// @returns Native API pointer to texture. If result is 0, texture is not created yet from the + /// main thread. /// /// @warning Must be called only on render thread. /// diff --git a/include/bgfx/c99/bgfxplatform.h b/include/bgfx/c99/bgfxplatform.h index 42824cce3..1fb82c974 100644 --- a/include/bgfx/c99/bgfxplatform.h +++ b/include/bgfx/c99/bgfxplatform.h @@ -47,7 +47,7 @@ BGFX_C_API void bgfx_set_platform_data(const bgfx_platform_data_t* _data); typedef struct bgfx_internal_data { - const struct bgfx_caps* caps; + const struct bgfx_caps* caps; void* context; } bgfx_internal_data_t; @@ -56,7 +56,7 @@ typedef struct bgfx_internal_data BGFX_C_API const bgfx_internal_data_t* bgfx_get_internal_data(); /**/ -BGFX_C_API void bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _handle, uintptr_t _ptr); +BGFX_C_API uintptr_t bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _handle, uintptr_t _ptr); /**/ BGFX_C_API uintptr_t bgfx_override_internal_texture(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags); @@ -67,8 +67,8 @@ typedef struct bgfx_interface_vtbl bgfx_render_frame_t (*render_frame)(); void (*set_platform_data)(const bgfx_platform_data_t* _data); const bgfx_internal_data_t* (*get_internal_data)(); - void (*override_internal_texture_ptr)(bgfx_texture_handle_t _handle, uintptr_t _ptr); - uintptr_t (*override_internal_texture)(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags); + uintptr_t (*override_internal_texture_ptr)(bgfx_texture_handle_t _handle, uintptr_t _ptr); + uintptr_t (*override_internal_texture)(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags); void (*vertex_decl_begin)(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer); void (*vertex_decl_add)(bgfx_vertex_decl_t* _decl, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt); void (*vertex_decl_skip)(bgfx_vertex_decl_t* _decl, uint8_t _num); diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 5491995ef..aae0311eb 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -314,18 +314,31 @@ namespace bgfx return &g_internalData; } - void overrideInternal(TextureHandle _handle, uintptr_t _ptr) + uintptr_t overrideInternal(TextureHandle _handle, uintptr_t _ptr) { BGFX_CHECK_RENDER_THREAD(); - s_ctx->m_renderCtx->overrideInternal(_handle, _ptr); + RendererContextI* rci = s_ctx->m_renderCtx; + if (0 == rci->getInternal(_handle) ) + { + return 0; + } + + rci->overrideInternal(_handle, _ptr); + + return rci->getInternal(_handle); } uintptr_t overrideInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags) { BGFX_CHECK_RENDER_THREAD(); + RendererContextI* rci = s_ctx->m_renderCtx; + if (0 == rci->getInternal(_handle) ) + { + return 0; + } uint32_t size = sizeof(uint32_t) + sizeof(TextureCreate); - Memory* mem = const_cast(alloc(size) ); + Memory* mem = const_cast(alloc(size) ); bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; @@ -343,12 +356,12 @@ namespace bgfx tc.m_mem = NULL; bx::write(&writer, tc); - s_ctx->m_renderCtx->destroyTexture(_handle); - s_ctx->m_renderCtx->createTexture(_handle, mem, _flags, 0); + rci->destroyTexture(_handle); + rci->createTexture(_handle, mem, _flags, 0); release(mem); - return s_ctx->m_renderCtx->getInternal(_handle); + return rci->getInternal(_handle); } void setGraphicsDebuggerPresent(bool _present) @@ -4457,10 +4470,10 @@ BGFX_C_API const bgfx_internal_data_t* bgfx_get_internal_data() return (const bgfx_internal_data_t*)bgfx::getInternalData(); } -BGFX_C_API void bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _handle, uintptr_t _ptr) +BGFX_C_API uintptr_t bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _handle, uintptr_t _ptr) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - bgfx::overrideInternal(handle.cpp, _ptr); + return bgfx::overrideInternal(handle.cpp, _ptr); } BGFX_C_API uintptr_t bgfx_override_internal_texture(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags)