3 Commits

Author SHA1 Message Date
Ray
7cbadefd06 Remove some spacing on module data 2026-11-24 21:09:37 +01:00
Ray
9fcb245f28 Clipboard image enabled by default 2026-11-24 21:09:03 +01:00
dd8e7491e2 [rmodels] Fix memory leak in LoadModelAnimations() (#6449) 2026-11-24 15:14:10 +01:00
14 changed files with 77 additions and 86 deletions

View File

@ -113,16 +113,6 @@
// Enabling this flag allows manual control of the frame processes, use at your own risk // Enabling this flag allows manual control of the frame processes, use at your own risk
#define SUPPORT_CUSTOM_FRAME_CONTROL 0 // Disabled by default #define SUPPORT_CUSTOM_FRAME_CONTROL 0 // Disabled by default
#endif #endif
#ifndef SUPPORT_CLIPBOARD_IMAGE
// Support for clipboard image loading
// NOTE: Only working on SDL3, GLFW (Windows) and RGFW (Windows)
// WARNING: It requires support for some additional flags:
// - SUPPORT_MODULE_RTEXTURES
// - SUPPORT_FILEFORMAT_BMP (Windows clipboard)
// - SUPPORT_FILEFORMAT_PNG (Wayland clipboard)
// - SUPPORT_FILEFORMAT_JPG
#define SUPPORT_CLIPBOARD_IMAGE 1
#endif
// rcore: Configuration values // rcore: Configuration values
// NOTE: Below values are already defined inside [rcore.c] so there is no need to be // NOTE: Below values are already defined inside [rcore.c] so there is no need to be

View File

@ -721,7 +721,7 @@ Image GetClipboardImage(void)
{ {
Image image = { 0 }; Image image = { 0 };
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
return image; return image;
} }

View File

@ -1080,7 +1080,7 @@ void SetClipboardText(const char *text)
} }
// Get clipboard text content // Get clipboard text content
// NOTE: returned string is allocated and freed by GLFW // NOTE: Returned string is allocated and freed by GLFW
const char *GetClipboardText(void) const char *GetClipboardText(void)
{ {
return glfwGetClipboardString(platform.handle); return glfwGetClipboardString(platform.handle);
@ -1108,7 +1108,11 @@ Image GetClipboardImage(void)
{ {
Image image = { 0 }; Image image = { 0 };
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES #if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
#if defined(_WIN32) #if defined(_WIN32)
unsigned int dataSize = 0; unsigned int dataSize = 0;
void *bmpData = NULL; void *bmpData = NULL;
@ -1163,11 +1167,8 @@ Image GetClipboardImage(void)
XFree(data); XFree(data);
} }
#else #else
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); TRACELOG(LOG_WARNING, "Clipboard image not implemented on target platform");
#endif #endif
#else
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
#endif // SUPPORT_CLIPBOARD_IMAGE
return image; return image;
} }

View File

@ -168,6 +168,17 @@ extern "C" {
#undef Size #undef Size
#endif #endif
#if defined(_WIN32)
#define WIN32_CLIPBOARD_IMPLEMENTATION
#define WINUSER_ALREADY_INCLUDED
#define WINBASE_ALREADY_INCLUDED
#define WINGDI_ALREADY_INCLUDED
#include "../external/win32_clipboard.h"
#elif defined(__linux__) && defined(DRGFW_X11)
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#endif
#include <stdbool.h> #include <stdbool.h>
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -1307,26 +1318,17 @@ const char *GetClipboardText(void)
return RGFW_readClipboard(NULL); return RGFW_readClipboard(NULL);
} }
#if SUPPORT_CLIPBOARD_IMAGE
#if defined(_WIN32)
#define WIN32_CLIPBOARD_IMPLEMENTATION
#define WINUSER_ALREADY_INCLUDED
#define WINBASE_ALREADY_INCLUDED
#define WINGDI_ALREADY_INCLUDED
#include "../external/win32_clipboard.h"
#elif defined(__linux__) && defined(DRGFW_X11)
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#endif
#endif
// Get clipboard image // Get clipboard image
Image GetClipboardImage(void) Image GetClipboardImage(void)
{ {
Image image = { 0 }; Image image = { 0 };
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES #if !SUPPORT_MODULE_RTEXTURES
#if defined(_WIN32 TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
#if defined(_WIN32)
unsigned int dataSize = 0; unsigned int dataSize = 0;
void *fileData = NULL; void *fileData = NULL;
@ -1386,11 +1388,8 @@ Image GetClipboardImage(void)
XDestroyWindow(dpy, win); XDestroyWindow(dpy, win);
XCloseDisplay(dpy); XCloseDisplay(dpy);
#else #else
TRACELOG(LOG_WARNING, "Clipboard image: PLATFORM_DESKTOP_RGFW doesn't implement GetClipboardImage() for this OS"); TRACELOG(LOG_WARNING, "Clipboard image not implemented on target platform");
#endif // _WIN32 #endif
#else
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
#endif // SUPPORT_CLIPBOARD_IMAGE
return image; return image;
} }

