Texture override internal now returns 0 to signal that internal texture is not yet created.

This commit is contained in:
Branimir Karadžić 2016-02-05 18:41:01 -08:00
parent 55e72a2dd1
commit cf6ccace77
4 changed files with 32 additions and 15 deletions

View file

@ -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.

View file

@ -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.
///

View file

@ -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);

View file

@ -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<Memory*>(alloc(size) );
Memory* mem = const_cast<Memory*>(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)