Branimir Karadžić 11 years ago
parent
commit
c4b040a382
3 changed files with 46 additions and 23 deletions
  1. 1 1
      examples/common/entry/entry.cpp
  2. 2 0
      examples/common/entry/entry.h
  3. 43 22
      include/bgfx.c99.h

+ 1 - 1
examples/common/entry/entry.cpp

@@ -13,7 +13,7 @@
 #include "cmd.h"
 #include "cmd.h"
 #include "input.h"
 #include "input.h"
 
 
-extern int _main_(int _argc, char** _argv);
+extern "C" int _main_(int _argc, char** _argv);
 
 
 namespace entry
 namespace entry
 {
 {

+ 2 - 0
examples/common/entry/entry.h

@@ -12,6 +12,8 @@
 
 
 namespace bx { struct FileReaderI; struct FileWriterI; }
 namespace bx { struct FileReaderI; struct FileWriterI; }
 
 
+extern "C" int _main_(int _argc, char** _argv);
+
 namespace entry
 namespace entry
 {
 {
 	struct MouseButton
 	struct MouseButton

+ 43 - 22
include/bgfx.c99.h

@@ -251,6 +251,24 @@ typedef enum bgfx_fatal
 
 
 } bgfx_fatal_t;
 } bgfx_fatal_t;
 
 
+#if defined(_MSC_VER)
+#   define BGFX_VTBL_CALL __stdcall
+#   define BGFX_VTBL_THIS  // passed via ecx
+#   define BGFX_VTBL_THIS_ // passed via ecx
+#else
+#   define BGFX_VTBL_CALL _cdecl
+#   define BGFX_VTBL_THIS  BGFX_VTBL_INTEFRACE _this
+#   define BGFX_VTBL_THIS_ BGFX_VTBL_INTEFRACE _this,
+#endif // defined(_MSC_VER)
+
+/**
+ */
+typedef struct bgfx_callback_interface
+{
+    const struct bgfx_callback_vtbl* vtbl;
+
+} bgfx_callback_interface_t;
+
 /**
 /**
  *  Callback interface to implement application specific behavior.
  *  Callback interface to implement application specific behavior.
  *  Cached items are currently used only for OpenGL binary shaders.
  *  Cached items are currently used only for OpenGL binary shaders.
@@ -261,76 +279,79 @@ typedef enum bgfx_fatal
  */
  */
 typedef struct bgfx_callback_vtbl
 typedef struct bgfx_callback_vtbl
 {
 {
+#   define BGFX_VTBL_INTEFRACE bgfx_callback_interface_t
+
+    void* ctor;
+
     /**
     /**
-     *  If fatal code code is not Fatal::DebugCheck this callback is
+     *  If fatal code code is not BGFX_FATAL_DEBUG_CHECK this callback is
      *  called on unrecoverable error. It's not safe to continue, inform
      *  called on unrecoverable error. It's not safe to continue, inform
      *  user and terminate application from this call.
      *  user and terminate application from this call.
      */
      */
-    void (*fatal)(bgfx_fatal_t _code, const char* _str);
+    void (BGFX_VTBL_CALL *fatal)(BGFX_VTBL_THIS_ bgfx_fatal_t _code, const char* _str);
 
 
     /**
     /**
      *  Return size of for cached item. Return 0 if no cached item was
      *  Return size of for cached item. Return 0 if no cached item was
      *  found.
      *  found.
      */
      */
-    uint32_t (*cache_read_size)(uint64_t _id);
+    uint32_t (BGFX_VTBL_CALL *cache_read_size)(BGFX_VTBL_THIS_ uint64_t _id);
 
 
     /**
     /**
      *  Read cached item.
      *  Read cached item.
      */
      */
-    bool (*cache_read)(uint64_t _id, void* _data, uint32_t _size);
+    bool (BGFX_VTBL_CALL *cache_read)(BGFX_VTBL_THIS_ uint64_t _id, void* _data, uint32_t _size);
 
 
     /**
     /**
      *  Write cached item.
      *  Write cached item.
      */
      */
-    void (*cache_write)(uint64_t _id, const void* _data, uint32_t _size);
+    void (BGFX_VTBL_CALL *cache_write)(BGFX_VTBL_THIS_ uint64_t _id, const void* _data, uint32_t _size);
 
 
     /**
     /**
      *  Screenshot captured. Screenshot format is always 4-byte BGRA.
      *  Screenshot captured. Screenshot format is always 4-byte BGRA.
      */
      */
-    void (*screen_shot)(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip);
+    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);
 
 
     /**
     /**
      *  Called when capture begins.
      *  Called when capture begins.
      */
      */
-    void (*capture_begin)(uint32_t _width, uint32_t _height, uint32_t _pitch, bgfx_texture_format_t _format, 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);
 
 
     /**
     /**
      *  Called when capture ends.
      *  Called when capture ends.
      */
      */
-    void (*capture_end)();
+    void (BGFX_VTBL_CALL *capture_end)(BGFX_VTBL_THIS);
 
 
     /**
     /**
      *  Captured frame.
      *  Captured frame.
      */
      */
-    void (*capture_frame)(const void* _data, uint32_t _size);
+    void (BGFX_VTBL_CALL *capture_frame)(BGFX_VTBL_THIS_ const void* _data, uint32_t _size);
+
+#   undef BGFX_VTBL_INTEFRACE
 
 
 } bgfx_callback_vtbl_t;
 } bgfx_callback_vtbl_t;
 
 
 /**
 /**
  */
  */
-typedef struct bgfx_callback_interface
+typedef struct bgfx_reallocator_interface
 {
 {
-    const bgfx_callback_vtbl_t* vtbl;
+    const struct bgfx_reallocator_vtbl* vtbl;
 
 
-} bgfx_callback_interface_t;
+} bgfx_reallocator_interface_t;
 
 
 /**
 /**
  */
  */
 typedef struct bgfx_reallocator_vtbl
 typedef struct bgfx_reallocator_vtbl
 {
 {
-    void* (*alloc)(size_t _size, size_t _align, const char* _file, uint32_t _line);
-    void (*free)(void* _ptr, size_t _align, const char* _file, uint32_t _line);
-    void* (*realloc)(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line);
+#   define BGFX_VTBL_INTEFRACE bgfx_reallocator_interface_t
 
 
-} bgfx_reallocator_vtbl_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);
 
 
-/**
- */
-typedef struct bgfx_reallocator_interface
-{
-    const bgfx_reallocator_vtbl_t* vtbl;
+#   undef BGFX_VTBL_INTEFRACE
 
 
-} bgfx_reallocator_interface_t;
+} bgfx_reallocator_vtbl_t;
 
 
 #if defined(__cplusplus)
 #if defined(__cplusplus)
 #    define BGFX_C_API extern "C"
 #    define BGFX_C_API extern "C"