summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/entry
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/common/entry')
-rw-r--r--3rdparty/bgfx/examples/common/entry/cmd.cpp18
-rw-r--r--3rdparty/bgfx/examples/common/entry/cmd.h2
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry.cpp359
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry.h70
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_android.cpp92
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp4
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_glfw.cpp192
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_ios.mm37
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_nacl.cpp231
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_noop.cpp4
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_osx.mm112
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_p.h29
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_sdl.cpp25
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_windows.cpp41
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_winrt.cx2
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_x11.cpp14
16 files changed, 662 insertions, 570 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/cmd.cpp b/3rdparty/bgfx/examples/common/entry/cmd.cpp
index ae3d14d3400..08fe6b27501 100644
--- a/3rdparty/bgfx/examples/common/entry/cmd.cpp
+++ b/3rdparty/bgfx/examples/common/entry/cmd.cpp
@@ -4,8 +4,9 @@
*/
#include <bx/allocator.h>
-#include <bx/hash.h>
#include <bx/commandline.h>
+#include <bx/hash.h>
+#include <bx/string.h>
#include "dbg.h"
#include "cmd.h"
@@ -28,7 +29,7 @@ struct CmdContext
void add(const char* _name, ConsoleFn _fn, void* _userData)
{
- uint32_t cmd = bx::hashMurmur2A(_name, (uint32_t)bx::strnlen(_name) );
+ uint32_t cmd = bx::hash<bx::HashMurmur2A>(_name, (uint32_t)bx::strLen(_name) );
BX_CHECK(m_lookup.end() == m_lookup.find(cmd), "Command \"%s\" already exist.", _name);
Func fn = { _fn, _userData };
m_lookup.insert(stl::make_pair(cmd, fn) );
@@ -46,7 +47,7 @@ struct CmdContext
if (argc > 0)
{
int err = -1;
- uint32_t cmd = bx::hashMurmur2A(argv[0], (uint32_t)bx::strnlen(argv[0]) );
+ uint32_t cmd = bx::hash<bx::HashMurmur2A>(argv[0], (uint32_t)bx::strLen(argv[0]) );
CmdLookup::iterator it = m_lookup.find(cmd);
if (it != m_lookup.end() )
{
@@ -104,7 +105,14 @@ void cmdAdd(const char* _name, ConsoleFn _fn, void* _userData)
s_cmdContext->add(_name, _fn, _userData);
}
-void cmdExec(const char* _cmd)
+void cmdExec(const char* _format, ...)
{
- s_cmdContext->exec(_cmd);
+ char tmp[2048];
+
+ va_list argList;
+ va_start(argList, _format);
+ bx::vsnprintf(tmp, BX_COUNTOF(tmp), _format, argList);
+ va_end(argList);
+
+ s_cmdContext->exec(tmp);
}
diff --git a/3rdparty/bgfx/examples/common/entry/cmd.h b/3rdparty/bgfx/examples/common/entry/cmd.h
index 2fa1ad41623..b11f1af7a9f 100644
--- a/3rdparty/bgfx/examples/common/entry/cmd.h
+++ b/3rdparty/bgfx/examples/common/entry/cmd.h
@@ -19,6 +19,6 @@ void cmdShutdown();
void cmdAdd(const char* _name, ConsoleFn _fn, void* _userData = NULL);
///
-void cmdExec(const char* _cmd);
+void cmdExec(const char* _format, ...);
#endif // CMD_H_HEADER_GUARD
diff --git a/3rdparty/bgfx/examples/common/entry/entry.cpp b/3rdparty/bgfx/examples/common/entry/entry.cpp
index 97701343dba..f476bb5e459 100644
--- a/3rdparty/bgfx/examples/common/entry/entry.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry.cpp
@@ -4,9 +4,9 @@
*/
#include <bx/bx.h>
+#include <bx/file.h>
+#include <bx/sort.h>
#include <bgfx/bgfx.h>
-#include <bx/string.h>
-#include <bx/crtimpl.h>
#include <time.h>
@@ -18,19 +18,16 @@
#include "cmd.h"
#include "input.h"
-#define RMT_ENABLED ENTRY_CONFIG_PROFILER
-#include <remotery/lib/Remotery.h>
-
-extern "C" int _main_(int _argc, char** _argv);
+extern "C" int32_t _main_(int32_t _argc, char** _argv);
namespace entry
{
static uint32_t s_debug = BGFX_DEBUG_NONE;
static uint32_t s_reset = BGFX_RESET_NONE;
+ static uint32_t s_width = ENTRY_DEFAULT_WIDTH;
+ static uint32_t s_height = ENTRY_DEFAULT_HEIGHT;
static bool s_exit = false;
- static Remotery* s_rmt = NULL;
-
static bx::FileReaderI* s_fileReader = NULL;
static bx::FileWriterI* s_fileWriter = NULL;
@@ -39,50 +36,33 @@ namespace entry
typedef bx::StringT<&g_allocator> String;
- void* rmtMalloc(void* /*_context*/, rmtU32 _size)
- {
- return BX_ALLOC(g_allocator, _size);
- }
-
- void* rmtRealloc(void* /*_context*/, void* _ptr, rmtU32 _size)
- {
- return BX_REALLOC(g_allocator, _ptr, _size);
- }
-
- void rmtFree(void* /*_context*/, void* _ptr)
- {
- BX_FREE(g_allocator, _ptr);
- }
-
static String s_currentDir;
-#if BX_CONFIG_CRT_FILE_READER_WRITER
- class FileReader : public bx::CrtFileReader
+ class FileReader : public bx::FileReader
{
- typedef bx::CrtFileReader super;
+ typedef bx::FileReader super;
public:
- virtual bool open(const char* _filePath, bx::Error* _err) BX_OVERRIDE
+ virtual bool open(const bx::FilePath& _filePath, bx::Error* _err) override
{
String filePath(s_currentDir);
- filePath.append(_filePath);
+ filePath.append(_filePath.get() );
return super::open(filePath.getPtr(), _err);
}
};
- class FileWriter : public bx::CrtFileWriter
+ class FileWriter : public bx::FileWriter
{
- typedef bx::CrtFileWriter super;
+ typedef bx::FileWriter super;
public:
- virtual bool open(const char* _filePath, bool _append, bx::Error* _err) BX_OVERRIDE
+ virtual bool open(const bx::FilePath& _filePath, bool _append, bx::Error* _err) override
{
String filePath(s_currentDir);
- filePath.append(_filePath);
+ filePath.append(_filePath.get() );
return super::open(filePath.getPtr(), _append, _err);
}
};
-#endif // BX_CONFIG_CRT_FILE_READER_WRITER
void setCurrentDir(const char* _dir)
{
@@ -95,7 +75,7 @@ namespace entry
BX_PRAGMA_DIAGNOSTIC_PUSH();
BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4459); // warning C4459: declaration of 's_allocator' hides global declaration
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wshadow");
- static bx::CrtAllocator s_allocator;
+ static bx::DefaultAllocator s_allocator;
return &s_allocator;
BX_PRAGMA_DIAGNOSTIC_POP();
}
@@ -254,13 +234,17 @@ BX_PRAGMA_DIAGNOSTIC_POP();
bool setOrToggle(uint32_t& _flags, const char* _name, uint32_t _bit, int _first, int _argc, char const* const* _argv)
{
- if (0 == bx::strncmp(_argv[_first], _name) )
+ if (0 == bx::strCmp(_argv[_first], _name) )
{
int arg = _first+1;
if (_argc > arg)
{
_flags &= ~_bit;
- _flags |= bx::toBool(_argv[arg]) ? _bit : 0;
+
+ bool set = false;
+ bx::fromString(&set, _argv[arg]);
+
+ _flags |= set ? _bit : 0;
}
else
{
@@ -275,13 +259,23 @@ BX_PRAGMA_DIAGNOSTIC_POP();
int cmdMouseLock(CmdContext* /*_context*/, void* /*_userData*/, int _argc, char const* const* _argv)
{
- if (_argc > 1)
+ if (1 < _argc)
{
- inputSetMouseLock(_argc > 1 ? bx::toBool(_argv[1]) : !inputIsMouseLocked() );
- return 0;
+ bool set = false;
+ if (2 < _argc)
+ {
+ bx::fromString(&set, _argv[1]);
+ inputSetMouseLock(set);
+ }
+ else
+ {
+ inputSetMouseLock(!inputIsMouseLocked() );
+ }
+
+ return bx::kExitSuccess;
}
- return 1;
+ return bx::kExitFailure;
}
int cmdGraphics(CmdContext* /*_context*/, void* /*_userData*/, int _argc, char const* const* _argv)
@@ -300,17 +294,19 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|| setOrToggle(s_reset, "depthclamp", BGFX_RESET_DEPTH_CLAMP, 1, _argc, _argv)
)
{
- return 0;
+ return bx::kExitSuccess;
}
else if (setOrToggle(s_debug, "stats", BGFX_DEBUG_STATS, 1, _argc, _argv)
|| setOrToggle(s_debug, "ifh", BGFX_DEBUG_IFH, 1, _argc, _argv)
|| setOrToggle(s_debug, "text", BGFX_DEBUG_TEXT, 1, _argc, _argv)
- || setOrToggle(s_debug, "wireframe", BGFX_DEBUG_WIREFRAME, 1, _argc, _argv) )
+ || setOrToggle(s_debug, "wireframe", BGFX_DEBUG_WIREFRAME, 1, _argc, _argv)
+ || setOrToggle(s_debug, "profiler", BGFX_DEBUG_PROFILER, 1, _argc, _argv)
+ )
{
bgfx::setDebug(s_debug);
- return 0;
+ return bx::kExitSuccess;
}
- else if (0 == bx::strncmp(_argv[1], "screenshot") )
+ else if (0 == bx::strCmp(_argv[1], "screenshot") )
{
bgfx::FrameBufferHandle fbh = BGFX_INVALID_HANDLE;
@@ -328,23 +324,23 @@ BX_PRAGMA_DIAGNOSTIC_POP();
bgfx::requestScreenShot(fbh, filePath);
}
- return 0;
+ return bx::kExitSuccess;
}
- else if (0 == bx::strncmp(_argv[1], "fullscreen") )
+ else if (0 == bx::strCmp(_argv[1], "fullscreen") )
{
WindowHandle window = { 0 };
toggleFullscreen(window);
- return 0;
+ return bx::kExitSuccess;
}
}
- return 1;
+ return bx::kExitFailure;
}
int cmdExit(CmdContext* /*_context*/, void* /*_userData*/, int /*_argc*/, char const* const* /*_argv*/)
{
s_exit = true;
- return 0;
+ return bx::kExitSuccess;
}
static const InputBinding s_bindings[] =
@@ -362,6 +358,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
{ entry::Key::F4, entry::Modifier::None, 1, NULL, "graphics hmd" },
{ entry::Key::F4, entry::Modifier::LeftShift, 1, NULL, "graphics hmdrecenter" },
{ entry::Key::F4, entry::Modifier::LeftCtrl, 1, NULL, "graphics hmddbg" },
+ { entry::Key::F6, entry::Modifier::None, 1, NULL, "graphics profiler" },
{ entry::Key::F7, entry::Modifier::None, 1, NULL, "graphics vsync" },
{ entry::Key::F8, entry::Modifier::None, 1, NULL, "graphics msaa" },
{ entry::Key::F9, entry::Modifier::None, 1, NULL, "graphics flush" },
@@ -380,87 +377,265 @@ BX_PRAGMA_DIAGNOSTIC_POP();
}
#endif // BX_PLATFORM_EMSCRIPTEN
- static App* s_apps = NULL;
+ static AppI* s_currentApp = NULL;
+ static AppI* s_apps = NULL;
+ static uint32_t s_numApps = 0;
- App::App(const char* _name)
+ static char s_restartArgs[1024] = { '\0' };
+
+ static AppI* getCurrentApp(AppI* _set = NULL)
{
- m_name = _name;
- m_next = s_apps;
+ if (NULL != _set)
+ {
+ s_currentApp = _set;
+ }
+ else if (NULL == s_currentApp)
+ {
+ s_currentApp = getFirstApp();
+ }
+
+ return s_currentApp;
+ }
+
+ static AppI* getNextWrap(AppI* _app)
+ {
+ AppI* next = _app->getNext();
+ if (NULL != next)
+ {
+ return next;
+ }
+
+ return getFirstApp();
+ }
+
+ int cmdApp(CmdContext* /*_context*/, void* /*_userData*/, int _argc, char const* const* _argv)
+ {
+ if (0 == bx::strCmp(_argv[1], "restart") )
+ {
+ if (2 == _argc)
+ {
+ bx::strCopy(s_restartArgs, BX_COUNTOF(s_restartArgs), getCurrentApp()->getName() );
+ return bx::kExitSuccess;
+ }
+
+ if (0 == bx::strCmp(_argv[2], "next") )
+ {
+ AppI* next = getNextWrap(getCurrentApp() );
+ bx::strCopy(s_restartArgs, BX_COUNTOF(s_restartArgs), next->getName() );
+ return bx::kExitSuccess;
+ }
+ else if (0 == bx::strCmp(_argv[2], "prev") )
+ {
+ AppI* prev = getCurrentApp();
+ for (AppI* app = getNextWrap(prev); app != getCurrentApp(); app = getNextWrap(app) )
+ {
+ prev = app;
+ }
+
+ bx::strCopy(s_restartArgs, BX_COUNTOF(s_restartArgs), prev->getName() );
+ return bx::kExitSuccess;
+ }
+
+ for (AppI* app = getFirstApp(); NULL != app; app = app->getNext() )
+ {
+ if (0 == bx::strCmp(_argv[2], app->getName() ) )
+ {
+ bx::strCopy(s_restartArgs, BX_COUNTOF(s_restartArgs), app->getName() );
+ return bx::kExitSuccess;
+ }
+ }
+ }
+
+ return bx::kExitFailure;
+ }
+
+ AppI::AppI(const char* _name, const char* _description)
+ {
+ m_name = _name;
+ m_description = _description;
+ m_next = s_apps;
+
s_apps = this;
+ s_numApps++;
+ }
+
+ AppI::~AppI()
+ {
+ for (AppI* prev = NULL, *app = s_apps, *next = app->getNext()
+ ; NULL != app
+ ; prev = app, app = next, next = app->getNext() )
+ {
+ if (app == this)
+ {
+ if (NULL != prev)
+ {
+ prev->m_next = next;
+ }
+ else
+ {
+ s_apps = next;
+ }
+
+ --s_numApps;
+
+ break;
+ }
+ }
}
- App::~App()
+ const char* AppI::getName() const
{
+ return m_name;
}
- App* getFirstApp()
+ const char* AppI::getDescription() const
+ {
+ return m_description;
+ }
+
+ AppI* AppI::getNext()
+ {
+ return m_next;
+ }
+
+ AppI* getFirstApp()
{
return s_apps;
}
- int runApp(AppI* _app, int _argc, char** _argv)
+ uint32_t getNumApps()
+ {
+ return s_numApps;
+ }
+
+ int runApp(AppI* _app, int _argc, const char* const* _argv)
{
- _app->init(_argc, _argv);
+ _app->init(_argc, _argv, s_width, s_height);
bgfx::frame();
WindowHandle defaultWindow = { 0 };
- setWindowSize(defaultWindow, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
+ setWindowSize(defaultWindow, s_width, s_height);
#if BX_PLATFORM_EMSCRIPTEN
s_app = _app;
emscripten_set_main_loop(&updateApp, -1, 1);
#else
- while (_app->update() );
+ while (_app->update() )
+ {
+ if (0 != bx::strLen(s_restartArgs) )
+ {
+ break;
+ }
+ }
#endif // BX_PLATFORM_EMSCRIPTEN
return _app->shutdown();
}
- int main(int _argc, char** _argv)
+ static int32_t sortApp(const void* _lhs, const void* _rhs)
{
- //DBG(BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME);
+ const AppI* lhs = *(const AppI**)_lhs;
+ const AppI* rhs = *(const AppI**)_rhs;
- if (BX_ENABLED(ENTRY_CONFIG_PROFILER) )
+ return bx::strCmpI(lhs->getName(), rhs->getName() );
+ }
+
+ static void sortApps()
+ {
+ if (2 > s_numApps)
{
- rmtSettings* settings = rmt_Settings();
- BX_WARN(NULL != settings, "Remotery is not enabled.");
- if (NULL != settings)
- {
- settings->malloc = rmtMalloc;
- settings->realloc = rmtRealloc;
- settings->free = rmtFree;
+ return;
+ }
- rmtError err = rmt_CreateGlobalInstance(&s_rmt);
- BX_WARN(RMT_ERROR_NONE != err, "Remotery failed to create global instance.");
- if (RMT_ERROR_NONE == err)
- {
- rmt_SetCurrentThreadName("Main");
- }
- else
- {
- s_rmt = NULL;
- }
- }
+ AppI** apps = (AppI**)BX_ALLOC(g_allocator, s_numApps*sizeof(AppI*) );
+
+ uint32_t ii = 0;
+ for (AppI* app = getFirstApp(); NULL != app; app = app->getNext() )
+ {
+ apps[ii++] = app;
}
+ bx::quickSort(apps, s_numApps, sizeof(AppI*), sortApp);
+
+ s_apps = apps[0];
+ for (ii = 1; ii < s_numApps; ++ii)
+ {
+ AppI* app = apps[ii-1];
+ app->m_next = apps[ii];
+ }
+ apps[s_numApps-1]->m_next = NULL;
+
+ BX_FREE(g_allocator, apps);
+ }
+
+ int main(int _argc, const char* const* _argv)
+ {
+ //DBG(BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME);
-#if BX_CONFIG_CRT_FILE_READER_WRITER
s_fileReader = BX_NEW(g_allocator, FileReader);
s_fileWriter = BX_NEW(g_allocator, FileWriter);
-#endif // BX_CONFIG_CRT_FILE_READER_WRITER
cmdInit();
cmdAdd("mouselock", cmdMouseLock);
cmdAdd("graphics", cmdGraphics );
cmdAdd("exit", cmdExit );
+ cmdAdd("app", cmdApp );
inputInit();
inputAddBindings("bindings", s_bindings);
entry::WindowHandle defaultWindow = { 0 };
- entry::setWindowTitle(defaultWindow, bx::baseName(_argv[0]) );
+
+ bx::FilePath fp(_argv[0]);
+ char title[bx::kMaxFilePath];
+ bx::strCopy(title, BX_COUNTOF(title), fp.getBaseName() );
+
+ entry::setWindowTitle(defaultWindow, title);
setWindowSize(defaultWindow, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
- int32_t result = ::_main_(_argc, _argv);
+ sortApps();
+
+ const char* find = "";
+ if (1 < _argc)
+ {
+ find = _argv[_argc-1];
+ }
+
+restart:
+ AppI* selected = NULL;
+
+ for (AppI* app = getFirstApp(); NULL != app; app = app->getNext() )
+ {
+ if (NULL == selected
+ && bx::strFindI(app->getName(), find) )
+ {
+ selected = app;
+ }
+#if 0
+ DBG("%c %s, %s"
+ , app == selected ? '>' : ' '
+ , app->getName()
+ , app->getDescription()
+ );
+#endif // 0
+ }
+
+ int32_t result = bx::kExitSuccess;
+ s_restartArgs[0] = '\0';
+ if (0 == s_numApps)
+ {
+ result = ::_main_(_argc, (char**)_argv);
+ }
+ else
+ {
+ result = runApp(getCurrentApp(selected), _argc, _argv);
+ }
+
+ if (0 != bx::strLen(s_restartArgs) )
+ {
+ find = s_restartArgs;
+ goto restart;
+ }
+
setCurrentDir("");
inputRemoveBindings("bindings");
@@ -468,19 +643,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
cmdShutdown();
-#if BX_CONFIG_CRT_FILE_READER_WRITER
BX_DELETE(g_allocator, s_fileReader);
s_fileReader = NULL;
BX_DELETE(g_allocator, s_fileWriter);
s_fileWriter = NULL;
-#endif // BX_CONFIG_CRT_FILE_READER_WRITER
-
- if (BX_ENABLED(ENTRY_CONFIG_PROFILER)
- && NULL != s_rmt)
- {
- rmt_DestroyGlobalInstance(s_rmt);
- }
return result;
}
@@ -597,6 +764,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
_debug = s_debug;
+ s_width = _width;
+ s_height = _height;
+
return s_exit;
}
@@ -774,6 +944,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
bx::AllocatorI* getAllocator()
{
+ if (NULL == g_allocator)
+ {
+ g_allocator = getDefaultAllocator();
+ }
+
return g_allocator;
}
diff --git a/3rdparty/bgfx/examples/common/entry/entry.h b/3rdparty/bgfx/examples/common/entry/entry.h
index cfdfd25dd81..9efe7c672aa 100644
--- a/3rdparty/bgfx/examples/common/entry/entry.h
+++ b/3rdparty/bgfx/examples/common/entry/entry.h
@@ -18,12 +18,21 @@ extern "C" int _main_(int _argc, char** _argv);
#define ENTRY_WINDOW_FLAG_ASPECT_RATIO UINT32_C(0x00000001)
#define ENTRY_WINDOW_FLAG_FRAME UINT32_C(0x00000002)
-#define ENTRY_IMPLEMENT_MAIN(_app) \
- int _main_(int _argc, char** _argv) \
- { \
- _app app; \
- return entry::runApp(&app, _argc, _argv); \
- }
+#ifndef ENTRY_CONFIG_IMPLEMENT_MAIN
+# define ENTRY_CONFIG_IMPLEMENT_MAIN 0
+#endif // ENTRY_CONFIG_IMPLEMENT_MAIN
+
+#if ENTRY_CONFIG_IMPLEMENT_MAIN
+#define ENTRY_IMPLEMENT_MAIN(_app, _name, _description) \
+ int _main_(int _argc, char** _argv) \
+ { \
+ _app app(_name, _description); \
+ return entry::runApp(&app, _argc, _argv); \
+ }
+#else
+#define ENTRY_IMPLEMENT_MAIN(_app, _name, _description) \
+ _app s_ ## _app ## App(_name, _description)
+#endif // ENTRY_CONFIG_IMPLEMENT_MAIN
namespace entry
{
@@ -267,45 +276,48 @@ namespace entry
bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset);
- struct BX_NO_VTABLE AppI
+ class BX_NO_VTABLE AppI
{
+ public:
+ ///
+ AppI(const char* _name, const char* _description);
+
+ ///
virtual ~AppI() = 0;
- virtual void init(int _argc, char** _argv) = 0;
+
+ ///
+ virtual void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) = 0;
+
+ ///
virtual int shutdown() = 0;
- virtual bool update() = 0;
- };
- inline AppI::~AppI()
- {
- }
+ ///
+ virtual bool update() = 0;
- class App : public AppI
- {
- public:
- App(const char* _name);
+ ///
+ const char* getName() const;
- virtual ~App();
+ ///
+ const char* getDescription() const;
- const char* getName() const
- {
- return m_name;
- }
+ ///
+ AppI* getNext();
- AppI* getNext()
- {
- return m_next;
- }
+ AppI* m_next;
private:
const char* m_name;
- App* m_next;
+ const char* m_description;
};
///
- App* getFirstApp();
+ AppI* getFirstApp();
+
+ ///
+ uint32_t getNumApps();
///
- int runApp(AppI* _app, int _argc, char** _argv);
+ int runApp(AppI* _app, int _argc, const char* const* _argv);
} // namespace entry
diff --git a/3rdparty/bgfx/examples/common/entry/entry_android.cpp b/3rdparty/bgfx/examples/common/entry/entry_android.cpp
index 78ed2f7a507..3c39f6085f0 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_android.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_android.cpp
@@ -9,8 +9,8 @@
#include <bgfx/platform.h>
-#include <stdio.h>
#include <bx/thread.h>
+#include <bx/file.h>
#include <android/input.h>
#include <android/log.h>
@@ -86,9 +86,87 @@ namespace entry
struct MainThreadEntry
{
int m_argc;
- char** m_argv;
+ const char* const* m_argv;
- static int32_t threadFunc(void* _userData);
+ static int32_t threadFunc(bx::Thread* _thread, void* _userData);
+ };
+
+ class FileReaderAndroid : public bx::FileReaderI
+ {
+ public:
+ FileReaderAndroid(AAssetManager* _assetManager, AAsset* _file)
+ : m_assetManager(_assetManager)
+ , m_file(_file)
+ , m_open(false)
+ {
+ }
+
+ virtual ~FileReaderAndroid()
+ {
+ close();
+ }
+
+ virtual bool open(const bx::FilePath& _filePath, bx::Error* _err) override
+ {
+ BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors.");
+
+ if (NULL != m_file)
+ {
+ BX_ERROR_SET(_err, BX_ERROR_READERWRITER_ALREADY_OPEN, "FileReader: File is already open.");
+ return false;
+ }
+
+ m_file = AAssetManager_open(m_assetManager, _filePath.get(), AASSET_MODE_RANDOM);
+ if (NULL == m_file)
+ {
+ BX_ERROR_SET(_err, BX_ERROR_READERWRITER_OPEN, "FileReader: Failed to open file.");
+ return false;
+ }
+
+ m_open = true;
+ return true;
+ }
+
+ virtual void close() override
+ {
+ if (m_open
+ && NULL != m_file)
+ {
+ AAsset_close(m_file);
+ m_file = NULL;
+ }
+ }
+
+ virtual int64_t seek(int64_t _offset, bx::Whence::Enum _whence) override
+ {
+ BX_CHECK(NULL != m_file, "Reader/Writer file is not open.");
+ return AAsset_seek64(m_file, _offset, _whence);
+
+ }
+
+ virtual int32_t read(void* _data, int32_t _size, bx::Error* _err) override
+ {
+ BX_CHECK(NULL != m_file, "Reader/Writer file is not open.");
+ BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors.");
+
+ int32_t size = (int32_t)AAsset_read(m_file, _data, _size);
+ if (size != _size)
+ {
+ if (0 == AAsset_getRemainingLength(m_file) )
+ {
+ BX_ERROR_SET(_err, BX_ERROR_READERWRITER_EOF, "FileReader: EOF.");
+ }
+
+ return size >= 0 ? size : 0;
+ }
+
+ return size;
+ }
+
+ private:
+ AAssetManager* m_assetManager;
+ AAsset* m_file;
+ bool m_open;
};
struct Context
@@ -119,9 +197,9 @@ namespace entry
, 0
);
- const char* argv[1] = { "android.so" };
+ const char* const argv[1] = { "android.so" };
m_mte.m_argc = 1;
- m_mte.m_argv = const_cast<char**>(argv);
+ m_mte.m_argv = argv;
while (0 == m_app->destroyRequested)
{
@@ -472,8 +550,10 @@ namespace entry
BX_UNUSED(_handle, _lock);
}
- int32_t MainThreadEntry::threadFunc(void* _userData)
+ int32_t MainThreadEntry::threadFunc(bx::Thread* _thread, void* _userData)
{
+ BX_UNUSED(_thread);
+
int32_t result = chdir("/sdcard/bgfx/examples/runtime");
BX_CHECK(0 == result, "Failed to chdir to dir. android.permission.WRITE_EXTERNAL_STORAGE?", errno);
diff --git a/3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp b/3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp
index 9cabff5e838..87857612ee5 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp
@@ -86,7 +86,7 @@ namespace entry
}
}
- int32_t run(int _argc, char** _argv)
+ int32_t run(int _argc, const char* const* _argv)
{
emscripten_set_mousedown_callback("#canvas", this, true, mouseCb);
emscripten_set_mouseup_callback("#canvas", this, true, mouseCb);
@@ -397,7 +397,7 @@ namespace entry
}
}
-int main(int _argc, char** _argv)
+int main(int _argc, const char* const* _argv)
{
using namespace entry;
return s_ctx.run(_argc, _argv);
diff --git a/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp b/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp
index 0ff8fd31c64..9c3ad35894e 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp
@@ -28,8 +28,9 @@
#include <bgfx/platform.h>
-#include <bx/thread.h>
#include <bx/handlealloc.h>
+#include <bx/thread.h>
+#include <bx/mutex.h>
#include <tinystl/string.h>
#include "dbg.h"
@@ -227,9 +228,9 @@ namespace entry
struct MainThreadEntry
{
int m_argc;
- char** m_argv;
+ const char* const* m_argv;
- static int32_t threadFunc(void* _userData);
+ static int32_t threadFunc(bx::Thread* _thread, void* _userData);
};
enum MsgType
@@ -308,86 +309,92 @@ namespace entry
struct Context
{
Context()
- : m_scrollPos(0.0)
+ : m_msgs(getAllocator() )
+ , m_scrollPos(0.0f)
{
bx::memSet(s_translateKey, 0, sizeof(s_translateKey));
- s_translateKey[GLFW_KEY_ESCAPE] = Key::Esc;
- s_translateKey[GLFW_KEY_ENTER] = Key::Return;
- s_translateKey[GLFW_KEY_TAB] = Key::Tab;
- s_translateKey[GLFW_KEY_BACKSPACE] = Key::Backspace;
- s_translateKey[GLFW_KEY_SPACE] = Key::Space;
- s_translateKey[GLFW_KEY_UP] = Key::Up;
- s_translateKey[GLFW_KEY_DOWN] = Key::Down;
- s_translateKey[GLFW_KEY_LEFT] = Key::Left;
- s_translateKey[GLFW_KEY_RIGHT] = Key::Right;
- s_translateKey[GLFW_KEY_PAGE_UP] = Key::PageUp;
- s_translateKey[GLFW_KEY_PAGE_DOWN] = Key::PageDown;
- s_translateKey[GLFW_KEY_HOME] = Key::Home;
- s_translateKey[GLFW_KEY_END] = Key::End;
+ s_translateKey[GLFW_KEY_ESCAPE] = Key::Esc;
+ s_translateKey[GLFW_KEY_ENTER] = Key::Return;
+ s_translateKey[GLFW_KEY_TAB] = Key::Tab;
+ s_translateKey[GLFW_KEY_BACKSPACE] = Key::Backspace;
+ s_translateKey[GLFW_KEY_SPACE] = Key::Space;
+ s_translateKey[GLFW_KEY_UP] = Key::Up;
+ s_translateKey[GLFW_KEY_DOWN] = Key::Down;
+ s_translateKey[GLFW_KEY_LEFT] = Key::Left;
+ s_translateKey[GLFW_KEY_RIGHT] = Key::Right;
+ s_translateKey[GLFW_KEY_PAGE_UP] = Key::PageUp;
+ s_translateKey[GLFW_KEY_PAGE_DOWN] = Key::PageDown;
+ s_translateKey[GLFW_KEY_HOME] = Key::Home;
+ s_translateKey[GLFW_KEY_END] = Key::End;
s_translateKey[GLFW_KEY_PRINT_SCREEN] = Key::Print;
- s_translateKey[GLFW_KEY_KP_ADD] = Key::Plus;
+ s_translateKey[GLFW_KEY_KP_ADD] = Key::Plus;
+ s_translateKey[GLFW_KEY_EQUAL] = Key::Plus;
s_translateKey[GLFW_KEY_KP_SUBTRACT] = Key::Minus;
- s_translateKey[GLFW_KEY_F1] = Key::F1;
- s_translateKey[GLFW_KEY_F2] = Key::F2;
- s_translateKey[GLFW_KEY_F3] = Key::F3;
- s_translateKey[GLFW_KEY_F4] = Key::F4;
- s_translateKey[GLFW_KEY_F5] = Key::F5;
- s_translateKey[GLFW_KEY_F6] = Key::F6;
- s_translateKey[GLFW_KEY_F7] = Key::F7;
- s_translateKey[GLFW_KEY_F8] = Key::F8;
- s_translateKey[GLFW_KEY_F9] = Key::F9;
- s_translateKey[GLFW_KEY_F10] = Key::F10;
- s_translateKey[GLFW_KEY_F11] = Key::F11;
- s_translateKey[GLFW_KEY_F12] = Key::F12;
- s_translateKey[GLFW_KEY_KP_0] = Key::NumPad0;
- s_translateKey[GLFW_KEY_KP_1] = Key::NumPad1;
- s_translateKey[GLFW_KEY_KP_2] = Key::NumPad2;
- s_translateKey[GLFW_KEY_KP_3] = Key::NumPad3;
- s_translateKey[GLFW_KEY_KP_4] = Key::NumPad4;
- s_translateKey[GLFW_KEY_KP_5] = Key::NumPad5;
- s_translateKey[GLFW_KEY_KP_6] = Key::NumPad6;
- s_translateKey[GLFW_KEY_KP_7] = Key::NumPad7;
- s_translateKey[GLFW_KEY_KP_8] = Key::NumPad8;
- s_translateKey[GLFW_KEY_KP_9] = Key::NumPad9;
- s_translateKey[GLFW_KEY_0] = Key::Key0;
- s_translateKey[GLFW_KEY_1] = Key::Key1;
- s_translateKey[GLFW_KEY_2] = Key::Key2;
- s_translateKey[GLFW_KEY_3] = Key::Key3;
- s_translateKey[GLFW_KEY_4] = Key::Key4;
- s_translateKey[GLFW_KEY_5] = Key::Key5;
- s_translateKey[GLFW_KEY_6] = Key::Key6;
- s_translateKey[GLFW_KEY_7] = Key::Key7;
- s_translateKey[GLFW_KEY_8] = Key::Key8;
- s_translateKey[GLFW_KEY_9] = Key::Key9;
- s_translateKey[GLFW_KEY_A] = Key::KeyA;
- s_translateKey[GLFW_KEY_B] = Key::KeyB;
- s_translateKey[GLFW_KEY_C] = Key::KeyC;
- s_translateKey[GLFW_KEY_D] = Key::KeyD;
- s_translateKey[GLFW_KEY_E] = Key::KeyE;
- s_translateKey[GLFW_KEY_F] = Key::KeyF;
- s_translateKey[GLFW_KEY_G] = Key::KeyG;
- s_translateKey[GLFW_KEY_H] = Key::KeyH;
- s_translateKey[GLFW_KEY_I] = Key::KeyI;
- s_translateKey[GLFW_KEY_J] = Key::KeyJ;
- s_translateKey[GLFW_KEY_K] = Key::KeyK;
- s_translateKey[GLFW_KEY_L] = Key::KeyL;
- s_translateKey[GLFW_KEY_M] = Key::KeyM;
- s_translateKey[GLFW_KEY_N] = Key::KeyN;
- s_translateKey[GLFW_KEY_O] = Key::KeyO;
- s_translateKey[GLFW_KEY_P] = Key::KeyP;
- s_translateKey[GLFW_KEY_Q] = Key::KeyQ;
- s_translateKey[GLFW_KEY_R] = Key::KeyR;
- s_translateKey[GLFW_KEY_S] = Key::KeyS;
- s_translateKey[GLFW_KEY_T] = Key::KeyT;
- s_translateKey[GLFW_KEY_U] = Key::KeyU;
- s_translateKey[GLFW_KEY_V] = Key::KeyV;
- s_translateKey[GLFW_KEY_W] = Key::KeyW;
- s_translateKey[GLFW_KEY_X] = Key::KeyX;
- s_translateKey[GLFW_KEY_Y] = Key::KeyY;
- s_translateKey[GLFW_KEY_Z] = Key::KeyZ;
+ s_translateKey[GLFW_KEY_MINUS] = Key::Minus;
+ s_translateKey[GLFW_KEY_COMMA] = Key::Comma;
+ s_translateKey[GLFW_KEY_PERIOD] = Key::Period;
+ s_translateKey[GLFW_KEY_SLASH] = Key::Slash;
+ s_translateKey[GLFW_KEY_F1] = Key::F1;
+ s_translateKey[GLFW_KEY_F2] = Key::F2;
+ s_translateKey[GLFW_KEY_F3] = Key::F3;
+ s_translateKey[GLFW_KEY_F4] = Key::F4;
+ s_translateKey[GLFW_KEY_F5] = Key::F5;
+ s_translateKey[GLFW_KEY_F6] = Key::F6;
+ s_translateKey[GLFW_KEY_F7] = Key::F7;
+ s_translateKey[GLFW_KEY_F8] = Key::F8;
+ s_translateKey[GLFW_KEY_F9] = Key::F9;
+ s_translateKey[GLFW_KEY_F10] = Key::F10;
+ s_translateKey[GLFW_KEY_F11] = Key::F11;
+ s_translateKey[GLFW_KEY_F12] = Key::F12;
+ s_translateKey[GLFW_KEY_KP_0] = Key::NumPad0;
+ s_translateKey[GLFW_KEY_KP_1] = Key::NumPad1;
+ s_translateKey[GLFW_KEY_KP_2] = Key::NumPad2;
+ s_translateKey[GLFW_KEY_KP_3] = Key::NumPad3;
+ s_translateKey[GLFW_KEY_KP_4] = Key::NumPad4;
+ s_translateKey[GLFW_KEY_KP_5] = Key::NumPad5;
+ s_translateKey[GLFW_KEY_KP_6] = Key::NumPad6;
+ s_translateKey[GLFW_KEY_KP_7] = Key::NumPad7;
+ s_translateKey[GLFW_KEY_KP_8] = Key::NumPad8;
+ s_translateKey[GLFW_KEY_KP_9] = Key::NumPad9;
+ s_translateKey[GLFW_KEY_0] = Key::Key0;
+ s_translateKey[GLFW_KEY_1] = Key::Key1;
+ s_translateKey[GLFW_KEY_2] = Key::Key2;
+ s_translateKey[GLFW_KEY_3] = Key::Key3;
+ s_translateKey[GLFW_KEY_4] = Key::Key4;
+ s_translateKey[GLFW_KEY_5] = Key::Key5;
+ s_translateKey[GLFW_KEY_6] = Key::Key6;
+ s_translateKey[GLFW_KEY_7] = Key::Key7;
+ s_translateKey[GLFW_KEY_8] = Key::Key8;
+ s_translateKey[GLFW_KEY_9] = Key::Key9;
+ s_translateKey[GLFW_KEY_A] = Key::KeyA;
+ s_translateKey[GLFW_KEY_B] = Key::KeyB;
+ s_translateKey[GLFW_KEY_C] = Key::KeyC;
+ s_translateKey[GLFW_KEY_D] = Key::KeyD;
+ s_translateKey[GLFW_KEY_E] = Key::KeyE;
+ s_translateKey[GLFW_KEY_F] = Key::KeyF;
+ s_translateKey[GLFW_KEY_G] = Key::KeyG;
+ s_translateKey[GLFW_KEY_H] = Key::KeyH;
+ s_translateKey[GLFW_KEY_I] = Key::KeyI;
+ s_translateKey[GLFW_KEY_J] = Key::KeyJ;
+ s_translateKey[GLFW_KEY_K] = Key::KeyK;
+ s_translateKey[GLFW_KEY_L] = Key::KeyL;
+ s_translateKey[GLFW_KEY_M] = Key::KeyM;
+ s_translateKey[GLFW_KEY_N] = Key::KeyN;
+ s_translateKey[GLFW_KEY_O] = Key::KeyO;
+ s_translateKey[GLFW_KEY_P] = Key::KeyP;
+ s_translateKey[GLFW_KEY_Q] = Key::KeyQ;
+ s_translateKey[GLFW_KEY_R] = Key::KeyR;
+ s_translateKey[GLFW_KEY_S] = Key::KeyS;
+ s_translateKey[GLFW_KEY_T] = Key::KeyT;
+ s_translateKey[GLFW_KEY_U] = Key::KeyU;
+ s_translateKey[GLFW_KEY_V] = Key::KeyV;
+ s_translateKey[GLFW_KEY_W] = Key::KeyW;
+ s_translateKey[GLFW_KEY_X] = Key::KeyX;
+ s_translateKey[GLFW_KEY_Y] = Key::KeyY;
+ s_translateKey[GLFW_KEY_Z] = Key::KeyZ;
}
- int run(int _argc, char** _argv)
+ int run(int _argc, const char* const* _argv)
{
m_mte.m_argc = _argc;
m_mte.m_argv = _argv;
@@ -397,7 +404,7 @@ namespace entry
if (!glfwInit() )
{
DBG("glfwInit failed!");
- return EXIT_FAILURE;
+ return bx::kExitFailure;
}
glfwSetJoystickCallback(joystickCb);
@@ -416,7 +423,7 @@ namespace entry
{
DBG("glfwCreateWindow failed!");
glfwTerminate();
- return EXIT_FAILURE;
+ return bx::kExitFailure;
}
glfwSetKeyCallback(m_windows[0], keyCb);
@@ -533,17 +540,25 @@ namespace entry
case GLFW_WINDOW_TOGGLE_FULL_SCREEN:
{
GLFWwindow* window = m_windows[msg->m_handle.idx];
- if (glfwGetWindowMonitor(window))
+ if (glfwGetWindowMonitor(window) )
{
- int width, height;
- glfwGetWindowSize(window, &width, &height);
- glfwSetWindowMonitor(window, NULL, 0, 0, width, height, 0);
+ glfwSetWindowMonitor(window
+ , NULL
+ , m_oldX
+ , m_oldY
+ , m_oldWidth
+ , m_oldHeight
+ , 0
+ );
}
else
{
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
if (NULL != monitor)
{
+ glfwGetWindowPos(window, &m_oldX, &m_oldY);
+ glfwGetWindowSize(window, &m_oldWidth, &m_oldHeight);
+
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
glfwSetWindowMonitor(window
, monitor
@@ -624,6 +639,11 @@ namespace entry
bx::SpScUnboundedQueueT<Msg> m_msgs;
+ int32_t m_oldX;
+ int32_t m_oldY;
+ int32_t m_oldWidth;
+ int32_t m_oldHeight;
+
double m_scrollPos;
};
@@ -818,8 +838,10 @@ namespace entry
glfwPostEmptyEvent();
}
- int32_t MainThreadEntry::threadFunc(void* _userData)
+ int32_t MainThreadEntry::threadFunc(bx::Thread* _thread, void* _userData)
{
+ BX_UNUSED(_thread);
+
MainThreadEntry* self = (MainThreadEntry*)_userData;
int32_t result = main(self->m_argc, self->m_argv);
@@ -833,7 +855,7 @@ namespace entry
}
}
-int main(int _argc, char** _argv)
+int main(int _argc, const char* const* _argv)
{
using namespace entry;
return s_ctx.run(_argc, _argv);
diff --git a/3rdparty/bgfx/examples/common/entry/entry_ios.mm b/3rdparty/bgfx/examples/common/entry/entry_ios.mm
index c2dbdce65e1..d781089fb63 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_ios.mm
+++ b/3rdparty/bgfx/examples/common/entry/entry_ios.mm
@@ -27,9 +27,9 @@ namespace entry
struct MainThreadEntry
{
int m_argc;
- char** m_argv;
+ const char* const* m_argv;
- static int32_t threadFunc(void* _userData);
+ static int32_t threadFunc(bx::Thread* _thread, void* _userData);
};
static WindowHandle s_defaultWindow = { 0 };
@@ -38,9 +38,9 @@ namespace entry
{
Context(uint32_t _width, uint32_t _height)
{
- static const char* argv[1] = { "ios" };
+ const char* const argv[1] = { "ios" };
m_mte.m_argc = 1;
- m_mte.m_argv = const_cast<char**>(argv);
+ m_mte.m_argv = argv;
m_eventQueue.postSizeEvent(s_defaultWindow, _width, _height);
@@ -63,19 +63,22 @@ namespace entry
static Context* s_ctx;
- int32_t MainThreadEntry::threadFunc(void* _userData)
+ int32_t MainThreadEntry::threadFunc(bx::Thread* _thread, void* _userData)
{
+ BX_UNUSED(_thread);
+
CFBundleRef mainBundle = CFBundleGetMainBundle();
- if ( mainBundle != nil )
+ if (mainBundle != nil)
{
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
- if ( resourcesURL != nil )
+ if (resourcesURL != nil)
{
char path[PATH_MAX];
- if (CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX) )
+ if (CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8*)path, PATH_MAX) )
{
chdir(path);
}
+
CFRelease(resourcesURL);
}
}
@@ -247,6 +250,8 @@ static void* m_device = NULL;
BX_UNUSED(touches);
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self];
+ touchLocation.x *= self.contentScaleFactor;
+ touchLocation.y *= self.contentScaleFactor;
s_ctx->m_eventQueue.postMouseEvent(s_defaultWindow, touchLocation.x, touchLocation.y, 0);
s_ctx->m_eventQueue.postMouseEvent(s_defaultWindow, touchLocation.x, touchLocation.y, 0, MouseButton::Left, true);
@@ -257,6 +262,9 @@ static void* m_device = NULL;
BX_UNUSED(touches);
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self];
+ touchLocation.x *= self.contentScaleFactor;
+ touchLocation.y *= self.contentScaleFactor;
+
s_ctx->m_eventQueue.postMouseEvent(s_defaultWindow, touchLocation.x, touchLocation.y, 0, MouseButton::Left, false);
}
@@ -265,6 +273,9 @@ static void* m_device = NULL;
BX_UNUSED(touches);
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self];
+ touchLocation.x *= self.contentScaleFactor;
+ touchLocation.y *= self.contentScaleFactor;
+
s_ctx->m_eventQueue.postMouseEvent(s_defaultWindow, touchLocation.x, touchLocation.y, 0);
}
@@ -273,6 +284,9 @@ static void* m_device = NULL;
BX_UNUSED(touches);
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self];
+ touchLocation.x *= self.contentScaleFactor;
+ touchLocation.y *= self.contentScaleFactor;
+
s_ctx->m_eventQueue.postMouseEvent(s_defaultWindow, touchLocation.x, touchLocation.y, 0, MouseButton::Left, false);
}
@@ -312,8 +326,7 @@ static void* m_device = NULL;
[m_window makeKeyAndVisible];
- //float scaleFactor = [[UIScreen mainScreen] scale]; // should use this, but needs to further pass the value to the `nvgBeginFrame()` call's `devicePixelRatio` parameter in `ExampleNanoVG` class' `update()` method so it can actually work properly.
- float scaleFactor = 1.0f;
+ float scaleFactor = [[UIScreen mainScreen] scale];
[m_view setContentScaleFactor: scaleFactor ];
s_ctx = new Context((uint32_t)(scaleFactor*rect.size.width), (uint32_t)(scaleFactor*rect.size.height));
@@ -361,10 +374,10 @@ static void* m_device = NULL;
@end
-int main(int _argc, char* _argv[])
+int main(int _argc, const char* const* _argv)
{
NSAutoreleasePool* pool = [ [NSAutoreleasePool alloc] init];
- int exitCode = UIApplicationMain(_argc, _argv, @"UIApplication", NSStringFromClass([AppDelegate class]) );
+ int exitCode = UIApplicationMain(_argc, (char**)_argv, @"UIApplication", NSStringFromClass([AppDelegate class]) );
[pool release];
return exitCode;
}
diff --git a/3rdparty/bgfx/examples/common/entry/entry_nacl.cpp b/3rdparty/bgfx/examples/common/entry/entry_nacl.cpp
deleted file mode 100644
index b51a96e3446..00000000000
--- a/3rdparty/bgfx/examples/common/entry/entry_nacl.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright 2011-2017 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
- */
-
-#include "entry_p.h"
-
-#if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_NACL
-
-#include <bgfx/platform.h>
-
-#include <pthread.h>
-#include <string>
-
-#include <ppapi/c/pp_errors.h>
-#include <ppapi/c/pp_module.h>
-#include <ppapi/c/ppb.h>
-#include <ppapi/c/ppb_core.h>
-#include <ppapi/c/ppb_graphics_3d.h>
-#include <ppapi/c/ppb_instance.h>
-#include <ppapi/c/ppb_message_loop.h>
-#include <ppapi/c/ppb_url_loader.h>
-#include <ppapi/c/ppb_url_request_info.h>
-#include <ppapi/c/ppb_url_response_info.h>
-#include <ppapi/c/ppb_var.h>
-#include <ppapi/c/ppp.h>
-#include <ppapi/c/ppp_instance.h>
-#include <ppapi/gles2/gl2ext_ppapi.h>
-
-#include <bx/thread.h>
-
-#include "entry.h"
-
-namespace entry
-{
- const PPB_Core* g_coreInterface;
- const PPB_Instance* g_instInterface;
- const PPB_Graphics3D* g_graphicsInterface;
- const PPB_MessageLoop* g_messageLoopInterface;
- const PPB_URLLoader* g_urlLoaderInterface;
- const PPB_URLRequestInfo* g_urlRequestInterface;
- const PPB_URLResponseInfo* g_urlResponseInterface;
- const PPB_Var* g_varInterface;
- PP_Instance g_instance;
-
- const Event* poll()
- {
- return NULL;
- }
-
- const Event* poll(WindowHandle _handle)
- {
- BX_UNUSED(_handle);
- return NULL;
- }
-
- void release(const Event* _event)
- {
- BX_UNUSED(_event);
- }
-
- WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags, const char* _title)
- {
- BX_UNUSED(_x, _y, _width, _height, _flags, _title);
- WindowHandle handle = { UINT16_MAX };
- return handle;
- }
-
- void destroyWindow(WindowHandle _handle)
- {
- BX_UNUSED(_handle);
- }
-
- void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
- {
- BX_UNUSED(_handle, _x, _y);
- }
-
- void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
- {
- BX_UNUSED(_handle, _width, _height);
- }
-
- void setWindowTitle(WindowHandle _handle, const char* _title)
- {
- BX_UNUSED(_handle, _title);
- }
-
- void toggleWindowFrame(WindowHandle _handle)
- {
- BX_UNUSED(_handle);
- }
-
- void toggleFullscreen(WindowHandle _handle)
- {
- BX_UNUSED(_handle);
- }
-
- void setMouseLock(WindowHandle _handle, bool _lock)
- {
- BX_UNUSED(_handle, _lock);
- }
-
- template<typename Type>
- bool initializeInterface(PPB_GetInterface _interface, const char* _name, const Type*& _result)
- {
- _result = reinterpret_cast<const Type*>(_interface(_name) );
-// DBG("%p %s", _result, _name);
- return NULL != _result;
- }
-
- struct MainThreadEntry
- {
- int m_argc;
- char** m_argv;
-
- static int32_t threadFunc(void* _userData);
- };
-
- struct NaclContext
- {
- NaclContext()
- {
- static const char* argv[1] = { "nacl.nexe" };
- m_mte.m_argc = 1;
- m_mte.m_argv = const_cast<char**>(argv);
-
- m_thread.init(MainThreadEntry::threadFunc, &m_mte);
- }
-
- ~NaclContext()
- {
- m_thread.shutdown();
- }
-
- MainThreadEntry m_mte;
- bx::Thread m_thread;
- };
-
- static NaclContext* s_ctx;
-
- int32_t MainThreadEntry::threadFunc(void* _userData)
- {
- MainThreadEntry* self = (MainThreadEntry*)_userData;
-
- PP_Resource resource = g_messageLoopInterface->Create(g_instance);
- g_messageLoopInterface->AttachToCurrentThread(resource);
-
- int32_t result = main(self->m_argc, self->m_argv);
- return result;
- }
-
- static PP_Bool naclInstanceDidCreate(PP_Instance _instance, uint32_t /*_argc*/, const char* /*_argn*/[], const char* /*_argv*/[])
- {
- g_instance = _instance; // one instance only!
-
- if (bgfx::naclSetInterfaces(g_instance, g_instInterface, g_graphicsInterface, NULL) )
- {
- s_ctx = new NaclContext;
- return PP_TRUE;
- }
-
- return PP_FALSE;
- }
-
- static void naclInstanceDidDestroy(PP_Instance _instance)
- {
- BX_UNUSED(_instance);
- delete s_ctx;
- }
-
- static void naclInstanceDidChangeView(PP_Instance /*_instance*/, PP_Resource /*_view*/)
- {
- }
-
- static void naclInstanceDidChangeFocus(PP_Instance /*_instance*/, PP_Bool /*_focus*/)
- {
- }
-
- static PP_Bool naclInstanceHandleDocumentLoad(PP_Instance /*_instance*/, PP_Resource /*_urlLoader*/)
- {
- return PP_FALSE;
- }
-
-} // namespace entry
-
-using namespace entry;
-
-PP_EXPORT const void* PPP_GetInterface(const char* _name)
-{
- if (0 == bx::strncmp(_name, PPP_INSTANCE_INTERFACE) )
- {
- static PPP_Instance instanceInterface =
- {
- &naclInstanceDidCreate,
- &naclInstanceDidDestroy,
- &naclInstanceDidChangeView,
- &naclInstanceDidChangeFocus,
- &naclInstanceHandleDocumentLoad,
- };
-
- return &instanceInterface;
- }
-
- return NULL;
-}
-
-PP_EXPORT int32_t PPP_InitializeModule(PP_Module _module, PPB_GetInterface _interface)
-{
- DBG("PPAPI version: %d", PPAPI_RELEASE);
-
- BX_UNUSED(_module);
- bool result = true;
- result &= initializeInterface(_interface, PPB_CORE_INTERFACE, g_coreInterface);
- result &= initializeInterface(_interface, PPB_GRAPHICS_3D_INTERFACE, g_graphicsInterface);
- result &= initializeInterface(_interface, PPB_INSTANCE_INTERFACE, g_instInterface);
- result &= initializeInterface(_interface, PPB_MESSAGELOOP_INTERFACE, g_messageLoopInterface);
- result &= initializeInterface(_interface, PPB_URLLOADER_INTERFACE, g_urlLoaderInterface);
- result &= initializeInterface(_interface, PPB_URLREQUESTINFO_INTERFACE, g_urlRequestInterface);
- result &= initializeInterface(_interface, PPB_URLRESPONSEINFO_INTERFACE, g_urlResponseInterface);
- result &= initializeInterface(_interface, PPB_VAR_INTERFACE, g_varInterface);
- result &= glInitializePPAPI(_interface);
-
- return result ? PP_OK : PP_ERROR_NOINTERFACE;
-}
-
-PP_EXPORT void PPP_ShutdownModule()
-{
-}
-
-#endif // ENTRY_CONFIG_USE_NATIVE && BX_PLATFROM_NACL
diff --git a/3rdparty/bgfx/examples/common/entry/entry_noop.cpp b/3rdparty/bgfx/examples/common/entry/entry_noop.cpp
index 1e85e2df28b..a0007bc5c98 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_noop.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_noop.cpp
@@ -7,8 +7,6 @@
#if ENTRY_CONFIG_USE_NOOP
-#include <stdio.h>
-
namespace entry
{
const Event* poll()
@@ -71,7 +69,7 @@ namespace entry
} // namespace entry
-int main(int _argc, char** _argv)
+int main(int _argc, const char* const* _argv)
{
entry::main(_argc, _argv);
}
diff --git a/3rdparty/bgfx/examples/common/entry/entry_osx.mm b/3rdparty/bgfx/examples/common/entry/entry_osx.mm
index 49a8f9bbfff..e99d59bab27 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_osx.mm
+++ b/3rdparty/bgfx/examples/common/entry/entry_osx.mm
@@ -64,21 +64,24 @@ namespace entry
struct MainThreadEntry
{
int m_argc;
- char** m_argv;
+ const char* const* m_argv;
- static int32_t threadFunc(void* _userData)
+ static int32_t threadFunc(bx::Thread* _thread, void* _userData)
{
+ BX_UNUSED(_thread);
+
CFBundleRef mainBundle = CFBundleGetMainBundle();
- if ( mainBundle != nil )
+ if (mainBundle != nil)
{
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
- if ( resourcesURL != nil )
+ if (resourcesURL != nil)
{
char path[PATH_MAX];
- if (CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX) )
+ if (CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8*)path, PATH_MAX) )
{
chdir(path);
}
+
CFRelease(resourcesURL);
}
}
@@ -100,7 +103,7 @@ namespace entry
, m_fullscreen(false)
{
s_translateKey[27] = Key::Esc;
- s_translateKey[uint8_t('\n')] = Key::Return;
+ s_translateKey[uint8_t('\r')] = Key::Return;
s_translateKey[uint8_t('\t')] = Key::Tab;
s_translateKey[127] = Key::Backspace;
s_translateKey[uint8_t(' ')] = Key::Space;
@@ -271,66 +274,52 @@ namespace entry
switch (eventType)
{
- case NSMouseMoved:
- case NSLeftMouseDragged:
- case NSRightMouseDragged:
- case NSOtherMouseDragged:
- {
- getMousePos(&m_mx, &m_my);
- m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll);
- break;
- }
-
- case NSLeftMouseDown:
+ case NSMouseMoved:
+ case NSLeftMouseDragged:
+ case NSRightMouseDragged:
+ case NSOtherMouseDragged:
+ getMousePos(&m_mx, &m_my);
+ m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll);
+ break;
+
+ case NSLeftMouseDown:
{
// Command + Left Mouse Button acts as middle! This just a temporary solution!
// This is because the average OSX user doesn't have middle mouse click.
MouseButton::Enum mb = ([event modifierFlags] & NSCommandKeyMask) ? MouseButton::Middle : MouseButton::Left;
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, mb, true);
- break;
}
+ break;
- case NSLeftMouseUp:
- {
- m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Left, false);
- m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, false); // TODO: remove!
- break;
- }
+ case NSLeftMouseUp:
+ m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Left, false);
+ m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, false);
+ break;
- case NSRightMouseDown:
- {
- m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, true);
- break;
- }
+ case NSRightMouseDown:
+ m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, true);
+ break;
- case NSRightMouseUp:
- {
- m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, false);
- break;
- }
+ case NSRightMouseUp:
+ m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, false);
+ break;
- case NSOtherMouseDown:
- {
- m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, true);
- break;
- }
+ case NSOtherMouseDown:
+ m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, true);
+ break;
- case NSOtherMouseUp:
- {
- m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, false);
- break;
- }
+ case NSOtherMouseUp:
+ m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, false);
+ break;
- case NSScrollWheel:
- {
- m_scrollf += [event deltaY];
+ case NSScrollWheel:
+ m_scrollf += [event deltaY];
- m_scroll = (int32_t)m_scrollf;
- m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll);
- break;
- }
+ m_scroll = (int32_t)m_scrollf;
+ m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll);
+ break;
- case NSKeyDown:
+ case NSKeyDown:
{
uint8_t modifiers = 0;
uint8_t pressedChar[4];
@@ -351,11 +340,10 @@ namespace entry
return false;
}
}
-
- break;
}
+ break;
- case NSKeyUp:
+ case NSKeyUp:
{
uint8_t modifiers = 0;
uint8_t pressedChar[4];
@@ -369,8 +357,11 @@ namespace entry
return false;
}
- break;
}
+ break;
+
+ default:
+ break;
}
[NSApp sendEvent:event];
@@ -409,7 +400,7 @@ namespace entry
m_eventQueue.postSuspendEvent(s_defaultWindow, Suspend::DidSuspend);
}
- int32_t run(int _argc, char** _argv)
+ int32_t run(int _argc, const char* const* _argv)
{
[NSApplication sharedApplication];
@@ -487,10 +478,7 @@ namespace entry
{
@autoreleasepool
{
- if (bgfx::RenderFrame::Exiting == bgfx::renderFrame() )
- {
- break;
- }
+ bgfx::renderFrame();
}
while (dispatchEvent(peekEvent() ) )
@@ -770,7 +758,7 @@ namespace entry
@end
-int main(int _argc, char** _argv)
+int main(int _argc, const char* const* _argv)
{
using namespace entry;
return s_ctx.run(_argc, _argv);
diff --git a/3rdparty/bgfx/examples/common/entry/entry_p.h b/3rdparty/bgfx/examples/common/entry/entry_p.h
index ab45cfef5b5..fa4792a5cb5 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_p.h
+++ b/3rdparty/bgfx/examples/common/entry/entry_p.h
@@ -67,7 +67,7 @@ namespace entry
static void static_deallocate(void* _ptr, size_t /*_bytes*/);
};
- int main(int _argc, char** _argv);
+ int main(int _argc, const char* const* _argv);
char keyToAscii(Key::Enum _key, uint8_t _modifiers);
@@ -177,6 +177,11 @@ namespace entry
class EventQueue
{
public:
+ EventQueue()
+ : m_queue(getAllocator() )
+ {
+ }
+
~EventQueue()
{
for (const Event* ev = poll(); NULL != ev; ev = poll() )
@@ -187,7 +192,7 @@ namespace entry
void postAxisEvent(WindowHandle _handle, GamepadHandle _gamepad, GamepadAxis::Enum _axis, int32_t _value)
{
- AxisEvent* ev = new AxisEvent(_handle);
+ AxisEvent* ev = BX_NEW(getAllocator(), AxisEvent)(_handle);
ev->m_gamepad = _gamepad;
ev->m_axis = _axis;
ev->m_value = _value;
@@ -196,7 +201,7 @@ namespace entry
void postCharEvent(WindowHandle _handle, uint8_t _len, const uint8_t _char[4])
{
- CharEvent* ev = new CharEvent(_handle);
+ CharEvent* ev = BX_NEW(getAllocator(), CharEvent)(_handle);
ev->m_len = _len;
bx::memCopy(ev->m_char, _char, 4);
m_queue.push(ev);
@@ -204,13 +209,13 @@ namespace entry
void postExitEvent()
{
- Event* ev = new Event(Event::Exit);
+ Event* ev = BX_NEW(getAllocator(), Event)(Event::Exit);
m_queue.push(ev);
}
void postGamepadEvent(WindowHandle _handle, GamepadHandle _gamepad, bool _connected)
{
- GamepadEvent* ev = new GamepadEvent(_handle);
+ GamepadEvent* ev = BX_NEW(getAllocator(), GamepadEvent)(_handle);
ev->m_gamepad = _gamepad;
ev->m_connected = _connected;
m_queue.push(ev);
@@ -218,7 +223,7 @@ namespace entry
void postKeyEvent(WindowHandle _handle, Key::Enum _key, uint8_t _modifiers, bool _down)
{
- KeyEvent* ev = new KeyEvent(_handle);
+ KeyEvent* ev = BX_NEW(getAllocator(), KeyEvent)(_handle);
ev->m_key = _key;
ev->m_modifiers = _modifiers;
ev->m_down = _down;
@@ -227,7 +232,7 @@ namespace entry
void postMouseEvent(WindowHandle _handle, int32_t _mx, int32_t _my, int32_t _mz)
{
- MouseEvent* ev = new MouseEvent(_handle);
+ MouseEvent* ev = BX_NEW(getAllocator(), MouseEvent)(_handle);
ev->m_mx = _mx;
ev->m_my = _my;
ev->m_mz = _mz;
@@ -239,7 +244,7 @@ namespace entry
void postMouseEvent(WindowHandle _handle, int32_t _mx, int32_t _my, int32_t _mz, MouseButton::Enum _button, bool _down)
{
- MouseEvent* ev = new MouseEvent(_handle);
+ MouseEvent* ev = BX_NEW(getAllocator(), MouseEvent)(_handle);
ev->m_mx = _mx;
ev->m_my = _my;
ev->m_mz = _mz;
@@ -251,7 +256,7 @@ namespace entry
void postSizeEvent(WindowHandle _handle, uint32_t _width, uint32_t _height)
{
- SizeEvent* ev = new SizeEvent(_handle);
+ SizeEvent* ev = BX_NEW(getAllocator(), SizeEvent)(_handle);
ev->m_width = _width;
ev->m_height = _height;
m_queue.push(ev);
@@ -259,14 +264,14 @@ namespace entry
void postWindowEvent(WindowHandle _handle, void* _nwh = NULL)
{
- WindowEvent* ev = new WindowEvent(_handle);
+ WindowEvent* ev = BX_NEW(getAllocator(), WindowEvent)(_handle);
ev->m_nwh = _nwh;
m_queue.push(ev);
}
void postSuspendEvent(WindowHandle _handle, Suspend::Enum _state)
{
- SuspendEvent* ev = new SuspendEvent(_handle);
+ SuspendEvent* ev = BX_NEW(getAllocator(), SuspendEvent)(_handle);
ev->m_state = _state;
m_queue.push(ev);
}
@@ -293,7 +298,7 @@ namespace entry
void release(const Event* _event) const
{
- delete _event;
+ BX_DELETE(getAllocator(), const_cast<Event*>(_event) );
}
private:
diff --git a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
index b8476f77bff..62a59b5bc04 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
@@ -11,7 +11,7 @@
# define SDL_MAIN_HANDLED
#endif // BX_PLATFORM_WINDOWS
-#include <bx/bx.h>
+#include <bx/os.h>
#include <SDL2/SDL.h>
@@ -25,12 +25,10 @@ BX_PRAGMA_DIAGNOSTIC_POP()
# undef None
#endif // defined(None)
-#include <stdio.h>
#include <bx/mutex.h>
#include <bx/thread.h>
#include <bx/handlealloc.h>
#include <bx/readerwriter.h>
-#include <bx/crtimpl.h>
#include <tinystl/allocator.h>
#include <tinystl/string.h>
@@ -251,7 +249,7 @@ namespace entry
int m_argc;
char** m_argv;
- static int32_t threadFunc(void* _userData);
+ static int32_t threadFunc(bx::Thread* _thread, void* _userData);
};
///
@@ -487,16 +485,25 @@ namespace entry
WindowHandle defaultWindow = { 0 };
setWindowSize(defaultWindow, m_width, m_height, true);
- bx::FileReaderI* reader = getFileReader();
+ bx::FileReaderI* reader = NULL;
+ while (NULL == reader)
+ {
+ reader = getFileReader();
+ bx::sleep(100);
+ }
+
if (bx::open(reader, "gamecontrollerdb.txt") )
{
bx::AllocatorI* allocator = getAllocator();
uint32_t size = (uint32_t)bx::getSize(reader);
- void* data = BX_ALLOC(allocator, size);
+ void* data = BX_ALLOC(allocator, size + 1);
bx::read(reader, data, size);
bx::close(reader);
+ ((char*)data)[size] = '\0';
- SDL_GameControllerAddMapping( (char*)data);
+ if (SDL_GameControllerAddMapping( (char*)data) < 0) {
+ DBG("SDL game controller add mapping failed: %s", SDL_GetError());
+ }
BX_FREE(allocator, data);
}
@@ -1083,8 +1090,10 @@ namespace entry
sdlPostEvent(SDL_USER_WINDOW_MOUSE_LOCK, _handle, NULL, _lock);
}
- int32_t MainThreadEntry::threadFunc(void* _userData)
+ int32_t MainThreadEntry::threadFunc(bx::Thread* _thread, void* _userData)
{
+ BX_UNUSED(_thread);
+
MainThreadEntry* self = (MainThreadEntry*)_userData;
int32_t result = main(self->m_argc, self->m_argv);
diff --git a/3rdparty/bgfx/examples/common/entry/entry_windows.cpp b/3rdparty/bgfx/examples/common/entry/entry_windows.cpp
index 055c85788a2..68045859eb0 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_windows.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_windows.cpp
@@ -311,9 +311,9 @@ namespace entry
struct MainThreadEntry
{
int m_argc;
- char** m_argv;
+ const char* const* m_argv;
- static int32_t threadFunc(void* _userData);
+ static int32_t threadFunc(bx::Thread* _thread, void* _userData);
};
struct Msg
@@ -381,7 +381,7 @@ namespace entry
s_translateKey[VK_OEM_7] = Key::Quote;
s_translateKey[VK_OEM_COMMA] = Key::Comma;
s_translateKey[VK_OEM_PERIOD] = Key::Period;
- s_translateKey[VK_DECIMAL] = Key::Period;
+ s_translateKey[VK_DECIMAL] = Key::Period;
s_translateKey[VK_OEM_2] = Key::Slash;
s_translateKey[VK_OEM_5] = Key::Backslash;
s_translateKey[VK_OEM_3] = Key::Tilde;
@@ -445,7 +445,7 @@ namespace entry
s_translateKey[uint8_t('Z')] = Key::KeyZ;
}
- int32_t run(int _argc, char** _argv)
+ int32_t run(int _argc, const char* const* _argv)
{
SetDllDirectoryA(".");
@@ -498,6 +498,8 @@ namespace entry
mte.m_argc = _argc;
mte.m_argv = _argv;
+ bgfx::renderFrame();
+
bx::Thread thread;
thread.init(mte.threadFunc, &mte);
m_init = true;
@@ -509,6 +511,8 @@ namespace entry
while (!m_exit)
{
+ bgfx::renderFrame();
+
s_xinput.update(m_eventQueue);
WaitForInputIdle(GetCurrentProcess(), 16);
@@ -519,6 +523,8 @@ namespace entry
}
}
+ while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ) {};
+
thread.shutdown();
DestroyWindow(m_hwnd[0]);
@@ -661,13 +667,23 @@ namespace entry
}
// Recalculate position using different anchor points
- switch(_wparam)
+ switch (_wparam)
{
- case WMSZ_LEFT:
case WMSZ_TOPLEFT:
+ rect.left = rect.right - width - m_frameWidth;
+ rect.top = rect.bottom - height - m_frameHeight;
+ break;
+
+ case WMSZ_TOP:
+ case WMSZ_TOPRIGHT:
+ rect.right = rect.left + width + m_frameWidth;
+ rect.top = rect.bottom - height - m_frameHeight;
+ break;
+
+ case WMSZ_LEFT:
case WMSZ_BOTTOMLEFT:
- rect.left = rect.right - width - m_frameWidth;
- rect.bottom = rect.top + height + m_frameHeight;
+ rect.left = rect.right - width - m_frameWidth;
+ rect.bottom = rect.top + height + m_frameHeight;
break;
default:
@@ -881,10 +897,6 @@ namespace entry
}
else
{
-#if defined(__MINGW32__)
- rect = m_rect;
- style = m_style;
-#else
HMONITOR monitor = MonitorFromWindow(_hwnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi;
mi.cbSize = sizeof(mi);
@@ -892,7 +904,6 @@ namespace entry
newrect = mi.rcMonitor;
rect = mi.rcMonitor;
m_aspectRatio = float(newrect.right - newrect.left)/float(newrect.bottom - newrect.top);
-#endif // !defined(__MINGW__)
}
SetWindowLong(_hwnd, GWL_STYLE, style);
@@ -1085,7 +1096,7 @@ namespace entry
PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_MOUSE_LOCK, _handle.idx, _lock);
}
- int32_t MainThreadEntry::threadFunc(void* _userData)
+ int32_t MainThreadEntry::threadFunc(bx::Thread* /*_thread*/, void* _userData)
{
MainThreadEntry* self = (MainThreadEntry*)_userData;
int32_t result = main(self->m_argc, self->m_argv);
@@ -1095,7 +1106,7 @@ namespace entry
} // namespace entry
-int main(int _argc, char** _argv)
+int main(int _argc, const char* const* _argv)
{
using namespace entry;
return s_ctx.run(_argc, _argv);
diff --git a/3rdparty/bgfx/examples/common/entry/entry_winrt.cx b/3rdparty/bgfx/examples/common/entry/entry_winrt.cx
index 39e3d1d249d..c59aab100ed 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_winrt.cx
+++ b/3rdparty/bgfx/examples/common/entry/entry_winrt.cx
@@ -24,7 +24,7 @@ using namespace Windows::Graphics::Display;
#endif // BX_PLATFORM_WINRT
using namespace Platform;
-static char* g_emptyArgs[] = { "" };
+static const char* const g_emptyArgs[] = { "" };
static entry::WindowHandle g_defaultWindow = { 0 };
static entry::EventQueue g_eventQueue;
diff --git a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp
index 78e4306eb2d..d65520f4f08 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp
@@ -220,10 +220,10 @@ namespace entry
struct MainThreadEntry
{
- int m_argc;
- char** m_argv;
+ int32_t m_argc;
+ const char* const* m_argv;
- static int32_t threadFunc(void* _userData);
+ static int32_t threadFunc(bx::Thread* _thread, void* _userData);
};
struct Msg
@@ -343,7 +343,7 @@ namespace entry
m_mz = 0;
}
- int32_t run(int _argc, char** _argv)
+ int32_t run(int _argc, const char* const* _argv)
{
XInitThreads();
m_display = XOpenDisplay(0);
@@ -679,8 +679,10 @@ namespace entry
static Context s_ctx;
- int32_t MainThreadEntry::threadFunc(void* _userData)
+ int32_t MainThreadEntry::threadFunc(bx::Thread* _thread, void* _userData)
{
+ BX_UNUSED(_thread);
+
MainThreadEntry* self = (MainThreadEntry*)_userData;
int32_t result = main(self->m_argc, self->m_argv);
s_ctx.m_exit = true;
@@ -773,7 +775,7 @@ namespace entry
} // namespace entry
-int main(int _argc, char** _argv)
+int main(int _argc, const char* const* _argv)
{
using namespace entry;
return s_ctx.run(_argc, _argv);