bgfx: fix leak of autoreleased objects and support OS X 10.6 Snow Leopard

This commit is contained in:
Vas Crabb 2015-04-03 01:53:48 +11:00
parent d055017fa2
commit 397265f2fc

View file

@ -7,6 +7,7 @@
#if BX_PLATFORM_OSX && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL)
# include "renderer_gl.h"
# include <AvailabilityMacros.h>
# include <Cocoa/Cocoa.h>
# include <bx/os.h>
@ -36,6 +37,22 @@ namespace bgfx { namespace gl
}
};
class AutoreleasePoolHolder
{
public:
AutoreleasePoolHolder() : pool([[NSAutoreleasePool alloc] init])
{
}
~AutoreleasePoolHolder()
{
[pool release];
}
private:
NSAutoreleasePool* pool;
};
static void* s_opengl = NULL;
void GlContext::create(uint32_t _width, uint32_t _height)
@ -45,11 +62,13 @@ namespace bgfx { namespace gl
s_opengl = bx::dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL");
BX_CHECK(NULL != s_opengl, "OpenGL dynamic library is not found!");
const AutoreleasePoolHolder pool;
NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow;
m_context = g_bgfxNSGL;
if (NULL == g_bgfxNSGL)
{
#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
NSOpenGLPixelFormatAttribute profile =
#if BGFX_CONFIG_RENDERER_OPENGL >= 31
NSOpenGLProfileVersion3_2Core
@ -57,9 +76,12 @@ namespace bgfx { namespace gl
NSOpenGLProfileVersionLegacy
#endif // BGFX_CONFIG_RENDERER_OPENGL >= 31
;
#endif // defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
NSOpenGLPFAOpenGLProfile, profile,
#endif // defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADepthSize, 24,