This commit is contained in:
Branimir Karadžić 2016-01-20 19:27:48 -08:00
parent 11d023414c
commit cc205ee0d5
11 changed files with 67 additions and 21 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(5)
#define BGFX_API_VERSION UINT32_C(6)
///
#define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write.

View file

@ -73,22 +73,55 @@ namespace bgfx
/// Get internal data for interop.
///
/// @attention It's expected you understand some bgfx internals before you
/// use this call.
///
/// @warning Must be called only on render thread.
///
/// @attention C99 equivalent is `bgfx_get_internal_data`.
///
const InternalData* getInternalData();
/// Set externally created texture.
/// Override internal texture with externally created texture. Previously
/// created internal texture will released.
///
/// @attention It's expected you understand some bgfx internals before you
/// use this call.
///
/// @param[in] _handle Texture handle.
/// @param[in] _ptr Native API pointer to texture.
///
/// @warning Must be called only on render thread.
///
/// @attention C99 equivalent is `bgfx_set_internal_texture`.
/// @attention C99 equivalent is `bgfx_override_internal_texture_ptr`.
///
void setInternal(TextureHandle _handle, uintptr_t _ptr);
void overrideInternal(TextureHandle _handle, uintptr_t _ptr);
/// Override internal texture by creating new texture. Previously created
/// internal texture will released.
///
uintptr_t setInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE);
/// @attention It's expected you understand some bgfx internals before you
/// use this call.
///
/// @param[in] _handle Texture handle.
/// @param[in] _width Width.
/// @param[in] _height Height.
/// @param[in] _numMips Number of mip-maps.
/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
/// is repeat.
/// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap
/// mode.
/// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
/// sampling.
///
/// @returns Native API pointer to texture.
///
/// @warning Must be called only on render thread.
///
/// @attention C99 equivalent is `bgfx_override_internal_texture`.
///
uintptr_t overrideInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE);
} // namespace bgfx

View file

@ -56,14 +56,19 @@ typedef struct bgfx_internal_data
BGFX_C_API const bgfx_internal_data_t* bgfx_get_internal_data();
/**/
BGFX_C_API void bgfx_set_internal_texture(bgfx_texture_handle_t _handle, uintptr_t _ptr);
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(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags);
/**/
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_platform_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);
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,13 +314,13 @@ namespace bgfx
return &g_internalData;
}
void setInternal(TextureHandle _handle, uintptr_t _ptr)
void overrideInternal(TextureHandle _handle, uintptr_t _ptr)
{
BGFX_CHECK_RENDER_THREAD();
s_ctx->m_renderCtx->setInternal(_handle, _ptr);
s_ctx->m_renderCtx->overrideInternal(_handle, _ptr);
}
uintptr_t setInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags)
uintptr_t overrideInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags)
{
BGFX_CHECK_RENDER_THREAD();
@ -4448,10 +4448,16 @@ 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_set_internal_texture(bgfx_texture_handle_t _handle, uintptr_t _ptr)
BGFX_C_API void 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::setInternal(handle.cpp, _ptr);
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)
{
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
return bgfx::overrideInternal(handle.cpp, _width, _height, _numMips, bgfx::TextureFormat::Enum(_format), _flags);
}
BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
@ -4462,6 +4468,8 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
BGFX_IMPORT_FUNC(render_frame) \
BGFX_IMPORT_FUNC(set_platform_data) \
BGFX_IMPORT_FUNC(get_internal_data) \
BGFX_IMPORT_FUNC(override_internal_texture_ptr) \
BGFX_IMPORT_FUNC(override_internal_texture) \
BGFX_IMPORT_FUNC(vertex_decl_begin) \
BGFX_IMPORT_FUNC(vertex_decl_add) \
BGFX_IMPORT_FUNC(vertex_decl_skip) \

View file

@ -2043,7 +2043,7 @@ namespace bgfx
virtual void updateTextureEnd() = 0;
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 void overrideInternal(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;

View file

@ -1755,9 +1755,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
release(mem);
}
void setInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
void overrideInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
{
m_textures[_handle.idx].setInternal(_ptr);
m_textures[_handle.idx].overrideInternal(_ptr);
}
uintptr_t getInternal(TextureHandle _handle) BX_OVERRIDE
@ -4175,7 +4175,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
}
}
void TextureD3D11::setInternal(uintptr_t _ptr)
void TextureD3D11::overrideInternal(uintptr_t _ptr)
{
destroy();
m_flags |= BGFX_TEXTURE_INTERNAL_SHARED;

View file

@ -223,7 +223,7 @@ namespace bgfx { namespace d3d11
void create(const Memory* _mem, uint32_t _flags, uint8_t _skip);
void destroy();
void setInternal(uintptr_t _ptr);
void overrideInternal(uintptr_t _ptr);
void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
void commit(uint8_t _stage, uint32_t _flags, const float _palette[][4]);
void resolve();

View file

@ -1372,7 +1372,7 @@ namespace bgfx { namespace d3d12
release(mem);
}
void setInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
void overrideInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
{
BX_UNUSED(_handle, _ptr);
}

View file

@ -997,7 +997,7 @@ namespace bgfx { namespace d3d9
texture.m_height = _height;
}
void setInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
void overrideInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
{
BX_UNUSED(_handle, _ptr);
}

View file

@ -2228,7 +2228,7 @@ namespace bgfx { namespace gl
release(mem);
}
void setInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
void overrideInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
{
BX_UNUSED(_handle, _ptr);
}

View file

@ -121,7 +121,7 @@ namespace bgfx { namespace noop
{
}
void setInternal(TextureHandle /*_handle*/, uintptr_t /*_ptr*/) BX_OVERRIDE
void overrideInternal(TextureHandle /*_handle*/, uintptr_t /*_ptr*/) BX_OVERRIDE
{
}