diff options
| author | jussi | 2023-06-02 23:19:32 +0300 |
|---|---|---|
| committer | jussi | 2023-06-02 23:19:32 +0300 |
| commit | ed6d37294a6b72382cca09f6808565b61bd0c36b (patch) | |
| tree | e3d00f3b3e0c339d329274f27ed39cf21f3cafad | |
| parent | d550afa3d41e49c6cb215498db0eb547a628d578 (diff) | |
| download | reilua-enhanced-ed6d37294a6b72382cca09f6808565b61bd0c36b.tar.gz reilua-enhanced-ed6d37294a6b72382cca09f6808565b61bd0c36b.tar.bz2 reilua-enhanced-ed6d37294a6b72382cca09f6808565b61bd0c36b.zip | |
rlgl Some Render batch management functions and Matrix operations functions.
| -rw-r--r-- | API.md | 123 | ||||
| -rw-r--r-- | ReiLua_API.lua | 102 | ||||
| -rw-r--r-- | changelog | 7 | ||||
| -rw-r--r-- | devnotes | 9 | ||||
| -rw-r--r-- | include/lrlgl.h | 16 | ||||
| -rw-r--r-- | src/lua_core.c | 16 | ||||
| -rw-r--r-- | src/rlgl.c | 284 |
7 files changed, 553 insertions, 4 deletions
@@ -6833,6 +6833,101 @@ Get light enabled --- +## RLGL - Matrix operations + +--- + +> success = RL.rlMatrixMode( int mode ) + +Choose the current matrix to be transformed + +- Failure return false +- Success return true + +--- + +> RL.rlPushMatrix() + +Push the current matrix to stack + +--- + +> RL.rlPopMatrix() + +Pop latest inserted matrix from stack + +--- + +> RL.rlLoadIdentity() + +Reset current matrix to identity matrix + +--- + +> success = RL.rlTranslatef( Vector3 translation ) + +Multiply the current matrix by a translation matrix + +- Failure return false +- Success return true + +--- + +> success = RL.rlRotatef( float angle, Vector3 rotation ) + +Multiply the current matrix by a rotation matrix + +- Failure return false +- Success return true + +--- + +> success = RL.rlScalef( Vector3 scale ) + +Multiply the current matrix by a scaling matrix + +- Failure return false +- Success return true + +--- + +> success = RL.rlMultMatrixf( Matrix matrix ) + +Multiply the current matrix by another matrix + +- Failure return false +- Success return true + +--- + +> success = RL.rlFrustum( float left, float right, float bottom, float top, float znear, float zfar ) + +Multiply the current matrix by a perspective matrix generated by parameters + +- Failure return false +- Success return true + +--- + +> success = RL.rlOrtho( float left, float right, float bottom, float top, float znear, float zfar ) + +Multiply the current matrix by an orthographic matrix generated by parameters + +- Failure return false +- Success return true + +--- + +> success = RL.rlViewport( Rectangle viewport ) + +Set the viewport area ( transformation from normalized device coordinates to window coordinates ) +NOTE: We store current viewport dimensions + +- Failure return false +- Success return true + +--- + ## RLGL - Textures state --- @@ -7024,6 +7119,34 @@ Get current OpenGL version --- +## RLGL - Render batch management + +--- + +> RL.rlDrawRenderBatchActive() + +Update and draw internal render batch + +--- + +> overflow = RL.rlCheckRenderBatchLimit( int vCount ) + +Check internal buffer overflow for a given number of vertex and force a rlRenderBatch draw call if required + +- Failure return nil +- Success return bool + +--- + +> success = RL.rlSetTexture( int id ) + +Set current texture for render batch and check buffers limits + +- Failure return false +- Success return true + +--- + ## RLGL - Textures management --- diff --git a/ReiLua_API.lua b/ReiLua_API.lua index 990295e..f7e1bb8 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -5549,6 +5549,88 @@ function RL.GetLightColor( light ) end ---@return any enabled function RL.IsLightEnabled( light ) end +-- RLGL - Matrix operations + +---Choose the current matrix to be transformed +---- Failure return false +---- Success return true +---@param mode integer +---@return any success +function RL.rlMatrixMode( mode ) end + +---Push the current matrix to stack +---@return any RL.rlPushMatrix +function RL.rlPushMatrix() end + +---Pop latest inserted matrix from stack +---@return any RL.rlPopMatrix +function RL.rlPopMatrix() end + +---Reset current matrix to identity matrix +---@return any RL.rlLoadIdentity +function RL.rlLoadIdentity() end + +---Multiply the current matrix by a translation matrix +---- Failure return false +---- Success return true +---@param translation table +---@return any success +function RL.rlTranslatef( translation ) end + +---Multiply the current matrix by a rotation matrix +---- Failure return false +---- Success return true +---@param angle number +---@param rotation table +---@return any success +function RL.rlRotatef( angle, rotation ) end + +---Multiply the current matrix by a scaling matrix +---- Failure return false +---- Success return true +---@param scale table +---@return any success +function RL.rlScalef( scale ) end + +---Multiply the current matrix by another matrix +---- Failure return false +---- Success return true +---@param matrix table +---@return any success +function RL.rlMultMatrixf( matrix ) end + +---Multiply the current matrix by a perspective matrix generated by parameters +---- Failure return false +---- Success return true +---@param left number +---@param right number +---@param bottom number +---@param top number +---@param znear number +---@param zfar number +---@return any success +function RL.rlFrustum( left, right, bottom, top, znear, zfar ) end + +---Multiply the current matrix by an orthographic matrix generated by parameters +---- Failure return false +---- Success return true +---@param left number +---@param right number +---@param bottom number +---@param top number +---@param znear number +---@param zfar number +---@return any success +function RL.rlOrtho( left, right, bottom, top, znear, zfar ) end + +---Set the viewport area ( transformation from normalized device coordinates to window coordinates ) +---NOTE: We store current viewport dimensions +---- Failure return false +---- Success return true +---@param viewport table +---@return any success +function RL.rlViewport( viewport ) end + -- RLGL - Textures state ---Select and active a texture slot @@ -5686,6 +5768,26 @@ function RL.rlDisableSmoothLines() end ---@return any version function RL.rlGetVersion() end +-- RLGL - Render batch management + +---Update and draw internal render batch +---@return any RL.rlDrawRenderBatchActive +function RL.rlDrawRenderBatchActive() end + +---Check internal buffer overflow for a given number of vertex and force a rlRenderBatch draw call if required +---- Failure return nil +---- Success return bool +---@param vCount integer +---@return any overflow +function RL.rlCheckRenderBatchLimit( vCount ) end + +---Set current texture for render batch and check buffers limits +---- Failure return false +---- Success return true +---@param id integer +---@return any success +function RL.rlSetTexture( id ) end + -- RLGL - Textures management ---Load texture in GPU @@ -19,6 +19,11 @@ KEY CHANGES: - ADDED: rlgl Textures management functions - ADDED: Texture and RenderTexture can be given as tables - ADDED: Camera2D and Camera3D can be given as tables + - ADDED: Camera2D and Camera3D can be given as tables + - ADDED: rlgl New defines + - ADDED: rlgl Textures state functions + - ADDED: rlgl Some Render batch management functions + - ADDED: rlgl Matrix operations functions Detailed changes: - FIXED: uluaGetRay was looking for integers instead of tables @@ -81,8 +86,6 @@ Detailed changes: - ADDED: GetMaterialTexture, GetMaterialColor, GetMaterialValue and GetMaterialShader - ADDED: SetMaterialParams and GetMaterialParams - ADDED: GetTextureId - - ADDED: RLGL defines - - ADDED: RLGL Textures state functions ------------------------------------------------------------------------ Release: ReiLua version 0.4.0 Using Raylib 4.2 @@ -1,4 +1,11 @@ Current { + * rlgl + * Vertex level operations. + * Vertex buffers state. + * Vertex buffers management + * Shaders management + * Matrix state management + * Compute shader management * New type validators. } @@ -10,8 +17,6 @@ Backlog { * Text * Ability to set font texture filtering. * Codepoints? - * rlgl - * More low level functions. Could be usefull now when for example DrawTexturePoly is removed. * Audio * AudioStream. * Core. diff --git a/include/lrlgl.h b/include/lrlgl.h index b07fc09..5f2adae 100644 --- a/include/lrlgl.h +++ b/include/lrlgl.h @@ -1,5 +1,17 @@ #pragma once +/* Matrix operations */ +int lrlglMatrixMode( lua_State *L ); +int lrlglPushMatrix( lua_State *L ); +int lrlglPopMatrix( lua_State *L ); +int lrlglLoadIdentity( lua_State *L ); +int lrlglTranslatef( lua_State *L ); +int lrlglRotatef( lua_State *L ); +int lrlglScalef( lua_State *L ); +int lrlglMultMatrixf( lua_State *L ); +int lrlglFrustum( lua_State *L ); +int lrlglOrtho( lua_State *L ); +int lrlglViewport( lua_State *L ); /* Textures state */ int lrlglActiveTextureSlot( lua_State *L ); int lrlglEnableTexture( lua_State *L ); @@ -28,6 +40,10 @@ int lrlglEnableSmoothLines( lua_State *L ); int lrlglDisableSmoothLines( lua_State *L ); /* Initialization functions */ int lrlglGetVersion( lua_State *L ); +/* Render batch management */ +int lrlglDrawRenderBatchActive( lua_State *L ); +int lrlglCheckRenderBatchLimit( lua_State *L ); +int lrlglSetTexture( lua_State *L ); /* Textures management */ int lrlglLoadTexture( lua_State *L ); int lrlglLoadTextureDepth( lua_State *L ); diff --git a/src/lua_core.c b/src/lua_core.c index 0fa02da..1ff92cf 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1475,6 +1475,18 @@ void luaRegister() { assingGlobalFunction( "IsLightEnabled", llightsIsLightEnabled ); /* RLGL */ + /* Matrix operations */ + assingGlobalFunction( "rlMatrixMode", lrlglMatrixMode ); + assingGlobalFunction( "rlPushMatrix", lrlglPushMatrix ); + assingGlobalFunction( "rlPopMatrix", lrlglPopMatrix ); + assingGlobalFunction( "rlLoadIdentity", lrlglLoadIdentity ); + assingGlobalFunction( "rlTranslatef", lrlglTranslatef ); + assingGlobalFunction( "rlRotatef", lrlglRotatef ); + assingGlobalFunction( "rlScalef", lrlglScalef ); + assingGlobalFunction( "rlMultMatrixf", lrlglMultMatrixf ); + assingGlobalFunction( "rlFrustum", lrlglFrustum ); + assingGlobalFunction( "rlOrtho", lrlglOrtho ); + assingGlobalFunction( "rlViewport", lrlglViewport ); /* Textures state */ assingGlobalFunction( "rlActiveTextureSlot", lrlglActiveTextureSlot ); assingGlobalFunction( "rlEnableTexture", lrlglEnableTexture ); @@ -1503,6 +1515,10 @@ void luaRegister() { assingGlobalFunction( "rlDisableSmoothLines", lrlglDisableSmoothLines ); /* Initialization functions. */ assingGlobalFunction( "rlGetVersion", lrlglGetVersion ); + /* Render batch management. */ + assingGlobalFunction( "rlDrawRenderBatchActive", lrlglDrawRenderBatchActive ); + assingGlobalFunction( "rlCheckRenderBatchLimit", lrlglCheckRenderBatchLimit ); + assingGlobalFunction( "rlSetTexture", lrlglSetTexture ); /* Textures management */ assingGlobalFunction( "rlLoadTexture", lrlglLoadTexture ); assingGlobalFunction( "rlLoadTextureDepth", lrlglLoadTextureDepth ); @@ -4,6 +4,236 @@ #include "lrlgl.h" /* +## RLGL - Matrix operations +*/ + +/* +> success = RL.rlMatrixMode( int mode ) + +Choose the current matrix to be transformed + +- Failure return false +- Success return true +*/ +int lrlglMatrixMode( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlMatrixMode( int mode )" ); + lua_pushboolean( L, false ); + return 1; + } + rlMatrixMode( lua_tointeger( L, 1 ) ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> RL.rlPushMatrix() + +Push the current matrix to stack +*/ +int lrlglPushMatrix( lua_State *L ) { + rlPushMatrix(); + + return 0; +} + +/* +> RL.rlPopMatrix() + +Pop latest inserted matrix from stack +*/ +int lrlglPopMatrix( lua_State *L ) { + rlPopMatrix(); + + return 0; +} + +/* +> RL.rlLoadIdentity() + +Reset current matrix to identity matrix +*/ +int lrlglLoadIdentity( lua_State *L ) { + rlLoadIdentity(); + + return 0; +} + +/* +> success = RL.rlTranslatef( Vector3 translation ) + +Multiply the current matrix by a translation matrix + +- Failure return false +- Success return true +*/ +int lrlglTranslatef( lua_State *L ) { + if ( !lua_istable( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlTranslatef( Vector3 translation )" ); + lua_pushboolean( L, false ); + return 1; + } + Vector3 translation = uluaGetVector3Index( L, 1 ); + + rlTranslatef( translation.x, translation.y, translation.z ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL.rlRotatef( float angle, Vector3 rotation ) + +Multiply the current matrix by a rotation matrix + +- Failure return false +- Success return true +*/ +int lrlglRotatef( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlRotatef( float angle, Vector3 rotation )" ); + lua_pushboolean( L, false ); + return 1; + } + float angle = lua_tonumber( L, 1 ); + Vector3 rotation = uluaGetVector3Index( L, 2 ); + + rlRotatef( angle, rotation.x, rotation.y, rotation.z ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL.rlScalef( Vector3 scale ) + +Multiply the current matrix by a scaling matrix + +- Failure return false +- Success return true +*/ +int lrlglScalef( lua_State *L ) { + if ( !lua_istable( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlScalef( Vector3 scale )" ); + lua_pushboolean( L, false ); + return 1; + } + Vector3 scale = uluaGetVector3Index( L, 1 ); + + rlScalef( scale.x, scale.y, scale.z ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL.rlMultMatrixf( Matrix matrix ) + +Multiply the current matrix by another matrix + +- Failure return false +- Success return true +*/ +int lrlglMultMatrixf( lua_State *L ) { + if ( !lua_istable( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlMultMatrixf( Matrix matrix )" ); + lua_pushboolean( L, false ); + return 1; + } + Matrix matrix = uluaGetMatrixIndex( L, 1 ); + float matf[16] = { + matrix.m0, matrix.m4, matrix.m8, matrix.m12, + matrix.m1, matrix.m5, matrix.m9, matrix.m13, + matrix.m2, matrix.m6, matrix.m10, matrix.m14, + matrix.m3, matrix.m7, matrix.m11, matrix.m15 + }; + rlMultMatrixf( matf ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL.rlFrustum( float left, float right, float bottom, float top, float znear, float zfar ) + +Multiply the current matrix by a perspective matrix generated by parameters + +- Failure return false +- Success return true +*/ +int lrlglFrustum( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) + || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlFrustum( float left, float right, float bottom, float top, float znear, float zfar )" ); + lua_pushboolean( L, false ); + return 1; + } + double left = lua_tonumber( L, 1 ); + double right = lua_tonumber( L, 2 ); + double bottom = lua_tonumber( L, 3 ); + double top = lua_tonumber( L, 4 ); + double znear = lua_tonumber( L, 5 ); + double zfar = lua_tonumber( L, 6 ); + + rlFrustum( left, right, bottom, top, znear, zfar ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL.rlOrtho( float left, float right, float bottom, float top, float znear, float zfar ) + +Multiply the current matrix by an orthographic matrix generated by parameters + +- Failure return false +- Success return true +*/ +int lrlglOrtho( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) + || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlOrtho( float left, float right, float bottom, float top, float znear, float zfar )" ); + lua_pushboolean( L, false ); + return 1; + } + double left = lua_tonumber( L, 1 ); + double right = lua_tonumber( L, 2 ); + double bottom = lua_tonumber( L, 3 ); + double top = lua_tonumber( L, 4 ); + double znear = lua_tonumber( L, 5 ); + double zfar = lua_tonumber( L, 6 ); + + rlOrtho( left, right, bottom, top, znear, zfar ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL.rlViewport( Rectangle viewport ) + +Set the viewport area ( transformation from normalized device coordinates to window coordinates ) +NOTE: We store current viewport dimensions + +- Failure return false +- Success return true +*/ +int lrlglViewport( lua_State *L ) { + if ( !lua_istable( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlViewport( Rectangle viewport )" ); + lua_pushboolean( L, false ); + return 1; + } + Rectangle rect = uluaGetRectangleIndex( L, 1 ); + + rlViewport( rect.x, rect.y, rect.width, rect.height ); + lua_pushboolean( L, true ); + + return 1; +} + +/* ## RLGL - Textures state */ @@ -377,6 +607,60 @@ int lrlglGetVersion( lua_State *L ) { } /* +## RLGL - Render batch management +*/ + +/* +> RL.rlDrawRenderBatchActive() + +Update and draw internal render batch +*/ +int lrlglDrawRenderBatchActive( lua_State *L ) { + rlDrawRenderBatchActive(); + + return 0; +} + +/* +> overflow = RL.rlCheckRenderBatchLimit( int vCount ) + +Check internal buffer overflow for a given number of vertex and force a rlRenderBatch draw call if required + +- Failure return nil +- Success return bool +*/ +int lrlglCheckRenderBatchLimit( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlCheckRenderBatchLimit( int vCount )" ); + lua_pushnil( L ); + return 1; + } + lua_pushboolean( L, rlCheckRenderBatchLimit( lua_tointeger( L, 1 ) ) ); + + return 1; +} + +/* +> success = RL.rlSetTexture( int id ) + +Set current texture for render batch and check buffers limits + +- Failure return false +- Success return true +*/ +int lrlglSetTexture( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlSetTexture( int id )" ); + lua_pushboolean( L, false ); + return 1; + } + rlSetTexture( lua_tointeger( L, 1 ) ); + lua_pushboolean( L, true ); + + return 1; +} + +/* ## RLGL - Textures management */ |
