mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Merge branch 'master' of github.com:bkaradzic/bgfx
This commit is contained in:
commit
9852949a38
14 changed files with 502 additions and 76 deletions
241
examples/common/entry_ios.mm
Normal file
241
examples/common/entry_ios.mm
Normal file
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
|
||||
#if BX_PLATFORM_IOS
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <QuartzCore/CAEAGLLayer.h>
|
||||
|
||||
#include <bgfxplatform.h>
|
||||
#include <bx/uint32_t.h>
|
||||
#include <bx/thread.h>
|
||||
|
||||
#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<char**>(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<UIApplicationDelegate>
|
||||
{
|
||||
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
|
|
@ -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();
|
||||
|
|
|
@ -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 <X11/Xlib.h>
|
||||
|
||||
|
|
19
makefile
19
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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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*" }
|
||||
|
|
13
src/bgfx.cpp
13
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()
|
||||
|
|
|
@ -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
|
||||
|
|
42
src/glcontext_eagl.h
Executable file
42
src/glcontext_eagl.h
Executable file
|
@ -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__
|
89
src/glcontext_eagl.mm
Normal file
89
src/glcontext_eagl.mm
Normal file
|
@ -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 <UIKit/UIKit.h>
|
||||
# include <QuartzCore/CAEAGLLayer.h>
|
||||
# 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)
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
@ -2427,6 +2433,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)
|
||||
{
|
||||
|
@ -2439,6 +2446,7 @@ namespace bgfx
|
|||
s_drawElementsInstanced = glDrawElementsInstanced;
|
||||
}
|
||||
}
|
||||
# endif // !BX_PLATFORM_IOS
|
||||
#endif // !BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
|
||||
if (s_renderCtx.m_vaoSupport)
|
||||
|
@ -2628,7 +2636,7 @@ namespace bgfx
|
|||
|
||||
void Context::rendererSetMarker(const char* _marker, uint32_t /*_size*/)
|
||||
{
|
||||
GREMEDY_SETMARKER(_marker);
|
||||
GREMEDY_SETMARKER(_marker);
|
||||
}
|
||||
|
||||
void Context::rendererSubmit()
|
||||
|
@ -2639,7 +2647,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);
|
||||
|
||||
|
|
|
@ -66,9 +66,28 @@
|
|||
|
||||
#elif BGFX_CONFIG_RENDERER_OPENGLES2 || BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
# if BGFX_CONFIG_RENDERER_OPENGLES2
|
||||
# include <GLES2/gl2platform.h>
|
||||
# include <GLES2/gl2.h>
|
||||
# include <GLES2/gl2ext.h>
|
||||
# if BX_PLATFORM_IOS
|
||||
# include <OpenGLES/ES2/gl.h>
|
||||
# include <OpenGLES/ES2/glext.h>
|
||||
|
||||
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 <GLES2/gl2platform.h>
|
||||
# include <GLES2/gl2.h>
|
||||
# include <GLES2/gl2ext.h>
|
||||
# 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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue