Added SDL2 entry point.

This commit is contained in:
bkaradzic 2013-08-12 20:47:41 -07:00
parent ea38983f8d
commit e92eb7504b
3 changed files with 127 additions and 2 deletions

View File

@ -0,0 +1,123 @@
/*
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "entry.h"
#if BX_PLATFORM_OSX
#include <SDL2/SDL.h>
#include <bgfxplatform.h>
#include "entry_p.h"
#include <stdio.h>
#include <bx/thread.h>
namespace entry
{
struct MainThreadEntry
{
int m_argc;
char** m_argv;
static int32_t threadFunc(void* _userData);
};
struct Context
{
Context()
: m_window(NULL)
{
}
void run()
{
const char* argv[1] = { "sdl.so" };
m_mte.m_argc = 1;
m_mte.m_argv = const_cast<char**>(argv);
SDL_Init(SDL_INIT_VIDEO);
m_window = SDL_CreateWindow("bgfx"
, SDL_WINDOWPOS_UNDEFINED
, SDL_WINDOWPOS_UNDEFINED
, 1200
, 720
, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL
);
bgfx::sdlSetWindow(m_window);
m_thread.init(MainThreadEntry::threadFunc, &m_mte);
bool exit = false;
SDL_Event event;
while (!exit && SDL_WaitEvent(&event) )
{
switch (event.type)
{
case SDL_QUIT:
m_eventQueue.postExitEvent();
exit = true;
break;
}
}
m_thread.shutdown();
SDL_DestroyWindow(m_window);
SDL_Quit();
}
MainThreadEntry m_mte;
bx::Thread m_thread;
EventQueue m_eventQueue;
SDL_Window* m_window;
};
static Context s_ctx;
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)
{
}
int32_t MainThreadEntry::threadFunc(void* _userData)
{
MainThreadEntry* self = (MainThreadEntry*)_userData;
int32_t result = main(self->m_argc, self->m_argv);
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
return result;
}
} // namespace entry
int main(int _argc, const char* _argv[])
{
using namespace entry;
s_ctx.run();
}
#endif // BX_PLATFORM_

View File

@ -77,7 +77,7 @@ namespace bgfx
// If SDL.h is included before bgfxplatform.h we can enable SDL window
// interop convenience code.
# include <SDL_syswm.h>
# include <SDL2/SDL_syswm.h>
namespace bgfx
{
@ -101,6 +101,7 @@ namespace bgfx
return true;
}
} // namespace bgfx
#elif defined(_glfw3_h_)

View File

@ -95,11 +95,12 @@ function exampleProject(_name, _uuid)
configuration { "osx" }
files {
BGFX_DIR .. "examples/common/**.mm",
-- BGFX_DIR .. "examples/common/**.mm",
}
links {
"Cocoa.framework",
"OpenGL.framework",
"SDL2",
}
configuration { "ios*" }