summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lua_core.c31
-rw-r--r--src/rlgl.c359
-rw-r--r--src/state.c2
-rw-r--r--src/textures.c59
4 files changed, 448 insertions, 3 deletions
diff --git a/src/lua_core.c b/src/lua_core.c
index c789be1..d14c41e 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -26,6 +26,12 @@ static void assignGlobalFloat( float value, const char *name ) {
lua_setfield( L, -2, name );
}
+static void assignGlobalDouble( double value, const char *name ) {
+ lua_State *L = state->luaState;
+ lua_pushnumber( L, value );
+ lua_setfield( L, -2, name );
+}
+
static void assignGlobalColor( Color color, const char *name ) {
lua_State *L = state->luaState;
uluaPushColor( L, color );
@@ -499,8 +505,8 @@ void defineGlobals() {
/* RLGL Shader limits */
assignGlobalInt( RL_MAX_SHADER_LOCATIONS, "RL_MAX_SHADER_LOCATIONS" );
/* RLGL Projection matrix culling */
- assignGlobalInt( RL_CULL_DISTANCE_NEAR, "RL_CULL_DISTANCE_NEAR" );
- assignGlobalInt( RL_CULL_DISTANCE_FAR, "RL_CULL_DISTANCE_FAR" );
+ assignGlobalDouble( RL_CULL_DISTANCE_NEAR, "RL_CULL_DISTANCE_NEAR" );
+ assignGlobalDouble( RL_CULL_DISTANCE_FAR, "RL_CULL_DISTANCE_FAR" );
/* RLGL Texture parameters */
assignGlobalInt( RL_TEXTURE_WRAP_S, "RL_TEXTURE_WRAP_S" );
assignGlobalInt( RL_TEXTURE_WRAP_T, "RL_TEXTURE_WRAP_T" );
@@ -1069,6 +1075,7 @@ void luaRegister() {
assingGlobalFunction( "ImageAlphaClear", ltexturesImageAlphaClear );
assingGlobalFunction( "ImageAlphaMask", ltexturesImageAlphaMask );
assingGlobalFunction( "ImageAlphaPremultiply", ltexturesImageAlphaPremultiply );
+ assingGlobalFunction( "ImageBlurGaussian", ltexturesImageBlurGaussian );
assingGlobalFunction( "ImageResize", ltexturesImageResize );
assingGlobalFunction( "ImageResizeNN", ltexturesImageResizeNN );
assingGlobalFunction( "ImageResizeCanvas", ltexturesImageResizeCanvas );
@@ -1093,6 +1100,7 @@ void luaRegister() {
assingGlobalFunction( "ImageDrawPixel", ltexturesImageDrawPixel );
assingGlobalFunction( "ImageDrawLine", ltexturesImageDrawLine );
assingGlobalFunction( "ImageDrawCircle", ltexturesImageDrawCircle );
+ assingGlobalFunction( "ImageDrawCircleLines", ltexturesImageDrawCircleLines );
assingGlobalFunction( "ImageDrawRectangle", ltexturesImageDrawRectangle );
assingGlobalFunction( "ImageDrawRectangleLines", ltexturesImageDrawRectangleLines );
assingGlobalFunction( "ImageDraw", ltexturesImageDraw );
@@ -1497,6 +1505,15 @@ void luaRegister() {
assingGlobalFunction( "rlColor4ub", lrlglColor4ub );
assingGlobalFunction( "rlColor3f", lrlglColor3f );
assingGlobalFunction( "rlColor4f", lrlglColor4f );
+ /* Vertex buffers state. */
+ assingGlobalFunction( "rlEnableVertexArray", lrlglEnableVertexArray );
+ assingGlobalFunction( "rlDisableVertexArray", lrlglDisableVertexArray );
+ assingGlobalFunction( "rlEnableVertexBuffer", lrlglEnableVertexBuffer );
+ assingGlobalFunction( "rlDisableVertexBuffer", lrlglDisableVertexBuffer );
+ assingGlobalFunction( "rlEnableVertexBufferElement", lrlglEnableVertexBufferElement );
+ assingGlobalFunction( "rlDisableVertexBufferElement", lrlglDisableVertexBufferElement );
+ assingGlobalFunction( "rlEnableVertexAttribute", lrlglEnableVertexAttribute );
+ assingGlobalFunction( "rlDisableVertexAttribute", lrlglDisableVertexAttribute );
/* Textures state. */
assingGlobalFunction( "rlActiveTextureSlot", lrlglActiveTextureSlot );
assingGlobalFunction( "rlEnableTexture", lrlglEnableTexture );
@@ -1505,6 +1522,9 @@ void luaRegister() {
assingGlobalFunction( "rlDisableTextureCubemap", lrlglDisableTextureCubemap );
assingGlobalFunction( "rlTextureParameters", lrlglTextureParameters );
assingGlobalFunction( "rlCubemapParameters", lrlglCubemapParameters );
+ /* Shader state. */
+ assingGlobalFunction( "rlEnableShader", lrlglEnableShader );
+ assingGlobalFunction( "rlDisableShader", lrlglDisableShader );
/* Framebuffer state. */
assingGlobalFunction( "rlEnableFramebuffer", lrlglEnableFramebuffer );
assingGlobalFunction( "rlDisableFramebuffer", lrlglDisableFramebuffer );
@@ -1543,6 +1563,13 @@ void luaRegister() {
assingGlobalFunction( "rlDrawRenderBatchActive", lrlglDrawRenderBatchActive );
assingGlobalFunction( "rlCheckRenderBatchLimit", lrlglCheckRenderBatchLimit );
assingGlobalFunction( "rlSetTexture", lrlglSetTexture );
+ /* Vertex buffers management. */
+ assingGlobalFunction( "rlLoadVertexArray", lrlglLoadVertexArray );
+ assingGlobalFunction( "rlLoadVertexBuffer", lrlglLoadVertexBuffer );
+ assingGlobalFunction( "rlUnloadVertexArray", lrlglUnloadVertexArray );
+ assingGlobalFunction( "rlUnloadVertexBuffer", lrlglUnloadVertexBuffer );
+ assingGlobalFunction( "rlSetVertexAttribute", lrlglSetVertexAttribute );
+ assingGlobalFunction( "rlDrawVertexArray", lrlglDrawVertexArray );
/* Textures management. */
assingGlobalFunction( "rlLoadTexture", lrlglLoadTexture );
assingGlobalFunction( "rlLoadTextureDepth", lrlglLoadTextureDepth );
diff --git a/src/rlgl.c b/src/rlgl.c
index 736541d..06425ff 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -3,6 +3,58 @@
#include "lua_core.h"
#include "lrlgl.h"
+static void* getVertexBuffer( lua_State *L, int *type, unsigned int *size ) {
+ *type = lua_tointeger( L, 2 );
+ size_t len = uluaGetTableLenIndex( L, 1 );
+ unsigned char *uByteArray;
+ float *floatArray;
+
+ switch ( *type ) {
+ case RL_UNSIGNED_BYTE:
+ *size = len * sizeof( unsigned char );
+ uByteArray = MemAlloc( *size );
+ break;
+ case RL_FLOAT:
+ *size = len * sizeof( float );
+ floatArray = MemAlloc( *size );
+ break;
+ default:
+ break;
+ }
+
+ int t = 1;
+ int i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ switch ( *type ) {
+ case RL_UNSIGNED_BYTE:
+ uByteArray[i] = lua_tointeger( L, -1 );
+ break;
+ case RL_FLOAT:
+ floatArray[i] = lua_tointeger( L, -1 );
+ break;
+ default:
+ break;
+ }
+
+ lua_pop( L, 1 );
+ i++;
+ }
+
+ switch ( *type ) {
+ case RL_UNSIGNED_BYTE:
+ return uByteArray;
+ break;
+ case RL_FLOAT:
+ return floatArray;
+ break;
+ default:
+ return NULL;
+ break;
+ }
+}
+
/*
## RLGL - Matrix operations
*/
@@ -423,6 +475,142 @@ int lrlglColor4f( lua_State *L ) {
}
/*
+## RLGL - Vertex buffers state
+*/
+
+/*
+> supported = RL.rlEnableVertexArray( int vaoId )
+
+Enable vertex array ( VAO, if supported )
+
+- Failure return nil
+- Success return bool
+*/
+int lrlglEnableVertexArray( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexArray( int vaoId )" );
+ lua_pushnil( L );
+ return 1;
+ }
+ lua_pushboolean( L, rlEnableVertexArray( lua_tointeger( L, 1 ) ) );
+
+ return 1;
+}
+
+/*
+> RL.rlDisableVertexArray()
+
+Disable vertex array ( VAO, if supported )
+*/
+int lrlglDisableVertexArray( lua_State *L ) {
+ rlDisableVertexArray();
+
+ return 0;
+}
+
+/*
+> success = RL.rlEnableVertexBuffer( int id )
+
+Enable vertex buffer ( VBO )
+
+- Failure return false
+- Success return true
+*/
+int lrlglEnableVertexBuffer( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexBuffer( int id )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ rlEnableVertexBuffer( lua_tointeger( L, 1 ) );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> RL.rlDisableVertexBuffer()
+
+Disable vertex buffer ( VBO )
+*/
+int lrlglDisableVertexBuffer( lua_State *L ) {
+ rlDisableVertexBuffer();
+
+ return 0;
+}
+
+/*
+> success = RL.rlEnableVertexBufferElement( int id )
+
+Enable vertex buffer element ( VBO element )
+
+- Failure return false
+- Success return true
+*/
+int lrlglEnableVertexBufferElement( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexBufferElement( int id )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ rlEnableVertexBufferElement( lua_tointeger( L, 1 ) );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> RL.rlDisableVertexBufferElement()
+
+Disable vertex buffer element ( VBO element )
+*/
+int lrlglDisableVertexBufferElement( lua_State *L ) {
+ rlDisableVertexBufferElement();
+
+ return 0;
+}
+
+/*
+> success = RL.rlEnableVertexAttribute( int index )
+
+Enable vertex attribute index
+
+- Failure return false
+- Success return true
+*/
+int lrlglEnableVertexAttribute( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexAttribute( int index )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ rlEnableVertexAttribute( lua_tointeger( L, 1 ) );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.rlDisableVertexAttribute( int index )
+
+Disable vertex attribute index
+
+- Failure return false
+- Success return true
+*/
+int lrlglDisableVertexAttribute( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDisableVertexAttribute( int index )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ rlDisableVertexAttribute( lua_tointeger( L, 1 ) );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
## RLGL - Textures state
*/
@@ -557,6 +745,41 @@ int lrlglCubemapParameters( lua_State *L ) {
}
/*
+## RLGL - Shader state
+*/
+
+/*
+> success = RL.rlEnableShader( int id )
+
+Enable shader program
+
+- Failure return false
+- Success return true
+*/
+int lrlglEnableShader( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableShader( int id )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ rlEnableShader( lua_tointeger( L, 1 ) );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> RL.rlDisableShader()
+
+Disable shader program
+*/
+int lrlglDisableShader( lua_State *L ) {
+ rlDisableShader();
+
+ return 0;
+}
+
+/*
## RLGL - Framebuffer state
*/
@@ -1068,6 +1291,142 @@ int lrlglSetTexture( lua_State *L ) {
}
/*
+## RLGL - Vertex buffers management
+*/
+
+/*
+> vaoId = RL.rlLoadVertexArray()
+
+Load vertex array (vao) if supported
+
+- Success return int
+*/
+int lrlglLoadVertexArray( lua_State *L ) {
+ lua_pushinteger( L, rlLoadVertexArray() );
+
+ return 1;
+}
+
+/*
+> vboId = RL.rlLoadVertexBuffer( Buffer{} buffer, int type, bool dynamic )
+
+Load a vertex buffer attribute. Type should be RL_UNSIGNED_BYTE or RL_FLOAT
+
+- Failure return -1
+- Success return int
+*/
+int lrlglLoadVertexBuffer( lua_State *L ) {
+ if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadVertexBuffer( Buffer{} buffer, int type, bool dynamic )" );
+ lua_pushinteger( L, -1 );
+ return 1;
+ }
+ unsigned int size = 0;
+ int type = 0;
+ void *vertexBuffer = getVertexBuffer( L, &type, &size );
+ bool dynamic = lua_tointeger( L, 3 );
+
+ lua_pushinteger( L, rlLoadVertexBuffer( vertexBuffer, size, dynamic ) );
+
+ if ( vertexBuffer != NULL ) {
+ MemFree( vertexBuffer );
+ }
+
+ return 1;
+}
+
+/*
+> success = RL.rlUnloadVertexArray( int vaoId )
+
+Unload vertex array object (VAO)
+
+- Failure return false
+- Success return true
+*/
+int lrlglUnloadVertexArray( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUnloadVertexArray( int vaoId )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ rlUnloadVertexArray( lua_tointeger( L, 1 ) );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.rlUnloadVertexBuffer( int vboId )
+
+Unload vertex buffer (VBO)
+
+- Failure return false
+- Success return true
+*/
+int lrlglUnloadVertexBuffer( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUnloadVertexBuffer( int vboId )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ rlUnloadVertexBuffer( lua_tointeger( L, 1 ) );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer )
+
+Set vertex attribute
+
+- Failure return false
+- Success return true
+*/
+int lrlglSetVertexAttribute( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 )
+ || !lua_isboolean( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int index = lua_tointeger( L, 1 );
+ int compSize = lua_tointeger( L, 2 );
+ int type = lua_tointeger( L, 3 );
+ bool normalized = lua_toboolean( L, 4 );
+ int stride = lua_tointeger( L, 5 );
+ int pointer = lua_tointeger( L, 6 );
+
+ rlSetVertexAttribute( index, compSize, type, normalized, stride, &pointer );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.rlDrawVertexArray( int offset, int count )
+
+Draw vertex array
+
+- Failure return false
+- Success return true
+*/
+int lrlglDrawVertexArray( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArray( int offset, int count )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int offset = lua_tointeger( L, 1 );
+ int count = lua_tointeger( L, 2 );
+
+ rlDrawVertexArray( offset, count );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
## RLGL - Textures management
*/
diff --git a/src/state.c b/src/state.c
index abaf2ae..79812e9 100644
--- a/src/state.c
+++ b/src/state.c
@@ -114,7 +114,7 @@ bool stateInit( const char *exePath ) {
return state->run;
}
-bool stateInitInterpret() {
+void stateInitInterpret() {
state = malloc( sizeof( State ) );
luaInit();
}
diff --git a/src/textures.c b/src/textures.c
index 786dfd4..c04179d 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -85,6 +85,8 @@ Texture2D* texturesGetSourceTexture( size_t id ) {
break;
}
}
+
+ return &state->textures[id]->texture;
}
void texturesFreeTexture( size_t id ) {
@@ -752,6 +754,33 @@ int ltexturesImageAlphaPremultiply( lua_State *L ) {
}
/*
+> success = RL.ImageBlurGaussian( Image image, int blurSize )
+
+Apply Gaussian blur using a box blur approximation
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageBlurGaussian( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageBlurGaussian( Image image, int blurSize )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, 1 );
+ int blurSize = lua_tointeger( L, 2 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageBlurGaussian( state->images[ imageId ], blurSize );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
> success = RL.ImageResize( Image image, Vector2 size )
Resize image ( Bicubic scaling algorithm )
@@ -1397,6 +1426,36 @@ int ltexturesImageDrawCircle( lua_State *L ) {
}
/*
+> success = RL.ImageDrawCircleLines( Image dst, Vector2 center, int radius, Color color )
+
+Draw circle outline within an image
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageDrawCircleLines( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawCircleLines( Image dst, Vector2 center, int radius, Color color )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, 1 );
+ Vector2 center = uluaGetVector2Index( L, 2 );
+ int radius = lua_tointeger( L, 3 );
+ Color color = uluaGetColorIndex( L, 4 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+
+ ImageDrawCircleLinesV( state->images[ imageId ], center, radius, color );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
> success = RL.ImageDrawRectangle( Image dst, Rectangle rec, Color color )
Draw rectangle within an image