View File

@ -1215,22 +1215,22 @@ Image GetClipboardImage(void)
{ {
Image image = { 0 }; Image image = { 0 };
#if SUPPORT_CLIPBOARD_IMAGE
#if !SUPPORT_MODULE_RTEXTURES #if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Enabling SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly"); TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image; return image;
#endif #endif
// It's nice to have support Bitmap on Linux as well, but not as necessary as Windows // It's nice to have support Bitmap on Linux as well, but not as necessary as Windows
#if !SUPPORT_FILEFORMAT_BMP && defined(_WIN32) #if !SUPPORT_FILEFORMAT_BMP && defined(_WIN32)
TRACELOG(LOG_WARNING, "WARNING: Enabling SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_FILEFORMAT_BMP, specially on Windows"); TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_FILEFORMAT_BMP on Windows");
return image; return image;
#endif #endif
// From what I've tested applications on Wayland saves images on clipboard as PNG // From what I've tested applications on Wayland saves images on clipboard as PNG
#if (!SUPPORT_FILEFORMAT_PNG || !SUPPORT_FILEFORMAT_JPG) && !defined(_WIN32) #if (!SUPPORT_FILEFORMAT_PNG || !SUPPORT_FILEFORMAT_JPG) && !defined(_WIN32)
TRACELOG(LOG_WARNING, "WARNING: Getting image from the clipboard might not work without SUPPORT_FILEFORMAT_PNG or SUPPORT_FILEFORMAT_JPG"); TRACELOG(LOG_WARNING, "Clipboard image might require SUPPORT_FILEFORMAT_PNG or SUPPORT_FILEFORMAT_JPG");
#endif #endif
// Let's hope compiler put these arrays in static memory // Let's hope compiler put these arrays in static memory
const char *imageFormats[] = { const char *imageFormats[] = {
"image/bmp", "image/bmp",
@ -1238,6 +1238,7 @@ Image GetClipboardImage(void)
"image/jpg", "image/jpg",
"image/tiff", "image/tiff",
}; };
const char *imageExtensions[] = { const char *imageExtensions[] = {
".bmp", ".bmp",
".png", ".png",
@ -1246,7 +1247,7 @@ Image GetClipboardImage(void)
}; };
size_t dataSize = 0; size_t dataSize = 0;
void *fileData = NULL; void *fileData = NULL;
for (int i = 0; i < SDL_arraysize(imageFormats); i++) for (int i = 0; i < SDL_arraysize(imageFormats); i++)
{ {
@ -1259,14 +1260,13 @@ Image GetClipboardImage(void)
if (IsImageValid(image)) if (IsImageValid(image))
{ {
TRACELOG(LOG_INFO, "Clipboard: Got image from clipboard successfully: %s", imageExtensions[i]); TRACELOG(LOG_INFO, "Clipboard image retrieved successfully (%s image data)", imageExtensions[i]);
return image; return image;
} }
} }
} }
if (!IsImageValid(image)) TRACELOG(LOG_WARNING, "Clipboard: Couldn't get clipboard data. ERROR: %s", SDL_GetError()); if (!IsImageValid(image)) TRACELOG(LOG_WARNING, "Clipboard image data can not be retrieved, ERROR: %s", SDL_GetError());
#endif // SUPPORT_CLIPBOARD_IMAGE
return image; return image;
} }

