2013-01-15 23:37:07 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
|
|
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bgfx_p.h"
|
|
|
|
|
2013-07-13 19:52:28 -04:00
|
|
|
#if BX_PLATFORM_OSX && (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
|
2013-01-15 23:37:07 -05:00
|
|
|
# include "renderer_gl.h"
|
2013-07-13 19:52:28 -04:00
|
|
|
# include <Cocoa/Cocoa.h>
|
|
|
|
# include <bx/os.h>
|
2013-01-15 23:37:07 -05:00
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
|
|
|
|
|
|
|
# define GL_IMPORT(_optional, _proto, _func) _proto _func
|
2013-07-14 02:11:02 -04:00
|
|
|
# include "glimports.h"
|
2013-01-15 23:37:07 -05:00
|
|
|
# undef GL_IMPORT
|
|
|
|
|
2013-07-14 02:11:02 -04:00
|
|
|
static void* s_opengl = NULL;
|
|
|
|
|
2013-01-15 23:37:07 -05:00
|
|
|
void GlContext::create(uint32_t _width, uint32_t _height)
|
|
|
|
{
|
2013-07-14 02:11:02 -04:00
|
|
|
s_opengl = bx::dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL");
|
|
|
|
BX_CHECK(NULL != s_opengl, "OpenGL dynamic library is not found!");
|
|
|
|
|
2013-01-15 23:37:07 -05:00
|
|
|
NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow;
|
2013-07-14 02:11:02 -04:00
|
|
|
|
2013-01-15 23:37:07 -05:00
|
|
|
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
|
2013-07-13 19:52:28 -04:00
|
|
|
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy, // NSOpenGLProfileVersion3_2Core,
|
2013-07-14 02:11:02 -04:00
|
|
|
NSOpenGLPFAColorSize, 24,
|
|
|
|
NSOpenGLPFAAlphaSize, 8,
|
|
|
|
NSOpenGLPFADepthSize, 24,
|
|
|
|
NSOpenGLPFAStencilSize, 8,
|
|
|
|
NSOpenGLPFADoubleBuffer, true,
|
|
|
|
NSOpenGLPFAAccelerated, true,
|
|
|
|
NSOpenGLPFANoRecovery, true,
|
|
|
|
0, 0,
|
2013-01-15 23:37:07 -05:00
|
|
|
};
|
2013-07-14 02:11:02 -04:00
|
|
|
|
|
|
|
NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
|
2013-01-15 23:37:07 -05:00
|
|
|
NSRect glViewRect = [[nsWindow contentView] bounds];
|
2013-07-14 02:11:02 -04:00
|
|
|
NSOpenGLView* glView = [[NSOpenGLView alloc] initWithFrame:glViewRect pixelFormat:pixelFormat];
|
2013-01-15 23:37:07 -05:00
|
|
|
|
|
|
|
[pixelFormat release];
|
|
|
|
[nsWindow setContentView:glView];
|
|
|
|
|
|
|
|
NSOpenGLContext* glContext = [glView openGLContext];
|
2013-07-14 02:11:02 -04:00
|
|
|
|
2013-01-15 23:37:07 -05:00
|
|
|
[glContext makeCurrentContext];
|
|
|
|
|
|
|
|
m_view = glView;
|
|
|
|
m_context = glContext;
|
|
|
|
|
|
|
|
import();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlContext::destroy()
|
|
|
|
{
|
|
|
|
NSOpenGLView* glView = (NSOpenGLView*)m_view;
|
|
|
|
m_view = 0;
|
|
|
|
m_context = 0;
|
|
|
|
[glView release];
|
2013-07-14 02:11:02 -04:00
|
|
|
|
|
|
|
bx::dlclose(s_opengl);
|
2013-01-15 23:37:07 -05:00
|
|
|
}
|
|
|
|
|
2013-05-06 02:10:01 -04:00
|
|
|
void GlContext::resize(uint32_t _width, uint32_t _height, bool _vsync)
|
2013-01-15 23:37:07 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlContext::swap()
|
|
|
|
{
|
|
|
|
NSOpenGLContext* glContext = (NSOpenGLContext*)m_context;
|
|
|
|
[glContext makeCurrentContext];
|
|
|
|
[glContext flushBuffer];
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlContext::import()
|
|
|
|
{
|
|
|
|
# define GL_IMPORT(_optional, _proto, _func) \
|
|
|
|
{ \
|
2013-07-14 02:11:02 -04:00
|
|
|
_func = (_proto)bx::dlsym(s_opengl, #_func); \
|
2013-01-15 23:37:07 -05:00
|
|
|
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. NSGLGetProcAddress(\"%s\")", #_func); \
|
|
|
|
}
|
|
|
|
# include "glimports.h"
|
|
|
|
# undef GL_IMPORT
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace bgfx
|
|
|
|
|
2013-07-13 19:52:28 -04:00
|
|
|
#endif // BX_PLATFORM_OSX && (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
|