From 07aae82d16d742efd36f4023f30ec2d77c390bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 22 Dec 2016 16:18:44 -0800 Subject: [PATCH] Replaced checkAvail* with getAvail* API. --- examples/07-callback/callback.cpp | 2 +- examples/09-hdr/hdr.cpp | 2 +- examples/16-shadowmaps/shadowmaps.cpp | 4 +- examples/18-ibl/ibl.cpp | 2 +- examples/19-oit/oit.cpp | 2 +- examples/21-deferred/deferred.cpp | 2 +- examples/23-vectordisplay/vectordisplay.cpp | 2 +- examples/31-rsm/reflectiveshadowmap.cpp | 2 +- examples/common/bgfx_utils.h | 14 ++++++ examples/common/debugdraw/debugdraw.cpp | 5 ++- examples/common/imgui/imgui.cpp | 9 ++-- examples/common/imgui/ocornut_imgui.cpp | 4 +- include/bgfx/bgfx.h | 35 +++++---------- include/bgfx/c99/bgfx.h | 9 ++-- include/bgfx/c99/platform.h | 7 ++- include/bgfx/defines.h | 2 +- src/bgfx.cpp | 48 ++++++++------------- src/bgfx_p.h | 34 ++++++++------- tools/texturev/texturev.cpp | 2 +- 19 files changed, 86 insertions(+), 101 deletions(-) diff --git a/examples/07-callback/callback.cpp b/examples/07-callback/callback.cpp index 770131900..38e82a150 100644 --- a/examples/07-callback/callback.cpp +++ b/examples/07-callback/callback.cpp @@ -148,7 +148,7 @@ struct BgfxCallback : public bgfx::CallbackI bx::Error err; if (bx::open(reader, filePath, &err) ) { - uint32_t size = bx::getSize(reader); + uint32_t size = (uint32_t)bx::getSize(reader); bx::close(reader); // Return size of shader file. return size; diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 8ce68adc3..fd45d01eb 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -36,7 +36,7 @@ bgfx::VertexDecl PosColorTexCoord0Vertex::ms_decl; void screenSpaceQuad(float _textureWidth, float _textureHeight, bool _originBottomLeft = false, float _width = 1.0f, float _height = 1.0f) { - if (bgfx::checkAvailTransientVertexBuffer(3, PosColorTexCoord0Vertex::ms_decl) ) + if (3 == bgfx::getAvailTransientVertexBuffer(3, PosColorTexCoord0Vertex::ms_decl) ) { bgfx::TransientVertexBuffer vb; bgfx::allocTransientVertexBuffer(&vb, 3, PosColorTexCoord0Vertex::ms_decl); diff --git a/examples/16-shadowmaps/shadowmaps.cpp b/examples/16-shadowmaps/shadowmaps.cpp index 18524f901..d1890fa2b 100644 --- a/examples/16-shadowmaps/shadowmaps.cpp +++ b/examples/16-shadowmaps/shadowmaps.cpp @@ -1057,7 +1057,7 @@ bgfx::VertexDecl PosColorTexCoord0Vertex::ms_decl; void screenSpaceQuad(float _textureWidth, float _textureHeight, bool _originBottomLeft = true, float _width = 1.0f, float _height = 1.0f) { - if (bgfx::checkAvailTransientVertexBuffer(3, PosColorTexCoord0Vertex::ms_decl) ) + if (3 == bgfx::getAvailTransientVertexBuffer(3, PosColorTexCoord0Vertex::ms_decl) ) { bgfx::TransientVertexBuffer vb; bgfx::allocTransientVertexBuffer(&vb, 3, PosColorTexCoord0Vertex::ms_decl); @@ -2691,7 +2691,7 @@ int _main_(int _argc, char** _argv) // Craft stencil mask for point light shadow map packing. if(LightType::PointLight == settings.m_lightType && settings.m_stencilPack) { - if (bgfx::checkAvailTransientVertexBuffer(6, posDecl) ) + if (6 == bgfx::getAvailTransientVertexBuffer(6, posDecl) ) { struct Pos { diff --git a/examples/18-ibl/ibl.cpp b/examples/18-ibl/ibl.cpp index 39d814514..9827dbafe 100644 --- a/examples/18-ibl/ibl.cpp +++ b/examples/18-ibl/ibl.cpp @@ -89,7 +89,7 @@ bgfx::VertexDecl PosColorTexCoord0Vertex::ms_decl; void screenSpaceQuad(float _textureWidth, float _textureHeight, bool _originBottomLeft = false, float _width = 1.0f, float _height = 1.0f) { - if (bgfx::checkAvailTransientVertexBuffer(3, PosColorTexCoord0Vertex::ms_decl) ) + if (3 == bgfx::getAvailTransientVertexBuffer(3, PosColorTexCoord0Vertex::ms_decl) ) { bgfx::TransientVertexBuffer vb; bgfx::allocTransientVertexBuffer(&vb, 3, PosColorTexCoord0Vertex::ms_decl); diff --git a/examples/19-oit/oit.cpp b/examples/19-oit/oit.cpp index 966f436eb..4a2132ec8 100644 --- a/examples/19-oit/oit.cpp +++ b/examples/19-oit/oit.cpp @@ -90,7 +90,7 @@ inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, flo void screenSpaceQuad(float _textureWidth, float _textureHeight, bool _originBottomLeft = false, float _width = 1.0f, float _height = 1.0f) { - if (bgfx::checkAvailTransientVertexBuffer(3, PosColorTexCoord0Vertex::ms_decl) ) + if (3 == bgfx::getAvailTransientVertexBuffer(3, PosColorTexCoord0Vertex::ms_decl) ) { bgfx::TransientVertexBuffer vb; bgfx::allocTransientVertexBuffer(&vb, 3, PosColorTexCoord0Vertex::ms_decl); diff --git a/examples/21-deferred/deferred.cpp b/examples/21-deferred/deferred.cpp index 2a195c757..44badac56 100644 --- a/examples/21-deferred/deferred.cpp +++ b/examples/21-deferred/deferred.cpp @@ -159,7 +159,7 @@ static const uint16_t s_cubeIndices[36] = void screenSpaceQuad(float _textureWidth, float _textureHeight, float _texelHalf, bool _originBottomLeft, float _width = 1.0f, float _height = 1.0f) { - if (bgfx::checkAvailTransientVertexBuffer(3, PosTexCoord0Vertex::ms_decl) ) + if (3 == bgfx::getAvailTransientVertexBuffer(3, PosTexCoord0Vertex::ms_decl) ) { bgfx::TransientVertexBuffer vb; bgfx::allocTransientVertexBuffer(&vb, 3, PosTexCoord0Vertex::ms_decl); diff --git a/examples/23-vectordisplay/vectordisplay.cpp b/examples/23-vectordisplay/vectordisplay.cpp index ed9866e38..0777343bd 100644 --- a/examples/23-vectordisplay/vectordisplay.cpp +++ b/examples/23-vectordisplay/vectordisplay.cpp @@ -741,7 +741,7 @@ void VectorDisplay::getSize(float* _outWidth, float* _outHeight) void VectorDisplay::screenSpaceQuad(float _textureWidth, float _textureHeight, float _width, float _height) { - if (bgfx::checkAvailTransientVertexBuffer(3, PosColorUvVertex::ms_decl) ) + if (3 == getAvailTransientVertexBuffer(3, PosColorUvVertex::ms_decl) ) { bgfx::TransientVertexBuffer vb; bgfx::allocTransientVertexBuffer(&vb, 3, PosColorUvVertex::ms_decl); diff --git a/examples/31-rsm/reflectiveshadowmap.cpp b/examples/31-rsm/reflectiveshadowmap.cpp index e18ce02bb..0ceb3d400 100644 --- a/examples/31-rsm/reflectiveshadowmap.cpp +++ b/examples/31-rsm/reflectiveshadowmap.cpp @@ -127,7 +127,7 @@ bgfx::VertexDecl PosTexCoord0Vertex::ms_decl; // Utility function to draw a screen space quad for deferred rendering void screenSpaceQuad(float _textureWidth, float _textureHeight, float _texelHalf, bool _originBottomLeft, float _width = 1.0f, float _height = 1.0f) { - if (bgfx::checkAvailTransientVertexBuffer(3, PosTexCoord0Vertex::ms_decl) ) + if (3 == bgfx::getAvailTransientVertexBuffer(3, PosTexCoord0Vertex::ms_decl) ) { bgfx::TransientVertexBuffer vb; bgfx::allocTransientVertexBuffer(&vb, 3, PosTexCoord0Vertex::ms_decl); diff --git a/examples/common/bgfx_utils.h b/examples/common/bgfx_utils.h index f9037da53..a5124dd49 100644 --- a/examples/common/bgfx_utils.h +++ b/examples/common/bgfx_utils.h @@ -15,6 +15,20 @@ bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName); bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags = BGFX_TEXTURE_NONE, uint8_t _skip = 0, bgfx::TextureInfo* _info = NULL); void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices); +/// Returns true if both internal transient index and vertex buffer have +/// enough space. +/// +/// @param[in] _numVertices Number of vertices. +/// @param[in] _decl Vertex declaration. +/// @param[in] _numIndices Number of indices. +/// +inline bool checkAvailTransientBuffers(uint32_t _numVertices, const bgfx::VertexDecl& _decl, uint32_t _numIndices) +{ + return _numVertices == bgfx::getAvailTransientVertexBuffer(_numVertices, _decl) + && _numIndices == bgfx::getAvailTransientIndexBuffer(_numIndices) + ; +} + struct MeshState { struct Texture diff --git a/examples/common/debugdraw/debugdraw.cpp b/examples/common/debugdraw/debugdraw.cpp index 0229cdd4c..a8889537d 100644 --- a/examples/common/debugdraw/debugdraw.cpp +++ b/examples/common/debugdraw/debugdraw.cpp @@ -6,6 +6,7 @@ #include #include #include "debugdraw.h" +#include "../bgfx_utils.h" #include "../packrect.h" #include @@ -1838,7 +1839,7 @@ private: { if (0 != m_pos) { - if (bgfx::checkAvailTransientBuffers(m_pos, DebugVertex::ms_decl, m_indexPos) ) + if (checkAvailTransientBuffers(m_pos, DebugVertex::ms_decl, m_indexPos) ) { bgfx::TransientVertexBuffer tvb; bgfx::allocTransientVertexBuffer(&tvb, m_pos, DebugVertex::ms_decl); @@ -1876,7 +1877,7 @@ private: if (0 != m_posQuad) { const uint32_t numIndices = m_posQuad/4*6; - if (bgfx::checkAvailTransientBuffers(m_posQuad, DebugUvVertex::ms_decl, numIndices) ) + if (checkAvailTransientBuffers(m_posQuad, DebugUvVertex::ms_decl, numIndices) ) { bgfx::TransientVertexBuffer tvb; bgfx::allocTransientVertexBuffer(&tvb, m_posQuad, DebugUvVertex::ms_decl); diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 04935e54a..05c25d127 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -32,6 +32,7 @@ #include "imgui.h" #include "ocornut_imgui.h" +#include "../bgfx_utils.h" #include "../nanovg/nanovg.h" #include @@ -1800,7 +1801,7 @@ struct Imgui const uint32_t numVertices = 14; const uint32_t numIndices = 36; - if (bgfx::checkAvailTransientBuffers(numVertices, PosNormalVertex::ms_decl, numIndices) ) + if (checkAvailTransientBuffers(numVertices, PosNormalVertex::ms_decl, numIndices) ) { bgfx::TransientVertexBuffer tvb; bgfx::allocTransientVertexBuffer(&tvb, numVertices, PosNormalVertex::ms_decl); @@ -2335,7 +2336,7 @@ struct Imgui } uint32_t numVertices = _numCoords*6 + (_numCoords-2)*3; - if (bgfx::checkAvailTransientVertexBuffer(numVertices, PosColorVertex::ms_decl) ) + if (numVertices == bgfx::getAvailTransientVertexBuffer(numVertices, PosColorVertex::ms_decl) ) { bgfx::TransientVertexBuffer tvb; bgfx::allocTransientVertexBuffer(&tvb, numVertices, PosColorVertex::ms_decl); @@ -2622,7 +2623,7 @@ struct Imgui getTextLength(m_fonts[m_currentFontIdx].m_cdata, _text, numVertices); } - if (bgfx::checkAvailTransientVertexBuffer(numVertices, PosColorUvVertex::ms_decl) ) + if (numVertices == bgfx::getAvailTransientVertexBuffer(numVertices, PosColorUvVertex::ms_decl) ) { bgfx::TransientVertexBuffer tvb; bgfx::allocTransientVertexBuffer(&tvb, numVertices, PosColorUvVertex::ms_decl); @@ -2712,7 +2713,7 @@ struct Imgui bool screenQuad(int32_t _x, int32_t _y, int32_t _width, uint32_t _height, bool _originBottomLeft = false) { - if (bgfx::checkAvailTransientVertexBuffer(6, PosUvVertex::ms_decl) ) + if (6 == bgfx::getAvailTransientVertexBuffer(6, PosUvVertex::ms_decl) ) { bgfx::TransientVertexBuffer vb; bgfx::allocTransientVertexBuffer(&vb, 6, PosUvVertex::ms_decl); diff --git a/examples/common/imgui/ocornut_imgui.cpp b/examples/common/imgui/ocornut_imgui.cpp index d15f96f61..315ee0c9b 100644 --- a/examples/common/imgui/ocornut_imgui.cpp +++ b/examples/common/imgui/ocornut_imgui.cpp @@ -11,6 +11,7 @@ #include #include "imgui.h" #include "ocornut_imgui.h" +#include "../bgfx_utils.h" #ifndef USE_ENTRY # if defined(SCI_NAMESPACE) @@ -86,8 +87,7 @@ struct OcornutImguiContext uint32_t numVertices = (uint32_t)drawList->VtxBuffer.size(); uint32_t numIndices = (uint32_t)drawList->IdxBuffer.size(); - if (!bgfx::checkAvailTransientVertexBuffer(numVertices, m_decl) - || !bgfx::checkAvailTransientIndexBuffer(numIndices) ) + if (!checkAvailTransientBuffers(numVertices, m_decl, numIndices) ) { // not enough space in transient buffer just quit drawing the rest... break; diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index cc5d024f9..74237cef7 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -1391,46 +1391,31 @@ namespace bgfx /// void destroyDynamicVertexBuffer(DynamicVertexBufferHandle _handle); - /// Returns true if internal transient index buffer has enough space. + /// Returns number of available indices. /// - /// @param[in] _num Number of indices. + /// @param[in] _num Number of required indices. /// - /// @attention C99 equivalent is `bgfx_check_avail_transient_index_buffer`. + /// @attention C99 equivalent is `bgfx_get_avail_transient_index_buffer`. /// - bool checkAvailTransientIndexBuffer(uint32_t _num); + uint32_t getAvailTransientIndexBuffer(uint32_t _num); - /// Returns true if internal transient vertex buffer has enough space. + /// Returns number of available vertices. /// - /// @param[in] _num Number of vertices. + /// @param[in] _num Number of required vertices. /// @param[in] _decl Vertex declaration. /// /// @attention C99 equivalent is `bgfx_check_avail_transient_vertex_buffer`. /// - bool checkAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl); + uint32_t getAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl); - /// Returns true if internal instance data buffer has enough space. + /// Returns number of available instance buffer slots. /// - /// @param[in] _num Number of instances. + /// @param[in] _num Number of required instances. /// @param[in] _stride Stride per instance. /// /// @attention C99 equivalent is `bgfx_check_avail_instance_data_buffer`. /// - bool checkAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride); - - /// Returns true if both internal transient index and vertex buffer have - /// enough space. - /// - /// @param[in] _numVertices Number of vertices. - /// @param[in] _decl Vertex declaration. - /// @param[in] _numIndices Number of indices. - /// - /// @attention C99 equivalent is `bgfx_check_avail_transient_buffers`. - /// - bool checkAvailTransientBuffers( - uint32_t _numVertices - , const VertexDecl& _decl - , uint32_t _numIndices - ); + uint32_t getAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride); /// Allocate transient index buffer. /// diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 605c2bc8a..98c24eaca 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -648,16 +648,13 @@ BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_han BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle); /**/ -BGFX_C_API bool bgfx_check_avail_transient_index_buffer(uint32_t _num); +BGFX_C_API uint32_t bgfx_get_avail_transient_index_buffer(uint32_t _num); /**/ -BGFX_C_API bool bgfx_check_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl); +BGFX_C_API uint32_t bgfx_get_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl); /**/ -BGFX_C_API bool bgfx_check_avail_instance_data_buffer(uint32_t _num, uint16_t _stride); - -/**/ -BGFX_C_API bool bgfx_check_avail_transient_buffers(uint32_t _numVertices, const bgfx_vertex_decl_t* _decl, uint32_t _numIndices); +BGFX_C_API uint32_t bgfx_get_avail_instance_data_buffer(uint32_t _num, uint16_t _stride); /**/ BGFX_C_API void bgfx_alloc_transient_index_buffer(bgfx_transient_index_buffer_t* _tib, uint32_t _num); diff --git a/include/bgfx/c99/platform.h b/include/bgfx/c99/platform.h index a56473658..83e6b6c19 100644 --- a/include/bgfx/c99/platform.h +++ b/include/bgfx/c99/platform.h @@ -113,10 +113,9 @@ typedef struct bgfx_interface_vtbl 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); + uint32_t (*get_avail_transient_index_buffer)(uint32_t _num); + uint32_t (*get_avail_transient_vertex_buffer)(uint32_t _num, const bgfx_vertex_decl_t* _decl); + uint32_t (*get_avail_instance_data_buffer)(uint32_t _num, uint16_t _stride); 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); diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index 89d05781b..9c3d0ef1e 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(33) +#define BGFX_API_VERSION UINT32_C(34) /// #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write. diff --git a/src/bgfx.cpp b/src/bgfx.cpp index cda4f16e5..9c0d60eb2 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2862,34 +2862,26 @@ error: s_ctx->destroyDynamicVertexBuffer(_handle); } - bool checkAvailTransientIndexBuffer(uint32_t _num) + uint32_t getAvailTransientIndexBuffer(uint32_t _num) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(0 < _num, "Requesting 0 indices."); - return s_ctx->checkAvailTransientIndexBuffer(_num); + return s_ctx->getAvailTransientIndexBuffer(_num); } - bool checkAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl) + uint32_t getAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(0 < _num, "Requesting 0 vertices."); BX_CHECK(0 != _decl.m_stride, "Invalid VertexDecl."); - return s_ctx->checkAvailTransientVertexBuffer(_num, _decl.m_stride); + return s_ctx->getAvailTransientVertexBuffer(_num, _decl.m_stride); } - bool checkAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride) + uint32_t getAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(0 < _num, "Requesting 0 instances."); - return s_ctx->checkAvailTransientVertexBuffer(_num, _stride); - } - - bool checkAvailTransientBuffers(uint32_t _numVertices, const VertexDecl& _decl, uint32_t _numIndices) - { - BX_CHECK(0 != _decl.m_stride, "Invalid VertexDecl."); - return checkAvailTransientVertexBuffer(_numVertices, _decl) - && checkAvailTransientIndexBuffer(_numIndices) - ; + return s_ctx->getAvailTransientVertexBuffer(_num, _stride); } void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num) @@ -2920,7 +2912,8 @@ error: bool allocTransientBuffers(bgfx::TransientVertexBuffer* _tvb, const bgfx::VertexDecl& _decl, uint32_t _numVertices, bgfx::TransientIndexBuffer* _tib, uint32_t _numIndices) { - if (checkAvailTransientBuffers(_numVertices, _decl, _numIndices) ) + if (_numVertices == getAvailTransientVertexBuffer(_numVertices, _decl) + && _numIndices == getAvailTransientIndexBuffer(_numIndices) ) { allocTransientVertexBuffer(_tvb, _numVertices, _decl); allocTransientIndexBuffer(_tib, _numIndices); @@ -4274,26 +4267,20 @@ BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_ha bgfx::destroyDynamicVertexBuffer(handle.cpp); } -BGFX_C_API bool bgfx_check_avail_transient_index_buffer(uint32_t _num) +BGFX_C_API uint32_t bgfx_get_avail_transient_index_buffer(uint32_t _num) { - return bgfx::checkAvailTransientIndexBuffer(_num); + return bgfx::getAvailTransientIndexBuffer(_num); } -BGFX_C_API bool bgfx_check_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl) +BGFX_C_API uint32_t bgfx_get_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl) { const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; - return bgfx::checkAvailTransientVertexBuffer(_num, decl); + return bgfx::getAvailTransientVertexBuffer(_num, decl); } -BGFX_C_API bool bgfx_check_avail_instance_data_buffer(uint32_t _num, uint16_t _stride) +BGFX_C_API uint32_t bgfx_get_avail_instance_data_buffer(uint32_t _num, uint16_t _stride) { - return bgfx::checkAvailInstanceDataBuffer(_num, _stride); -} - -BGFX_C_API bool bgfx_check_avail_transient_buffers(uint32_t _numVertices, const bgfx_vertex_decl_t* _decl, uint32_t _numIndices) -{ - const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; - return bgfx::checkAvailTransientBuffers(_numVertices, decl, _numIndices); + return bgfx::getAvailInstanceDataBuffer(_num, _stride); } BGFX_C_API void bgfx_alloc_transient_index_buffer(bgfx_transient_index_buffer_t* _tib, uint32_t _num) @@ -4886,10 +4873,9 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) 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(check_avail_transient_index_buffer) \ - BGFX_IMPORT_FUNC(check_avail_transient_vertex_buffer) \ - BGFX_IMPORT_FUNC(check_avail_instance_data_buffer) \ - BGFX_IMPORT_FUNC(check_avail_transient_buffers) \ + 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) \ diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 2c6d38ebf..abc884095 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1701,39 +1701,41 @@ namespace bgfx void sort(); - bool checkAvailTransientIndexBuffer(uint32_t _num) + uint32_t getAvailTransientIndexBuffer(uint32_t _num) { - uint32_t offset = m_iboffset; + uint32_t offset = bx::strideAlign(m_iboffset, sizeof(uint16_t) ); uint32_t iboffset = offset + _num*sizeof(uint16_t); iboffset = bx::uint32_min(iboffset, BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); uint32_t num = (iboffset-offset)/sizeof(uint16_t); - return num == _num; + return num; } uint32_t allocTransientIndexBuffer(uint32_t& _num) { uint32_t offset = bx::strideAlign(m_iboffset, sizeof(uint16_t) ); - m_iboffset = offset + _num*sizeof(uint16_t); - m_iboffset = bx::uint32_min(m_iboffset, BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); - _num = (m_iboffset-offset)/sizeof(uint16_t); + uint32_t num = getAvailTransientIndexBuffer(_num); + m_iboffset = offset + num*sizeof(uint16_t); + _num = num; + return offset; } - bool checkAvailTransientVertexBuffer(uint32_t _num, uint16_t _stride) + uint32_t getAvailTransientVertexBuffer(uint32_t _num, uint16_t _stride) { - uint32_t offset = bx::strideAlign(m_vboffset, _stride); + uint32_t offset = bx::strideAlign(m_vboffset, _stride); uint32_t vboffset = offset + _num * _stride; vboffset = bx::uint32_min(vboffset, BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE); uint32_t num = (vboffset-offset)/_stride; - return num == _num; + return num; } uint32_t allocTransientVertexBuffer(uint32_t& _num, uint16_t _stride) { uint32_t offset = bx::strideAlign(m_vboffset, _stride); - m_vboffset = offset + _num * _stride; - m_vboffset = bx::uint32_min(m_vboffset, BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE); - _num = (m_vboffset-offset)/_stride; + uint32_t num = getAvailTransientVertexBuffer(_num, _stride); + m_vboffset = offset + num * _stride; + _num = num; + return offset; } @@ -2689,14 +2691,14 @@ namespace bgfx m_dynamicVertexBufferHandle.free(_handle.idx); } - BGFX_API_FUNC(bool checkAvailTransientIndexBuffer(uint32_t _num) const) + BGFX_API_FUNC(uint32_t getAvailTransientIndexBuffer(uint32_t _num) const) { - return m_submit->checkAvailTransientIndexBuffer(_num); + return m_submit->getAvailTransientIndexBuffer(_num); } - BGFX_API_FUNC(bool checkAvailTransientVertexBuffer(uint32_t _num, uint16_t _stride) const) + BGFX_API_FUNC(uint32_t getAvailTransientVertexBuffer(uint32_t _num, uint16_t _stride) const) { - return m_submit->checkAvailTransientVertexBuffer(_num, _stride); + return m_submit->getAvailTransientVertexBuffer(_num, _stride); } TransientIndexBuffer* createTransientIndexBuffer(uint32_t _size) diff --git a/tools/texturev/texturev.cpp b/tools/texturev/texturev.cpp index 6cec3446b..1995aa8bd 100644 --- a/tools/texturev/texturev.cpp +++ b/tools/texturev/texturev.cpp @@ -384,7 +384,7 @@ bgfx::VertexDecl PosUvColorVertex::ms_decl; bool screenQuad(int32_t _x, int32_t _y, int32_t _width, uint32_t _height, uint32_t _abgr, bool _originBottomLeft = false) { - if (bgfx::checkAvailTransientVertexBuffer(6, PosUvColorVertex::ms_decl) ) + if (6 == bgfx::getAvailTransientVertexBuffer(6, PosUvColorVertex::ms_decl) ) { bgfx::TransientVertexBuffer vb; bgfx::allocTransientVertexBuffer(&vb, 6, PosUvColorVertex::ms_decl);