rlgl Matrix state management.

This commit is contained in:
jussi
2023-10-22 22:13:27 +03:00
parent 95be0403e6
commit 6915f3e27c
7 changed files with 190 additions and 7 deletions

View File

@@ -34,7 +34,7 @@ Application needs 'main.lua' or 'main' file as entry point. ReiLua executable wi
Example of basic "main.lua" file that will show basic windows with text. Example of basic "main.lua" file that will show basic windows with text.
``` ```Lua
local textColor = RL.BLACK local textColor = RL.BLACK
local textPos = { 192, 200 } local textPos = { 192, 200 }

View File

@@ -34,6 +34,7 @@ KEY CHANGES:
- ADDED: rlgl Shader state. - ADDED: rlgl Shader state.
- ADDED: RL.event function with input events. - ADDED: RL.event function with input events.
- ADDED: Window events. - ADDED: Window events.
- ADDED: rlgl Matrix state management.
Detailed changes: Detailed changes:
- FIXED: uluaGetRay was looking for integers instead of tables - FIXED: uluaGetRay was looking for integers instead of tables
@@ -103,7 +104,7 @@ Detailed changes:
- FIXED: isValidRenderTexture checks that it is TEXTURE_TYPE_RENDER_TEXTURE - FIXED: isValidRenderTexture checks that it is TEXTURE_TYPE_RENDER_TEXTURE
- FIXED: isValidTexture on CreateMaterial - FIXED: isValidTexture on CreateMaterial
- CHANGED: Renamed start, end arguments to a, b to avoid using Lua keyword "end" in argument names - CHANGED: Renamed start, end arguments to a, b to avoid using Lua keyword "end" in argument names
- ADDED: Argumets stored in "RL.arg" array - ADDED: Arguments stored in "RL.arg" array
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.4.0 Using Raylib 4.2 Release: ReiLua version 0.4.0 Using Raylib 4.2

View File

@@ -1,7 +1,6 @@
Current { Current {
* rlgl * rlgl
* Vertex buffers management * Vertex buffers management
* Matrix state management
* Shaders management * Shaders management
* Compute shader management * Compute shader management
} }

View File

@@ -95,4 +95,14 @@ int lrlglUnloadTexture( lua_State *L );
int lrlglLoadFramebuffer( lua_State *L ); int lrlglLoadFramebuffer( lua_State *L );
int lrlglFramebufferAttach( lua_State *L ); int lrlglFramebufferAttach( lua_State *L );
int lrlglFramebufferComplete( lua_State *L ); int lrlglFramebufferComplete( lua_State *L );
int lrlglUnloadFramebuffer( lua_State *L ); int lrlglUnloadFramebuffer( lua_State *L );
/* Matrix state management */
int lrlglGetMatrixModelview( lua_State *L );
int lrlglGetMatrixProjection( lua_State *L );
int lrlglGetMatrixTransform( lua_State *L );
int lrlglGetMatrixProjectionStereo( lua_State *L );
int lrlglGetMatrixViewOffsetStereo( lua_State *L );
int lrlglSetMatrixProjection( lua_State *L );
int lrlglSetMatrixModelview( lua_State *L );
int lrlglSetMatrixProjectionStereo( lua_State *L );
int lrlglSetMatrixViewOffsetStereo( lua_State *L );

4
lib/.gitignore vendored
View File

@@ -1 +1,3 @@
* libraylib.a
liblua.a
libluajit.a

View File

