mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 10:35:43 -05:00
Fixed issue #429.
This commit is contained in:
parent
33de71efbd
commit
ef143a1bb6
2 changed files with 97 additions and 29 deletions
|
@ -327,9 +327,6 @@ typedef enum bgfx_fatal
|
|||
#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
|
||||
|
@ -338,9 +335,6 @@ typedef enum bgfx_fatal
|
|||
# define BGFX_SHARED_LIB_API
|
||||
# endif // BGFX_SHARED_LIB_*
|
||||
#else
|
||||
# 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)
|
||||
|
||||
|
@ -360,19 +354,14 @@ typedef struct bgfx_callback_interface
|
|||
/**/
|
||||
typedef struct bgfx_callback_vtbl
|
||||
{
|
||||
# define BGFX_VTBL_INTEFRACE bgfx_callback_interface_t
|
||||
|
||||
void* ctor;
|
||||
void (BGFX_VTBL_CALL *fatal)(BGFX_VTBL_THIS_ bgfx_fatal_t _code, const char* _str);
|
||||
uint32_t (BGFX_VTBL_CALL *cache_read_size)(BGFX_VTBL_THIS_ uint64_t _id);
|
||||
bool (BGFX_VTBL_CALL *cache_read)(BGFX_VTBL_THIS_ uint64_t _id, void* _data, uint32_t _size);
|
||||
void (BGFX_VTBL_CALL *cache_write)(BGFX_VTBL_THIS_ uint64_t _id, const void* _data, uint32_t _size);
|
||||
void (BGFX_VTBL_CALL *screen_shot)(BGFX_VTBL_THIS_ const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip);
|
||||
void (BGFX_VTBL_CALL *capture_begin)(BGFX_VTBL_THIS_ uint32_t _width, uint32_t _height, uint32_t _pitch, bgfx_texture_format_t _format, bool _yflip);
|
||||
void (BGFX_VTBL_CALL *capture_end)(BGFX_VTBL_THIS);
|
||||
void (BGFX_VTBL_CALL *capture_frame)(BGFX_VTBL_THIS_ const void* _data, uint32_t _size);
|
||||
|
||||
# undef BGFX_VTBL_INTEFRACE
|
||||
void (*fatal)(bgfx_callback_interface_t* _this, bgfx_fatal_t _code, const char* _str);
|
||||
uint32_t (*cache_read_size)(bgfx_callback_interface_t* _this, uint64_t _id);
|
||||
bool (*cache_read)(bgfx_callback_interface_t* _this, uint64_t _id, void* _data, uint32_t _size);
|
||||
void (*cache_write)(bgfx_callback_interface_t* _this, uint64_t _id, const void* _data, uint32_t _size);
|
||||
void (*screen_shot)(bgfx_callback_interface_t* _this, const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip);
|
||||
void (*capture_begin)(bgfx_callback_interface_t* _this, uint32_t _width, uint32_t _height, uint32_t _pitch, bgfx_texture_format_t _format, bool _yflip);
|
||||
void (*capture_end)(bgfx_callback_interface_t* _this);
|
||||
void (*capture_frame)(bgfx_callback_interface_t* _this, const void* _data, uint32_t _size);
|
||||
|
||||
} bgfx_callback_vtbl_t;
|
||||
|
||||
|
@ -386,14 +375,9 @@ typedef struct bgfx_reallocator_interface
|
|||
/**/
|
||||
typedef struct bgfx_reallocator_vtbl
|
||||
{
|
||||
# define BGFX_VTBL_INTEFRACE bgfx_reallocator_interface_t
|
||||
|
||||
void* ctor;
|
||||
void* (BGFX_VTBL_CALL *alloc)(BGFX_VTBL_THIS_ size_t _size, size_t _align, const char* _file, uint32_t _line);
|
||||
void (BGFX_VTBL_CALL *free)(BGFX_VTBL_THIS_ void* _ptr, size_t _align, const char* _file, uint32_t _line);
|
||||
void* (BGFX_VTBL_CALL *realloc)(BGFX_VTBL_THIS_ void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line);
|
||||
|
||||
# undef BGFX_VTBL_INTEFRACE
|
||||
void* (*alloc)(bgfx_reallocator_interface_t* _this, size_t _size, size_t _align, const char* _file, uint32_t _line);
|
||||
void (*free)(bgfx_reallocator_interface_t* _this, void* _ptr, size_t _align, const char* _file, uint32_t _line);
|
||||
void* (*realloc)(bgfx_reallocator_interface_t* _this, void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line);
|
||||
|
||||
} bgfx_reallocator_vtbl_t;
|
||||
|
||||
|
|
88
src/bgfx.cpp
88
src/bgfx.cpp
|
@ -3054,6 +3054,84 @@ BX_STATIC_ASSERT(sizeof(bgfx::TextureInfo) == sizeof(bgfx_texture_info
|
|||
BX_STATIC_ASSERT(sizeof(bgfx::Caps) == sizeof(bgfx_caps_t) );
|
||||
BX_STATIC_ASSERT(sizeof(bgfx::PlatformData) == sizeof(bgfx_platform_data_t) );
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
struct CallbackC99 : public CallbackI
|
||||
{
|
||||
virtual ~CallbackC99()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void fatal(Fatal::Enum _code, const char* _str) BX_OVERRIDE
|
||||
{
|
||||
m_interface->vtbl->fatal(m_interface, (bgfx_fatal_t)_code, _str);
|
||||
}
|
||||
|
||||
virtual uint32_t cacheReadSize(uint64_t _id) BX_OVERRIDE
|
||||
{
|
||||
return m_interface->vtbl->cache_read_size(m_interface, _id);
|
||||
}
|
||||
|
||||
virtual bool cacheRead(uint64_t _id, void* _data, uint32_t _size) BX_OVERRIDE
|
||||
{
|
||||
return m_interface->vtbl->cache_read(m_interface, _id, _data, _size);
|
||||
}
|
||||
|
||||
virtual void cacheWrite(uint64_t _id, const void* _data, uint32_t _size) BX_OVERRIDE
|
||||
{
|
||||
m_interface->vtbl->cache_write(m_interface, _id, _data, _size);
|
||||
}
|
||||
|
||||
virtual void screenShot(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip) BX_OVERRIDE
|
||||
{
|
||||
m_interface->vtbl->screen_shot(m_interface, _filePath, _width, _height, _pitch, _data, _size, _yflip);
|
||||
}
|
||||
|
||||
virtual void captureBegin(uint32_t _width, uint32_t _height, uint32_t _pitch, TextureFormat::Enum _format, bool _yflip) BX_OVERRIDE
|
||||
{
|
||||
m_interface->vtbl->capture_begin(m_interface, _width, _height, _pitch, (bgfx_texture_format_t)_format, _yflip);
|
||||
}
|
||||
|
||||
virtual void captureEnd() BX_OVERRIDE
|
||||
{
|
||||
m_interface->vtbl->capture_end(m_interface);
|
||||
}
|
||||
|
||||
virtual void captureFrame(const void* _data, uint32_t _size) BX_OVERRIDE
|
||||
{
|
||||
m_interface->vtbl->capture_frame(m_interface, _data, _size);
|
||||
}
|
||||
|
||||
bgfx_callback_interface_t* m_interface;
|
||||
};
|
||||
|
||||
class AllocatorC99 : public bx::ReallocatorI
|
||||
{
|
||||
public:
|
||||
virtual ~AllocatorC99()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void* alloc(size_t _size, size_t _align, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
return m_interface->vtbl->alloc(m_interface, _size, _align, _file, _line);
|
||||
}
|
||||
|
||||
virtual void free(void* _ptr, size_t _align, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
m_interface->vtbl->free(m_interface, _ptr, _align, _file, _line);
|
||||
}
|
||||
|
||||
virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
return m_interface->vtbl->realloc(m_interface, _ptr, _size, _align, _file, _line);
|
||||
}
|
||||
|
||||
bgfx_reallocator_interface_t* m_interface;
|
||||
};
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer)
|
||||
{
|
||||
bgfx::VertexDecl* decl = (bgfx::VertexDecl*)_decl;
|
||||
|
@ -3130,11 +3208,17 @@ BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type)
|
|||
|
||||
BGFX_C_API void bgfx_init(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_reallocator_interface_t* _allocator)
|
||||
{
|
||||
static bgfx::CallbackC99 s_callback;
|
||||
s_callback.m_interface = _callback;
|
||||
|
||||
static bgfx::AllocatorC99 s_allocator;
|
||||
s_allocator.m_interface = _allocator;
|
||||
|
||||
return bgfx::init(bgfx::RendererType::Enum(_type)
|
||||
, _vendorId
|
||||
, _deviceId
|
||||
, reinterpret_cast<bgfx::CallbackI*>(_callback)
|
||||
, reinterpret_cast<bx::ReallocatorI*>(_allocator)
|
||||
, NULL == _callback ? NULL : &s_callback
|
||||
, NULL == _allocator ? NULL : &s_allocator
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue