bgfx/src/glcontext_nsgl.mm

99 lines
2.5 KiB
Text
Raw Normal View History

/*
* 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)
# include "renderer_gl.h"
2013-07-13 19:52:28 -04:00
# include <Cocoa/Cocoa.h>
# include <bx/os.h>
static void* NSGLGetProcAddress (const char* name) {
2013-07-13 19:52:28 -04:00
static void* dylib =
bx::dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL");
return dylib ? bx::dlsym(dylib, name) : NULL;
}
namespace bgfx
{
# define GL_IMPORT(_optional, _proto, _func) _proto _func
# include "glimports.h"
# undef GL_IMPORT
void GlContext::create(uint32_t _width, uint32_t _height)
{
NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow;
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
2013-07-13 19:52:28 -04:00
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy, // NSOpenGLProfileVersion3_2Core,
NSOpenGLPFAColorSize , 24,
NSOpenGLPFAAlphaSize , 8,
NSOpenGLPFADepthSize , 24,
NSOpenGLPFAStencilSize , 8,
NSOpenGLPFADoubleBuffer ,
NSOpenGLPFAAccelerated ,
NSOpenGLPFANoRecovery ,
0
};
NSOpenGLPixelFormat* pixelFormat =
[[NSOpenGLPixelFormat alloc]
initWithAttributes:pixelFormatAttributes];
NSRect glViewRect = [[nsWindow contentView] bounds];
NSOpenGLView* glView =
[[NSOpenGLView alloc]
initWithFrame:glViewRect
pixelFormat:pixelFormat];
[pixelFormat release];
[nsWindow setContentView:glView];
NSOpenGLContext* glContext = [glView openGLContext];
[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];
}
void GlContext::resize(uint32_t _width, uint32_t _height, bool _vsync)
{
}
void GlContext::swap()
{
NSOpenGLContext* glContext = (NSOpenGLContext*)m_context;
[glContext makeCurrentContext];
[glContext flushBuffer];
}
void GlContext::import()
{
# define GL_IMPORT(_optional, _proto, _func) \
{ \
_func = (_proto)NSGLGetProcAddress(#_func); \
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)