diff options
Diffstat (limited to '3rdparty/bgfx/src/bgfx.cpp')
-rw-r--r-- | 3rdparty/bgfx/src/bgfx.cpp | 154 |
1 files changed, 112 insertions, 42 deletions
diff --git a/3rdparty/bgfx/src/bgfx.cpp b/3rdparty/bgfx/src/bgfx.cpp index c24d07ccec2..34d56ddbc65 100644 --- a/3rdparty/bgfx/src/bgfx.cpp +++ b/3rdparty/bgfx/src/bgfx.cpp @@ -9,7 +9,7 @@ namespace bgfx { #define BGFX_MAIN_THREAD_MAGIC UINT32_C(0x78666762) -#if BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS +#if BGFX_CONFIG_MULTITHREADED # define BGFX_CHECK_MAIN_THREAD() \ BX_CHECK(NULL != s_ctx, "Library is not initialized yet."); \ BX_CHECK(BGFX_MAIN_THREAD_MAGIC == s_threadIndex, "Must be called from main thread.") @@ -17,7 +17,7 @@ namespace bgfx #else # define BGFX_CHECK_MAIN_THREAD() # define BGFX_CHECK_RENDER_THREAD() -#endif // BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS +#endif // BGFX_CONFIG_MULTITHREADED #if BGFX_CONFIG_USE_TINYSTL void* TinyStlAllocator::static_allocate(size_t _bytes) @@ -42,8 +42,18 @@ namespace bgfx virtual void traceVargs(const char* _filePath, uint16_t _line, const char* _format, va_list _argList) BX_OVERRIDE { - dbgPrintf("%s (%d): ", _filePath, _line); - dbgPrintfVargs(_format, _argList); + char temp[2048]; + char* out = temp; + int32_t len = bx::snprintf(out, sizeof(temp), "%s (%d): ", _filePath, _line); + int32_t total = len + bx::vsnprintf(out + len, sizeof(temp)-len, _format, _argList); + if ( (int32_t)sizeof(temp) < total) + { + out = (char*)alloca(total+1); + memcpy(out, temp, len); + bx::vsnprintf(out + len, total-len, _format, _argList); + } + out[total] = '\0'; + bx::debugOutput(out); } virtual void fatal(Fatal::Enum _code, const char* _str) BX_OVERRIDE @@ -200,7 +210,52 @@ namespace bgfx Caps g_caps; - static BX_THREAD uint32_t s_threadIndex = 0; +#if BGFX_CONFIG_MULTITHREADED && !defined(BX_THREAD_LOCAL) + class ThreadData + { + BX_CLASS(ThreadData + , NO_COPY + , NO_ASSIGNMENT + ); + + public: + ThreadData(uintptr_t _rhs) + { + union { uintptr_t ui; void* ptr; } cast = { _rhs }; + m_tls.set(cast.ptr); + } + + operator uintptr_t() const + { + union { uintptr_t ui; void* ptr; } cast; + cast.ptr = m_tls.get(); + return cast.ui; + } + + uintptr_t operator=(uintptr_t _rhs) + { + union { uintptr_t ui; void* ptr; } cast = { _rhs }; + m_tls.set(cast.ptr); + return _rhs; + } + + bool operator==(uintptr_t _rhs) const + { + uintptr_t lhs = *this; + return lhs == _rhs; + } + + private: + bx::TlsData m_tls; + }; + + static ThreadData s_threadIndex(0); +#elif !BGFX_CONFIG_MULTITHREADED + static uint32_t s_threadIndex(0); +#else + static BX_THREAD_LOCAL uint32_t s_threadIndex(0); +#endif + static Context* s_ctx = NULL; static bool s_renderFrameCalled = false; PlatformData g_platformData; @@ -722,7 +777,7 @@ namespace bgfx return m_num; } - m_constEnd = m_constantBuffer->getPos(); + m_uniformEnd = m_uniformBuffer->getPos(); m_key.m_program = invalidHandle == _handle.idx ? 0 @@ -739,14 +794,14 @@ namespace bgfx m_sortValues[m_num] = m_numRenderItems; ++m_num; - m_draw.m_constBegin = m_constBegin; - m_draw.m_constEnd = m_constEnd; + m_draw.m_constBegin = m_uniformBegin; + m_draw.m_constEnd = m_uniformEnd; m_draw.m_flags |= m_flags; m_renderItem[m_numRenderItems].draw = m_draw; ++m_numRenderItems; m_draw.clear(); - m_constBegin = m_constEnd; + m_uniformBegin = m_uniformEnd; m_flags = BGFX_STATE_NONE; return m_num; @@ -766,7 +821,7 @@ namespace bgfx return m_num; } - m_constEnd = m_constantBuffer->getPos(); + m_uniformEnd = m_uniformBuffer->getPos(); m_compute.m_matrix = m_draw.m_matrix; m_compute.m_num = m_draw.m_num; @@ -786,13 +841,13 @@ namespace bgfx m_sortValues[m_num] = m_numRenderItems; ++m_num; - m_compute.m_constBegin = m_constBegin; - m_compute.m_constEnd = m_constEnd; + m_compute.m_constBegin = m_uniformBegin; + m_compute.m_constEnd = m_uniformEnd; m_renderItem[m_numRenderItems].compute = m_compute; ++m_numRenderItems; m_compute.clear(); - m_constBegin = m_constEnd; + m_uniformBegin = m_uniformEnd; return m_num; } @@ -844,21 +899,21 @@ namespace bgfx 1, }; - void ConstantBuffer::writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num) + void UniformBuffer::writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num) { uint32_t opcode = encodeOpcode(_type, _loc, _num, true); write(opcode); write(_value, g_uniformTypeSize[_type]*_num); } - void ConstantBuffer::writeUniformHandle(UniformType::Enum _type, uint16_t _loc, UniformHandle _handle, uint16_t _num) + void UniformBuffer::writeUniformHandle(UniformType::Enum _type, uint16_t _loc, UniformHandle _handle, uint16_t _num) { uint32_t opcode = encodeOpcode(_type, _loc, _num, false); write(opcode); write(&_handle, sizeof(UniformHandle) ); } - void ConstantBuffer::writeMarker(const char* _marker) + void UniformBuffer::writeMarker(const char* _marker) { uint16_t num = (uint16_t)strlen(_marker)+1; uint32_t opcode = encodeOpcode(bgfx::UniformType::Count, 0, num, true); @@ -977,7 +1032,6 @@ namespace bgfx // should not be created. BX_TRACE("Application called bgfx::renderFrame directly, not creating render thread."); m_singleThreaded = true - && !BX_ENABLED(BX_PLATFORM_OSX || BX_PLATFORM_IOS) && ~BGFX_MAIN_THREAD_MAGIC == s_threadIndex ; } @@ -1243,10 +1297,10 @@ namespace bgfx memcpy(m_submit->m_view, m_view, sizeof(m_view) ); memcpy(m_submit->m_proj, m_proj, sizeof(m_proj) ); memcpy(m_submit->m_viewFlags, m_viewFlags, sizeof(m_viewFlags) ); - if (m_clearColorDirty > 0) + if (m_colorPaletteDirty > 0) { - --m_clearColorDirty; - memcpy(m_submit->m_clearColor, m_clearColor, sizeof(m_clearColor) ); + --m_colorPaletteDirty; + memcpy(m_submit->m_colorPalette, m_clearColor, sizeof(m_clearColor) ); } m_submit->finish(); @@ -1271,6 +1325,19 @@ namespace bgfx ); } + const char* Context::getName(UniformHandle _handle) const + { + for (UniformHashMap::const_iterator it = m_uniformHashMap.begin(), itEnd = m_uniformHashMap.end(); it != itEnd; ++it) + { + if (it->second.idx == _handle.idx) + { + return it->first.c_str(); + } + } + + return NULL; + } + bool Context::renderFrame() { if (m_rendererInitialized @@ -1299,12 +1366,12 @@ namespace bgfx return m_exit; } - void rendererUpdateUniforms(RendererContextI* _renderCtx, ConstantBuffer* _constantBuffer, uint32_t _begin, uint32_t _end) + void rendererUpdateUniforms(RendererContextI* _renderCtx, UniformBuffer* _uniformBuffer, uint32_t _begin, uint32_t _end) { - _constantBuffer->reset(_begin); - while (_constantBuffer->getPos() < _end) + _uniformBuffer->reset(_begin); + while (_uniformBuffer->getPos() < _end) { - uint32_t opcode = _constantBuffer->read(); + uint32_t opcode = _uniformBuffer->read(); if (UniformType::End == opcode) { @@ -1315,10 +1382,10 @@ namespace bgfx uint16_t loc; uint16_t num; uint16_t copy; - ConstantBuffer::decodeOpcode(opcode, type, loc, num, copy); + UniformBuffer::decodeOpcode(opcode, type, loc, num, copy); uint32_t size = g_uniformTypeSize[type]*num; - const char* data = _constantBuffer->read(size); + const char* data = _uniformBuffer->read(size); if (UniformType::Count > type) { if (copy) @@ -1496,11 +1563,7 @@ again: if (windowsVersionIs(Condition::GreaterEqual, 0x0602) ) { -#if defined(__MINGW32__) - first = RendererType::Direct3D11; -#else first = RendererType::Direct3D12; -#endif // __MINGW32__ second = RendererType::Direct3D11; if (!s_rendererCreator[second].supported) { @@ -1568,6 +1631,13 @@ again: } else { +#if 0 + if (s_rendererCreator[RendererType::Metal].supported) + { + _type = RendererType::Metal; + } + else +#endif // 0 if (s_rendererCreator[RendererType::OpenGL].supported) { _type = RendererType::OpenGL; @@ -2635,8 +2705,8 @@ again: if (BackbufferRatio::Count != _ratio) { - _width = uint16_t(s_ctx->m_frame->m_resolution.m_width); - _height = uint16_t(s_ctx->m_frame->m_resolution.m_height); + _width = uint16_t(s_ctx->m_resolution.m_width); + _height = uint16_t(s_ctx->m_resolution.m_height); getTextureSizeFromRatio(_ratio, _width, _height); } @@ -2852,7 +2922,7 @@ again: s_ctx->destroyUniform(_handle); } - void setClearColor(uint8_t _index, uint32_t _rgba) + void setPaletteColor(uint8_t _index, uint32_t _rgba) { BGFX_CHECK_MAIN_THREAD(); @@ -2868,20 +2938,20 @@ again: bb * 1.0f/255.0f, aa * 1.0f/255.0f, }; - s_ctx->setClearColor(_index, rgba); + s_ctx->setPaletteColor(_index, rgba); } - void setClearColor(uint8_t _index, float _r, float _g, float _b, float _a) + void setPaletteColor(uint8_t _index, float _r, float _g, float _b, float _a) { BGFX_CHECK_MAIN_THREAD(); float rgba[4] = { _r, _g, _b, _a }; - s_ctx->setClearColor(_index, rgba); + s_ctx->setPaletteColor(_index, rgba); } - void setClearColor(uint8_t _index, const float _rgba[4]) + void setPaletteColor(uint8_t _index, const float _rgba[4]) { BGFX_CHECK_MAIN_THREAD(); - s_ctx->setClearColor(_index, _rgba); + s_ctx->setPaletteColor(_index, _rgba); } bool checkView(uint8_t _id) @@ -3178,8 +3248,8 @@ again: } } // namespace bgfx -#include <bgfx.c99.h> -#include <bgfxplatform.c99.h> +#include <bgfx/c99/bgfx.h> +#include <bgfx/c99/bgfxplatform.h> 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) ); @@ -3742,9 +3812,9 @@ BGFX_C_API void bgfx_destroy_uniform(bgfx_uniform_handle_t _handle) bgfx::destroyUniform(handle.cpp); } -BGFX_C_API void bgfx_set_clear_color(uint8_t _index, const float _rgba[4]) +BGFX_C_API void bgfx_set_palette_color(uint8_t _index, const float _rgba[4]) { - bgfx::setClearColor(_index, _rgba); + bgfx::setPaletteColor(_index, _rgba); } BGFX_C_API void bgfx_set_view_name(uint8_t _id, const char* _name) |