From 83d0aab77a206d6384dedc194da381e6eafb4b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 31 Aug 2017 22:08:22 -0700 Subject: [PATCH] Updated C99 API. --- include/bgfx/c99/bgfx.h | 6 + include/bgfx/c99/platform.h | 2 + include/bgfx/defines.h | 2 +- src/bgfx.cpp | 274 +++++++++++++++++++----------------- 4 files changed, 153 insertions(+), 131 deletions(-) diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 4e0fa4472..b9b2d4e59 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -709,6 +709,9 @@ BGFX_C_API uint16_t bgfx_get_shader_uniforms(bgfx_shader_handle_t _handle, bgfx_ /**/ BGFX_C_API void bgfx_get_uniform_info(bgfx_uniform_handle_t _handle, bgfx_uniform_info_t* _info); +/**/ +BGFX_C_API void bgfx_set_shader_name(bgfx_shader_handle_t _handle, const char* _name); + /**/ BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle); @@ -754,6 +757,9 @@ BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint16_t /**/ BGFX_C_API uint32_t bgfx_read_texture(bgfx_texture_handle_t _handle, void* _data, uint8_t _mip); +/**/ +BGFX_C_API void bgfx_set_texture_name(bgfx_texture_handle_t _handle, const char* _name); + /**/ BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle); diff --git a/include/bgfx/c99/platform.h b/include/bgfx/c99/platform.h index 8edeecafa..ee5ceb1f1 100644 --- a/include/bgfx/c99/platform.h +++ b/include/bgfx/c99/platform.h @@ -123,6 +123,7 @@ typedef struct bgfx_interface_vtbl 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 (*set_shader_name)(bgfx_shader_handle_t _handle, const char* _name); 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); @@ -138,6 +139,7 @@ typedef struct bgfx_interface_vtbl 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, uint16_t _layer, 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); uint32_t (*read_texture)(bgfx_texture_handle_t _handle, void* _data, uint8_t _mip); + void (*set_texture_name)(bgfx_texture_handle_t _handle, const char* _name); 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); diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index f3a109ec5..812b4255a 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -6,7 +6,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(47) +#define BGFX_API_VERSION UINT32_C(48) /// Color RGB/alpha/depth write. When it's not specified write will be disabled. #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write. diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 53d06768d..c06a7ea45 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -4514,6 +4514,12 @@ BGFX_C_API uint16_t bgfx_get_shader_uniforms(bgfx_shader_handle_t _handle, bgfx_ return bgfx::getShaderUniforms(handle.cpp, (bgfx::UniformHandle*)_uniforms, _max); } +BGFX_C_API void bgfx_set_shader_name(bgfx_shader_handle_t _handle, const char* _name) +{ + union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle = { _handle }; + bgfx::setName(handle.cpp, _name); +} + BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle) { union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle = { _handle }; @@ -4614,6 +4620,12 @@ BGFX_C_API uint32_t bgfx_read_texture(bgfx_texture_handle_t _handle, void* _data return bgfx::readTexture(handle.cpp, _data, _mip); } +BGFX_C_API void bgfx_set_texture_name(bgfx_texture_handle_t _handle, const char* _name) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + bgfx::setName(handle.cpp, _name); +} + BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; @@ -5008,137 +5020,139 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) { if (_version == BGFX_API_VERSION) { -#define BGFX_IMPORT \ - 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) \ - BGFX_IMPORT_FUNC(vertex_decl_end) \ - BGFX_IMPORT_FUNC(vertex_pack) \ - BGFX_IMPORT_FUNC(vertex_unpack) \ - BGFX_IMPORT_FUNC(vertex_convert) \ - BGFX_IMPORT_FUNC(weld_vertices) \ - BGFX_IMPORT_FUNC(topology_convert) \ - BGFX_IMPORT_FUNC(topology_sort_tri_list) \ - BGFX_IMPORT_FUNC(get_supported_renderers) \ - BGFX_IMPORT_FUNC(get_renderer_name) \ - BGFX_IMPORT_FUNC(init) \ - BGFX_IMPORT_FUNC(shutdown) \ - BGFX_IMPORT_FUNC(reset) \ - BGFX_IMPORT_FUNC(frame) \ - BGFX_IMPORT_FUNC(get_renderer_type) \ - BGFX_IMPORT_FUNC(get_caps) \ - BGFX_IMPORT_FUNC(get_hmd) \ - BGFX_IMPORT_FUNC(get_stats) \ - BGFX_IMPORT_FUNC(alloc) \ - BGFX_IMPORT_FUNC(copy) \ - BGFX_IMPORT_FUNC(make_ref) \ - BGFX_IMPORT_FUNC(make_ref_release) \ - BGFX_IMPORT_FUNC(set_debug) \ - BGFX_IMPORT_FUNC(dbg_text_clear) \ - BGFX_IMPORT_FUNC(dbg_text_printf) \ - BGFX_IMPORT_FUNC(dbg_text_vprintf) \ - BGFX_IMPORT_FUNC(dbg_text_image) \ - BGFX_IMPORT_FUNC(create_index_buffer) \ - BGFX_IMPORT_FUNC(destroy_index_buffer) \ - BGFX_IMPORT_FUNC(create_vertex_buffer) \ - BGFX_IMPORT_FUNC(destroy_vertex_buffer) \ - BGFX_IMPORT_FUNC(create_dynamic_index_buffer) \ - BGFX_IMPORT_FUNC(create_dynamic_index_buffer_mem) \ - BGFX_IMPORT_FUNC(update_dynamic_index_buffer) \ - BGFX_IMPORT_FUNC(destroy_dynamic_index_buffer) \ - BGFX_IMPORT_FUNC(create_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(create_dynamic_vertex_buffer_mem) \ - BGFX_IMPORT_FUNC(update_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(destroy_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(get_avail_transient_index_buffer) \ - BGFX_IMPORT_FUNC(get_avail_transient_vertex_buffer) \ - BGFX_IMPORT_FUNC(get_avail_instance_data_buffer) \ - BGFX_IMPORT_FUNC(alloc_transient_index_buffer) \ - BGFX_IMPORT_FUNC(alloc_transient_vertex_buffer) \ - BGFX_IMPORT_FUNC(alloc_transient_buffers) \ - BGFX_IMPORT_FUNC(alloc_instance_data_buffer) \ - BGFX_IMPORT_FUNC(create_indirect_buffer) \ - BGFX_IMPORT_FUNC(destroy_indirect_buffer) \ - BGFX_IMPORT_FUNC(create_shader) \ - BGFX_IMPORT_FUNC(get_shader_uniforms) \ - BGFX_IMPORT_FUNC(destroy_shader) \ - BGFX_IMPORT_FUNC(create_program) \ - BGFX_IMPORT_FUNC(create_compute_program) \ - BGFX_IMPORT_FUNC(destroy_program) \ - BGFX_IMPORT_FUNC(is_texture_valid) \ - BGFX_IMPORT_FUNC(calc_texture_size) \ - BGFX_IMPORT_FUNC(create_texture) \ - BGFX_IMPORT_FUNC(create_texture_2d) \ - BGFX_IMPORT_FUNC(create_texture_2d_scaled) \ - BGFX_IMPORT_FUNC(create_texture_3d) \ - BGFX_IMPORT_FUNC(create_texture_cube) \ - BGFX_IMPORT_FUNC(update_texture_2d) \ - BGFX_IMPORT_FUNC(update_texture_3d) \ - BGFX_IMPORT_FUNC(update_texture_cube) \ - BGFX_IMPORT_FUNC(read_texture) \ - BGFX_IMPORT_FUNC(destroy_texture) \ - BGFX_IMPORT_FUNC(create_frame_buffer) \ - BGFX_IMPORT_FUNC(create_frame_buffer_scaled) \ - BGFX_IMPORT_FUNC(create_frame_buffer_from_attachment) \ - BGFX_IMPORT_FUNC(create_frame_buffer_from_nwh) \ - BGFX_IMPORT_FUNC(get_texture) \ - BGFX_IMPORT_FUNC(destroy_frame_buffer) \ - BGFX_IMPORT_FUNC(create_uniform) \ - BGFX_IMPORT_FUNC(get_uniform_info) \ - BGFX_IMPORT_FUNC(destroy_uniform) \ - BGFX_IMPORT_FUNC(create_occlusion_query) \ - BGFX_IMPORT_FUNC(get_result) \ - BGFX_IMPORT_FUNC(destroy_occlusion_query) \ - BGFX_IMPORT_FUNC(set_palette_color) \ - BGFX_IMPORT_FUNC(set_view_name) \ - BGFX_IMPORT_FUNC(set_view_rect) \ - BGFX_IMPORT_FUNC(set_view_scissor) \ - BGFX_IMPORT_FUNC(set_view_clear) \ - BGFX_IMPORT_FUNC(set_view_clear_mrt) \ - BGFX_IMPORT_FUNC(set_view_mode) \ - BGFX_IMPORT_FUNC(set_view_frame_buffer) \ - BGFX_IMPORT_FUNC(set_view_transform) \ - BGFX_IMPORT_FUNC(set_view_transform_stereo) \ - BGFX_IMPORT_FUNC(set_view_order) \ - BGFX_IMPORT_FUNC(set_marker) \ - BGFX_IMPORT_FUNC(set_state) \ - BGFX_IMPORT_FUNC(set_condition) \ - BGFX_IMPORT_FUNC(set_stencil) \ - BGFX_IMPORT_FUNC(set_scissor) \ - BGFX_IMPORT_FUNC(set_scissor_cached) \ - BGFX_IMPORT_FUNC(set_transform) \ - BGFX_IMPORT_FUNC(alloc_transform) \ - BGFX_IMPORT_FUNC(set_transform_cached) \ - BGFX_IMPORT_FUNC(set_uniform) \ - BGFX_IMPORT_FUNC(set_index_buffer) \ - BGFX_IMPORT_FUNC(set_dynamic_index_buffer) \ - BGFX_IMPORT_FUNC(set_transient_index_buffer) \ - BGFX_IMPORT_FUNC(set_vertex_buffer) \ - BGFX_IMPORT_FUNC(set_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(set_transient_vertex_buffer) \ - BGFX_IMPORT_FUNC(set_instance_data_buffer) \ - BGFX_IMPORT_FUNC(set_instance_data_from_vertex_buffer) \ +#define BGFX_IMPORT \ + 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) \ + BGFX_IMPORT_FUNC(vertex_decl_end) \ + BGFX_IMPORT_FUNC(vertex_pack) \ + BGFX_IMPORT_FUNC(vertex_unpack) \ + BGFX_IMPORT_FUNC(vertex_convert) \ + BGFX_IMPORT_FUNC(weld_vertices) \ + BGFX_IMPORT_FUNC(topology_convert) \ + BGFX_IMPORT_FUNC(topology_sort_tri_list) \ + BGFX_IMPORT_FUNC(get_supported_renderers) \ + BGFX_IMPORT_FUNC(get_renderer_name) \ + BGFX_IMPORT_FUNC(init) \ + BGFX_IMPORT_FUNC(shutdown) \ + BGFX_IMPORT_FUNC(reset) \ + BGFX_IMPORT_FUNC(frame) \ + BGFX_IMPORT_FUNC(get_renderer_type) \ + BGFX_IMPORT_FUNC(get_caps) \ + BGFX_IMPORT_FUNC(get_hmd) \ + BGFX_IMPORT_FUNC(get_stats) \ + BGFX_IMPORT_FUNC(alloc) \ + BGFX_IMPORT_FUNC(copy) \ + BGFX_IMPORT_FUNC(make_ref) \ + BGFX_IMPORT_FUNC(make_ref_release) \ + BGFX_IMPORT_FUNC(set_debug) \ + BGFX_IMPORT_FUNC(dbg_text_clear) \ + BGFX_IMPORT_FUNC(dbg_text_printf) \ + BGFX_IMPORT_FUNC(dbg_text_vprintf) \ + BGFX_IMPORT_FUNC(dbg_text_image) \ + BGFX_IMPORT_FUNC(create_index_buffer) \ + BGFX_IMPORT_FUNC(destroy_index_buffer) \ + BGFX_IMPORT_FUNC(create_vertex_buffer) \ + BGFX_IMPORT_FUNC(destroy_vertex_buffer) \ + BGFX_IMPORT_FUNC(create_dynamic_index_buffer) \ + BGFX_IMPORT_FUNC(create_dynamic_index_buffer_mem) \ + BGFX_IMPORT_FUNC(update_dynamic_index_buffer) \ + BGFX_IMPORT_FUNC(destroy_dynamic_index_buffer) \ + BGFX_IMPORT_FUNC(create_dynamic_vertex_buffer) \ + BGFX_IMPORT_FUNC(create_dynamic_vertex_buffer_mem) \ + BGFX_IMPORT_FUNC(update_dynamic_vertex_buffer) \ + BGFX_IMPORT_FUNC(destroy_dynamic_vertex_buffer) \ + BGFX_IMPORT_FUNC(get_avail_transient_index_buffer) \ + BGFX_IMPORT_FUNC(get_avail_transient_vertex_buffer) \ + BGFX_IMPORT_FUNC(get_avail_instance_data_buffer) \ + BGFX_IMPORT_FUNC(alloc_transient_index_buffer) \ + BGFX_IMPORT_FUNC(alloc_transient_vertex_buffer) \ + BGFX_IMPORT_FUNC(alloc_transient_buffers) \ + BGFX_IMPORT_FUNC(alloc_instance_data_buffer) \ + BGFX_IMPORT_FUNC(create_indirect_buffer) \ + BGFX_IMPORT_FUNC(destroy_indirect_buffer) \ + BGFX_IMPORT_FUNC(create_shader) \ + BGFX_IMPORT_FUNC(get_shader_uniforms) \ + BGFX_IMPORT_FUNC(set_shader_name) \ + BGFX_IMPORT_FUNC(destroy_shader) \ + BGFX_IMPORT_FUNC(create_program) \ + BGFX_IMPORT_FUNC(create_compute_program) \ + BGFX_IMPORT_FUNC(destroy_program) \ + BGFX_IMPORT_FUNC(is_texture_valid) \ + BGFX_IMPORT_FUNC(calc_texture_size) \ + BGFX_IMPORT_FUNC(create_texture) \ + BGFX_IMPORT_FUNC(create_texture_2d) \ + BGFX_IMPORT_FUNC(create_texture_2d_scaled) \ + BGFX_IMPORT_FUNC(create_texture_3d) \ + BGFX_IMPORT_FUNC(create_texture_cube) \ + BGFX_IMPORT_FUNC(update_texture_2d) \ + BGFX_IMPORT_FUNC(update_texture_3d) \ + BGFX_IMPORT_FUNC(update_texture_cube) \ + BGFX_IMPORT_FUNC(read_texture) \ + BGFX_IMPORT_FUNC(set_texture_name) \ + BGFX_IMPORT_FUNC(destroy_texture) \ + BGFX_IMPORT_FUNC(create_frame_buffer) \ + BGFX_IMPORT_FUNC(create_frame_buffer_scaled) \ + BGFX_IMPORT_FUNC(create_frame_buffer_from_attachment) \ + BGFX_IMPORT_FUNC(create_frame_buffer_from_nwh) \ + BGFX_IMPORT_FUNC(get_texture) \ + BGFX_IMPORT_FUNC(destroy_frame_buffer) \ + BGFX_IMPORT_FUNC(create_uniform) \ + BGFX_IMPORT_FUNC(get_uniform_info) \ + BGFX_IMPORT_FUNC(destroy_uniform) \ + BGFX_IMPORT_FUNC(create_occlusion_query) \ + BGFX_IMPORT_FUNC(get_result) \ + BGFX_IMPORT_FUNC(destroy_occlusion_query) \ + BGFX_IMPORT_FUNC(set_palette_color) \ + BGFX_IMPORT_FUNC(set_view_name) \ + BGFX_IMPORT_FUNC(set_view_rect) \ + BGFX_IMPORT_FUNC(set_view_scissor) \ + BGFX_IMPORT_FUNC(set_view_clear) \ + BGFX_IMPORT_FUNC(set_view_clear_mrt) \ + BGFX_IMPORT_FUNC(set_view_mode) \ + BGFX_IMPORT_FUNC(set_view_frame_buffer) \ + BGFX_IMPORT_FUNC(set_view_transform) \ + BGFX_IMPORT_FUNC(set_view_transform_stereo) \ + BGFX_IMPORT_FUNC(set_view_order) \ + BGFX_IMPORT_FUNC(set_marker) \ + BGFX_IMPORT_FUNC(set_state) \ + BGFX_IMPORT_FUNC(set_condition) \ + BGFX_IMPORT_FUNC(set_stencil) \ + BGFX_IMPORT_FUNC(set_scissor) \ + BGFX_IMPORT_FUNC(set_scissor_cached) \ + BGFX_IMPORT_FUNC(set_transform) \ + BGFX_IMPORT_FUNC(alloc_transform) \ + BGFX_IMPORT_FUNC(set_transform_cached) \ + BGFX_IMPORT_FUNC(set_uniform) \ + BGFX_IMPORT_FUNC(set_index_buffer) \ + BGFX_IMPORT_FUNC(set_dynamic_index_buffer) \ + BGFX_IMPORT_FUNC(set_transient_index_buffer) \ + BGFX_IMPORT_FUNC(set_vertex_buffer) \ + BGFX_IMPORT_FUNC(set_dynamic_vertex_buffer) \ + BGFX_IMPORT_FUNC(set_transient_vertex_buffer) \ + BGFX_IMPORT_FUNC(set_instance_data_buffer) \ + BGFX_IMPORT_FUNC(set_instance_data_from_vertex_buffer) \ BGFX_IMPORT_FUNC(set_instance_data_from_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(set_texture) \ - BGFX_IMPORT_FUNC(touch) \ - BGFX_IMPORT_FUNC(submit) \ - BGFX_IMPORT_FUNC(submit_occlusion_query) \ - BGFX_IMPORT_FUNC(submit_indirect) \ - BGFX_IMPORT_FUNC(set_image) \ - BGFX_IMPORT_FUNC(set_compute_index_buffer) \ - BGFX_IMPORT_FUNC(set_compute_vertex_buffer) \ - BGFX_IMPORT_FUNC(set_compute_dynamic_index_buffer) \ - BGFX_IMPORT_FUNC(set_compute_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(set_compute_indirect_buffer) \ - BGFX_IMPORT_FUNC(dispatch) \ - BGFX_IMPORT_FUNC(dispatch_indirect) \ - BGFX_IMPORT_FUNC(discard) \ - BGFX_IMPORT_FUNC(blit) \ + BGFX_IMPORT_FUNC(set_texture) \ + BGFX_IMPORT_FUNC(touch) \ + BGFX_IMPORT_FUNC(submit) \ + BGFX_IMPORT_FUNC(submit_occlusion_query) \ + BGFX_IMPORT_FUNC(submit_indirect) \ + BGFX_IMPORT_FUNC(set_image) \ + BGFX_IMPORT_FUNC(set_compute_index_buffer) \ + BGFX_IMPORT_FUNC(set_compute_vertex_buffer) \ + BGFX_IMPORT_FUNC(set_compute_dynamic_index_buffer) \ + BGFX_IMPORT_FUNC(set_compute_dynamic_vertex_buffer) \ + BGFX_IMPORT_FUNC(set_compute_indirect_buffer) \ + BGFX_IMPORT_FUNC(dispatch) \ + BGFX_IMPORT_FUNC(dispatch_indirect) \ + BGFX_IMPORT_FUNC(discard) \ + BGFX_IMPORT_FUNC(blit) \ BGFX_IMPORT_FUNC(request_screen_shot) static bgfx_interface_vtbl_t s_bgfx_interface =