summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2025-01-31 15:26:20 +0200
committerjussi2025-01-31 15:26:20 +0200
commit38d41e245782e3dde02dc7717737af09da31ce93 (patch)
tree10982ef4f94fb2898b6abd45692a394e4eff76b1
parentc8131ea95846f76fb196a78ce9c9b09aeb15736c (diff)
downloadreilua-enhanced-38d41e245782e3dde02dc7717737af09da31ce93.tar.gz
reilua-enhanced-38d41e245782e3dde02dc7717737af09da31ce93.tar.bz2
reilua-enhanced-38d41e245782e3dde02dc7717737af09da31ce93.zip
UpdateTexture and UpdateTextureRec now take pixel data as Buffer.
-rw-r--r--API.md6
-rw-r--r--ReiLua_API.lua6
-rw-r--r--changelog1
-rw-r--r--src/textures.c62
4 files changed, 11 insertions, 64 deletions
diff --git a/API.md b/API.md
index bd54ad5..f1bf974 100644
--- a/API.md
+++ b/API.md
@@ -7611,17 +7611,15 @@ Unload render texture from GPU memory (VRAM)
---
-> RL.UpdateTexture( Texture texture, int{} pixels )
+> RL.UpdateTexture( Texture texture, Buffer pixels )
Update GPU texture with new data
-NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
---
-> RL.UpdateTextureRec( Texture texture, Rectangle rec, int{} pixels )
+> RL.UpdateTextureRec( Texture texture, Rectangle rec, Buffer pixels )
Update GPU texture rectangle with new data.
-Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 4621123..47e4903 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -4133,17 +4133,15 @@ function RL.IsRenderTextureValid( target ) end
function RL.UnloadRenderTexture( target ) end
---Update GPU texture with new data
----NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
---@param texture any
----@param pixels table
+---@param pixels any
---@return any RL.UpdateTexture
function RL.UpdateTexture( texture, pixels ) end
---Update GPU texture rectangle with new data.
----Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
---@param texture any
---@param rec table
----@param pixels table
+---@param pixels any
---@return any RL.UpdateTextureRec
function RL.UpdateTextureRec( texture, rec, pixels ) end
diff --git a/changelog b/changelog
index 7202e6a..2ea7814 100644
--- a/changelog
+++ b/changelog
@@ -36,6 +36,7 @@ DETAILED CHANGES:
- FIXED: Bitwise functions now use 64 bit integers.
- CHANGE: SetBufferData takes table of values.
- ADDED: Texture atlas repeat example.
+ - CHANGE: UpdateTexture and UpdateTextureRec now take pixel data as Buffer.
------------------------------------------------------------------------
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
diff --git a/src/textures.c b/src/textures.c
index e185470..89b6e8f 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -1480,80 +1480,30 @@ int ltextureUnloadRenderTexture( lua_State* L ) {
}
/*
-> RL.UpdateTexture( Texture texture, int{} pixels )
+> RL.UpdateTexture( Texture texture, Buffer pixels )
Update GPU texture with new data
-NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
*/
int ltexturesUpdateTexture( lua_State* L ) {
Texture* texture = uluaGetTexture( L, 1 );
- size_t len = uluaGetTableLen( L, 2 );
+ Buffer* pixels = uluaGetBuffer( L, 2 );
- unsigned char* pixels = malloc( len * 4 * sizeof( unsigned char ) );
-
- int t = lua_gettop( L );
- unsigned int i = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t ) != 0 ) {
- size_t colLen = uluaGetTableLen( L, lua_gettop( L ) );
-
- int t2 = lua_gettop( L );
- unsigned int j = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t2 ) != 0 ) {
- *( pixels + ( i * colLen ) + j ) = lua_tointeger( L, -1 );
-
- j++;
- lua_pop( L, 1 );
- }
- i++;
- lua_pop( L, 1 );
- }
- UpdateTexture( *texture, pixels );
- free( pixels );
+ UpdateTexture( *texture, pixels->data );
return 0;
}
/*
-> RL.UpdateTextureRec( Texture texture, Rectangle rec, int{} pixels )
+> RL.UpdateTextureRec( Texture texture, Rectangle rec, Buffer pixels )
Update GPU texture rectangle with new data.
-Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
*/
int ltexturesUpdateTextureRec( lua_State* L ) {
Texture* texture = uluaGetTexture( L, 1 );
Rectangle rec = uluaGetRectangle( L, 2 );
- size_t len = uluaGetTableLen( L, 3 );
-
- unsigned char* pixels = malloc( len * 4 * sizeof( unsigned char ) );
-
- int t = lua_gettop( L );
- unsigned int i = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t ) != 0 ) {
- size_t colLen = uluaGetTableLen( L, lua_gettop( L ) );
-
- int t2 = lua_gettop( L );
- unsigned int j = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t2 ) != 0 ) {
- *( pixels + ( i * colLen ) + j ) = lua_tointeger( L, -1 );
-
- j++;
- lua_pop( L, 1 );
- }
- i++;
- lua_pop( L, 1 );
- }
- lua_pop( L, 1 ); /* Pixels arg. */
+ Buffer* pixels = uluaGetBuffer( L, 3 );
- UpdateTextureRec( *texture, rec, pixels );
- free( pixels );
+ UpdateTextureRec( *texture, rec, pixels->data );
return 0;
}