diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index d20470d0e..2ba1417f6 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -641,6 +641,17 @@ namespace bgfx bool cubeMap; //!< Texture is cubemap. }; + /// Uniform info. + /// + /// @attention C99 equivalent is `bgfx_uniform_info_t`. + /// + struct UniformInfo + { + char name[256]; //!< Uniform name. + UniformType::Enum type; //!< Uniform type. + uint16_t num; //!< Number of elements in array. + }; + /// Frame buffer texture attachemnt info. /// /// @attention C99 equivalent is `bgfx_attachment_t`. @@ -1986,6 +1997,15 @@ namespace bgfx /// UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num = 1); + /// Retrieve uniform info. + /// + /// @param[in] _handle Handle to uniform object. + /// @param[out] _info Uniform info. + /// + /// @attention C99 equivalent is `bgfx_get_uniform_info`. + /// + void getUniformInfo(UniformHandle _handle, UniformInfo& _info); + /// Destroy shader uniform parameter. /// /// @param[in] _handle Handle to uniform object. diff --git a/include/bgfx/bgfxdefines.h b/include/bgfx/bgfxdefines.h index 7d2b21662..f42fd25c6 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(28) +#define BGFX_API_VERSION UINT32_C(29) /// #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write. diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 046932441..fdf7f52d2 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -390,6 +390,15 @@ typedef struct bgfx_texture_info } bgfx_texture_info_t; +/**/ +typedef struct bgfx_uniform_info +{ + char name[256]; + bgfx_uniform_type_t type; + uint16_t num; + +} bgfx_uniform_info_t; + /**/ typedef struct bgfx_attachment { diff --git a/include/bgfx/c99/bgfxplatform.h b/include/bgfx/c99/bgfxplatform.h index 2b7643ef1..56b4d8ab7 100644 --- a/include/bgfx/c99/bgfxplatform.h +++ b/include/bgfx/c99/bgfxplatform.h @@ -147,6 +147,7 @@ typedef struct bgfx_interface_vtbl 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 (*get_uniform_info)(bgfx_uniform_handle_t _handle, bgfx_uniform_info_t* _info); 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); diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 02b76fa8b..fc316cf5e 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -3290,6 +3290,12 @@ error: return s_ctx->createUniform(_name, _type, _num); } + void getUniformInfo(UniformHandle _handle, UniformInfo& _info) + { + BGFX_CHECK_MAIN_THREAD(); + s_ctx->getUniformInfo(_handle, _info); + } + void destroyUniform(UniformHandle _handle) { BGFX_CHECK_MAIN_THREAD(); @@ -3788,6 +3794,7 @@ BGFX_C99_STRUCT_SIZE_CHECK(bgfx::TransientIndexBuffer, bgfx_transient_index_buf BGFX_C99_STRUCT_SIZE_CHECK(bgfx::TransientVertexBuffer, bgfx_transient_vertex_buffer_t); BGFX_C99_STRUCT_SIZE_CHECK(bgfx::InstanceDataBuffer, bgfx_instance_data_buffer_t); BGFX_C99_STRUCT_SIZE_CHECK(bgfx::TextureInfo, bgfx_texture_info_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::UniformInfo, bgfx_uniform_info_t); BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Attachment, bgfx_attachment_t); BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Caps::GPU, bgfx_caps_gpu_t); BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Caps::Limits, bgfx_caps_limits_t); @@ -4358,6 +4365,13 @@ BGFX_C_API bgfx_uniform_handle_t bgfx_create_uniform(const char* _name, bgfx_uni return handle.c; } +BGFX_C_API void bgfx_get_uniform_info(bgfx_uniform_handle_t _handle, bgfx_uniform_info_t* _info) +{ + union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle = { _handle }; + bgfx::UniformInfo& info = *(bgfx::UniformInfo*)_info; + bgfx::getUniformInfo(handle.cpp, info); +} + BGFX_C_API void bgfx_destroy_uniform(bgfx_uniform_handle_t _handle) { union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle = { _handle }; @@ -4786,6 +4800,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) BGFX_IMPORT_FUNC(create_frame_buffer_from_nwh) \ 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) \ diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 69b45c56a..bcd4f84a8 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1127,7 +1127,7 @@ namespace bgfx char m_buffer[8]; }; - struct UniformInfo + struct UniformRegInfo { const void* m_data; UniformHandle m_handle; @@ -1144,7 +1144,7 @@ namespace bgfx { } - const UniformInfo* find(const char* _name) const + const UniformRegInfo* find(const char* _name) const { uint16_t handle = m_uniforms.find(bx::hashMurmur2A(_name) ); if (UniformHashMap::invalid != handle) @@ -1155,14 +1155,14 @@ namespace bgfx return NULL; } - const UniformInfo& add(UniformHandle _handle, const char* _name, const void* _data) + const UniformRegInfo& add(UniformHandle _handle, const char* _name, const void* _data) { BX_CHECK(isValid(_handle), "Uniform handle is invalid (name: %s)!", _name); const uint32_t key = bx::hashMurmur2A(_name); m_uniforms.removeByKey(key); m_uniforms.insert(key, _handle.idx); - UniformInfo& info = m_info[_handle.idx]; + UniformRegInfo& info = m_info[_handle.idx]; info.m_data = _data; info.m_handle = _handle; @@ -1177,7 +1177,7 @@ namespace bgfx private: typedef bx::HandleHashMapT UniformHashMap; UniformHashMap m_uniforms; - UniformInfo m_info[BGFX_CONFIG_MAX_UNIFORMS]; + UniformRegInfo m_info[BGFX_CONFIG_MAX_UNIFORMS]; }; struct Binding @@ -3490,6 +3490,16 @@ namespace bgfx return handle; } + BGFX_API_FUNC(void getUniformInfo(UniformHandle _handle, UniformInfo& _info) ) + { + BGFX_CHECK_HANDLE("getUniformInfo", m_uniformHandle, _handle); + + UniformRef& uniform = m_uniformRef[_handle.idx]; + bx::strlcpy(_info.name, uniform.m_name.getPtr(), sizeof(_info.name) ); + _info.type = uniform.m_type; + _info.num = uniform.m_num; + } + BGFX_API_FUNC(void destroyUniform(UniformHandle _handle) ) { BGFX_CHECK_HANDLE("destroyUniform", m_uniformHandle, _handle); diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 29b5d3925..5a0979bb5 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -4207,7 +4207,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } else if (0 == (BGFX_UNIFORM_SAMPLERBIT & type) ) { - const UniformInfo* info = s_renderD3D11->m_uniformReg.find(name); + const UniformRegInfo* info = s_renderD3D11->m_uniformReg.find(name); BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); if (NULL != info) diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index d7a449ea8..4092f621e 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -3880,7 +3880,7 @@ data.NumQualityLevels = 0; } else if (0 == (BGFX_UNIFORM_SAMPLERBIT & type) ) { - const UniformInfo* info = s_renderD3D12->m_uniformReg.find(name); + const UniformRegInfo* info = s_renderD3D12->m_uniformReg.find(name); BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); if (NULL != info) diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 1b26f9a91..78a167d3e 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -2427,7 +2427,7 @@ namespace bgfx { namespace d3d9 } else if (0 == (BGFX_UNIFORM_SAMPLERBIT & type) ) { - const UniformInfo* info = s_renderD3D9->m_uniformReg.find(name); + const UniformRegInfo* info = s_renderD3D9->m_uniformReg.find(name); BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); if (NULL != info) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 73122fe74..25e5141a0 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -4161,7 +4161,7 @@ namespace bgfx { namespace gl } else { - const UniformInfo* info = s_renderGL->m_uniformReg.find(name); + const UniformRegInfo* info = s_renderGL->m_uniformReg.find(name); BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); if (NULL != info) diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 027c65e68..e69fc596a 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -2285,7 +2285,7 @@ namespace bgfx { namespace mtl } else { - const UniformInfo* info = s_renderMtl->m_uniformReg.find(name); + const UniformRegInfo* info = s_renderMtl->m_uniformReg.find(name); BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); if (NULL != info)