View File

@ -91,13 +91,11 @@ typedef enum MONITOR_DPI_TYPE {
#include <GL/gl.h> #include <GL/gl.h>
#endif #endif
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES #define WIN32_CLIPBOARD_IMPLEMENTATION
#define WIN32_CLIPBOARD_IMPLEMENTATION #define WINUSER_ALREADY_INCLUDED
#define WINUSER_ALREADY_INCLUDED #define WINBASE_ALREADY_INCLUDED
#define WINBASE_ALREADY_INCLUDED #define WINGDI_ALREADY_INCLUDED
#define WINGDI_ALREADY_INCLUDED #include "../external/win32_clipboard.h"
#include "../external/win32_clipboard.h"
#endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
@ -1485,7 +1483,11 @@ Image GetClipboardImage(void)
{ {
Image image = { 0 }; Image image = { 0 };
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES #if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
unsigned int dataSize = 0; unsigned int dataSize = 0;
void *fileData = NULL; void *fileData = NULL;
int width = 0; int width = 0;
@ -1496,12 +1498,10 @@ Image GetClipboardImage(void)
if (fileData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data."); if (fileData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data.");
else else
{ {
// TODO: Support additional image file-formats
image = LoadImageFromMemory(".bmp", (const unsigned char*)fileData, (int)dataSize); image = LoadImageFromMemory(".bmp", (const unsigned char*)fileData, (int)dataSize);
RL_FREE(fileData); RL_FREE(fileData);
} }
#else
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
#endif
return image; return image;
} }

View File

@ -570,7 +570,7 @@ Image GetClipboardImage(void)
{ {
Image image = { 0 }; Image image = { 0 };
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
return image; return image;
} }

View File

@ -323,7 +323,7 @@ Image GetClipboardImage(void)
{ {
Image image = { 0 }; Image image = { 0 };
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
return image; return image;
} }

View File

@ -302,7 +302,7 @@ Image GetClipboardImage(void)
{ {
Image image = { 0 }; Image image = { 0 };
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
return image; return image;
} }

View File

@ -901,11 +901,16 @@ bool SetClipboardImage(Image image)
Image GetClipboardImage(void) Image GetClipboardImage(void)
{ {
Image image = { 0 }; Image image = { 0 };
int width = 0;
int height = 0; #if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
RequestClipboardData(); RequestClipboardData();
int width = 0;
int height = 0;
unsigned char *data = GetLastPastedImage(&width, &height); unsigned char *data = GetLastPastedImage(&width, &height);
if (data != NULL) if (data != NULL)
@ -1703,7 +1708,6 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
// Gesture data is sent to gestures-system for processing // Gesture data is sent to gestures-system for processing
// Prevent calling ProcessGestureEvent() when Emscripten is present and there's a touch gesture, so EmscriptenTouchCallback() can handle it itself // Prevent calling ProcessGestureEvent() when Emscripten is present and there's a touch gesture, so EmscriptenTouchCallback() can handle it itself
if (GetMouseX() != 0 || GetMouseY() != 0) ProcessGestureEvent(gestureEvent); if (GetMouseX() != 0 || GetMouseY() != 0) ProcessGestureEvent(gestureEvent);
#endif #endif
} }

View File

@ -864,12 +864,15 @@ EM_ASYNC_JS(void, RequestClipboardData, (void), {
EM_JS(char *, GetLastPastedText, (void), { EM_JS(char *, GetLastPastedText, (void), {
var str = window._lastClipboardString || ""; var str = window._lastClipboardString || "";
var length = lengthBytesUTF8(str) + 1; var length = lengthBytesUTF8(str) + 1;
if (length > 1) if (length > 1)
{ {
var ptr = _malloc(length); var ptr = _malloc(length);
stringToUTF8(str, ptr, length); stringToUTF8(str, ptr, length);
return ptr; return ptr;
} }
return 0; return 0;
}); });
@ -885,7 +888,7 @@ EM_JS(unsigned char *, GetLastPastedImage, (int *width, int *height), {
// Set the width and height via the pointers passed from C // Set the width and height via the pointers passed from C
// HEAP32 handles the 4-byte integers // HEAP32 handles the 4-byte integers
if (width) setValue(width, window._lastImgWidth, 'i32'); if (width) setValue(width, window._lastImgWidth, 'i32');
if (height) setValue(height, window._lastImgHeight, 'i32'); if (height) setValue(height, window._lastImgHeight, 'i32');
// Clear the JS buffer so there is no need to fetch the same image twice // Clear the JS buffer so there is no need to fetch the same image twice
@ -921,10 +924,16 @@ bool SetClipboardImage(Image image)
Image GetClipboardImage(void) Image GetClipboardImage(void)
{ {
Image image = { 0 }; Image image = { 0 };
int width = 0;
int height = 0; #if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
RequestClipboardData(); RequestClipboardData();
int width = 0;
int height = 0;
unsigned char *data = GetLastPastedImage(&width, &height); unsigned char *data = GetLastPastedImage(&width, &height);
if (data != NULL) if (data != NULL)

View File

@ -322,11 +322,9 @@ typedef struct CoreData {
char **dropFilepaths; // Store dropped files paths pointers (provided by GLFW) char **dropFilepaths; // Store dropped files paths pointers (provided by GLFW)
unsigned int dropFileCount; // Count dropped files strings unsigned int dropFileCount; // Count dropped files strings
} Window; } Window;
struct { struct {
const char *basePath; // Base path for data storage const char *basePath; // Base path for data storage
} Storage; } Storage;
struct { struct {
struct { struct {
@ -343,7 +341,6 @@ typedef struct CoreData {
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode) int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
int charPressedQueueCount; // Input characters queue count int charPressedQueueCount; // Input characters queue count
} Keyboard; } Keyboard;
struct { struct {
Vector2 offset; // Mouse offset Vector2 offset; // Mouse offset
@ -361,7 +358,6 @@ typedef struct CoreData {
char previousButtonState[MAX_MOUSE_BUTTONS]; // Registers previous mouse button state char previousButtonState[MAX_MOUSE_BUTTONS]; // Registers previous mouse button state
Vector2 currentWheelMove; // Registers current mouse wheel variation Vector2 currentWheelMove; // Registers current mouse wheel variation
Vector2 previousWheelMove; // Registers previous mouse wheel variation Vector2 previousWheelMove; // Registers previous mouse wheel variation
} Mouse; } Mouse;
struct { struct {
int pointCount; // Number of touch points active int pointCount; // Number of touch points active
@ -370,7 +366,6 @@ typedef struct CoreData {
Vector2 previousPosition[MAX_TOUCH_POINTS]; // Previous touch position on screen Vector2 previousPosition[MAX_TOUCH_POINTS]; // Previous touch position on screen
char currentTouchState[MAX_TOUCH_POINTS]; // Registers current touch state char currentTouchState[MAX_TOUCH_POINTS]; // Registers current touch state
char previousTouchState[MAX_TOUCH_POINTS]; // Registers previous touch state char previousTouchState[MAX_TOUCH_POINTS]; // Registers previous touch state
} Touch; } Touch;
struct { struct {
int lastButtonPressed; // Register last gamepad button pressed int lastButtonPressed; // Register last gamepad button pressed
@ -380,9 +375,7 @@ typedef struct CoreData {
char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXES]; // Gamepad axes state float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXES]; // Gamepad axes state
} Gamepad; } Gamepad;
} Input; } Input;
struct { struct {
double current; // Current time measure (seconds) double current; // Current time measure (seconds)
@ -393,7 +386,6 @@ typedef struct CoreData {
double target; // Desired time for one frame, if 0 not applied (seconds) double target; // Desired time for one frame, if 0 not applied (seconds)
unsigned long long base; // Base time measure for hi-res timer (ticks or nanoseconds) unsigned long long base; // Base time measure for hi-res timer (ticks or nanoseconds)
unsigned int frameCounter; // Frame counter (frames) unsigned int frameCounter; // Frame counter (frames)
} Time; } Time;
} CoreData; } CoreData;
@ -579,6 +571,13 @@ const char *TextFormat(const char *text, ...); // Formatting of text with variab
//Vector2 GetMonitorPosition(int monitor) //Vector2 GetMonitorPosition(int monitor)
//const char *GetMonitorName(int monitor) //const char *GetMonitorName(int monitor)
// Clipboard interaction support
// NOTE: Only working on SDL3, GLFW (Windows) and RGFW (Windows)
// WARNING: It requires support for some additional flags:
// - SUPPORT_MODULE_RTEXTURES
// - SUPPORT_FILEFORMAT_BMP (Windows clipboard)
// - SUPPORT_FILEFORMAT_PNG (Wayland clipboard)
// - SUPPORT_FILEFORMAT_JPG
//void SetClipboardText(const char *text) //void SetClipboardText(const char *text)
//const char *GetClipboardText(void) //const char *GetClipboardText(void)
//bool SetClipboardImage(Image image) //bool SetClipboardImage(Image image)
@ -2694,9 +2693,7 @@ const char *GetApplicationDirectory(void)
appDir[0] = '.'; appDir[0] = '.';
appDir[1] = '\\'; appDir[1] = '\\';
} }
#elif defined(__linux__) #elif defined(__linux__)
unsigned int size = sizeof(appDir); unsigned int size = sizeof(appDir);
ssize_t len = readlink("/proc/self/exe", appDir, size); ssize_t len = readlink("/proc/self/exe", appDir, size);
@ -2716,9 +2713,7 @@ const char *GetApplicationDirectory(void)
appDir[0] = '.'; appDir[0] = '.';
appDir[1] = '/'; appDir[1] = '/';
} }
#elif defined(__APPLE__) #elif defined(__APPLE__)
uint32_t size = sizeof(appDir); uint32_t size = sizeof(appDir);
if (_NSGetExecutablePath(appDir, &size) == 0) if (_NSGetExecutablePath(appDir, &size) == 0)
@ -2738,9 +2733,7 @@ const char *GetApplicationDirectory(void)
appDir[0] = '.'; appDir[0] = '.';
appDir[1] = '/'; appDir[1] = '/';
} }
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
size_t size = sizeof(appDir); size_t size = sizeof(appDir);
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
@ -2761,9 +2754,7 @@ const char *GetApplicationDirectory(void)
appDir[0] = '.'; appDir[0] = '.';
appDir[1] = '/'; appDir[1] = '/';
} }
#elif defined(__wasm__) #elif defined(__wasm__)
appDir[0] = '/'; appDir[0] = '/';
#endif #endif

