From 4b5159394c7d3953f0196e28cd0f9f9a6017464a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 1 Jun 2014 15:26:36 -0700 Subject: [PATCH] Added shared library support. --- include/bgfx.c99.h | 32 ++++++++++++++++++++-------- premake/bgfx.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++ src/bgfx.cpp | 2 -- 3 files changed, 75 insertions(+), 11 deletions(-) diff --git a/include/bgfx.c99.h b/include/bgfx.c99.h index b8e0cfc77..99595c708 100644 --- a/include/bgfx.c99.h +++ b/include/bgfx.c99.h @@ -253,16 +253,38 @@ typedef enum bgfx_fatal } bgfx_fatal_t; +#ifndef BGFX_SHARED_LIB_BUILD +# define BGFX_SHARED_LIB_BUILD 0 +#endif // BGFX_SHARED_LIB_BUILD + +#ifndef BGFX_SHARED_LIB_USE +# define BGFX_SHARED_LIB_USE 0 +#endif // BGFX_SHARED_LIB_USE + #if defined(_MSC_VER) # define BGFX_VTBL_CALL __stdcall # define BGFX_VTBL_THIS // passed via ecx # define BGFX_VTBL_THIS_ // passed via ecx +# if BGFX_SHARED_LIB_BUILD +# define BGFX_SHARED_LIB_API __declspec(dllexport) +# elif BGFX_SHARED_LIB_USE +# define BGFX_SHARED_LIB_API __declspec(dllimport) +# else +# define BGFX_SHARED_LIB_API +# endif // BGFX_SHARED_LIB_* #else -# define BGFX_VTBL_CALL _cdecl +# define BGFX_VTBL_CALL # define BGFX_VTBL_THIS BGFX_VTBL_INTEFRACE _this # define BGFX_VTBL_THIS_ BGFX_VTBL_INTEFRACE _this, +# define BGFX_SHARED_LIB_API #endif // defined(_MSC_VER) +#if defined(__cplusplus) +# define BGFX_C_API extern "C" BGFX_SHARED_LIB_API +#else +# define BGFX_C_API BGFX_SHARED_LIB_API +#endif // defined(__cplusplus) + /** */ typedef struct bgfx_callback_interface @@ -355,12 +377,6 @@ typedef struct bgfx_reallocator_vtbl } bgfx_reallocator_vtbl_t; -#if defined(__cplusplus) -# define BGFX_C_API extern "C" -#else -# define BGFX_C_API -#endif // defined(__cplusplus) - /** * Start vertex declaration. */ @@ -1283,6 +1299,4 @@ BGFX_C_API void bgfx_discard(); */ BGFX_C_API void bgfx_save_screen_shot(const char* _filePath); -#undef BGFX_C_API - #endif // BGFX_C99_H_HEADER_GUARD diff --git a/premake/bgfx.lua b/premake/bgfx.lua index 9b0a65edd..c2f8795e4 100644 --- a/premake/bgfx.lua +++ b/premake/bgfx.lua @@ -53,3 +53,55 @@ project "bgfx" } copyLib() + +project "bgfx-shared-lib" + uuid "09986168-e9d9-11e3-9c8e-f2aef940a72a" + kind "SharedLib" + + includedirs { + BGFX_DIR .. "../bx/include", + } + + defines { + "BGFX_SHARED_LIB_BUILD=1", +-- "BGFX_CONFIG_RENDERER_OPENGL=1", + } + + configuration { "Debug" } + defines { + "BGFX_CONFIG_DEBUG=1", + } + + configuration { "windows" } + includedirs { + "$(DXSDK_DIR)/include", + } + + configuration { "osx or ios*" } + files { + BGFX_DIR .. "src/**.mm", + } + + configuration { "vs* or linux or mingw or osx or ios*" } + includedirs { + --nacl has GLES2 headers modified... + BGFX_DIR .. "3rdparty/khronos", + } + + configuration {} + + includedirs { + BGFX_DIR .. "include", + } + + files { + BGFX_DIR .. "include/**.h", + BGFX_DIR .. "src/**.cpp", + BGFX_DIR .. "src/**.h", + } + + excludes { + BGFX_DIR .. "src/**.bin.h", + } + + copyLib() diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 0fd5ee571..3c87c4b27 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2619,8 +2619,6 @@ BX_STATIC_ASSERT(sizeof(bgfx::TransientVertexBuffer) == sizeof(bgfx_transient_ve BX_STATIC_ASSERT(sizeof(bgfx::InstanceDataBuffer) == sizeof(bgfx_instance_data_buffer_t) ); BX_STATIC_ASSERT(sizeof(bgfx::TextureInfo) == sizeof(bgfx_texture_info_t) ); -#define BGFX_C_API extern "C" - BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer) { bgfx::VertexDecl* decl = (bgfx::VertexDecl*)_decl;