Skip to content

Commit

Permalink
fix(*): replace glm::* C++-structs with C-structs for better compat…
Browse files Browse the repository at this point in the history
…ibility

Generally, these structs were compatible with C under Linux and MacOS but Windows (specifically MSVC) seems to compile them differently, breaking compatibility.
  • Loading branch information
lmichaelis committed Dec 26, 2023
1 parent a08040c commit 1af0df3
Show file tree
Hide file tree
Showing 22 changed files with 519 additions and 184 deletions.
16 changes: 12 additions & 4 deletions include/zenkit-capi/Boxes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@
#ifdef __cplusplus
#include "zenkit/Boxes.hh"

using ZkAxisAlignedBoundingBox = zenkit::AxisAlignedBoundingBox;
using ZkOrientedBoundingBox = zenkit::OrientedBoundingBox;
#else
typedef struct {
typedef struct ZkInternal_OrientedBoundingBox ZkOrientedBoundingBox;
#endif

typedef struct ZkInternal_AxisAlignedBoundingBox {
ZkVec3f min;
ZkVec3f max;
} ZkAxisAlignedBoundingBox;

typedef struct ZkInternal_OrientedBoundingBox ZkOrientedBoundingBox;
#ifdef __cplusplus
ZkInternal_AxisAlignedBoundingBox() : min(), max() {}
ZkInternal_AxisAlignedBoundingBox(zenkit::AxisAlignedBoundingBox const& bbox) : min(bbox.min), max(bbox.max) {}

operator zenkit::AxisAlignedBoundingBox() const {
return {min, max};
}
#endif
} ZkAxisAlignedBoundingBox;

typedef ZkBool (*ZkOrientedBoundingBoxEnumerator)(void*, ZkOrientedBoundingBox const* box);

Expand Down
20 changes: 15 additions & 5 deletions include/zenkit-capi/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@
#ifdef __cplusplus
#include <zenkit/Mesh.hh>
using ZkMesh = zenkit::Mesh;
using ZkVertex = zenkit::VertexFeature;
using ZkLightMap = zenkit::LightMap;
using ZkPolygon = zenkit::Polygon;
#else
typedef struct ZkInternal_Mesh ZkMesh;
typedef struct ZkInternal_LightMap ZkLightMap;
typedef struct ZkInternal_Polygon ZkPolygon;
#endif

typedef struct {
typedef struct ZkInternal_Vertex {
ZkVec2f texture;
uint32_t light;
ZkVec3f normal;
} ZkVertex;

#ifdef __cplusplus
ZkInternal_Vertex() : texture(), light(0), normal() {}
ZkInternal_Vertex(zenkit::VertexFeature const& v) : texture(v.texture), light(v.light), normal(v.normal) {}
#endif
} ZkVertex;

typedef ZkBool (*ZkVertexEnumerator)(void* ctx, ZkVertex* vertex);
typedef ZkBool (*ZkLightMapEnumerator)(void* ctx, ZkLightMap const* lightMap);
typedef ZkBool (*ZkPolygonEnumerator)(void* ctx, ZkPolygon const* polygon);

Expand All @@ -43,8 +48,13 @@ ZKC_API ZkSize ZkMesh_getMaterialCount(ZkMesh const* slf);
ZKC_API ZkMaterial const* ZkMesh_getMaterial(ZkMesh const* slf, ZkSize i);
ZKC_API void ZkMesh_enumerateMaterials(ZkMesh const* slf, ZkMaterialEnumerator cb, void* ctx);

ZKC_API ZkVec3f const* ZkMesh_getPositions(ZkMesh const* slf, ZkSize* count);
ZKC_API ZkVertex const* ZkMesh_getVertices(ZkMesh const* slf, ZkSize* count);
ZKC_API ZkSize ZkMesh_getPositionCount(ZkMesh const* slf);
ZKC_API ZkVec3f ZkMesh_getPosition(ZkMesh const* slf, ZkSize i);
ZKC_API void ZkMesh_enumeratePositions(ZkMesh const* slf, ZkVec3fEnumerator cb, void* ctx);

