summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorjussi2022-08-19 13:38:09 +0300
committerjussi2022-08-19 13:38:09 +0300
commit49f1dad6b9deeb769e384ae547fca9f64b90bf79 (patch)
treeb02b240d6c11c1bf29c3dc6ac9a7063137b4c971 /include
parent4f54a0a4992358c633e5e3535e2980211028f3a2 (diff)
downloadreilua-enhanced-49f1dad6b9deeb769e384ae547fca9f64b90bf79.tar.gz
reilua-enhanced-49f1dad6b9deeb769e384ae547fca9f64b90bf79.tar.bz2
reilua-enhanced-49f1dad6b9deeb769e384ae547fca9f64b90bf79.zip
Moved to raylib 4.2.0. Renamed some directory functions to raylib 4.2.0 conventions. Removed GenMeshBinormals and GetRayCollisionModel. Sound and music pan.
Diffstat (limited to 'include')
-rw-r--r--include/audio.h2
-rw-r--r--include/core.h4
-rw-r--r--include/models.h2
-rw-r--r--include/raylib.h116
-rw-r--r--include/raymath.h511
-rw-r--r--include/rlgl.h192
6 files changed, 581 insertions, 246 deletions
diff --git a/include/audio.h b/include/audio.h
index 1bb9601..45002aa 100644
--- a/include/audio.h
+++ b/include/audio.h
@@ -21,6 +21,7 @@ int laudioGetSoundsPlaying( lua_State *L );
int laudioIsSoundPlaying( lua_State *L );
int laudioSetSoundVolume( lua_State *L );
int laudioSetSoundPitch( lua_State *L );
+int laudioSetSoundPan( lua_State *L );
int laudioWaveFormat( lua_State *L );
int laudioWaveCopy( lua_State *L );
int laudioWaveCrop( lua_State *L );
@@ -34,5 +35,6 @@ int laudioResumeMusicStream( lua_State *L );
int laudioSeekMusicStream( lua_State *L );
int laudioSetMusicVolume( lua_State *L );
int laudioSetMusicPitch( lua_State *L );
+int laudioSetMusicPan( lua_State *L );
int laudioGetMusicTimeLength( lua_State *L );
int laudioGetMusicTimePlayed( lua_State *L );
diff --git a/include/core.h b/include/core.h
index 29b2953..9812d8d 100644
--- a/include/core.h
+++ b/include/core.h
@@ -84,10 +84,10 @@ int lcoreGetFileNameWithoutExt( lua_State *L );
int lcoreGetDirectoryPath( lua_State *L );
int lcoreGetPrevDirectoryPath( lua_State *L );
int lcoreGetWorkingDirectory( lua_State *L );
-int lcoreGetDirectoryFiles( lua_State *L );
+int lcoreLoadDirectoryFiles( lua_State *L );
int lcoreChangeDirectory( lua_State *L );
int lcoreIsFileDropped( lua_State *L );
-int lcoreGetDroppedFiles( lua_State *L );
+int lcoreLoadDroppedFiles( lua_State *L );
int lcoreGetFileModTime( lua_State *L );
/* Camera2D. */
int lcoreCreateCamera2D( lua_State *L );
diff --git a/include/models.h b/include/models.h
index f3297eb..0113b62 100644
--- a/include/models.h
+++ b/include/models.h
@@ -38,7 +38,6 @@ int lmodelsSetMeshColor( lua_State *L );
int lmodelsExportMesh( lua_State *L );
int lmodelsGetMeshBoundingBox( lua_State *L );
int lmodelsGenMeshTangents( lua_State *L );
-int lmodelsGenMeshBinormals( lua_State *L );
/* Material. */
int lmodelsLoadMaterialDefault( lua_State *L );
int lmodelsCreateMaterial( lua_State *L );
@@ -71,7 +70,6 @@ int lmodelsCheckCollisionBoxes( lua_State *L );
int lmodelsCheckCollisionBoxSphere( lua_State *L );
int lmodelsGetRayCollisionSphere( lua_State *L );
int lmodelsGetRayCollisionBox( lua_State *L );
-int lmodelsGetRayCollisionModel( lua_State *L );
int lmodelsGetRayCollisionMesh( lua_State *L );
int lmodelsGetRayCollisionTriangle( lua_State *L );
int lmodelsGetRayCollisionQuad( lua_State *L );
diff --git a/include/raylib.h b/include/raylib.h
index 1a9ecce..8a5d50c 100644
--- a/include/raylib.h
+++ b/include/raylib.h
@@ -1,6 +1,6 @@
/**********************************************************************************************
*
-* raylib v4.0 - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
+* raylib v4.2 - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
*
* FEATURES:
* - NO external dependencies, all required libraries included with raylib
@@ -33,8 +33,8 @@
*
* OPTIONAL DEPENDENCIES (included):
* [rcore] msf_gif (Miles Fogle) for GIF recording
-* [rcore] sinfl (Micha Mettke) for DEFLATE decompression algorythm
-* [rcore] sdefl (Micha Mettke) for DEFLATE compression algorythm
+* [rcore] sinfl (Micha Mettke) for DEFLATE decompression algorithm
+* [rcore] sdefl (Micha Mettke) for DEFLATE compression algorithm
* [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)
* [rtextures] stb_image_resize (Sean Barret) for image resizing algorithms
@@ -56,7 +56,7 @@
* raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software:
*
-* Copyright (c) 2013-2021 Ramon Santamaria (@raysan5)
+* Copyright (c) 2013-2022 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
@@ -80,12 +80,15 @@
#include <stdarg.h> // Required for: va_list - Only used by TraceLogCallback
-#define RAYLIB_VERSION "4.0"
+#define RAYLIB_VERSION "4.2"
// Function specifiers in case library is build/used as a shared library (Windows)
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
#if defined(_WIN32)
#if defined(BUILD_LIBTYPE_SHARED)
+ #if defined(__TINYC__)
+ #define __declspec(x) __attribute__((x))
+ #endif
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
#elif defined(USE_LIBTYPE_SHARED)
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
@@ -110,6 +113,7 @@
#endif
// Allow custom memory allocators
+// NOTE: Require recompiling raylib sources
#ifndef RL_MALLOC
#define RL_MALLOC(sz) malloc(sz)
#endif
@@ -177,10 +181,10 @@
// Structures Definition
//----------------------------------------------------------------------------------
// Boolean type
-#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
+#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
#include <stdbool.h>
#elif !defined(__cplusplus) && !defined(bool)
- typedef enum bool { false, true } bool;
+ typedef enum bool { false = 0, true = !false } bool;
#define RL_BOOL_TYPE
#endif
@@ -322,7 +326,7 @@ typedef struct Mesh {
// Vertex attributes data
float *vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
float *texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
- float *texcoords2; // Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
+ float *texcoords2; // Vertex texture second coordinates (UV - 2 components per vertex) (shader-location = 5)
float *normals; // Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
float *tangents; // Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4)
unsigned char *colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
@@ -425,11 +429,15 @@ typedef struct Wave {
void *data; // Buffer data pointer
} Wave;
+// Opaque structs declaration
+// NOTE: Actual structs are defined internally in raudio module
typedef struct rAudioBuffer rAudioBuffer;
+typedef struct rAudioProcessor rAudioProcessor;
// AudioStream, custom audio stream
typedef struct AudioStream {
rAudioBuffer *buffer; // Pointer to internal data used by the audio system
+ rAudioProcessor *processor; // Pointer to internal data processor, useful for audio effects
unsigned int sampleRate; // Frequency (samples per second)
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
@@ -478,6 +486,13 @@ typedef struct VrStereoConfig {
float scaleIn[2]; // VR distortion scale in
} VrStereoConfig;
+// File path list
+typedef struct FilePathList {
+ unsigned int capacity; // Filepaths max entries
+ unsigned int count; // Filepaths entries count
+ char **paths; // Filepaths entries
+} FilePathList;
+
//----------------------------------------------------------------------------------
// Enumerators Definition
//----------------------------------------------------------------------------------
@@ -497,6 +512,7 @@ typedef enum {
FLAG_WINDOW_ALWAYS_RUN = 0x00000100, // Set to allow windows running while minimized
FLAG_WINDOW_TRANSPARENT = 0x00000010, // Set to allow transparent framebuffer
FLAG_WINDOW_HIGHDPI = 0x00002000, // Set to support HighDPI
+ FLAG_WINDOW_MOUSE_PASSTHROUGH = 0x00004000, // Set to support mouse passthrough, only supported when FLAG_WINDOW_UNDECORATED
FLAG_MSAA_4X_HINT = 0x00000020, // Set to try enabling MSAA 4X
FLAG_INTERLACED_HINT = 0x00010000 // Set to try enabling interlaced video format (for V3D)
} ConfigFlags;
@@ -839,7 +855,8 @@ typedef enum {
BLEND_MULTIPLIED, // Blend textures multiplying colors
BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
- BLEND_CUSTOM // Belnd textures using custom src/dst factors (use rlSetBlendMode())
+ BLEND_ALPHA_PREMULTIPLY, // Blend premultiplied textures considering alpha
+ BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendMode())
} BlendMode;
// Gesture
@@ -885,8 +902,8 @@ typedef enum {
typedef void (*TraceLogCallback)(int logLevel, const char *text, va_list args); // Logging: Redirect trace log messages
typedef unsigned char *(*LoadFileDataCallback)(const char *fileName, unsigned int *bytesRead); // FileIO: Load binary data
typedef bool (*SaveFileDataCallback)(const char *fileName, void *data, unsigned int bytesToWrite); // FileIO: Save binary data
-typedef char *(*LoadFileTextCallback)(const char *fileName); // FileIO: Load text data
-typedef bool (*SaveFileTextCallback)(const char *fileName, char *text); // FileIO: Save text data
+typedef char *(*LoadFileTextCallback)(const char *fileName); // FileIO: Load text data
+typedef bool (*SaveFileTextCallback)(const char *fileName, char *text); // FileIO: Save text data
//------------------------------------------------------------------------------------
// Global Variables Definition
@@ -913,7 +930,7 @@ RLAPI bool IsWindowMaximized(void); // Check if wi
RLAPI bool IsWindowFocused(void); // Check if window is currently focused (only PLATFORM_DESKTOP)
RLAPI bool IsWindowResized(void); // Check if window has been resized last frame
RLAPI bool IsWindowState(unsigned int flag); // Check if one specific window flag is enabled
-RLAPI void SetWindowState(unsigned int flags); // Set window configuration state using flags
+RLAPI void SetWindowState(unsigned int flags); // Set window configuration state using flags (only PLATFORM_DESKTOP)
RLAPI void ClearWindowState(unsigned int flags); // Clear window configuration state flags
RLAPI void ToggleFullscreen(void); // Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP)
RLAPI void MaximizeWindow(void); // Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
@@ -925,6 +942,7 @@ RLAPI void SetWindowPosition(int x, int y); // Set window
RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window (fullscreen mode)
RLAPI void SetWindowMinSize(int width, int height); // Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
RLAPI void SetWindowSize(int width, int height); // Set window dimensions
+RLAPI void SetWindowOpacity(float opacity); // Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
RLAPI void *GetWindowHandle(void); // Get native window handle
RLAPI int GetScreenWidth(void); // Get current screen width
RLAPI int GetScreenHeight(void); // Get current screen height
@@ -933,8 +951,8 @@ RLAPI int GetRenderHeight(void); // Get current
RLAPI int GetMonitorCount(void); // Get number of connected monitors
RLAPI int GetCurrentMonitor(void); // Get current connected monitor
RLAPI Vector2 GetMonitorPosition(int monitor); // Get specified monitor position
-RLAPI int GetMonitorWidth(int monitor); // Get specified monitor width (max available by monitor)
-RLAPI int GetMonitorHeight(int monitor); // Get specified monitor height (max available by monitor)
+RLAPI int GetMonitorWidth(int monitor); // Get specified monitor width (current video mode used by monitor)
+RLAPI int GetMonitorHeight(int monitor); // Get specified monitor height (current video mode used by monitor)
RLAPI int GetMonitorPhysicalWidth(int monitor); // Get specified monitor physical width in millimetres
RLAPI int GetMonitorPhysicalHeight(int monitor); // Get specified monitor physical height in millimetres
RLAPI int GetMonitorRefreshRate(int monitor); // Get specified monitor refresh rate
@@ -943,6 +961,8 @@ RLAPI Vector2 GetWindowScaleDPI(void); // Get window
RLAPI const char *GetMonitorName(int monitor); // Get the human-readable, UTF-8 encoded name of the primary monitor
RLAPI void SetClipboardText(const char *text); // Set clipboard text content
RLAPI const char *GetClipboardText(void); // Get clipboard text content
+RLAPI void EnableEventWaiting(void); // Enable waiting for events on EndDrawing(), no automatic event polling
+RLAPI void DisableEventWaiting(void); // Disable waiting for events on EndDrawing(), automatic events polling
// Custom frame control functions
// NOTE: Those functions are intended for advance users that want full control over the frame processing
@@ -950,7 +970,7 @@ RLAPI const char *GetClipboardText(void); // Get clipboa
// To avoid that behaviour and control frame processes manually, enable in config.h: SUPPORT_CUSTOM_FRAME_CONTROL
RLAPI void SwapScreenBuffer(void); // Swap back buffer with front buffer (screen drawing)
RLAPI void PollInputEvents(void); // Register all input events
-RLAPI void WaitTime(float ms); // Wait for some milliseconds (halt program execution)
+RLAPI void WaitTime(double seconds); // Wait for some time (halt program execution)
// Cursor-related functions
RLAPI void ShowCursor(void); // Shows cursor
@@ -1000,9 +1020,9 @@ RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Get a ray t
RLAPI Matrix GetCameraMatrix(Camera camera); // Get camera transform matrix (view matrix)
RLAPI Matrix GetCameraMatrix2D(Camera2D camera); // Get camera 2d transform matrix
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Get the screen space position for a 3d world space position
+RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Get the world space position for a 2d camera screen space position
RLAPI Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int height); // Get size position for a 3d world space position
RLAPI Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera); // Get the screen space position for a 2d camera world space position
-RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Get the world space position for a 2d camera screen space position
// Timing-related functions
RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum)
@@ -1022,6 +1042,8 @@ RLAPI void *MemAlloc(int size); // Internal me
RLAPI void *MemRealloc(void *ptr, int size); // Internal memory reallocator
RLAPI void MemFree(void *ptr); // Internal memory free
+RLAPI void OpenURL(const char *url); // Open URL with default system browser (if available)
+
// Set custom callbacks
// WARNING: Callbacks setup is intended for advance users
RLAPI void SetTraceLogCallback(TraceLogCallback callback); // Set custom trace log
@@ -1031,40 +1053,39 @@ RLAPI void SetLoadFileTextCallback(LoadFileTextCallback callback); // Set custom
RLAPI void SetSaveFileTextCallback(SaveFileTextCallback callback); // Set custom file text data saver
// Files management functions
-RLAPI unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead); // Load file data as byte array (read)
+RLAPI unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead); // Load file data as byte array (read)
RLAPI void UnloadFileData(unsigned char *data); // Unload file data allocated by LoadFileData()
-RLAPI bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite); // Save data to file from byte array (write), returns true on success
+RLAPI bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite); // Save data to file from byte array (write), returns true on success
+RLAPI bool ExportDataAsCode(const char *data, unsigned int size, const char *fileName); // Export data to code (.h), returns true on success
RLAPI char *LoadFileText(const char *fileName); // Load text data from file (read), returns a '\0' terminated string
RLAPI void UnloadFileText(char *text); // Unload file text data allocated by LoadFileText()
RLAPI bool SaveFileText(const char *fileName, char *text); // Save text data to file (write), string must be '\0' terminated, returns true on success
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 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
RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string)
RLAPI const char *GetDirectoryPath(const char *filePath); // Get full path for a given fileName with path (uses static string)
RLAPI const char *GetPrevDirectoryPath(const char *dirPath); // Get previous directory path for a given path (uses static string)
RLAPI const char *GetWorkingDirectory(void); // Get current working directory (uses static string)
-RLAPI char **GetDirectoryFiles(const char *dirPath, int *count); // Get filenames in a directory path (memory should be freed)
-RLAPI void ClearDirectoryFiles(void); // Clear directory files paths buffers (free memory)
+RLAPI const char *GetApplicationDirectory(void); // Get the directory if the running application (uses static string)
RLAPI bool ChangeDirectory(const char *dir); // Change working directory, return true on success
+RLAPI bool IsPathFile(const char *path); // Check if a given path is a file or a directory
+RLAPI FilePathList LoadDirectoryFiles(const char *dirPath); // Load directory filepaths
+RLAPI FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool scanSubdirs); // Load directory filepaths with extension filtering and recursive directory scan
+RLAPI void UnloadDirectoryFiles(FilePathList files); // Unload filepaths
RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window
-RLAPI char **GetDroppedFiles(int *count); // Get dropped files names (memory should be freed)
-RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer (free memory)
+RLAPI FilePathList LoadDroppedFiles(void); // Load dropped filepaths
+RLAPI void UnloadDroppedFiles(FilePathList files); // Unload dropped filepaths
RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time)
// Compression/Encoding functionality
-RLAPI unsigned char *CompressData(unsigned char *data, int dataLength, int *compDataLength); // Compress data (DEFLATE algorithm)
-RLAPI unsigned char *DecompressData(unsigned char *compData, int compDataLength, int *dataLength); // Decompress data (DEFLATE algorithm)
-RLAPI char *EncodeDataBase64(const unsigned char *data, int dataLength, int *outputLength); // Encode data to Base64 string
-RLAPI unsigned char *DecodeDataBase64(unsigned char *data, int *outputLength); // Decode Base64 string data
-
-// Persistent storage management
-RLAPI bool SaveStorageValue(unsigned int position, int value); // Save integer value to storage file (to defined position), returns true on success
-RLAPI int LoadStorageValue(unsigned int position); // Load integer value from storage file (from defined position)
-
-RLAPI void OpenURL(const char *url); // Open URL with default system browser (if available)
+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 unsigned char *data, int *outputSize); // Decode Base64 string data, memory must be MemFree()
//------------------------------------------------------------------------------------
// Input Handling Functions (Module: core)
@@ -1103,7 +1124,8 @@ RLAPI Vector2 GetMouseDelta(void); // Get mouse delta
RLAPI void SetMousePosition(int x, int y); // Set mouse position XY
RLAPI void SetMouseOffset(int offsetX, int offsetY); // Set mouse offset
RLAPI void SetMouseScale(float scaleX, float scaleY); // Set mouse scaling
-RLAPI float GetMouseWheelMove(void); // Get mouse wheel movement Y
+RLAPI float GetMouseWheelMove(void); // Get mouse wheel movement for X or Y, whichever is larger
+RLAPI Vector2 GetMouseWheelMoveV(void); // Get mouse wheel movement for both X and Y
RLAPI void SetMouseCursor(int cursor); // Set mouse cursor
// Input-related functions: touch
@@ -1324,7 +1346,8 @@ RLAPI Font LoadFontFromMemory(const char *fileType, const unsigned char *fileDat
RLAPI GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int glyphCount, int type); // Load font data for further use
RLAPI Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **recs, int glyphCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info
RLAPI void UnloadFontData(GlyphInfo *chars, int glyphCount); // Unload font chars info data (RAM)
-RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM)
+RLAPI void UnloadFont(Font font); // Unload font from GPU memory (VRAM)
+RLAPI bool ExportFontAsCode(Font font, const char *fileName); // Export font as code file, returns true on success
// Text drawing functions
RLAPI void DrawFPS(int posX, int posY); // Draw current FPS
@@ -1332,6 +1355,7 @@ RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color co
RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters
RLAPI void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint); // Draw text using Font and pro parameters (rotation)
RLAPI void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSize, Color tint); // Draw one character (codepoint)
+RLAPI void DrawTextCodepoints(Font font, const int *codepoints, int count, Vector2 position, float fontSize, float spacing, Color tint); // Draw multiple character (codepoint)
// Text font info functions
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
@@ -1346,7 +1370,7 @@ RLAPI void UnloadCodepoints(int *codepoints); // Unload
RLAPI int GetCodepointCount(const char *text); // Get total number of codepoints in a UTF-8 encoded string
RLAPI int GetCodepoint(const char *text, int *bytesProcessed); // Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
RLAPI const char *CodepointToUTF8(int codepoint, int *byteSize); // Encode one codepoint into UTF-8 byte array (array length returned as parameter)
-RLAPI char *TextCodepointsToUTF8(int *codepoints, int length); // Encode text as codepoints array into UTF-8 text string (WARNING: memory must be freed!)
+RLAPI char *TextCodepointsToUTF8(const int *codepoints, int length); // Encode text as codepoints array into UTF-8 text string (WARNING: memory must be freed!)
// Text strings management functions (no UTF-8 strings, only byte chars)
// NOTE: Some strings allocate memory internally for returned strings, just be careful!
@@ -1416,14 +1440,13 @@ RLAPI void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source,
// Mesh management functions
RLAPI void UploadMesh(Mesh *mesh, bool dynamic); // Upload mesh vertex data in GPU and provide VAO/VBO ids
-RLAPI void UpdateMeshBuffer(Mesh mesh, int index, void *data, int dataSize, int offset); // Update mesh vertex data in GPU for a specific buffer index
+RLAPI void UpdateMeshBuffer(Mesh mesh, int index, const void *data, int dataSize, int offset); // Update mesh vertex data in GPU for a specific buffer index
RLAPI void UnloadMesh(Mesh mesh); // Unload mesh data from CPU and GPU
RLAPI void DrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform
-RLAPI void DrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int instances); // Draw multiple mesh instances with material and different transforms
+RLAPI void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, int instances); // Draw multiple mesh instances with material and different transforms
RLAPI bool ExportMesh(Mesh mesh, const char *fileName); // Export mesh data to file, returns true on success
RLAPI BoundingBox GetMeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits
RLAPI void GenMeshTangents(Mesh *mesh); // Compute mesh tangents
-RLAPI void GenMeshBinormals(Mesh *mesh); // Compute mesh binormals
// Mesh generation functions
RLAPI Mesh GenMeshPoly(int sides, float radius); // Generate polygonal mesh
@@ -1449,7 +1472,7 @@ RLAPI void SetModelMeshMaterial(Model *model, int meshId, int materialId);
RLAPI ModelAnimation *LoadModelAnimations(const char *fileName, unsigned int *animCount); // Load model animations from file
RLAPI void UpdateModelAnimation(Model model, ModelAnimation anim, int frame); // Update model animation pose
RLAPI void UnloadModelAnimation(ModelAnimation anim); // Unload animation data
-RLAPI void UnloadModelAnimations(ModelAnimation* animations, unsigned int count); // Unload animation array data
+RLAPI void UnloadModelAnimations(ModelAnimation *animations, unsigned int count); // Unload animation array data
RLAPI bool IsModelAnimationValid(Model model, ModelAnimation anim); // Check model animation skeleton match
// Collision detection functions
@@ -1458,7 +1481,6 @@ RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2);
RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 center, float radius); // Check collision between box and sphere
RLAPI RayCollision GetRayCollisionSphere(Ray ray, Vector3 center, float radius); // Get collision info between ray and sphere
RLAPI RayCollision GetRayCollisionBox(Ray ray, BoundingBox box); // Get collision info between ray and box
-RLAPI RayCollision GetRayCollisionModel(Ray ray, Model model); // Get collision info between ray and model
RLAPI RayCollision GetRayCollisionMesh(Ray ray, Mesh mesh, Matrix transform); // Get collision info between ray and mesh
RLAPI RayCollision GetRayCollisionTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3); // Get collision info between ray and triangle
RLAPI RayCollision GetRayCollisionQuad(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4); // Get collision info between ray and quad
@@ -1466,6 +1488,7 @@ RLAPI RayCollision GetRayCollisionQuad(Ray ray, Vector3 p1, Vector3 p2, Vector3
//------------------------------------------------------------------------------------
// Audio Loading and Playing Functions (Module: audio)
//------------------------------------------------------------------------------------
+typedef void (*AudioCallback)(void *bufferData, unsigned int frames);
// Audio device management functions
RLAPI void InitAudioDevice(void); // Initialize audio device and context
@@ -1495,15 +1518,16 @@ RLAPI int GetSoundsPlaying(void); // Get num
RLAPI bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing
RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
-RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format
+RLAPI void SetSoundPan(Sound sound, float pan); // Set pan for a sound (0.5 is center)
RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave
RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range
-RLAPI float *LoadWaveSamples(Wave wave); // Load samples data from wave as a floats array
+RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format
+RLAPI float *LoadWaveSamples(Wave wave); // Load samples data from wave as a 32bit float data array
RLAPI void UnloadWaveSamples(float *samples); // Unload samples data loaded with LoadWaveSamples()
// Music management functions
RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file
-RLAPI Music LoadMusicStreamFromMemory(const char *fileType, unsigned char *data, int dataSize); // Load music stream from data
+RLAPI Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data, int dataSize); // Load music stream from data
RLAPI void UnloadMusicStream(Music music); // Unload music stream
RLAPI void PlayMusicStream(Music music); // Start music playing
RLAPI bool IsMusicStreamPlaying(Music music); // Check if music is playing
@@ -1514,6 +1538,7 @@ RLAPI void ResumeMusicStream(Music music); // Resume
RLAPI void SeekMusicStream(Music music, float position); // Seek music to a position (in seconds)
RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level)
RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level)
+RLAPI void SetMusicPan(Music music, float pan); // Set pan for a music (0.5 is center)
RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds)
RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
@@ -1529,7 +1554,12 @@ RLAPI bool IsAudioStreamPlaying(AudioStream stream); // Check i
RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream
RLAPI void SetAudioStreamVolume(AudioStream stream, float volume); // Set volume for audio stream (1.0 is max level)
RLAPI void SetAudioStreamPitch(AudioStream stream, float pitch); // Set pitch for audio stream (1.0 is base level)
+RLAPI void SetAudioStreamPan(AudioStream stream, float pan); // Set pan for audio stream (0.5 is centered)
RLAPI void SetAudioStreamBufferSizeDefault(int size); // Default size for new audio streams
+RLAPI void SetAudioStreamCallback(AudioStream stream, AudioCallback callback); // Audio thread callback to request new data
+
+RLAPI void AttachAudioStreamProcessor(AudioStream stream, AudioCallback processor); // Attach audio stream processor to stream
+RLAPI void DetachAudioStreamProcessor(AudioStream stream, AudioCallback processor); // Detach audio stream processor from stream
#if defined(__cplusplus)
}
diff --git a/include/raymath.h b/include/raymath.h
index 9714962..fbe4cea 100644
--- a/include/raymath.h
+++ b/include/raymath.h
@@ -18,14 +18,14 @@
* - Functions are always self-contained, no function use another raymath function inside,
* required code is directly re-implemented inside
* - Functions input parameters are always received by value (2 unavoidable exceptions)
-* - Functions use always a "result" anmed variable for return
+* - Functions use always a "result" variable for return
* - Functions are always defined inline
* - Angles are always in radians (DEG2RAD/RAD2DEG macros provided for convenience)
*
*
* LICENSE: zlib/libpng
*
-* Copyright (c) 2015-2021 Ramon Santamaria (@raysan5)
+* Copyright (c) 2015-2022 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
@@ -77,6 +77,10 @@
#define PI 3.14159265358979323846f
#endif
+#ifndef EPSILON
+ #define EPSILON 0.000001f
+#endif
+
#ifndef DEG2RAD
#define DEG2RAD (PI/180.0f)
#endif
@@ -154,7 +158,7 @@ typedef struct float16 {
float v[16];
} float16;
-#include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), fminf(), fmaxf(), fabs()
+#include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), floor(), fminf(), fmaxf(), fabs()
//----------------------------------------------------------------------------------
// Module Functions Definition - Utils math
@@ -189,7 +193,23 @@ RMAPI float Normalize(float value, float start, float end)
// Remap input value within input range to output range
RMAPI float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd)
{
- float result =(value - inputStart)/(inputEnd - inputStart)*(outputEnd - outputStart) + outputStart;
+ float result = (value - inputStart)/(inputEnd - inputStart)*(outputEnd - outputStart) + outputStart;
+
+ return result;
+}
+
+// Wrap input value from min to max
+RMAPI float Wrap(float value, float min, float max)
+{
+ float result = value - (max - min)*floorf((value - min)/(max - min));
+
+ return result;
+}
+
+// Check whether two given floats are almost equal
+RMAPI int FloatEquals(float x, float y)
+{
+ int result = (fabsf(x - y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(x), fabsf(y))));
return result;
}
@@ -278,11 +298,19 @@ RMAPI float Vector2Distance(Vector2 v1, Vector2 v2)
return result;
}
+// Calculate square distance between two vectors
+RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2)
+{
+ float result = ((v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y));
+
+ return result;
+}
+
// Calculate angle from two vectors
RMAPI float Vector2Angle(Vector2 v1, Vector2 v2)
{
float result = atan2f(v2.y, v2.x) - atan2f(v1.y, v1.x);
-
+
return result;
}
@@ -334,6 +362,21 @@ RMAPI Vector2 Vector2Normalize(Vector2 v)
return result;
}
+// Transforms a Vector2 by a given Matrix
+RMAPI Vector2 Vector2Transform(Vector2 v, Matrix mat)
+{
+ Vector2 result = { 0 };
+
+ float x = v.x;
+ float y = v.y;
+ float z = 0;
+
+ result.x = mat.m0*x + mat.m4*y + mat.m8*z + mat.m12;
+ result.y = mat.m1*x + mat.m5*y + mat.m9*z + mat.m13;
+
+ return result;
+}
+
// Calculate linear interpolation between two vectors
RMAPI Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount)
{
@@ -363,8 +406,11 @@ RMAPI Vector2 Vector2Rotate(Vector2 v, float angle)
{
Vector2 result = { 0 };
- result.x = v.x*cosf(angle) - v.y*sinf(angle);
- result.y = v.x*sinf(angle) + v.y*cosf(angle);
+ float cosres = cosf(angle);
+ float sinres = sinf(angle);
+
+ result.x = v.x*cosres - v.y*sinres;
+ result.y = v.x*sinres + v.y*cosres;
return result;
}
@@ -388,6 +434,62 @@ RMAPI Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance)
return result;
}
+// Invert the given vector
+RMAPI Vector2 Vector2Invert(Vector2 v)
+{
+ Vector2 result = { 1.0f/v.x, 1.0f/v.y };
+
+ return result;
+}
+
+// Clamp the components of the vector between
+// min and max values specified by the given vectors
+RMAPI Vector2 Vector2Clamp(Vector2 v, Vector2 min, Vector2 max)
+{
+ Vector2 result = { 0 };
+
+ result.x = fminf(max.x, fmaxf(min.x, v.x));
+ result.y = fminf(max.y, fmaxf(min.y, v.y));
+
+ return result;
+}
+
+// Clamp the magnitude of the vector between two min and max values
+RMAPI Vector2 Vector2ClampValue(Vector2 v, float min, float max)
+{
+ Vector2 result = v;
+
+ float length = (v.x*v.x) + (v.y*v.y);
+ if (length > 0.0f)
+ {
+ length = sqrtf(length);
+
+ if (length < min)
+ {
+ float scale = min/length;
+ result.x = v.x*scale;
+ result.y = v.y*scale;
+ }
+ else if (length > max)
+ {
+ float scale = max/length;
+ result.x = v.x*scale;
+ result.y = v.y*scale;
+ }
+ }
+
+ return result;
+}
+
+// Check whether two given vectors are almost equal
+RMAPI int Vector2Equals(Vector2 p, Vector2 q)
+{
+ int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
+ ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y)))));
+
+ return result;
+}
+
//----------------------------------------------------------------------------------
// Module Functions Definition - Vector3 math
//----------------------------------------------------------------------------------
@@ -472,14 +574,14 @@ RMAPI Vector3 Vector3Perpendicular(Vector3 v)
float min = (float) fabs(v.x);
Vector3 cardinalAxis = {1.0f, 0.0f, 0.0f};
- if (fabs(v.y) < min)
+ if (fabsf(v.y) < min)
{
min = (float) fabs(v.y);
Vector3 tmp = {0.0f, 1.0f, 0.0f};
cardinalAxis = tmp;
}
- if (fabs(v.z) < min)
+ if (fabsf(v.z) < min)
{
Vector3 tmp = {0.0f, 0.0f, 1.0f};
cardinalAxis = tmp;
@@ -530,16 +632,29 @@ RMAPI float Vector3Distance(Vector3 v1, Vector3 v2)
return result;
}
+// Calculate square distance between two vectors
+RMAPI float Vector3DistanceSqr(Vector3 v1, Vector3 v2)
+{
+ float result = 0.0f;
+
+ float dx = v2.x - v1.x;
+ float dy = v2.y - v1.y;
+ float dz = v2.z - v1.z;
+ result = dx*dx + dy*dy + dz*dz;
+
+ return result;
+}
+
// Calculate angle between two vectors
RMAPI float Vector3Angle(Vector3 v1, Vector3 v2)
{
float result = 0.0f;
-
+
Vector3 cross = { v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x };
float len = sqrtf(cross.x*cross.x + cross.y*cross.y + cross.z*cross.z);
float dot = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
result = atan2f(len, dot);
-
+
return result;
}
@@ -638,6 +753,58 @@ RMAPI Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q)
return result;
}
+// Rotates a vector around an axis
+RMAPI Vector3 Vector3RotateByAxisAngle(Vector3 v, Vector3 axis, float angle)
+{
+ // Using Euler-Rodrigues Formula
+ // Ref.: https://en.wikipedia.org/w/index.php?title=Euler%E2%80%93Rodrigues_formula
+
+ Vector3 result = v;
+
+ // Vector3Normalize(axis);
+ float length = sqrtf(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z);
+ if (length == 0.0f) length = 1.0f;
+ float ilength = 1.0f / length;
+ axis.x *= ilength;
+ axis.y *= ilength;
+ axis.z *= ilength;
+
+ angle /= 2.0f;
+ float a = sinf(angle);
+ float b = axis.x * a;
+ float c = axis.y * a;
+ float d = axis.z * a;
+ a = cosf(angle);
+ Vector3 w = { b, c, d };
+
+ // Vector3CrossProduct(w, v)
+ Vector3 wv = { w.y * v.z - w.z * v.y, w.z * v.x - w.x * v.z, w.x * v.y - w.y * v.x };
+
+ // Vector3CrossProduct(w, wv)
+ Vector3 wwv = { w.y * wv.z - w.z * wv.y, w.z * wv.x - w.x * wv.z, w.x * wv.y - w.y * wv.x };
+
+ // Vector3Scale(wv, 2 * a)
+ a *= 2;
+ wv.x *= a;
+ wv.y *= a;
+ wv.z *= a;
+
+ // Vector3Scale(wwv, 2)
+ wwv.x *= 2;
+ wwv.y *= 2;
+ wwv.z *= 2;
+
+ result.x += wv.x;
+ result.y += wv.y;
+ result.z += wv.z;
+
+ result.x += wwv.x;
+ result.y += wwv.y;
+ result.z += wwv.z;
+
+ return result;
+}
+
// Calculate linear interpolation between two vectors
RMAPI Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount)
{
@@ -812,6 +979,92 @@ RMAPI float3 Vector3ToFloatV(Vector3 v)
return buffer;
}
+// Invert the given vector
+RMAPI Vector3 Vector3Invert(Vector3 v)
+{
+ Vector3 result = { 1.0f/v.x, 1.0f/v.y, 1.0f/v.z };
+
+ return result;
+}
+
+// Clamp the components of the vector between
+// min and max values specified by the given vectors
+RMAPI Vector3 Vector3Clamp(Vector3 v, Vector3 min, Vector3 max)
+{
+ Vector3 result = { 0 };
+
+ result.x = fminf(max.x, fmaxf(min.x, v.x));
+ result.y = fminf(max.y, fmaxf(min.y, v.y));
+ result.z = fminf(max.z, fmaxf(min.z, v.z));
+
+ return result;
+}
+
+// Clamp the magnitude of the vector between two values
+RMAPI Vector3 Vector3ClampValue(Vector3 v, float min, float max)
+{
+ Vector3 result = v;
+
+ float length = (v.x*v.x) + (v.y*v.y) + (v.z*v.z);
+ if (length > 0.0f)
+ {
+ length = sqrtf(length);
+
+ if (length < min)
+ {
+ float scale = min/length;
+ result.x = v.x*scale;
+ result.y = v.y*scale;
+ result.z = v.z*scale;
+ }
+ else if (length > max)
+ {
+ float scale = max/length;
+ result.x = v.x*scale;
+ result.y = v.y*scale;
+ result.z = v.z*scale;
+ }
+ }
+
+ return result;
+}
+
+// Check whether two given vectors are almost equal
+RMAPI int Vector3Equals(Vector3 p, Vector3 q)
+{
+ int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
+ ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
+ ((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z)))));
+
+ return result;
+}
+
+// Compute the direction of a refracted ray where v specifies the
+// normalized direction of the incoming ray, n specifies the
+// normalized normal vector of the interface of two optical media,
+// and r specifies the ratio of the refractive index of the medium
+// from where the ray comes to the refractive index of the medium
+// on the other side of the surface
+RMAPI Vector3 Vector3Refract(Vector3 v, Vector3 n, float r)
+{
+ Vector3 result = { 0 };
+
+ float dot = v.x*n.x + v.y*n.y + v.z*n.z;
+ float d = 1.0f - r*r*(1.0f - dot*dot);
+
+ if (d >= 0.0f)
+ {
+ d = sqrtf(d);
+ v.x = r*v.x - (r*dot + d)*n.x;
+ v.y = r*v.y - (r*dot + d)*n.y;
+ v.z = r*v.z - (r*dot + d)*n.z;
+
+ result = v;
+ }
+
+ return result;
+}
+
//----------------------------------------------------------------------------------
// Module Functions Definition - Matrix math
//----------------------------------------------------------------------------------
@@ -917,45 +1170,6 @@ RMAPI Matrix MatrixInvert(Matrix mat)
return result;
}
-// Normalize provided matrix
-RMAPI Matrix MatrixNormalize(Matrix mat)
-{
- Matrix result = { 0 };
-
- // Cache the matrix values (speed optimization)
- float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
- float a10 = mat.m4, a11 = mat.m5, a12 = mat.m6, a13 = mat.m7;
- float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
- float a30 = mat.m12, a31 = mat.m13, a32 = mat.m14, a33 = mat.m15;
-
- // MatrixDeterminant(mat)
- float det = a30*a21*a12*a03 - a20*a31*a12*a03 - a30*a11*a22*a03 + a10*a31*a22*a03 +
- a20*a11*a32*a03 - a10*a21*a32*a03 - a30*a21*a02*a13 + a20*a31*a02*a13 +
- a30*a01*a22*a13 - a00*a31*a22*a13 - a20*a01*a32*a13 + a00*a21*a32*a13 +
- a30*a11*a02*a23 - a10*a31*a02*a23 - a30*a01*a12*a23 + a00*a31*a12*a23 +
- a10*a01*a32*a23 - a00*a11*a32*a23 - a20*a11*a02*a33 + a10*a21*a02*a33 +
- a20*a01*a12*a33 - a00*a21*a12*a33 - a10*a01*a22*a33 + a00*a11*a22*a33;
-
- result.m0 = mat.m0/det;
- result.m1 = mat.m1/det;
- result.m2 = mat.m2/det;
- result.m3 = mat.m3/det;
- result.m4 = mat.m4/det;
- result.m5 = mat.m5/det;
- result.m6 = mat.m6/det;
- result.m7 = mat.m7/det;
- result.m8 = mat.m8/det;
- result.m9 = mat.m9/det;
- result.m10 = mat.m10/det;
- result.m11 = mat.m11/det;
- result.m12 = mat.m12/det;
- result.m13 = mat.m13/det;
- result.m14 = mat.m14/det;
- result.m15 = mat.m15/det;
-
- return result;
-}
-
// Get identity matrix
RMAPI Matrix MatrixIdentity(void)
{
@@ -1099,7 +1313,8 @@ RMAPI Matrix MatrixRotate(Vector3 axis, float angle)
return result;
}
-// Get x-rotation matrix (angle in radians)
+// Get x-rotation matrix
+// NOTE: Angle must be provided in radians
RMAPI Matrix MatrixRotateX(float angle)
{
Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
@@ -1111,14 +1326,15 @@ RMAPI Matrix MatrixRotateX(float angle)
float sinres = sinf(angle);
result.m5 = cosres;
- result.m6 = -sinres;
- result.m9 = sinres;
+ result.m6 = sinres;
+ result.m9 = -sinres;
result.m10 = cosres;
return result;
}
-// Get y-rotation matrix (angle in radians)
+// Get y-rotation matrix
+// NOTE: Angle must be provided in radians
RMAPI Matrix MatrixRotateY(float angle)
{
Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
@@ -1130,14 +1346,15 @@ RMAPI Matrix MatrixRotateY(float angle)
float sinres = sinf(angle);
result.m0 = cosres;
- result.m2 = sinres;
- result.m8 = -sinres;
+ result.m2 = -sinres;
+ result.m8 = sinres;
result.m10 = cosres;
return result;
}
-// Get z-rotation matrix (angle in radians)
+// Get z-rotation matrix
+// NOTE: Angle must be provided in radians
RMAPI Matrix MatrixRotateZ(float angle)
{
Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
@@ -1149,74 +1366,76 @@ RMAPI Matrix MatrixRotateZ(float angle)
float sinres = sinf(angle);
result.m0 = cosres;
- result.m1 = -sinres;
- result.m4 = sinres;
+ result.m1 = sinres;
+ result.m4 = -sinres;
result.m5 = cosres;
return result;
}
-// Get xyz-rotation matrix (angles in radians)
-RMAPI Matrix MatrixRotateXYZ(Vector3 ang)
+// Get xyz-rotation matrix
+// NOTE: Angle must be provided in radians
+RMAPI Matrix MatrixRotateXYZ(Vector3 angle)
{
Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
- float cosz = cosf(-ang.z);
- float sinz = sinf(-ang.z);
- float cosy = cosf(-ang.y);
- float siny = sinf(-ang.y);
- float cosx = cosf(-ang.x);
- float sinx = sinf(-ang.x);
+ float cosz = cosf(-angle.z);
+ float sinz = sinf(-angle.z);
+ float cosy = cosf(-angle.y);
+ float siny = sinf(-angle.y);
+ float cosx = cosf(-angle.x);
+ float sinx = sinf(-angle.x);
result.m0 = cosz*cosy;
- result.m4 = (cosz*siny*sinx) - (sinz*cosx);
- result.m8 = (cosz*siny*cosx) + (sinz*sinx);
+ result.m1 = (cosz*siny*sinx) - (sinz*cosx);
+ result.m2 = (cosz*siny*cosx) + (sinz*sinx);
- result.m1 = sinz*cosy;
+ result.m4 = sinz*cosy;
result.m5 = (sinz*siny*sinx) + (cosz*cosx);
- result.m9 = (sinz*siny*cosx) - (cosz*sinx);
+ result.m6 = (sinz*siny*cosx) - (cosz*sinx);
- result.m2 = -siny;
- result.m6 = cosy*sinx;
+ result.m8 = -siny;
+ result.m9 = cosy*sinx;
result.m10= cosy*cosx;
return result;
}
-// Get zyx-rotation matrix (angles in radians)
-RMAPI Matrix MatrixRotateZYX(Vector3 ang)
+// Get zyx-rotation matrix
+// NOTE: Angle must be provided in radians
+RMAPI Matrix MatrixRotateZYX(Vector3 angle)
{
Matrix result = { 0 };
- float cz = cosf(ang.z);
- float sz = sinf(ang.z);
- float cy = cosf(ang.y);
- float sy = sinf(ang.y);
- float cx = cosf(ang.x);
- float sx = sinf(ang.x);
+ float cz = cosf(angle.z);
+ float sz = sinf(angle.z);
+ float cy = cosf(angle.y);
+ float sy = sinf(angle.y);
+ float cx = cosf(angle.x);
+ float sx = sinf(angle.x);
result.m0 = cz*cy;
- result.m1 = cz*sy*sx - cx*sz;
- result.m2 = sz*sx + cz*cx*sy;
- result.m3 = 0;
+ result.m4 = cz*sy*sx - cx*sz;
+ result.m8 = sz*sx + cz*cx*sy;
+ result.m12 = 0;
- result.m4 = cy*sz;
+ result.m1 = cy*sz;
result.m5 = cz*cx + sz*sy*sx;
- result.m6 = cx*sz*sy - cz*sx;
- result.m7 = 0;
+ result.m9 = cx*sz*sy - cz*sx;
+ result.m13 = 0;
- result.m8 = -sy;
- result.m9 = cy*sx;
+ result.m2 = -sy;
+ result.m6 = cy*sx;
result.m10 = cy*cx;
- result.m11 = 0;
-
- result.m12 = 0;
- result.m13 = 0;
result.m14 = 0;
+
+ result.m3 = 0;
+ result.m7 = 0;
+ result.m11 = 0;
result.m15 = 1;
return result;
@@ -1266,7 +1485,7 @@ RMAPI Matrix MatrixFrustum(double left, double right, double bottom, double top,
}
// Get perspective projection matrix
-// NOTE: Angle should be provided in radians
+// NOTE: Fovy angle must be provided in radians
RMAPI Matrix MatrixPerspective(double fovy, double aspect, double near, double far)
{
Matrix result = { 0 };
@@ -1475,10 +1694,9 @@ RMAPI Quaternion QuaternionInvert(Quaternion q)
{
Quaternion result = q;
- float length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
- float lengthSq = length*length;
+ float lengthSq = q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w;
- if (lengthSq != 0.0)
+ if (lengthSq != 0.0f)
{
float invLength = 1.0f/lengthSq;
@@ -1512,12 +1730,10 @@ RMAPI Quaternion QuaternionScale(Quaternion q, float mul)
{
Quaternion result = { 0 };
- float qax = q.x, qay = q.y, qaz = q.z, qaw = q.w;
-
- result.x = qax*mul + qaw*mul + qay*mul - qaz*mul;
- result.y = qay*mul + qaw*mul + qaz*mul - qax*mul;
- result.z = qaz*mul + qaw*mul + qax*mul - qay*mul;
- result.w = qaw*mul - qax*mul - qay*mul - qaz*mul;
+ result.x = q.x*mul;
+ result.y = q.y*mul;
+ result.z = q.z*mul;
+ result.w = q.w*mul;
return result;
}
@@ -1581,14 +1797,14 @@ RMAPI Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount)
cosHalfTheta = -cosHalfTheta;
}
- if (fabs(cosHalfTheta) >= 1.0f) result = q1;
+ if (fabsf(cosHalfTheta) >= 1.0f) result = q1;
else if (cosHalfTheta > 0.95f) result = QuaternionNlerp(q1, q2, amount);
else
{
float halfTheta = acosf(cosHalfTheta);
float sinHalfTheta = sqrtf(1.0f - cosHalfTheta*cosHalfTheta);
- if (fabs(sinHalfTheta) < 0.001f)
+ if (fabsf(sinHalfTheta) < 0.001f)
{
result.x = (q1.x*0.5f + q2.x*0.5f);
result.y = (q1.y*0.5f + q2.y*0.5f);
@@ -1643,30 +1859,60 @@ RMAPI Quaternion QuaternionFromMatrix(Matrix mat)
{
Quaternion result = { 0 };
- if ((mat.m0 > mat.m5) && (mat.m0 > mat.m10))
+ float fourWSquaredMinus1 = mat.m0 + mat.m5 + mat.m10;
+ float fourXSquaredMinus1 = mat.m0 - mat.m5 - mat.m10;
+ float fourYSquaredMinus1 = mat.m5 - mat.m0 - mat.m10;
+ float fourZSquaredMinus1 = mat.m10 - mat.m0 - mat.m5;
+
+ int biggestIndex = 0;
+ float fourBiggestSquaredMinus1 = fourWSquaredMinus1;
+ if (fourXSquaredMinus1 > fourBiggestSquaredMinus1)
{
- float s = sqrtf(1.0f + mat.m0 - mat.m5 - mat.m10)*2;
+ fourBiggestSquaredMinus1 = fourXSquaredMinus1;
+ biggestIndex = 1;
+ }
- result.x = 0.25f*s;
- result.y = (mat.m4 + mat.m1)/s;
- result.z = (mat.m2 + mat.m8)/s;
- result.w = (mat.m9 - mat.m6)/s;
+ if (fourYSquaredMinus1 > fourBiggestSquaredMinus1)
+ {
+ fourBiggestSquaredMinus1 = fourYSquaredMinus1;
+ biggestIndex = 2;
}
- else if (mat.m5 > mat.m10)
+
+ if (fourZSquaredMinus1 > fourBiggestSquaredMinus1)
{
- float s = sqrtf(1.0f + mat.m5 - mat.m0 - mat.m10)*2;
- result.x = (mat.m4 + mat.m1)/s;
- result.y = 0.25f*s;
- result.z = (mat.m9 + mat.m6)/s;
- result.w = (mat.m2 - mat.m8)/s;
+ fourBiggestSquaredMinus1 = fourZSquaredMinus1;
+ biggestIndex = 3;
}
- else
+
+ float biggestVal = sqrtf(fourBiggestSquaredMinus1 + 1.0f) * 0.5f;
+ float mult = 0.25f / biggestVal;
+
+ switch (biggestIndex)
{
- float s = sqrtf(1.0f + mat.m10 - mat.m0 - mat.m5)*2;
- result.x = (mat.m2 + mat.m8)/s;
- result.y = (mat.m9 + mat.m6)/s;
- result.z = 0.25f*s;
- result.w = (mat.m4 - mat.m1)/s;
+ case 0:
+ result.w = biggestVal;
+ result.x = (mat.m6 - mat.m9) * mult;
+ result.y = (mat.m8 - mat.m2) * mult;
+ result.z = (mat.m1 - mat.m4) * mult;
+ break;
+ case 1:
+ result.x = biggestVal;
+ result.w = (mat.m6 - mat.m9) * mult;
+ result.y = (mat.m1 + mat.m4) * mult;
+ result.z = (mat.m8 + mat.m2) * mult;
+ break;
+ case 2:
+ result.y = biggestVal;
+ result.w = (mat.m8 - mat.m2) * mult;
+ result.x = (mat.m1 + mat.m4) * mult;
+ result.z = (mat.m6 + mat.m9) * mult;
+ break;
+ case 3:
+ result.z = biggestVal;
+ result.w = (mat.m1 - mat.m4) * mult;
+ result.x = (mat.m8 + mat.m2) * mult;
+ result.y = (mat.m6 + mat.m9) * mult;
+ break;
}
return result;
@@ -1706,7 +1952,7 @@ RMAPI Matrix QuaternionToMatrix(Quaternion q)
}
// Get rotation quaternion for an angle and axis
-// NOTE: angle must be provided in radians
+// NOTE: Angle must be provided in radians
RMAPI Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle)
{
Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f };
@@ -1754,7 +2000,7 @@ RMAPI Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle)
// Get the rotation angle and axis for a given quaternion
RMAPI void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle)
{
- if (fabs(q.w) > 1.0f)
+ if (fabsf(q.w) > 1.0f)
{
// QuaternionNormalize(q);
float length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
@@ -1847,4 +2093,19 @@ RMAPI Quaternion QuaternionTransform(Quaternion q, Matrix mat)
return result;
}
+// Check whether two given quaternions are almost equal
+RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
+{
+ int result = (((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
+ ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
+ ((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z))))) &&
+ ((fabsf(p.w - q.w)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.w), fabsf(q.w)))))) ||
+ (((fabsf(p.x + q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
+ ((fabsf(p.y + q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
+ ((fabsf(p.z + q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z))))) &&
+ ((fabsf(p.w + q.w)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.w), fabsf(q.w))))));
+
+ return result;
+}
+
#endif // RAYMATH_H
diff --git a/include/rlgl.h b/include/rlgl.h
index 0b74014..2fa604d 100644
--- a/include/rlgl.h
+++ b/include/rlgl.h
@@ -85,7 +85,7 @@
*
* LICENSE: zlib/libpng
*
-* Copyright (c) 2014-2021 Ramon Santamaria (@raysan5)
+* Copyright (c) 2014-2022 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
@@ -358,11 +358,11 @@ typedef struct rlRenderBatch {
float currentDepth; // Current depth value for next draw
} rlRenderBatch;
-#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
+#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
#include <stdbool.h>
#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE)
// Boolean type
- typedef enum bool { false, true } bool;
+typedef enum bool { false = 0, true = !false } bool;
#endif
#if !defined(RL_MATRIX_TYPE)
@@ -433,7 +433,8 @@ typedef enum {
RL_BLEND_MULTIPLIED, // Blend textures multiplying colors
RL_BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
RL_BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
- RL_BLEND_CUSTOM // Belnd textures using custom src/dst factors (use SetBlendModeCustom())
+ RL_BLEND_ALPHA_PREMULTIPLY, // Blend premultiplied textures considering alpha
+ RL_BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendFactors())
} rlBlendMode;
// Shader location point type
@@ -597,7 +598,9 @@ RLAPI void rlglInit(int width, int height); // Initialize rlgl (buffer
RLAPI void rlglClose(void); // De-inititialize rlgl (buffers, shaders, textures)
RLAPI void rlLoadExtensions(void *loader); // Load OpenGL extensions (loader function required)
RLAPI int rlGetVersion(void); // Get current OpenGL version
+RLAPI void rlSetFramebufferWidth(int width); // Set current framebuffer width
RLAPI int rlGetFramebufferWidth(void); // Get default framebuffer width
+RLAPI void rlSetFramebufferHeight(int height); // Set current framebuffer height
RLAPI int rlGetFramebufferHeight(void); // Get default framebuffer height
RLAPI unsigned int rlGetTextureIdDefault(void); // Get default texture id
@@ -619,25 +622,26 @@ RLAPI void rlSetTexture(unsigned int id); // Set current texture for r
// Vertex buffers management
RLAPI unsigned int rlLoadVertexArray(void); // Load vertex array (vao) if supported
-RLAPI unsigned int rlLoadVertexBuffer(void *buffer, int size, bool dynamic); // Load a vertex buffer attribute
-RLAPI unsigned int rlLoadVertexBufferElement(void *buffer, int size, bool dynamic); // Load a new attributes element buffer
-RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, void *data, int dataSize, int offset); // Update GPU buffer with new data
+RLAPI unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic); // Load a vertex buffer attribute
+RLAPI unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic); // Load a new attributes element buffer
+RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset); // Update GPU buffer with new data
+RLAPI void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset); // Update vertex buffer elements with new data
RLAPI void rlUnloadVertexArray(unsigned int vaoId);
RLAPI void rlUnloadVertexBuffer(unsigned int vboId);
-RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, void *pointer);
+RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer);
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor);
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count); // Set vertex attribute default value
RLAPI void rlDrawVertexArray(int offset, int count);
-RLAPI void rlDrawVertexArrayElements(int offset, int count, void *buffer);
+RLAPI void rlDrawVertexArrayElements(int offset, int count, const void *buffer);
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances);
-RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, void *buffer, int instances);
+RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances);
// Textures management
-RLAPI unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
+RLAPI unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
-RLAPI unsigned int rlLoadTextureCubemap(void *data, int size, int format); // Load texture cubemap
+RLAPI unsigned int rlLoadTextureCubemap(const void *data, int size, int format); // Load texture cubemap
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update GPU texture with new data
-RLAPI void rlGetGlTextureFormats(int format, int *glInternalFormat, int *glFormat, int *glType); // Get OpenGL internal formats
+RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
RLAPI const char *rlGetPixelFormatName(unsigned int format); // Get name string for pixel format
RLAPI void rlUnloadTexture(unsigned int id); // Unload texture from GPU memory
RLAPI void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int *mipmaps); // Generate mipmap data for selected texture
@@ -713,7 +717,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
#include <OpenGL/glext.h> // OpenGL extensions library
#else
// APIENTRY for OpenGL function pointer declarations is required
- #ifndef APIENTRY
+ #if !defined(APIENTRY)
#if defined(_WIN32)
#define APIENTRY __stdcall
#else
@@ -925,8 +929,8 @@ typedef struct rlglData {
int glBlendDstFactor; // Blending destination factor
int glBlendEquation; // Blending equation
- int framebufferWidth; // Default framebuffer width
- int framebufferHeight; // Default framebuffer height
+ int framebufferWidth; // Current framebuffer width
+ int framebufferHeight; // Current framebuffer height
} State; // Renderer state
struct {
@@ -1228,6 +1232,7 @@ void rlOrtho(double left, double right, double bottom, double top, double znear,
#endif
// Set the viewport area (transformation from normalized device coordinates to window coordinates)
+// NOTE: We store current viewport dimensions
void rlViewport(int x, int y, int width, int height)
{
glViewport(x, y, width, height);
@@ -1512,6 +1517,11 @@ void rlTextureParameters(unsigned int id, int param, int value)
{
glBindTexture(GL_TEXTURE_2D, id);
+#if !defined(GRAPHICS_API_OPENGL_11)
+ // Reset anisotropy filter, in case it was set
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
+#endif
+
switch (param)
{
case RL_TEXTURE_WRAP_S:
@@ -1535,7 +1545,7 @@ void rlTextureParameters(unsigned int id, int param, int value)
if (value <= RLGL.ExtSupported.maxAnisotropyLevel) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)value);
else if (RLGL.ExtSupported.maxAnisotropyLevel > 0.0f)
{
- TRACELOG(RL_LOG_WARNING, "GL: Maximum anisotropic filter level supported is %iX", id, RLGL.ExtSupported.maxAnisotropyLevel);
+ TRACELOG(RL_LOG_WARNING, "GL: Maximum anisotropic filter level supported is %iX", id, (int)RLGL.ExtSupported.maxAnisotropyLevel);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)value);
}
else TRACELOG(RL_LOG_WARNING, "GL: Anisotropic filtering not supported");
@@ -1778,7 +1788,12 @@ void rlSetBlendMode(int mode)
case RL_BLEND_MULTIPLIED: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_ADD_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_SUBTRACT_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_SUBTRACT); break;
- case RL_BLEND_CUSTOM: glBlendFunc(RLGL.State.glBlendSrcFactor, RLGL.State.glBlendDstFactor); glBlendEquation(RLGL.State.glBlendEquation); break;
+ case RL_BLEND_ALPHA_PREMULTIPLY: glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
+ case RL_BLEND_CUSTOM:
+ {
+ // NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors()
+ glBlendFunc(RLGL.State.glBlendSrcFactor, RLGL.State.glBlendDstFactor); glBlendEquation(RLGL.State.glBlendEquation);
+ } break;
default: break;
}
@@ -2212,6 +2227,22 @@ int rlGetVersion(void)
return glVersion;
}
+// Set current framebuffer width
+void rlSetFramebufferWidth(int width)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ RLGL.State.framebufferWidth = width;
+#endif
+}
+
+// Set current framebuffer height
+void rlSetFramebufferHeight(int height)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ RLGL.State.framebufferHeight = height;
+#endif
+}
+
// Get default framebuffer width
int rlGetFramebufferWidth(void)
{
@@ -2594,6 +2625,9 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
glUseProgram(0); // Unbind shader program
}
+
+ // Restore viewport to default measures
+ if (eyeCount == 2) rlViewport(0, 0, RLGL.State.framebufferWidth, RLGL.State.framebufferHeight);
//------------------------------------------------------------------------------------------------------------
// Reset batch buffers
@@ -2676,7 +2710,7 @@ bool rlCheckRenderBatchLimit(int vCount)
// Textures data management
//-----------------------------------------------------------------------------------------
// Convert image data to OpenGL texture (returns OpenGL valid Id)
-unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount)
+unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount)
{
glBindTexture(GL_TEXTURE_2D, 0); // Free any old binding
@@ -2738,7 +2772,7 @@ unsigned int rlLoadTexture(void *data, int width, int height, int format, int mi
{
unsigned int mipSize = rlGetPixelDataSize(mipWidth, mipHeight, format);
- int glInternalFormat, glFormat, glType;
+ unsigned int glInternalFormat, glFormat, glType;
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
TRACELOGD("TEXTURE: Load mipmap level %i (%i x %i), size: %i, offset: %i", i, mipWidth, mipHeight, mipSize, mipOffset);
@@ -2878,7 +2912,7 @@ unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer)
// Load texture cubemap
// NOTE: Cubemap data is expected to be 6 images in a single data array (one after the other),
// expected the following convention: +X, -X, +Y, -Y, +Z, -Z
-unsigned int rlLoadTextureCubemap(void *data, int size, int format)
+unsigned int rlLoadTextureCubemap(const void *data, int size, int format)
{
unsigned int id = 0;
@@ -2888,7 +2922,7 @@ unsigned int rlLoadTextureCubemap(void *data, int size, int format)
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
- int glInternalFormat, glFormat, glType;
+ unsigned int glInternalFormat, glFormat, glType;
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
if (glInternalFormat != -1)
@@ -2960,7 +2994,7 @@ void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int h
{
glBindTexture(GL_TEXTURE_2D, id);
- int glInternalFormat, glFormat, glType;
+ unsigned int glInternalFormat, glFormat, glType;
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
if ((glInternalFormat != -1) && (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB))
@@ -2971,11 +3005,11 @@ void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int h
}
// Get OpenGL internal formats and data type from raylib PixelFormat
-void rlGetGlTextureFormats(int format, int *glInternalFormat, int *glFormat, int *glType)
+void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType)
{
- *glInternalFormat = -1;
- *glFormat = -1;
- *glType = -1;
+ *glInternalFormat = 0;
+ *glFormat = 0;
+ *glType = 0;
switch (format)
{
@@ -3081,14 +3115,11 @@ void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
if ((texIsPOT) || (RLGL.ExtSupported.texNPOT))
{
- //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorythm: GL_FASTEST, GL_NICEST, GL_DONT_CARE
+ //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorithm: GL_FASTEST, GL_NICEST, GL_DONT_CARE
glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate Trilinear filtering for mipmaps
-
- #define MIN(a,b) (((a)<(b))?(a):(b))
- #define MAX(a,b) (((a)>(b))?(a):(b))
+ #define MIN(a,b) (((a)<(b))? (a):(b))
+ #define MAX(a,b) (((a)>(b))? (a):(b))
*mipmaps = 1 + (int)floor(log(MAX(width, height))/log(2));
TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Mipmaps generated automatically, total: %i", id, *mipmaps);
@@ -3121,7 +3152,7 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
// GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.)
glPixelStorei(GL_PACK_ALIGNMENT, 1);
- int glInternalFormat, glFormat, glType;
+ unsigned int glInternalFormat, glFormat, glType;
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
unsigned int size = rlGetPixelDataSize(width, height, format);
@@ -3164,7 +3195,6 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
return pixels;
}
-
// Read screen pixel data (color buffer)
unsigned char *rlReadScreenPixels(int width, int height)
{
@@ -3313,7 +3343,7 @@ void rlUnloadFramebuffer(unsigned int id)
// Vertex data management
//-----------------------------------------------------------------------------------------
// Load a new attributes buffer
-unsigned int rlLoadVertexBuffer(void *buffer, int size, bool dynamic)
+unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic)
{
unsigned int id = 0;
@@ -3327,7 +3357,7 @@ unsigned int rlLoadVertexBuffer(void *buffer, int size, bool dynamic)
}
// Load a new attributes element buffer
-unsigned int rlLoadVertexBufferElement(void *buffer, int size, bool dynamic)
+unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic)
{
unsigned int id = 0;
@@ -3374,7 +3404,7 @@ void rlDisableVertexBufferElement(void)
// Update vertex buffer with new data
// NOTE: dataSize and offset must be provided in bytes
-void rlUpdateVertexBuffer(unsigned int id, void *data, int dataSize, int offset)
+void rlUpdateVertexBuffer(unsigned int id, const void *data, int dataSize, int offset)
{
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
glBindBuffer(GL_ARRAY_BUFFER, id);
@@ -3384,7 +3414,7 @@ void rlUpdateVertexBuffer(unsigned int id, void *data, int dataSize, int offset)
// Update vertex buffer elements with new data
// NOTE: dataSize and offset must be provided in bytes
-void rlUpdateVertexBufferElements(unsigned int id, void *data, int dataSize, int offset)
+void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset)
{
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
@@ -3437,9 +3467,9 @@ void rlDrawVertexArray(int offset, int count)
}
// Draw vertex array elements
-void rlDrawVertexArrayElements(int offset, int count, void *buffer)
+void rlDrawVertexArrayElements(int offset, int count, const void *buffer)
{
- glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (unsigned short *)buffer + offset);
+ glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (const unsigned short *)buffer + offset);
}
// Draw vertex array instanced
@@ -3451,10 +3481,10 @@ void rlDrawVertexArrayInstanced(int offset, int count, int instances)
}
// Draw vertex array elements instanced
-void rlDrawVertexArrayElementsInstanced(int offset, int count, void *buffer, int instances)
+void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances)
{
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
- glDrawElementsInstanced(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (unsigned short *)buffer + offset, instances);
+ glDrawElementsInstanced(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (const unsigned short *)buffer + offset, instances);
#endif
}
@@ -3495,7 +3525,7 @@ unsigned int rlLoadVertexArray(void)
}
// Set vertex attribute
-void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, void *pointer)
+void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer)
{
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
glVertexAttribPointer(index, compSize, type, normalized, stride, pointer);
@@ -3541,56 +3571,69 @@ unsigned int rlLoadShaderCode(const char *vsCode, const char *fsCode)
unsigned int id = 0;
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
- unsigned int vertexShaderId = RLGL.State.defaultVShaderId;
- unsigned int fragmentShaderId = RLGL.State.defaultFShaderId;
+ unsigned int vertexShaderId = 0;
+ unsigned int fragmentShaderId = 0;
+ // Compile vertex shader (if provided)
if (vsCode != NULL) vertexShaderId = rlCompileShader(vsCode, GL_VERTEX_SHADER);
+ // In case no vertex shader was provided or compilation failed, we use default vertex shader
+ if (vertexShaderId == 0) vertexShaderId = RLGL.State.defaultVShaderId;
+
+ // Compile fragment shader (if provided)
if (fsCode != NULL) fragmentShaderId = rlCompileShader(fsCode, GL_FRAGMENT_SHADER);
+ // In case no fragment shader was provided or compilation failed, we use default fragment shader
+ if (fragmentShaderId == 0) fragmentShaderId = RLGL.State.defaultFShaderId;
+ // In case vertex and fragment shader are the default ones, no need to recompile, we can just assign the default shader program id
if ((vertexShaderId == RLGL.State.defaultVShaderId) && (fragmentShaderId == RLGL.State.defaultFShaderId)) id = RLGL.State.defaultShaderId;
else
{
+ // One of or both shader are new, we need to compile a new shader program
id = rlLoadShaderProgram(vertexShaderId, fragmentShaderId);
+ // We can detach and delete vertex/fragment shaders (if not default ones)
+ // NOTE: We detach shader before deletion to make sure memory is freed
if (vertexShaderId != RLGL.State.defaultVShaderId)
{
- // Detach shader before deletion to make sure memory is freed
glDetachShader(id, vertexShaderId);
glDeleteShader(vertexShaderId);
}
if (fragmentShaderId != RLGL.State.defaultFShaderId)
{
- // Detach shader before deletion to make sure memory is freed
glDetachShader(id, fragmentShaderId);
glDeleteShader(fragmentShaderId);
}
+ // In case shader program loading failed, we assign default shader
if (id == 0)
{
- TRACELOG(RL_LOG_WARNING, "SHADER: Failed to load custom shader code");
+ // In case shader loading fails, we return the default shader
+ TRACELOG(RL_LOG_WARNING, "SHADER: Failed to load custom shader code, using default shader");
id = RLGL.State.defaultShaderId;
}
- }
-
- // Get available shader uniforms
- // NOTE: This information is useful for debug...
- int uniformCount = -1;
-
- glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &uniformCount);
-
- for (int i = 0; i < uniformCount; i++)
- {
- int namelen = -1;
- int num = -1;
- char name[256] = { 0 }; // Assume no variable names longer than 256
- GLenum type = GL_ZERO;
+ /*
+ else
+ {
+ // Get available shader uniforms
+ // NOTE: This information is useful for debug...
+ int uniformCount = -1;
+ glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &uniformCount);
- // Get the name of the uniforms
- glGetActiveUniform(id, i, sizeof(name) - 1, &namelen, &num, &type, name);
+ for (int i = 0; i < uniformCount; i++)
+ {
+ int namelen = -1;
+ int num = -1;
+ char name[256] = { 0 }; // Assume no variable names longer than 256
+ GLenum type = GL_ZERO;
- name[namelen] = 0;
+ // Get the name of the uniforms
+ glGetActiveUniform(id, i, sizeof(name) - 1, &namelen, &num, &type, name);
- TRACELOGD("SHADER: [ID %i] Active uniform (%s) set at location: %i", id, name, glGetUniformLocation(id, name));
+ name[namelen] = 0;
+ TRACELOGD("SHADER: [ID %i] Active uniform (%s) set at location: %i", id, name, glGetUniformLocation(id, name));
+ }
+ }
+ */
}
#endif
@@ -3629,7 +3672,7 @@ unsigned int rlCompileShader(const char *shaderCode, int type)
if (maxLength > 0)
{
int length = 0;
- char *log = RL_CALLOC(maxLength, sizeof(char));
+ char *log = (char *)RL_CALLOC(maxLength, sizeof(char));
glGetShaderInfoLog(shader, maxLength, &length, log);
TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Compile error: %s", shader, log);
RL_FREE(log);
@@ -3691,7 +3734,7 @@ unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId)
if (maxLength > 0)
{
int length = 0;
- char *log = RL_CALLOC(maxLength, sizeof(char));
+ char *log = (char *)RL_CALLOC(maxLength, sizeof(char));
glGetProgramInfoLog(program, maxLength, &length, log);
TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Link error: %s", program, log);
RL_FREE(log);
@@ -3858,7 +3901,7 @@ unsigned int rlLoadComputeShaderProgram(unsigned int shaderId)
if (maxLength > 0)
{
int length = 0;
- char *log = RL_CALLOC(maxLength, sizeof(char));
+ char *log = (char *)RL_CALLOC(maxLength, sizeof(char));
glGetProgramInfoLog(program, maxLength, &length, log);
TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Link error: %s", program, log);
RL_FREE(log);
@@ -3894,7 +3937,7 @@ void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned
unsigned int rlLoadShaderBuffer(unsigned long long size, const void *data, int usageHint)
{
unsigned int ssbo = 0;
-
+
#if defined(GRAPHICS_API_OPENGL_43)
glGenBuffers(1, &ssbo);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
@@ -3927,7 +3970,7 @@ void rlUpdateShaderBufferElements(unsigned int id, const void *data, unsigned lo
unsigned long long rlGetShaderBufferSize(unsigned int id)
{
long long size = 0;
-
+
#if defined(GRAPHICS_API_OPENGL_43)
glBindBuffer(GL_SHADER_STORAGE_BUFFER, id);
glGetInteger64v(GL_SHADER_STORAGE_BUFFER_SIZE, &size);
@@ -3967,7 +4010,7 @@ void rlCopyBuffersElements(unsigned int destId, unsigned int srcId, unsigned lon
void rlBindImageTexture(unsigned int id, unsigned int index, unsigned int format, int readonly)
{
#if defined(GRAPHICS_API_OPENGL_43)
- int glInternalFormat = 0, glFormat = 0, glType = 0;
+ unsigned int glInternalFormat = 0, glFormat = 0, glType = 0;
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
glBindImageTexture(index, id, 0, 0, 0, readonly ? GL_READ_ONLY : GL_READ_WRITE, glInternalFormat);
@@ -4338,7 +4381,8 @@ static void rlLoadShaderDefault(void)
"} \n";
#endif
- // NOTE: Compiled vertex/fragment shaders are kept for re-use
+ // NOTE: Compiled vertex/fragment shaders are not deleted,
+ // they are kept for re-use as default shaders in case some shader loading fails
RLGL.State.defaultVShaderId = rlCompileShader(defaultVShaderCode, GL_VERTEX_SHADER); // Compile default vertex shader
RLGL.State.defaultFShaderId = rlCompileShader(defaultFShaderCode, GL_FRAGMENT_SHADER); // Compile default fragment shader