From bf22ffaae15655ef231683323ca569af1ad56d6e Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Sun, 21 Jul 2013 14:44:53 -0700 Subject: [PATCH] iOS stuff. --- examples/common/entry_ios.mm | 241 ++++++++++++++++++++++++++++++++++ examples/common/entry_osx.mm | 93 +++++++------ include/bgfxplatform.h | 6 + makefile | 19 ++- premake/bgfx.lua | 4 +- premake/premake4.lua | 5 +- src/bgfx.cpp | 13 +- src/bgfx_p.h | 3 + src/glcontext_eagl.h | 42 ++++++ src/glcontext_eagl.mm | 89 +++++++++++++ src/glcontext_nsgl.h | 6 +- src/renderer_gl.cpp | 14 +- src/renderer_gl.h | 27 +++- tools/geometryc/geometryc.cpp | 16 +-- 14 files changed, 502 insertions(+), 76 deletions(-) create mode 100644 examples/common/entry_ios.mm create mode 100755 src/glcontext_eagl.h create mode 100644 src/glcontext_eagl.mm diff --git a/examples/common/entry_ios.mm b/examples/common/entry_ios.mm new file mode 100644 index 00000000..542017df --- /dev/null +++ b/examples/common/entry_ios.mm @@ -0,0 +1,241 @@ +/* + * Copyright 2011-2013 Branimir Karadzic. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#include + +#if BX_PLATFORM_IOS + +#import +#import +#import + +#include +#include +#include + +#include "entry_p.h" +#include "dbg.h" + +extern int _main_(int _argc, char** _argv); + +namespace bgfx +{ + void renderFrame(); +} + +namespace entry +{ + struct MainThreadEntry + { + int m_argc; + char** m_argv; + + static int32_t threadFunc(void* _userData); + }; + + struct Context + { + Context() + { + const char* argv[1] = { "ios" }; + m_mte.m_argc = 1; + m_mte.m_argv = const_cast(argv); + + m_eventQueue.postSizeEvent(720, 1024); + + m_thread.init(MainThreadEntry::threadFunc, &m_mte); + } + + ~Context() + { + m_thread.shutdown(); + } + + MainThreadEntry m_mte; + bx::Thread m_thread; + + EventQueue m_eventQueue; + }; + + static Context* s_ctx; + + int32_t MainThreadEntry::threadFunc(void* _userData) + { + MainThreadEntry* self = (MainThreadEntry*)_userData; + int32_t result = _main_(self->m_argc, self->m_argv); + return result; + } + + const Event* poll() + { + return s_ctx->m_eventQueue.poll(); + } + + void release(const Event* _event) + { + s_ctx->m_eventQueue.release(_event); + } + + void setWindowSize(uint32_t _width, uint32_t _height) + { + } + + void toggleWindowFrame() + { + } + + void setMouseLock(bool _lock) + { + } + +} // namespace entry + +using namespace entry; + +@interface EAGLView : UIView +{ + + EAGLContext* m_context; + CADisplayLink* m_displayLink; +} + +@property (nonatomic, retain) EAGLContext* m_context; + +@end + +@implementation EAGLView + +@synthesize m_context; + ++ (Class)layerClass +{ + return [CAEAGLLayer class]; +} + +- (id)initWithFrame:(CGRect)rect +{ + self = [super initWithFrame:rect]; + + if (nil == self) + { + return nil; + } + + CAEAGLLayer* layer = (CAEAGLLayer*)self.layer; + layer.opaque = true; + + layer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys + : [NSNumber numberWithBool:false] + , kEAGLDrawablePropertyRetainedBacking + , kEAGLColorFormatRGBA8 + , kEAGLDrawablePropertyColorFormat + , nil + ]; + + m_context = [ [EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + BX_CHECK(NULL != m_context, "Failed to create kEAGLRenderingAPIOpenGLES2 context."); + + [EAGLContext setCurrentContext:m_context]; + + bgfx::iosSetEaglContext(m_context, layer); + + return self; +} + +- (void)start +{ + if (nil == m_displayLink) + { + m_displayLink = [self.window.screen displayLinkWithTarget:self selector:@selector(renderFrame)]; + [m_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + } +} + +- (void)stop +{ + if (nil != m_displayLink) + { + [m_displayLink invalidate]; + m_displayLink = nil; + } +} + +- (void)renderFrame +{ + bgfx::renderFrame(); +} + +@end + +@interface AppDelegate : UIResponder +{ + UIWindow* m_window; + EAGLView* m_view; +} + +@property (nonatomic, retain) UIWindow* m_window; +@property (nonatomic, retain) EAGLView* m_view; + +@end + +@implementation AppDelegate + +@synthesize m_window; +@synthesize m_view; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + CGRect rect = [ [UIScreen mainScreen] bounds]; + m_window = [ [UIWindow alloc] initWithFrame: rect]; + m_view = [ [EAGLView alloc] initWithFrame: rect]; + + [m_window addSubview: m_view]; + [m_window makeKeyAndVisible]; + + s_ctx = new Context; + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + [m_view stop]; +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ +} + +- (void)applicationWillEnterForeground:(UIApplication *)application +{ +} + +- (void)applicationDidBecomeActive:(UIApplication *)application +{ + [m_view start]; +} + +- (void)applicationWillTerminate:(UIApplication *)application +{ + [m_view stop]; +} + +- (void)dealloc +{ + [m_window release]; + [m_view release]; + [super dealloc]; +} + +@end + +int main(int _argc, char* _argv[]) +{ + NSAutoreleasePool* pool = [ [NSAutoreleasePool alloc] init]; + int exitCode = UIApplicationMain(_argc, _argv, @"UIApplication", NSStringFromClass([AppDelegate class]) ); + [pool release]; + return exitCode; +} + +#endif // BX_PLATFORM_IOS diff --git a/examples/common/entry_osx.mm b/examples/common/entry_osx.mm index ac590454..1f9760fa 100755 --- a/examples/common/entry_osx.mm +++ b/examples/common/entry_osx.mm @@ -37,7 +37,7 @@ extern int _main_(int _argc, char** _argv); - (id)init { self = [super init]; if (self) { - self->terminated = false; + self->terminated = false; } return self; } @@ -77,7 +77,7 @@ extern int _main_(int _argc, char** _argv); - (void)windowCreated:(NSWindow *)window { assert(window); - + [window setDelegate:self]; assert(self->windowCount < ~0u); @@ -86,12 +86,12 @@ extern int _main_(int _argc, char** _argv); - (BOOL)windowShouldClose:(NSWindow *)window { assert(window); - + [window setDelegate:nil]; assert(self->windowCount); self->windowCount -= 1; - + if (self->windowCount == 0) { [NSApp terminate:self]; return false; @@ -106,39 +106,39 @@ namespace entry { int m_argc; char** m_argv; - + static int32_t threadFunc(void* _userData) { MainThreadEntry* self = (MainThreadEntry*)_userData; return _main_(self->m_argc, self->m_argv); } }; - + struct Context { Context() : m_exit(false) { } - + NSEvent* WaitEvent () { return - [NSApp - nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantFuture] // wait for event - inMode:NSDefaultRunLoopMode - dequeue:YES]; + [NSApp + nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantFuture] // wait for event + inMode:NSDefaultRunLoopMode + dequeue:YES]; } - + NSEvent* PeekEvent () { return - [NSApp - nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantPast] // do not wait for event - inMode:NSDefaultRunLoopMode - dequeue:YES]; + [NSApp + nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantPast] // do not wait for event + inMode:NSDefaultRunLoopMode + dequeue:YES]; } - + bool DispatchEvent (NSEvent* event) { if (event) { [NSApp sendEvent:event]; @@ -147,22 +147,22 @@ namespace entry } return false; } - + int32_t main(int _argc, char** _argv) { - [NSApplication sharedApplication]; + [NSApplication sharedApplication]; id dg = [bgfxApplicationDelegate sharedDelegate]; [NSApp setDelegate:dg]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; [NSApp activateIgnoringOtherApps:YES]; [NSApp finishLaunching]; [[NSNotificationCenter defaultCenter] - postNotificationName:NSApplicationWillFinishLaunchingNotification - object:NSApp]; + postNotificationName:NSApplicationWillFinishLaunchingNotification + object:NSApp]; [[NSNotificationCenter defaultCenter] - postNotificationName:NSApplicationDidFinishLaunchingNotification - object:NSApp]; - + postNotificationName:NSApplicationDidFinishLaunchingNotification + object:NSApp]; + id quitMenuItem = [NSMenuItem new]; [quitMenuItem initWithTitle:@"Quit" @@ -175,53 +175,52 @@ namespace entry id menubar = [[NSMenu new] autorelease]; [menubar addItem:appMenuItem]; [NSApp setMainMenu:menubar]; - + NSRect rect = NSMakeRect(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT); NSWindow* window = [NSWindow alloc]; [window - initWithContentRect:rect - styleMask:0 - |NSTitledWindowMask - |NSClosableWindowMask - |NSMiniaturizableWindowMask - |NSResizableWindowMask - backing:NSBackingStoreBuffered defer:NO - ]; - NSString* appName = [[NSProcessInfo processInfo] processName]; + initWithContentRect:rect + styleMask:0 + |NSTitledWindowMask + |NSClosableWindowMask + |NSMiniaturizableWindowMask + |NSResizableWindowMask + backing:NSBackingStoreBuffered defer:NO + ]; + NSString* appName = [[NSProcessInfo processInfo] processName]; [window setTitle:appName]; [window cascadeTopLeftFromPoint:NSMakePoint(20,20)]; [window makeKeyAndOrderFront:nil]; [[bgfxWindowDelegate sharedDelegate] windowCreated:window]; - + bgfx::osxSetNSWindow(window); - + MainThreadEntry mte; mte.m_argc = _argc; mte.m_argv = _argv; - + bx::Thread thread; thread.init(mte.threadFunc, &mte); while (!(m_exit = [dg applicationHasTerminated])) { - DispatchEvent(WaitEvent()); + DispatchEvent(WaitEvent()); while (DispatchEvent(PeekEvent())); } m_eventQueue.postExitEvent(); - + thread.shutdown(); - + return 0; } - + EventQueue m_eventQueue; - + bool m_exit; - }; - + static Context s_ctx; - + const Event* poll() { return s_ctx.m_eventQueue.poll(); diff --git a/include/bgfxplatform.h b/include/bgfxplatform.h index 331faa9e..28f337c5 100755 --- a/include/bgfxplatform.h +++ b/include/bgfxplatform.h @@ -20,6 +20,12 @@ namespace bgfx void androidSetWindow(::ANativeWindow* _window); } // namespace bgfx +#elif BX_PLATFORM_IOS +namespace bgfx +{ + void iosSetEaglContext(void* _context, void* _layer); +} // namespace bgfx + #elif BX_PLATFORM_LINUX # include diff --git a/makefile b/makefile index 98ee8d3b..23ed44be 100755 --- a/makefile +++ b/makefile @@ -13,7 +13,8 @@ all: premake4 --file=premake/premake4.lua --gcc=mingw gmake premake4 --file=premake/premake4.lua --gcc=linux gmake premake4 --file=premake/premake4.lua --gcc=osx gmake - premake4 --file=premake/premake4.lua --gcc=ios gmake + premake4 --file=premake/premake4.lua --gcc=ios-arm gmake + premake4 --file=premake/premake4.lua --gcc=ios-simulator gmake premake4 --file=premake/premake4.lua --gcc=qnx-arm gmake premake4 --file=premake/premake4.lua xcode4 make -s --no-print-directory -C src @@ -86,11 +87,17 @@ osx-release64: make -C .build/projects/gmake-osx config=release64 osx: osx-debug32 osx-release32 osx-debug64 osx-release64 -ios-debug: - make -R -C .build/projects/gmake-ios config=debug -ios-release: - make -R -C .build/projects/gmake-ios config=release -ios: ios-debug ios-release +ios-arm-debug: + make -R -C .build/projects/gmake-ios-arm config=debug +ios-arm-release: + make -R -C .build/projects/gmake-ios-arm config=release +ios-arm: ios-arm-debug ios-arm-release + +ios-simulator-debug: + make -R -C .build/projects/gmake-ios-simulator config=debug +ios-simulator-release: + make -R -C .build/projects/gmake-ios-simulator config=release +ios-simulator: ios-simulator-debug ios-simulator-release qnx-arm-debug: make -R -C .build/projects/gmake-qnx-arm config=debug diff --git a/premake/bgfx.lua b/premake/bgfx.lua index e00a878c..0a009c53 100644 --- a/premake/bgfx.lua +++ b/premake/bgfx.lua @@ -30,12 +30,12 @@ project "bgfx" "$(DXSDK_DIR)/include", } - configuration { "osx or ios" } + configuration { "osx or ios*" } files { BGFX_DIR .. "src/**.mm", } - configuration { "vs* or linux or mingw or osx or ios" } + configuration { "vs* or linux or mingw or osx or ios*" } includedirs { --nacl has GLES2 headers modified... BGFX_DIR .. "3rdparty/glext", diff --git a/premake/premake4.lua b/premake/premake4.lua index 4e6e5100..01b5c891 100644 --- a/premake/premake4.lua +++ b/premake/premake4.lua @@ -102,7 +102,8 @@ function exampleProject(_name, _uuid) "OpenGL.framework", } - configuration { "ios" } + configuration { "ios*" } + kind "ConsoleApp" files { BGFX_DIR .. "examples/common/**.mm", } @@ -110,6 +111,8 @@ function exampleProject(_name, _uuid) "-framework CoreFoundation", "-framework Foundation", "-framework OpenGLES", + "-framework UIKit", + "-framework QuartzCore", } configuration { "qnx*" } diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 4c6996b0..e303e5f9 100755 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -35,10 +35,19 @@ namespace bgfx #if BX_PLATFORM_ANDROID ::ANativeWindow* g_bgfxAndroidWindow = NULL; - void androidSetWindow(ANativeWindow* _window) + void androidSetWindow(::ANativeWindow* _window) { g_bgfxAndroidWindow = _window; } +#elif BX_PLATFORM_IOS + void* g_bgfxEaglContext = NULL; + void* g_bgfxEaglLayer = NULL; + void iosSetEaglContext(void* _context, void* _layer) + { + g_bgfxEaglContext = _context; + g_bgfxEaglLayer = _layer; + } + #elif BX_PLATFORM_OSX void* g_bgfxNSWindow = NULL; @@ -638,7 +647,7 @@ namespace bgfx s_threadIndex = BGFX_MAIN_THREAD_MAGIC; // On NaCl renderer is on the main thread. - s_ctx.init(!BX_PLATFORM_NACL); + s_ctx.init(!BX_PLATFORM_NACL && !BX_PLATFORM_IOS); } void shutdown() diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 28b71ef3..8d336edf 100755 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -156,6 +156,9 @@ namespace bgfx { #if BX_PLATFORM_ANDROID extern ::ANativeWindow* g_bgfxAndroidWindow; +#elif BX_PLATFORM_IOS + extern void* g_bgfxEaglContext; + extern void* g_bgfxEaglLayer; #elif BX_PLATFORM_OSX extern void* g_bgfxNSWindow; #elif BX_PLATFORM_WINDOWS diff --git a/src/glcontext_eagl.h b/src/glcontext_eagl.h new file mode 100755 index 00000000..8934022c --- /dev/null +++ b/src/glcontext_eagl.h @@ -0,0 +1,42 @@ +/* + * Copyright 2011-2013 Branimir Karadzic. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#ifndef __GLCONTEXT_EAGL_H__ +#define __GLCONTEXT_EAGL_H__ + +#if BX_PLATFORM_IOS + +namespace bgfx +{ + struct GlContext + { + GlContext() + : m_context(0) + { + } + + void create(uint32_t _width, uint32_t _height); + void destroy(); + void resize(uint32_t _width, uint32_t _height, bool _vsync); + void swap(); + void import(); + + bool isValid() const + { + return 0 != m_context; + } + + void* m_view; + void* m_context; + + GLuint m_fbo; + GLuint m_colorRbo; + GLuint m_depthRbo; + }; +} // namespace bgfx + +#endif // BX_PLATFORM_IOS + +#endif // __GLCONTEXT_EAGL_H__ diff --git a/src/glcontext_eagl.mm b/src/glcontext_eagl.mm new file mode 100644 index 00000000..9b9d10d8 --- /dev/null +++ b/src/glcontext_eagl.mm @@ -0,0 +1,89 @@ +/* + * Copyright 2011-2013 Branimir Karadzic. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#include "bgfx_p.h" + +#if BX_PLATFORM_IOS && (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL) +# include +# include +# include "renderer_gl.h" + +namespace bgfx +{ + void GlContext::create(uint32_t _width, uint32_t _height) + { + EAGLContext* context = (EAGLContext*)g_bgfxEaglContext; + CAEAGLLayer* layer = (CAEAGLLayer*)g_bgfxEaglLayer; + [EAGLContext setCurrentContext:context]; + + m_context = g_bgfxEaglContext; + + GL_CHECK(glGenFramebuffers(1, &m_fbo) ); + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo) ); + + GL_CHECK(glGenRenderbuffers(1, &m_colorRbo) ); + GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) ); + + [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer]; + GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorRbo) ); + + GLint width; + GLint height; + GL_CHECK(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width) ); + GL_CHECK(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height) ); + BX_TRACE("Screen size: %d x %d", width, height); + + GL_CHECK(glGenRenderbuffers(1, &m_depthRbo) ); + GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_depthRbo) ); + GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height) ); + GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthRbo) ); + + BX_CHECK(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER) + , "glCheckFramebufferStatus failed 0x%08x" + , glCheckFramebufferStatus(GL_FRAMEBUFFER) + ); + } + + void GlContext::destroy() + { + if (0 != m_fbo) + { + GL_CHECK(glDeleteFramebuffers(1, &m_fbo) ); + m_fbo = 0; + } + + if (0 != m_colorRbo) + { + GL_CHECK(glDeleteRenderbuffers(1, &m_colorRbo) ); + m_colorRbo = 0; + } + + if (0 != m_depthRbo) + { + GL_CHECK(glDeleteRenderbuffers(1, &m_depthRbo) ); + m_depthRbo = 0; + } + } + + void GlContext::resize(uint32_t _width, uint32_t _height, bool _vsync) + { + BX_TRACE("resize context"); + } + + void GlContext::swap() + { + EAGLContext* context = (EAGLContext*)m_context; + [EAGLContext setCurrentContext:context]; + GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) ); + [context presentRenderbuffer:GL_RENDERBUFFER]; + } + + void GlContext::import() + { + } + +} // namespace bgfx + +#endif // BX_PLATFORM_IOS && (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL) diff --git a/src/glcontext_nsgl.h b/src/glcontext_nsgl.h index b8e7c1b9..362c144b 100755 --- a/src/glcontext_nsgl.h +++ b/src/glcontext_nsgl.h @@ -16,18 +16,18 @@ namespace bgfx : m_context(0) { } - + void create(uint32_t _width, uint32_t _height); void destroy(); void resize(uint32_t _width, uint32_t _height, bool _vsync); void swap(); void import(); - + bool isValid() const { return 0 != m_context; } - + void* m_view; void* m_context; }; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index d0694eed..bc6cbcb1 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -282,6 +282,8 @@ namespace bgfx } #endif // BGFX_CONFIG_RENDERER_OPENGL + extern GLuint m_backBufferFbo; + struct RendererContext { RendererContext() @@ -428,6 +430,10 @@ namespace bgfx if (!m_glctx.isValid() ) { m_glctx.create(_width, _height); +#if BX_PLATFORM_IOS + // BK - Temp, need to figure out how to deal with FBO created by context. + m_backBufferFbo = m_glctx.m_fbo; +#endif // BX_PLATFORM_IOS } else { @@ -537,7 +543,7 @@ namespace bgfx void init() { - m_glctx.create(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT); + setRenderContextSize(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT); m_vendor = getGLString(GL_VENDOR); m_renderer = getGLString(GL_RENDERER); @@ -2425,6 +2431,7 @@ namespace bgfx s_drawArraysInstanced = stubDrawArraysInstanced; s_drawElementsInstanced = stubDrawElementsInstanced; +# if !BX_PLATFORM_IOS if (s_extension[Extension::ARB_instanced_arrays].m_supported || s_extension[Extension::ANGLE_instanced_arrays].m_supported) { @@ -2437,6 +2444,7 @@ namespace bgfx s_drawElementsInstanced = glDrawElementsInstanced; } } +# endif // !BX_PLATFORM_IOS #endif // !BGFX_CONFIG_RENDERER_OPENGLES3 if (s_renderCtx.m_vaoSupport) @@ -2626,7 +2634,7 @@ namespace bgfx void Context::rendererSetMarker(const char* _marker, uint32_t /*_size*/) { - GREMEDY_SETMARKER(_marker); + GREMEDY_SETMARKER(_marker); } void Context::rendererSubmit() @@ -2637,7 +2645,7 @@ namespace bgfx GL_CHECK(glBindVertexArray(defaultVao) ); } - GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) ); + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, s_renderCtx.m_backBufferFbo) ); s_renderCtx.updateResolution(m_render->m_resolution); diff --git a/src/renderer_gl.h b/src/renderer_gl.h index c4969a11..b5078655 100755 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -66,9 +66,28 @@ #elif BGFX_CONFIG_RENDERER_OPENGLES2 || BGFX_CONFIG_RENDERER_OPENGLES3 # if BGFX_CONFIG_RENDERER_OPENGLES2 -# include -# include -# include +# if BX_PLATFORM_IOS +# include +# include + +typedef void (GL_APIENTRYP PFNGLBINDVERTEXARRAYOESPROC) (GLuint array); +typedef void (GL_APIENTRYP PFNGLDELETEVERTEXARRAYSOESPROC) (GLsizei n, const GLuint *arrays); +typedef void (GL_APIENTRYP PFNGLGENVERTEXARRAYSOESPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (GL_APIENTRYP PFNGLISVERTEXARRAYOESPROC) (GLuint array); +typedef void (GL_APIENTRYP PFNGLGETPROGRAMBINARYOESPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +typedef void (GL_APIENTRYP PFNGLPROGRAMBINARYOESPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length); +typedef void (GL_APIENTRYP PFLGLDRAWARRAYSINSTANCEDANGLEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +typedef void (GL_APIENTRYP PFLGLDRAWELEMENTSINSTANCEDANGLEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount); +typedef void (GL_APIENTRYP PFLGLVERTEXATTRIBDIVISORANGLEPROC) (GLuint index, GLuint divisor); +//#define GL_UNSIGNED_INT_10_10_10_2_OES 0x8DF6 +#define GL_UNSIGNED_INT_2_10_10_10_REV_EXT 0x8368 +#define GL_SAMPLER_3D_OES 0x8B5F +#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 +# else +# include +# include +# include +# endif // BX_PLATFORM_ # define glProgramBinary glProgramBinaryOES # define glGetProgramBinary glGetProgramBinaryOES # define glBindVertexArray glBindVertexArrayOES @@ -214,7 +233,7 @@ typedef void (*PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC)(GLuint shader, GLsizei b #elif BX_PLATFORM_OSX # include "glcontext_nsgl.h" #elif BX_PLATFORM_IOS -# include "glcontext_ios.h" +# include "glcontext_eagl.h" #endif // BX_PLATFORM_ #if BGFX_CONFIG_DEBUG_GREMEDY && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX) diff --git a/tools/geometryc/geometryc.cpp b/tools/geometryc/geometryc.cpp index 45db67e9..4e260a27 100644 --- a/tools/geometryc/geometryc.cpp +++ b/tools/geometryc/geometryc.cpp @@ -345,6 +345,14 @@ inline uint32_t rgbaToAbgr(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a) ; } +struct GroupSortByMaterial +{ + bool operator()(const Group& _lhs, const Group& _rhs) + { + return _lhs.m_material < _rhs.m_material; + } +}; + int main(int _argc, const char* _argv[]) { bx::CommandLine cmdLine(_argc, _argv); @@ -635,14 +643,6 @@ int main(int _argc, const char* _argv[]) parseElapsed += now; int64_t convertElapsed = -now; - struct GroupSortByMaterial - { - bool operator()(const Group& _lhs, const Group& _rhs) - { - return _lhs.m_material < _rhs.m_material; - } - }; - std::sort(groups.begin(), groups.end(), GroupSortByMaterial() ); bool hasColor = false;