Added tinystl support.

This commit is contained in:
bkaradzic 2012-06-27 20:49:45 -07:00
parent 1b0f2b6cbc
commit d8c1ddae83
7 changed files with 71 additions and 20 deletions

View File

@ -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
------

View File

@ -3,6 +3,7 @@ project "bgfx"
kind "StaticLib"
includedirs {
BGFX_DIR .. "../tinystl/include",
BGFX_DIR .. "../bx/include",
BGFX_DIR .. "3rdparty/glext",
}

View File

@ -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

View File

@ -61,7 +61,9 @@ extern HWND g_bgfxHwnd;
#elif BX_PLATFORM_XBOX360
# include <malloc.h>
# include <xtl.h>
#endif // BX_PLATFORM_WINDOWS
#elif BX_PLATFORM_POSIX
# include <pthread.h>
#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 <TINYSTL/string.h>
# include <TINYSTL/unordered_map.h>
namespace stl = tinystl;
#else
namespace std { namespace tr1 {} using namespace tr1; } // namespace std
#include <string>
# include <string>
# include <unordered_map>
namespace stl = std;
#endif // BGFX_CONFIG_USE_TINYSTL
#include <list>
#include <unordered_map>
#include <algorithm>
#include "config.h"
@ -812,7 +831,7 @@ namespace bgfx
info.m_data = _data;
info.m_func = _func;
std::pair<UniformHashMap::iterator, bool> result = m_uniforms.insert(UniformHashMap::value_type(_name, info) );
stl::pair<UniformHashMap::iterator, bool> result = m_uniforms.insert(UniformHashMap::value_type(_name, info) );
return result.first->second;
}
@ -820,7 +839,7 @@ namespace bgfx
}
private:
typedef std::unordered_map<std::string, UniformInfo> UniformHashMap;
typedef stl::unordered_map<stl::string, UniformInfo> 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<uint32_t, MaterialHandle> MaterialMap;
typedef stl::unordered_map<uint32_t, MaterialHandle> 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<uint32_t, VertexDeclHandle> VertexDeclMap;
typedef stl::unordered_map<uint32_t, VertexDeclHandle> 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<Free> FreeList;
FreeList m_free;
typedef std::unordered_map<uint64_t, uint32_t> UsedList;
typedef stl::unordered_map<uint64_t, uint32_t> UsedList;
UsedList m_used;
};

View File

@ -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__

View File

@ -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)

View File

@ -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
{