Adding ability to pass texture created outside of bgfx.

This commit is contained in:
Branimir Karadžić 2016-01-17 20:33:39 -08:00
parent 86a38a0160
commit 07e65283b0
12 changed files with 232 additions and 143 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(4)
#define BGFX_API_VERSION UINT32_C(5)
///
#define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write.

View file

@ -11,6 +11,7 @@
// necessary to use this header in conjunction with creating windows.
#include <bx/platform.h>
#include <bgfx/bgfx.h>
namespace bgfx
{
@ -78,6 +79,14 @@ namespace bgfx
///
const InternalData* getInternalData();
/// Set externally created texture.
///
/// @warning Must be called only on render thread.
///
/// @attention C99 equivalent is `bgfx_set_internal_texture`.
///
void setInternal(TextureHandle _handle, uintptr_t _ptr);
} // namespace bgfx
#if BX_PLATFORM_ANDROID

View file

@ -40,7 +40,6 @@
#endif // defined(__cplusplus)
#include <bgfx/bgfxdefines.h>
#include <bgfx/c99/bgfxplatform.h>
typedef enum bgfx_renderer_type
{
@ -429,141 +428,6 @@ typedef struct bgfx_allocator_vtbl
} bgfx_allocator_vtbl_t;
/**/
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)();
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);
void (*vertex_decl_end)(bgfx_vertex_decl_t* _decl);
void (*vertex_pack)(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, void* _data, uint32_t _index);
void (*vertex_unpack)(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, const void* _data, uint32_t _index);
void (*vertex_convert)(const bgfx_vertex_decl_t* _destDecl, void* _destData, const bgfx_vertex_decl_t* _srcDecl, const void* _srcData, uint32_t _num);
uint16_t (*weld_vertices)(uint16_t* _output, const bgfx_vertex_decl_t* _decl, const void* _data, uint16_t _num, float _epsilon);
void (*image_swizzle_bgra8)(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
void (*image_rgba8_downsample_2x2)(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
uint8_t (*get_supported_renderers)(bgfx_renderer_type_t _enum[BGFX_RENDERER_TYPE_COUNT]);
const char* (*get_renderer_name)(bgfx_renderer_type_t _type);
bool (*init)(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_allocator_interface_t* _allocator);
void (*shutdown)();
void (*reset)(uint32_t _width, uint32_t _height, uint32_t _flags);
uint32_t (*frame)();
bgfx_renderer_type_t (*get_renderer_type)();
const bgfx_caps_t* (*get_caps)();
const bgfx_hmd_t* (*get_hmd)();
const bgfx_stats_t* (*get_stats)();
const bgfx_memory_t* (*alloc)(uint32_t _size);
const bgfx_memory_t* (*copy)(const void* _data, uint32_t _size);
const bgfx_memory_t* (*make_ref)(const void* _data, uint32_t _size);
const bgfx_memory_t* (*make_ref_release)(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData);
void (*set_debug)(uint32_t _debug);
void (*dbg_text_clear)(uint8_t _attr, bool _small);
void (*dbg_text_printf)(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);
void (*dbg_text_image)(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch);
bgfx_index_buffer_handle_t (*create_index_buffer)(const bgfx_memory_t* _mem, uint16_t _flags);
void (*destroy_index_buffer)(bgfx_index_buffer_handle_t _handle);
bgfx_vertex_buffer_handle_t (*create_vertex_buffer)(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
void (*destroy_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle);
bgfx_dynamic_index_buffer_handle_t (*create_dynamic_index_buffer)(uint32_t _num, uint16_t _flags);
bgfx_dynamic_index_buffer_handle_t (*create_dynamic_index_buffer_mem)(const bgfx_memory_t* _mem, uint16_t _flags);
void (*update_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _startIndex, const bgfx_memory_t* _mem);
void (*destroy_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle);
bgfx_dynamic_vertex_buffer_handle_t (*create_dynamic_vertex_buffer)(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
bgfx_dynamic_vertex_buffer_handle_t (*create_dynamic_vertex_buffer_mem)(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
void (*update_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, const bgfx_memory_t* _mem);
void (*destroy_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle);
bool (*check_avail_transient_index_buffer)(uint32_t _num);
bool (*check_avail_transient_vertex_buffer)(uint32_t _num, const bgfx_vertex_decl_t* _decl);
bool (*check_avail_instance_data_buffer)(uint32_t _num, uint16_t _stride);
bool (*check_avail_transient_buffers)(uint32_t _numVertices, const bgfx_vertex_decl_t* _decl, uint32_t _numIndices);
void (*alloc_transient_index_buffer)(bgfx_transient_index_buffer_t* _tib, uint32_t _num);
void (*alloc_transient_vertex_buffer)(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_decl_t* _decl);
bool (*alloc_transient_buffers)(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_decl_t* _decl, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices);
const bgfx_instance_data_buffer_t* (*alloc_instance_data_buffer)(uint32_t _num, uint16_t _stride);
bgfx_indirect_buffer_handle_t (*create_indirect_buffer)(uint32_t _num);
void (*destroy_indirect_buffer)(bgfx_indirect_buffer_handle_t _handle);
bgfx_shader_handle_t (*create_shader)(const bgfx_memory_t* _mem);
uint16_t (*get_shader_uniforms)(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max);
void (*destroy_shader)(bgfx_shader_handle_t _handle);
bgfx_program_handle_t (*create_program)(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders);
bgfx_program_handle_t (*create_compute_program)(bgfx_shader_handle_t _csh, bool _destroyShaders);
void (*destroy_program)(bgfx_program_handle_t _handle);
void (*calc_texture_size)(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, bgfx_texture_format_t _format);
bgfx_texture_handle_t (*create_texture)(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info);
bgfx_texture_handle_t (*create_texture_2d)(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
bgfx_texture_handle_t (*create_texture_2d_scaled)(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags);
bgfx_texture_handle_t (*create_texture_3d)(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
bgfx_texture_handle_t (*create_texture_cube)(uint16_t _size, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
void (*update_texture_2d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
void (*update_texture_3d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem);
void (*update_texture_cube)(bgfx_texture_handle_t _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
void (*destroy_texture)(bgfx_texture_handle_t _handle);
bgfx_frame_buffer_handle_t (*create_frame_buffer)(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags);
bgfx_frame_buffer_handle_t (*create_frame_buffer_scaled)(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags);
bgfx_frame_buffer_handle_t (*create_frame_buffer_from_handles)(uint8_t _num, const bgfx_texture_handle_t* _handles, bool _destroyTextures);
bgfx_frame_buffer_handle_t (*create_frame_buffer_from_nwh)(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat);
void (*destroy_frame_buffer)(bgfx_frame_buffer_handle_t _handle);
bgfx_uniform_handle_t (*create_uniform)(const char* _name, bgfx_uniform_type_t _type, uint16_t _num);
void (*destroy_uniform)(bgfx_uniform_handle_t _handle);
bgfx_occlusion_query_handle_t (*create_occlusion_query)();
bgfx_occlusion_query_result_t (*get_result)(bgfx_occlusion_query_handle_t _handle);
void (*destroy_occlusion_query)(bgfx_occlusion_query_handle_t _handle);
void (*set_palette_color)(uint8_t _index, const float _rgba[4]);
void (*set_view_name)(uint8_t _id, const char* _name);
void (*set_view_rect)(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*set_view_scissor)(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*set_view_clear)(uint8_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil);
void (*set_view_clear_mrt)(uint8_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7);
void (*set_view_seq)(uint8_t _id, bool _enabled);
void (*set_view_frame_buffer)(uint8_t _id, bgfx_frame_buffer_handle_t _handle);
void (*set_view_transform)(uint8_t _id, const void* _view, const void* _proj);
void (*set_view_transform_stereo)(uint8_t _id, const void* _view, const void* _projL, uint8_t _flags, const void* _projR);
void (*set_view_remap)(uint8_t _id, uint8_t _num, const void* _remap);
void (*set_marker)(const char* _marker);
void (*set_state)(uint64_t _state, uint32_t _rgba);
void (*set_condition)(bgfx_occlusion_query_handle_t _handle, bool _visible);
void (*set_stencil)(uint32_t _fstencil, uint32_t _bstencil);
uint16_t (*set_scissor)(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*set_scissor_cached)(uint16_t _cache);
uint32_t (*set_transform)(const void* _mtx, uint16_t _num);
uint32_t (*alloc_transform)(bgfx_transform_t* _transform, uint16_t _num);
void (*set_transform_cached)(uint32_t _cache, uint16_t _num);
void (*set_uniform)(bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num);
void (*set_index_buffer)(bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices);
void (*set_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices);
void (*set_transient_index_buffer)(const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices);
void (*set_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices);
void (*set_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _numVertices);
void (*set_transient_vertex_buffer)(const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices);
void (*set_instance_data_buffer)(const bgfx_instance_data_buffer_t* _idb, uint32_t _num);
void (*set_instance_data_from_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
void (*set_instance_data_from_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
void (*set_texture)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags);
void (*set_texture_from_frame_buffer)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, uint32_t _flags);
uint32_t (*touch)(uint8_t _id);
uint32_t (*submit)(uint8_t _id, bgfx_program_handle_t _handle, int32_t _depth);
uint32_t (*submit_occlusion_query)(uint8_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, int32_t _depth);
uint32_t (*submit_indirect)(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth);
void (*set_image)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format);
void (*set_image_from_frame_buffer)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_access_t _access, bgfx_texture_format_t _format);
void (*set_compute_index_buffer)(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access);
void (*set_compute_vertex_buffer)(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access);
void (*set_compute_dynamic_index_buffer)(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access);
void (*set_compute_dynamic_vertex_buffer)(uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access);
void (*set_compute_indirect_buffer)(uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access);
uint32_t (*dispatch)(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags);
uint32_t (*dispatch_indirect)(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags);
void (*discard)();
void (*blit)(uint8_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth);
void (*save_screen_shot)(const char* _filePath);
} bgfx_interface_vtbl_t;
typedef bgfx_interface_vtbl_t* (*PFN_BGFX_GET_INTERFACE)(uint32_t _version);
/**/
BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer);

View file

@ -13,6 +13,7 @@
// necessary to use this header in conjunction with creating windows.
#include <bx/platform.h>
#include <bgfx/c99/bgfxplatform.h>
typedef enum bgfx_render_frame
{
@ -41,6 +42,7 @@ typedef struct bgfx_platform_data
} bgfx_platform_data_t;
/**/
BGFX_C_API void bgfx_set_platform_data(const bgfx_platform_data_t* _data);
typedef struct bgfx_internal_data
@ -50,6 +52,145 @@ typedef struct bgfx_internal_data
} bgfx_internal_data_t;
/**/
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);
/**/
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)();
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);
void (*vertex_decl_end)(bgfx_vertex_decl_t* _decl);
void (*vertex_pack)(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, void* _data, uint32_t _index);
void (*vertex_unpack)(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, const void* _data, uint32_t _index);
void (*vertex_convert)(const bgfx_vertex_decl_t* _destDecl, void* _destData, const bgfx_vertex_decl_t* _srcDecl, const void* _srcData, uint32_t _num);
uint16_t (*weld_vertices)(uint16_t* _output, const bgfx_vertex_decl_t* _decl, const void* _data, uint16_t _num, float _epsilon);
void (*image_swizzle_bgra8)(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
void (*image_rgba8_downsample_2x2)(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
uint8_t (*get_supported_renderers)(bgfx_renderer_type_t _enum[BGFX_RENDERER_TYPE_COUNT]);
const char* (*get_renderer_name)(bgfx_renderer_type_t _type);
bool (*init)(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_allocator_interface_t* _allocator);
void (*shutdown)();
void (*reset)(uint32_t _width, uint32_t _height, uint32_t _flags);
uint32_t (*frame)();
bgfx_renderer_type_t (*get_renderer_type)();
const bgfx_caps_t* (*get_caps)();
const bgfx_hmd_t* (*get_hmd)();
const bgfx_stats_t* (*get_stats)();
const bgfx_memory_t* (*alloc)(uint32_t _size);
const bgfx_memory_t* (*copy)(const void* _data, uint32_t _size);
const bgfx_memory_t* (*make_ref)(const void* _data, uint32_t _size);
const bgfx_memory_t* (*make_ref_release)(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData);
void (*set_debug)(uint32_t _debug);
void (*dbg_text_clear)(uint8_t _attr, bool _small);
void (*dbg_text_printf)(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);
void (*dbg_text_image)(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch);
bgfx_index_buffer_handle_t (*create_index_buffer)(const bgfx_memory_t* _mem, uint16_t _flags);
void (*destroy_index_buffer)(bgfx_index_buffer_handle_t _handle);
bgfx_vertex_buffer_handle_t (*create_vertex_buffer)(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
void (*destroy_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle);
bgfx_dynamic_index_buffer_handle_t (*create_dynamic_index_buffer)(uint32_t _num, uint16_t _flags);
bgfx_dynamic_index_buffer_handle_t (*create_dynamic_index_buffer_mem)(const bgfx_memory_t* _mem, uint16_t _flags);
void (*update_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _startIndex, const bgfx_memory_t* _mem);
void (*destroy_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle);
bgfx_dynamic_vertex_buffer_handle_t (*create_dynamic_vertex_buffer)(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
bgfx_dynamic_vertex_buffer_handle_t (*create_dynamic_vertex_buffer_mem)(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
void (*update_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, const bgfx_memory_t* _mem);
void (*destroy_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle);
bool (*check_avail_transient_index_buffer)(uint32_t _num);
bool (*check_avail_transient_vertex_buffer)(uint32_t _num, const bgfx_vertex_decl_t* _decl);
bool (*check_avail_instance_data_buffer)(uint32_t _num, uint16_t _stride);
bool (*check_avail_transient_buffers)(uint32_t _numVertices, const bgfx_vertex_decl_t* _decl, uint32_t _numIndices);
void (*alloc_transient_index_buffer)(bgfx_transient_index_buffer_t* _tib, uint32_t _num);
void (*alloc_transient_vertex_buffer)(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_decl_t* _decl);
bool (*alloc_transient_buffers)(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_decl_t* _decl, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices);
const bgfx_instance_data_buffer_t* (*alloc_instance_data_buffer)(uint32_t _num, uint16_t _stride);
bgfx_indirect_buffer_handle_t (*create_indirect_buffer)(uint32_t _num);
void (*destroy_indirect_buffer)(bgfx_indirect_buffer_handle_t _handle);
bgfx_shader_handle_t (*create_shader)(const bgfx_memory_t* _mem);
uint16_t (*get_shader_uniforms)(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max);
void (*destroy_shader)(bgfx_shader_handle_t _handle);
bgfx_program_handle_t (*create_program)(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders);
bgfx_program_handle_t (*create_compute_program)(bgfx_shader_handle_t _csh, bool _destroyShaders);
void (*destroy_program)(bgfx_program_handle_t _handle);
void (*calc_texture_size)(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, bgfx_texture_format_t _format);
bgfx_texture_handle_t (*create_texture)(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info);
bgfx_texture_handle_t (*create_texture_2d)(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
bgfx_texture_handle_t (*create_texture_2d_scaled)(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags);
bgfx_texture_handle_t (*create_texture_3d)(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
bgfx_texture_handle_t (*create_texture_cube)(uint16_t _size, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
void (*update_texture_2d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
void (*update_texture_3d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem);
void (*update_texture_cube)(bgfx_texture_handle_t _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
void (*destroy_texture)(bgfx_texture_handle_t _handle);
bgfx_frame_buffer_handle_t (*create_frame_buffer)(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags);
bgfx_frame_buffer_handle_t (*create_frame_buffer_scaled)(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags);
bgfx_frame_buffer_handle_t (*create_frame_buffer_from_handles)(uint8_t _num, const bgfx_texture_handle_t* _handles, bool _destroyTextures);
bgfx_frame_buffer_handle_t (*create_frame_buffer_from_nwh)(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat);
void (*destroy_frame_buffer)(bgfx_frame_buffer_handle_t _handle);
bgfx_uniform_handle_t (*create_uniform)(const char* _name, bgfx_uniform_type_t _type, uint16_t _num);
void (*destroy_uniform)(bgfx_uniform_handle_t _handle);
bgfx_occlusion_query_handle_t (*create_occlusion_query)();
bgfx_occlusion_query_result_t (*get_result)(bgfx_occlusion_query_handle_t _handle);
void (*destroy_occlusion_query)(bgfx_occlusion_query_handle_t _handle);
void (*set_palette_color)(uint8_t _index, const float _rgba[4]);
void (*set_view_name)(uint8_t _id, const char* _name);
void (*set_view_rect)(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*set_view_scissor)(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*set_view_clear)(uint8_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil);
void (*set_view_clear_mrt)(uint8_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7);
void (*set_view_seq)(uint8_t _id, bool _enabled);
void (*set_view_frame_buffer)(uint8_t _id, bgfx_frame_buffer_handle_t _handle);
void (*set_view_transform)(uint8_t _id, const void* _view, const void* _proj);
void (*set_view_transform_stereo)(uint8_t _id, const void* _view, const void* _projL, uint8_t _flags, const void* _projR);
void (*set_view_remap)(uint8_t _id, uint8_t _num, const void* _remap);
void (*set_marker)(const char* _marker);
void (*set_state)(uint64_t _state, uint32_t _rgba);
void (*set_condition)(bgfx_occlusion_query_handle_t _handle, bool _visible);
void (*set_stencil)(uint32_t _fstencil, uint32_t _bstencil);
uint16_t (*set_scissor)(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*set_scissor_cached)(uint16_t _cache);
uint32_t (*set_transform)(const void* _mtx, uint16_t _num);
uint32_t (*alloc_transform)(bgfx_transform_t* _transform, uint16_t _num);
void (*set_transform_cached)(uint32_t _cache, uint16_t _num);
void (*set_uniform)(bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num);
void (*set_index_buffer)(bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices);
void (*set_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices);
void (*set_transient_index_buffer)(const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices);
void (*set_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices);
void (*set_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _numVertices);
void (*set_transient_vertex_buffer)(const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices);
void (*set_instance_data_buffer)(const bgfx_instance_data_buffer_t* _idb, uint32_t _num);
void (*set_instance_data_from_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
void (*set_instance_data_from_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
void (*set_texture)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags);
void (*set_texture_from_frame_buffer)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, uint32_t _flags);
uint32_t (*touch)(uint8_t _id);
uint32_t (*submit)(uint8_t _id, bgfx_program_handle_t _handle, int32_t _depth);
uint32_t (*submit_occlusion_query)(uint8_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, int32_t _depth);
uint32_t (*submit_indirect)(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth);
void (*set_image)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format);
void (*set_image_from_frame_buffer)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_access_t _access, bgfx_texture_format_t _format);
void (*set_compute_index_buffer)(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access);
void (*set_compute_vertex_buffer)(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access);
void (*set_compute_dynamic_index_buffer)(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access);
void (*set_compute_dynamic_vertex_buffer)(uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access);
void (*set_compute_indirect_buffer)(uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access);
uint32_t (*dispatch)(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags);
uint32_t (*dispatch_indirect)(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags);
void (*discard)();
void (*blit)(uint8_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth);
void (*save_screen_shot)(const char* _filePath);
} bgfx_interface_vtbl_t;
typedef bgfx_interface_vtbl_t* (*PFN_BGFX_GET_INTERFACE)(uint32_t _version);
#endif // BGFX_PLATFORM_C99_H_HEADER_GUARD

View file

@ -314,6 +314,12 @@ namespace bgfx
return &g_internalData;
}
void setInternal(TextureHandle _handle, uintptr_t _ptr)
{
BGFX_CHECK_RENDER_THREAD();
s_ctx->m_renderCtx->setInternal(_handle, _ptr);
}
void setGraphicsDebuggerPresent(bool _present)
{
BX_TRACE("Graphics debugger is %spresent.", _present ? "" : "not ");
@ -3498,6 +3504,32 @@ again:
#include <bgfx/c99/bgfx.h>
#include <bgfx/c99/bgfxplatform.h>
#define FLAGS_MASK_TEST(_flags, _mask) ( (_flags) == ( (_flags) & (_mask) ) )
BX_STATIC_ASSERT(FLAGS_MASK_TEST(0
| BGFX_TEXTURE_INTERNAL_DEFAULT_SAMPLER
| BGFX_TEXTURE_INTERNAL_SHARED
, BGFX_TEXTURE_RESERVED_MASK
) );
BX_STATIC_ASSERT(FLAGS_MASK_TEST(0
| BGFX_RESET_INTERNAL_FORCE
, BGFX_RESET_RESERVED_MASK
) );
BX_STATIC_ASSERT(FLAGS_MASK_TEST(0
| BGFX_STATE_INTERNAL_SCISSOR
| BGFX_STATE_INTERNAL_OCCLUSION_QUERY
, BGFX_STATE_RESERVED_MASK
) );
BX_STATIC_ASSERT(FLAGS_MASK_TEST(0
| BGFX_SUBMIT_INTERNAL_OCCLUSION_VISIBLE
, BGFX_SUBMIT_RESERVED_MASK
) );
#undef FLAGS_MASK_TEST
BX_STATIC_ASSERT(bgfx::Fatal::Count == bgfx::Fatal::Enum(BGFX_FATAL_COUNT) );
BX_STATIC_ASSERT(bgfx::RendererType::Count == bgfx::RendererType::Enum(BGFX_RENDERER_TYPE_COUNT) );
BX_STATIC_ASSERT(bgfx::Attrib::Count == bgfx::Attrib::Enum(BGFX_ATTRIB_COUNT) );
@ -4385,6 +4417,12 @@ 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)
{
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
bgfx::setInternal(handle.cpp, _ptr);
}
BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
{
if (_version == BGFX_API_VERSION)

View file

@ -201,6 +201,7 @@ namespace stl
#define BGFX_MAX_COMPUTE_BINDINGS 8
#define BGFX_TEXTURE_INTERNAL_DEFAULT_SAMPLER UINT32_C(0x10000000)
#define BGFX_TEXTURE_INTERNAL_SHARED UINT32_C(0x20000000)
#define BGFX_RESET_INTERNAL_FORCE UINT32_C(0x80000000)
@ -2042,6 +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 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;

View file

@ -1755,6 +1755,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
release(mem);
}
void setInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
{
m_textures[_handle.idx].setInternal(_ptr);
}
void destroyTexture(TextureHandle _handle) BX_OVERRIDE
{
m_textures[_handle.idx].destroy();
@ -4157,10 +4162,20 @@ BX_PRAGMA_DIAGNOSTIC_POP();
void TextureD3D11::destroy()
{
s_renderD3D11->m_srvUavLru.invalidateWithParent(getHandle().idx);
if (0 == (m_flags & BGFX_TEXTURE_INTERNAL_SHARED) )
{
DX_RELEASE(m_srv, 0);
DX_RELEASE(m_uav, 0);
DX_RELEASE(m_ptr, 0);
}
}
void TextureD3D11::setInternal(uintptr_t _ptr)
{
destroy();
m_flags |= BGFX_TEXTURE_INTERNAL_SHARED;
m_ptr = (ID3D11Resource*)_ptr;
}
void TextureD3D11::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem)
{

View file

@ -223,6 +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 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,6 +1372,11 @@ namespace bgfx { namespace d3d12
release(mem);
}
void setInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
{
BX_UNUSED(_handle, _ptr);
}
void destroyTexture(TextureHandle _handle) BX_OVERRIDE
{
m_textures[_handle.idx].destroy();

View file

@ -997,6 +997,11 @@ namespace bgfx { namespace d3d9
texture.m_height = _height;
}
void setInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
{
BX_UNUSED(_handle, _ptr);
}
void destroyTexture(TextureHandle _handle) BX_OVERRIDE
{
m_textures[_handle.idx].destroy();

View file

@ -2228,6 +2228,11 @@ namespace bgfx { namespace gl
release(mem);
}
void setInternal(TextureHandle _handle, uintptr_t _ptr) BX_OVERRIDE
{
BX_UNUSED(_handle, _ptr);
}
void destroyTexture(TextureHandle _handle) BX_OVERRIDE
{
m_textures[_handle.idx].destroy();

View file

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