@@ -1957,6 +1957,16 @@ void luaRegister() {
assingGlobalFunction( "rlFramebufferAttach", lrlglFramebufferAttach ); assingGlobalFunction( "rlFramebufferAttach", lrlglFramebufferAttach );
assingGlobalFunction( "rlFramebufferComplete", lrlglFramebufferComplete ); assingGlobalFunction( "rlFramebufferComplete", lrlglFramebufferComplete );
assingGlobalFunction( "rlUnloadFramebuffer", lrlglUnloadFramebuffer ); assingGlobalFunction( "rlUnloadFramebuffer", lrlglUnloadFramebuffer );
/* Matrix state management. */
assingGlobalFunction( "rlGetMatrixModelview", lrlglGetMatrixModelview );
assingGlobalFunction( "rlGetMatrixProjection", lrlglGetMatrixProjection );
assingGlobalFunction( "rlGetMatrixTransform", lrlglGetMatrixTransform );
assingGlobalFunction( "rlGetMatrixProjectionStereo", lrlglGetMatrixProjectionStereo );
assingGlobalFunction( "rlGetMatrixViewOffsetStereo", lrlglGetMatrixViewOffsetStereo );
assingGlobalFunction( "rlSetMatrixProjection", lrlglSetMatrixProjection );
assingGlobalFunction( "rlSetMatrixModelview", lrlglSetMatrixModelview );
assingGlobalFunction( "rlSetMatrixProjectionStereo", lrlglSetMatrixProjectionStereo );
assingGlobalFunction( "rlSetMatrixViewOffsetStereo", lrlglSetMatrixViewOffsetStereo );
/* OpenGL */ /* OpenGL */
/* Framebuffer management. */ /* Framebuffer management. */

View File

@@ -1579,7 +1579,7 @@ Delete framebuffer from GPU
int lrlglUnloadFramebuffer( lua_State *L ) { int lrlglUnloadFramebuffer( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) { if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUnloadFramebuffer( int id )" ); TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUnloadFramebuffer( int id )" );
lua_pushboolean( L, false ); lua_pushnil( L );
return 1; return 1;
} }
unsigned int id = lua_tointeger( L, 1 ); unsigned int id = lua_tointeger( L, 1 );
@@ -1588,4 +1588,165 @@ int lrlglUnloadFramebuffer( lua_State *L ) {
lua_pushboolean( L, true ); lua_pushboolean( L, true );
return 1; return 1;
} }
/*
## RLGL - Matrix state management
*/
/*
> modelview = RL.rlGetMatrixModelview()
Get internal modelview matrix
- Success return Matrix
*/
int lrlglGetMatrixModelview( lua_State *L ) {
uluaPushMatrix( L, rlGetMatrixModelview() );
return 1;
}
/*
> projection = RL.rlGetMatrixProjection()
Get internal projection matrix
- Success return Matrix
*/
int lrlglGetMatrixProjection( lua_State *L ) {
uluaPushMatrix( L, rlGetMatrixProjection() );
return 1;
}
/*
> transform = RL.rlGetMatrixTransform()
Get internal accumulated transform matrix
- Success return Matrix
*/
int lrlglGetMatrixTransform( lua_State *L ) {
uluaPushMatrix( L, rlGetMatrixTransform() );
return 1;
}
/*
> projection = RL.rlGetMatrixProjectionStereo( int eye )
Get internal projection matrix for stereo render (selected eye)
- Failure return false
- Success return Matrix
*/
int lrlglGetMatrixProjectionStereo( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlGetMatrixProjectionStereo( int eye )" );
lua_pushboolean( L, false );
return 1;
}
uluaPushMatrix( L, rlGetMatrixProjectionStereo( lua_tointeger( L, 1 ) ) );
return 1;
}
/*
> viewOffset = RL.rlGetMatrixViewOffsetStereo( int eye )
Get internal view offset matrix for stereo render (selected eye)
- Failure return false
- Success return Matrix
*/
int lrlglGetMatrixViewOffsetStereo( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlGetMatrixViewOffsetStereo( int eye )" );
lua_pushboolean( L, false );
return 1;
}
uluaPushMatrix( L, rlGetMatrixViewOffsetStereo( lua_tointeger( L, 1 ) ) );
return 1;
}
/*
> success = RL.rlSetMatrixProjection( Matrix proj )
Set a custom projection matrix (replaces internal projection matrix)
- Failure return false
- Success return true
*/
int lrlglSetMatrixProjection( lua_State *L ) {
if ( !lua_istable( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetMatrixProjection( Matrix proj )" );
lua_pushboolean( L, false );
return 1;
}
rlSetMatrixProjection( uluaGetMatrixIndex( L, 1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlSetMatrixModelview( Matrix view )
Set a custom modelview matrix (replaces internal modelview matrix)
- Failure return false
- Success return true
*/
int lrlglSetMatrixModelview( lua_State *L ) {
if ( !lua_istable( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetMatrixModelview( Matrix view )" );
lua_pushboolean( L, false );
return 1;
}
rlSetMatrixModelview( uluaGetMatrixIndex( L, 1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlSetMatrixProjectionStereo( Matrix right, Matrix left )
Set eyes projection matrices for stereo rendering
- Failure return false
- Success return true
*/
int lrlglSetMatrixProjectionStereo( lua_State *L ) {
if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetMatrixModelview( Matrix right, Matrix left )" );
lua_pushboolean( L, false );
return 1;
}
rlSetMatrixProjectionStereo( uluaGetMatrixIndex( L, 1 ), uluaGetMatrixIndex( L, 2 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlSetMatrixViewOffsetStereo( Matrix right, Matrix left )
Set eyes view offsets matrices for stereo rendering
- Failure return false
- Success return true
*/
int lrlglSetMatrixViewOffsetStereo( lua_State *L ) {
if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetMatrixViewOffsetStereo( Matrix right, Matrix left )" );
lua_pushboolean( L, false );
return 1;
}
rlSetMatrixViewOffsetStereo( uluaGetMatrixIndex( L, 1 ), uluaGetMatrixIndex( L, 2 ) );
lua_pushboolean( L, true );
return 1;
}