ZKC_API ZkSize ZkMesh_getVertexCount(ZkMesh const* slf);
ZKC_API ZkVertex ZkMesh_getVertex(ZkMesh const* slf, ZkSize i);
ZKC_API void ZkMesh_enumerateVertices(ZkMesh const* slf, ZkVertexEnumerator cb, void* ctx);

ZKC_API ZkSize ZkMesh_getLightMapCount(ZkMesh const* slf);
ZKC_API ZkLightMap const* ZkMesh_getLightMap(ZkMesh const* slf, ZkSize i);
Expand Down
10 changes: 7 additions & 3 deletions include/zenkit-capi/ModelAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
#ifdef __cplusplus
#include <zenkit/ModelAnimation.hh>
using ZkModelAnimation = zenkit::ModelAnimation;
using ZkAnimationSample = zenkit::AnimationSample;
#else
typedef struct ZkInternal_ModelAnimation ZkModelAnimation;
#endif

typedef struct {
typedef struct ZkInternal_AnimationSample {
ZkVec3f position;
ZkQuat rotation;
} ZkAnimationSample;

#ifdef __cplusplus
ZkInternal_AnimationSample() : position(), rotation() {}
ZkInternal_AnimationSample(zenkit::AnimationSample const& v) : position(v.position), rotation(v.rotation) {}
#endif
} ZkAnimationSample;

typedef ZkBool (*ZkAnimationSampleEnumerator)(void* ctx, ZkAnimationSample* sample);

Expand Down
10 changes: 8 additions & 2 deletions include/zenkit-capi/MorphMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ ZKC_API void ZkMorphMesh_del(ZkMorphMesh* slf);

ZKC_API ZkString ZkMorphMesh_getName(ZkMorphMesh const* slf);
ZKC_API ZkMultiResolutionMesh const* ZkMorphMesh_getMesh(ZkMorphMesh const* slf);
ZKC_API ZkVec3f const* ZkMorphMesh_getMorphPositions(ZkMorphMesh const* slf, ZkSize* count);

ZKC_API ZkSize ZkMorphMesh_getMorphPositionCount(ZkMorphMesh const* slf);
ZKC_API ZkVec3f ZkMorphMesh_getMorphPosition(ZkMorphMesh const* slf, ZkSize i);
ZKC_API void ZkMorphMesh_enumerateMorphPositions(ZkMorphMesh const* slf, ZkVec3fEnumerator cb, void* ctx);

ZKC_API ZkSize ZkMorphMesh_getAnimationCount(ZkMorphMesh const* slf);
ZKC_API ZkMorphAnimation const* ZkMorphMesh_getAnimation(ZkMorphMesh const* slf, ZkSize i);
Expand All @@ -47,7 +50,10 @@ ZKC_API float ZkMorphAnimation_getSpeed(ZkMorphAnimation const* slf);
ZKC_API uint8_t ZkMorphAnimation_getFlags(ZkMorphAnimation const* slf);
ZKC_API uint32_t ZkMorphAnimation_getFrameCount(ZkMorphAnimation const* slf);
ZKC_API uint32_t const* ZkMorphAnimation_getVertices(ZkMorphAnimation const* slf, ZkSize* count);
ZKC_API ZkVec3f const* ZkMorphAnimation_getSamples(ZkMorphAnimation const* slf, ZkSize* count);

ZKC_API ZkSize ZkMorphAnimation_getSampleCount(ZkMorphAnimation const* slf);
ZKC_API ZkVec3f ZkMorphAnimation_getSample(ZkMorphAnimation const* slf, ZkSize i);
ZKC_API void ZkMorphAnimation_enumerateSamples(ZkMorphAnimation const* slf, ZkVec3fEnumerator cb, void* ctx);

