mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-24 16:48:18 -05:00
Cleanup.
This commit is contained in:
parent
5db71608cb
commit
bed490bd53
24 changed files with 180 additions and 93 deletions
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include "../common/entry.h"
|
||||
#include "../common/dbg.h"
|
||||
#include "../common/processevents.h"
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include "../common/entry.h"
|
||||
#include "../common/dbg.h"
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include "../common/entry.h"
|
||||
#include "../common/dbg.h"
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include "../common/entry.h"
|
||||
#include "../common/dbg.h"
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include <bx/readerwriter.h>
|
||||
#include "../common/entry.h"
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include "../common/entry.h"
|
||||
#include "../common/dbg.h"
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/countof.h>
|
||||
#include <bx/timer.h>
|
||||
#include "../common/entry.h"
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include <bx/readerwriter.h>
|
||||
#include <bx/string.h>
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include <bx/uint32_t.h>
|
||||
#include "../common/entry.h"
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/countof.h>
|
||||
#include <bx/timer.h>
|
||||
#include <bx/readerwriter.h>
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include <bx/countof.h>
|
||||
#include <bx/string.h>
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include "../common/entry.h"
|
||||
#include "../common/dbg.h"
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include <bx/readerwriter.h>
|
||||
#include "../common/entry.h"
|
||||
|
@ -28,7 +29,8 @@ struct KnightPos
|
|||
int32_t m_y;
|
||||
};
|
||||
|
||||
KnightPos knightTour[8*4] = {
|
||||
KnightPos knightTour[8*4] =
|
||||
{
|
||||
{0,0}, {1,2}, {3,3}, {4,1}, {5,3}, {7,2}, {6,0}, {5,2},
|
||||
{7,3}, {6,1}, {4,0}, {3,2}, {2,0}, {0,1}, {1,3}, {2,1},
|
||||
{0,2}, {1,0}, {2,2}, {0,3}, {1,1}, {3,0}, {4,2}, {5,0},
|
||||
|
|
38
examples/common/common.h
Normal file
38
examples/common/common.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __COMMON_H__
|
||||
#define __COMMON_H__
|
||||
|
||||
#include "dbg.h"
|
||||
|
||||
#if 0
|
||||
# define BX_TRACE(_format, ...) \
|
||||
do { \
|
||||
DBG(BX_FILE_LINE_LITERAL "BGFX " _format "\n", ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
# define BX_WARN(_condition, _format, ...) \
|
||||
do { \
|
||||
if (!(_condition) ) \
|
||||
{ \
|
||||
DBG("WARN " _format, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
# define BX_CHECK(_condition, _format, ...) \
|
||||
do { \
|
||||
if (!(_condition) ) \
|
||||
{ \
|
||||
DBG("CHECK " _format, ##__VA_ARGS__); \
|
||||
bx::debugBreak(); \
|
||||
} \
|
||||
} while(0)
|
||||
#endif // 0
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include <bx/debug.h>
|
||||
|
||||
#endif // __COMMON_H__
|
|
@ -3,7 +3,7 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include "common.h"
|
||||
#include <bgfx.h>
|
||||
|
||||
#include <limits.h> // INT_MAX
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include "common.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#define DBG_FILE_LINE_LITERAL "" __FILE__ "(" DBG_STRINGIZE(__LINE__) "): "
|
||||
#define DBG(_format, ...) dbgPrintf(DBG_FILE_LINE_LITERAL "" _format "\n", ##__VA_ARGS__)
|
||||
|
||||
extern void dbgOutput(const char* _out);
|
||||
extern void dbgPrintfVargs(const char* _format, va_list _argList);
|
||||
extern void dbgPrintf(const char* _format, ...);
|
||||
extern void dbgPrintfData(const void* _data, uint32_t _size, const char* _format, ...);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include "common.h"
|
||||
|
||||
#if BX_PLATFORM_ANDROID
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include "common.h"
|
||||
|
||||
#if BX_PLATFORM_LINUX
|
||||
|
||||
|
|
|
@ -3,30 +3,49 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include "common.h"
|
||||
|
||||
#if BX_PLATFORM_NACL
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.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 <bgfxplatform.h>
|
||||
#include "dbg.h"
|
||||
#include <bx/thread.h>
|
||||
|
||||
#include "entry.h"
|
||||
|
||||
extern int _main_(int _argc, char** _argv);
|
||||
|
||||
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;
|
||||
|
@ -48,65 +67,84 @@ namespace entry
|
|||
{
|
||||
}
|
||||
|
||||
} // namespace entry
|
||||
|
||||
extern int _main_(int _argc, char** _argv);
|
||||
|
||||
static void* _entry_(void*)
|
||||
template<typename Type>
|
||||
bool initializeInterface(PPB_GetInterface _interface, const char* _name, const Type*& _result)
|
||||
{
|
||||
const char* argv[1] = { "nacl.nexe" };
|
||||
_main_(1, const_cast<char**>(argv) );
|
||||
return NULL;
|
||||
_result = reinterpret_cast<const Type*>(_interface(_name) );
|
||||
return NULL != _result;
|
||||
}
|
||||
|
||||
struct MainThreadEntry
|
||||
{
|
||||
int m_argc;
|
||||
char** m_argv;
|
||||
|
||||
static int32_t threadFunc(void* _userData);
|
||||
};
|
||||
|
||||
struct NaclContext
|
||||
{
|
||||
NaclContext()
|
||||
: m_thread(0)
|
||||
{
|
||||
const char* argv[1] = { "nacl.nexe" };
|
||||
m_mte.m_argc = 1;
|
||||
m_mte.m_argv = const_cast<char**>(argv);
|
||||
|
||||
bgfx::naclSetIntefraces(g_instance, g_instInterface, g_graphicsInterface, NULL);
|
||||
m_thread.init(MainThreadEntry::threadFunc, &m_mte);
|
||||
}
|
||||
|
||||
const PPB_Instance* m_instInterface;
|
||||
const PPB_Graphics3D* m_graphicsInterface;
|
||||
~NaclContext()
|
||||
{
|
||||
m_thread.shutdown();
|
||||
}
|
||||
|
||||
pthread_t m_thread;
|
||||
PP_Module m_module;
|
||||
PP_Instance m_instance;
|
||||
MainThreadEntry m_mte;
|
||||
bx::Thread m_thread;
|
||||
};
|
||||
|
||||
static NaclContext s_ctx;
|
||||
static NaclContext* s_ctx;
|
||||
|
||||
static PP_Bool naclInstanceDidCreate(PP_Instance _instance, uint32_t _argc, const char* _argn[], const char* _argv[])
|
||||
int32_t MainThreadEntry::threadFunc(void* _userData)
|
||||
{
|
||||
s_ctx.m_instance = _instance;
|
||||
MainThreadEntry* self = (MainThreadEntry*)_userData;
|
||||
|
||||
bgfx::naclSetIntefraces(s_ctx.m_instance, s_ctx.m_instInterface, s_ctx.m_graphicsInterface, NULL);
|
||||
pthread_create(&s_ctx.m_thread, NULL, _entry_, NULL);
|
||||
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!
|
||||
s_ctx = new NaclContext;
|
||||
return PP_TRUE;
|
||||
}
|
||||
|
||||
static void naclInstanceDidDestroy(PP_Instance _instance)
|
||||
{
|
||||
if (s_ctx.m_thread)
|
||||
{
|
||||
pthread_join(s_ctx.m_thread, NULL);
|
||||
}
|
||||
delete s_ctx;
|
||||
}
|
||||
|
||||
static void naclInstanceDidChangeView(PP_Instance _instance, PP_Resource _view)
|
||||
static void naclInstanceDidChangeView(PP_Instance /*_instance*/, PP_Resource /*_view*/)
|
||||
{
|
||||
}
|
||||
|
||||
static void naclInstanceDidChangeFocus(PP_Instance _instance, PP_Bool _focus)
|
||||
static void naclInstanceDidChangeFocus(PP_Instance /*_instance*/, PP_Bool /*_focus*/)
|
||||
{
|
||||
}
|
||||
|
||||
static PP_Bool naclInstanceHandleDocumentLoad(PP_Instance _instance, PP_Resource _urlLoader)
|
||||
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 == strcmp(_name, PPP_INSTANCE_INTERFACE) )
|
||||
|
@ -126,20 +164,17 @@ PP_EXPORT const void* PPP_GetInterface(const char* _name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
bool initializeInterface(const Type*& _result, PPB_GetInterface _interface, const char* _name)
|
||||
{
|
||||
_result = reinterpret_cast<const Type*>(_interface(_name) );
|
||||
return NULL != _result;
|
||||
}
|
||||
|
||||
PP_EXPORT int32_t PPP_InitializeModule(PP_Module _module, PPB_GetInterface _interface)
|
||||
{
|
||||
s_ctx.m_module = _module;
|
||||
|
||||
bool result = true;
|
||||
result &= initializeInterface(s_ctx.m_instInterface, _interface, PPB_INSTANCE_INTERFACE);
|
||||
result &= initializeInterface(s_ctx.m_graphicsInterface, _interface, PPB_GRAPHICS_3D_INTERFACE);
|
||||
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;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include "common.h"
|
||||
|
||||
#if BX_PLATFORM_QNX
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include "common.h"
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include "../common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <freetype/freetype.h>
|
||||
#include <edtaa3/edtaa3func.cpp>
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include <bgfx.h>
|
||||
#include "../common.h"
|
||||
|
||||
#include <bgfx.h>
|
||||
#include <stddef.h> // offsetof
|
||||
#include <memory.h> // memcpy
|
||||
#include <wchar.h> // wcslen
|
||||
|
|
Loading…
Reference in a new issue