Merge branch 'master' of github.com:bkaradzic/bgfx

This commit is contained in:
bkaradzic 2013-11-18 20:46:12 -08:00
commit 8c609d77c8
5 changed files with 50 additions and 19 deletions

View file

@ -13,6 +13,7 @@
#include <bx/uint32_t.h>
#include <bx/thread.h>
#include <bx/os.h>
#define DEFAULT_WIDTH 1280
#define DEFAULT_HEIGHT 720
@ -225,7 +226,8 @@ namespace entry
NSString* appName = [[NSProcessInfo processInfo] processName];
[window setTitle:appName];
[window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
[window makeKeyAndOrderFront:nil];
[window makeKeyAndOrderFront:window];
[window setContentView:nil];
[[Window sharedDelegate] windowCreated:window];
bgfx::osxSetNSWindow(window);
@ -239,11 +241,18 @@ namespace entry
while (!(m_exit = [dg applicationHasTerminated]) )
{
DispatchEvent(WaitEvent() );
//DispatchEvent(WaitEvent() );
if (bgfx::RenderFrame::Exiting == bgfx::renderFrame() )
{
break;
}
while (DispatchEvent(PeekEvent() ) );
}
m_eventQueue.postExitEvent();
while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() );
thread.shutdown();
return 0;

View file

@ -12,6 +12,26 @@
#include <bx/bx.h>
namespace bgfx
{
struct RenderFrame
{
enum Enum
{
NoContext,
Render,
Exiting,
Count
};
};
/// WARNING: This call should be only used on platforms that don't
/// allow creating separate rendering thread. Proper use requires
/// changes inside lib.
RenderFrame::Enum renderFrame();
}
#if BX_PLATFORM_ANDROID
# include <android/native_window.h>

View file

@ -197,11 +197,6 @@ namespace bgfx
static BX_THREAD uint32_t s_threadIndex = 0;
static Context* s_ctx = NULL;
bool hasContext()
{
return NULL != s_ctx;
}
void setGraphicsDebuggerPresent(bool _present)
{
BX_TRACE("Graphics debugger is %spresent.", _present ? "" : "not ");
@ -710,7 +705,7 @@ namespace bgfx
s_ctx = BX_NEW(g_allocator, Context);
// On NaCl and iOS renderer is on the main thread.
s_ctx->init(!BX_PLATFORM_NACL && !BX_PLATFORM_IOS);
s_ctx->init(!BX_PLATFORM_NACL && !BX_PLATFORM_IOS && !BX_PLATFORM_OSX);
BX_TRACE("Init complete.");
}
@ -720,9 +715,10 @@ namespace bgfx
BX_TRACE("Shutdown...");
BGFX_CHECK_MAIN_THREAD();
s_ctx->shutdown();
Context* ctx = s_ctx; // it's going to be NULLd inside shutdown.
ctx->shutdown();
BX_DELETE(g_allocator, s_ctx);
BX_DELETE(g_allocator, ctx);
if (NULL != s_callbackStub)
{
@ -758,10 +754,20 @@ namespace bgfx
return s_ctx->frame();
}
bool renderFrame()
RenderFrame::Enum renderFrame()
{
if (NULL == s_ctx)
{
return RenderFrame::NoContext;
}
BGFX_CHECK_RENDER_THREAD();
return s_ctx->renderFrame();
if (s_ctx->renderFrame() )
{
return RenderFrame::Exiting;
}
return RenderFrame::Render;
}
const uint32_t g_uniformTypeSize[UniformType::Count+1] =
@ -891,6 +897,7 @@ namespace bgfx
}
#endif // BGFX_CONFIG_MULTITHREADED
s_ctx = NULL; // Can't be used by renderFrame at this point.
renderSemWait();
m_submit->destroy();

View file

@ -73,6 +73,7 @@ namespace bgfx
#include <bx/string.h>
#include <bx/os.h>
#include "bgfxplatform.h"
#include "image.h"
#define BGFX_CHUNK_MAGIC_FSH BX_MAKEFOURCC('F', 'S', 'H', 0x1)
@ -233,7 +234,6 @@ namespace bgfx
bool isGraphicsDebuggerPresent();
void release(const Memory* _mem);
const char* getAttribName(Attrib::Enum _attr);
bool renderFrame();
inline uint32_t gcd(uint32_t _a, uint32_t _b)
{

View file

@ -15,8 +15,6 @@ namespace bgfx
# include "glimports.h"
# undef GL_IMPORT
extern bool hasContext();
void naclSwapCompleteCb(void* /*_data*/, int32_t /*_result*/);
PP_CompletionCallback naclSwapComplete =
@ -80,10 +78,7 @@ namespace bgfx
s_ppapi.swap();
}
if (hasContext() )
{
renderFrame();
}
renderFrame();
}
static void GL_APIENTRY naclVertexAttribDivisor(GLuint _index, GLuint _divisor)