Merge branch 'master' into master
This commit is contained in:
commit
db2abfb9be
28 changed files with 34715 additions and 15170 deletions
|
|
@ -868,7 +868,7 @@ clean: clean_shell_$(PLATFORM_SHELL)
|
|||
@echo "removed all generated files!"
|
||||
|
||||
clean_shell_sh:
|
||||
rm -fv *.o $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).a $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).bc $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).so* raygui.c $(RAYLIB_RELEASE_PATH)/*-protocol.h $(RAYLIB_RELEASE_PATH)/*-protocol-code.h
|
||||
rm -fv *.o $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).a $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).web.a $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).so* raygui.c $(RAYLIB_RELEASE_PATH)/*-protocol.h $(RAYLIB_RELEASE_PATH)/*-protocol-code.h
|
||||
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
|
||||
rm -fv $(NATIVE_APP_GLUE)/android_native_app_glue.o
|
||||
endif
|
||||
|
|
@ -879,6 +879,7 @@ clean_shell_cmd:
|
|||
del *.o /s
|
||||
cd $(RAYLIB_RELEASE_PATH) & \
|
||||
del lib$(RAYLIB_LIB_NAME).a /s & \
|
||||
del lib$(RAYLIB_LIB_NAME).web.a /s & \
|
||||
del lib$(RAYLIB_LIB_NAME)dll.a /s & \
|
||||
del $(RAYLIB_LIB_NAME).dll /s & \
|
||||
del raygui.c /s & \
|
||||
|
|
|
|||
14
src/config.h
14
src/config.h
|
|
@ -95,7 +95,6 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// rcore: Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
#define MAX_FILEPATH_CAPACITY 8192 // Maximum file paths capacity
|
||||
|
|
@ -104,7 +103,7 @@
|
|||
#define MAX_KEYBOARD_KEYS 512 // Maximum number of keyboard keys supported
|
||||
#define MAX_MOUSE_BUTTONS 8 // Maximum number of mouse buttons supported
|
||||
#define MAX_GAMEPADS 4 // Maximum number of gamepads supported
|
||||
#define MAX_GAMEPAD_AXIS 8 // Maximum number of axis supported (per gamepad)
|
||||
#define MAX_GAMEPAD_AXES 8 // Maximum number of axes supported (per gamepad)
|
||||
#define MAX_GAMEPAD_BUTTONS 32 // Maximum number of buttons supported (per gamepad)
|
||||
#define MAX_GAMEPAD_VIBRATION_TIME 2.0f // Maximum vibration time in seconds
|
||||
#define MAX_TOUCH_POINTS 8 // Maximum number of touch points supported
|
||||
|
|
@ -136,8 +135,8 @@
|
|||
|
||||
#define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
|
||||
|
||||
#define RL_CULL_DISTANCE_NEAR 0.001 // Default projection matrix near cull distance
|
||||
#define RL_CULL_DISTANCE_FAR 10000.0 // Default projection matrix far cull distance
|
||||
#define RL_CULL_DISTANCE_NEAR 0.05 // Default projection matrix near cull distance
|
||||
#define RL_CULL_DISTANCE_FAR 4000.0 // Default projection matrix far cull distance
|
||||
|
||||
// Default shader vertex attribute locations
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION 0
|
||||
|
|
@ -153,7 +152,6 @@
|
|||
#endif
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX 9
|
||||
|
||||
|
||||
// Default shader vertex attribute names to set location points
|
||||
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION
|
||||
|
|
@ -173,7 +171,6 @@
|
|||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: rshapes - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
|
|
@ -185,11 +182,10 @@
|
|||
//------------------------------------------------------------------------------------
|
||||
#define SPLINE_SEGMENT_DIVISIONS 24 // Spline segments subdivisions
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: rtextures - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
// Selecte desired fileformats to be supported for image data loading
|
||||
// Selected desired fileformats to be supported for image data loading
|
||||
#define SUPPORT_FILEFORMAT_PNG 1
|
||||
//#define SUPPORT_FILEFORMAT_BMP 1
|
||||
//#define SUPPORT_FILEFORMAT_TGA 1
|
||||
|
|
@ -213,7 +209,6 @@
|
|||
// If not defined, still some functions are supported: ImageFormat(), ImageCrop(), ImageToPOT()
|
||||
#define SUPPORT_IMAGE_MANIPULATION 1
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: rtext - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
|
|
@ -240,7 +235,6 @@
|
|||
// TextFormat(), TextSubtext(), TextToUpper(), TextToLower(), TextToPascal(), TextSplit()
|
||||
#define MAX_TEXTSPLIT_COUNT 128 // Maximum number of substrings to split: TextSplit()
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: rmodels - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
|
|
|
|||
21393
src/external/RGFW.h
vendored
21393
src/external/RGFW.h
vendored
File diff suppressed because it is too large
Load diff
462
src/external/dr_flac.h
vendored
462
src/external/dr_flac.h
vendored
|
|
@ -1,121 +1,12 @@
|
|||
/*
|
||||
FLAC audio decoder. Choice of public domain or MIT-0. See license statements at the end of this file.
|
||||
dr_flac - v0.12.42 - 2023-11-02
|
||||
dr_flac - v0.13.0 - TBD
|
||||
|
||||
David Reid - mackron@gmail.com
|
||||
|
||||
GitHub: https://github.com/mackron/dr_libs
|
||||
*/
|
||||
|
||||
/*
|
||||
RELEASE NOTES - v0.12.0
|
||||
=======================
|
||||
Version 0.12.0 has breaking API changes including changes to the existing API and the removal of deprecated APIs.
|
||||
|
||||
|
||||
Improved Client-Defined Memory Allocation
|
||||
-----------------------------------------
|
||||
The main change with this release is the addition of a more flexible way of implementing custom memory allocation routines. The
|
||||
existing system of DRFLAC_MALLOC, DRFLAC_REALLOC and DRFLAC_FREE are still in place and will be used by default when no custom
|
||||
allocation callbacks are specified.
|
||||
|
||||
To use the new system, you pass in a pointer to a drflac_allocation_callbacks object to drflac_open() and family, like this:
|
||||
|
||||
void* my_malloc(size_t sz, void* pUserData)
|
||||
{
|
||||
return malloc(sz);
|
||||
}
|
||||
void* my_realloc(void* p, size_t sz, void* pUserData)
|
||||
{
|
||||
return realloc(p, sz);
|
||||
}
|
||||
void my_free(void* p, void* pUserData)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
...
|
||||
|
||||
drflac_allocation_callbacks allocationCallbacks;
|
||||
allocationCallbacks.pUserData = &myData;
|
||||
allocationCallbacks.onMalloc = my_malloc;
|
||||
allocationCallbacks.onRealloc = my_realloc;
|
||||
allocationCallbacks.onFree = my_free;
|
||||
drflac* pFlac = drflac_open_file("my_file.flac", &allocationCallbacks);
|
||||
|
||||
The advantage of this new system is that it allows you to specify user data which will be passed in to the allocation routines.
|
||||
|
||||
Passing in null for the allocation callbacks object will cause dr_flac to use defaults which is the same as DRFLAC_MALLOC,
|
||||
DRFLAC_REALLOC and DRFLAC_FREE and the equivalent of how it worked in previous versions.
|
||||
|
||||
Every API that opens a drflac object now takes this extra parameter. These include the following:
|
||||
|
||||
drflac_open()
|
||||
drflac_open_relaxed()
|
||||
drflac_open_with_metadata()
|
||||
drflac_open_with_metadata_relaxed()
|
||||
drflac_open_file()
|
||||
drflac_open_file_with_metadata()
|
||||
drflac_open_memory()
|
||||
drflac_open_memory_with_metadata()
|
||||
drflac_open_and_read_pcm_frames_s32()
|
||||
drflac_open_and_read_pcm_frames_s16()
|
||||
drflac_open_and_read_pcm_frames_f32()
|
||||
drflac_open_file_and_read_pcm_frames_s32()
|
||||
drflac_open_file_and_read_pcm_frames_s16()
|
||||
drflac_open_file_and_read_pcm_frames_f32()
|
||||
drflac_open_memory_and_read_pcm_frames_s32()
|
||||
drflac_open_memory_and_read_pcm_frames_s16()
|
||||
drflac_open_memory_and_read_pcm_frames_f32()
|
||||
|
||||
|
||||
|
||||
Optimizations
|
||||
-------------
|
||||
Seeking performance has been greatly improved. A new binary search based seeking algorithm has been introduced which significantly
|
||||
improves performance over the brute force method which was used when no seek table was present. Seek table based seeking also takes
|
||||
advantage of the new binary search seeking system to further improve performance there as well. Note that this depends on CRC which
|
||||
means it will be disabled when DR_FLAC_NO_CRC is used.
|
||||
|
||||
The SSE4.1 pipeline has been cleaned up and optimized. You should see some improvements with decoding speed of 24-bit files in
|
||||
particular. 16-bit streams should also see some improvement.
|
||||
|
||||
drflac_read_pcm_frames_s16() has been optimized. Previously this sat on top of drflac_read_pcm_frames_s32() and performed it's s32
|
||||
to s16 conversion in a second pass. This is now all done in a single pass. This includes SSE2 and ARM NEON optimized paths.
|
||||
|
||||
A minor optimization has been implemented for drflac_read_pcm_frames_s32(). This will now use an SSE2 optimized pipeline for stereo
|
||||
channel reconstruction which is the last part of the decoding process.
|
||||
|
||||
The ARM build has seen a few improvements. The CLZ (count leading zeroes) and REV (byte swap) instructions are now used when
|
||||
compiling with GCC and Clang which is achieved using inline assembly. The CLZ instruction requires ARM architecture version 5 at
|
||||
compile time and the REV instruction requires ARM architecture version 6.
|
||||
|
||||
An ARM NEON optimized pipeline has been implemented. To enable this you'll need to add -mfpu=neon to the command line when compiling.
|
||||
|
||||
|
||||
Removed APIs
|
||||
------------
|
||||
The following APIs were deprecated in version 0.11.0 and have been completely removed in version 0.12.0:
|
||||
|
||||
drflac_read_s32() -> drflac_read_pcm_frames_s32()
|
||||
drflac_read_s16() -> drflac_read_pcm_frames_s16()
|
||||
drflac_read_f32() -> drflac_read_pcm_frames_f32()
|
||||
drflac_seek_to_sample() -> drflac_seek_to_pcm_frame()
|
||||
drflac_open_and_decode_s32() -> drflac_open_and_read_pcm_frames_s32()
|
||||
drflac_open_and_decode_s16() -> drflac_open_and_read_pcm_frames_s16()
|
||||
drflac_open_and_decode_f32() -> drflac_open_and_read_pcm_frames_f32()
|
||||
drflac_open_and_decode_file_s32() -> drflac_open_file_and_read_pcm_frames_s32()
|
||||
drflac_open_and_decode_file_s16() -> drflac_open_file_and_read_pcm_frames_s16()
|
||||
drflac_open_and_decode_file_f32() -> drflac_open_file_and_read_pcm_frames_f32()
|
||||
drflac_open_and_decode_memory_s32() -> drflac_open_memory_and_read_pcm_frames_s32()
|
||||
drflac_open_and_decode_memory_s16() -> drflac_open_memory_and_read_pcm_frames_s16()
|
||||
drflac_open_and_decode_memory_f32() -> drflac_open_memroy_and_read_pcm_frames_f32()
|
||||
|
||||
Prior versions of dr_flac operated on a per-sample basis whereas now it operates on PCM frames. The removed APIs all relate
|
||||
to the old per-sample APIs. You now need to use the "pcm_frame" versions.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Introduction
|
||||
============
|
||||
|
|
@ -179,7 +70,7 @@ reports metadata to the application through the use of a callback, and every met
|
|||
|
||||
The main opening APIs (`drflac_open()`, etc.) will fail if the header is not present. The presents a problem in certain scenarios such as broadcast style
|
||||
streams or internet radio where the header may not be present because the user has started playback mid-stream. To handle this, use the relaxed APIs:
|
||||
|
||||
|
||||
`drflac_open_relaxed()`
|
||||
`drflac_open_with_metadata_relaxed()`
|
||||
|
||||
|
|
@ -234,8 +125,8 @@ extern "C" {
|
|||
#define DRFLAC_XSTRINGIFY(x) DRFLAC_STRINGIFY(x)
|
||||
|
||||
#define DRFLAC_VERSION_MAJOR 0
|
||||
#define DRFLAC_VERSION_MINOR 12
|
||||
#define DRFLAC_VERSION_REVISION 42
|
||||
#define DRFLAC_VERSION_MINOR 13
|
||||
#define DRFLAC_VERSION_REVISION 0
|
||||
#define DRFLAC_VERSION_STRING DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MAJOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MINOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_REVISION)
|
||||
|
||||
#include <stddef.h> /* For size_t. */
|
||||
|
|
@ -348,11 +239,11 @@ but also more memory. In my testing there is diminishing returns after about 4KB
|
|||
#define DRFLAC_64BIT
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) || defined(_M_X64)
|
||||
#if defined(__x86_64__) || (defined(_M_X64) && !defined(_M_ARM64EC))
|
||||
#define DRFLAC_X64
|
||||
#elif defined(__i386) || defined(_M_IX86)
|
||||
#define DRFLAC_X86
|
||||
#elif defined(__arm__) || defined(_M_ARM) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
|
||||
#elif defined(__arm__) || defined(_M_ARM) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
|
||||
#define DRFLAC_ARM
|
||||
#endif
|
||||
/* End Architecture Detection */
|
||||
|
|
@ -406,8 +297,9 @@ typedef enum
|
|||
|
||||
typedef enum
|
||||
{
|
||||
drflac_seek_origin_start,
|
||||
drflac_seek_origin_current
|
||||
DRFLAC_SEEK_SET,
|
||||
DRFLAC_SEEK_CUR,
|
||||
DRFLAC_SEEK_END
|
||||
} drflac_seek_origin;
|
||||
|
||||
/* The order of members in this structure is important because we map this directly to the raw data within the SEEKTABLE metadata block. */
|
||||
|
|
@ -547,7 +439,7 @@ offset (in)
|
|||
The number of bytes to move, relative to the origin. Will never be negative.
|
||||
|
||||
origin (in)
|
||||
The origin of the seek - the current position or the start of the stream.
|
||||
The origin of the seek - the current position, the start of the stream, or the end of the stream.
|
||||
|
||||
|
||||
Return Value
|
||||
|
|
@ -557,14 +449,32 @@ Whether or not the seek was successful.
|
|||
|
||||
Remarks
|
||||
-------
|
||||
The offset will never be negative. Whether or not it is relative to the beginning or current position is determined by the "origin" parameter which will be
|
||||
either drflac_seek_origin_start or drflac_seek_origin_current.
|
||||
Seeking relative to the start and the current position must always be supported. If seeking from the end of the stream is not supported, return DRFLAC_FALSE.
|
||||
|
||||
When seeking to a PCM frame using drflac_seek_to_pcm_frame(), dr_flac may call this with an offset beyond the end of the FLAC stream. This needs to be detected
|
||||
and handled by returning DRFLAC_FALSE.
|
||||
*/
|
||||
typedef drflac_bool32 (* drflac_seek_proc)(void* pUserData, int offset, drflac_seek_origin origin);
|
||||
|
||||
/*
|
||||
Callback for when the current position in the stream needs to be retrieved.
|
||||
|
||||
|
||||
Parameters
|
||||
----------
|
||||
pUserData (in)
|
||||
The user data that was passed to drflac_open() and family.
|
||||
|
||||
pCursor (out)
|
||||
A pointer to a variable to receive the current position in the stream.
|
||||
|
||||
|
||||
Return Value
|
||||
------------
|
||||
Whether or not the operation was successful.
|
||||
*/
|
||||
typedef drflac_bool32 (* drflac_tell_proc)(void* pUserData, drflac_int64* pCursor);
|
||||
|
||||
/*
|
||||
Callback for when a metadata block is read.
|
||||
|
||||
|
|
@ -603,6 +513,9 @@ typedef struct
|
|||
/* The function to call when the current read position needs to be moved. */
|
||||
drflac_seek_proc onSeek;
|
||||
|
||||
/* The function to call when the current read position needs to be retrieved. */
|
||||
drflac_tell_proc onTell;
|
||||
|
||||
/* The user data to pass around to onRead and onSeek. */
|
||||
void* pUserData;
|
||||
|
||||
|
|
@ -828,7 +741,7 @@ drflac_open_memory()
|
|||
drflac_open_with_metadata()
|
||||
drflac_close()
|
||||
*/
|
||||
DRFLAC_API drflac* drflac_open(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
DRFLAC_API drflac* drflac_open(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
|
||||
/*
|
||||
Opens a FLAC stream with relaxed validation of the header block.
|
||||
|
|
@ -869,7 +782,7 @@ force your `onRead` callback to return 0, which dr_flac will use as an indicator
|
|||
|
||||
Use `drflac_open_with_metadata_relaxed()` if you need access to metadata.
|
||||
*/
|
||||
DRFLAC_API drflac* drflac_open_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
DRFLAC_API drflac* drflac_open_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
|
||||
/*
|
||||
Opens a FLAC decoder and notifies the caller of the metadata chunks (album art, etc.).
|
||||
|
|
@ -926,7 +839,7 @@ drflac_open_memory_with_metadata()
|
|||
drflac_open()
|
||||
drflac_close()
|
||||
*/
|
||||
DRFLAC_API drflac* drflac_open_with_metadata(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
DRFLAC_API drflac* drflac_open_with_metadata(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
|
||||
/*
|
||||
The same as drflac_open_with_metadata(), except attempts to open the stream even when a header block is not present.
|
||||
|
|
@ -936,7 +849,7 @@ See Also
|
|||
drflac_open_with_metadata()
|
||||
drflac_open_relaxed()
|
||||
*/
|
||||
DRFLAC_API drflac* drflac_open_with_metadata_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
DRFLAC_API drflac* drflac_open_with_metadata_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, drflac_meta_proc onMeta, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
|
||||
/*
|
||||
Closes the given FLAC decoder.
|
||||
|
|
@ -1234,13 +1147,13 @@ read samples into a dynamically sized buffer on the heap until no samples are le
|
|||
|
||||
Do not call this function on a broadcast type of stream (like internet radio streams and whatnot).
|
||||
*/
|
||||
DRFLAC_API drflac_int32* drflac_open_and_read_pcm_frames_s32(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
DRFLAC_API drflac_int32* drflac_open_and_read_pcm_frames_s32(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, void* pUserData, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
|
||||
/* Same as drflac_open_and_read_pcm_frames_s32(), except returns signed 16-bit integer samples. */
|
||||
DRFLAC_API drflac_int16* drflac_open_and_read_pcm_frames_s16(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
DRFLAC_API drflac_int16* drflac_open_and_read_pcm_frames_s16(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, void* pUserData, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
|
||||
/* Same as drflac_open_and_read_pcm_frames_s32(), except returns 32-bit floating-point samples. */
|
||||
DRFLAC_API float* drflac_open_and_read_pcm_frames_f32(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
DRFLAC_API float* drflac_open_and_read_pcm_frames_f32(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, void* pUserData, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
|
||||
|
||||
#ifndef DR_FLAC_NO_STDIO
|
||||
/* Same as drflac_open_and_read_pcm_frames_s32() except opens the decoder from a file. */
|
||||
|
|
@ -2960,25 +2873,25 @@ static drflac_bool32 drflac__seek_to_byte(drflac_bs* bs, drflac_uint64 offsetFro
|
|||
*/
|
||||
if (offsetFromStart > 0x7FFFFFFF) {
|
||||
drflac_uint64 bytesRemaining = offsetFromStart;
|
||||
if (!bs->onSeek(bs->pUserData, 0x7FFFFFFF, drflac_seek_origin_start)) {
|
||||
if (!bs->onSeek(bs->pUserData, 0x7FFFFFFF, DRFLAC_SEEK_SET)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
bytesRemaining -= 0x7FFFFFFF;
|
||||
|
||||
while (bytesRemaining > 0x7FFFFFFF) {
|
||||
if (!bs->onSeek(bs->pUserData, 0x7FFFFFFF, drflac_seek_origin_current)) {
|
||||
if (!bs->onSeek(bs->pUserData, 0x7FFFFFFF, DRFLAC_SEEK_CUR)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
bytesRemaining -= 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
if (bytesRemaining > 0) {
|
||||
if (!bs->onSeek(bs->pUserData, (int)bytesRemaining, drflac_seek_origin_current)) {
|
||||
if (!bs->onSeek(bs->pUserData, (int)bytesRemaining, DRFLAC_SEEK_CUR)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!bs->onSeek(bs->pUserData, (int)offsetFromStart, drflac_seek_origin_start)) {
|
||||
if (!bs->onSeek(bs->pUserData, (int)offsetFromStart, DRFLAC_SEEK_SET)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
|
@ -5393,6 +5306,12 @@ static drflac_bool32 drflac__read_subframe_header(drflac_bs* bs, drflac_subframe
|
|||
return DRFLAC_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
Default to 0 for the LPC order. It's important that we always set this to 0 for non LPC
|
||||
and FIXED subframes because we'll be using it in a generic validation check later.
|
||||
*/
|
||||
pSubframe->lpcOrder = 0;
|
||||
|
||||
type = (header & 0x7E) >> 1;
|
||||
if (type == 0) {
|
||||
pSubframe->subframeType = DRFLAC_SUBFRAME_CONSTANT;
|
||||
|
|
@ -5465,6 +5384,18 @@ static drflac_bool32 drflac__decode_subframe(drflac_bs* bs, drflac_frame* frame,
|
|||
|
||||
pSubframe->pSamplesS32 = pDecodedSamplesOut;
|
||||
|
||||
/*
|
||||
pDecodedSamplesOut will be pointing to a buffer that was allocated with enough memory to store
|
||||
maxBlockSizeInPCMFrames samples (as specified in the FLAC header). We need to guard against an
|
||||
overflow here. At a higher level we are checking maxBlockSizeInPCMFrames from the header, but
|
||||
here we need to do an additional check to ensure this frame's block size fully encompasses any
|
||||
warmup samples which is determined by the LPC order. For non LPC and FIXED subframes, the LPC
|
||||
order will be have been set to 0 in drflac__read_subframe_header().
|
||||
*/
|
||||
if (frame->header.blockSizeInPCMFrames < pSubframe->lpcOrder) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
|
||||
switch (pSubframe->subframeType)
|
||||
{
|
||||
case DRFLAC_SUBFRAME_CONSTANT:
|
||||
|
|
@ -6312,6 +6243,7 @@ typedef struct
|
|||
{
|
||||
drflac_read_proc onRead;
|
||||
drflac_seek_proc onSeek;
|
||||
drflac_tell_proc onTell;
|
||||
drflac_meta_proc onMeta;
|
||||
drflac_container container;
|
||||
void* pUserData;
|
||||
|
|
@ -6479,7 +6411,7 @@ static void drflac__free_from_callbacks(void* p, const drflac_allocation_callbac
|
|||
}
|
||||
|
||||
|
||||
static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, void* pUserData, void* pUserDataMD, drflac_uint64* pFirstFramePos, drflac_uint64* pSeektablePos, drflac_uint32* pSeekpointCount, drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, drflac_meta_proc onMeta, void* pUserData, void* pUserDataMD, drflac_uint64* pFirstFramePos, drflac_uint64* pSeektablePos, drflac_uint32* pSeekpointCount, drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
/*
|
||||
We want to keep track of the byte position in the stream of the seektable. At the time of calling this function we know that
|
||||
|
|
@ -6489,6 +6421,8 @@ static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, d
|
|||
drflac_uint64 seektablePos = 0;
|
||||
drflac_uint32 seektableSize = 0;
|
||||
|
||||
(void)onTell;
|
||||
|
||||
for (;;) {
|
||||
drflac_metadata metadata;
|
||||
drflac_uint8 isLastBlock = 0;
|
||||
|
|
@ -6702,10 +6636,10 @@ static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, d
|
|||
|
||||
/* Skip to the index point count */
|
||||
pRunningData += 35;
|
||||
|
||||
|
||||
indexCount = pRunningData[0];
|
||||
pRunningData += 1;
|
||||
|
||||
|
||||
bufferSize += indexCount * sizeof(drflac_cuesheet_track_index);
|
||||
|
||||
/* Quick validation check. */
|
||||
|
|
@ -6840,7 +6774,7 @@ static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, d
|
|||
metadata.data.padding.unused = 0;
|
||||
|
||||
/* Padding doesn't have anything meaningful in it, so just skip over it, but make sure the caller is aware of it by firing the callback. */
|
||||
if (!onSeek(pUserData, blockSize, drflac_seek_origin_current)) {
|
||||
if (!onSeek(pUserData, blockSize, DRFLAC_SEEK_CUR)) {
|
||||
isLastBlock = DRFLAC_TRUE; /* An error occurred while seeking. Attempt to recover by treating this as the last block which will in turn terminate the loop. */
|
||||
} else {
|
||||
onMeta(pUserDataMD, &metadata);
|
||||
|
|
@ -6852,7 +6786,7 @@ static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, d
|
|||
{
|
||||
/* Invalid chunk. Just skip over this one. */
|
||||
if (onMeta) {
|
||||
if (!onSeek(pUserData, blockSize, drflac_seek_origin_current)) {
|
||||
if (!onSeek(pUserData, blockSize, DRFLAC_SEEK_CUR)) {
|
||||
isLastBlock = DRFLAC_TRUE; /* An error occurred while seeking. Attempt to recover by treating this as the last block which will in turn terminate the loop. */
|
||||
}
|
||||
}
|
||||
|
|
@ -6886,7 +6820,7 @@ static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, d
|
|||
|
||||
/* If we're not handling metadata, just skip over the block. If we are, it will have been handled earlier in the switch statement above. */
|
||||
if (onMeta == NULL && blockSize > 0) {
|
||||
if (!onSeek(pUserData, blockSize, drflac_seek_origin_current)) {
|
||||
if (!onSeek(pUserData, blockSize, DRFLAC_SEEK_CUR)) {
|
||||
isLastBlock = DRFLAC_TRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -7220,6 +7154,7 @@ typedef struct
|
|||
{
|
||||
drflac_read_proc onRead; /* The original onRead callback from drflac_open() and family. */
|
||||
drflac_seek_proc onSeek; /* The original onSeek callback from drflac_open() and family. */
|
||||
drflac_tell_proc onTell; /* The original onTell callback from drflac_open() and family. */
|
||||
void* pUserData; /* The user data passed on onRead and onSeek. This is the user data that was passed on drflac_open() and family. */
|
||||
drflac_uint64 currentBytePos; /* The position of the byte we are sitting on in the physical byte stream. Used for efficient seeking. */
|
||||
drflac_uint64 firstBytePos; /* The position of the first byte in the physical bitstream. Points to the start of the "OggS" identifier of the FLAC bos page. */
|
||||
|
|
@ -7241,32 +7176,32 @@ static size_t drflac_oggbs__read_physical(drflac_oggbs* oggbs, void* bufferOut,
|
|||
|
||||
static drflac_bool32 drflac_oggbs__seek_physical(drflac_oggbs* oggbs, drflac_uint64 offset, drflac_seek_origin origin)
|
||||
{
|
||||
if (origin == drflac_seek_origin_start) {
|
||||
if (origin == DRFLAC_SEEK_SET) {
|
||||
if (offset <= 0x7FFFFFFF) {
|
||||
if (!oggbs->onSeek(oggbs->pUserData, (int)offset, drflac_seek_origin_start)) {
|
||||
if (!oggbs->onSeek(oggbs->pUserData, (int)offset, DRFLAC_SEEK_SET)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
oggbs->currentBytePos = offset;
|
||||
|
||||
return DRFLAC_TRUE;
|
||||
} else {
|
||||
if (!oggbs->onSeek(oggbs->pUserData, 0x7FFFFFFF, drflac_seek_origin_start)) {
|
||||
if (!oggbs->onSeek(oggbs->pUserData, 0x7FFFFFFF, DRFLAC_SEEK_SET)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
oggbs->currentBytePos = offset;
|
||||
|
||||
return drflac_oggbs__seek_physical(oggbs, offset - 0x7FFFFFFF, drflac_seek_origin_current);
|
||||
return drflac_oggbs__seek_physical(oggbs, offset - 0x7FFFFFFF, DRFLAC_SEEK_CUR);
|
||||
}
|
||||
} else {
|
||||
while (offset > 0x7FFFFFFF) {
|
||||
if (!oggbs->onSeek(oggbs->pUserData, 0x7FFFFFFF, drflac_seek_origin_current)) {
|
||||
if (!oggbs->onSeek(oggbs->pUserData, 0x7FFFFFFF, DRFLAC_SEEK_CUR)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
oggbs->currentBytePos += 0x7FFFFFFF;
|
||||
offset -= 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
if (!oggbs->onSeek(oggbs->pUserData, (int)offset, drflac_seek_origin_current)) { /* <-- Safe cast thanks to the loop above. */
|
||||
if (!oggbs->onSeek(oggbs->pUserData, (int)offset, DRFLAC_SEEK_CUR)) { /* <-- Safe cast thanks to the loop above. */
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
oggbs->currentBytePos += offset;
|
||||
|
|
@ -7298,7 +7233,7 @@ static drflac_bool32 drflac_oggbs__goto_next_page(drflac_oggbs* oggbs, drflac_og
|
|||
|
||||
if (header.serialNumber != oggbs->serialNumber) {
|
||||
/* It's not a FLAC page. Skip it. */
|
||||
if (pageBodySize > 0 && !drflac_oggbs__seek_physical(oggbs, pageBodySize, drflac_seek_origin_current)) {
|
||||
if (pageBodySize > 0 && !drflac_oggbs__seek_physical(oggbs, pageBodySize, DRFLAC_SEEK_CUR)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
continue;
|
||||
|
|
@ -7384,7 +7319,7 @@ static drflac_bool32 drflac_oggbs__seek_to_next_packet(drflac_oggbs* oggbs)
|
|||
At this point we will have found either the packet or the end of the page. If were at the end of the page we'll
|
||||
want to load the next page and keep searching for the end of the packet.
|
||||
*/
|
||||
drflac_oggbs__seek_physical(oggbs, bytesToEndOfPacketOrPage, drflac_seek_origin_current);
|
||||
drflac_oggbs__seek_physical(oggbs, bytesToEndOfPacketOrPage, DRFLAC_SEEK_CUR);
|
||||
oggbs->bytesRemainingInPage -= bytesToEndOfPacketOrPage;
|
||||
|
||||
if (atEndOfPage) {
|
||||
|
|
@ -7462,8 +7397,8 @@ static drflac_bool32 drflac__on_seek_ogg(void* pUserData, int offset, drflac_see
|
|||
DRFLAC_ASSERT(offset >= 0); /* <-- Never seek backwards. */
|
||||
|
||||
/* Seeking is always forward which makes things a lot simpler. */
|
||||
if (origin == drflac_seek_origin_start) {
|
||||
if (!drflac_oggbs__seek_physical(oggbs, (int)oggbs->firstBytePos, drflac_seek_origin_start)) {
|
||||
if (origin == DRFLAC_SEEK_SET) {
|
||||
if (!drflac_oggbs__seek_physical(oggbs, (int)oggbs->firstBytePos, DRFLAC_SEEK_SET)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -7471,38 +7406,50 @@ static drflac_bool32 drflac__on_seek_ogg(void* pUserData, int offset, drflac_see
|
|||
return DRFLAC_FALSE;
|
||||
}
|
||||
|
||||
return drflac__on_seek_ogg(pUserData, offset, drflac_seek_origin_current);
|
||||
}
|
||||
return drflac__on_seek_ogg(pUserData, offset, DRFLAC_SEEK_CUR);
|
||||
} else if (origin == DRFLAC_SEEK_CUR) {
|
||||
while (bytesSeeked < offset) {
|
||||
int bytesRemainingToSeek = offset - bytesSeeked;
|
||||
DRFLAC_ASSERT(bytesRemainingToSeek >= 0);
|
||||
|
||||
DRFLAC_ASSERT(origin == drflac_seek_origin_current);
|
||||
if (oggbs->bytesRemainingInPage >= (size_t)bytesRemainingToSeek) {
|
||||
bytesSeeked += bytesRemainingToSeek;
|
||||
(void)bytesSeeked; /* <-- Silence a dead store warning emitted by Clang Static Analyzer. */
|
||||
oggbs->bytesRemainingInPage -= bytesRemainingToSeek;
|
||||
break;
|
||||
}
|
||||
|
||||
while (bytesSeeked < offset) {
|
||||
int bytesRemainingToSeek = offset - bytesSeeked;
|
||||
DRFLAC_ASSERT(bytesRemainingToSeek >= 0);
|
||||
/* If we get here it means some of the requested data is contained in the next pages. */
|
||||
if (oggbs->bytesRemainingInPage > 0) {
|
||||
bytesSeeked += (int)oggbs->bytesRemainingInPage;
|
||||
oggbs->bytesRemainingInPage = 0;
|
||||
}
|
||||
|
||||
if (oggbs->bytesRemainingInPage >= (size_t)bytesRemainingToSeek) {
|
||||
bytesSeeked += bytesRemainingToSeek;
|
||||
(void)bytesSeeked; /* <-- Silence a dead store warning emitted by Clang Static Analyzer. */
|
||||
oggbs->bytesRemainingInPage -= bytesRemainingToSeek;
|
||||
break;
|
||||
}
|
||||
|
||||
/* If we get here it means some of the requested data is contained in the next pages. */
|
||||
if (oggbs->bytesRemainingInPage > 0) {
|
||||
bytesSeeked += (int)oggbs->bytesRemainingInPage;
|
||||
oggbs->bytesRemainingInPage = 0;
|
||||
}
|
||||
|
||||
DRFLAC_ASSERT(bytesRemainingToSeek > 0);
|
||||
if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_fail_on_crc_mismatch)) {
|
||||
/* Failed to go to the next page. We either hit the end of the stream or had a CRC mismatch. */
|
||||
return DRFLAC_FALSE;
|
||||
DRFLAC_ASSERT(bytesRemainingToSeek > 0);
|
||||
if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_fail_on_crc_mismatch)) {
|
||||
/* Failed to go to the next page. We either hit the end of the stream or had a CRC mismatch. */
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
}
|
||||
} else if (origin == DRFLAC_SEEK_END) {
|
||||
/* Seeking to the end is not supported. */
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
|
||||
return DRFLAC_TRUE;
|
||||
}
|
||||
|
||||
static drflac_bool32 drflac__on_tell_ogg(void* pUserData, drflac_int64* pCursor)
|
||||
{
|
||||
/*
|
||||
Not implemented for Ogg containers because we don't currently track the byte position of the logical bitstream. To support this, we'll need
|
||||
to track the position in drflac__on_read_ogg and drflac__on_seek_ogg.
|
||||
*/
|
||||
(void)pUserData;
|
||||
(void)pCursor;
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
|
||||
|
||||
static drflac_bool32 drflac_ogg__seek_to_pcm_frame(drflac* pFlac, drflac_uint64 pcmFrameIndex)
|
||||
{
|
||||
|
|
@ -7525,7 +7472,7 @@ static drflac_bool32 drflac_ogg__seek_to_pcm_frame(drflac* pFlac, drflac_uint64
|
|||
runningGranulePosition = 0;
|
||||
for (;;) {
|
||||
if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_recover_on_crc_mismatch)) {
|
||||
drflac_oggbs__seek_physical(oggbs, originalBytePos, drflac_seek_origin_start);
|
||||
drflac_oggbs__seek_physical(oggbs, originalBytePos, DRFLAC_SEEK_SET);
|
||||
return DRFLAC_FALSE; /* Never did find that sample... */
|
||||
}
|
||||
|
||||
|
|
@ -7559,7 +7506,7 @@ static drflac_bool32 drflac_ogg__seek_to_pcm_frame(drflac* pFlac, drflac_uint64
|
|||
a new frame. This property means that after we've seeked to the page we can immediately start looping over frames until
|
||||
we find the one containing the target sample.
|
||||
*/
|
||||
if (!drflac_oggbs__seek_physical(oggbs, runningFrameBytePos, drflac_seek_origin_start)) {
|
||||
if (!drflac_oggbs__seek_physical(oggbs, runningFrameBytePos, DRFLAC_SEEK_SET)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_recover_on_crc_mismatch)) {
|
||||
|
|
@ -7726,7 +7673,7 @@ static drflac_bool32 drflac__init_private__ogg(drflac_init_info* pInit, drflac_r
|
|||
The next 2 bytes are the non-audio packets, not including this one. We don't care about this because we're going to
|
||||
be handling it in a generic way based on the serial number and packet types.
|
||||
*/
|
||||
if (!onSeek(pUserData, 2, drflac_seek_origin_current)) {
|
||||
if (!onSeek(pUserData, 2, DRFLAC_SEEK_CUR)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -7783,18 +7730,18 @@ static drflac_bool32 drflac__init_private__ogg(drflac_init_info* pInit, drflac_r
|
|||
}
|
||||
} else {
|
||||
/* Not a FLAC header. Skip it. */
|
||||
if (!onSeek(pUserData, bytesRemainingInPage, drflac_seek_origin_current)) {
|
||||
if (!onSeek(pUserData, bytesRemainingInPage, DRFLAC_SEEK_CUR)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Not a FLAC header. Seek past the entire page and move on to the next. */
|
||||
if (!onSeek(pUserData, bytesRemainingInPage, drflac_seek_origin_current)) {
|
||||
if (!onSeek(pUserData, bytesRemainingInPage, DRFLAC_SEEK_CUR)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!onSeek(pUserData, pageBodySize, drflac_seek_origin_current)) {
|
||||
if (!onSeek(pUserData, pageBodySize, DRFLAC_SEEK_CUR)) {
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
|
@ -7819,18 +7766,19 @@ static drflac_bool32 drflac__init_private__ogg(drflac_init_info* pInit, drflac_r
|
|||
}
|
||||
#endif
|
||||
|
||||
static drflac_bool32 drflac__init_private(drflac_init_info* pInit, drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, drflac_container container, void* pUserData, void* pUserDataMD)
|
||||
static drflac_bool32 drflac__init_private(drflac_init_info* pInit, drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, drflac_meta_proc onMeta, drflac_container container, void* pUserData, void* pUserDataMD)
|
||||
{
|
||||
drflac_bool32 relaxed;
|
||||
drflac_uint8 id[4];
|
||||
|
||||
if (pInit == NULL || onRead == NULL || onSeek == NULL) {
|
||||
if (pInit == NULL || onRead == NULL || onSeek == NULL) { /* <-- onTell is optional. */
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
|
||||
DRFLAC_ZERO_MEMORY(pInit, sizeof(*pInit));
|
||||
pInit->onRead = onRead;
|
||||
pInit->onSeek = onSeek;
|
||||
pInit->onTell = onTell;
|
||||
pInit->onMeta = onMeta;
|
||||
pInit->container = container;
|
||||
pInit->pUserData = pUserData;
|
||||
|
|
@ -7838,6 +7786,7 @@ static drflac_bool32 drflac__init_private(drflac_init_info* pInit, drflac_read_p
|
|||
|
||||
pInit->bs.onRead = onRead;
|
||||
pInit->bs.onSeek = onSeek;
|
||||
pInit->bs.onTell = onTell;
|
||||
pInit->bs.pUserData = pUserData;
|
||||
drflac__reset_cache(&pInit->bs);
|
||||
|
||||
|
|
@ -7870,7 +7819,7 @@ static drflac_bool32 drflac__init_private(drflac_init_info* pInit, drflac_read_p
|
|||
headerSize += 10;
|
||||
}
|
||||
|
||||
if (!onSeek(pUserData, headerSize, drflac_seek_origin_current)) {
|
||||
if (!onSeek(pUserData, headerSize, DRFLAC_SEEK_CUR)) {
|
||||
return DRFLAC_FALSE; /* Failed to seek past the tag. */
|
||||
}
|
||||
pInit->runningFilePos += headerSize;
|
||||
|
|
@ -7922,7 +7871,7 @@ static void drflac__init_from_info(drflac* pFlac, const drflac_init_info* pInit)
|
|||
}
|
||||
|
||||
|
||||
static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, drflac_container container, void* pUserData, void* pUserDataMD, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, drflac_meta_proc onMeta, drflac_container container, void* pUserData, void* pUserDataMD, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
drflac_init_info init;
|
||||
drflac_uint32 allocationSize;
|
||||
|
|
@ -7940,7 +7889,7 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
|
|||
/* CPU support first. */
|
||||
drflac__init_cpu_caps();
|
||||
|
||||
if (!drflac__init_private(&init, onRead, onSeek, onMeta, container, pUserData, pUserDataMD)) {
|
||||
if (!drflac__init_private(&init, onRead, onSeek, onTell, onMeta, container, pUserData, pUserDataMD)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -7996,6 +7945,7 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
|
|||
DRFLAC_ZERO_MEMORY(pOggbs, sizeof(*pOggbs));
|
||||
pOggbs->onRead = onRead;
|
||||
pOggbs->onSeek = onSeek;
|
||||
pOggbs->onTell = onTell;
|
||||
pOggbs->pUserData = pUserData;
|
||||
pOggbs->currentBytePos = init.oggFirstBytePos;
|
||||
pOggbs->firstBytePos = init.oggFirstBytePos;
|
||||
|
|
@ -8016,17 +7966,19 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
|
|||
if (init.hasMetadataBlocks) {
|
||||
drflac_read_proc onReadOverride = onRead;
|
||||
drflac_seek_proc onSeekOverride = onSeek;
|
||||
drflac_tell_proc onTellOverride = onTell;
|
||||
void* pUserDataOverride = pUserData;
|
||||
|
||||
#ifndef DR_FLAC_NO_OGG
|
||||
if (init.container == drflac_container_ogg) {
|
||||
onReadOverride = drflac__on_read_ogg;
|
||||
onSeekOverride = drflac__on_seek_ogg;
|
||||
onTellOverride = drflac__on_tell_ogg;
|
||||
pUserDataOverride = (void*)pOggbs;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!drflac__read_and_decode_metadata(onReadOverride, onSeekOverride, onMeta, pUserDataOverride, pUserDataMD, &firstFramePos, &seektablePos, &seekpointCount, &allocationCallbacks)) {
|
||||
if (!drflac__read_and_decode_metadata(onReadOverride, onSeekOverride, onTellOverride, onMeta, pUserDataOverride, pUserDataMD, &firstFramePos, &seektablePos, &seekpointCount, &allocationCallbacks)) {
|
||||
#ifndef DR_FLAC_NO_OGG
|
||||
drflac__free_from_callbacks(pOggbs, &allocationCallbacks);
|
||||
#endif
|
||||
|
|
@ -8061,6 +8013,7 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
|
|||
/* The Ogg bistream needs to be layered on top of the original bitstream. */
|
||||
pFlac->bs.onRead = drflac__on_read_ogg;
|
||||
pFlac->bs.onSeek = drflac__on_seek_ogg;
|
||||
pFlac->bs.onTell = drflac__on_tell_ogg;
|
||||
pFlac->bs.pUserData = (void*)pInternalOggbs;
|
||||
pFlac->_oggbs = (void*)pInternalOggbs;
|
||||
}
|
||||
|
|
@ -8087,7 +8040,7 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
|
|||
DRFLAC_ASSERT(pFlac->bs.onRead != NULL);
|
||||
|
||||
/* Seek to the seektable, then just read directly into our seektable buffer. */
|
||||
if (pFlac->bs.onSeek(pFlac->bs.pUserData, (int)seektablePos, drflac_seek_origin_start)) {
|
||||
if (pFlac->bs.onSeek(pFlac->bs.pUserData, (int)seektablePos, DRFLAC_SEEK_SET)) {
|
||||
drflac_uint32 iSeekpoint;
|
||||
|
||||
for (iSeekpoint = 0; iSeekpoint < seekpointCount; iSeekpoint += 1) {
|
||||
|
|
@ -8105,7 +8058,7 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
|
|||
}
|
||||
|
||||
/* We need to seek back to where we were. If this fails it's a critical error. */
|
||||
if (!pFlac->bs.onSeek(pFlac->bs.pUserData, (int)pFlac->firstFLACFramePosInBytes, drflac_seek_origin_start)) {
|
||||
if (!pFlac->bs.onSeek(pFlac->bs.pUserData, (int)pFlac->firstFLACFramePosInBytes, DRFLAC_SEEK_SET)) {
|
||||
drflac__free_from_callbacks(pFlac, &allocationCallbacks);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -8276,7 +8229,7 @@ static drflac_result drflac_result_from_errno(int e)
|
|||
#ifdef ENOSYS
|
||||
case ENOSYS: return DRFLAC_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
#ifdef ENOTEMPTY
|
||||
#if defined(ENOTEMPTY) && ENOTEMPTY != EEXIST /* In AIX, ENOTEMPTY and EEXIST use the same value. */
|
||||
case ENOTEMPTY: return DRFLAC_DIRECTORY_NOT_EMPTY;
|
||||
#endif
|
||||
#ifdef ELOOP
|
||||
|
|
@ -8727,11 +8680,41 @@ static size_t drflac__on_read_stdio(void* pUserData, void* bufferOut, size_t byt
|
|||
|
||||
static drflac_bool32 drflac__on_seek_stdio(void* pUserData, int offset, drflac_seek_origin origin)
|
||||
{
|
||||
DRFLAC_ASSERT(offset >= 0); /* <-- Never seek backwards. */
|
||||
int whence = SEEK_SET;
|
||||
if (origin == DRFLAC_SEEK_CUR) {
|
||||
whence = SEEK_CUR;
|
||||
} else if (origin == DRFLAC_SEEK_END) {
|
||||
whence = SEEK_END;
|
||||
}
|
||||
|
||||
return fseek((FILE*)pUserData, offset, (origin == drflac_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0;
|
||||
return fseek((FILE*)pUserData, offset, whence) == 0;
|
||||
}
|
||||
|
||||
static drflac_bool32 drflac__on_tell_stdio(void* pUserData, drflac_int64* pCursor)
|
||||
{
|
||||
FILE* pFileStdio = (FILE*)pUserData;
|
||||
drflac_int64 result;
|
||||
|
||||
/* These were all validated at a higher level. */
|
||||
DRFLAC_ASSERT(pFileStdio != NULL);
|
||||
DRFLAC_ASSERT(pCursor != NULL);
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(_MSC_VER) && _MSC_VER > 1200
|
||||
result = _ftelli64(pFileStdio);
|
||||
#else
|
||||
result = ftell(pFileStdio);
|
||||
#endif
|
||||
#else
|
||||
result = ftell(pFileStdio);
|
||||
#endif
|
||||
|
||||
*pCursor = result;
|
||||
|
||||
return DRFLAC_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DRFLAC_API drflac* drflac_open_file(const char* pFileName, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
|
|
@ -8742,7 +8725,7 @@ DRFLAC_API drflac* drflac_open_file(const char* pFileName, const drflac_allocati
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pFlac = drflac_open(drflac__on_read_stdio, drflac__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
|
||||
pFlac = drflac_open(drflac__on_read_stdio, drflac__on_seek_stdio, drflac__on_tell_stdio, (void*)pFile, pAllocationCallbacks);
|
||||
if (pFlac == NULL) {
|
||||
fclose(pFile);
|
||||
return NULL;
|
||||
|
|
@ -8761,7 +8744,7 @@ DRFLAC_API drflac* drflac_open_file_w(const wchar_t* pFileName, const drflac_all
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pFlac = drflac_open(drflac__on_read_stdio, drflac__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
|
||||
pFlac = drflac_open(drflac__on_read_stdio, drflac__on_seek_stdio, drflac__on_tell_stdio, (void*)pFile, pAllocationCallbacks);
|
||||
if (pFlac == NULL) {
|
||||
fclose(pFile);
|
||||
return NULL;
|
||||
|
|
@ -8780,7 +8763,7 @@ DRFLAC_API drflac* drflac_open_file_with_metadata(const char* pFileName, drflac_
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pFlac = drflac_open_with_metadata_private(drflac__on_read_stdio, drflac__on_seek_stdio, onMeta, drflac_container_unknown, (void*)pFile, pUserData, pAllocationCallbacks);
|
||||
pFlac = drflac_open_with_metadata_private(drflac__on_read_stdio, drflac__on_seek_stdio, drflac__on_tell_stdio, onMeta, drflac_container_unknown, (void*)pFile, pUserData, pAllocationCallbacks);
|
||||
if (pFlac == NULL) {
|
||||
fclose(pFile);
|
||||
return pFlac;
|
||||
|
|
@ -8799,7 +8782,7 @@ DRFLAC_API drflac* drflac_open_file_with_metadata_w(const wchar_t* pFileName, dr
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pFlac = drflac_open_with_metadata_private(drflac__on_read_stdio, drflac__on_seek_stdio, onMeta, drflac_container_unknown, (void*)pFile, pUserData, pAllocationCallbacks);
|
||||
pFlac = drflac_open_with_metadata_private(drflac__on_read_stdio, drflac__on_seek_stdio, drflac__on_tell_stdio, onMeta, drflac_container_unknown, (void*)pFile, pUserData, pAllocationCallbacks);
|
||||
if (pFlac == NULL) {
|
||||
fclose(pFile);
|
||||
return pFlac;
|
||||
|
|
@ -8834,28 +8817,45 @@ static size_t drflac__on_read_memory(void* pUserData, void* bufferOut, size_t by
|
|||
static drflac_bool32 drflac__on_seek_memory(void* pUserData, int offset, drflac_seek_origin origin)
|
||||
{
|
||||
drflac__memory_stream* memoryStream = (drflac__memory_stream*)pUserData;
|
||||
drflac_int64 newCursor;
|
||||
|
||||
DRFLAC_ASSERT(memoryStream != NULL);
|
||||
DRFLAC_ASSERT(offset >= 0); /* <-- Never seek backwards. */
|
||||
|
||||
if (offset > (drflac_int64)memoryStream->dataSize) {
|
||||
newCursor = memoryStream->currentReadPos;
|
||||
|
||||
if (origin == DRFLAC_SEEK_SET) {
|
||||
newCursor = 0;
|
||||
} else if (origin == DRFLAC_SEEK_CUR) {
|
||||
newCursor = (drflac_int64)memoryStream->currentReadPos;
|
||||
} else if (origin == DRFLAC_SEEK_END) {
|
||||
newCursor = (drflac_int64)memoryStream->dataSize;
|
||||
} else {
|
||||
DRFLAC_ASSERT(!"Invalid seek origin");
|
||||
return DRFLAC_FALSE;
|
||||
}
|
||||
|
||||
if (origin == drflac_seek_origin_current) {
|
||||
if (memoryStream->currentReadPos + offset <= memoryStream->dataSize) {
|
||||
memoryStream->currentReadPos += offset;
|
||||
} else {
|
||||
return DRFLAC_FALSE; /* Trying to seek too far forward. */
|
||||
}
|
||||
} else {
|
||||
if ((drflac_uint32)offset <= memoryStream->dataSize) {
|
||||
memoryStream->currentReadPos = offset;
|
||||
} else {
|
||||
return DRFLAC_FALSE; /* Trying to seek too far forward. */
|
||||
}
|
||||
newCursor += offset;
|
||||
|
||||
if (newCursor < 0) {
|
||||
return DRFLAC_FALSE; /* Trying to seek prior to the start of the buffer. */
|
||||
}
|
||||
if ((size_t)newCursor > memoryStream->dataSize) {
|
||||
return DRFLAC_FALSE; /* Trying to seek beyond the end of the buffer. */
|
||||
}
|
||||
|
||||
memoryStream->currentReadPos = (size_t)newCursor;
|
||||
|
||||
return DRFLAC_TRUE;
|
||||
}
|
||||
|
||||
static drflac_bool32 drflac__on_tell_memory(void* pUserData, drflac_int64* pCursor)
|
||||
{
|
||||
drflac__memory_stream* memoryStream = (drflac__memory_stream*)pUserData;
|
||||
|
||||
DRFLAC_ASSERT(memoryStream != NULL);
|
||||
DRFLAC_ASSERT(pCursor != NULL);
|
||||
|
||||
*pCursor = (drflac_int64)memoryStream->currentReadPos;
|
||||
return DRFLAC_TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -8867,7 +8867,7 @@ DRFLAC_API drflac* drflac_open_memory(const void* pData, size_t dataSize, const
|
|||
memoryStream.data = (const drflac_uint8*)pData;
|
||||
memoryStream.dataSize = dataSize;
|
||||
memoryStream.currentReadPos = 0;
|
||||
pFlac = drflac_open(drflac__on_read_memory, drflac__on_seek_memory, &memoryStream, pAllocationCallbacks);
|
||||
pFlac = drflac_open(drflac__on_read_memory, drflac__on_seek_memory, drflac__on_tell_memory, &memoryStream, pAllocationCallbacks);
|
||||
if (pFlac == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -8898,7 +8898,7 @@ DRFLAC_API drflac* drflac_open_memory_with_metadata(const void* pData, size_t da
|
|||
memoryStream.data = (const drflac_uint8*)pData;
|
||||
memoryStream.dataSize = dataSize;
|
||||
memoryStream.currentReadPos = 0;
|
||||
pFlac = drflac_open_with_metadata_private(drflac__on_read_memory, drflac__on_seek_memory, onMeta, drflac_container_unknown, &memoryStream, pUserData, pAllocationCallbacks);
|
||||
pFlac = drflac_open_with_metadata_private(drflac__on_read_memory, drflac__on_seek_memory, drflac__on_tell_memory, onMeta, drflac_container_unknown, &memoryStream, pUserData, pAllocationCallbacks);
|
||||
if (pFlac == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -8923,22 +8923,22 @@ DRFLAC_API drflac* drflac_open_memory_with_metadata(const void* pData, size_t da
|
|||
|
||||
|
||||
|
||||
DRFLAC_API drflac* drflac_open(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
DRFLAC_API drflac* drflac_open(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
return drflac_open_with_metadata_private(onRead, onSeek, NULL, drflac_container_unknown, pUserData, pUserData, pAllocationCallbacks);
|
||||
return drflac_open_with_metadata_private(onRead, onSeek, onTell, NULL, drflac_container_unknown, pUserData, pUserData, pAllocationCallbacks);
|
||||
}
|
||||
DRFLAC_API drflac* drflac_open_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
DRFLAC_API drflac* drflac_open_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
return drflac_open_with_metadata_private(onRead, onSeek, NULL, container, pUserData, pUserData, pAllocationCallbacks);
|
||||
return drflac_open_with_metadata_private(onRead, onSeek, onTell, NULL, container, pUserData, pUserData, pAllocationCallbacks);
|
||||
}
|
||||
|
||||
DRFLAC_API drflac* drflac_open_with_metadata(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
DRFLAC_API drflac* drflac_open_with_metadata(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
return drflac_open_with_metadata_private(onRead, onSeek, onMeta, drflac_container_unknown, pUserData, pUserData, pAllocationCallbacks);
|
||||
return drflac_open_with_metadata_private(onRead, onSeek, onTell, onMeta, drflac_container_unknown, pUserData, pUserData, pAllocationCallbacks);
|
||||
}
|
||||
DRFLAC_API drflac* drflac_open_with_metadata_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
DRFLAC_API drflac* drflac_open_with_metadata_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, drflac_meta_proc onMeta, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
return drflac_open_with_metadata_private(onRead, onSeek, onMeta, container, pUserData, pUserData, pAllocationCallbacks);
|
||||
return drflac_open_with_metadata_private(onRead, onSeek, onTell, onMeta, container, pUserData, pUserData, pAllocationCallbacks);
|
||||
}
|
||||
|
||||
DRFLAC_API void drflac_close(drflac* pFlac)
|
||||
|
|
@ -11770,7 +11770,7 @@ DRFLAC_DEFINE_FULL_READ_AND_CLOSE(s32, drflac_int32)
|
|||
DRFLAC_DEFINE_FULL_READ_AND_CLOSE(s16, drflac_int16)
|
||||
DRFLAC_DEFINE_FULL_READ_AND_CLOSE(f32, float)
|
||||
|
||||
DRFLAC_API drflac_int32* drflac_open_and_read_pcm_frames_s32(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalPCMFrameCountOut, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
DRFLAC_API drflac_int32* drflac_open_and_read_pcm_frames_s32(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalPCMFrameCountOut, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
drflac* pFlac;
|
||||
|
||||
|
|
@ -11784,7 +11784,7 @@ DRFLAC_API drflac_int32* drflac_open_and_read_pcm_frames_s32(drflac_read_proc on
|
|||
*totalPCMFrameCountOut = 0;
|
||||
}
|
||||
|
||||
pFlac = drflac_open(onRead, onSeek, pUserData, pAllocationCallbacks);
|
||||
pFlac = drflac_open(onRead, onSeek, onTell, pUserData, pAllocationCallbacks);
|
||||
if (pFlac == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -11792,7 +11792,7 @@ DRFLAC_API drflac_int32* drflac_open_and_read_pcm_frames_s32(drflac_read_proc on
|
|||
return drflac__full_read_and_close_s32(pFlac, channelsOut, sampleRateOut, totalPCMFrameCountOut);
|
||||
}
|
||||
|
||||
DRFLAC_API drflac_int16* drflac_open_and_read_pcm_frames_s16(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalPCMFrameCountOut, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
DRFLAC_API drflac_int16* drflac_open_and_read_pcm_frames_s16(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalPCMFrameCountOut, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
drflac* pFlac;
|
||||
|
||||
|
|
@ -11806,7 +11806,7 @@ DRFLAC_API drflac_int16* drflac_open_and_read_pcm_frames_s16(drflac_read_proc on
|
|||
*totalPCMFrameCountOut = 0;
|
||||
}
|
||||
|
||||
pFlac = drflac_open(onRead, onSeek, pUserData, pAllocationCallbacks);
|
||||
pFlac = drflac_open(onRead, onSeek, onTell, pUserData, pAllocationCallbacks);
|
||||
if (pFlac == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -11814,7 +11814,7 @@ DRFLAC_API drflac_int16* drflac_open_and_read_pcm_frames_s16(drflac_read_proc on
|
|||
return drflac__full_read_and_close_s16(pFlac, channelsOut, sampleRateOut, totalPCMFrameCountOut);
|
||||
}
|
||||
|
||||
DRFLAC_API float* drflac_open_and_read_pcm_frames_f32(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalPCMFrameCountOut, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
DRFLAC_API float* drflac_open_and_read_pcm_frames_f32(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_tell_proc onTell, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalPCMFrameCountOut, const drflac_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
drflac* pFlac;
|
||||
|
||||
|
|
@ -11828,7 +11828,7 @@ DRFLAC_API float* drflac_open_and_read_pcm_frames_f32(drflac_read_proc onRead, d
|
|||
*totalPCMFrameCountOut = 0;
|
||||
}
|
||||
|
||||
pFlac = drflac_open(onRead, onSeek, pUserData, pAllocationCallbacks);
|
||||
pFlac = drflac_open(onRead, onSeek, onTell, pUserData, pAllocationCallbacks);
|
||||
if (pFlac == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -12077,6 +12077,26 @@ DRFLAC_API drflac_bool32 drflac_next_cuesheet_track(drflac_cuesheet_track_iterat
|
|||
/*
|
||||
REVISION HISTORY
|
||||
================
|
||||
v0.13.0 - TBD
|
||||
- API CHANGE: Seek origin enums have been renamed to match the naming convention used by other dr_libs libraries:
|
||||
- drflac_seek_origin_start -> DRFLAC_SEEK_SET
|
||||
- drflac_seek_origin_current -> DRFLAC_SEEK_CUR
|
||||
- DRFLAC_SEEK_END (new)
|
||||
- API CHANGE: A new seek origin has been added to allow seeking from the end of the file. If you implement your own `onSeek` callback, you should now detect and handle `DRFLAC_SEEK_END`. If seeking to the end is not supported, return `DRFLAC_FALSE`. If you only use `*_open_file()` or `*_open_memory()`, you need not change anything.
|
||||
- API CHANGE: An `onTell` callback has been added to the following functions:
|
||||
- drflac_open()
|
||||
- drflac_open_relaxed()
|
||||
- drflac_open_with_metadata()
|
||||
- drflac_open_with_metadata_relaxed()
|
||||
- drflac_open_and_read_pcm_frames_s32()
|
||||
- drflac_open_and_read_pcm_frames_s16()
|
||||
- drflac_open_and_read_pcm_frames_f32()
|
||||
- Fix compilation for AIX OS.
|
||||
|
||||
v0.12.43 - 2024-12-17
|
||||
- Fix a possible buffer overflow during decoding.
|
||||
- Improve detection of ARM64EC
|
||||
|
||||
v0.12.42 - 2023-11-02
|
||||
- Fix build for ARMv6-M.
|
||||
- Fix a compilation warning with GCC.
|
||||
|
|
|
|||
899
src/external/dr_mp3.h
vendored
899
src/external/dr_mp3.h
vendored
File diff suppressed because it is too large
Load diff
492
src/external/dr_wav.h
vendored
492
src/external/dr_wav.h
vendored
File diff suppressed because it is too large
Load diff
2115
src/external/glfw/src/mappings.h
vendored
2115
src/external/glfw/src/mappings.h
vendored
File diff suppressed because it is too large
Load diff
4
src/external/jar_mod.h
vendored
4
src/external/jar_mod.h
vendored
|
|
@ -1130,7 +1130,7 @@ static bool jar_mod_load( jar_mod_context_t * modctx, void * mod_data, int mod_d
|
|||
{
|
||||
if( modctx )
|
||||
{
|
||||
memcopy(&(modctx->song.title),modmemory,1084);
|
||||
memcopy(&(modctx->song), modmemory, 1084);
|
||||
|
||||
i = 0;
|
||||
modctx->number_of_channels = 0;
|
||||
|
|
@ -1593,4 +1593,4 @@ void jar_mod_seek_start(jar_mod_context_t * ctx)
|
|||
//-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif //end of header file
|
||||
#endif //end of header file
|
||||
|
|
|
|||
1813
src/external/miniaudio.h
vendored
1813
src/external/miniaudio.h
vendored
File diff suppressed because it is too large
Load diff
46
src/external/qoaplay.c
vendored
46
src/external/qoaplay.c
vendored
|
|
@ -46,7 +46,6 @@ typedef struct {
|
|||
unsigned int sample_position; // Current streaming sample position
|
||||
|
||||
unsigned char *buffer; // Buffer used to read samples from file/memory (used on decoding)
|
||||
unsigned int buffer_len; // Buffer length to read samples for streaming
|
||||
|
||||
short *sample_data; // Sample data decoded
|
||||
unsigned int sample_data_len; // Sample data decoded length
|
||||
|
|
@ -111,7 +110,7 @@ qoaplay_desc *qoaplay_open(const char *path)
|
|||
qoa_ctx->file = file;
|
||||
qoa_ctx->file_data = NULL;
|
||||
qoa_ctx->file_data_size = 0;
|
||||
qoa_ctx->file_data_offset = 0;
|
||||
qoa_ctx->file_data_offset = first_frame_pos;
|
||||
qoa_ctx->first_frame_pos = first_frame_pos;
|
||||
|
||||
// Setup data pointers to previously allocated data
|
||||
|
|
@ -128,34 +127,30 @@ qoaplay_desc *qoaplay_open(const char *path)
|
|||
// Open QOA file from memory, no FILE pointer required
|
||||
qoaplay_desc *qoaplay_open_memory(const unsigned char *data, int data_size)
|
||||
{
|
||||
// Read and decode the file header
|
||||
unsigned char header[QOA_MIN_FILESIZE];
|
||||
memcpy(header, data, QOA_MIN_FILESIZE);
|
||||
|
||||
qoa_desc qoa;
|
||||
unsigned int first_frame_pos = qoa_decode_header(header, QOA_MIN_FILESIZE, &qoa);
|
||||
if (data_size < QOA_MIN_FILESIZE) return NULL;
|
||||
unsigned int first_frame_pos = qoa_decode_header(data, QOA_MIN_FILESIZE, &qoa);
|
||||
if (!first_frame_pos) return NULL;
|
||||
|
||||
// Allocate one chunk of memory for the qoaplay_desc struct
|
||||
// + the sample data for one frame
|
||||
// + a buffer to hold one frame of encoded data
|
||||
unsigned int buffer_size = qoa_max_frame_size(&qoa);
|
||||
unsigned int sample_data_size = qoa.channels*QOA_FRAME_LEN*sizeof(short)*2;
|
||||
qoaplay_desc *qoa_ctx = QOA_MALLOC(sizeof(qoaplay_desc) + buffer_size + sample_data_size);
|
||||
qoaplay_desc *qoa_ctx = QOA_MALLOC(sizeof(qoaplay_desc) + sample_data_size + data_size);
|
||||
memset(qoa_ctx, 0, sizeof(qoaplay_desc));
|
||||
|
||||
qoa_ctx->file = NULL;
|
||||
|
||||
// Keep a copy of file data provided to be managed internally
|
||||
qoa_ctx->file_data = (unsigned char *)QOA_MALLOC(data_size);
|
||||
qoa_ctx->file_data = (((unsigned char *)qoa_ctx) + sizeof(qoaplay_desc) + sample_data_size);
|
||||
memcpy(qoa_ctx->file_data, data, data_size);
|
||||
qoa_ctx->file_data_size = data_size;
|
||||
qoa_ctx->file_data_offset = 0;
|
||||
qoa_ctx->file_data_offset = first_frame_pos;
|
||||
qoa_ctx->first_frame_pos = first_frame_pos;
|
||||
|
||||
// Setup data pointers to previously allocated data
|
||||
qoa_ctx->buffer = ((unsigned char *)qoa_ctx) + sizeof(qoaplay_desc);
|
||||
qoa_ctx->sample_data = (short *)(((unsigned char *)qoa_ctx) + sizeof(qoaplay_desc) + buffer_size);
|
||||
qoa_ctx->buffer = NULL;
|
||||
qoa_ctx->sample_data = (short *)(((unsigned char *)qoa_ctx) + sizeof(qoaplay_desc));
|
||||
|
||||
qoa_ctx->info.channels = qoa.channels;
|
||||
qoa_ctx->info.samplerate = qoa.samplerate;
|
||||
|
|
@ -169,11 +164,7 @@ void qoaplay_close(qoaplay_desc *qoa_ctx)
|
|||
{
|
||||
if (qoa_ctx->file) fclose(qoa_ctx->file);
|
||||
|
||||
if ((qoa_ctx->file_data) && (qoa_ctx->file_data_size > 0))
|
||||
{
|
||||
QOA_FREE(qoa_ctx->file_data);
|
||||
qoa_ctx->file_data_size = 0;
|
||||
}
|
||||
qoa_ctx->file_data_size = 0;
|
||||
|
||||
QOA_FREE(qoa_ctx);
|
||||
}
|
||||
|
|
@ -181,16 +172,23 @@ void qoaplay_close(qoaplay_desc *qoa_ctx)
|
|||
// Decode one frame from QOA data
|
||||
unsigned int qoaplay_decode_frame(qoaplay_desc *qoa_ctx)
|
||||
{
|
||||
if (qoa_ctx->file) qoa_ctx->buffer_len = fread(qoa_ctx->buffer, 1, qoa_max_frame_size(&qoa_ctx->info), qoa_ctx->file);
|
||||
unsigned char *buffer;
|
||||
unsigned int buffer_len;
|
||||
|
||||
if (qoa_ctx->file)
|
||||
{
|
||||
buffer = qoa_ctx->buffer;
|
||||
buffer_len = fread(buffer, 1, qoa_max_frame_size(&qoa_ctx->info), qoa_ctx->file);
|
||||
}
|
||||
else
|
||||
{
|
||||
qoa_ctx->buffer_len = qoa_max_frame_size(&qoa_ctx->info);
|
||||
memcpy(qoa_ctx->buffer, qoa_ctx->file_data + qoa_ctx->file_data_offset, qoa_ctx->buffer_len);
|
||||
qoa_ctx->file_data_offset += qoa_ctx->buffer_len;
|
||||
buffer = qoa_ctx->file_data + qoa_ctx->file_data_offset;
|
||||
buffer_len = qoa_max_frame_size(&qoa_ctx->info);
|
||||
qoa_ctx->file_data_offset += buffer_len;
|
||||
}
|
||||
|
||||
unsigned int frame_len;
|
||||
qoa_decode_frame(qoa_ctx->buffer, qoa_ctx->buffer_len, &qoa_ctx->info, qoa_ctx->sample_data, &frame_len);
|
||||
qoa_decode_frame(buffer, buffer_len, &qoa_ctx->info, qoa_ctx->sample_data, &frame_len);
|
||||
qoa_ctx->sample_data_pos = 0;
|
||||
qoa_ctx->sample_data_len = frame_len;
|
||||
|
||||
|
|
@ -201,7 +199,7 @@ unsigned int qoaplay_decode_frame(qoaplay_desc *qoa_ctx)
|
|||
void qoaplay_rewind(qoaplay_desc *qoa_ctx)
|
||||
{
|
||||
if (qoa_ctx->file) fseek(qoa_ctx->file, qoa_ctx->first_frame_pos, SEEK_SET);
|
||||
else qoa_ctx->file_data_offset = 0;
|
||||
else qoa_ctx->file_data_offset = qoa_ctx->first_frame_pos;
|
||||
|
||||
qoa_ctx->sample_position = 0;
|
||||
qoa_ctx->sample_data_len = 0;
|
||||
|
|
|
|||
994
src/external/rl_gputex.h
vendored
994
src/external/rl_gputex.h
vendored
File diff suppressed because it is too large
Load diff
42
src/external/rprand.h
vendored
42
src/external/rprand.h
vendored
|
|
@ -15,15 +15,15 @@
|
|||
* - Support 64 bits generation
|
||||
*
|
||||
* ADDITIONAL NOTES:
|
||||
* This library implements two pseudo-random number generation algorithms:
|
||||
* This library implements two pseudo-random number generation algorithms:
|
||||
*
|
||||
* - Xoshiro128** : https://prng.di.unimi.it/xoshiro128starstar.c
|
||||
* - SplitMix64 : https://prng.di.unimi.it/splitmix64.c
|
||||
*
|
||||
* SplitMix64 is used to initialize the Xoshiro128** state, from a provided seed
|
||||
*
|
||||
* It's suggested to use SplitMix64 to initialize the state of the generators starting from
|
||||
* a 64-bit seed, as research has shown that initialization must be performed with a generator
|
||||
* It's suggested to use SplitMix64 to initialize the state of the generators starting from
|
||||
* a 64-bit seed, as research has shown that initialization must be performed with a generator
|
||||
* radically different in nature from the one initialized to avoid correlation on similar seeds.
|
||||
*
|
||||
* CONFIGURATION:
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
* Generates the implementation of the library into the included file.
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* or source files without problems. But only ONE file should hold the implementation.
|
||||
*
|
||||
*
|
||||
* DEPENDENCIES: none
|
||||
*
|
||||
* VERSIONS HISTORY:
|
||||
|
|
@ -153,7 +153,7 @@ static uint32_t rprand_state[4] = { // Xoshiro128** state, initializ
|
|||
0x218b21e5,
|
||||
0xaa91febd,
|
||||
0x976414d4
|
||||
};
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module internal functions declaration
|
||||
|
|
@ -190,8 +190,8 @@ int rprand_get_value(int min, int max)
|
|||
int *rprand_load_sequence(unsigned int count, int min, int max)
|
||||
{
|
||||
int *sequence = NULL;
|
||||
|
||||
if (count > (unsigned int)(abs(max - min) + 1))
|
||||
|
||||
if (count > (unsigned int)(abs(max - min) + 1))
|
||||
{
|
||||
RPRAND_LOG("WARNING: Sequence count required is greater than range provided\n");
|
||||
//count = (max - min);
|
||||
|
|
@ -244,26 +244,26 @@ static inline uint32_t rprand_rotate_left(const uint32_t x, int k)
|
|||
}
|
||||
|
||||
// Xoshiro128** generator info:
|
||||
//
|
||||
//
|
||||
// Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org)
|
||||
//
|
||||
//
|
||||
// To the extent possible under law, the author has dedicated all copyright
|
||||
// and related and neighboring rights to this software to the public domain
|
||||
// worldwide. This software is distributed without any warranty.
|
||||
//
|
||||
//
|
||||
// See <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
//
|
||||
//
|
||||
// This is xoshiro128** 1.1, one of our 32-bit all-purpose, rock-solid
|
||||
// generators. It has excellent speed, a state size (128 bits) that is
|
||||
// large enough for mild parallelism, and it passes all tests we are aware
|
||||
// of.
|
||||
//
|
||||
//
|
||||
// Note that version 1.0 had mistakenly s[0] instead of s[1] as state
|
||||
// word passed to the scrambler.
|
||||
//
|
||||
//
|
||||
// For generating just single-precision (i.e., 32-bit) floating-point
|
||||
// numbers, xoshiro128+ is even faster.
|
||||
//
|
||||
//
|
||||
// The state must be seeded so that it is not everywhere zero.
|
||||
//
|
||||
uint32_t rprand_xoshiro(void)
|
||||
|
|
@ -275,29 +275,29 @@ uint32_t rprand_xoshiro(void)
|
|||
rprand_state[3] ^= rprand_state[1];
|
||||
rprand_state[1] ^= rprand_state[2];
|
||||
rprand_state[0] ^= rprand_state[3];
|
||||
|
||||
|
||||
rprand_state[2] ^= t;
|
||||
|
||||
|
||||
rprand_state[3] = rprand_rotate_left(rprand_state[3], 11);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// SplitMix64 generator info:
|
||||
//
|
||||
//
|
||||
// Written in 2015 by Sebastiano Vigna (vigna@acm.org)
|
||||
//
|
||||
//
|
||||
// To the extent possible under law, the author has dedicated all copyright
|
||||
// and related and neighboring rights to this software to the public domain
|
||||
// worldwide. This software is distributed without any warranty.
|
||||
//
|
||||
//
|
||||
// See <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
//
|
||||
//
|
||||
//
|
||||
// This is a fixed-increment version of Java 8's SplittableRandom generator
|
||||
// See http://dx.doi.org/10.1145/2714064.2660195 and
|
||||
// http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html
|
||||
//
|
||||
//
|
||||
// It is a very fast generator passing BigCrush, and it can be useful if
|
||||
// for some reason you absolutely want 64 bits of state.
|
||||
uint64_t rprand_splitmix64()
|
||||
|
|
|
|||
|
|
@ -70,6 +70,16 @@ typedef struct {
|
|||
EGLConfig config; // Graphic config
|
||||
} PlatformData;
|
||||
|
||||
typedef struct {
|
||||
// Store data for both Hover and Touch events
|
||||
// Used to ignore Hover events which are interpreted as Touch events
|
||||
int32_t pointCount; // Number of touch points active
|
||||
int32_t pointId[MAX_TOUCH_POINTS]; // Point identifiers
|
||||
Vector2 position[MAX_TOUCH_POINTS]; // Touch position on screen
|
||||
|
||||
int32_t hoverPoints[MAX_TOUCH_POINTS]; // Hover Points
|
||||
} TouchRaw;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -246,6 +256,8 @@ static const KeyboardKey mapKeycode[KEYCODE_MAP_SIZE] = {
|
|||
KEY_KP_EQUAL // AKEYCODE_NUMPAD_EQUALS
|
||||
};
|
||||
|
||||
static TouchRaw touchRaw = { 0 };
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Internal Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -801,6 +813,8 @@ int InitPlatform(void)
|
|||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++) touchRaw.hoverPoints[i] = -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1269,25 +1283,85 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
|||
}
|
||||
|
||||
// Register touch points count
|
||||
CORE.Input.Touch.pointCount = AMotionEvent_getPointerCount(event);
|
||||
touchRaw.pointCount = AMotionEvent_getPointerCount(event);
|
||||
|
||||
for (int i = 0; (i < CORE.Input.Touch.pointCount) && (i < MAX_TOUCH_POINTS); i++)
|
||||
for (int i = 0; (i < touchRaw.pointCount) && (i < MAX_TOUCH_POINTS); i++)
|
||||
{
|
||||
// Register touch points id
|
||||
CORE.Input.Touch.pointId[i] = AMotionEvent_getPointerId(event, i);
|
||||
touchRaw.pointId[i] = AMotionEvent_getPointerId(event, i);
|
||||
|
||||
// Register touch points position
|
||||
CORE.Input.Touch.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) };
|
||||
touchRaw.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) };
|
||||
|
||||
// Normalize CORE.Input.Touch.position[i] for CORE.Window.screen.width and CORE.Window.screen.height
|
||||
float widthRatio = (float)(CORE.Window.screen.width + CORE.Window.renderOffset.x)/(float)CORE.Window.display.width;
|
||||
float heightRatio = (float)(CORE.Window.screen.height + CORE.Window.renderOffset.y)/(float)CORE.Window.display.height;
|
||||
CORE.Input.Touch.position[i].x = CORE.Input.Touch.position[i].x*widthRatio - (float)CORE.Window.renderOffset.x/2;
|
||||
CORE.Input.Touch.position[i].y = CORE.Input.Touch.position[i].y*heightRatio - (float)CORE.Window.renderOffset.y/2;
|
||||
touchRaw.position[i].x = touchRaw.position[i].x*widthRatio - (float)CORE.Window.renderOffset.x/2;
|
||||
touchRaw.position[i].y = touchRaw.position[i].y*heightRatio - (float)CORE.Window.renderOffset.y/2;
|
||||
}
|
||||
|
||||
int32_t action = AMotionEvent_getAction(event);
|
||||
unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
|
||||
int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
|
||||
|
||||
if (flags == AMOTION_EVENT_ACTION_HOVER_ENTER)
|
||||
{
|
||||
// The new pointer is hover
|
||||
// So add it to hoverPoints
|
||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
|
||||
{
|
||||
if (touchRaw.hoverPoints[i] == -1)
|
||||
{
|
||||
touchRaw.hoverPoints[i] = touchRaw.pointId[pointerIndex];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags == AMOTION_EVENT_ACTION_POINTER_UP) || (flags == AMOTION_EVENT_ACTION_UP) || (flags == AMOTION_EVENT_ACTION_HOVER_EXIT))
|
||||
{
|
||||
// One of the touchpoints is released, remove it from touch point arrays
|
||||
if (flags == AMOTION_EVENT_ACTION_HOVER_EXIT)
|
||||
{
|
||||
// If the touchPoint is hover, remove it from hoverPoints
|
||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
|
||||
{
|
||||
if (touchRaw.hoverPoints[i] == touchRaw.pointId[pointerIndex])
|
||||
{
|
||||
touchRaw.hoverPoints[i] = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = pointerIndex; (i < touchRaw.pointCount - 1) && (i < MAX_TOUCH_POINTS - 1); i++)
|
||||
{
|
||||
touchRaw.pointId[i] = touchRaw.pointId[i+1];
|
||||
touchRaw.position[i] = touchRaw.position[i+1];
|
||||
}
|
||||
touchRaw.pointCount--;
|
||||
}
|
||||
|
||||
int pointCount = 0;
|
||||
for (int i = 0; (i < touchRaw.pointCount) && (i < MAX_TOUCH_POINTS); i++)
|
||||
{
|
||||
// If the touchPoint is hover, Ignore it
|
||||
bool hover = false;
|
||||
for (int j = 0; j < MAX_TOUCH_POINTS; j++)
|
||||
{
|
||||
// Check if the touchPoint is in hoverPointers
|
||||
if (touchRaw.hoverPoints[j] == touchRaw.pointId[i])
|
||||
{
|
||||
hover = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hover) continue;
|
||||
|
||||
CORE.Input.Touch.pointId[pointCount] = touchRaw.pointId[i];
|
||||
CORE.Input.Touch.position[pointCount] = touchRaw.position[i];
|
||||
pointCount++;
|
||||
}
|
||||
CORE.Input.Touch.pointCount = pointCount;
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
|
@ -1312,20 +1386,6 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
|||
ProcessGestureEvent(gestureEvent);
|
||||
#endif
|
||||
|
||||
int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
|
||||
|
||||
if (flags == AMOTION_EVENT_ACTION_POINTER_UP || flags == AMOTION_EVENT_ACTION_UP)
|
||||
{
|
||||
// One of the touchpoints is released, remove it from touch point arrays
|
||||
for (int i = pointerIndex; (i < CORE.Input.Touch.pointCount - 1) && (i < MAX_TOUCH_POINTS); i++)
|
||||
{
|
||||
CORE.Input.Touch.pointId[i] = CORE.Input.Touch.pointId[i+1];
|
||||
CORE.Input.Touch.position[i] = CORE.Input.Touch.position[i+1];
|
||||
}
|
||||
|
||||
CORE.Input.Touch.pointCount--;
|
||||
}
|
||||
|
||||
// When all touchpoints are tapped and released really quickly, this event is generated
|
||||
if (flags == AMOTION_EVENT_ACTION_CANCEL) CORE.Input.Touch.pointCount = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* rcore_desktop - Functions to manage window, graphics device and inputs
|
||||
* rcore_desktop_glfw - Functions to manage window, graphics device and inputs
|
||||
*
|
||||
* PLATFORM: DESKTOP: GLFW
|
||||
* - Windows (Win32, Win64)
|
||||
|
|
@ -74,9 +74,14 @@
|
|||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||
#include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
|
||||
|
||||
//#define GLFW_EXPOSE_NATIVE_X11 // WARNING: Exposing Xlib.h > X.h results in dup symbols for Font type
|
||||
//#define GLFW_EXPOSE_NATIVE_WAYLAND
|
||||
#define GLFW_EXPOSE_NATIVE_X11
|
||||
#define Font X11Font // Hack to fix 'Font' name collision
|
||||
// The definition and references to the X11 Font type will be replaced by 'X11Font'
|
||||
// Works as long as the current file consistently references any X11 Font as X11Font
|
||||
// Since it is never referenced (as of writting), this does not pose an issue
|
||||
#include "GLFW/glfw3native.h" // Required for: glfwGetX11Window()
|
||||
#undef Font // Revert hack and allow normal raylib Font usage
|
||||
#endif
|
||||
#if defined(__APPLE__)
|
||||
#include <unistd.h> // Required for: usleep()
|
||||
|
|
@ -130,9 +135,9 @@ static void CursorEnterCallback(GLFWwindow *window, int enter);
|
|||
static void JoystickCallback(int jid, int event); // GLFW3 Joystick Connected/Disconnected Callback
|
||||
|
||||
// Wrappers used by glfwInitAllocator
|
||||
static void* AllocateWrapper(size_t size, void* user); // GLFW3 GLFWallocatefun, wrapps around RL_MALLOC macro
|
||||
static void* ReallocateWrapper(void* block, size_t size, void* user); // GLFW3 GLFWreallocatefun, wrapps around RL_MALLOC macro
|
||||
static void DeallocateWrapper(void* block, void* user); // GLFW3 GLFWdeallocatefun, wraps around RL_FREE macro
|
||||
static void *AllocateWrapper(size_t size, void *user); // GLFW3 GLFWallocatefun, wrapps around RL_MALLOC macro
|
||||
static void *ReallocateWrapper(void *block, size_t size, void *user); // GLFW3 GLFWreallocatefun, wrapps around RL_MALLOC macro
|
||||
static void DeallocateWrapper(void *block, void *user); // GLFW3 GLFWdeallocatefun, wraps around RL_FREE macro
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
|
|
@ -576,7 +581,7 @@ void SetWindowIcons(Image *images, int count)
|
|||
else
|
||||
{
|
||||
int valid = 0;
|
||||
GLFWimage *icons = RL_CALLOC(count, sizeof(GLFWimage));
|
||||
GLFWimage *icons = (GLFWimage *)RL_CALLOC(count, sizeof(GLFWimage));
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
|
|
@ -705,6 +710,12 @@ void SetWindowFocused(void)
|
|||
glfwFocusWindow(platform.handle);
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
// Local storage for the window handle returned by glfwGetX11Window
|
||||
// This is needed as X11 handles are integers and may not fit inside a pointer depending on platform
|
||||
// Storing the handle locally and returning a pointer in GetWindowHandle allows the code to work regardless of pointer width
|
||||
static XID X11WindowHandle;
|
||||
#endif
|
||||
// Get native window handle
|
||||
void *GetWindowHandle(void)
|
||||
{
|
||||
|
|
@ -713,12 +724,10 @@ void *GetWindowHandle(void)
|
|||
return glfwGetWin32Window(platform.handle);
|
||||
#endif
|
||||
#if defined(__linux__)
|
||||
// NOTE: Returned handle is: unsigned long Window (X.h)
|
||||
// typedef unsigned long XID;
|
||||
// typedef XID Window;
|
||||
//unsigned long id = (unsigned long)glfwGetX11Window(platform.handle);
|
||||
//return NULL; // TODO: Find a way to return value... cast to void *?
|
||||
return (void *)platform.handle;
|
||||
// Store the window handle localy and return a pointer to the variable instead
|
||||
// Reasoning detailed in the declaration of X11WindowHandle
|
||||
X11WindowHandle = glfwGetX11Window(platform.handle);
|
||||
return &X11WindowHandle;
|
||||
#endif
|
||||
#if defined(__APPLE__)
|
||||
// NOTE: Returned handle is: (objc_object *)
|
||||
|
|
@ -1057,9 +1066,9 @@ double GetTime(void)
|
|||
}
|
||||
|
||||
// Open URL with default system browser (if available)
|
||||
// NOTE: This function is only safe to use if you control the URL given.
|
||||
// A user could craft a malicious string performing another action.
|
||||
// Only call this function yourself not with user input or make sure to check the string yourself.
|
||||
// NOTE: This function is only safe to use if you control the URL given
|
||||
// A user could craft a malicious string performing another action
|
||||
// Only call this function yourself not with user input or make sure to check the string yourself
|
||||
// Ref: https://github.com/raysan5/raylib/issues/686
|
||||
void OpenURL(const char *url)
|
||||
{
|
||||
|
|
@ -1121,7 +1130,7 @@ void SetMouseCursor(int cursor)
|
|||
}
|
||||
}
|
||||
|
||||
// Get physical key name.
|
||||
// Get physical key name
|
||||
const char *GetKeyName(int key)
|
||||
{
|
||||
return glfwGetKeyName(key, glfwGetKeyScancode(key));
|
||||
|
|
@ -1238,7 +1247,7 @@ void PollInputEvents(void)
|
|||
}
|
||||
}
|
||||
|
||||
// Get current axis state
|
||||
// Get current state of axes
|
||||
const float *axes = state.axes;
|
||||
|
||||
for (int k = 0; (axes != NULL) && (k < GLFW_GAMEPAD_AXIS_LAST + 1); k++)
|
||||
|
|
@ -1246,7 +1255,7 @@ void PollInputEvents(void)
|
|||
CORE.Input.Gamepad.axisState[i][k] = axes[k];
|
||||
}
|
||||
|
||||
// Register buttons for 2nd triggers (because GLFW doesn't count these as buttons but rather axis)
|
||||
// Register buttons for 2nd triggers (because GLFW doesn't count these as buttons but rather as axes)
|
||||
if (CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_LEFT_TRIGGER] > 0.1f)
|
||||
{
|
||||
CORE.Input.Gamepad.currentButtonState[i][GAMEPAD_BUTTON_LEFT_TRIGGER_2] = 1;
|
||||
|
|
@ -1297,20 +1306,20 @@ static void SetDimensionsFromMonitor(GLFWmonitor *monitor)
|
|||
}
|
||||
|
||||
// Function wrappers around RL_*alloc macros, used by glfwInitAllocator() inside of InitPlatform()
|
||||
// We need to provide these because GLFWallocator expects function pointers with specific signatures.
|
||||
// Similar wrappers exist in utils.c but we cannot reuse them here due to declaration mismatch.
|
||||
// We need to provide these because GLFWallocator expects function pointers with specific signatures
|
||||
// Similar wrappers exist in utils.c but we cannot reuse them here due to declaration mismatch
|
||||
// https://www.glfw.org/docs/latest/intro_guide.html#init_allocator
|
||||
static void* AllocateWrapper(size_t size, void* user)
|
||||
static void *AllocateWrapper(size_t size, void *user)
|
||||
{
|
||||
(void)user;
|
||||
return RL_MALLOC(size);
|
||||
}
|
||||
static void* ReallocateWrapper(void* block, size_t size, void* user)
|
||||
static void *ReallocateWrapper(void *block, size_t size, void *user)
|
||||
{
|
||||
(void)user;
|
||||
return RL_REALLOC(block, size);
|
||||
}
|
||||
static void DeallocateWrapper(void* block, void* user)
|
||||
static void DeallocateWrapper(void *block, void *user)
|
||||
{
|
||||
(void)user;
|
||||
RL_FREE(block);
|
||||
|
|
@ -1327,6 +1336,7 @@ int InitPlatform(void)
|
|||
.reallocate = ReallocateWrapper,
|
||||
.user = NULL, // RL_*ALLOC macros are not capable of handling user-provided data
|
||||
};
|
||||
|
||||
glfwInitAllocator(&allocator);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
|
@ -1384,15 +1394,15 @@ int InitPlatform(void)
|
|||
// HACK: Most of this was written before GLFW_SCALE_FRAMEBUFFER existed and
|
||||
// was enabled by default. Disabling it gets back the old behavior. A
|
||||
// complete fix will require removing a lot of CORE.Window.render
|
||||
// manipulation code.
|
||||
// manipulation code
|
||||
glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_FALSE);
|
||||
|
||||
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
||||
{
|
||||
// Resize window content area based on the monitor content scale.
|
||||
// NOTE: This hint only has an effect on platforms where screen coordinates and pixels always map 1:1 such as Windows and X11.
|
||||
// On platforms like macOS the resolution of the framebuffer is changed independently of the window size.
|
||||
glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); // Scale content area based on the monitor content scale where window is placed on
|
||||
// Resize window content area based on the monitor content scale
|
||||
// NOTE: This hint only has an effect on platforms where screen coordinates and pixels always map 1:1 such as Windows and X11
|
||||
// On platforms like macOS the resolution of the framebuffer is changed independently of the window size
|
||||
glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); // Scale content area based on the monitor content scale where window is placed on
|
||||
#if defined(__APPLE__)
|
||||
glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE);
|
||||
#endif
|
||||
|
|
@ -1411,8 +1421,8 @@ int InitPlatform(void)
|
|||
}
|
||||
|
||||
// NOTE: When asking for an OpenGL context version, most drivers provide the highest supported version
|
||||
// with backward compatibility to older OpenGL versions.
|
||||
// For example, if using OpenGL 1.1, driver can provide a 4.3 backwards compatible context.
|
||||
// with backward compatibility to older OpenGL versions
|
||||
// For example, if using OpenGL 1.1, driver can provide a 4.3 backwards compatible context
|
||||
|
||||
// Check selection OpenGL version
|
||||
if (rlGetVersion() == RL_OPENGL_21)
|
||||
|
|
@ -1458,9 +1468,9 @@ int InitPlatform(void)
|
|||
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
|
||||
}
|
||||
|
||||
// NOTE: GLFW 3.4+ defers initialization of the Joystick subsystem on the first call to any Joystick related functions.
|
||||
// Forcing this initialization here avoids doing it on PollInputEvents() called by EndDrawing() after first frame has been just drawn.
|
||||
// The initialization will still happen and possible delays still occur, but before the window is shown, which is a nicer experience.
|
||||
// NOTE: GLFW 3.4+ defers initialization of the Joystick subsystem on the first call to any Joystick related functions
|
||||
// Forcing this initialization here avoids doing it on PollInputEvents() called by EndDrawing() after first frame has been just drawn
|
||||
// The initialization will still happen and possible delays still occur, but before the window is shown, which is a nicer experience
|
||||
// REF: https://github.com/raysan5/raylib/issues/1554
|
||||
glfwSetJoystickCallback(NULL);
|
||||
|
||||
|
|
@ -1468,7 +1478,7 @@ int InitPlatform(void)
|
|||
if (CORE.Window.fullscreen)
|
||||
{
|
||||
// According to glfwCreateWindow(), if the user does not have a choice, fullscreen applications
|
||||
// should default to the primary monitor.
|
||||
// should default to the primary monitor
|
||||
|
||||
monitor = glfwGetPrimaryMonitor();
|
||||
if (!monitor)
|
||||
|
|
@ -1482,8 +1492,8 @@ int InitPlatform(void)
|
|||
// Remember center for switching from fullscreen to window
|
||||
if ((CORE.Window.screen.height == CORE.Window.display.height) && (CORE.Window.screen.width == CORE.Window.display.width))
|
||||
{
|
||||
// If screen width/height equal to the display, we can't calculate the window pos for toggling full-screened/windowed.
|
||||
// Toggling full-screened/windowed with pos(0, 0) can cause problems in some platforms, such as X11.
|
||||
// If screen width/height equal to the display, we can't calculate the window pos for toggling full-screened/windowed
|
||||
// Toggling full-screened/windowed with pos(0, 0) can cause problems in some platforms, such as X11
|
||||
CORE.Window.position.x = CORE.Window.display.width/4;
|
||||
CORE.Window.position.y = CORE.Window.display.height/4;
|
||||
}
|
||||
|
|
@ -1544,7 +1554,7 @@ int InitPlatform(void)
|
|||
// No-fullscreen window creation
|
||||
bool requestWindowedFullscreen = (CORE.Window.screen.height == 0) && (CORE.Window.screen.width == 0);
|
||||
|
||||
// Default to at least one pixel in size, as creation with a zero dimension is not allowed.
|
||||
// Default to at least one pixel in size, as creation with a zero dimension is not allowed
|
||||
int creationWidth = CORE.Window.screen.width != 0 ? CORE.Window.screen.width : 1;
|
||||
int creationHeight = CORE.Window.screen.height != 0 ? CORE.Window.screen.height : 1;
|
||||
|
||||
|
|
@ -1556,8 +1566,8 @@ int InitPlatform(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
// After the window was created, determine the monitor that the window manager assigned.
|
||||
// Derive display sizes, and, if possible, window size in case it was zero at beginning.
|
||||
// After the window was created, determine the monitor that the window manager assigned
|
||||
// Derive display sizes, and, if possible, window size in case it was zero at beginning
|
||||
|
||||
int monitorCount = 0;
|
||||
int monitorIndex = GetCurrentMonitor();
|
||||
|
|
@ -1572,7 +1582,7 @@ int InitPlatform(void)
|
|||
}
|
||||
else
|
||||
{
|
||||
// The monitor for the window-manager-created window can not be determined, so it can not be centered.
|
||||
// The monitor for the window-manager-created window can not be determined, so it can not be centered
|
||||
glfwTerminate();
|
||||
TRACELOG(LOG_WARNING, "GLFW: Failed to determine Monitor to center Window");
|
||||
return -1;
|
||||
|
|
@ -1594,7 +1604,7 @@ int InitPlatform(void)
|
|||
|
||||
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
||||
// NOTE: V-Sync can be enabled by graphic driver configuration, it doesn't need
|
||||
// to be activated on web platforms since VSync is enforced there.
|
||||
// to be activated on web platforms since VSync is enforced there
|
||||
if (CORE.Window.flags & FLAG_VSYNC_HINT)
|
||||
{
|
||||
// WARNING: It seems to hit a critical render path in Intel HD Graphics
|
||||
|
|
@ -1607,7 +1617,7 @@ int InitPlatform(void)
|
|||
|
||||
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
||||
{
|
||||
// NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling.
|
||||
// NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling
|
||||
// Framebuffer scaling should be activated with: glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE);
|
||||
#if !defined(__APPLE__)
|
||||
glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight);
|
||||
|
|
@ -1650,7 +1660,8 @@ int InitPlatform(void)
|
|||
int monitorHeight = 0;
|
||||
glfwGetMonitorWorkarea(monitor, &monitorX, &monitorY, &monitorWidth, &monitorHeight);
|
||||
|
||||
// Here CORE.Window.render.width/height should be used instead of CORE.Window.screen.width/height to center the window correctly when the high dpi flag is enabled.
|
||||
// Here CORE.Window.render.width/height should be used instead of
|
||||
// CORE.Window.screen.width/height to center the window correctly when the high dpi flag is enabled
|
||||
int posX = monitorX + (monitorWidth - (int)CORE.Window.render.width)/2;
|
||||
int posY = monitorY + (monitorHeight - (int)CORE.Window.render.height)/2;
|
||||
if (posX < monitorX) posX = monitorX;
|
||||
|
|
@ -1696,6 +1707,8 @@ int InitPlatform(void)
|
|||
// Retrieve gamepad names
|
||||
for (int i = 0; i < MAX_GAMEPADS; i++)
|
||||
{
|
||||
// WARNING: If glfwGetJoystickName() is longer than MAX_GAMEPAD_NAME_LENGTH,
|
||||
// we can get a not-NULL terminated string, so, we only copy up to (MAX_GAMEPAD_NAME_LENGTH - 1)
|
||||
if (glfwJoystickPresent(i)) strncpy(CORE.Input.Gamepad.name[i], glfwGetJoystickName(i), MAX_GAMEPAD_NAME_LENGTH - 1);
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
@ -1753,7 +1766,7 @@ static void ErrorCallback(int error, const char *description)
|
|||
static void WindowSizeCallback(GLFWwindow *window, int width, int height)
|
||||
{
|
||||
// WARNING: On window minimization, callback is called,
|
||||
// but we don't want to change internal screen values, it breaks things
|
||||
// but we don't want to change internal screen values, it breaks things
|
||||
if ((width == 0) || (height == 0)) return;
|
||||
|
||||
// Reset viewport and projection matrix for new size
|
||||
|
|
@ -1850,8 +1863,8 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i
|
|||
// WARNING: GLFW could return GLFW_REPEAT, we need to consider it as 1
|
||||
// to work properly with our implementation (IsKeyDown/IsKeyUp checks)
|
||||
if (action == GLFW_RELEASE) CORE.Input.Keyboard.currentKeyState[key] = 0;
|
||||
else if(action == GLFW_PRESS) CORE.Input.Keyboard.currentKeyState[key] = 1;
|
||||
else if(action == GLFW_REPEAT) CORE.Input.Keyboard.keyRepeatInFrame[key] = 1;
|
||||
else if (action == GLFW_PRESS) CORE.Input.Keyboard.currentKeyState[key] = 1;
|
||||
else if (action == GLFW_REPEAT) CORE.Input.Keyboard.keyRepeatInFrame[key] = 1;
|
||||
|
||||
// WARNING: Check if CAPS/NUM key modifiers are enabled and force down state for those keys
|
||||
if (((key == KEY_CAPS_LOCK) && ((mods & GLFW_MOD_CAPS_LOCK) > 0)) ||
|
||||
|
|
@ -1973,6 +1986,9 @@ static void JoystickCallback(int jid, int event)
|
|||
{
|
||||
if (event == GLFW_CONNECTED)
|
||||
{
|
||||
// WARNING: If glfwGetJoystickName() is longer than MAX_GAMEPAD_NAME_LENGTH,
|
||||
// we can get a not-NULL terminated string, so, we clean destination and only copy up to -1
|
||||
memset(CORE.Input.Gamepad.name[jid], 0, MAX_GAMEPAD_NAME_LENGTH);
|
||||
strncpy(CORE.Input.Gamepad.name[jid], glfwGetJoystickName(jid), MAX_GAMEPAD_NAME_LENGTH - 1);
|
||||
}
|
||||
else if (event == GLFW_DISCONNECTED)
|
||||
|
|
|
|||
|
|
@ -175,7 +175,9 @@ static const unsigned short keyMappingRGFW[] = {
|
|||
[RGFW_superL] = KEY_LEFT_SUPER,
|
||||
#ifndef RGFW_MACOS
|
||||
[RGFW_shiftR] = KEY_RIGHT_SHIFT,
|
||||
[RGFW_controlR] = KEY_RIGHT_CONTROL,
|
||||
[RGFW_altR] = KEY_RIGHT_ALT,
|
||||
[RGFW_superR] = KEY_RIGHT_SUPER,
|
||||
#endif
|
||||
[RGFW_space] = KEY_SPACE,
|
||||
|
||||
|
|
@ -583,7 +585,7 @@ void SetWindowPosition(int x, int y)
|
|||
// Set monitor for the current window
|
||||
void SetWindowMonitor(int monitor)
|
||||
{
|
||||
RGFW_window_moveToMonitor(platform.window, RGFW_getMonitors()[monitor]);
|
||||
RGFW_window_moveToMonitor(platform.window, RGFW_getMonitors(NULL)[monitor]);
|
||||
}
|
||||
|
||||
// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
|
||||
|
|
@ -640,7 +642,7 @@ int GetMonitorCount(void)
|
|||
#define MAX_MONITORS_SUPPORTED 6
|
||||
|
||||
int count = MAX_MONITORS_SUPPORTED;
|
||||
RGFW_monitor *mons = RGFW_getMonitors();
|
||||
RGFW_monitor *mons = RGFW_getMonitors(NULL);
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
|
|
@ -657,7 +659,7 @@ int GetMonitorCount(void)
|
|||
// Get current monitor where window is placed
|
||||
int GetCurrentMonitor(void)
|
||||
{
|
||||
RGFW_monitor *mons = RGFW_getMonitors();
|
||||
RGFW_monitor *mons = RGFW_getMonitors(NULL);
|
||||
RGFW_monitor mon = { 0 };
|
||||
|
||||
if (platform.window) mon = RGFW_window_getMonitor(platform.window);
|
||||
|
|
@ -674,7 +676,7 @@ int GetCurrentMonitor(void)
|
|||
// Get selected monitor position
|
||||
Vector2 GetMonitorPosition(int monitor)
|
||||
{
|
||||
RGFW_monitor *mons = RGFW_getMonitors();
|
||||
RGFW_monitor *mons = RGFW_getMonitors(NULL);
|
||||
|
||||
return (Vector2){ (float)mons[monitor].x, (float)mons[monitor].y };
|
||||
}
|
||||
|
|
@ -682,7 +684,7 @@ Vector2 GetMonitorPosition(int monitor)
|
|||
// Get selected monitor width (currently used by monitor)
|
||||
int GetMonitorWidth(int monitor)
|
||||
{
|
||||
RGFW_monitor *mons = RGFW_getMonitors();
|
||||
RGFW_monitor *mons = RGFW_getMonitors(NULL);
|
||||
|
||||
return mons[monitor].mode.area.w;
|
||||
}
|
||||
|
|
@ -690,7 +692,7 @@ int GetMonitorWidth(int monitor)
|
|||
// Get selected monitor height (currently used by monitor)
|
||||
int GetMonitorHeight(int monitor)
|
||||
{
|
||||
RGFW_monitor *mons = RGFW_getMonitors();
|
||||
RGFW_monitor *mons = RGFW_getMonitors(NULL);
|
||||
|
||||
return mons[monitor].mode.area.h;
|
||||
}
|
||||
|
|
@ -698,7 +700,7 @@ int GetMonitorHeight(int monitor)
|
|||
// Get selected monitor physical width in millimetres
|
||||
int GetMonitorPhysicalWidth(int monitor)
|
||||
{
|
||||
RGFW_monitor *mons = RGFW_getMonitors();
|
||||
RGFW_monitor *mons = RGFW_getMonitors(NULL);
|
||||
|
||||
return mons[monitor].physW;
|
||||
}
|
||||
|
|
@ -706,7 +708,7 @@ int GetMonitorPhysicalWidth(int monitor)
|
|||
// Get selected monitor physical height in millimetres
|
||||
int GetMonitorPhysicalHeight(int monitor)
|
||||
{
|
||||
RGFW_monitor *mons = RGFW_getMonitors();
|
||||
RGFW_monitor *mons = RGFW_getMonitors(NULL);
|
||||
|
||||
return (int)mons[monitor].physH;
|
||||
}
|
||||
|
|
@ -714,7 +716,7 @@ int GetMonitorPhysicalHeight(int monitor)
|
|||
// Get selected monitor refresh rate
|
||||
int GetMonitorRefreshRate(int monitor)
|
||||
{
|
||||
RGFW_monitor *mons = RGFW_getMonitors();
|
||||
RGFW_monitor *mons = RGFW_getMonitors(NULL);
|
||||
|
||||
return (int)mons[monitor].mode.refreshRate;
|
||||
}
|
||||
|
|
@ -722,7 +724,7 @@ int GetMonitorRefreshRate(int monitor)
|
|||
// Get the human-readable, UTF-8 encoded name of the selected monitor
|
||||
const char *GetMonitorName(int monitor)
|
||||
{
|
||||
RGFW_monitor *mons = RGFW_getMonitors();
|
||||
RGFW_monitor *mons = RGFW_getMonitors(NULL);
|
||||
|
||||
return mons[monitor].name;
|
||||
}
|
||||
|
|
@ -987,7 +989,7 @@ void PollInputEvents(void)
|
|||
|
||||
if ((CORE.Window.eventWaiting) || (IsWindowState(FLAG_WINDOW_MINIMIZED) && !IsWindowState(FLAG_WINDOW_ALWAYS_RUN)))
|
||||
{
|
||||
RGFW_window_eventWait(platform.window, 0); // Wait for input events: keyboard/mouse/window events (callbacks) -> Update keys state
|
||||
RGFW_window_eventWait(platform.window, -1); // Wait for input events: keyboard/mouse/window events (callbacks) -> Update keys state
|
||||
CORE.Time.previous = GetTime();
|
||||
}
|
||||
|
||||
|
|
@ -1319,6 +1321,13 @@ int InitPlatform(void)
|
|||
platform.window = RGFW_createWindow(CORE.Window.title, RGFW_RECT(0, 0, CORE.Window.screen.width, CORE.Window.screen.height), flags);
|
||||
platform.mon.mode.area.w = 0;
|
||||
|
||||
if (platform.window != NULL)
|
||||
{
|
||||
// NOTE: RGFW's exit key is distinct from raylib's exit key (which can
|
||||
// be set with SetExitKey()) and defaults to Escape
|
||||
platform.window->exitKey = RGFW_keyNULL;
|
||||
}
|
||||
|
||||
#ifndef PLATFORM_WEB_RGFW
|
||||
RGFW_area screenSize = RGFW_getScreenSize();
|
||||
CORE.Window.display.width = screenSize.w;
|
||||
|
|
|
|||
|
|
@ -52,13 +52,27 @@
|
|||
#ifndef SDL_ENABLE_OLD_NAMES
|
||||
#define SDL_ENABLE_OLD_NAMES // Just in case we're on SDL3, we need some in-between compatibily
|
||||
#endif
|
||||
#include "SDL.h" // SDL base library (window/rendered, input, timing... functionality)
|
||||
// SDL base library (window/rendered, input, timing... functionality)
|
||||
#ifdef USING_SDL3_PROJECT
|
||||
#include "SDL3/SDL.h"
|
||||
#elif USING_SDL2_PROJECT
|
||||
#include "SDL2/SDL.h"
|
||||
#else
|
||||
#include "SDL.h"
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// It seems it does not need to be included to work
|
||||
//#include "SDL_opengles2.h"
|
||||
#else
|
||||
#include "SDL_opengl.h" // SDL OpenGL functionality (if required, instead of internal renderer)
|
||||
// SDL OpenGL functionality (if required, instead of internal renderer)
|
||||
#ifdef USING_SDL3_PROJECT
|
||||
#include "SDL3/SDL_opengl.h"
|
||||
#elif USING_SDL2_PROJECT
|
||||
#include "SDL2/SDL_opengl.h"
|
||||
#else
|
||||
#include "SDL_opengl.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -238,8 +252,7 @@ static const int CursorsLUT[] = {
|
|||
//SDL_SYSTEM_CURSOR_WAITARROW, // No equivalent implemented on MouseCursor enum on raylib.h
|
||||
};
|
||||
|
||||
|
||||
// SDL3 Migration Layer made to avoid `ifdefs` inside functions when we can.
|
||||
// SDL3 Migration Layer made to avoid 'ifdefs' inside functions when we can
|
||||
#if defined(PLATFORM_DESKTOP_SDL3)
|
||||
|
||||
// SDL3 Migration:
|
||||
|
|
@ -256,7 +269,7 @@ static const int CursorsLUT[] = {
|
|||
// SDL3 Migration: SDL_INIT_TIMER - no longer needed before calling SDL_AddTimer()
|
||||
#define SDL_INIT_TIMER 0x0 // It's a flag, so no problem in setting it to zero if we use in a bitor (|)
|
||||
|
||||
// SDL3 Migration: The SDL_WINDOW_SHOWN flag has been removed. Windows are shown by default and can be created hidden by using the SDL_WINDOW_HIDDEN flag.
|
||||
// SDL3 Migration: The SDL_WINDOW_SHOWN flag has been removed. Windows are shown by default and can be created hidden by using the SDL_WINDOW_HIDDEN flag
|
||||
#define SDL_WINDOW_SHOWN 0x0 // It's a flag, so no problem in setting it to zero if we use in a bitor (|)
|
||||
|
||||
// SDL3 Migration: Renamed
|
||||
|
|
@ -290,13 +303,13 @@ int SDL_GetNumVideoDisplays(void)
|
|||
int monitorCount = 0;
|
||||
SDL_DisplayID *displays = SDL_GetDisplays(&monitorCount);
|
||||
|
||||
// Safe because If `mem` is NULL, SDL_free does nothing
|
||||
// Safe because If 'mem' is NULL, SDL_free does nothing
|
||||
SDL_free(displays);
|
||||
|
||||
return monitorCount;
|
||||
}
|
||||
|
||||
// SLD3 Migration: To emulate SDL2 this function should return `SDL_DISABLE` or `SDL_ENABLE`
|
||||
// SLD3 Migration: To emulate SDL2 this function should return 'SDL_DISABLE' or 'SDL_ENABLE'
|
||||
// representing the *processing state* of the event before this function makes any changes to it
|
||||
Uint8 SDL_EventState(Uint32 type, int state)
|
||||
{
|
||||
|
|
@ -331,7 +344,7 @@ SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth
|
|||
// SDL3 Migration:
|
||||
// SDL_GetDisplayDPI() -
|
||||
// not reliable across platforms, approximately replaced by multiplying
|
||||
// SDL_GetWindowDisplayScale() times 160 on iPhone and Android, and 96 on other platforms.
|
||||
// SDL_GetWindowDisplayScale() times 160 on iPhone and Android, and 96 on other platforms
|
||||
// returns 0 on success or a negative error code on failure
|
||||
int SDL_GetDisplayDPI(int displayIndex, float *ddpi, float *hdpi, float *vdpi)
|
||||
{
|
||||
|
|
@ -369,7 +382,7 @@ int SDL_NumJoysticks(void)
|
|||
|
||||
// SDL_SetRelativeMouseMode
|
||||
// returns 0 on success or a negative error code on failure
|
||||
// If relative mode is not supported, this returns -1.
|
||||
// If relative mode is not supported, this returns -1
|
||||
int SDL_SetRelativeMouseMode_Adapter(SDL_bool enabled)
|
||||
{
|
||||
// SDL_SetWindowRelativeMouseMode(SDL_Window *window, bool enabled)
|
||||
|
|
@ -424,6 +437,8 @@ void ClosePlatform(void); // Close platform
|
|||
|
||||
static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode); // Help convert SDL scancodes to raylib key
|
||||
|
||||
static int GetCodepointNextSDL(const char *text, int *codepointSize); // Get next codepoint in a byte sequence and bytes processed
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -565,7 +580,7 @@ void SetWindowState(unsigned int flags)
|
|||
if (flags & FLAG_WINDOW_UNFOCUSED)
|
||||
{
|
||||
// NOTE: To be able to implement this part it seems that we should
|
||||
// do it ourselves, via `Windows.h`, `X11/Xlib.h` or even `Cocoa.h`
|
||||
// do it ourselves, via 'windows.h', 'X11/Xlib.h' or even 'Cocoa.h'
|
||||
TRACELOG(LOG_WARNING, "SetWindowState() - FLAG_WINDOW_UNFOCUSED is not supported on PLATFORM_DESKTOP_SDL");
|
||||
}
|
||||
if (flags & FLAG_WINDOW_TOPMOST)
|
||||
|
|
@ -721,7 +736,7 @@ void SetWindowIcon(Image image)
|
|||
bmask = 0x001F, amask = 0;
|
||||
depth = 16, pitch = image.width*2;
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8:
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8:
|
||||
{
|
||||
// WARNING: SDL2 could be using BGR but SDL3 RGB
|
||||
rmask = 0xFF0000, gmask = 0x00FF00;
|
||||
|
|
@ -826,7 +841,7 @@ void SetWindowMonitor(int monitor)
|
|||
// NOTE:
|
||||
// 1. SDL started supporting moving exclusive fullscreen windows between displays on SDL3,
|
||||
// see commit https://github.com/libsdl-org/SDL/commit/3f5ef7dd422057edbcf3e736107e34be4b75d9ba
|
||||
// 2. A workaround for SDL2 is leaving fullscreen, moving the window, then entering full screen again.
|
||||
// 2. A workaround for SDL2 is leaving fullscreen, moving the window, then entering full screen again
|
||||
const bool wasFullscreen = ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0)? true : false;
|
||||
|
||||
const int screenWidth = CORE.Window.screen.width;
|
||||
|
|
@ -839,7 +854,7 @@ void SetWindowMonitor(int monitor)
|
|||
if (SDL_GetDisplayUsableBounds(monitor, &usableBounds) == 0)
|
||||
#endif
|
||||
{
|
||||
if (wasFullscreen == 1) ToggleFullscreen(); // Leave fullscreen.
|
||||
if (wasFullscreen == 1) ToggleFullscreen(); // Leave fullscreen
|
||||
|
||||
// If the screen size is larger than the monitor usable area, anchor it on the top left corner, otherwise, center it
|
||||
if ((screenWidth >= usableBounds.w) || (screenHeight >= usableBounds.h))
|
||||
|
|
@ -847,11 +862,11 @@ void SetWindowMonitor(int monitor)
|
|||
// NOTE:
|
||||
// 1. There's a known issue where if the window larger than the target display bounds,
|
||||
// when moving the windows to that display, the window could be clipped back
|
||||
// ending up positioned partly outside the target display.
|
||||
// ending up positioned partly outside the target display
|
||||
// 2. The workaround for that is, previously to moving the window,
|
||||
// setting the window size to the target display size, so they match.
|
||||
// setting the window size to the target display size, so they match
|
||||
// 3. It wasn't done here because we can't assume changing the window size automatically
|
||||
// is acceptable behavior by the user.
|
||||
// is acceptable behavior by the user
|
||||
SDL_SetWindowPosition(platform.window, usableBounds.x, usableBounds.y);
|
||||
CORE.Window.position.x = usableBounds.x;
|
||||
CORE.Window.position.y = usableBounds.y;
|
||||
|
|
@ -1084,12 +1099,11 @@ Vector2 GetWindowScaleDPI(void)
|
|||
#ifndef PLATFORM_DESKTOP_SDL3
|
||||
// NOTE: SDL_GetWindowDisplayScale was only added on SDL3
|
||||
// see https://wiki.libsdl.org/SDL3/SDL_GetWindowDisplayScale
|
||||
// TODO: Implement the window scale factor calculation manually.
|
||||
// TODO: Implement the window scale factor calculation manually
|
||||
TRACELOG(LOG_WARNING, "GetWindowScaleDPI() not implemented on target platform");
|
||||
#else
|
||||
scale.x = SDL_GetWindowDisplayScale(platform.window);
|
||||
scale.y = scale.x;
|
||||
TRACELOG(LOG_INFO, "WindowScaleDPI is %f", scale.x);
|
||||
scale.y = scale.x;
|
||||
#endif
|
||||
|
||||
return scale;
|
||||
|
|
@ -1153,13 +1167,13 @@ Image GetClipboardImage(void)
|
|||
image = LoadImageFromMemory(imageExtensions[i], fileData, dataSize);
|
||||
if (IsImageValid(image))
|
||||
{
|
||||
TRACELOG(LOG_INFO, "Clipboard image: Got image from clipboard as a `%s` successfully", imageExtensions[i]);
|
||||
TRACELOG(LOG_INFO, "Clipboard: Got image from clipboard successfully: %s", imageExtensions[i]);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsImageValid(image)) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data. Error: %s", SDL_GetError());
|
||||
if (!IsImageValid(image)) TRACELOG(LOG_WARNING, "Clipboard: Couldn't get clipboard data. ERROR: %s", SDL_GetError());
|
||||
#endif
|
||||
|
||||
return image;
|
||||
|
|
@ -1231,9 +1245,9 @@ double GetTime(void)
|
|||
}
|
||||
|
||||
// Open URL with default system browser (if available)
|
||||
// NOTE: This function is only safe to use if you control the URL given.
|
||||
// A user could craft a malicious string performing another action.
|
||||
// Only call this function yourself not with user input or make sure to check the string yourself.
|
||||
// NOTE: This function is only safe to use if you control the URL given
|
||||
// A user could craft a malicious string performing another action
|
||||
// Only call this function yourself not with user input or make sure to check the string yourself
|
||||
// Ref: https://github.com/raysan5/raylib/issues/686
|
||||
void OpenURL(const char *url)
|
||||
{
|
||||
|
|
@ -1285,7 +1299,7 @@ void SetMouseCursor(int cursor)
|
|||
CORE.Input.Mouse.cursor = cursor;
|
||||
}
|
||||
|
||||
// Get physical key name.
|
||||
// Get physical key name
|
||||
const char *GetKeyName(int key)
|
||||
{
|
||||
return SDL_GetKeyName(key);
|
||||
|
|
@ -1452,10 +1466,9 @@ void PollInputEvents(void)
|
|||
|
||||
#ifndef PLATFORM_DESKTOP_SDL3
|
||||
// SDL3 states:
|
||||
// The SDL_WINDOWEVENT_* events have been moved to top level events,
|
||||
// and SDL_WINDOWEVENT has been removed.
|
||||
// In general, handling this change just means checking for the individual events instead of first checking for SDL_WINDOWEVENT
|
||||
// and then checking for window events. You can compare the event >= SDL_EVENT_WINDOW_FIRST and <= SDL_EVENT_WINDOW_LAST if you need to see whether it's a window event.
|
||||
// The SDL_WINDOWEVENT_* events have been moved to top level events, and SDL_WINDOWEVENT has been removed
|
||||
// In general, handling this change just means checking for the individual events instead of first checking for SDL_WINDOWEVENT
|
||||
// and then checking for window events. You can compare the event >= SDL_EVENT_WINDOW_FIRST and <= SDL_EVENT_WINDOW_LAST if you need to see whether it's a window event.
|
||||
case SDL_WINDOWEVENT:
|
||||
{
|
||||
switch (event.window.event)
|
||||
|
|
@ -1601,13 +1614,18 @@ void PollInputEvents(void)
|
|||
{
|
||||
// NOTE: event.text.text data comes an UTF-8 text sequence but we register codepoints (int)
|
||||
|
||||
int codepointSize = 0;
|
||||
|
||||
// Check if there is space available in the queue
|
||||
if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE)
|
||||
{
|
||||
// Add character (codepoint) to the queue
|
||||
CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = GetCodepointNext(event.text.text, &codepointSize);
|
||||
#if defined(PLATFORM_DESKTOP_SDL3)
|
||||
unsigned int textLen = strlen(event.text.text);
|
||||
unsigned int codepoint = (unsigned int)SDL_StepUTF8(&event.text.text, textLen);
|
||||
#else
|
||||
int codepointSize = 0;
|
||||
int codepoint = GetCodepointNextSDL(event.text.text, &codepointSize);
|
||||
#endif
|
||||
CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = codepoint;
|
||||
CORE.Input.Keyboard.charPressedQueueCount++;
|
||||
}
|
||||
} break;
|
||||
|
|
@ -1697,8 +1715,8 @@ void PollInputEvents(void)
|
|||
CORE.Input.Gamepad.axisCount[jid] = SDL_JoystickNumAxes(SDL_GameControllerGetJoystick(platform.gamepad[jid]));
|
||||
CORE.Input.Gamepad.axisState[jid][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f;
|
||||
CORE.Input.Gamepad.axisState[jid][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
|
||||
memset(CORE.Input.Gamepad.name[jid], 0, MAX_GAMEPAD_NAME_LENGTH);
|
||||
strncpy(CORE.Input.Gamepad.name[jid], SDL_GameControllerNameForIndex(jid), MAX_GAMEPAD_NAME_LENGTH - 1);
|
||||
CORE.Input.Gamepad.name[jid][MAX_GAMEPAD_NAME_LENGTH - 1] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1825,7 +1843,7 @@ void PollInputEvents(void)
|
|||
{
|
||||
if (platform.gamepadId[i] == event.jaxis.which)
|
||||
{
|
||||
// SDL axis value range is -32768 to 32767, we normalize it to RayLib's -1.0 to 1.0f range
|
||||
// SDL axis value range is -32768 to 32767, we normalize it to raylib's -1.0 to 1.0f range
|
||||
float value = event.jaxis.value/(float)32767;
|
||||
CORE.Input.Gamepad.axisState[i][axis] = value;
|
||||
|
||||
|
|
@ -2093,4 +2111,42 @@ static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode)
|
|||
|
||||
return KEY_NULL; // No equivalent key in Raylib
|
||||
}
|
||||
// EOF
|
||||
|
||||
// Get next codepoint in a byte sequence and bytes processed
|
||||
static int GetCodepointNextSDL(const char *text, int *codepointSize)
|
||||
{
|
||||
const char *ptr = text;
|
||||
int codepoint = 0x3f; // Codepoint (defaults to '?')
|
||||
*codepointSize = 1;
|
||||
|
||||
// Get current codepoint and bytes processed
|
||||
if (0xf0 == (0xf8 & ptr[0]))
|
||||
{
|
||||
// 4 byte UTF-8 codepoint
|
||||
if (((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80) || ((ptr[3] & 0xC0) ^ 0x80)) { return codepoint; } // 10xxxxxx checks
|
||||
codepoint = ((0x07 & ptr[0]) << 18) | ((0x3f & ptr[1]) << 12) | ((0x3f & ptr[2]) << 6) | (0x3f & ptr[3]);
|
||||
*codepointSize = 4;
|
||||
}
|
||||
else if (0xe0 == (0xf0 & ptr[0]))
|
||||
{
|
||||
// 3 byte UTF-8 codepoint */
|
||||
if (((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80)) { return codepoint; } // 10xxxxxx checks
|
||||
codepoint = ((0x0f & ptr[0]) << 12) | ((0x3f & ptr[1]) << 6) | (0x3f & ptr[2]);
|
||||
*codepointSize = 3;
|
||||
}
|
||||
else if (0xc0 == (0xe0 & ptr[0]))
|
||||
{
|
||||
// 2 byte UTF-8 codepoint
|
||||
if ((ptr[1] & 0xC0) ^ 0x80) { return codepoint; } // 10xxxxxx checks
|
||||
codepoint = ((0x1f & ptr[0]) << 6) | (0x3f & ptr[1]);
|
||||
*codepointSize = 2;
|
||||
}
|
||||
else if (0x00 == (0x80 & ptr[0]))
|
||||
{
|
||||
// 1 byte UTF-8 codepoint
|
||||
codepoint = ptr[0];
|
||||
*codepointSize = 1;
|
||||
}
|
||||
|
||||
return codepoint;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@
|
|||
*
|
||||
* CONFIGURATION:
|
||||
* #define SUPPORT_SSH_KEYBOARD_RPI (Raspberry Pi only)
|
||||
* Reconfigure standard input to receive key inputs, works with SSH connection.
|
||||
* Reconfigure standard input to receive key inputs, works with SSH connection
|
||||
* WARNING: Reconfiguring standard input could lead to undesired effects, like breaking other
|
||||
* running processes orblocking the device if not restored properly. Use with care.
|
||||
* running processes orblocking the device if not restored properly. Use with care
|
||||
*
|
||||
* DEPENDENCIES:
|
||||
* - DRM and GLM: System libraries for display initialization and configuration
|
||||
|
|
@ -48,11 +48,11 @@
|
|||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#include <fcntl.h> // POSIX file control definitions - open(), creat(), fcntl()
|
||||
#include <unistd.h> // POSIX standard function definitions - read(), close(), STDIN_FILENO
|
||||
#include <termios.h> // POSIX terminal control definitions - tcgetattr(), tcsetattr()
|
||||
#include <pthread.h> // POSIX threads management (inputs reading)
|
||||
#include <dirent.h> // POSIX directory browsing
|
||||
#include <fcntl.h> // POSIX file control definitions - open(), creat(), fcntl()
|
||||
#include <unistd.h> // POSIX standard function definitions - read(), close(), STDIN_FILENO
|
||||
#include <termios.h> // POSIX terminal control definitions - tcgetattr(), tcsetattr()
|
||||
#include <pthread.h> // POSIX threads management (inputs reading)
|
||||
#include <dirent.h> // POSIX directory browsing
|
||||
|
||||
#include <sys/ioctl.h> // Required for: ioctl() - UNIX System call for device-specific input/output operations
|
||||
#include <linux/kd.h> // Linux: KDSKBMODE, K_MEDIUMRAM constants definition
|
||||
|
|
@ -71,6 +71,14 @@
|
|||
#include "EGL/egl.h" // Native platform windowing system interface
|
||||
#include "EGL/eglext.h" // EGL extensions
|
||||
|
||||
// NOTE: DRM cache enables triple buffered DRM caching
|
||||
#if defined(SUPPORT_DRM_CACHE)
|
||||
#include <poll.h> // Required for: drmHandleEvent() poll
|
||||
#include <errno.h> // Required for: EBUSY, EAGAIN
|
||||
|
||||
#define MAX_DRM_CACHED_BUFFERS 3
|
||||
#endif // SUPPORT_DRM_CACHE
|
||||
|
||||
#ifndef EGL_OPENGL_ES3_BIT
|
||||
#define EGL_OPENGL_ES3_BIT 0x40
|
||||
#endif
|
||||
|
|
@ -78,18 +86,16 @@
|
|||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#define USE_LAST_TOUCH_DEVICE // When multiple touchscreens are connected, only use the one with the highest event<N> number
|
||||
#define USE_LAST_TOUCH_DEVICE // When multiple touchscreens are connected, only use the one with the highest event<N> number
|
||||
|
||||
#define DEFAULT_EVDEV_PATH "/dev/input/" // Path to the linux input events
|
||||
#define DEFAULT_EVDEV_PATH "/dev/input/" // Path to the linux input events
|
||||
|
||||
// So actually the biggest key is KEY_CNT but we only really map the keys up to
|
||||
// KEY_ALS_TOGGLE
|
||||
// Actually biggest key is KEY_CNT but we only really map the keys up to KEY_ALS_TOGGLE
|
||||
#define KEYMAP_SIZE KEY_ALS_TOGGLE
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
typedef struct {
|
||||
// Display data
|
||||
int fd; // File descriptor for /dev/dri/...
|
||||
|
|
@ -124,11 +130,23 @@ typedef struct {
|
|||
|
||||
// Gamepad data
|
||||
int gamepadStreamFd[MAX_GAMEPADS]; // Gamepad device file descriptor
|
||||
int gamepadAbsAxisRange[MAX_GAMEPADS][MAX_GAMEPAD_AXIS][2]; // [0] = min, [1] = range value of the axis
|
||||
int gamepadAbsAxisRange[MAX_GAMEPADS][MAX_GAMEPAD_AXES][2]; // [0] = min, [1] = range value of the axes
|
||||
int gamepadAbsAxisMap[MAX_GAMEPADS][ABS_CNT]; // Maps the axes gamepads from the evdev api to a sequential one
|
||||
int gamepadCount; // The number of gamepads registered
|
||||
} PlatformData;
|
||||
|
||||
#if defined(SUPPORT_DRM_CACHE)
|
||||
typedef struct {
|
||||
struct gbm_bo *bo; // Graphics buffer object
|
||||
uint32_t fbId; // DRM framebuffer ID
|
||||
} FramebufferCache;
|
||||
|
||||
static FramebufferCache fbCache[MAX_DRM_CACHED_BUFFERS] = { 0 };
|
||||
static volatile int fbCacheCount = 0;
|
||||
static volatile bool pendingFlip = false;
|
||||
static bool crtcSet = false;
|
||||
#endif // SUPPORT_DRM_CACHE
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -551,6 +569,212 @@ void DisableCursor(void)
|
|||
CORE.Input.Mouse.cursorHidden = true;
|
||||
}
|
||||
|
||||
#if defined(SUPPORT_DRM_CACHE)
|
||||
|
||||
// Destroy cached framebuffer callback, set by gbm_bo_set_user_data()
|
||||
static void DestroyFrameBufferCallback(struct gbm_bo *bo, void *data)
|
||||
{
|
||||
uint32_t fbId = (uintptr_t)data;
|
||||
|
||||
// Remove from cache
|
||||
for (int i = 0; i < fbCacheCount; i++)
|
||||
{
|
||||
if (fbCache[i].bo == bo)
|
||||
{
|
||||
TRACELOG(LOG_INFO, "DISPLAY: DRM: Framebuffer removed [%u]", (uintptr_t)fbId);
|
||||
drmModeRmFB(platform.fd, fbCache[i].fbId); // Release DRM FB
|
||||
|
||||
// Shift remaining entries
|
||||
for (int j = i; j < fbCacheCount - 1; j++) fbCache[j] = fbCache[j + 1];
|
||||
|
||||
fbCacheCount--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create or retrieve cached DRM FB for BO
|
||||
static uint32_t GetOrCreateFbForBo(struct gbm_bo *bo)
|
||||
{
|
||||
// Try to find existing cache entry
|
||||
for (int i = 0; i < fbCacheCount; i++)
|
||||
{
|
||||
if (fbCache[i].bo == bo) return fbCache[i].fbId;
|
||||
}
|
||||
|
||||
// Create new entry if cache not full
|
||||
if (fbCacheCount >= MAX_DRM_CACHED_BUFFERS) return 0; // FB cache full
|
||||
|
||||
uint32_t handle = gbm_bo_get_handle(bo).u32;
|
||||
uint32_t stride = gbm_bo_get_stride(bo);
|
||||
uint32_t width = gbm_bo_get_width(bo);
|
||||
uint32_t height = gbm_bo_get_height(bo);
|
||||
|
||||
uint32_t fbId = 0;
|
||||
if (drmModeAddFB(platform.fd, width, height, 24, 32, stride, handle, &fbId)) return 0;
|
||||
|
||||
// Store in cache
|
||||
fbCache[fbCacheCount] = (FramebufferCache){ .bo = bo, .fbId = fbId };
|
||||
fbCacheCount++;
|
||||
|
||||
// Set destroy callback to auto-cleanup
|
||||
gbm_bo_set_user_data(bo, (void *)(uintptr_t)fbId, DestroyFrameBufferCallback);
|
||||
|
||||
TRACELOG(LOG_INFO, "DISPLAY: DRM: Added new buffer object [%u]" , (uintptr_t)fbId);
|
||||
|
||||
return fbId;
|
||||
}
|
||||
|
||||
// Renders a blank frame to allocate initial buffers
|
||||
// TODO: WARNING: Platform layers do not include OpenGL code!
|
||||
void RenderBlankFrame()
|
||||
{
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
eglSwapBuffers(platform.device, platform.surface);
|
||||
glFinish(); // Ensure the buffer is processed
|
||||
}
|
||||
|
||||
// Initialize with first buffer only
|
||||
int InitSwapScreenBuffer()
|
||||
{
|
||||
if (!platform.gbmSurface || (platform.fd < 0))
|
||||
{
|
||||
TRACELOG(LOG_ERROR, "DISPLAY: DRM: Swap buffers can not be initialized");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Render a blank frame to allocate buffers
|
||||
RenderBlankFrame();
|
||||
|
||||
// Get first buffer
|
||||
struct gbm_bo *bo = gbm_surface_lock_front_buffer(platform.gbmSurface);
|
||||
if (!bo)
|
||||
{
|
||||
TRACELOG(LOG_ERROR, "DISPLAY: DRM: Failed to lock initial swap buffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create FB for first buffer
|
||||
uint32_t fbId = GetOrCreateFbForBo(bo);
|
||||
if (!fbId)
|
||||
{
|
||||
gbm_surface_release_buffer(platform.gbmSurface, bo);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initial CRTC setup
|
||||
if (drmModeSetCrtc(platform.fd, platform.crtc->crtc_id, fbId, 0, 0, &platform.connector->connector_id, 1, &platform.connector->modes[platform.modeIndex]))
|
||||
{
|
||||
TRACELOG(LOG_ERROR, "DISPLAY: DRM: Failed to initialize CRTC setup. ERROR: %s", strerror(errno));
|
||||
gbm_surface_release_buffer(platform.gbmSurface, bo);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Keep first buffer locked until flipped
|
||||
platform.prevBO = bo;
|
||||
crtcSet = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Static page flip handler
|
||||
// NOTE: Called once the drmModePageFlip() finished from the drmHandleEvent() context
|
||||
static void PageFlipHandler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data)
|
||||
{
|
||||
// Unused inputs
|
||||
(void)fd;
|
||||
(void)frame;
|
||||
(void)sec;
|
||||
(void)usec;
|
||||
|
||||
pendingFlip = false;
|
||||
struct gbm_bo *boToRelease = (struct gbm_bo *)data;
|
||||
|
||||
// Buffers are released after the flip completes (via page_flip_handler), ensuring they're no longer in use
|
||||
// Prevents the GPU from writing to a buffer being scanned out
|
||||
if (boToRelease) gbm_surface_release_buffer(platform.gbmSurface, boToRelease);
|
||||
}
|
||||
|
||||
// Swap implementation with proper caching
|
||||
void SwapScreenBuffer()
|
||||
{
|
||||
if (!crtcSet || !platform.gbmSurface) return;
|
||||
|
||||
static int loopCnt = 0;
|
||||
static int errCnt[5] = {0};
|
||||
loopCnt++;
|
||||
|
||||
// Call this only, if pendingFlip is not set
|
||||
eglSwapBuffers(platform.device, platform.surface);
|
||||
|
||||
// Process pending events non-blocking
|
||||
drmEventContext evctx = {
|
||||
.version = DRM_EVENT_CONTEXT_VERSION,
|
||||
.page_flip_handler = PageFlipHandler
|
||||
};
|
||||
|
||||
struct pollfd pfd = { .fd = platform.fd, .events = POLLIN };
|
||||
|
||||
// Polling for event for 0ms
|
||||
while (poll(&pfd, 1, 0) > 0) drmHandleEvent(platform.fd, &evctx);
|
||||
|
||||
// Skip if previous flip pending
|
||||
if (pendingFlip)
|
||||
{
|
||||
errCnt[0]++; // Skip frame: flip pending
|
||||
return;
|
||||
}
|
||||
|
||||
// Get new front buffer
|
||||
struct gbm_bo *nextBO = gbm_surface_lock_front_buffer(platform.gbmSurface);
|
||||
if (!nextBO) // Failed to lock front buffer
|
||||
{
|
||||
errCnt[1]++;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get FB ID (creates new one if needed)
|
||||
uint32_t fbId = GetOrCreateFbForBo(nextBO);
|
||||
if (!fbId)
|
||||
{
|
||||
gbm_surface_release_buffer(platform.gbmSurface, nextBO);
|
||||
errCnt[2]++;
|
||||
return;
|
||||
}
|
||||
|
||||
// Attempt page flip
|
||||
// NOTE: rmModePageFlip() schedules a buffer-flip for the next vblank and then notifies us about it
|
||||
// It takes a CRTC-id, fb-id and an arbitrary data-pointer and then schedules the page-flip
|
||||
// This is fully asynchronous and when the page-flip happens, the DRM-fd will become readable and we can call drmHandleEvent()
|
||||
// This will read all vblank/page-flip events and call our modeset_page_flip_event() callback with the data-pointer that we passed to drmModePageFlip()
|
||||
// We simply call modeset_draw_dev() then so the next frame is rendered... returns immediately
|
||||
if (drmModePageFlip(platform.fd, platform.crtc->crtc_id, fbId, DRM_MODE_PAGE_FLIP_EVENT, platform.prevBO))
|
||||
{
|
||||
if (errno == EBUSY) errCnt[3]++; // Display busy - skip flip
|
||||
else errCnt[4]++; // Page flip failed
|
||||
|
||||
gbm_surface_release_buffer(platform.gbmSurface, nextBO);
|
||||
return;
|
||||
}
|
||||
|
||||
// Success: update state
|
||||
pendingFlip = true;
|
||||
platform.prevBO = nextBO;
|
||||
|
||||
/*
|
||||
// Some benchmarking code
|
||||
if (loopCnt >= 600)
|
||||
{
|
||||
TRACELOG(LOG_INFO, "DRM: Error counters: %d, %d, %d, %d, %d, %d", errCnt[0], errCnt[1], errCnt[2], errCnt[3], errCnt[4], loopCnt);
|
||||
for (int i = 0; i < 5; i++) errCnt[i] = 0;
|
||||
loopCnt = 0;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#else // !SUPPORT_DRM_CACHE
|
||||
|
||||
// Swap back buffer with front buffer (screen drawing)
|
||||
void SwapScreenBuffer(void)
|
||||
{
|
||||
|
|
@ -580,6 +804,7 @@ void SwapScreenBuffer(void)
|
|||
|
||||
platform.prevBO = bo;
|
||||
}
|
||||
#endif // SUPPORT_DRM_CACHE
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Misc
|
||||
|
|
@ -599,9 +824,9 @@ double GetTime(void)
|
|||
}
|
||||
|
||||
// Open URL with default system browser (if available)
|
||||
// NOTE: This function is only safe to use if you control the URL given.
|
||||
// A user could craft a malicious string performing another action.
|
||||
// Only call this function yourself not with user input or make sure to check the string yourself.
|
||||
// NOTE: This function is only safe to use if you control the URL given
|
||||
// A user could craft a malicious string performing another action
|
||||
// Only call this function yourself not with user input or make sure to check the string yourself
|
||||
// Ref: https://github.com/raysan5/raylib/issues/686
|
||||
void OpenURL(const char *url)
|
||||
{
|
||||
|
|
@ -638,7 +863,7 @@ void SetMouseCursor(int cursor)
|
|||
TRACELOG(LOG_WARNING, "SetMouseCursor() not implemented on target platform");
|
||||
}
|
||||
|
||||
// Get physical key name.
|
||||
// Get physical key name
|
||||
const char *GetKeyName(int key)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "GetKeyName() not implemented on target platform");
|
||||
|
|
@ -672,7 +897,7 @@ void PollInputEvents(void)
|
|||
PollKeyboardEvents();
|
||||
|
||||
#if defined(SUPPORT_SSH_KEYBOARD_RPI)
|
||||
// NOTE: Keyboard reading could be done using input_event(s) or just read from stdin, both methods are used here.
|
||||
// NOTE: Keyboard reading could be done using input_event(s) or just read from stdin, both methods are used here
|
||||
// stdin reading is still used for legacy purposes, it allows keyboard input trough SSH console
|
||||
if (!platform.eventKeyboardMode) ProcessKeyboard();
|
||||
#endif
|
||||
|
|
@ -778,8 +1003,8 @@ int InitPlatform(void)
|
|||
drmModeConnector *con = drmModeGetConnector(platform.fd, res->connectors[i]);
|
||||
TRACELOG(LOG_TRACE, "DISPLAY: Connector modes detected: %i", con->count_modes);
|
||||
|
||||
// In certain cases the status of the conneciton is reported as UKNOWN, but it is still connected.
|
||||
// This might be a hardware or software limitation like on Raspberry Pi Zero with composite output.
|
||||
// In certain cases the status of the conneciton is reported as UKNOWN, but it is still connected
|
||||
// This might be a hardware or software limitation like on Raspberry Pi Zero with composite output
|
||||
if (((con->connection == DRM_MODE_CONNECTED) || (con->connection == DRM_MODE_UNKNOWNCONNECTION)) && (con->encoder_id))
|
||||
{
|
||||
TRACELOG(LOG_TRACE, "DISPLAY: DRM mode connected");
|
||||
|
|
@ -935,7 +1160,7 @@ int InitPlatform(void)
|
|||
// Initialize the EGL device connection
|
||||
if (eglInitialize(platform.device, NULL, NULL) == EGL_FALSE)
|
||||
{
|
||||
// If all of the calls to eglInitialize returned EGL_FALSE then an error has occurred.
|
||||
// If all of the calls to eglInitialize returned EGL_FALSE then an error has occurred
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: Failed to initialize EGL device");
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -948,7 +1173,7 @@ int InitPlatform(void)
|
|||
|
||||
TRACELOG(LOG_TRACE, "DISPLAY: EGL configs available: %d", numConfigs);
|
||||
|
||||
EGLConfig *configs = RL_CALLOC(numConfigs, sizeof(*configs));
|
||||
EGLConfig *configs = (EGLConfig *)RL_CALLOC(numConfigs, sizeof(*configs));
|
||||
if (!configs)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: Failed to get memory for EGL configs");
|
||||
|
|
@ -1083,9 +1308,21 @@ int InitPlatform(void)
|
|||
CORE.Storage.basePath = GetWorkingDirectory();
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#if defined(SUPPORT_DRM_CACHE)
|
||||
if (InitSwapScreenBuffer() == 0)
|
||||
{
|
||||
TRACELOG(LOG_INFO, "PLATFORM: DRM: Initialized successfully");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACELOG(LOG_INFO, "PLATFORM: DRM: Initialized failed");
|
||||
return -1;
|
||||
}
|
||||
#else // !SUPPORT_DRM_CACHE
|
||||
TRACELOG(LOG_INFO, "PLATFORM: DRM: Initialized successfully");
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Close platform
|
||||
|
|
@ -1319,7 +1556,7 @@ static void ProcessKeyboard(void)
|
|||
{
|
||||
CORE.Input.Keyboard.currentKeyState[259] = 1;
|
||||
|
||||
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = 257; // Add keys pressed into queue
|
||||
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = 259; // Add keys pressed into queue
|
||||
CORE.Input.Keyboard.keyPressedQueueCount++;
|
||||
}
|
||||
else
|
||||
|
|
@ -1374,7 +1611,7 @@ static void InitEvdevInput(void)
|
|||
if ((strncmp("event", entity->d_name, strlen("event")) == 0) || // Search for devices named "event*"
|
||||
(strncmp("mouse", entity->d_name, strlen("mouse")) == 0)) // Search for devices named "mouse*"
|
||||
{
|
||||
sprintf(path, "%s%s", DEFAULT_EVDEV_PATH, entity->d_name);
|
||||
snprintf(path, MAX_FILEPATH_LENGTH, "%s%s", DEFAULT_EVDEV_PATH, entity->d_name);
|
||||
ConfigureEvdevDevice(path); // Configure the device if appropriate
|
||||
}
|
||||
}
|
||||
|
|
@ -1407,7 +1644,7 @@ static void ConfigureEvdevDevice(char *device)
|
|||
return;
|
||||
}
|
||||
|
||||
// At this point we have a connection to the device, but we don't yet know what the device is.
|
||||
// At this point we have a connection to the device, but we don't yet know what the device is
|
||||
// It could be many things, even as simple as a power button...
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -1460,7 +1697,7 @@ static void ConfigureEvdevDevice(char *device)
|
|||
// matter if we support them
|
||||
else if (hasAbsXY && TEST_BIT(keyBits, BTN_MOUSE)) isMouse = true;
|
||||
|
||||
// If any of the common joystick axis is present, we assume it's a gamepad
|
||||
// If any of the common joystick axes are present, we assume it's a gamepad
|
||||
else
|
||||
{
|
||||
for (int axis = (hasAbsXY? ABS_Z : ABS_X); axis < ABS_PRESSURE; axis++)
|
||||
|
|
@ -1546,7 +1783,7 @@ static void ConfigureEvdevDevice(char *device)
|
|||
if (absAxisCount > 0)
|
||||
{
|
||||
// TODO / NOTE
|
||||
// So gamepad axis (as in the actual linux joydev.c) are just simply enumerated
|
||||
// So gamepad axes (as in the actual linux joydev.c) are just simply enumerated
|
||||
// and (at least for some input drivers like xpat) it's convention to use
|
||||
// ABS_X, ABX_Y for one joystick ABS_RX, ABS_RY for the other and the Z axes for the
|
||||
// shoulder buttons
|
||||
|
|
@ -1681,7 +1918,7 @@ static void PollGamepadEvents(void)
|
|||
|
||||
TRACELOG(LOG_DEBUG, "INPUT: Gamepad %2i: Axis: %2i Value: %i", i, axisRaylib, event.value);
|
||||
|
||||
if (axisRaylib < MAX_GAMEPAD_AXIS)
|
||||
if (axisRaylib < MAX_GAMEPAD_AXES)
|
||||
{
|
||||
int min = platform.gamepadAbsAxisRange[i][event.code][0];
|
||||
int range = platform.gamepadAbsAxisRange[i][event.code][1];
|
||||
|
|
|
|||
|
|
@ -111,23 +111,23 @@ int InitPlatform(void); // Initialize platform (graphics, inputs and mo
|
|||
void ClosePlatform(void); // Close platform
|
||||
|
||||
// Error callback event
|
||||
static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error
|
||||
static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error
|
||||
|
||||
// Window callbacks events
|
||||
static void WindowSizeCallback(GLFWwindow *window, int width, int height); // GLFW3 WindowSize Callback, runs when window is resized
|
||||
static void WindowIconifyCallback(GLFWwindow *window, int iconified); // GLFW3 WindowIconify Callback, runs when window is minimized/restored
|
||||
static void WindowSizeCallback(GLFWwindow *window, int width, int height); // GLFW3 Window Size Callback, runs when window is resized
|
||||
static void WindowIconifyCallback(GLFWwindow *window, int iconified); // GLFW3 Window Iconify Callback, runs when window is minimized/restored
|
||||
//static void WindowMaximizeCallback(GLFWwindow *window, int maximized); // GLFW3 Window Maximize Callback, runs when window is maximized
|
||||
static void WindowFocusCallback(GLFWwindow *window, int focused); // GLFW3 WindowFocus Callback, runs when window get/lose focus
|
||||
static void WindowFocusCallback(GLFWwindow *window, int focused); // GLFW3 Window Focus Callback, runs when window get/lose focus
|
||||
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); // GLFW3 Window Drop Callback, runs when drop files into window
|
||||
static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley); // GLFW3 Window Content Scale Callback, runs when window changes scale
|
||||
|
||||
// Input callbacks events
|
||||
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
|
||||
static void CharCallback(GLFWwindow *window, unsigned int key); // GLFW3 Char Key Callback, runs on key pressed (get char value)
|
||||
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
|
||||
static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); // GLFW3 Cursor Position Callback, runs on mouse move
|
||||
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Srolling Callback, runs on mouse wheel
|
||||
static void CursorEnterCallback(GLFWwindow *window, int enter); // GLFW3 Cursor Enter Callback, cursor enters client area
|
||||
static void CharCallback(GLFWwindow *window, unsigned int key); // GLFW3 Char Key Callback, runs on key pressed (get char value)
|
||||
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
|
||||
static void MouseMoveCallback(GLFWwindow *window, double x, double y); // GLFW3 Mouse Move Callback, runs on mouse move
|
||||
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Mouse Scrolling Callback, runs on mouse wheel
|
||||
static void MouseEnterCallback(GLFWwindow *window, int enter); // GLFW3 Mouse Enter Callback, cursor enters client area
|
||||
|
||||
// Emscripten window callback events
|
||||
static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData);
|
||||
|
|
@ -137,6 +137,7 @@ static EM_BOOL EmscriptenFocusCallback(int eventType, const EmscriptenFocusEvent
|
|||
static EM_BOOL EmscriptenVisibilityChangeCallback(int eventType, const EmscriptenVisibilityChangeEvent *visibilityChangeEvent, void *userData);
|
||||
|
||||
// Emscripten input callback events
|
||||
//static EM_BOOL EmscriptenKeyboardCallback(int eventType, const EmscriptenKeyboardEvent *keyboardEvent, void *userData);
|
||||
static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
|
||||
static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
|
||||
static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData);
|
||||
|
|
@ -163,13 +164,13 @@ bool WindowShouldClose(void)
|
|||
// REF: https://emscripten.org/docs/porting/asyncify.html
|
||||
|
||||
// WindowShouldClose() is not called on a web-ready raylib application if using emscripten_set_main_loop()
|
||||
// and encapsulating one frame execution on a UpdateDrawFrame() function,
|
||||
// and encapsulating one frame execution on a UpdateDrawFrame() function,
|
||||
// allowing the browser to manage execution asynchronously
|
||||
|
||||
// Optionally we can manage the time we give-control-back-to-browser if required,
|
||||
// but it seems below line could generate stuttering on some browsers
|
||||
emscripten_sleep(12);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1081,7 +1082,7 @@ void PollInputEvents(void)
|
|||
}
|
||||
|
||||
// Register axis data for every connected gamepad
|
||||
for (int j = 0; (j < gamepadState.numAxes) && (j < MAX_GAMEPAD_AXIS); j++)
|
||||
for (int j = 0; (j < gamepadState.numAxes) && (j < MAX_GAMEPAD_AXES); j++)
|
||||
{
|
||||
CORE.Input.Gamepad.axisState[i][j] = gamepadState.axis[j];
|
||||
}
|
||||
|
|
@ -1300,23 +1301,24 @@ int InitPlatform(void)
|
|||
emscripten_set_window_title((CORE.Window.title != 0)? CORE.Window.title : " ");
|
||||
|
||||
// Set window callback events
|
||||
glfwSetWindowSizeCallback(platform.handle, WindowSizeCallback); // NOTE: Resizing not allowed by default!
|
||||
glfwSetWindowSizeCallback(platform.handle, WindowSizeCallback);
|
||||
glfwSetWindowIconifyCallback(platform.handle, WindowIconifyCallback);
|
||||
glfwSetWindowFocusCallback(platform.handle, WindowFocusCallback);
|
||||
glfwSetDropCallback(platform.handle, WindowDropCallback);
|
||||
|
||||
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
||||
{
|
||||
glfwSetWindowContentScaleCallback(platform.handle, WindowContentScaleCallback);
|
||||
// Window content (framebuffer) scale callback
|
||||
glfwSetWindowContentScaleCallback(platform.handle, WindowContentScaleCallback);
|
||||
}
|
||||
|
||||
// Set input callback events
|
||||
glfwSetKeyCallback(platform.handle, KeyCallback);
|
||||
glfwSetCharCallback(platform.handle, CharCallback);
|
||||
glfwSetMouseButtonCallback(platform.handle, MouseButtonCallback);
|
||||
glfwSetCursorPosCallback(platform.handle, MouseCursorPosCallback); // Track mouse position changes
|
||||
glfwSetCursorPosCallback(platform.handle, MouseMoveCallback);
|
||||
glfwSetScrollCallback(platform.handle, MouseScrollCallback);
|
||||
glfwSetCursorEnterCallback(platform.handle, CursorEnterCallback);
|
||||
glfwSetCursorEnterCallback(platform.handle, MouseEnterCallback);
|
||||
|
||||
glfwMakeContextCurrent(platform.handle);
|
||||
result = true; // TODO: WARNING: glfwGetError(NULL); symbol can not be found in Web
|
||||
|
|
@ -1356,48 +1358,36 @@ int InitPlatform(void)
|
|||
rlLoadExtensions(glfwGetProcAddress);
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// Initialize input events callbacks
|
||||
// Initialize events callbacks
|
||||
//----------------------------------------------------------------------------
|
||||
// Setup callback functions for the DOM events
|
||||
// Setup window events callbacks
|
||||
emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenFullscreenChangeCallback);
|
||||
|
||||
emscripten_set_blur_callback(GetCanvasId(), platform.handle, 1, EmscriptenFocusCallback);
|
||||
emscripten_set_focus_callback(GetCanvasId(), platform.handle, 1, EmscriptenFocusCallback);
|
||||
emscripten_set_visibilitychange_callback(NULL, 1, EmscriptenVisibilityChangeCallback);
|
||||
|
||||
// WARNING: Below resize code was breaking fullscreen mode for sample games and examples, it needs review
|
||||
// Check fullscreen change events(note this is done on the window since most browsers don't support this on #canvas)
|
||||
// emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback);
|
||||
// Check Resize event (note this is done on the window since most browsers don't support this on #canvas)
|
||||
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback);
|
||||
|
||||
// Trigger this once to get initial window sizing
|
||||
// Trigger resize callback to force initial size
|
||||
EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL);
|
||||
|
||||
// Support keyboard events -> Not used, GLFW.JS takes care of that
|
||||
// emscripten_set_keypress_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback);
|
||||
// emscripten_set_keydown_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback);
|
||||
|
||||
// Support mouse events
|
||||
// Setup input events
|
||||
// NOTE: Keyboard callbacks only used to consume some events, libglfw.js takes care of the actual input
|
||||
//emscripten_set_keypress_callback(GetCanvasId(), NULL, 1, EmscriptenKeyboardCallback); // WRNING: Breaks input
|
||||
//emscripten_set_keydown_callback(GetCanvasId(), NULL, 1, EmscriptenKeyboardCallback);
|
||||
emscripten_set_click_callback(GetCanvasId(), NULL, 1, EmscriptenMouseCallback);
|
||||
emscripten_set_pointerlockchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenPointerlockCallback);
|
||||
|
||||
// Following the mouse delta when the mouse is locked
|
||||
emscripten_set_mousemove_callback(GetCanvasId(), NULL, 1, EmscriptenMouseMoveCallback);
|
||||
|
||||
// Support touch events
|
||||
emscripten_set_touchstart_callback(GetCanvasId(), NULL, 1, EmscriptenTouchCallback);
|
||||
emscripten_set_touchend_callback(GetCanvasId(), NULL, 1, EmscriptenTouchCallback);
|
||||
emscripten_set_touchmove_callback(GetCanvasId(), NULL, 1, EmscriptenTouchCallback);
|
||||
emscripten_set_touchcancel_callback(GetCanvasId(), NULL, 1, EmscriptenTouchCallback);
|
||||
|
||||
// Support gamepad events (not provided by GLFW3 on emscripten)
|
||||
emscripten_set_gamepadconnected_callback(NULL, 1, EmscriptenGamepadCallback);
|
||||
emscripten_set_gamepaddisconnected_callback(NULL, 1, EmscriptenGamepadCallback);
|
||||
|
||||
// Support focus events
|
||||
emscripten_set_blur_callback(GetCanvasId(), platform.handle, 1, EmscriptenFocusCallback);
|
||||
emscripten_set_focus_callback(GetCanvasId(), platform.handle, 1, EmscriptenFocusCallback);
|
||||
|
||||
// Support visibility events
|
||||
emscripten_set_visibilitychange_callback(NULL, 1, EmscriptenVisibilityChangeCallback);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// Initialize timing system
|
||||
|
|
@ -1422,14 +1412,15 @@ void ClosePlatform(void)
|
|||
glfwTerminate();
|
||||
}
|
||||
|
||||
// GLFW3 Error Callback, runs on GLFW3 error
|
||||
// GLFW3 callback functions, called on GLFW registered events
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
// GLFW3: Called on errors
|
||||
static void ErrorCallback(int error, const char *description)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "GLFW: Error: %i Description: %s", error, description);
|
||||
}
|
||||
|
||||
// GLFW3 WindowSize Callback, runs when window is resizedLastFrame
|
||||
// NOTE: Window resizing not allowed by default
|
||||
// GLFW3: Called on window resizing, runs when window is resizedLastFrame
|
||||
static void WindowSizeCallback(GLFWwindow *window, int width, int height)
|
||||
{
|
||||
// Reset viewport and projection matrix for new size
|
||||
|
|
@ -1458,34 +1449,27 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height)
|
|||
// NOTE: Postprocessing texture is not scaled to new size
|
||||
}
|
||||
|
||||
// GLFW3: Called on window content (framebuffer) scaled
|
||||
static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley)
|
||||
{
|
||||
CORE.Window.screenScale = MatrixScale(scalex, scaley, 1.0f);
|
||||
}
|
||||
|
||||
// GLFW3 WindowIconify Callback, runs when window is minimized/restored
|
||||
// GLFW3: Called on windows minimized/restored
|
||||
static void WindowIconifyCallback(GLFWwindow *window, int iconified)
|
||||
{
|
||||
if (iconified) CORE.Window.flags |= FLAG_WINDOW_MINIMIZED; // The window was iconified
|
||||
else CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; // The window was restored
|
||||
}
|
||||
|
||||
/*
|
||||
// GLFW3 Window Maximize Callback, runs when window is maximized
|
||||
static void WindowMaximizeCallback(GLFWwindow *window, int maximized)
|
||||
{
|
||||
// TODO.
|
||||
}
|
||||
*/
|
||||
|
||||
// GLFW3 WindowFocus Callback, runs when window get/lose focus
|
||||
// GLFW3: Called on windows get/lose focus
|
||||
static void WindowFocusCallback(GLFWwindow *window, int focused)
|
||||
{
|
||||
if (focused) CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; // The window was focused
|
||||
else CORE.Window.flags |= FLAG_WINDOW_UNFOCUSED; // The window lost focus
|
||||
}
|
||||
|
||||
// GLFW3 Window Drop Callback, runs when drop files into window
|
||||
// GLFW3: Called on file-drop over the window
|
||||
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths)
|
||||
{
|
||||
if (count > 0)
|
||||
|
|
@ -1513,7 +1497,7 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
|
|||
}
|
||||
}
|
||||
|
||||
// GLFW3 Keyboard Callback, runs on key pressed
|
||||
// GLFW3: Called on keyboard interaction
|
||||
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key < 0) return; // Security check, macOS fn key generates -1
|
||||
|
|
@ -1536,7 +1520,7 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i
|
|||
if ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(platform.handle, GLFW_TRUE);
|
||||
}
|
||||
|
||||
// GLFW3 Char Key Callback, runs on key down (gets equivalent unicode char value)
|
||||
// GLFW3: Called on key down interaction, gets equivalent unicode char value for the key
|
||||
static void CharCallback(GLFWwindow *window, unsigned int key)
|
||||
{
|
||||
//TRACELOG(LOG_DEBUG, "Char Callback: KEY:%i(%c)", key, key);
|
||||
|
|
@ -1555,7 +1539,7 @@ static void CharCallback(GLFWwindow *window, unsigned int key)
|
|||
}
|
||||
}
|
||||
|
||||
// GLFW3 Mouse Button Callback, runs on mouse button pressed
|
||||
// GLFW3: Called on mouse button interaction
|
||||
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
|
||||
{
|
||||
// WARNING: GLFW could only return GLFW_PRESS (1) or GLFW_RELEASE (0) for now,
|
||||
|
|
@ -1571,7 +1555,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
|
|||
if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
|
||||
else if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) gestureEvent.touchAction = TOUCH_ACTION_UP;
|
||||
|
||||
// NOTE: TOUCH_ACTION_MOVE event is registered in MouseCursorPosCallback()
|
||||
// NOTE: TOUCH_ACTION_MOVE event is registered in MouseMoveCallback()
|
||||
|
||||
// Assign a pointer ID
|
||||
gestureEvent.pointId[0] = 0;
|
||||
|
|
@ -1593,8 +1577,8 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
|
|||
#endif
|
||||
}
|
||||
|
||||
// GLFW3 Cursor Position Callback, runs on mouse move
|
||||
static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
|
||||
// GLFW3: Called on mouse move
|
||||
static void MouseMoveCallback(GLFWwindow *window, double x, double y)
|
||||
{
|
||||
// If the pointer is not locked, follow the position
|
||||
if (!CORE.Input.Mouse.cursorHidden)
|
||||
|
|
@ -1628,34 +1612,28 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
|
|||
#endif
|
||||
}
|
||||
|
||||
static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
|
||||
{
|
||||
// To emulate the GLFW_RAW_MOUSE_MOTION property.
|
||||
if (CORE.Input.Mouse.cursorHidden)
|
||||
{
|
||||
CORE.Input.Mouse.previousPosition.x = lockedMousePos.x - mouseEvent->movementX;
|
||||
CORE.Input.Mouse.previousPosition.y = lockedMousePos.y - mouseEvent->movementY;
|
||||
}
|
||||
|
||||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
|
||||
// GLFW3 Scrolling Callback, runs on mouse wheel
|
||||
// GLFW3: Called on mouse wheel scrolling
|
||||
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset)
|
||||
{
|
||||
CORE.Input.Mouse.currentWheelMove = (Vector2){ (float)xoffset, (float)yoffset };
|
||||
}
|
||||
|
||||
// GLFW3 CursorEnter Callback, when cursor enters the window
|
||||
static void CursorEnterCallback(GLFWwindow *window, int enter)
|
||||
// GLFW3: Called on mouse entering the window
|
||||
static void MouseEnterCallback(GLFWwindow *window, int enter)
|
||||
{
|
||||
if (enter) CORE.Input.Mouse.cursorOnScreen = true;
|
||||
else CORE.Input.Mouse.cursorOnScreen = false;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Register fullscreen change events
|
||||
static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData)
|
||||
// Emscripten callback functions, called on specific browser events
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
// Emscripten: Called on key events
|
||||
static EM_BOOL EmscriptenKeyboardCallback(int eventType, const EmscriptenKeyboardEvent *keyboardEvent, void *userData)
|
||||
{
|
||||
// WARNING: Keyboard inputs already processed through GLFW callback
|
||||
|
||||
// NOTE: 1. Reset the fullscreen flags if the user left fullscreen manually by pressing the Escape key
|
||||
// 2. Which is a necessary safeguard because that case will bypass the toggles CORE.Window.flags resets
|
||||
if (platform.ourFullscreen) platform.ourFullscreen = false;
|
||||
|
|
@ -1670,23 +1648,21 @@ static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const Emscripte
|
|||
}
|
||||
}
|
||||
|
||||
// trigger resize event after a brief pause to ensure the canvas exists to resize
|
||||
// Trigger resize event after a brief pause to ensure the canvas exists to resize
|
||||
EM_ASM({ setTimeout(function() { window.dispatchEvent(new Event("resize")); }, 50); });
|
||||
|
||||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
*/
|
||||
|
||||
// Register window resize event
|
||||
// static EM_BOOL EmscriptenWindowResizedCallback(int eventType, const EmscriptenUiEvent *event, void *userData)
|
||||
// {
|
||||
// // TODO: Implement EmscriptenWindowResizedCallback()?
|
||||
|
||||
// return 1; // The event was consumed by the callback handler
|
||||
// }
|
||||
|
||||
// Register DOM element resize event
|
||||
static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData)
|
||||
// Emscripten: Called on mouse input events
|
||||
static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
|
||||
{
|
||||
// NOTE: Current code solves mouse position problems with the 3 possible approaches to canvas scaling
|
||||
// 1. Canvas not scaled, framebuffer size is fixed
|
||||
// 2. Canvas is scaled to 100% browser size, framebuffer size is fixed
|
||||
// 3. Canvas is resized to browser size, framebuffer is resized
|
||||
|
||||
// Don't resize non-resizeable windows
|
||||
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) == 0) return 1;
|
||||
|
||||
|
|
@ -1703,7 +1679,7 @@ static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *
|
|||
|
||||
emscripten_set_canvas_element_size(GetCanvasId(), width, height);
|
||||
|
||||
glfwSetWindowSize(platform.handle, width, height); // inform glfw of the new size
|
||||
glfwSetWindowSize(platform.handle, width, height); // Inform glfw of the new size
|
||||
|
||||
SetupViewport(width, height); // Reset viewport and projection matrix for new size
|
||||
|
||||
|
|
@ -1717,20 +1693,25 @@ static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *
|
|||
CORE.Window.screen.width = width;
|
||||
CORE.Window.screen.height = height;
|
||||
|
||||
// NOTE: Postprocessing texture is not scaled to new size
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Register mouse input events
|
||||
static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
|
||||
{
|
||||
// This is only for registering mouse click events with emscripten and doesn't need to do anything
|
||||
// WARNING: RenderTextures are not scaled to new size
|
||||
|
||||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
|
||||
// Register pointer lock events
|
||||
// Emscripten: Called on mouse move events
|
||||
static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
|
||||
{
|
||||
// To emulate the GLFW_RAW_MOUSE_MOTION property.
|
||||
if (CORE.Input.Mouse.cursorHidden)
|
||||
{
|
||||
CORE.Input.Mouse.previousPosition.x = lockedMousePos.x - mouseEvent->movementX;
|
||||
CORE.Input.Mouse.previousPosition.y = lockedMousePos.y - mouseEvent->movementY;
|
||||
}
|
||||
|
||||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
|
||||
// Emscripten: Called on pointer lock events
|
||||
static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData)
|
||||
{
|
||||
CORE.Input.Mouse.cursorHidden = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0);
|
||||
|
|
@ -1744,7 +1725,7 @@ static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPoin
|
|||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
|
||||
// Register connected/disconnected gamepads events
|
||||
// Emscripten: Called on connect/disconnect gamepads events
|
||||
static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
|
||||
{
|
||||
/*
|
||||
|
|
@ -1759,33 +1740,14 @@ static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadE
|
|||
if (gamepadEvent->connected && (gamepadEvent->index < MAX_GAMEPADS))
|
||||
{
|
||||
CORE.Input.Gamepad.ready[gamepadEvent->index] = true;
|
||||
sprintf(CORE.Input.Gamepad.name[gamepadEvent->index], "%s", gamepadEvent->id);
|
||||
snprintf(CORE.Input.Gamepad.name[gamepadEvent->index], MAX_GAMEPAD_NAME_LENGTH, "%s", gamepadEvent->id);
|
||||
}
|
||||
else CORE.Input.Gamepad.ready[gamepadEvent->index] = false;
|
||||
|
||||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
|
||||
static EM_BOOL EmscriptenFocusCallback(int eventType, const EmscriptenFocusEvent *focusEvent, void *userData)
|
||||
{
|
||||
EM_BOOL consumed = 1;
|
||||
switch (eventType)
|
||||
{
|
||||
case EMSCRIPTEN_EVENT_BLUR: WindowFocusCallback(userData, 0); break;
|
||||
case EMSCRIPTEN_EVENT_FOCUS: WindowFocusCallback(userData, 1); break;
|
||||
default: consumed = 0; break;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
static EM_BOOL EmscriptenVisibilityChangeCallback(int eventType, const EmscriptenVisibilityChangeEvent *visibilityChangeEvent, void *userData)
|
||||
{
|
||||
if (visibilityChangeEvent->hidden) CORE.Window.flags |= FLAG_WINDOW_HIDDEN; // The window was hidden
|
||||
else CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // The window was restored
|
||||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
|
||||
// Register touch input events
|
||||
// Emscripten: Called on touch input events
|
||||
static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
|
||||
{
|
||||
// Register touch points count
|
||||
|
|
@ -1871,7 +1833,85 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
|
|||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
|
||||
// obtaining the canvas id provided by the module configuration
|
||||
// Emscripten: Called on fullscreen change events
|
||||
static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData)
|
||||
{
|
||||
// NOTE: 1. Reset the fullscreen flags if the user left fullscreen manually by pressing the Escape key
|
||||
// 2. Which is a necessary safeguard because that case will bypass the toggles CORE.Window.flags resets
|
||||
if (platform.ourFullscreen) platform.ourFullscreen = false;
|
||||
else
|
||||
{
|
||||
const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
|
||||
if (!wasFullscreen)
|
||||
{
|
||||
CORE.Window.fullscreen = false;
|
||||
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;
|
||||
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
|
||||
}
|
||||
}
|
||||
|
||||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
|
||||
// Emscripten: Called on resize event
|
||||
static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData)
|
||||
{
|
||||
// Don't resize non-resizeable windows
|
||||
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) == 0) return 1;
|
||||
|
||||
// This event is called whenever the window changes sizes,
|
||||
// so the size of the canvas object is explicitly retrieved below
|
||||
int width = EM_ASM_INT( return window.innerWidth; );
|
||||
int height = EM_ASM_INT( return window.innerHeight; );
|
||||
|
||||
if (width < (int)CORE.Window.screenMin.width) width = CORE.Window.screenMin.width;
|
||||
else if ((width > (int)CORE.Window.screenMax.width) && (CORE.Window.screenMax.width > 0)) width = CORE.Window.screenMax.width;
|
||||
|
||||
if (height < (int)CORE.Window.screenMin.height) height = CORE.Window.screenMin.height;
|
||||
else if ((height > (int)CORE.Window.screenMax.height) && (CORE.Window.screenMax.height > 0)) height = CORE.Window.screenMax.height;
|
||||
|
||||
emscripten_set_canvas_element_size(GetCanvasId(), width, height);
|
||||
|
||||
SetupViewport(width, height); // Reset viewport and projection matrix for new size
|
||||
|
||||
CORE.Window.currentFbo.width = width;
|
||||
CORE.Window.currentFbo.height = height;
|
||||
CORE.Window.resizedLastFrame = true;
|
||||
|
||||
if (IsWindowFullscreen()) return 1;
|
||||
|
||||
// Set current screen size
|
||||
CORE.Window.screen.width = width;
|
||||
CORE.Window.screen.height = height;
|
||||
|
||||
// NOTE: Postprocessing texture is not scaled to new size
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Emscripten: Called on windows focus change events
|
||||
static EM_BOOL EmscriptenFocusCallback(int eventType, const EmscriptenFocusEvent *focusEvent, void *userData)
|
||||
{
|
||||
EM_BOOL consumed = 1;
|
||||
switch (eventType)
|
||||
{
|
||||
case EMSCRIPTEN_EVENT_BLUR: WindowFocusCallback(userData, 0); break;
|
||||
case EMSCRIPTEN_EVENT_FOCUS: WindowFocusCallback(userData, 1); break;
|
||||
default: consumed = 0; break;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
// Emscripten: Called on visibility change events
|
||||
static EM_BOOL EmscriptenVisibilityChangeCallback(int eventType, const EmscriptenVisibilityChangeEvent *visibilityChangeEvent, void *userData)
|
||||
{
|
||||
if (visibilityChangeEvent->hidden) CORE.Window.flags |= FLAG_WINDOW_HIDDEN; // The window was hidden
|
||||
else CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // The window was restored
|
||||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
|
||||
// JS: Get the canvas id provided by the module configuration
|
||||
EM_JS(char*, GetCanvasIdJs, (), {
|
||||
var canvasId = "#" + Module.canvas.id;
|
||||
var lengthBytes = lengthBytesUTF8(canvasId) + 1;
|
||||
|
|
@ -1880,6 +1920,7 @@ EM_JS(char*, GetCanvasIdJs, (), {
|
|||
return stringOnWasmHeap;
|
||||
});
|
||||
|
||||
// Get canvas id (using embedded JS function)
|
||||
static const char *GetCanvasId(void)
|
||||
{
|
||||
static char *canvasId = NULL;
|
||||
|
|
|
|||
75
src/raudio.c
75
src/raudio.c
|
|
@ -15,8 +15,8 @@
|
|||
* raudio module is included in the build
|
||||
*
|
||||
* #define RAUDIO_STANDALONE
|
||||
* Define to use the module as standalone library (independently of raylib).
|
||||
* Required types and functions are defined in the same module.
|
||||
* Define to use the module as standalone library (independently of raylib)
|
||||
* Required types and functions are defined in the same module
|
||||
*
|
||||
* #define SUPPORT_FILEFORMAT_WAV
|
||||
* #define SUPPORT_FILEFORMAT_OGG
|
||||
|
|
@ -81,7 +81,7 @@
|
|||
#include "utils.h" // Required for: fopen() Android mapping
|
||||
#endif
|
||||
|
||||
#if defined(SUPPORT_MODULE_RAUDIO)
|
||||
#if defined(SUPPORT_MODULE_RAUDIO) || defined(RAUDIO_STANDALONE)
|
||||
|
||||
#if defined(_WIN32)
|
||||
// To avoid conflicting windows.h symbols with raylib, some flags are defined
|
||||
|
|
@ -89,7 +89,7 @@
|
|||
// by user at some point and won't be included...
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
// If defined, the following flags inhibit definition of the indicated items.
|
||||
// If defined, the following flags inhibit definition of the indicated items
|
||||
#define NOGDICAPMASKS // CC_*, LC_*, PC_*, CP_*, TC_*, RC_
|
||||
#define NOVIRTUALKEYCODES // VK_*
|
||||
#define NOWINMESSAGES // WM_*, EM_*, LB_*, CB_*
|
||||
|
|
@ -124,9 +124,9 @@
|
|||
#define NOWH // SetWindowsHook and WH_*
|
||||
#define NOWINOFFSETS // GWL_*, GCL_*, associated routines
|
||||
#define NOCOMM // COMM driver routines
|
||||
#define NOKANJI // Kanji support stuff.
|
||||
#define NOHELP // Help engine interface.
|
||||
#define NOPROFILER // Profiler interface.
|
||||
#define NOKANJI // Kanji support stuff
|
||||
#define NOHELP // Help engine interface
|
||||
#define NOPROFILER // Profiler interface
|
||||
#define NODEFERWINDOWPOS // DeferWindowPos routines
|
||||
#define NOMCX // Modem Configuration Extensions
|
||||
|
||||
|
|
@ -451,7 +451,6 @@ void SetAudioBufferPan(AudioBuffer *buffer, float pan);
|
|||
void TrackAudioBuffer(AudioBuffer *buffer);
|
||||
void UntrackAudioBuffer(AudioBuffer *buffer);
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Audio Device initialization and Closing
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -996,7 +995,6 @@ Sound LoadSoundAlias(Sound source)
|
|||
return sound;
|
||||
}
|
||||
|
||||
|
||||
// Checks if a sound is valid (data loaded and buffers initialized)
|
||||
bool IsSoundValid(Sound sound)
|
||||
{
|
||||
|
|
@ -1037,6 +1035,8 @@ void UnloadSoundAlias(Sound alias)
|
|||
}
|
||||
|
||||
// Update sound buffer with new data
|
||||
// NOTE 1: data format must match sound.stream.sampleSize
|
||||
// NOTE 2: frameCount must not exceed sound.frameCount
|
||||
void UpdateSound(Sound sound, const void *data, int frameCount)
|
||||
{
|
||||
if (sound.stream.buffer != NULL)
|
||||
|
|
@ -1118,7 +1118,7 @@ bool ExportWaveAsCode(Wave wave, const char *fileName)
|
|||
|
||||
// NOTE: Text data buffer size is estimated considering wave data size in bytes
|
||||
// and requiring 12 char bytes for every byte; the actual size varies, but
|
||||
// the longest possible char being appended is "%.4ff,\n ", which is 12 bytes.
|
||||
// the longest possible char being appended is "%.4ff,\n ", which is 12 bytes
|
||||
char *txtData = (char *)RL_CALLOC(waveDataSize*12 + 2000, sizeof(char));
|
||||
|
||||
int byteCount = 0;
|
||||
|
|
@ -1337,7 +1337,7 @@ Music LoadMusicStream(const char *fileName)
|
|||
#if defined(SUPPORT_FILEFORMAT_WAV)
|
||||
else if (IsFileExtension(fileName, ".wav"))
|
||||
{
|
||||
drwav *ctxWav = RL_CALLOC(1, sizeof(drwav));
|
||||
drwav *ctxWav = (drwav *)RL_CALLOC(1, sizeof(drwav));
|
||||
bool success = drwav_init_file(ctxWav, fileName, NULL);
|
||||
|
||||
if (success)
|
||||
|
|
@ -1387,7 +1387,7 @@ Music LoadMusicStream(const char *fileName)
|
|||
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||
else if (IsFileExtension(fileName, ".mp3"))
|
||||
{
|
||||
drmp3 *ctxMp3 = RL_CALLOC(1, sizeof(drmp3));
|
||||
drmp3 *ctxMp3 = (drmp3 *)RL_CALLOC(1, sizeof(drmp3));
|
||||
int result = drmp3_init_file(ctxMp3, fileName, NULL);
|
||||
|
||||
if (result > 0)
|
||||
|
|
@ -1478,7 +1478,7 @@ Music LoadMusicStream(const char *fileName)
|
|||
#if defined(SUPPORT_FILEFORMAT_MOD)
|
||||
else if (IsFileExtension(fileName, ".mod"))
|
||||
{
|
||||
jar_mod_context_t *ctxMod = RL_CALLOC(1, sizeof(jar_mod_context_t));
|
||||
jar_mod_context_t *ctxMod = (jar_mod_context_t *)RL_CALLOC(1, sizeof(jar_mod_context_t));
|
||||
jar_mod_init(ctxMod);
|
||||
int result = jar_mod_load_file(ctxMod, fileName);
|
||||
|
||||
|
|
@ -1529,7 +1529,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data,
|
|||
#if defined(SUPPORT_FILEFORMAT_WAV)
|
||||
else if ((strcmp(fileType, ".wav") == 0) || (strcmp(fileType, ".WAV") == 0))
|
||||
{
|
||||
drwav *ctxWav = RL_CALLOC(1, sizeof(drwav));
|
||||
drwav *ctxWav = (drwav *)RL_CALLOC(1, sizeof(drwav));
|
||||
|
||||
bool success = drwav_init_memory(ctxWav, (const void *)data, dataSize, NULL);
|
||||
|
||||
|
|
@ -1545,7 +1545,8 @@ Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data,
|
|||
music.looping = true; // Looping enabled by default
|
||||
musicLoaded = true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
drwav_uninit(ctxWav);
|
||||
RL_FREE(ctxWav);
|
||||
}
|
||||
|
|
@ -1580,7 +1581,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data,
|
|||
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||
else if ((strcmp(fileType, ".mp3") == 0) || (strcmp(fileType, ".MP3") == 0))
|
||||
{
|
||||
drmp3 *ctxMp3 = RL_CALLOC(1, sizeof(drmp3));
|
||||
drmp3 *ctxMp3 = (drmp3 *)RL_CALLOC(1, sizeof(drmp3));
|
||||
int success = drmp3_init_memory(ctxMp3, (const void*)data, dataSize, NULL);
|
||||
|
||||
if (success)
|
||||
|
|
@ -1869,6 +1870,7 @@ void SeekMusicStream(Music music, float position)
|
|||
void UpdateMusicStream(Music music)
|
||||
{
|
||||
if (music.stream.buffer == NULL) return;
|
||||
if (!music.stream.buffer->playing) return;
|
||||
|
||||
ma_mutex_lock(&AUDIO.System.lock);
|
||||
|
||||
|
|
@ -1888,14 +1890,28 @@ void UpdateMusicStream(Music music)
|
|||
// Check both sub-buffers to check if they require refilling
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (!music.stream.buffer->isSubBufferProcessed[i]) continue; // No refilling required, move to next sub-buffer
|
||||
|
||||
unsigned int framesLeft = music.frameCount - music.stream.buffer->framesProcessed; // Frames left to be processed
|
||||
unsigned int framesToStream = 0; // Total frames to be streamed
|
||||
|
||||
if ((framesLeft >= subBufferSizeInFrames) || music.looping) framesToStream = subBufferSizeInFrames;
|
||||
else framesToStream = framesLeft;
|
||||
|
||||
if (framesToStream == 0)
|
||||
{
|
||||
// Check if both buffers have been processed
|
||||
if (music.stream.buffer->isSubBufferProcessed[0] && music.stream.buffer->isSubBufferProcessed[1])
|
||||
{
|
||||
ma_mutex_unlock(&AUDIO.System.lock);
|
||||
StopMusicStream(music);
|
||||
return;
|
||||
}
|
||||
|
||||
ma_mutex_unlock(&AUDIO.System.lock);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!music.stream.buffer->isSubBufferProcessed[i]) continue; // No refilling required, move to next sub-buffer
|
||||
|
||||
int frameCountStillNeeded = framesToStream;
|
||||
int frameCountReadTotal = 0;
|
||||
|
||||
|
|
@ -2008,19 +2024,6 @@ void UpdateMusicStream(Music music)
|
|||
}
|
||||
|
||||
UpdateAudioStreamInLockedState(music.stream, AUDIO.System.pcmBuffer, framesToStream);
|
||||
|
||||
music.stream.buffer->framesProcessed = music.stream.buffer->framesProcessed%music.frameCount;
|
||||
|
||||
if (framesLeft <= subBufferSizeInFrames)
|
||||
{
|
||||
if (!music.looping)
|
||||
{
|
||||
ma_mutex_unlock(&AUDIO.System.lock);
|
||||
// Streaming is ending, we filled latest frames from input
|
||||
StopMusicStream(music);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ma_mutex_unlock(&AUDIO.System.lock);
|
||||
|
|
@ -2083,8 +2086,12 @@ float GetMusicTimePlayed(Music music)
|
|||
int subBufferSize = (int)music.stream.buffer->sizeInFrames/2;
|
||||
int framesInFirstBuffer = music.stream.buffer->isSubBufferProcessed[0]? 0 : subBufferSize;
|
||||
int framesInSecondBuffer = music.stream.buffer->isSubBufferProcessed[1]? 0 : subBufferSize;
|
||||
int framesInBuffers = framesInFirstBuffer + framesInSecondBuffer;
|
||||
if ((unsigned int)framesInBuffers > music.frameCount) {
|
||||
if (!music.looping) framesInBuffers = music.frameCount;
|
||||
}
|
||||
int framesSentToMix = music.stream.buffer->frameCursorPos%subBufferSize;
|
||||
int framesPlayed = (framesProcessed - framesInFirstBuffer - framesInSecondBuffer + framesSentToMix)%(int)music.frameCount;
|
||||
int framesPlayed = (framesProcessed - framesInBuffers + framesSentToMix)%(int)music.frameCount;
|
||||
if (framesPlayed < 0) framesPlayed += music.frameCount;
|
||||
secondsPlayed = (float)framesPlayed/music.stream.sampleRate;
|
||||
ma_mutex_unlock(&AUDIO.System.lock);
|
||||
|
|
@ -2340,7 +2347,6 @@ void DetachAudioMixedProcessor(AudioCallback process)
|
|||
ma_mutex_unlock(&AUDIO.System.lock);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -2681,8 +2687,7 @@ static void UpdateAudioStreamInLockedState(AudioStream stream, const void *data,
|
|||
ma_uint32 subBufferSizeInFrames = stream.buffer->sizeInFrames/2;
|
||||
unsigned char *subBuffer = stream.buffer->data + ((subBufferSizeInFrames*stream.channels*(stream.sampleSize/8))*subBufferToUpdate);
|
||||
|
||||
// Total frames processed in buffer is always the complete size, filled with 0 if required
|
||||
stream.buffer->framesProcessed += subBufferSizeInFrames;
|
||||
stream.buffer->framesProcessed += frameCount;
|
||||
|
||||
// Does this API expect a whole buffer to be updated in one go?
|
||||
// Assuming so, but if not will need to change this logic
|
||||
|
|
|
|||
34
src/raylib.h
34
src/raylib.h
|
|
@ -5,7 +5,7 @@
|
|||
* FEATURES:
|
||||
* - NO external dependencies, all required libraries included with raylib
|
||||
* - Multiplatform: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly,
|
||||
* MacOS, Haiku, Android, Raspberry Pi, DRM native, HTML5.
|
||||
* MacOS, Haiku, Android, Raspberry Pi, DRM native, HTML5
|
||||
* - Written in plain C code (C99) in PascalCase/camelCase notation
|
||||
* - Hardware accelerated with OpenGL (1.1, 2.1, 3.3, 4.3, ES2, ES3 - choose at compile)
|
||||
* - Unique OpenGL abstraction layer (usable as standalone module): [rlgl]
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
* [rcore] msf_gif (Miles Fogle) for GIF recording
|
||||
* [rcore] sinfl (Micha Mettke) for DEFLATE decompression algorithm
|
||||
* [rcore] sdefl (Micha Mettke) for DEFLATE compression algorithm
|
||||
* [rcore] rprand (Ramon Snatamaria) for pseudo-random numbers generation
|
||||
* [rcore] rprand (Ramon Santamaria) for pseudo-random numbers generation
|
||||
* [rtextures] qoi (Dominic Szablewski - https://phoboslab.org) for QOI image manage
|
||||
* [rtextures] stb_image (Sean Barret) for images loading (BMP, TGA, PNG, JPEG, HDR...)
|
||||
* [rtextures] stb_image_write (Sean Barret) for image writing (BMP, TGA, PNG, JPG)
|
||||
|
|
@ -743,7 +743,7 @@ typedef enum {
|
|||
GAMEPAD_BUTTON_RIGHT_THUMB // Gamepad joystick pressed button right
|
||||
} GamepadButton;
|
||||
|
||||
// Gamepad axis
|
||||
// Gamepad axes
|
||||
typedef enum {
|
||||
GAMEPAD_AXIS_LEFT_X = 0, // Gamepad left stick X axis
|
||||
GAMEPAD_AXIS_LEFT_Y = 1, // Gamepad left stick Y axis
|
||||
|
|
@ -1129,7 +1129,7 @@ RLAPI bool SaveFileText(const char *fileName, const char *text); // Save text d
|
|||
// File system functions
|
||||
RLAPI bool FileExists(const char *fileName); // Check if file exists
|
||||
RLAPI bool DirectoryExists(const char *dirPath); // Check if a directory path exists
|
||||
RLAPI bool IsFileExtension(const char *fileName, const char *ext); // Check file extension (including point: .png, .wav)
|
||||
RLAPI bool IsFileExtension(const char *fileName, const char *ext); // Check file extension (recommended include point: .png, .wav)
|
||||
RLAPI int GetFileLength(const char *fileName); // Get file length in bytes (NOTE: GetFileSize() conflicts with windows.h)
|
||||
RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes dot: '.png')
|
||||
RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string
|
||||
|
|
@ -1153,8 +1153,8 @@ RLAPI long GetFileModTime(const char *fileName); // Get file mo
|
|||
// Compression/Encoding functionality
|
||||
RLAPI unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDataSize); // Compress data (DEFLATE algorithm), memory must be MemFree()
|
||||
RLAPI unsigned char *DecompressData(const unsigned char *compData, int compDataSize, int *dataSize); // Decompress data (DEFLATE algorithm), memory must be MemFree()
|
||||
RLAPI char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize); // Encode data to Base64 string, memory must be MemFree()
|
||||
RLAPI unsigned char *DecodeDataBase64(const char *data, int *outputSize); // Decode Base64 string data, memory must be MemFree()
|
||||
RLAPI char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize); // Encode data to Base64 string (includes NULL terminator), memory must be MemFree()
|
||||
RLAPI unsigned char *DecodeDataBase64(const char *text, int *outputSize); // Decode Base64 string (expected NULL terminated), memory must be MemFree()
|
||||
RLAPI unsigned int ComputeCRC32(unsigned char *data, int dataSize); // Compute CRC32 hash code
|
||||
RLAPI unsigned int *ComputeMD5(unsigned char *data, int dataSize); // Compute MD5 hash code, returns static int[4] (16 bytes)
|
||||
RLAPI unsigned int *ComputeSHA1(unsigned char *data, int dataSize); // Compute SHA1 hash code, returns static int[5] (20 bytes)
|
||||
|
|
@ -1192,8 +1192,8 @@ RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Check if a game
|
|||
RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Check if a gamepad button has been released once
|
||||
RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Check if a gamepad button is NOT being pressed
|
||||
RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed
|
||||
RLAPI int GetGamepadAxisCount(int gamepad); // Get gamepad axis count for a gamepad
|
||||
RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Get axis movement value for a gamepad axis
|
||||
RLAPI int GetGamepadAxisCount(int gamepad); // Get axis count for a gamepad
|
||||
RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Get movement value for a gamepad axis
|
||||
RLAPI int SetGamepadMappings(const char *mappings); // Set internal gamepad mappings (SDL_GameControllerDB)
|
||||
RLAPI void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration); // Set gamepad vibration for both motors (duration in seconds)
|
||||
|
||||
|
|
@ -1264,7 +1264,9 @@ RLAPI void DrawCircleV(Vector2 center, float radius, Color color);
|
|||
RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline
|
||||
RLAPI void DrawCircleLinesV(Vector2 center, float radius, Color color); // Draw circle outline (Vector version)
|
||||
RLAPI void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, Color color); // Draw ellipse
|
||||
RLAPI void DrawEllipseV(Vector2 center, float radiusH, float radiusV, Color color); // Draw ellipse (Vector version)
|
||||
RLAPI void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Color color); // Draw ellipse outline
|
||||
RLAPI void DrawEllipseLinesV(Vector2 center, float radiusH, float radiusV, Color color); // Draw ellipse outline (Vector version)
|
||||
RLAPI void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color); // Draw ring
|
||||
RLAPI void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color); // Draw ring outline
|
||||
RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle
|
||||
|
|
@ -1273,7 +1275,7 @@ RLAPI void DrawRectangleRec(Rectangle rec, Color color);
|
|||
RLAPI void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color); // Draw a color-filled rectangle with pro parameters
|
||||
RLAPI void DrawRectangleGradientV(int posX, int posY, int width, int height, Color top, Color bottom); // Draw a vertical-gradient-filled rectangle
|
||||
RLAPI void DrawRectangleGradientH(int posX, int posY, int width, int height, Color left, Color right); // Draw a horizontal-gradient-filled rectangle
|
||||
RLAPI void DrawRectangleGradientEx(Rectangle rec, Color topLeft, Color bottomLeft, Color topRight, Color bottomRight); // Draw a gradient-filled rectangle with custom vertex colors
|
||||
RLAPI void DrawRectangleGradientEx(Rectangle rec, Color topLeft, Color bottomLeft, Color bottomRight, Color topRight); // Draw a gradient-filled rectangle with custom vertex colors
|
||||
RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline
|
||||
RLAPI void DrawRectangleLinesEx(Rectangle rec, float lineThick, Color color); // Draw rectangle outline with extended parameters
|
||||
RLAPI void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color color); // Draw rectangle with rounded edges
|
||||
|
|
@ -1406,8 +1408,8 @@ RLAPI void ImageDrawRectangleLines(Image *dst, Rectangle rec, int thick, Color c
|
|||
RLAPI void ImageDrawTriangle(Image *dst, Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle within an image
|
||||
RLAPI void ImageDrawTriangleEx(Image *dst, Vector2 v1, Vector2 v2, Vector2 v3, Color c1, Color c2, Color c3); // Draw triangle with interpolated colors within an image
|
||||
RLAPI void ImageDrawTriangleLines(Image *dst, Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline within an image
|
||||
RLAPI void ImageDrawTriangleFan(Image *dst, Vector2 *points, int pointCount, Color color); // Draw a triangle fan defined by points within an image (first vertex is the center)
|
||||
RLAPI void ImageDrawTriangleStrip(Image *dst, Vector2 *points, int pointCount, Color color); // Draw a triangle strip defined by points within an image
|
||||
RLAPI void ImageDrawTriangleFan(Image *dst, const Vector2 *points, int pointCount, Color color); // Draw a triangle fan defined by points within an image (first vertex is the center)
|
||||
RLAPI void ImageDrawTriangleStrip(Image *dst, const Vector2 *points, int pointCount, Color color); // Draw a triangle strip defined by points within an image
|
||||
RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint); // Draw a source image within a destination image (tint applied to source)
|
||||
RLAPI void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) within an image (destination)
|
||||
RLAPI void ImageDrawTextEx(Image *dst, Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text (custom sprite font) within an image (destination)
|
||||
|
|
@ -1422,8 +1424,8 @@ RLAPI bool IsTextureValid(Texture2D texture);
|
|||
RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory (VRAM)
|
||||
RLAPI bool IsRenderTextureValid(RenderTexture2D target); // Check if a render texture is valid (loaded in GPU)
|
||||
RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory (VRAM)
|
||||
RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data
|
||||
RLAPI void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels); // Update GPU texture rectangle with new data
|
||||
RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data (pixels should be able to fill texture)
|
||||
RLAPI void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels); // Update GPU texture rectangle with new data (pixels and rec should fit in texture)
|
||||
|
||||
// Texture configuration functions
|
||||
RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture
|
||||
|
|
@ -1512,9 +1514,9 @@ RLAPI const char *TextSubtext(const char *text, int position, int length);
|
|||
RLAPI char *TextReplace(const char *text, const char *replace, const char *by); // Replace text string (WARNING: memory must be freed!)
|
||||
RLAPI char *TextInsert(const char *text, const char *insert, int position); // Insert text in a position (WARNING: memory must be freed!)
|
||||
RLAPI char *TextJoin(char **textList, int count, const char *delimiter); // Join text strings with delimiter
|
||||
RLAPI char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings
|
||||
RLAPI char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings, using MAX_TEXTSPLIT_COUNT static strings
|
||||
RLAPI void TextAppend(char *text, const char *append, int *position); // Append text at specific position and move cursor!
|
||||
RLAPI int TextFindIndex(const char *text, const char *find); // Find first text occurrence within a string
|
||||
RLAPI int TextFindIndex(const char *text, const char *find); // Find first text occurrence within a string, -1 if not found
|
||||
RLAPI char *TextToUpper(const char *text); // Get upper case version of provided string
|
||||
RLAPI char *TextToLower(const char *text); // Get lower case version of provided string
|
||||
RLAPI char *TextToPascal(const char *text); // Get Pascal case notation version of provided string
|
||||
|
|
@ -1644,7 +1646,7 @@ RLAPI Sound LoadSound(const char *fileName); // Load so
|
|||
RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound from wave data
|
||||
RLAPI Sound LoadSoundAlias(Sound source); // Create a new sound that shares the same sample data as the source sound, does not own the sound data
|
||||
RLAPI bool IsSoundValid(Sound sound); // Checks if a sound is valid (data loaded and buffers initialized)
|
||||
RLAPI void UpdateSound(Sound sound, const void *data, int sampleCount); // Update sound buffer with new data
|
||||
RLAPI void UpdateSound(Sound sound, const void *data, int sampleCount); // Update sound buffer with new data (data and frame count should fit in sound)
|
||||
RLAPI void UnloadWave(Wave wave); // Unload wave data
|
||||
RLAPI void UnloadSound(Sound sound); // Unload sound
|
||||
RLAPI void UnloadSoundAlias(Sound alias); // Unload a sound alias (does not deallocate sample data)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue