summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2025-08-30 16:41:05 +0300
committerjussi2025-08-30 16:41:05 +0300
commitde672a85d2778c47fce0d412cea787405388330c (patch)
treefcae06a78397f52bc819c99cdbeaa417c48cf57b
parent15deeccc4bcbe5b68f002f8cc91ee4ed8ced68fb (diff)
downloadreilua-enhanced-de672a85d2778c47fce0d412cea787405388330c.tar.gz
reilua-enhanced-de672a85d2778c47fce0d412cea787405388330c.tar.bz2
reilua-enhanced-de672a85d2778c47fce0d412cea787405388330c.zip
DrawMeshInstanced takes transforms as Buffer.
-rw-r--r--API.md8
-rw-r--r--README.md3
-rw-r--r--ReiLua_API.lua8
-rw-r--r--changelog1
-rw-r--r--examples/instancing/main.lua15
-rw-r--r--examples/resources/lib/matrix.lua9
-rw-r--r--src/core.c43
-rw-r--r--src/models.c18
-rw-r--r--src/platforms/core_desktop_glfw.c1
9 files changed, 50 insertions, 56 deletions
diff --git a/API.md b/API.md
index 0aaf35f..2d46f87 100644
--- a/API.md
+++ b/API.md
@@ -5726,7 +5726,7 @@ Decode Base64 string data
> code = RL.ComputeCRC32( Buffer data )
-Compute CRC32 hash code. Note! Buffer should be type BUFFER_UNSIGNED_CHAR
+Compute CRC32 hash code.
- Failure return false
- Success return int
@@ -5735,7 +5735,7 @@ Compute CRC32 hash code. Note! Buffer should be type BUFFER_UNSIGNED_CHAR
> code = RL.ComputeMD5( Buffer data )
-Compute MD5 hash code, returns static int[4] (16 bytes). Note! Buffer should be type BUFFER_UNSIGNED_CHAR
+Compute MD5 hash code, returns static int[4] (16 bytes).
- Failure return false
- Success return int{4}
@@ -5744,7 +5744,7 @@ Compute MD5 hash code, returns static int[4] (16 bytes). Note! Buffer should be
> code = RL.ComputeSHA1( Buffer data )
-Compute SHA1 hash code, returns static int[5] (20 bytes). Note! Buffer should be type BUFFER_UNSIGNED_CHAR
+Compute SHA1 hash code, returns static int[5] (20 bytes).
- Failure return false
- Success return int{5}
@@ -8746,7 +8746,7 @@ Draw a 3d mesh with material and transform
---
-> RL.DrawMeshInstanced( Mesh mesh, Material material, Matrix{} transforms, int instances )
+> RL.DrawMeshInstanced( Mesh mesh, Material material, Buffer transforms, int instances )
Draw multiple mesh instances with material and different transforms
diff --git a/README.md b/README.md
index e7a5bc5..1f5772a 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,9 @@ List of some MISSING features that are planned to be included. For specific func
* v0.9
+* v1.0
+ * raylib 6.0
+
## Usage
Application needs 'main.lua' or 'main' file as entry point. ReiLua executable will first look it from same directory. Alternatively, path to the folder where "main.lua" is located can be given as argument. There are seven Lua functions that the framework will call, 'RL.init', 'RL.update', 'RL.draw', 'RL.event', 'RL.log', 'RL.exit' and 'RL.config'.
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 47e696e..e5640d6 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -2349,21 +2349,21 @@ function RL.EncodeDataBase64( data ) end
---@return any outputSize
function RL.DecodeDataBase64( data ) end
----Compute CRC32 hash code. Note! Buffer should be type BUFFER_UNSIGNED_CHAR
+---Compute CRC32 hash code.
---- Failure return false
---- Success return int
---@param data any
---@return any code
function RL.ComputeCRC32( data ) end
----Compute MD5 hash code, returns static int[4] (16 bytes). Note! Buffer should be type BUFFER_UNSIGNED_CHAR
+---Compute MD5 hash code, returns static int[4] (16 bytes).
---- Failure return false
---- Success return int{4}
---@param data any
---@return any code
function RL.ComputeMD5( data ) end
----Compute SHA1 hash code, returns static int[5] (20 bytes). Note! Buffer should be type BUFFER_UNSIGNED_CHAR
+---Compute SHA1 hash code, returns static int[5] (20 bytes).
---- Failure return false
---- Success return int{5}
---@param data any
@@ -5250,7 +5250,7 @@ function RL.DrawMesh( mesh, material, transform ) end
---Draw multiple mesh instances with material and different transforms
---@param mesh any
---@param material any
----@param transforms table
+---@param transforms any
---@param instances integer
---@return any RL.DrawMeshInstanced
function RL.DrawMeshInstanced( mesh, material, transforms, instances ) end
diff --git a/changelog b/changelog
index 0ffd8f2..4e7c33c 100644
--- a/changelog
+++ b/changelog
@@ -55,6 +55,7 @@ DETAILED CHANGES:
- FIXED: uluaGet* pops lua stack correctly when userdata given in table.
- ADDED: MeasureTextBoxed.
- CHANGE: DrawTextBoxedEx to DrawTextBoxed.
+ - CHANGE: DrawMeshInstanced takes transforms as Buffer. Much better performance.
------------------------------------------------------------------------
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
diff --git a/examples/instancing/main.lua b/examples/instancing/main.lua
index 1966479..9e14383 100644
--- a/examples/instancing/main.lua
+++ b/examples/instancing/main.lua
@@ -8,10 +8,14 @@
Modified by Jussi Viitala (@nullstare) for ReiLua style.
]]
+package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
+
+Matrix = require( "matrix" )
+
local MAX_INSTANCES = 10000
local cube
-local transforms = {}
+local transformsBuf
local camera
local shader
@@ -41,6 +45,9 @@ function RL.init()
-- Define mesh to be instanced
cube = RL.GenMeshCube( { 1, 1, 1 } )
+ transformsBuf = RL.LoadBufferFormatted( MAX_INSTANCES * 16, RL.BUFFER_FLOAT, 0 )
+ local bufPos = 0
+
-- Translate and rotate cubes randomly
for i = 1, MAX_INSTANCES do
local translation = RL.MatrixTranslate( { math.random( -50, 50 ), math.random( -50, 50 ), math.random( -50, 50 ) } )
@@ -48,7 +55,8 @@ function RL.init()
local angle = math.rad( math.random( 0, 10 ) )
local rotation = RL.MatrixRotate( axis, angle )
- table.insert( transforms, RL.MatrixMultiply( rotation, translation ) )
+ RL.SetBufferData( transformsBuf, bufPos, Matrix:temp( RL.MatrixMultiply( rotation, translation ) ):arr() )
+ bufPos = bufPos + 16
end
-- Load lighting shader
@@ -101,7 +109,7 @@ function RL.draw()
-- Draw meshes instanced using material containing instancing shader (RED + lighting),
-- transforms[] for the instances should be provided, they are dynamically
-- updated in GPU every frame, so we can animate the different mesh instances
- RL.DrawMeshInstanced( cube, matInstances, transforms, MAX_INSTANCES )
+ RL.DrawMeshInstanced( cube, matInstances, transformsBuf, MAX_INSTANCES )
-- Draw cube mesh with default material (BLUE)
RL.DrawMesh( cube, matDefault, RL.MatrixTranslate( { 10.0, 0.0, 0.0 } ) )
@@ -113,4 +121,5 @@ end
function RL.exit()
RL.UnloadMaterial( matInstances, true )
RL.UnloadMesh( cube )
+ RL.UnloadBuffer( transformsBuf )
end
diff --git a/examples/resources/lib/matrix.lua b/examples/resources/lib/matrix.lua
index 2ed0ffb..d540d28 100644
--- a/examples/resources/lib/matrix.lua
+++ b/examples/resources/lib/matrix.lua
@@ -58,6 +58,15 @@ function Matrix:set( m )
self:copyMatrix( m )
end
+function Matrix:arr()
+ return {
+ self[1][1], self[2][1], self[3][1], self[4][1],
+ self[1][2], self[2][2], self[3][2], self[4][2],
+ self[1][3], self[2][3], self[3][3], self[4][3],
+ self[1][4], self[2][4], self[3][4], self[4][4],
+ }
+end
+
function Matrix:serialize()
local str = { "Matrix:new({" }
diff --git a/src/core.c b/src/core.c
index 2f19e2d..4cbd551 100644
--- a/src/core.c
+++ b/src/core.c
@@ -2201,7 +2201,7 @@ int lcoreDecodeDataBase64( lua_State* L ) {
/*
> code = RL.ComputeCRC32( Buffer data )
-Compute CRC32 hash code. Note! Buffer should be type BUFFER_UNSIGNED_CHAR
+Compute CRC32 hash code.
- Failure return false
- Success return int
@@ -2209,12 +2209,7 @@ Compute CRC32 hash code. Note! Buffer should be type BUFFER_UNSIGNED_CHAR
int lcoreComputeCRC32( lua_State* L ) {
Buffer* buffer = uluaGetBuffer( L, 1 );
- if ( buffer->type == BUFFER_UNSIGNED_CHAR ) {
- lua_pushinteger( L, ComputeCRC32( buffer->data, buffer->size ) );
- }
- else {
- lua_pushboolean( L, false );
- }
+ lua_pushinteger( L, ComputeCRC32( buffer->data, buffer->size ) );
return 1;
}
@@ -2222,7 +2217,7 @@ int lcoreComputeCRC32( lua_State* L ) {
/*
> code = RL.ComputeMD5( Buffer data )
-Compute MD5 hash code, returns static int[4] (16 bytes). Note! Buffer should be type BUFFER_UNSIGNED_CHAR
+Compute MD5 hash code, returns static int[4] (16 bytes).
- Failure return false
- Success return int{4}
@@ -2230,17 +2225,12 @@ Compute MD5 hash code, returns static int[4] (16 bytes). Note! Buffer should be
int lcoreComputeMD5( lua_State* L ) {
Buffer* buffer = uluaGetBuffer( L, 1 );
- if ( buffer->type == BUFFER_UNSIGNED_CHAR ) {
- unsigned int* code = ComputeMD5( buffer->data, buffer->size );
- lua_createtable( L, 4, 0 );
+ unsigned int* code = ComputeMD5( buffer->data, buffer->size );
+ lua_createtable( L, 4, 0 );
- for ( unsigned int i = 0; i < 4; i++ ) {
- lua_pushinteger( L, code[i] );
- lua_rawseti( L, -2, i + 1 );
- }
- }
- else {
- lua_pushboolean( L, false );
+ for ( unsigned int i = 0; i < 4; i++ ) {
+ lua_pushinteger( L, code[i] );
+ lua_rawseti( L, -2, i + 1 );
}
return 1;
@@ -2249,7 +2239,7 @@ int lcoreComputeMD5( lua_State* L ) {
/*
> code = RL.ComputeSHA1( Buffer data )
-Compute SHA1 hash code, returns static int[5] (20 bytes). Note! Buffer should be type BUFFER_UNSIGNED_CHAR
+Compute SHA1 hash code, returns static int[5] (20 bytes).
- Failure return false
- Success return int{5}
@@ -2257,17 +2247,12 @@ Compute SHA1 hash code, returns static int[5] (20 bytes). Note! Buffer should be
int lcoreComputeSHA1( lua_State* L ) {
Buffer* buffer = uluaGetBuffer( L, 1 );
- if ( buffer->type == BUFFER_UNSIGNED_CHAR ) {
- unsigned int* code = ComputeSHA1( buffer->data, buffer->size );
- lua_createtable( L, 5, 0 );
+ unsigned int* code = ComputeSHA1( buffer->data, buffer->size );
+ lua_createtable( L, 5, 0 );
- for ( unsigned int i = 0; i < 5; i++ ) {
- lua_pushinteger( L, code[i] );
- lua_rawseti( L, -2, i + 1 );
- }
- }
- else {
- lua_pushboolean( L, false );
+ for ( unsigned int i = 0; i < 5; i++ ) {
+ lua_pushinteger( L, code[i] );
+ lua_rawseti( L, -2, i + 1 );
}
return 1;
diff --git a/src/models.c b/src/models.c
index cee92bc..8040388 100644
--- a/src/models.c
+++ b/src/models.c
@@ -1145,29 +1145,17 @@ int lmodelsDrawMesh( lua_State* L ) {
}
/*
-> RL.DrawMeshInstanced( Mesh mesh, Material material, Matrix{} transforms, int instances )
+> RL.DrawMeshInstanced( Mesh mesh, Material material, Buffer transforms, int instances )
Draw multiple mesh instances with material and different transforms
*/
int lmodelsDrawMeshInstanced( lua_State* L ) {
Mesh* mesh = uluaGetMesh( L, 1 );
Material* material = uluaGetMaterial( L, 2 );
- luaL_checktype( L, 3, LUA_TTABLE );
+ Buffer* transforms = uluaGetBuffer( L, 3 );
int instances = luaL_checkinteger( L, 4 );
- Matrix transforms[ instances ];
-
- int t = 3, i = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t ) != 0 ) {
- if ( lua_istable( L, -1 ) ) {
- transforms[i] = uluaGetMatrix( L, lua_gettop( L ) );
- }
- i++;
- lua_pop( L, 1 );
- }
- DrawMeshInstanced( *mesh, *material, transforms, instances );
+ DrawMeshInstanced( *mesh, *material, (Matrix*)transforms->data, instances );
return 0;
}
diff --git a/src/platforms/core_desktop_glfw.c b/src/platforms/core_desktop_glfw.c
index 8d9f01c..3bb7c03 100644
--- a/src/platforms/core_desktop_glfw.c
+++ b/src/platforms/core_desktop_glfw.c
@@ -99,7 +99,6 @@ int lcoreGetKeyScancode( lua_State* L ) {
Called when the window is resized. Type GLFW_WINDOW_SIZE_EVENT
*/
static void windowSizeEvent( GLFWwindow* window, int width, int height ) {
-// GLFWwindowsizefun windowSizeEvent( GLFWwindow* window, int width, int height ) {
/* Pass through to raylib callback. */
state->raylibWindowSizeCallback( window, width, height );