New object types for Image, Texture, RenderTexture, Camera2D, Camera3D and Shader.

This commit is contained in:
jussi
2023-10-27 22:53:56 +03:00
parent 4cb4edcaf0
commit 7ef87c8e2f
20 changed files with 967 additions and 2904 deletions

1081
src/core.c

File diff suppressed because it is too large Load Diff

View File

@@ -9,40 +9,32 @@
*/
/*
> success = RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )
> RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )
Copy a block of pixels from one framebuffer object to another.
Use -1 RenderTexture for window framebuffer.
- Failure return false
- Success return true
*/
int lglBlitFramebuffer( lua_State *L ) {
if ( !isValidRenderTexture( L, 1, true ) || !isValidRenderTexture( L, 2, true ) || !lua_istable( L, 3 )
|| !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )" );
lua_pushboolean( L, false );
return 1;
}
RenderTexture2D srcTex = uluaGetRenderTexture( L, 1 );
RenderTexture2D dstTex = uluaGetRenderTexture( L, 2 );
// TOCO Currently doesn't support setting window render target because of luaL_checkudata.
RenderTexture *srcTex = luaL_checkudata( L, 1, "RenderTexture" );
RenderTexture *dstTex = luaL_checkudata( L, 2, "RenderTexture" );
Rectangle srcRect = uluaGetRectangleIndex( L, 3 );
Rectangle dstRect = uluaGetRectangleIndex( L, 4 );
int mask = lua_tointeger( L, 5 );
int filter = lua_tointeger( L, 6 );
int mask = luaL_checkinteger( L, 5 );
int filter = luaL_checkinteger( L, 6 );
if ( lua_tointeger( L, 1 ) == -1 ) {
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
}
else {
glBindFramebuffer( GL_READ_FRAMEBUFFER, srcTex.id );
glBindFramebuffer( GL_READ_FRAMEBUFFER, srcTex->id );
}
if ( lua_tointeger( L, 2 ) == -1 ) {
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
}
else {
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, dstTex.id );
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, dstTex->id );
}
glBlitFramebuffer(
@@ -55,7 +47,5 @@ int lglBlitFramebuffer( lua_State *L ) {
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
lua_pushboolean( L, true );
return 1;
}

View File

@@ -59,54 +59,35 @@ Create a light and get shader locations
- Success return int
*/
int llightsCreateLight( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 )
|| !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CreateLight( int type, Vector3 position, Vector3 target, Color color, Shader shader )" );
lua_pushinteger( L, -1 );
return 1;
}
int type = lua_tointeger( L, 1 );
int type = luaL_checkinteger( L, 1 );
Vector3 position = uluaGetVector3Index( L, 2 );
Vector3 target = uluaGetVector3Index( L, 3 );
Color color = uluaGetColorIndex( L, 4 );
size_t shaderId = lua_tointeger( L, 5 );
Shader *shader = luaL_checkudata( L, 5, "Shader" );
int i = newLight();
*state->lights[i] = CreateLight( type, position, target, color, *state->shaders[ shaderId ] );
*state->lights[i] = CreateLight( type, position, target, color, *shader );
lua_pushinteger( L, i );
return 1;
}
/*
> success = RL.UpdateLightValues( Shader shader, Light light )
> RL.UpdateLightValues( Shader shader, Light light )
Send light properties to shader
- Failure return false
- Success return true
*/
int llightsUpdateLightValues( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UpdateLightValues( Shader shader, Light light )" );
lua_pushboolean( L, false );
return 1;
}
size_t shaderId = lua_tointeger( L, 1 );
Shader *shader = luaL_checkudata( L, 1, "Shader" );
size_t lightId = lua_tointeger( L, 2 );
if ( !validLight( lightId ) ) {
lua_pushboolean( L, false );
return 1;
}
if ( !validShader( shaderId ) ) {
lua_pushboolean( L, false );
return 1;
}
UpdateLightValues( *state->shaders[ shaderId ], *state->lights[ lightId ] );
lua_pushboolean( L, true );
UpdateLightValues( *shader, *state->lights[ lightId ] );
return 1;
return 0;
}
/*

View File

@@ -14,6 +14,116 @@
#include "lgl.h"
#include "reasings.h"
/* Define types. */
/* Buffer. */
static int gcBuffer( lua_State *L ) {
Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" );
free( buffer->data );
}
static void defineBuffer() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "Buffer" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, gcBuffer );
lua_setfield( L, -2, "__gc" );
}
/* Image */
static int gcImage( lua_State *L ) {
Image *image = luaL_checkudata ( L, 1, "Image" );
printf( "gcImage\n" );
UnloadImage( *image );
}
static void defineImage() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "Image" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, gcImage );
lua_setfield( L, -2, "__gc" );
}
/* Texture */
static int gcTexture( lua_State *L ) {
Texture *texture = luaL_checkudata ( L, 1, "Texture" );
printf( "gcTexture\n" );
UnloadTexture( *texture );
}
static void defineTexture() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "Texture" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, gcTexture );
lua_setfield( L, -2, "__gc" );
}
/* RenderRexture. */
static int gcRenderTexture( lua_State *L ) {
RenderTexture *renderTexture = luaL_checkudata ( L, 1, "RenderTexture" );
printf( "gcRenderTexture\n" );
UnloadRenderTexture( *renderTexture );
}
static void defineRenderTexture() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "RenderTexture" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, gcRenderTexture );
lua_setfield( L, -2, "__gc" );
}
/* Camera2D. */
static void defineCamera2D() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "Camera2D" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
}
/* Camera3D. */
static void defineCamera3D() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "Camera3D" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
}
/* Shader. */
static int gcShader( lua_State *L ) {
Shader *shader = luaL_checkudata ( L, 1, "Shader" );
printf( "gcShader\n" );
UnloadShader( *shader );
}
static void defineShader() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "Shader" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, gcShader );
lua_setfield( L, -2, "__gc" );
}
/* Assing globals. */
static void assignGlobalInt( int value, const char *name ) {
lua_State *L = state->luaState;
lua_pushinteger( L, value );
@@ -371,9 +481,6 @@ static void defineGlobals() {
assignGlobalInt( NPATCH_NINE_PATCH, "NPATCH_NINE_PATCH" );
assignGlobalInt( NPATCH_THREE_PATCH_VERTICAL, "NPATCH_THREE_PATCH_VERTICAL" );
assignGlobalInt( NPATCH_THREE_PATCH_HORIZONTAL, "NPATCH_THREE_PATCH_HORIZONTAL" );
/* TextureTypes */
assignGlobalInt( TEXTURE_TYPE_TEXTURE, "TEXTURE_TYPE_TEXTURE" );
assignGlobalInt( TEXTURE_TYPE_RENDER_TEXTURE, "TEXTURE_TYPE_RENDER_TEXTURE" );
/* Colors */
assignGlobalColor( LIGHTGRAY, "LIGHTGRAY" );
assignGlobalColor( GRAY, "GRAY" );
@@ -641,39 +748,6 @@ static void defineGlobals() {
lua_pop( L, -1 );
}
static int gcBuffer( lua_State *L ) {
Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" );
free( buffer->data );
}
static void defineBuffer() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "Buffer" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, gcBuffer );
lua_setfield( L, -2, "__gc" );
}
// static int gcTexture( lua_State *L ) {
// Texture *texture = luaL_checkudata ( L, 1, "Texture" );
// printf( "gcTexture\n" );
// printf( "\ttexture->id = %d\n", texture->id );
// UnloadTexture( *texture );
// }
// static void defineTexture() {
// lua_State *L = state->luaState;
// luaL_newmetatable( L, "Texture" );
// lua_pushvalue( L, -1 );
// lua_setfield( L, -2, "__index" );
// lua_pushcfunction( L, gcTexture );
// lua_setfield( L, -2, "__gc" );
// }
// Custom logging funtion.
static void logCustom( int logLevel, const char *text, va_list args ) {
char string[ STRING_LEN ] = {'\0'};
@@ -1060,8 +1134,14 @@ bool luaInit( int argn, const char **argc ) {
return false;
}
defineGlobals();
/* Define object types. */
defineBuffer();
// defineTexture();
defineImage();
defineTexture();
defineRenderTexture();
defineCamera2D();
defineCamera3D();
defineShader();
/* Set arguments. */
lua_getglobal( L, "RL" );
@@ -1124,7 +1204,6 @@ bool luaCallMain() {
if ( lua_tostring( state->luaState, -1 ) ) {
TraceLog( LOG_ERROR, "Lua error: %s\n", lua_tostring( state->luaState, -1 ) );
}
lua_pushcfunction( L, luaTraceback );
int tracebackidx = lua_gettop( L );
@@ -1235,7 +1314,6 @@ void luaRegister() {
/* Core. */
/* Window. */
assingGlobalFunction( "IsWindowReady", lcoreIsWindowReady );
assingGlobalFunction( "IsWindowFullscreen", lcoreIsWindowFullscreen );
assingGlobalFunction( "IsWindowHidden", lcoreIsWindowHidden );
@@ -1307,7 +1385,6 @@ void luaRegister() {
assingGlobalFunction( "SetShaderValueTexture", lcoreSetShaderValueTexture );
assingGlobalFunction( "SetShaderValue", lcoreSetShaderValue );
assingGlobalFunction( "SetShaderValueV", lcoreSetShaderValueV );
assingGlobalFunction( "UnloadShader", lcoreUnloadShader );
/* File. */
assingGlobalFunction( "GetBasePath", lcoreGetBasePath );
assingGlobalFunction( "FileExists", lcoreFileExists );
@@ -1329,7 +1406,6 @@ void luaRegister() {
assingGlobalFunction( "GetFileModTime", lcoreGetFileModTime );
/* Camera2D. */
assingGlobalFunction( "CreateCamera2D", lcoreCreateCamera2D );
assingGlobalFunction( "UnloadCamera2D", lcoreUnloadCamera2D );
assingGlobalFunction( "BeginMode2D", lcoreBeginMode2D );
assingGlobalFunction( "EndMode2D", lcoreEndMode2D );
assingGlobalFunction( "SetCamera2DTarget", lcoreSetCamera2DTarget );
@@ -1342,7 +1418,6 @@ void luaRegister() {
assingGlobalFunction( "GetCamera2DZoom", lcoreGetCamera2DZoom );
/* Camera3D. */
assingGlobalFunction( "CreateCamera3D", lcoreCreateCamera3D );
assingGlobalFunction( "UnloadCamera3D", lcoreUnloadCamera3D );
assingGlobalFunction( "BeginMode3D", lcoreBeginMode3D );
assingGlobalFunction( "EndMode3D", lcoreEndMode3D );
assingGlobalFunction( "SetCamera3DPosition", lcoreSetCamera3DPosition );
@@ -1472,7 +1547,6 @@ void luaRegister() {
assingGlobalFunction( "LoadImage", ltexturesLoadImage );
assingGlobalFunction( "LoadImageFromTexture", ltexturesLoadImageFromTexture );
assingGlobalFunction( "LoadImageFromScreen", ltexturesLoadImageFromScreen );
assingGlobalFunction( "UnloadImage", ltexturesUnloadImage );
assingGlobalFunction( "ExportImage", ltexturesExportImage );
assingGlobalFunction( "ExportImageAsCode", ltexturesExportImageAsCode );
/* Image Generation. */
@@ -1535,7 +1609,6 @@ void luaRegister() {
assingGlobalFunction( "LoadTextureFromImage", ltexturesLoadTextureFromImage );
assingGlobalFunction( "LoadTextureCubemap", ltexturesLoadTextureCubemap );
assingGlobalFunction( "LoadRenderTexture", ltexturesLoadRenderTexture );
assingGlobalFunction( "UnloadTexture", ltexturesUnloadTexture );
assingGlobalFunction( "IsTextureReady", ltexturesIsTextureReady );
assingGlobalFunction( "UpdateTexture", ltexturesUpdateTexture );
assingGlobalFunction( "UpdateTextureRec", ltexturesUpdateTextureRec );
@@ -1546,7 +1619,6 @@ void luaRegister() {
assingGlobalFunction( "DrawTextureNPatch", ltexturesDrawTextureNPatch );
assingGlobalFunction( "BeginTextureMode", ltexturesBeginTextureMode );
assingGlobalFunction( "EndTextureMode", ltexturesEndTextureMode );
assingGlobalFunction( "GetTextureType", ltexturesGetTextureType );
/* Texture Configuration. */
assingGlobalFunction( "GenTextureMipmaps", ltexturesGenTextureMipmaps );
assingGlobalFunction( "SetTextureFilter", ltexturesSetTextureFilter );
@@ -1555,6 +1627,10 @@ void luaRegister() {
assingGlobalFunction( "GetTextureSize", ltexturesGetTextureSize );
assingGlobalFunction( "GetTextureMipmaps", ltexturesGetTextureMipmaps );
assingGlobalFunction( "GetTextureFormat", ltexturesGetTextureFormat );
/* RenderTexture Configuration. */
assingGlobalFunction( "GetRenderTextureId", ltexturesGetRenderTextureId );
assingGlobalFunction( "GetRenderTextureTexture", ltexturesGetRenderTextureTexture );
assingGlobalFunction( "GetRenderTextureDepthTexture", ltexturesGetRenderTextureDepthTexture );
/* Color/pixel */
assingGlobalFunction( "Fade", ltexturesFade );
assingGlobalFunction( "ColorToInt", ltexturesColorToInt );
@@ -2063,76 +2139,20 @@ void luaRegister() {
lua_pop( L, -1 );
}
/* Type validators. */
bool isValidTexture( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) {
int id = lua_tointeger( L, index );
if ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL ) {
return true;
}
}
else if ( allowTable && lua_istable( L, index ) ) {
return true;
}
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Texture." );
return false;
}
bool isValidRenderTexture( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) {
int id = lua_tointeger( L, index );
if ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL
&& state->textures[ id ]->type == TEXTURE_TYPE_RENDER_TEXTURE ) {
return true;
}
}
else if ( allowTable && lua_istable( L, index ) ) {
return true;
}
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid RenderTexture." );
return false;
}
bool isValidCamera2D( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) {
int id = lua_tointeger( L, index );
if ( 0 <= id && id < state->camera2DCount && state->camera2Ds[ id ] != NULL ) {
return true;
}
}
else if ( allowTable && lua_istable( L, index ) ) {
return true;
}
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera2D." );
return false;
}
bool isValidCamera3D( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) {
int id = lua_tointeger( L, index );
if ( ( 0 <= id && id < state->camera3DCount && state->camera3Ds[ id ] != NULL ) ) {
return true;
}
}
else if ( allowTable && lua_istable( L, index ) ) {
return true;
}
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera3D." );
return false;
}
/* Lua util functions. */
bool uluaGetBoolean( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TBOOLEAN );
return lua_toboolean( L, index );
}
Color uluaGetColor( lua_State *L ) {
return uluaGetColorIndex( L, lua_gettop( L ) );
}
Color uluaGetColorIndex( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
Color color = { 0, 0, 0, 255 };
if ( !lua_istable( L, index ) ) {
@@ -2188,7 +2208,7 @@ Vector2 uluaGetVector2( lua_State *L ) {
}
Vector2 uluaGetVector2Index( lua_State *L, int index ) {
// luaL_checktype( L, index, LUA_TTABLE );
luaL_checktype( L, index, LUA_TTABLE );
Vector2 vector = { 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
@@ -2232,6 +2252,7 @@ Vector3 uluaGetVector3( lua_State *L ) {
}
Vector3 uluaGetVector3Index( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
Vector3 vector = { 0.0f, 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
@@ -2281,6 +2302,7 @@ Vector4 uluaGetVector4( lua_State *L ) {
}
Vector4 uluaGetVector4Index( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
Vector4 vector = { 0.0f, 0.0f, 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
@@ -2336,6 +2358,7 @@ Rectangle uluaGetRectangle( lua_State *L ) {
}
Rectangle uluaGetRectangleIndex( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
Rectangle rect = { 0.0f, 0.0f, 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
@@ -2392,6 +2415,7 @@ Quaternion uluaGetQuaternion( lua_State *L ) {
}
Quaternion uluaGetQuaternionIndex( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
Quaternion quaternion = { 0.0f, 0.0f, 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
@@ -2447,6 +2471,7 @@ Matrix uluaGetMatrix( lua_State *L ) {
}
Matrix uluaGetMatrixIndex( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
Matrix matrix = { 0.0f };
float m[4][4];
@@ -2486,6 +2511,7 @@ BoundingBox uluaGetBoundingBox( lua_State *L ) {
}
BoundingBox uluaGetBoundingBoxIndex( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
BoundingBox box = { .min = { 0.0, 0.0, 0.0 }, .max = { 0.0, 0.0, 0.0 } };
if ( !lua_istable( L, index ) ) {
@@ -2530,6 +2556,7 @@ Ray uluaGetRay( lua_State *L ) {
}
Ray uluaGetRayIndex( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
Ray ray = { .position = { 0.0, 0.0, 0.0 }, .direction = { 0.0, 0.0, 0.0 } };
if ( !lua_istable( L, index ) ) {
@@ -2574,6 +2601,7 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L ) {
}
NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
NPatchInfo npatch = { .source = { 0.0, 0.0, 0.0, 0.0 }, .left = 0, .top = 0, .right = 0, .bottom = 0, .layout = NPATCH_NINE_PATCH };
if ( !lua_istable( L, index ) ) {
@@ -2635,216 +2663,6 @@ NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index ) {
return npatch;
}
Texture uluaGetTexture( lua_State *L, int index ) {
Texture texture = { 0 };
if ( lua_isnumber( L, index ) ) {
texture = *texturesGetSourceTexture( lua_tointeger( L, index ) );
}
else if ( lua_istable( L, index ) ) {
int t = index, i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( lua_isnumber( L, -2 ) ) {
switch ( i ) {
case 0:
texture.id = lua_tointeger( L, -1 );
break;
case 1:
texture.width = lua_tointeger( L, -1 );
break;
case 2:
texture.height = lua_tointeger( L, -1 );
break;
case 3:
texture.mipmaps = lua_tointeger( L, -1 );
break;
case 4:
texture.format = lua_tointeger( L, -1 );
break;
default:
break;
}
}
else if ( lua_isstring( L, -2 ) ) {
if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.id = lua_tointeger( L, -1 );
}
else if ( strcmp( "width", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.width = lua_tointeger( L, -1 );
}
else if ( strcmp( "height", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.height = lua_tointeger( L, -1 );
}
else if ( strcmp( "mipmaps", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.mipmaps = lua_tointeger( L, -1 );
}
else if ( strcmp( "format", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.format = lua_tointeger( L, -1 );
}
}
i++;
lua_pop( L, 1 );
}
}
return texture;
}
RenderTexture uluaGetRenderTexture( lua_State *L, int index ) {
RenderTexture renderTexture = { 0 };
if ( lua_isnumber( L, index ) ) {
renderTexture = state->textures[ lua_tointeger( L, index ) ]->renderTexture;
}
else if ( lua_istable( L, index ) ) {
int t = index, i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( lua_isnumber( L, -2 ) ) {
switch ( i ) {
case 0:
renderTexture.id = lua_tointeger( L, -1 );
break;
case 1:
renderTexture.texture = uluaGetTexture( L, lua_gettop( L ) );
break;
case 2:
renderTexture.depth = uluaGetTexture( L, lua_gettop( L ) );
break;
default:
break;
}
}
else if ( lua_isstring( L, -2 ) ) {
if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
renderTexture.id = lua_tointeger( L, -1 );
}
else if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 ) {
renderTexture.texture = uluaGetTexture( L, lua_gettop( L ) );
}
else if ( strcmp( "depth", (char*)lua_tostring( L, -2 ) ) == 0 ) {
renderTexture.depth = uluaGetTexture( L, lua_gettop( L ) );
}
}
i++;
lua_pop( L, 1 );
}
}
return renderTexture;
}
Camera2D uluaGetCamera2D( lua_State *L, int index ) {
Camera2D camera = { 0 };
if ( lua_isnumber( L, index ) ) {
camera = *state->camera2Ds[ lua_tointeger( L, index ) ];
}
else if ( lua_istable( L, index ) ) {
int t = index, i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( lua_isnumber( L, -2 ) ) {
switch ( i ) {
case 0:
camera.offset = uluaGetVector2Index( L, lua_gettop( L ) );
break;
case 1:
camera.target = uluaGetVector2Index( L, lua_gettop( L ) );
break;
case 2:
camera.rotation = lua_tonumber( L, -1 );
break;
case 3:
camera.zoom = lua_tonumber( L, -1 );
break;
default:
break;
}
}
else if ( lua_isstring( L, -2 ) ) {
if ( strcmp( "offset", (char*)lua_tostring( L, -2 ) ) == 0 ) {
camera.offset = uluaGetVector2Index( L, lua_gettop( L ) );
}
else if ( strcmp( "target", (char*)lua_tostring( L, -2 ) ) == 0 ) {
camera.target = uluaGetVector2Index( L, lua_gettop( L ) );
}
else if ( strcmp( "rotation", (char*)lua_tostring( L, -2 ) ) == 0 ) {
camera.rotation = lua_tonumber( L, -1 );
}
else if ( strcmp( "zoom", (char*)lua_tostring( L, -2 ) ) == 0 ) {
camera.zoom = lua_tonumber( L, -1 );
}
}
i++;
lua_pop( L, 1 );
}
}
return camera;
}
Camera3D uluaGetCamera3D( lua_State *L, int index ) {
Camera3D camera = { 0 };
if ( lua_isnumber( L, index ) ) {
camera = *state->camera3Ds[ lua_tointeger( L, index ) ];
}
else if ( lua_istable( L, index ) ) {
int t = index, i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( lua_isnumber( L, -2 ) ) {
switch ( i ) {
case 0:
camera.position = uluaGetVector3Index( L, lua_gettop( L ) );
break;
case 1:
camera.target = uluaGetVector3Index( L, lua_gettop( L ) );
break;
case 2:
camera.up = uluaGetVector3Index( L, lua_gettop( L ) );
break;
case 3:
camera.fovy = lua_tonumber( L, -1 );
break;
case 4:
camera.projection = lua_tointeger( L, -1 );
break;
default:
break;
}
}
else if ( lua_isstring( L, -2 ) ) {
if ( strcmp( "position", (char*)lua_tostring( L, -2 ) ) == 0 ) {
camera.position = uluaGetVector3Index( L, lua_gettop( L ) );
}
else if ( strcmp( "target", (char*)lua_tostring( L, -2 ) ) == 0 ) {
camera.target = uluaGetVector3Index( L, lua_gettop( L ) );
}
else if ( strcmp( "up", (char*)lua_tostring( L, -2 ) ) == 0 ) {
camera.up = uluaGetVector3Index( L, lua_gettop( L ) );
}
else if ( strcmp( "fovy", (char*)lua_tostring( L, -2 ) ) == 0 ) {
camera.fovy = lua_tonumber( L, -1 );
}
else if ( strcmp( "projection", (char*)lua_tostring( L, -2 ) ) == 0 ) {
camera.projection = lua_tointeger( L, -1 );
}
}
i++;
lua_pop( L, 1 );
}
}
return camera;
}
/* Push types. */
void uluaPushColor( lua_State *L, Color color ) {
@@ -3017,18 +2835,40 @@ void uluaPushBoundingBox( lua_State *L, BoundingBox box ) {
lua_rawseti( L, -2, 2 );
}
void uluaPushImage( lua_State *L, Image image ) {
Image *imageP = lua_newuserdata( L, sizeof( Image ) );
*imageP = image;
luaL_setmetatable( L, "Image" );
}
void uluaPushTexture( lua_State *L, Texture texture ) {
lua_createtable( L, 5, 0 );
lua_pushinteger( L, texture.id );
lua_setfield( L, -2, "id" );
lua_pushinteger( L, texture.width );
lua_setfield( L, -2, "width" );
lua_pushinteger( L, texture.height );
lua_setfield( L, -2, "height" );
lua_pushinteger( L, texture.mipmaps );
lua_setfield( L, -2, "mipmaps" );
lua_pushinteger( L, texture.format );
lua_setfield( L, -2, "format" );
Texture *textureP = lua_newuserdata( L, sizeof( Texture ) );
*textureP = texture;
luaL_setmetatable( L, "Texture" );
}
void uluaPushRenderTexture( lua_State *L, RenderTexture renderTexture ) {
RenderTexture *renderTextureP = lua_newuserdata( L, sizeof( RenderTexture ) );
*renderTextureP = renderTexture;
luaL_setmetatable( L, "RenderTexture" );
}
void uluaPushCamera2D( lua_State *L, Camera2D camera ) {
Camera2D *cameraP = lua_newuserdata( L, sizeof( Camera2D ) );
*cameraP = camera;
luaL_setmetatable( L, "Camera2D" );
}
void uluaPushCamera3D( lua_State *L, Camera3D camera ) {
Camera3D *cameraP = lua_newuserdata( L, sizeof( Camera3D ) );
*cameraP = camera;
luaL_setmetatable( L, "Camera3D" );
}
void uluaPushShader( lua_State *L, Shader shader ) {
Shader *shaderP = lua_newuserdata( L, sizeof( Shader ) );
*shaderP = shader;
luaL_setmetatable( L, "Shader" );
}
int uluaGetTableLen( lua_State *L ) {
@@ -3036,6 +2876,7 @@ int uluaGetTableLen( lua_State *L ) {
}
int uluaGetTableLenIndex( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
int t = index, i = 0;
lua_pushnil( L );

View File

@@ -700,21 +700,12 @@ int lmodelsDrawPlane( lua_State *L ) {
}
/*
> success = RL.DrawQuad3DTexture( Texture2D texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )
> RL.DrawQuad3DTexture( Texture texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )
Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ).
- Failure return false
- Success return true
*/
int lmodelDrawQuad3DTexture( lua_State *L ) {
if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawQuad3DTexture( Texture2D texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )" );
lua_pushboolean( L, false );
return 1;
}
/* Texture. */
Texture texture = uluaGetTexture( L, 1 );
Texture *texture = luaL_checkudata( L, 1, "Texture" );
/* Vertices. */
Vector3 vertices[4] = { 0 };
@@ -762,7 +753,7 @@ int lmodelDrawQuad3DTexture( lua_State *L ) {
/* Draw. */
rlCheckRenderBatchLimit( 4 );
rlSetTexture( texture.id );
rlSetTexture( texture->id );
rlBegin( RL_QUADS );
for ( i = 0; i < 4; ++i ) {
@@ -773,9 +764,7 @@ int lmodelDrawQuad3DTexture( lua_State *L ) {
rlEnd();
rlSetTexture( 0 );
lua_pushboolean( L, true );
return 1;
return 0;
}
/*
@@ -1053,19 +1042,9 @@ Generate heightmap mesh from image data
- Success return int
*/
int lmodelsGenMeshHeightmap( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshHeightmap( Image heightmap, Vector3 size )" );
lua_pushinteger( L, -1 );
return 1;
}
size_t imageId = lua_tointeger( L, 1 );
Image *heightmap = luaL_checkudata( L, 1, "Image" );
Vector3 size = uluaGetVector3Index( L, 2 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
Image *heightmap = state->images[ imageId ];
int i = newMesh();
*state->meshes[i] = GenMeshHeightmap( *heightmap, size );
@@ -1661,14 +1640,15 @@ int lmodelsCreateMaterial( lua_State *L ) {
lua_pushnil( L );
while ( lua_next( L, t4 ) != 0 ) {
if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 && isValidTexture( L, lua_gettop( L ), true ) ) {
state->materials[i]->maps[map].texture = uluaGetTexture( L, lua_gettop( L ) );
if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 ) {
Texture *texture = luaL_checkudata( L, lua_gettop( L ), "Texture" );
state->materials[i]->maps[map].texture = *texture;
}
else if ( strcmp( "color", (char*)lua_tostring( L, -2 ) ) == 0 && lua_istable( L, -1 ) ) {
state->materials[i]->maps[map].color = uluaGetColor( L );
else if ( strcmp( "color", (char*)lua_tostring( L, -2 ) ) == 0 ) {
state->materials[i]->maps[map].color = uluaGetColorIndex( L, lua_gettop( L ) );
}
else if ( strcmp( "value", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) {
state->materials[i]->maps[map].value = lua_tonumber( L, -1 );
else if ( strcmp( "value", (char*)lua_tostring( L, -2 ) ) == 0 ) {
state->materials[i]->maps[map].value = luaL_checkinteger( L, -1 );
}
lua_pop( L, 1 );
}
@@ -1697,7 +1677,8 @@ int lmodelsCreateMaterial( lua_State *L ) {
}
}
else if ( strcmp( "shader", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) {
state->materials[i]->shader = *state->shaders[ lua_tointeger( L, -1 ) ];
Shader *shader = luaL_checkudata( L, lua_gettop( L ), "Shader" );
state->materials[i]->shader = *shader;
}
lua_pop( L, 1 );
}
@@ -1735,27 +1716,18 @@ int lmodelsUnloadMaterial( lua_State *L ) {
}
/*
> success = RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )
> RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )
Set texture for a material map type ( MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS... )
- Failure return false
- Success return true
*/
int lmodelsSetMaterialTexture( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !isValidTexture( L, 3, true ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
}
size_t materialId = lua_tointeger( L, 1 );
int mapType = lua_tointeger( L, 2 );
Texture texture = uluaGetTexture( L, 3 );
Texture *texture = luaL_checkudata( L, 3, "Texture" );
SetMaterialTexture( state->materials[ materialId ], mapType, texture );
lua_pushboolean( L, true );
SetMaterialTexture( state->materials[ materialId ], mapType, *texture );
return 1;
return 0;
}
/*
@@ -1815,30 +1787,17 @@ int lmodelsSetMaterialValue( lua_State *L ) {
}
/*
> success = RL.SetMaterialShader( Material material, Shader shader )
> RL.SetMaterialShader( Material material, Shader shader )
Set shader for material
- Failure return false
- Success return true
*/
int lmodelsSetMaterialShader( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMaterialShader( Material material, Shader shader )" );
lua_pushboolean( L, false );
return 1;
}
size_t materialId = lua_tointeger( L, 1 );
size_t shaderId = lua_tointeger( L, 2 );
Shader *shader = luaL_checkudata( L, 2, "Shader" );
if ( !validMaterial( materialId || !validShader( shaderId ) ) ) {
lua_pushboolean( L, false );
return 1;
}
state->materials[ materialId ]->shader = *state->shaders[ shaderId ];
lua_pushboolean( L, true );
state->materials[ materialId ]->shader = *shader;
return 1;
return 0;
}
/*
@@ -1892,32 +1851,32 @@ Get texture from material map type. Returns -1 if no texture.
- Success return int
*/
int lmodelsGetMaterialTexture( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialTexture( Material material, int mapType )" );
lua_pushboolean( L, false );
return 1;
}
size_t materialId = lua_tointeger( L, 1 );
int mapType = lua_tointeger( L, 2 );
// if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
// TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialTexture( Material material, int mapType )" );
// lua_pushboolean( L, false );
// return 1;
// }
// size_t materialId = lua_tointeger( L, 1 );
// int mapType = lua_tointeger( L, 2 );
if ( !validMaterial( materialId ) ) {
lua_pushboolean( L, false );
return 1;
}
/* Check what ReiLua texture has same openGL texture and return that. */
for ( int i = 0; i < state->textureCount; i++ ) {
if ( state->textures[i]->type == TEXTURE_TYPE_TEXTURE
&& state->textures[i]->texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
lua_pushinteger( L, i );
return 1;
}
else if ( state->textures[i]->type == TEXTURE_TYPE_RENDER_TEXTURE
&& state->textures[i]->renderTexture.texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
lua_pushinteger( L, i );
return 1;
}
}
lua_pushinteger( L, -1 );
// if ( !validMaterial( materialId ) ) {
// lua_pushboolean( L, false );
// return 1;
// }
// /* Check what ReiLua texture has same openGL texture and return that. */
// for ( int i = 0; i < state->textureCount; i++ ) {
// if ( state->textures[i]->type == TEXTURE_TYPE_TEXTURE
// && state->textures[i]->texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
// lua_pushinteger( L, i );
// return 1;
// }
// else if ( state->textures[i]->type == TEXTURE_TYPE_RENDER_TEXTURE
// && state->textures[i]->renderTexture.texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
// lua_pushinteger( L, i );
// return 1;
// }
// }
// lua_pushinteger( L, -1 );
return 1;
}
@@ -1980,7 +1939,7 @@ int lmodelsGetMaterialValue( lua_State *L ) {
Get material shader. Returns -1 if no shader.
- Failure return false
- Success return int
- Success return Shader
*/
int lmodelsGetMaterialShader( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
@@ -1994,14 +1953,17 @@ int lmodelsGetMaterialShader( lua_State *L ) {
lua_pushboolean( L, false );
return 1;
}
uluaPushShader( L, state->materials[ materialId ]->shader );
/* Look for shader that has same shader program id. */
for ( int i = 0; i < state->shaderCount; i++ ) {
if ( state->shaders[i]->id == state->materials[ materialId ]->shader.id ) {
lua_pushinteger( L, i );
return 1;
}
}
lua_pushinteger( L, -1 );
// for ( int i = 0; i < state->shaderCount; i++ ) {
// if ( state->shaders[i]->id == state->materials[ materialId ]->shader.id ) {
// lua_pushinteger( L, i );
// return 1;
// }
// }
// lua_pushinteger( L, -1 );
return 1;
}
@@ -2263,92 +2225,59 @@ int lmodelsSetModelMeshMaterial( lua_State *L ) {
}
/*
> success = RL.DrawBillboard( Camera3D camera, Texture2D texture, Vector3 position, float size, Color tint )
> RL.DrawBillboard( Camera3D camera, Texture texture, Vector3 position, float size, Color tint )
Draw a billboard texture
- Failure return false
- Success return true
*/
int lmodelsDrawBillboard( lua_State *L ) {
if ( !isValidCamera3D( L, 1, true ) || !isValidTexture( L, 2, true ) || !lua_istable( L, 3 )
|| !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawBillboard( Camera camera, Texture2D texture, Vector3 position, float size, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Camera3D camera = uluaGetCamera3D( L, 1 );
Texture texture = uluaGetTexture( L, 2 );
Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
Texture *texture = luaL_checkudata( L, 2, "Texture" );
Vector3 position = uluaGetVector3Index( L, 3 );
float size = lua_tonumber( L, 4 );
float size = luaL_checknumber( L, 4 );
Color tint = uluaGetColorIndex( L, 5 );
DrawBillboard( camera, texture, position, size, tint );
lua_pushboolean( L, true );
DrawBillboard( *camera, *texture, position, size, tint );
return 1;
return 0;
}
/*
> success = RL.DrawBillboardRec( Camera3D camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint )
> RL.DrawBillboardRec( Camera3D camera, Texture texture, Rectangle source, Vector3 position, Vector2 size, Color tint )
Draw a billboard texture defined by source
- Failure return false
- Success return true
*/
int lmodelsDrawBillboardRec( lua_State *L ) {
if ( !isValidCamera3D( L, 1, true ) || !isValidTexture( L, 2, true ) || !lua_istable( L, 3 )
|| !lua_istable( L, 4 ) || !lua_istable( L, 5 ) || !lua_istable( L, 6 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawBillboardRec( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Camera3D camera = uluaGetCamera3D( L, 1 );
Texture texture = uluaGetTexture( L, 2 );
Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
Texture *texture = luaL_checkudata( L, 2, "Texture" );
Rectangle source = uluaGetRectangleIndex( L, 3 );
Vector3 position = uluaGetVector3Index( L, 4 );
Vector2 size = uluaGetVector2Index( L, 5 );
Color tint = uluaGetColorIndex( L, 6 );
// DrawBillboardRec( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, size, tint );
DrawBillboardRecNoRatio( camera, texture, source, position, size, tint );
lua_pushboolean( L, true );
DrawBillboardRecNoRatio( *camera, *texture, source, position, size, tint );
return 1;
return 0;
}
/*
> success = RL.DrawBillboardPro( Camera3D camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )
> RL.DrawBillboardPro( Camera3D camera, Texture texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )
Draw a billboard texture defined by source and rotation
- Failure return false
- Success return true
*/
int lmodelsDrawBillboardPro( lua_State *L ) {
if ( !isValidCamera3D( L, 1, true ) || !isValidTexture( L, 2, true ) || !lua_istable( L, 3 )
|| !lua_istable( L, 4 ) || !lua_istable( L, 5 ) || !lua_istable( L, 6 )
|| !lua_istable( L, 7 ) || !lua_isnumber( L, 8 ) || !lua_istable( L, 9 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawBillboardPro( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Camera3D camera = uluaGetCamera3D( L, 1 );
Texture texture = uluaGetTexture( L, 2 );
Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
Texture *texture = luaL_checkudata( L, 2, "Texture" );
Rectangle source = uluaGetRectangleIndex( L, 3 );
Vector3 position = uluaGetVector3Index( L, 4 );
Vector3 up = uluaGetVector3Index( L, 5 );
Vector2 size = uluaGetVector2Index( L, 6 );
Vector2 origin = uluaGetVector2Index( L, 7 );
float rotation = lua_tonumber( L, 8 );
float rotation = luaL_checknumber( L, 8 );
Color tint = uluaGetColorIndex( L, 9 );
// DrawBillboardPro( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, up, size, origin, rotation, tint );
DrawBillboardProNoRatio( camera, texture, source, position, up, size, origin, rotation, tint );
lua_pushboolean( L, true );
DrawBillboardProNoRatio( *camera, *texture, source, position, up, size, origin, rotation, tint );
return 1;
return 0;
}
/*

View File

@@ -9,28 +9,19 @@
*/
/*
> success = RL.SetShapesTexture( Texture2D texture, Rectangle source )
> RL.SetShapesTexture( Texture texture, Rectangle source )
Set texture and rectangle to be used on shapes drawing
NOTE: It can be useful when using basic shapes and one single font,
defining a font char white rectangle would allow drawing everything in a single draw call
- Failure return false
- Success return true
*/
int lshapesSetShapesTexture( lua_State *L ) {
if ( !isValidTexture( L, 1, true ) || !lua_isnumber( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetShapesTexture( Texture2D texture, Rectangle source )" );
lua_pushboolean( L, false );
return 1;
}
Texture texture = uluaGetTexture( L, 1 );
Texture *texture = luaL_checkudata( L, 1, "Texture" );
Rectangle source = uluaGetRectangleIndex( L, 2 );
SetShapesTexture( texture, source );
lua_pushboolean( L, true );
SetShapesTexture( *texture, source );
return 1;
return 0;
}
/*

View File

@@ -18,14 +18,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
state->luaState = NULL;
state->guiFont = 0;
state->logLevelInvalid = LOG_ERROR;
/* Images. */
state->imageAlloc = ALLOC_PAGE_SIZE;
state->imageCount = 0;
state->images = malloc( state->imageAlloc * sizeof( Image* ) );
/* Textures. */
state->textureAlloc = ALLOC_PAGE_SIZE;
state->textureCount = 0;
state->textures = malloc( state->textureAlloc * sizeof( ReiTexture* ) );
/* Fonts. */
state->fontAlloc = ALLOC_PAGE_SIZE;
state->fontCount = 1;
@@ -42,14 +34,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
state->musicAlloc = ALLOC_PAGE_SIZE;
state->musicCount = 0;
state->musics = malloc( state->musicAlloc * sizeof( Music* ) );
/* Camera2D's. */
state->camera2DAlloc = ALLOC_PAGE_SIZE;
state->camera2DCount = 0;
state->camera2Ds = malloc( state->camera2DAlloc * sizeof( Camera2D* ) );
/* Camera3D's. */
state->camera3DAlloc = ALLOC_PAGE_SIZE;
state->camera3DCount = 0;
state->camera3Ds = malloc( state->camera3DAlloc * sizeof( Camera3D* ) );
/* Meshes. */
state->meshAlloc = ALLOC_PAGE_SIZE;
state->meshCount = 0;
@@ -66,26 +50,17 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
state->animationAlloc = ALLOC_PAGE_SIZE;
state->animationCount = 0;
state->animations = malloc( state->animationAlloc * sizeof( ModelAnimations* ) );
/* Shaders. */
state->shaderAlloc = ALLOC_PAGE_SIZE;
state->shaderCount = 0;
state->shaders = malloc( state->shaderAlloc * sizeof( Shader* ) );
/* Lights. */
state->lightAlloc = ALLOC_PAGE_SIZE;
state->lightCount = 0;
state->lights = malloc( state->lightAlloc * sizeof( Light* ) );
for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) {
state->images[i] = NULL;
state->textures[i] = NULL;
state->waves[i] = NULL;
state->sounds[i] = NULL;
state->camera2Ds[i] = NULL;
state->camera3Ds[i] = NULL;
state->meshes[i] = NULL;
state->models[i] = NULL;
state->animations[i] = NULL;
state->shaders[i] = NULL;
state->lights[i] = NULL;
/* The ones we want to save the first. */
@@ -119,18 +94,6 @@ void stateInitInterpret( int argn, const char **argc ) {
}
void stateFree() {
for ( int i = 0; i < state->imageCount; ++i ) {
if ( state->images[i] != NULL ) {
UnloadImage( *state->images[i] );
free( state->images[i] );
}
}
for ( int i = 0; i < state->textureCount; ++i ) {
if ( state->textures[i] != NULL ) {
texturesFreeTexture(i);
free( state->textures[i] );
}
}
for ( int i = 0; i < state->fontCount; ++i ) {
if ( state->fonts[i] != NULL ) {
UnloadFont( *state->fonts[i] );
@@ -155,16 +118,6 @@ void stateFree() {
free( state->musics[i] );
}
}
for ( int i = 0; i < state->camera2DCount; ++i ) {
if ( state->camera2Ds[i] != NULL ) {
free( state->camera2Ds[i] );
}
}
for ( int i = 0; i < state->camera3DCount; ++i ) {
if ( state->camera3Ds[i] != NULL ) {
free( state->camera3Ds[i] );
}
}
for ( int i = 0; i < state->modelCount; ++i ) {
if ( state->models[i] != NULL ) {
//TODO Test if UnloadModel causes segfaults on exit.
@@ -194,12 +147,6 @@ void stateFree() {
free( state->animations[i] );
}
}
for ( int i = 0; i < state->shaderCount; ++i ) {
if ( state->shaders[i] != NULL ) {
UnloadShader( *state->shaders[i] );
free( state->shaders[i] );
}
}
#if !defined( PLATFORM_RPI ) || !defined( PLATFORM_DRM )
for ( int i = 0; i < state->lightCount; ++i ) {
@@ -218,19 +165,14 @@ void stateFree() {
if ( state->hasWindow ) {
CloseWindow();
}
free( state->images );
free( state->textures );
free( state->fonts );
free( state->waves );
free( state->sounds );
free( state->musics );
free( state->camera2Ds );
free( state->camera3Ds );
free( state->meshes );
free( state->materials );
free( state->models );
free( state->animations );
free( state->shaders );
free( state->lights );
free( state->exePath );
free( state );

View File

@@ -114,22 +114,12 @@ Load font from Image ( XNA style )
- Success return int
*/
int ltextLoadFontFromImage( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadFontFromImage( Image image, Color key, int firstChar )" );
lua_pushinteger( L, -1 );
return 1;
}
size_t imageId = lua_tointeger( L, 1 );
Image *image = luaL_checkudata( L, 1, "Image" );
Color key = uluaGetColorIndex( L, 2 );
int firstChar = lua_tointeger( L, 3 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
int i = newFont();
*state->fonts[i] = LoadFontFromImage( *state->images[ imageId ], key, firstChar );
*state->fonts[i] = LoadFontFromImage( *image, key, firstChar );
lua_pushinteger( L, i );
return 1;

File diff suppressed because it is too large Load Diff