rlgl Some Render batch management functions and Matrix operations functions.
This commit is contained in:
@@ -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 );
|
||||
|
||||
284
src/rlgl.c
284
src/rlgl.c
@@ -3,6 +3,236 @@
|
||||
#include "lua_core.h"
|
||||
#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
|
||||
*/
|
||||
@@ -376,6 +606,60 @@ int lrlglGetVersion( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
## 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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user