Explorar el Código

Replace external libraries custom allocators by raylib ones #1074

NOTE: Two libraries still use custom allocators: glfw and stb_vorbis
raysan5 hace 5 años
padre
commit
2344941974
Se han modificado 5 ficheros con 51 adiciones y 4 borrados
  1. 6 0
      src/core.c
  2. 15 2
      src/models.c
  3. 19 0
      src/raudio.c
  4. 3 0
      src/rlgl.h
  5. 8 2
      src/textures.c

+ 6 - 0
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()]

+ 15 - 2
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;

+ 19 - 0
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

+ 3 - 0
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

+ 8 - 2
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)