Browse Source

sokol_spine.h: fix C++ compilation, add to C/C++ compile tests

Andre Weissflog 2 years ago
parent
commit
25abcf80cd
4 changed files with 35 additions and 10 deletions
  1. 4 2
      tests/compile/CMakeLists.txt
  2. 8 0
      tests/compile/sokol_spine.c
  3. 9 0
      tests/compile/sokol_spine.cc
  4. 14 8
      util/sokol_spine.h

+ 4 - 2
tests/compile/CMakeLists.txt

@@ -13,6 +13,7 @@ set(c_sources
     sokol_shape.c
     sokol_nuklear.c
     sokol_color.c
+    sokol_spine.c
     sokol_main.c)
 if (NOT ANDROID AND NOT UWP)
     set(c_sources ${c_sources} sokol_fetch.c)
@@ -32,6 +33,7 @@ set(cxx_sources
     sokol_gfx_imgui.cc
     sokol_shape.cc
     sokol_color.cc
+    sokol_spine.cc
     sokol_main.cc)
 if (NOT ANDROID AND NOT UWP)
     set(cxx_sources ${cxx_sources} sokol_fetch.cc)
@@ -43,7 +45,7 @@ if (NOT UWP)
     else()
         add_executable(sokol-compiletest-c ${exe_type} sokol_app.c sokol_glue.c ${c_sources})
     endif()
-    target_link_libraries(sokol-compiletest-c PUBLIC cimgui nuklear)
+    target_link_libraries(sokol-compiletest-c PUBLIC cimgui nuklear spine)
     configure_c(sokol-compiletest-c)
 endif()
 
@@ -52,5 +54,5 @@ if (ANDROID)
 else()
     add_executable(sokol-compiletest-cxx ${exe_type} ${cxx_sources})
 endif()
-target_link_libraries(sokol-compiletest-cxx PUBLIC imgui nuklear)
+target_link_libraries(sokol-compiletest-cxx PUBLIC imgui nuklear spine)
 configure_cxx(sokol-compiletest-cxx)

+ 8 - 0
tests/compile/sokol_spine.c

@@ -0,0 +1,8 @@
+#include "sokol_gfx.h"
+#define SOKOL_IMPL
+#include "spine/spine.h"
+#include "sokol_spine.h"
+
+void use_sspine_impl(void) {
+    sspine_setup(&(sspine_desc){0});
+}

+ 9 - 0
tests/compile/sokol_spine.cc

@@ -0,0 +1,9 @@
+#include "sokol_gfx.h"
+#define SOKOL_IMPL
+#include "spine/spine.h"
+#include "sokol_spine.h"
+
+void use_sspine_impl(void) {
+    const sspine_desc desc = {};
+    sspine_setup(&desc);
+}

+ 14 - 8
util/sokol_spine.h

@@ -2759,16 +2759,29 @@ typedef struct {
 static _sspine_t _sspine;
 
 // dummy spine-c platform implementation functions
+#if defined(__cplusplus)
+extern "C" {
+#endif
 void _spAtlasPage_createTexture(spAtlasPage* self, const char* path) {
     // nothing to do here
     (void)self; (void)path;
 }
 
+void _spAtlasPage_disposeTexture(spAtlasPage* self) {
+    if (self->rendererObject != 0) {
+        const sg_image img = { (uint32_t)(uintptr_t)self->rendererObject };
+        sg_destroy_image(img);
+    }
+}
+
 char* _spUtil_readFile(const char* path, int* length) {
     (void)path;
     *length = 0;
     return 0;
 }
+#if defined(__cplusplus)
+} // extern "C"
+#endif
 
 //=== HELPER FUNCTION ==========================================================
 #define _SSPINE_PANIC(code) _sspine_log(SSPINE_ERROR_ ##code, SSPINE_LOGLEVEL_PANIC, __LINE__)
@@ -3276,13 +3289,6 @@ static sspine_atlas _sspine_alloc_atlas(void) {
     }
 }
 
-void _spAtlasPage_disposeTexture(spAtlasPage* self) {
-    if (self->rendererObject != 0) {
-        const sg_image img = { (uint32_t)(uintptr_t)self->rendererObject };
-        sg_destroy_image(img);
-    }
-}
-
 static sspine_resource_state _sspine_init_atlas(_sspine_atlas_t* atlas, const sspine_atlas_desc* desc) {
     SOKOL_ASSERT(atlas && (atlas->slot.state == SSPINE_RESOURCESTATE_ALLOC));
     SOKOL_ASSERT(desc);
@@ -3456,7 +3462,7 @@ static sspine_resource_state _sspine_init_skeleton(_sspine_skeleton_t* skeleton,
         spSkeletonBinary* skel_bin = spSkeletonBinary_create(atlas->sp_atlas);
         SOKOL_ASSERT(skel_bin);
         skel_bin->scale = desc->prescale;
-        skeleton->sp_skel_data = spSkeletonBinary_readSkeletonData(skel_bin, desc->binary_data.ptr, (int)desc->binary_data.size);
+        skeleton->sp_skel_data = spSkeletonBinary_readSkeletonData(skel_bin, (const unsigned char*)desc->binary_data.ptr, (int)desc->binary_data.size);
         spSkeletonBinary_dispose(skel_bin); skel_bin = 0;
         if (0 == skeleton->sp_skel_data) {
             _SSPINE_ERROR(SPINE_SKELETON_DATA_CREATION_FAILED);