(CocoaGL) Get rid of one static global
This commit is contained in:
parent
e044b0eeec
commit
eea8e12343
|
@ -72,12 +72,9 @@ typedef struct cocoa_ctx_data
|
||||||
/* TODO/FIXME - static globals */
|
/* TODO/FIXME - static globals */
|
||||||
static enum gfx_ctx_api cocoagl_api = GFX_CTX_NONE;
|
static enum gfx_ctx_api cocoagl_api = GFX_CTX_NONE;
|
||||||
static GLContextClass* g_hw_ctx = NULL;
|
static GLContextClass* g_hw_ctx = NULL;
|
||||||
static GLContextClass* g_context = NULL;
|
static GLContextClass* g_ctx = NULL;
|
||||||
static unsigned g_gl_minor = 0;
|
static unsigned g_gl_minor = 0;
|
||||||
static unsigned g_gl_major = 0;
|
static unsigned g_gl_major = 0;
|
||||||
#ifdef OSX
|
|
||||||
static NSOpenGLPixelFormat *g_fmt = NULL;
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_COCOATOUCH)
|
#if defined(HAVE_COCOATOUCH)
|
||||||
static GLKView *glk_view = NULL;
|
static GLKView *glk_view = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
@ -130,7 +127,7 @@ static void cocoa_gl_gfx_ctx_set_flags(void *data, uint32_t flags)
|
||||||
#if defined(OSX)
|
#if defined(OSX)
|
||||||
void cocoa_gl_gfx_ctx_update(void)
|
void cocoa_gl_gfx_ctx_update(void)
|
||||||
{
|
{
|
||||||
[g_context update];
|
[g_ctx update];
|
||||||
[g_hw_ctx update];
|
[g_hw_ctx update];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -148,7 +145,7 @@ void *glkitview_init(void)
|
||||||
|
|
||||||
void glkitview_bind_fbo(void)
|
void glkitview_bind_fbo(void)
|
||||||
{
|
{
|
||||||
if (g_context)
|
if (glk_view)
|
||||||
[glk_view bindDrawable];
|
[glk_view bindDrawable];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -163,9 +160,8 @@ static void cocoa_gl_gfx_ctx_destroy(void *data)
|
||||||
return;
|
return;
|
||||||
#ifdef OSX
|
#ifdef OSX
|
||||||
[GLContextClass clearCurrentContext];
|
[GLContextClass clearCurrentContext];
|
||||||
[g_context clearDrawable];
|
[g_ctx clearDrawable];
|
||||||
RELEASE(g_context);
|
RELEASE(g_ctx);
|
||||||
RELEASE(g_fmt);
|
|
||||||
if (g_hw_ctx)
|
if (g_hw_ctx)
|
||||||
[g_hw_ctx clearDrawable];
|
[g_hw_ctx clearDrawable];
|
||||||
RELEASE(g_hw_ctx);
|
RELEASE(g_hw_ctx);
|
||||||
|
@ -173,7 +169,7 @@ static void cocoa_gl_gfx_ctx_destroy(void *data)
|
||||||
#else
|
#else
|
||||||
[EAGLContext setCurrentContext:nil];
|
[EAGLContext setCurrentContext:nil];
|
||||||
#endif
|
#endif
|
||||||
g_context = nil;
|
g_ctx = nil;
|
||||||
|
|
||||||
free(cocoa_ctx);
|
free(cocoa_ctx);
|
||||||
}
|
}
|
||||||
|
@ -252,7 +248,7 @@ static void cocoa_gl_gfx_ctx_bind_hw_render(void *data, bool enable)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[g_context makeCurrentContext];
|
[g_ctx makeCurrentContext];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (enable)
|
if (enable)
|
||||||
|
@ -261,7 +257,7 @@ static void cocoa_gl_gfx_ctx_bind_hw_render(void *data, bool enable)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[EAGLContext setCurrentContext:g_context];
|
[EAGLContext setCurrentContext:g_ctx];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -293,7 +289,7 @@ static void cocoa_gl_gfx_ctx_swap_interval(void *data, int i)
|
||||||
unsigned interval = (unsigned)i;
|
unsigned interval = (unsigned)i;
|
||||||
#ifdef OSX
|
#ifdef OSX
|
||||||
GLint value = interval ? 1 : 0;
|
GLint value = interval ? 1 : 0;
|
||||||
[g_context setValues:&value forParameter:NSOpenGLCPSwapInterval];
|
[g_ctx setValues:&value forParameter:NSOpenGLCPSwapInterval];
|
||||||
#else
|
#else
|
||||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
||||||
/* < No way to disable Vsync on iOS? */
|
/* < No way to disable Vsync on iOS? */
|
||||||
|
@ -306,7 +302,7 @@ static void cocoa_gl_gfx_ctx_swap_interval(void *data, int i)
|
||||||
static void cocoa_gl_gfx_ctx_swap_buffers(void *data)
|
static void cocoa_gl_gfx_ctx_swap_buffers(void *data)
|
||||||
{
|
{
|
||||||
#ifdef OSX
|
#ifdef OSX
|
||||||
[g_context flushBuffer];
|
[g_ctx flushBuffer];
|
||||||
[g_hw_ctx flushBuffer];
|
[g_hw_ctx flushBuffer];
|
||||||
#else
|
#else
|
||||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
||||||
|
@ -351,6 +347,7 @@ static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{
|
{
|
||||||
|
NSOpenGLPixelFormat *fmt;
|
||||||
NSOpenGLPixelFormatAttribute attributes [] = {
|
NSOpenGLPixelFormatAttribute attributes [] = {
|
||||||
NSOpenGLPFAColorSize,
|
NSOpenGLPFAColorSize,
|
||||||
24,
|
24,
|
||||||
|
@ -385,32 +382,34 @@ static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
|
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
|
||||||
if (g_fmt == nil)
|
if (fmt == nil)
|
||||||
{
|
{
|
||||||
/* NSOpenGLFPAAllowOfflineRenderers is
|
/* NSOpenGLFPAAllowOfflineRenderers is
|
||||||
not supported on this OS version. */
|
not supported on this OS version. */
|
||||||
attributes[3] = (NSOpenGLPixelFormatAttribute)0;
|
attributes[3] = (NSOpenGLPixelFormatAttribute)0;
|
||||||
g_fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (cocoa_ctx->use_hw_ctx)
|
||||||
|
{
|
||||||
|
g_hw_ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
|
||||||
|
g_ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:g_hw_ctx];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
|
||||||
|
|
||||||
|
RELEASE(fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cocoa_ctx->use_hw_ctx)
|
[g_ctx setView:g_view];
|
||||||
{
|
|
||||||
g_hw_ctx = [[NSOpenGLContext alloc] initWithFormat:g_fmt shareContext:nil];
|
|
||||||
g_context = [[NSOpenGLContext alloc] initWithFormat:g_fmt shareContext:g_hw_ctx];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
g_context = [[NSOpenGLContext alloc] initWithFormat:g_fmt shareContext:nil];
|
|
||||||
|
|
||||||
[g_context setView:g_view];
|
|
||||||
#ifdef OSX
|
#ifdef OSX
|
||||||
[g_context makeCurrentContext];
|
[g_ctx makeCurrentContext];
|
||||||
#else
|
#else
|
||||||
[EAGLContext setCurrentContext:g_context];
|
[EAGLContext setCurrentContext:g_ctx];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TODO/FIXME: Screen mode support. */
|
/* TODO/FIXME: Screen mode support. */
|
||||||
|
@ -465,13 +464,13 @@ static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
|
||||||
|
|
||||||
if (cocoa_ctx->use_hw_ctx)
|
if (cocoa_ctx->use_hw_ctx)
|
||||||
g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||||
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
g_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||||
glk_view.context = g_context;
|
glk_view.context = g_ctx;
|
||||||
|
|
||||||
#ifdef OSX
|
#ifdef OSX
|
||||||
[g_context makeCurrentContext];
|
[g_ctx makeCurrentContext];
|
||||||
#else
|
#else
|
||||||
[EAGLContext setCurrentContext:g_context];
|
[EAGLContext setCurrentContext:g_ctx];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TODO: Maybe iOS users should be able to
|
/* TODO: Maybe iOS users should be able to
|
||||||
|
|
Loading…
Reference in New Issue