ZKC_API ZkDate ZkMorphSource_getFileDate(ZkMorphSource const* slf);
ZKC_API ZkString ZkMorphSource_getFileName(ZkMorphSource const* slf);
54 changes: 39 additions & 15 deletions include/zenkit-capi/MultiResolutionMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ using ZkMultiResolutionMesh = zenkit::MultiResolutionMesh;
using ZkSubMesh = zenkit::SubMesh;

using ZkMeshTriangle = zenkit::MeshTriangle;
using ZkMeshWedge = zenkit::MeshWedge;
using ZkMeshPlane = zenkit::MeshPlane;
using ZkMeshTriangleEdge = zenkit::MeshTriangleEdge;
using ZkMeshEdge = zenkit::MeshEdge;

Expand All @@ -28,34 +26,52 @@ typedef struct {
} ZkMeshTriangle;

typedef struct {
uint16_t edges[3];
} ZkMeshTriangleEdge;

typedef struct {
uint16_t edges[2];
} ZkMeshEdge;
#endif

typedef struct ZkInternal_MeshWedge {
ZkVec3f normal;
ZkVec2f texture;
uint16_t index;

#ifdef __cplusplus
ZkInternal_MeshWedge() : normal(), texture(), index(0) {}
ZkInternal_MeshWedge(zenkit::MeshWedge const& v) : normal(v.normal), texture(v.texture), index(v.index) {}
#endif
} ZkMeshWedge;

typedef struct {
typedef struct ZkInternal_MeshPlane {
float distance;
ZkVec3f normal;
} ZkMeshPlane;

typedef struct {
uint16_t edges[3];
} ZkMeshTriangleEdge;

typedef struct {
uint16_t edges[2];
} ZkMeshEdge;
#ifdef __cplusplus
ZkInternal_MeshPlane() : distance(0), normal() {}
ZkInternal_MeshPlane(zenkit::MeshPlane const& v) : distance(v.distance), normal(v.normal) {}
#endif
} ZkMeshPlane;

typedef ZkBool (*ZkSubMeshEnumerator)(void*, ZkSubMesh const*);
typedef ZkBool (*ZkMeshWedgeEnumerator)(void*, ZkMeshWedge*);
typedef ZkBool (*ZkMeshPlaneEnumerator)(void*, ZkMeshPlane*);

ZKC_API ZkMultiResolutionMesh* ZkMultiResolutionMesh_load(ZkRead* buf);
ZKC_API ZkMultiResolutionMesh* ZkMultiResolutionMesh_loadPath(ZkString path);
ZKC_API ZkMultiResolutionMesh* ZkMultiResolutionMesh_loadVfs(ZkVfs* vfs, ZkString name);
ZKC_API void ZkMultiResolutionMesh_del(ZkMultiResolutionMesh* slf);

ZKC_API ZkVec3f const* ZkMultiResolutionMesh_getPositions(ZkMultiResolutionMesh const* slf, ZkSize* count);
ZKC_API ZkVec3f const* ZkMultiResolutionMesh_getNormals(ZkMultiResolutionMesh const* slf, ZkSize* count);
ZKC_API ZkSize ZkMultiResolutionMesh_getPositionCount(ZkMultiResolutionMesh const* slf);
ZKC_API ZkVec3f ZkMultiResolutionMesh_getPosition(ZkMultiResolutionMesh const* slf, ZkSize i);
ZKC_API void
ZkMultiResolutionMesh_enumeratePositions(ZkMultiResolutionMesh const* slf, ZkVec3fEnumerator cb, void* ctx);

ZKC_API ZkSize ZkMultiResolutionMesh_getNormalCount(ZkMultiResolutionMesh const* slf);
ZKC_API ZkVec3f ZkMultiResolutionMesh_getNormal(ZkMultiResolutionMesh const* slf, ZkSize i);
ZKC_API void ZkMultiResolutionMesh_enumerateNormals(ZkMultiResolutionMesh const* slf, ZkVec3fEnumerator cb, void* ctx);

