summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjussi2025-01-31 15:26:20 +0200
committerjussi2025-01-31 15:26:20 +0200
commit38d41e245782e3dde02dc7717737af09da31ce93 (patch)
tree10982ef4f94fb2898b6abd45692a394e4eff76b1 /src
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.
Diffstat (limited to 'src')
-rw-r--r--src/textures.c62
1 files changed, 6 insertions, 56 deletions
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;
}