diff --git a/src/bgfx.cpp b/src/bgfx.cpp index f0332bc20..e401e1c9e 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -181,12 +181,7 @@ namespace bgfx return bx::alignedRealloc(this, _ptr, _size, _align, _file, _line); } - void checkLeaks() - { -#if BGFX_CONFIG_MEMORY_TRACKING - BX_WARN(0 == m_numBlocks, "MEMORY LEAK: %d (max: %d)", m_numBlocks, m_maxBlocks); -#endif // BGFX_CONFIG_MEMORY_TRACKING - } + void checkLeaks(); protected: #if BGFX_CONFIG_MEMORY_TRACKING @@ -196,7 +191,7 @@ namespace bgfx #endif // BGFX_CONFIG_MEMORY_TRACKING }; - static CallbackStub* s_callbackStub = NULL; + static CallbackStub* s_callbackStub = NULL; static AllocatorStub* s_allocatorStub = NULL; static bool s_graphicsDebuggerPresent = false; @@ -210,6 +205,19 @@ namespace bgfx static bool s_renderFrameCalled = false; PlatformData g_platformData; + void AllocatorStub::checkLeaks() + { +#if BGFX_CONFIG_MEMORY_TRACKING + // BK - CallbackStub will be deleted after printing this info, so there is always one + // leak if CallbackStub is used. + BX_WARN( (NULL != s_callbackStub ? 1 : 0) == m_numBlocks + , "MEMORY LEAK: %d (max: %d)" + , m_numBlocks + , m_maxBlocks + ); +#endif // BGFX_CONFIG_MEMORY_TRACKING + } + void setPlatformData(const PlatformData& _pd) { if (NULL != s_ctx) @@ -333,7 +341,7 @@ namespace bgfx case RendererType::Metal: mem = makeRef(vs_debugfont_mtl, sizeof(vs_debugfont_mtl) ); break; - + default: mem = makeRef(vs_debugfont_glsl, sizeof(vs_debugfont_glsl) ); break; @@ -355,7 +363,7 @@ namespace bgfx case RendererType::Metal: mem = makeRef(fs_debugfont_mtl, sizeof(fs_debugfont_mtl) ); break; - + default: mem = makeRef(fs_debugfont_glsl, sizeof(fs_debugfont_glsl) ); break; @@ -579,7 +587,7 @@ namespace bgfx else if (RendererType::Metal == g_caps.rendererType) { vsh = createShader(makeRef(vs_clear_mtl, sizeof(vs_clear_mtl) ) ); - + const Mem mem[] = { Mem(fs_clear0_mtl, sizeof(fs_clear0_mtl) ), @@ -591,7 +599,7 @@ namespace bgfx Mem(fs_clear6_mtl, sizeof(fs_clear6_mtl) ), Mem(fs_clear7_mtl, sizeof(fs_clear7_mtl) ), }; - + for (uint32_t ii = 0, num = g_caps.maxFBAttachments; ii < num; ++ii) { fragMem[ii] = makeRef(mem[ii].data, uint32_t(mem[ii].size) ); @@ -882,6 +890,7 @@ namespace bgfx CAPS_FLAGS(BGFX_CAPS_HMD), CAPS_FLAGS(BGFX_CAPS_INDEX32), CAPS_FLAGS(BGFX_CAPS_DRAW_INDIRECT), + CAPS_FLAGS(BGFX_CAPS_HIDPI), #undef CAPS_FLAGS }; @@ -1525,8 +1534,7 @@ again: _type = RendererType::Null; } } - else if (BX_ENABLED(0 - || BX_PLATFORM_IOS ) ) + else if (BX_ENABLED(BX_PLATFORM_IOS) ) { if (s_rendererCreator[RendererType::Metal].supported) { @@ -1536,7 +1544,6 @@ again: { _type = RendererType::OpenGLES; } - } else if (BX_ENABLED(0 || BX_PLATFORM_ANDROID @@ -2153,8 +2160,6 @@ again: if (NULL != s_allocatorStub) { -// s_allocatorStub->checkLeaks(); - bx::CrtAllocator allocator; BX_DELETE(&allocator, s_allocatorStub); s_allocatorStub = NULL; diff --git a/src/glcontext_eagl.h b/src/glcontext_eagl.h index 45ba0fbf3..fcc1088c9 100644 --- a/src/glcontext_eagl.h +++ b/src/glcontext_eagl.h @@ -23,7 +23,7 @@ namespace bgfx { namespace gl void destroy(); void resize(uint32_t _width, uint32_t _height, uint32_t _flags); - static bool isSwapChainSupported(); + uint64_t getCaps() const; SwapChainGL* createSwapChain(void* _nwh); void destroySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/glcontext_eagl.mm b/src/glcontext_eagl.mm index 0ff5e6379..86c196781 100644 --- a/src/glcontext_eagl.mm +++ b/src/glcontext_eagl.mm @@ -16,12 +16,12 @@ namespace bgfx { namespace gl # include "glimports.h" static void* s_opengles = NULL; - + void GlContext::create(uint32_t _width, uint32_t _height) { s_opengles = bx::dlopen("/System/Library/Frameworks/OpenGLES.framework/OpenGLES"); BX_CHECK(NULL != s_opengles, "OpenGLES dynamic library is not found!"); - + BX_UNUSED(_width, _height); CAEAGLLayer* layer = (CAEAGLLayer*)g_platformData.nwh; layer.opaque = true; @@ -64,7 +64,7 @@ namespace bgfx { namespace gl , "glCheckFramebufferStatus failed 0x%08x" , glCheckFramebufferStatus(GL_FRAMEBUFFER) ); - + import(); } @@ -90,7 +90,7 @@ namespace bgfx { namespace gl EAGLContext* context = (EAGLContext*)m_context; [context release]; - + bx::dlclose(s_opengles); } @@ -144,9 +144,9 @@ namespace bgfx { namespace gl ); } - bool GlContext::isSwapChainSupported() + uint64_t GlContext::getCaps() const { - return false; + return 0; } SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/) diff --git a/src/glcontext_egl.cpp b/src/glcontext_egl.cpp index 2850121e5..38ce7b286 100644 --- a/src/glcontext_egl.cpp +++ b/src/glcontext_egl.cpp @@ -355,12 +355,15 @@ EGL_IMPORT } } - bool GlContext::isSwapChainSupported() + uint64_t GlContext::getCaps() const { return BX_ENABLED(0 | BX_PLATFORM_LINUX | BX_PLATFORM_WINDOWS - ); + ) + ? BGFX_CAPS_SWAP_CHAIN + : 0 + ; } SwapChainGL* GlContext::createSwapChain(void* _nwh) diff --git a/src/glcontext_egl.h b/src/glcontext_egl.h index c8eb2d5d0..5c263c2a5 100644 --- a/src/glcontext_egl.h +++ b/src/glcontext_egl.h @@ -29,7 +29,7 @@ namespace bgfx { namespace gl void destroy(); void resize(uint32_t _width, uint32_t _height, uint32_t _flags); - static bool isSwapChainSupported(); + uint64_t getCaps() const; SwapChainGL* createSwapChain(void* _nwh); void destroySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/glcontext_glx.cpp b/src/glcontext_glx.cpp index 270e14dbe..547c75886 100644 --- a/src/glcontext_glx.cpp +++ b/src/glcontext_glx.cpp @@ -244,9 +244,9 @@ namespace bgfx { namespace gl } } - bool GlContext::isSwapChainSupported() + uint64_t GlContext::getCaps() const { - return true; + return BGFX_CAPS_SWAP_CHAIN; } SwapChainGL* GlContext::createSwapChain(void* _nwh) diff --git a/src/glcontext_glx.h b/src/glcontext_glx.h index a931356cb..c88ce5640 100644 --- a/src/glcontext_glx.h +++ b/src/glcontext_glx.h @@ -28,7 +28,7 @@ namespace bgfx { namespace gl void destroy(); void resize(uint32_t _width, uint32_t _height, uint32_t _flags); - static bool isSwapChainSupported(); + uint64_t getCaps() const; SwapChainGL* createSwapChain(void* _nwh); void destroySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/glcontext_nsgl.h b/src/glcontext_nsgl.h index 666926db9..d7d9886bd 100644 --- a/src/glcontext_nsgl.h +++ b/src/glcontext_nsgl.h @@ -23,7 +23,7 @@ namespace bgfx { namespace gl void destroy(); void resize(uint32_t _width, uint32_t _height, uint32_t _flags); - static bool isSwapChainSupported(); + uint64_t getCaps() const; SwapChainGL* createSwapChain(void* _nwh); void destroySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/glcontext_nsgl.mm b/src/glcontext_nsgl.mm index 774e3a92b..68f6d92f8 100644 --- a/src/glcontext_nsgl.mm +++ b/src/glcontext_nsgl.mm @@ -114,8 +114,6 @@ namespace bgfx { namespace gl m_context = glContext; } -// float x = [nsWindow backingScaleFactor]; - import(); } @@ -147,9 +145,14 @@ namespace bgfx { namespace gl [glContext update]; } - bool GlContext::isSwapChainSupported() + uint64_t GlContext::getCaps() const { - return false; + NSWindow* nsWindow = (NSWindow*)g_platformData.nwh; + uint64_t caps = 1.0f < [nsWindow backingScaleFactor] + ? BGFX_CAPS_HIDPI + : 0 + ; + return caps; } SwapChainGL* GlContext::createSwapChain(void* _nwh) diff --git a/src/glcontext_ppapi.cpp b/src/glcontext_ppapi.cpp index f61244dbd..bdbb50680 100644 --- a/src/glcontext_ppapi.cpp +++ b/src/glcontext_ppapi.cpp @@ -153,9 +153,9 @@ namespace bgfx { namespace gl s_ppapi.resize(_width, _height, _flags); } - bool GlContext::isSwapChainSupported() + uint64_t GlContext::getCaps() const { - return false; + return 0; } SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/) diff --git a/src/glcontext_ppapi.h b/src/glcontext_ppapi.h index f54ea2bb5..b67f19dfb 100644 --- a/src/glcontext_ppapi.h +++ b/src/glcontext_ppapi.h @@ -27,7 +27,7 @@ namespace bgfx { namespace gl void destroy(); void resize(uint32_t _width, uint32_t _height, uint32_t _flags); - static bool isSwapChainSupported(); + uint64_t getCaps() const; SwapChainGL* createSwapChain(void* _nwh); void destroySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/glcontext_wgl.cpp b/src/glcontext_wgl.cpp index ef7f570df..2105efda2 100644 --- a/src/glcontext_wgl.cpp +++ b/src/glcontext_wgl.cpp @@ -296,9 +296,9 @@ namespace bgfx { namespace gl } } - bool GlContext::isSwapChainSupported() + uint64_t GlContext::getCaps() const { - return true; + return BGFX_CAPS_SWAP_CHAIN; } SwapChainGL* GlContext::createSwapChain(void* _nwh) diff --git a/src/glcontext_wgl.h b/src/glcontext_wgl.h index 1948622b8..4665951b7 100644 --- a/src/glcontext_wgl.h +++ b/src/glcontext_wgl.h @@ -72,7 +72,7 @@ typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum z void destroy(); void resize(uint32_t _width, uint32_t _height, uint32_t _flags); - static bool isSwapChainSupported(); + uint64_t getCaps() const; SwapChainGL* createSwapChain(void* _nwh); void destroySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 44e29eecd..b7552b5b1 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1654,10 +1654,7 @@ namespace bgfx { namespace gl : 0 ; - g_caps.supported |= GlContext::isSwapChainSupported() - ? BGFX_CAPS_SWAP_CHAIN - : 0 - ; + g_caps.supported |= m_glctx.getCaps(); if (s_extension[Extension::EXT_texture_filter_anisotropic].m_supported) {