summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-03-17 13:40:07 +0100
committerraysan5 <[email protected]>2020-03-17 13:40:07 +0100
commit23449419744e463fea32c597ac967f064b14422c (patch)
tree4c0061802983768ba11e818daa217c18c1cad5a3 /src
parent6f41b9594a3f107ad7332af197cdd3565b7d33fe (diff)
downloadraylib-23449419744e463fea32c597ac967f064b14422c.tar.gz
raylib-23449419744e463fea32c597ac967f064b14422c.zip
Replace external libraries custom allocators by raylib ones #1074
NOTE: Two libraries still use custom allocators: glfw and stb_vorbis
Diffstat (limited to 'src')
-rw-r--r--src/core.c6
-rw-r--r--src/models.c17
-rw-r--r--src/raudio.c19
-rw-r--r--src/rlgl.h3
-rw-r--r--src/textures.c10
5 files changed, 51 insertions, 4 deletions
diff --git a/src/core.c b/src/core.c
index c759833b..5eb7e21f 100644
--- a/src/core.c
+++ b/src/core.c
@@ -146,6 +146,9 @@
#endif
#if defined(SUPPORT_GIF_RECORDING)
+ #define RGIF_MALLOC RL_MALLOC
+ #define RGIF_FREE RL_FREE
+
#define RGIF_IMPLEMENTATION
#include "external/rgif.h" // Support GIF recording
#endif
@@ -163,6 +166,9 @@
#include <sys/stat.h> // Required for: stat() [Used in GetFileModTime()]
#if (defined(PLATFORM_DESKTOP) || defined(PLATFORM_UWP)) && defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__))
+ #define DIRENT_MALLOC RL_MALLOC
+ #define DIRENT_FREE RL_FREE
+
#include "external/dirent.h" // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()]
#else
#include <dirent.h> // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()]
diff --git a/src/models.c b/src/models.c
index 60e9ca7a..491ca409 100644
--- a/src/models.c
+++ b/src/models.c
@@ -53,17 +53,30 @@
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
#if defined(SUPPORT_FILEFORMAT_OBJ) || defined(SUPPORT_FILEFORMAT_MTL)
+ #define TINYOBJ_MALLOC RL_MALLOC
+ #define TINYOBJ_CALLOC RL_CALLOC
+ #define TINYOBJ_REALLOC RL_REALLOC
+ #define TINYOBJ_FREE RL_FREE
+
#define TINYOBJ_LOADER_C_IMPLEMENTATION
#include "external/tinyobj_loader_c.h" // OBJ/MTL file formats loading
#endif
#if defined(SUPPORT_FILEFORMAT_GLTF)
+ #define CGLTF_MALLOC RL_MALLOC
+ #define CGLTF_FREE RL_FREE
+
#define CGLTF_IMPLEMENTATION
#include "external/cgltf.h" // glTF file format loading
#include "external/stb_image.h" // glTF texture images loading
#endif
#if defined(SUPPORT_MESH_GENERATION)
+ #define PAR_MALLOC(T, N) ((T*)RL_MALLOC(N*sizeof(T)))
+ #define PAR_CALLOC(T, N) ((T*)RL_CALLOC(N*sizeof(T), 1))
+ #define PAR_REALLOC(T, BUF, N) ((T*)RL_REALLOC(BUF, sizeof(T)*(N)))
+ #define PAR_FREE RL_FREE
+
#define PAR_SHAPES_IMPLEMENTATION
#include "external/par_shapes.h" // Shapes 3d parametric generation
#endif
@@ -1122,7 +1135,7 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
Vector3 inTranslation = { 0 };
Quaternion inRotation = { 0 };
- Vector3 inScale = { 0 };
+ //Vector3 inScale = { 0 }; // Not used...
Vector3 outTranslation = { 0 };
Quaternion outRotation = { 0 };
@@ -1137,7 +1150,7 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
boneId = model.meshes[m].boneIds[boneCounter];
inTranslation = model.bindPose[boneId].translation;
inRotation = model.bindPose[boneId].rotation;
- inScale = model.bindPose[boneId].scale;
+ //inScale = model.bindPose[boneId].scale;
outTranslation = anim.framePoses[frame][boneId].translation;
outRotation = anim.framePoses[frame][boneId].rotation;
outScale = anim.framePoses[frame][boneId].scale;
diff --git a/src/raudio.c b/src/raudio.c
index 8dd40015..2d2e1f3c 100644
--- a/src/raudio.c
+++ b/src/raudio.c
@@ -155,6 +155,9 @@ typedef struct tagBITMAPINFOHEADER {
#endif
#endif
+#define MA_MALLOC RL_MALLOC
+#define MA_FREE RL_FREE
+
#define MA_NO_JACK
#define MINIAUDIO_IMPLEMENTATION
#include "external/miniaudio.h" // miniaudio library
@@ -172,27 +175,43 @@ typedef struct tagBITMAPINFOHEADER {
#endif
#if defined(SUPPORT_FILEFORMAT_OGG)
+ // TODO: Remap malloc()/free() calls to RL_MALLOC/RL_FREE
+
#define STB_VORBIS_IMPLEMENTATION
#include "external/stb_vorbis.h" // OGG loading functions
#endif
#if defined(SUPPORT_FILEFORMAT_XM)
+ #define JARXM_MALLOC RL_MALLOC
+ #define JARXM_FREE RL_FREE
+
#define JAR_XM_IMPLEMENTATION
#include "external/jar_xm.h" // XM loading functions
#endif
#if defined(SUPPORT_FILEFORMAT_MOD)
+ #define JARMOD_MALLOC RL_MALLOC
+ #define JARMOD_FREE RL_FREE
+
#define JAR_MOD_IMPLEMENTATION
#include "external/jar_mod.h" // MOD loading functions
#endif
#if defined(SUPPORT_FILEFORMAT_FLAC)
+ #define DRFLAC_MALLOC RL_MALLOC
+ #define DRFLAC_REALLOC RL_REALLOC
+ #define DRFLAC_FREE RL_FREE
+
#define DR_FLAC_IMPLEMENTATION
#define DR_FLAC_NO_WIN32_IO
#include "external/dr_flac.h" // FLAC loading functions
#endif
#if defined(SUPPORT_FILEFORMAT_MP3)
+ #define DRMP3_MALLOC RL_MALLOC
+ #define DRMP3_REALLOC RL_REALLOC
+ #define DRMP3_FREE RL_FREE
+
#define DR_MP3_IMPLEMENTATION
#include "external/dr_mp3.h" // MP3 loading functions
#endif
diff --git a/src/rlgl.h b/src/rlgl.h
index c90905dc..6df8b0b7 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -650,6 +650,9 @@ RLAPI int GetPixelDataSize(int width, int height, int format);// Get pixel data
#include <OpenGL/gl3.h> // OpenGL 3 library for OSX
#include <OpenGL/gl3ext.h> // OpenGL 3 extensions library for OSX
#else
+ #define GLAD_REALLOC RL_REALLOC
+ #define GLAD_FREE RL_FREE
+
#define GLAD_IMPLEMENTATION
#if defined(RLGL_STANDALONE)
#include "glad.h" // GLAD extensions loading library, includes OpenGL headers
diff --git a/src/textures.c b/src/textures.c
index 9122e3b0..9e229b8c 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -124,14 +124,20 @@
#endif
#if defined(SUPPORT_IMAGE_EXPORT)
+ #define STBIW_MALLOC RL_MALLOC
+ #define STBIW_FREE RL_FREE
+ #define STBIW_REALLOC RL_REALLOC
+
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "external/stb_image_write.h" // Required for: stbi_write_*()
#endif
#if defined(SUPPORT_IMAGE_MANIPULATION)
+ #define STBIR_MALLOC(size,c) ((void)(c), RL_MALLOC(size))
+ #define STBIR_FREE(ptr,c) ((void)(c), RL_FREE(ptr))
+
#define STB_IMAGE_RESIZE_IMPLEMENTATION
- #include "external/stb_image_resize.h" // Required for: stbir_resize_uint8()
- // NOTE: Used for image scaling on ImageResize()
+ #include "external/stb_image_resize.h" // Required for: stbir_resize_uint8() [ImageResize()]
#endif
#if defined(SUPPORT_IMAGE_GENERATION)