View File

@ -1079,7 +1079,6 @@ typedef struct rlglData {
int framebufferWidth; // Current framebuffer width int framebufferWidth; // Current framebuffer width
int framebufferHeight; // Current framebuffer height int framebufferHeight; // Current framebuffer height
} State; // Renderer state } State; // Renderer state
struct { struct {
bool vao; // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object) bool vao; // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
@ -1101,7 +1100,6 @@ typedef struct rlglData {
float maxAnisotropyLevel; // Maximum anisotropy level supported (minimum is 2.0f) float maxAnisotropyLevel; // Maximum anisotropy level supported (minimum is 2.0f)
int maxDepthBits; // Maximum bits for depth component int maxDepthBits; // Maximum bits for depth component
} ExtSupported; // Extensions supported flags } ExtSupported; // Extensions supported flags
} rlglData; } rlglData;

View File

@ -6808,10 +6808,9 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
{ {
TRACELOG(LOG_WARNING, "MODEL: [%s] Expected one unique skin to load animation data from, but found %i", fileName, data->skins_count); TRACELOG(LOG_WARNING, "MODEL: [%s] Expected one unique skin to load animation data from, but found %i", fileName, data->skins_count);
} }
cgltf_free(data);
} }
cgltf_free(data);
UnloadFileData(fileData); UnloadFileData(fileData);
return animations; return animations;