ZKC_API ZkSize ZkMultiResolutionMesh_getSubMeshCount(ZkMultiResolutionMesh const* slf);
ZKC_API ZkSubMesh const* ZkMultiResolutionMesh_getSubMesh(ZkMultiResolutionMesh const* slf, ZkSize i);
Expand All @@ -73,10 +89,18 @@ ZKC_API ZkOrientedBoundingBox const* ZkMultiResolutionMesh_getOrientedBbox(ZkMul

ZKC_API ZkMaterial const* ZkSubMesh_getMaterial(ZkSubMesh const* slf);
ZKC_API ZkMeshTriangle const* ZkSubMesh_getTriangles(ZkSubMesh const* slf, ZkSize* count);
ZKC_API ZkMeshWedge const* ZkSubMesh_getWedges(ZkSubMesh const* slf, ZkSize* count);

ZKC_API ZkSize ZkSubMesh_getWedgeCount(ZkSubMesh const* slf);
ZKC_API ZkMeshWedge ZkSubMesh_getWedge(ZkSubMesh const* slf, ZkSize i);
ZKC_API void ZkSubMesh_enumerateWedges(ZkSubMesh const* slf, ZkMeshWedgeEnumerator cb, void* ctx);

ZKC_API float const* ZkSubMesh_getColors(ZkSubMesh const* slf, ZkSize* count);
ZKC_API uint16_t const* ZkSubMesh_getTrianglePlaneIndices(ZkSubMesh const* slf, ZkSize* count);
ZKC_API ZkMeshPlane const* ZkSubMesh_getTrianglePlanes(ZkSubMesh const* slf, ZkSize* count);

ZKC_API ZkSize ZkSubMesh_getTrianglePlaneCount(ZkSubMesh const* slf);
ZKC_API ZkMeshPlane ZkSubMesh_getTrianglePlane(ZkSubMesh const* slf, ZkSize i);
ZKC_API void ZkSubMesh_enumerateTrianglePlanes(ZkSubMesh const* slf, ZkMeshPlaneEnumerator cb, void* ctx);

ZKC_API ZkMeshTriangleEdge const* ZkSubMesh_getTriangleEdges(ZkSubMesh const* slf, ZkSize* count);
ZKC_API ZkMeshEdge const* ZkSubMesh_getEdges(ZkSubMesh const* slf, ZkSize* count);
ZKC_API float const* ZkSubMesh_getEdgeScores(ZkSubMesh const* slf, ZkSize* count);
Expand Down
38 changes: 29 additions & 9 deletions include/zenkit-capi/SoftSkinMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,57 @@
#include "Date.h"
#include "Library.h"
#include "MultiResolutionMesh.h"
#include "SoftSkinMesh.h"
#include "Vector.h"

#ifdef __cplusplus
#include <zenkit/ModelMesh.hh>
using ZkSoftSkinMesh = zenkit::SoftSkinMesh;
using ZkSoftSkinWedgeNormal = zenkit::SoftSkinWedgeNormal;
using ZkSoftSkinWeightEntry = zenkit::SoftSkinWeightEntry;
#else
typedef struct ZkInternal_SoftSkinMesh ZkSoftSkinMesh;
#endif

typedef struct {
typedef struct ZkInternal_SoftSkinWedgeNormal {
ZkVec3f normal;
uint32_t index;

#ifdef __cplusplus
ZkInternal_SoftSkinWedgeNormal() : normal(), index(0) {}
ZkInternal_SoftSkinWedgeNormal(zenkit::SoftSkinWedgeNormal const& v) : normal(v.normal), index(v.index) {}
#endif
} ZkSoftSkinWedgeNormal;

typedef struct {
typedef struct ZkInternal_SoftSkinWeightEntry {
float weight;
ZkVec3f position;
uint8_t node_index;
} ZkSoftSkinWeightEntry;

#ifdef __cplusplus
ZkInternal_SoftSkinWeightEntry() : weight(0), position(), node_index(0) {}
ZkInternal_SoftSkinWeightEntry(zenkit::SoftSkinWeightEntry const& v)
: weight(v.weight), position(v.position), node_index(v.node_index) {}
#endif
} ZkSoftSkinWeightEntry;

typedef ZkBool (*ZkSoftSkinMeshEnumerator)(void* ctx, ZkSoftSkinMesh const* mesh);
typedef ZkBool (*ZkSoftSkinWeightEnumerator)(void* ctx, ZkSoftSkinWeightEntry const* entry, ZkSize count);
typedef ZkBool (*ZkSoftSkinWeightEnumerator)(void* ctx, ZkSoftSkinWeightEntry* entry);
typedef ZkBool (*ZkSoftSkinWedgeNormalEnumerator)(void* ctx, ZkSoftSkinWedgeNormal normal);

ZKC_API ZkSize ZkSoftSkinMesh_getNodeCount(ZkSoftSkinMesh const* slf);
ZKC_API ZkMultiResolutionMesh const* ZkSoftSkinMesh_getMesh(ZkSoftSkinMesh const* slf);
ZKC_API ZkOrientedBoundingBox const* ZkSoftSkinMesh_getBbox(ZkSoftSkinMesh const* slf, ZkSize node);
ZKC_API void
ZkSoftSkinMesh_enumerateBoundingBoxes(ZkSoftSkinMesh const* slf, ZkOrientedBoundingBoxEnumerator cb, void* ctx);
ZKC_API ZkSoftSkinWeightEntry const* ZkSoftSkinMesh_getWeights(ZkSoftSkinMesh const* slf, ZkSize node, ZkSize* count);
ZKC_API void ZkSoftSkinMesh_enumerateWeights(ZkSoftSkinMesh const* slf, ZkSoftSkinWeightEnumerator cb, void* ctx);
ZKC_API ZkSoftSkinWedgeNormal const* ZkSoftSkinMesh_getWedgeNormals(ZkSoftSkinMesh const* slf, ZkSize* count);

ZKC_API ZkSize ZkSoftSkinMesh_getWeightTotal(ZkSoftSkinMesh const* slf);
ZKC_API ZkSize ZkSoftSkinMesh_getWeightCount(ZkSoftSkinMesh const* slf, ZkSize node);
ZKC_API ZkSoftSkinWeightEntry ZkSoftSkinMesh_getWeight(ZkSoftSkinMesh const* slf, ZkSize node, ZkSize i);
ZKC_API void
ZkSoftSkinMesh_enumerateWeights(ZkSoftSkinMesh const* slf, ZkSize node, ZkSoftSkinWeightEnumerator cb, void* ctx);

ZKC_API ZkSize ZkSoftSkinMesh_getWedgeNormalCount(ZkSoftSkinMesh const* slf);
ZKC_API ZkSoftSkinWedgeNormal ZkSoftSkinMesh_getWedgeNormal(ZkSoftSkinMesh const* slf, ZkSize i);
ZKC_API void
ZkSoftSkinMesh_enumerateWedgeNormals(ZkSoftSkinMesh const* slf, ZkSoftSkinWedgeNormalEnumerator cb, void* ctx);

ZKC_API int32_t const* ZkSoftSkinMesh_getNodes(ZkSoftSkinMesh const* slf, ZkSize* count);
6 changes: 5 additions & 1 deletion include/zenkit-capi/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ ZKC_API uint32_t ZkTexture_getWidthRef(ZkTexture const* slf);
ZKC_API uint32_t ZkTexture_getHeightRef(ZkTexture const* slf);
ZKC_API uint32_t ZkTexture_getMipmapCount(ZkTexture const* slf);
ZKC_API uint32_t ZkTexture_getAverageColor(ZkTexture const* slf);
ZKC_API ZkColorArgb const* ZkTexture_getPalette(ZkTexture const* slf, ZkSize* size);

ZKC_API ZkSize ZkTexture_getPaletteSize(ZkTexture const* slf);
ZKC_API ZkColor ZkTexture_getPaletteItem(ZkTexture const* slf, ZkSize i);
ZKC_API void ZkTexture_enumeratePaletteItems(ZkTexture const* slf, ZkColorEnumerator cb, void* ctx);

ZKC_API uint8_t const* ZkTexture_getMipmapRaw(ZkTexture const* slf, ZkSize level, ZkSize* size);
ZKC_API ZkSize ZkTexture_getMipmapRgba(ZkTexture const* slf, ZkSize level, uint8_t* buf, ZkSize size);

Expand Down
75 changes: 57 additions & 18 deletions include/zenkit-capi/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,78 @@
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/ext/quaternion_float.hpp>
#include <glm/gtc/quaternion.hpp>
#include <zenkit/Texture.hh>
#endif

using ZkVec2f = glm::vec2;
using ZkVec3f = glm::vec3;
using ZkVec4f = glm::vec4;
using ZkQuat = glm::quat;
using ZkColor = glm::u8vec4;
using ZkColorArgb = zenkit::ColorARGB;
#else

typedef struct {
typedef struct ZkInternal_Vec2 {
float x, y;

#ifdef __cplusplus
ZkInternal_Vec2() : x(0), y(0) {}
ZkInternal_Vec2(glm::vec2 v) : x(v.x), y(v.y) {}

operator glm::vec2() const {
return {x, y};
}
#endif
} ZkVec2f;

typedef struct {
typedef struct ZkInternal_Vec3 {
float x, y, z;

#ifdef __cplusplus
ZkInternal_Vec3() : x(0), y(0), z(0) {}
ZkInternal_Vec3(glm::vec3 v) : x(v.x), y(v.y), z(v.z) {}

operator glm::vec3() const {
return {x, y, z};
}
#endif
} ZkVec3f;

typedef struct {
typedef struct ZkInternal_Vec4 {
float x, y, z, w;

#ifdef __cplusplus
ZkInternal_Vec4() : x(0), y(0), z(0), w(0) {}
ZkInternal_Vec4(glm::vec4 v) : x(v.x), y(v.y), z(v.z), w(v.w) {}

operator glm::vec4() const {
return {x, y, z, w};
}
#endif
} ZkVec4f;

typedef struct {
typedef struct ZkInternal_Quat {
float x, y, z, w;

#ifdef __cplusplus
ZkInternal_Quat() : x(0), y(0), z(0), w(0) {}
ZkInternal_Quat(glm::quat v) : x(v.x), y(v.y), z(v.z), w(v.w) {}

operator glm::quat() const {
return {w, x, y, z};
}
#endif
} ZkQuat;

typedef struct {
typedef struct ZkInternal_Color {
uint8_t r, g, b, a;
} ZkColor;

typedef struct {
uint8_t a, r, g, b;
} ZkColorArgb;
#ifdef __cplusplus
ZkInternal_Color() : r(0), g(0), b(0), a(255) {}
ZkInternal_Color(glm::u8vec4 v) : r(v.r), g(v.g), b(v.b), a(v.a) {}
ZkInternal_Color(zenkit::ColorARGB v) : r(v.r), g(v.g), b(v.b), a(v.a) {}

operator glm::u8vec4() const {
return {r, g, b, a};
}
#endif
} ZkColor;

typedef ZkBool (*ZkVec2fEnumerator)(void* ctx, ZkVec2f v);
typedef ZkBool (*ZkVec3fEnumerator)(void* ctx, ZkVec3f v);
typedef ZkBool (*ZkVec4fEnumerator)(void* ctx, ZkVec4f v);
typedef ZkBool (*ZkQuatEnumerator)(void* ctx, ZkQuat v);
typedef ZkBool (*ZkColorEnumerator)(void* ctx, ZkColor v);
Loading

0 comments on commit 1af0df3

Please sign in to comment.