Allow non-zero terminated strings to be used with bgfx::setName API.

This commit is contained in:
Branimir Karadžić 2018-06-20 18:01:06 -07:00
parent 2efe4e1794
commit 8ec1a3a8f4
7 changed files with 28 additions and 20 deletions

View File

@ -2421,12 +2421,15 @@ namespace bgfx
///
/// @param[in] _handle Shader handle.
/// @param[in] _name Shader name.
/// @param[in] _len Shader name length (if length is INT32_MAX, it's expected
/// that _name is zero terminated string.
///
/// @attention C99 equivalent is `bgfx_set_shader_name`.
///
void setName(
ShaderHandle _handle
, const char* _name
, const char* _ptr
, int32_t _len = INT32_MAX
);
/// Destroy shader. Once a shader program is created with _handle,
@ -2781,12 +2784,15 @@ namespace bgfx
///
/// @param[in] _handle Texture handle.
/// @param[in] _name Texture name.
/// @param[in] _len Texture name length (if length is INT32_MAX, it's expected
/// that _name is zero terminated string.
///
/// @attention C99 equivalent is `bgfx_set_texture_name`.
///
void setName(
TextureHandle _handle
, const char* _name
, const char* _ptr
, int32_t _len = INT32_MAX
);
/// Returns texture direct access pointer.

View File

@ -819,7 +819,7 @@ 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_set_shader_name(bgfx_shader_handle_t _handle, const char* _name, int32_t _len);
/**/
BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle);
@ -867,7 +867,7 @@ 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_set_texture_name(bgfx_texture_handle_t _handle, const char* _name, int32_t _len);
/**/
BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle);

View File

@ -124,7 +124,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 (*set_shader_name)(bgfx_shader_handle_t _handle, const char* _name, int32_t _len);
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);
@ -140,7 +140,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 (*set_texture_name)(bgfx_texture_handle_t _handle, const char* _name, int32_t _len);
void* (*get_direct_access_ptr)(bgfx_texture_handle_t _handle);
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);

View File

@ -6,7 +6,7 @@
#ifndef BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_API_VERSION UINT32_C(73)
#define BGFX_API_VERSION UINT32_C(74)
/// Color RGB/alpha/depth write. When it's not specified write will be disabled.
#define BGFX_STATE_WRITE_R UINT64_C(0x0000000000000001) //!< Enable R write.

View File

@ -3590,9 +3590,9 @@ error:
return s_ctx->getShaderUniforms(_handle, _uniforms, _max);
}
void setName(ShaderHandle _handle, const char* _name)
void setName(ShaderHandle _handle, const char* _name, int32_t _len)
{
s_ctx->setName(_handle, _name);
s_ctx->setName(_handle, bx::StringView(_name, _len) );
}
void destroy(ShaderHandle _handle)
@ -3913,9 +3913,9 @@ error:
return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count, NULL != _mem);
}
void setName(TextureHandle _handle, const char* _name)
void setName(TextureHandle _handle, const char* _name, int32_t _len)
{
s_ctx->setName(_handle, _name);
s_ctx->setName(_handle, bx::StringView(_name, _len) );
}
void* getDirectAccessPtr(TextureHandle _handle)
@ -5068,10 +5068,10 @@ 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)
BGFX_C_API void bgfx_set_shader_name(bgfx_shader_handle_t _handle, const char* _name, int32_t _len)
{
union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle = { _handle };
bgfx::setName(handle.cpp, _name);
bgfx::setName(handle.cpp, _name, _len);
}
BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle)
@ -5174,10 +5174,10 @@ 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)
BGFX_C_API void bgfx_set_texture_name(bgfx_texture_handle_t _handle, const char* _name, int32_t _len)
{
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
bgfx::setName(handle.cpp, _name);
bgfx::setName(handle.cpp, _name, _len);
}
BGFX_C_API void* bgfx_get_direct_access_ptr(bgfx_texture_handle_t _handle)

View File

@ -3651,16 +3651,17 @@ namespace bgfx
return sr.m_num;
}
void setName(Handle _handle, const char* _name)
void setName(Handle _handle, const bx::StringView& _name)
{
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::SetName);
cmdbuf.write(_handle);
uint16_t len = (uint8_t)bx::strLen(_name)+1;
uint16_t len = uint16_t(_name.getLength()+1);
cmdbuf.write(len);
cmdbuf.write(_name, len);
cmdbuf.write(_name.getPtr(), len-1);
cmdbuf.write('\0');
}
BGFX_API_FUNC(void setName(ShaderHandle _handle, const char* _name) )
BGFX_API_FUNC(void setName(ShaderHandle _handle, const bx::StringView& _name) )
{
BGFX_MUTEX_SCOPE(m_resourceApiLock);
@ -3937,7 +3938,7 @@ namespace bgfx
return handle;
}
BGFX_API_FUNC(void setName(TextureHandle _handle, const char* _name) )
BGFX_API_FUNC(void setName(TextureHandle _handle, const bx::StringView& _name) )
{
BGFX_MUTEX_SCOPE(m_resourceApiLock);
BGFX_CHECK_HANDLE("setName", m_textureHandle, _handle);

View File

@ -777,6 +777,7 @@ namespace bgfx { namespace d3d12
debug0->SetProcessDebugFlags(D3D12XBOX_PROCESS_DEBUG_FLAGS(debugFlags) );
}
#endif // BX_PLATFORM_XBOXONE
BX_UNUSED(debugFlags);
DX_RELEASE(debug0, 0);
}