diff --git a/README.md b/README.md index d2eda9819..daffc9578 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ bgfx ==== -Rendering library. +Cross-platform rendering library. Supports: OpenGL 2.1, OpenGL ES 2.0, and Direct3D 9.0. @@ -9,6 +9,14 @@ OpenGL 2.1, OpenGL ES 2.0, and Direct3D 9.0. Platforms: Windows, Linux, Android, and Native Client. +Dependencies +------------ + +[https://github.com/bkaradzic/bx](https://github.com/bkaradzic/bx) + +Optional: +[https://github.com/mendsley/tinystl](https://github.com/mendsley/tinystl) + Notice ------ diff --git a/premake/bgfx.lua b/premake/bgfx.lua index 711bc2689..e607b6837 100644 --- a/premake/bgfx.lua +++ b/premake/bgfx.lua @@ -3,6 +3,7 @@ project "bgfx" kind "StaticLib" includedirs { + BGFX_DIR .. "../tinystl/include", BGFX_DIR .. "../bx/include", BGFX_DIR .. "3rdparty/glext", } diff --git a/src/bgfx.cpp b/src/bgfx.cpp index c9ba880e7..d1b0d436f 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -9,6 +9,22 @@ HWND g_bgfxHwnd = NULL; #endif // BX_PLATFORM_WINDOWS +#if BGFX_CONFIG_USE_TINYSTL +namespace tinystl +{ + void* allocator::static_allocate(size_t _bytes) + { + return bgfx::g_realloc(NULL, _bytes); + } + + void allocator::static_deallocate(void* _ptr, size_t /*_bytes*/) + { + bgfx::g_free(_ptr); + } + +} // namespace tinystl +#endif // BGFX_CONFIG_USE_TINYSTL + namespace bgfx { #define BGFX_MAIN_THREAD_MAGIC 0x78666762 diff --git a/src/bgfx_p.h b/src/bgfx_p.h index f98c2ea5d..c8212b055 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -61,7 +61,9 @@ extern HWND g_bgfxHwnd; #elif BX_PLATFORM_XBOX360 # include # include -#endif // BX_PLATFORM_WINDOWS +#elif BX_PLATFORM_POSIX +# include +#endif // BX_PLATFORM_* #ifndef MAKEFOURCC # define MAKEFOURCC(_a, _b, _c, _d) (0 \ @@ -76,10 +78,27 @@ extern HWND g_bgfxHwnd; #define BGFX_MAGIC MAKEFOURCC('B','G','F','X') +#if BGFX_CONFIG_USE_TINYSTL +namespace tinystl +{ + struct allocator + { + static void* static_allocate(size_t _bytes); + static void static_deallocate(void* _ptr, size_t /*_bytes*/); + }; +} // namespace tinystl +# define TINYSTL_ALLOCATOR_H + +# include +# include +namespace stl = tinystl; +#else namespace std { namespace tr1 {} using namespace tr1; } // namespace std -#include +# include +# include +namespace stl = std; +#endif // BGFX_CONFIG_USE_TINYSTL #include -#include #include #include "config.h" @@ -812,7 +831,7 @@ namespace bgfx info.m_data = _data; info.m_func = _func; - std::pair result = m_uniforms.insert(UniformHashMap::value_type(_name, info) ); + stl::pair result = m_uniforms.insert(UniformHashMap::value_type(_name, info) ); return result.first->second; } @@ -820,7 +839,7 @@ namespace bgfx } private: - typedef std::unordered_map UniformHashMap; + typedef stl::unordered_map UniformHashMap; UniformHashMap m_uniforms; }; @@ -1286,10 +1305,10 @@ namespace bgfx void add(MaterialHandle _handle, uint32_t _hash) { - m_materialMap.insert(std::make_pair(_hash, _handle) ); + m_materialMap.insert(stl::make_pair(_hash, _handle) ); } - typedef std::unordered_map MaterialMap; + typedef stl::unordered_map MaterialMap; MaterialMap m_materialMap; }; @@ -1317,7 +1336,7 @@ namespace bgfx { m_vertexBufferRef[_handle.idx] = _declHandle; m_vertexDeclRef[_declHandle.idx]++; - m_vertexDeclMap.insert(std::make_pair(_hash, _declHandle) ); + m_vertexDeclMap.insert(stl::make_pair(_hash, _declHandle) ); } VertexDeclHandle release(VertexBufferHandle _handle) @@ -1334,7 +1353,7 @@ namespace bgfx return declHandle; } - typedef std::unordered_map VertexDeclMap; + typedef stl::unordered_map VertexDeclMap; VertexDeclMap m_vertexDeclMap; uint16_t m_vertexDeclRef[BGFX_CONFIG_MAX_VERTEX_DECLS]; VertexDeclHandle m_vertexBufferRef[BGFX_CONFIG_MAX_VERTEX_BUFFERS]; @@ -1373,7 +1392,7 @@ namespace bgfx { uint64_t ptr = it->m_ptr; - m_used.insert(std::make_pair(ptr, _size) ); + m_used.insert(stl::make_pair(ptr, _size) ); if (it->m_size != _size) { @@ -1443,7 +1462,7 @@ namespace bgfx typedef std::list FreeList; FreeList m_free; - typedef std::unordered_map UsedList; + typedef stl::unordered_map UsedList; UsedList m_used; }; diff --git a/src/config.h b/src/config.h index f6f6ecd31..5993dfe98 100644 --- a/src/config.h +++ b/src/config.h @@ -124,4 +124,8 @@ # define BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE (512<<10) #endif // BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE +#ifndef BGFX_CONFIG_USE_TINYSTL +# define BGFX_CONFIG_USE_TINYSTL 0 +#endif // BGFX_CONFIG_USE_TINYSTL + #endif // __CONFIG_H__ diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index ee45f1f28..36e9354b7 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -964,6 +964,7 @@ namespace bgfx } } + (void)kind; // explicitly ignore unused variable kind in non-debug builds BX_TRACE("\t%s: %s, type %2d, num %2d, r.index %3d, r.count %2d" , kind , name @@ -1829,7 +1830,7 @@ namespace bgfx if (BGFX_CLEAR_NONE != clear.m_flags) { - D3DCOLOR color; + D3DCOLOR color = 0; DWORD flags = 0; if (BGFX_CLEAR_COLOR_BIT & clear.m_flags) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 1c793372b..98f46dbf4 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -109,13 +109,15 @@ namespace bgfx glSetCurrentContextPPAPI(m_context); m_graphicsInterface->SwapBuffers(m_context, naclSwapComplete); -// # define GL_IMPORT(_optional, _proto, _func) \ -// { \ -// _func = (_proto)eglGetProcAddress(#_func); \ -// BGFX_FATAL(_optional || NULL != _func, bgfx::Fatal::OPENGL_UnableToCreateContext, "Failed to create OpenGL context. eglGetProcAddress(\"%s\")", #_func); \ -// } -// # include "glimports.h" -// # undef GL_IMPORT +#if 0 + # define GL_IMPORT(_optional, _proto, _func) \ + { \ + _func = (_proto)eglGetProcAddress(#_func); \ + BGFX_FATAL(_optional || NULL != _func, bgfx::Fatal::OPENGL_UnableToCreateContext, "Failed to create OpenGL context. eglGetProcAddress(\"%s\")", #_func); \ + } + # include "glimports.h" + # undef GL_IMPORT +#endif } else {