From 8008ebf1b041e837eecf54c3904156309508a2a8 Mon Sep 17 00:00:00 2001 From: jussi Date: Thu, 1 Jun 2023 20:35:06 +0300 Subject: New rlgl functions and texture can be given as table. --- src/core.c | 8 +- src/gl.c | 21 ++---- src/lua_core.c | 144 ++++++++++++++++++++++++++++++++++++ src/models.c | 62 ++++++---------- src/rlgl.c | 219 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/shapes.c | 10 +-- src/textures.c | 225 ++++++++++++++++++++------------------------------------- 7 files changed, 478 insertions(+), 211 deletions(-) (limited to 'src') diff --git a/src/core.c b/src/core.c index 11feb35..3a4756d 100644 --- a/src/core.c +++ b/src/core.c @@ -1238,20 +1238,20 @@ Set shader uniform value for texture ( sampler2d ) - Success return true */ int lcoreSetShaderValueTexture( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !isValidTexture( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetShaderValueTexture( Shader shader, int locIndex, Texture2D texture )" ); lua_pushboolean( L, false ); return 1; } size_t shaderId = lua_tointeger( L, 1 ); int locIndex = lua_tointeger( L, 2 ); - size_t textureId = lua_tointeger( L, 3 ); + Texture texture = uluaGetTexture( L, 3 ); - if ( !validShader( shaderId ) || !validTexture( textureId, TEXTURE_TYPE_ALL ) ) { + if ( !validShader( shaderId ) ) { lua_pushboolean( L, false ); return 1; } - SetShaderValueTexture( *state->shaders[ shaderId ], locIndex, *texturesGetSourceTexture( textureId ) ); + SetShaderValueTexture( *state->shaders[ shaderId ], locIndex, texture ); lua_pushboolean( L, true ); return 1; diff --git a/src/gl.c b/src/gl.c index 6bd8a03..57f5376 100644 --- a/src/gl.c +++ b/src/gl.c @@ -18,38 +18,31 @@ Use -1 RenderTexture for window framebuffer. - Success return true */ int lglBlitFramebuffer( lua_State *L ) { - if ( !lua_isnumber( L, 1) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) + if ( !isValidRenderTexture( L, 1) || !isValidRenderTexture( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { TraceLog( LOG_WARNING, "%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; } - int srcTexId = lua_tointeger( L, 1 ); - int dstTexId = lua_tointeger( L, 2 ); + RenderTexture2D srcTex = uluaGetRenderTexture( L, 1 ); + RenderTexture2D dstTex = uluaGetRenderTexture( L, 2 ); Rectangle srcRect = uluaGetRectangleIndex( L, 3 ); Rectangle dstRect = uluaGetRectangleIndex( L, 4 ); int mask = lua_tointeger( L, 5 ); int filter = lua_tointeger( L, 6 ); - // if ( ( !validRenderTexture( srcTexId ) && srcTexId != -1 ) && ( !validRenderTexture( dstTexId ) && dstTexId != -1 ) ) { - if ( ( !validTexture( srcTexId, TEXTURE_TYPE_RENDER_TEXTURE ) && srcTexId != -1 ) - && ( !validTexture( dstTexId, TEXTURE_TYPE_RENDER_TEXTURE ) && dstTexId != -1 ) ) { - lua_pushboolean( L, false ); - return 1; - } - - if ( srcTexId == -1 ) { + if ( lua_tointeger( L, 1 ) == -1 ) { glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); } else { - glBindFramebuffer( GL_READ_FRAMEBUFFER, state->textures[ srcTexId ]->renderTexture.id ); + glBindFramebuffer( GL_READ_FRAMEBUFFER, srcTex.id ); } - if ( dstTexId == -1 ) { + if ( lua_tointeger( L, 2 ) == -1 ) { glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); } else { - glBindFramebuffer( GL_DRAW_FRAMEBUFFER, state->textures[ dstTexId ]->renderTexture.id ); + glBindFramebuffer( GL_DRAW_FRAMEBUFFER, dstTex.id ); } glBlitFramebuffer( diff --git a/src/lua_core.c b/src/lua_core.c index e14395c..14bb73e 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1018,6 +1018,7 @@ void luaRegister() { assingGlobalFunction( "GenTextureMipmaps", ltexturesGenTextureMipmaps ); assingGlobalFunction( "SetTextureFilter", ltexturesSetTextureFilter ); assingGlobalFunction( "SetTextureWrap", ltexturesSetTextureWrap ); + assingGlobalFunction( "GetTextureId", ltexturesGetTextureId ); assingGlobalFunction( "GetTextureSize", ltexturesGetTextureSize ); assingGlobalFunction( "GetTextureMipmaps", ltexturesGetTextureMipmaps ); assingGlobalFunction( "GetTextureFormat", ltexturesGetTextureFormat ); @@ -1370,6 +1371,10 @@ void luaRegister() { assingGlobalFunction( "IsLightEnabled", llightsIsLightEnabled ); /* RLGL */ + /* Framebuffer state. */ + assingGlobalFunction( "rlEnableFramebuffer", lrlglEnableFramebuffer ); + assingGlobalFunction( "rlDisableFramebuffer", lrlglDisableFramebuffer ); + assingGlobalFunction( "rlActiveDrawBuffers", lrlglActiveDrawBuffers ); /* General render state. */ assingGlobalFunction( "rlEnableColorBlend", lrlglEnableColorBlend ); assingGlobalFunction( "rlDisableColorBlend", lrlglDisableColorBlend ); @@ -1386,6 +1391,15 @@ void luaRegister() { assingGlobalFunction( "rlDisableSmoothLines", lrlglDisableSmoothLines ); /* Initialization functions. */ assingGlobalFunction( "rlGetVersion", lrlglGetVersion ); + /* Textures management */ + assingGlobalFunction( "rlLoadTexture", lrlglLoadTexture ); + assingGlobalFunction( "rlLoadTextureDepth", lrlglLoadTextureDepth ); + assingGlobalFunction( "rlUnloadTexture", lrlglUnloadTexture ); + /* Framebuffer management (fbo). */ + assingGlobalFunction( "rlLoadFramebuffer", lrlglLoadFramebuffer ); + assingGlobalFunction( "rlFramebufferAttach", lrlglFramebufferAttach ); + assingGlobalFunction( "rlFramebufferComplete", lrlglFramebufferComplete ); + assingGlobalFunction( "rlUnloadFramebuffer", lrlglUnloadFramebuffer ); /* OpenGL */ /* Framebuffer management. */ @@ -1430,6 +1444,28 @@ void luaRegister() { lua_pop( L, -1 ); } +/* Type validators. */ + +bool isValidTexture( lua_State *L, int index ) { + if ( lua_isnumber( L, index ) || lua_istable( L, index ) ) { + return true; + } + else { + TraceLog( LOG_WARNING, "%s", "Error. Invalid texture." ); + return false; + } +} + +bool isValidRenderTexture( lua_State *L, int index ) { + if ( lua_isnumber( L, index ) || lua_istable( L, index ) ) { + return true; + } + else { + TraceLog( LOG_WARNING, "%s", "Error. Invalid renderTexture." ); + return false; + } +} + /* Lua util functions. */ Color uluaGetColor( lua_State *L ) { @@ -1939,6 +1975,114 @@ NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index ) { return npatch; } +Texture uluaGetTexture( lua_State *L, int index ) { + Texture texture = { 0 }; + + if ( lua_isnumber( L, index ) ) { + if ( 0 <= lua_tointeger( 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 ) ) { + if ( 0 <= lua_tointeger( 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; +} + +/* Push types. */ + void uluaPushColor( lua_State *L, Color color ) { lua_createtable( L, 3, 0 ); lua_pushnumber( L, color.r ); diff --git a/src/models.c b/src/models.c index 30bf73c..dbedb07 100644 --- a/src/models.c +++ b/src/models.c @@ -708,14 +708,13 @@ Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ). - Success return true */ int lmodelDrawQuad3DTexture( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) { + if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawQuad3DTexture( Texture2D texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )" ); lua_pushboolean( L, false ); return 1; } - /* Texture. */ - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); /* Vertices. */ Vector3 vertices[4] = { 0 }; @@ -761,14 +760,9 @@ int lmodelDrawQuad3DTexture( lua_State *L ) { //TODO Normals. maybe something like Vector3Normalize(Vector3CrossProduct(Vector3Subtract(vB, vA), Vector3Subtract(vC, vA))); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - /* Draw. */ rlCheckRenderBatchLimit( 4 ); - rlSetTexture( texturesGetSourceTexture( texId )->id ); + rlSetTexture( texture.id ); rlBegin( RL_QUADS ); for ( i = 0; i < 4; ++i ) { @@ -1668,13 +1662,7 @@ int lmodelsCreateMaterial( lua_State *L ) { while ( lua_next( L, t4 ) != 0 ) { if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) { - size_t texId = lua_tointeger( L, -1 ); - - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - state->materials[i]->maps[map].texture = *texturesGetSourceTexture( texId ); + state->materials[i]->maps[map].texture = uluaGetTexture( L, lua_gettop( L ) ); } else if ( strcmp( "color", (char*)lua_tostring( L, -2 ) ) == 0 && lua_istable( L, -1 ) ) { state->materials[i]->maps[map].color = uluaGetColor( L ); @@ -1755,20 +1743,16 @@ Set texture for a material map type ( MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNES - Success return true */ int lmodelsSetMaterialTexture( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !isValidTexture( L, 3 ) ) { TraceLog( LOG_WARNING, "%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 ); - size_t texId = lua_tointeger( L, 3 ); + Texture texture = uluaGetTexture( L, 3 ); - if ( !validMaterial( materialId ) || !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - SetMaterialTexture( state->materials[ materialId ], mapType, *texturesGetSourceTexture( texId ) ); + SetMaterialTexture( state->materials[ materialId ], mapType, texture ); lua_pushboolean( L, true ); return 1; @@ -2197,7 +2181,6 @@ int lmodelsDrawModelEx( lua_State *L ) { lua_pushboolean( L, false ); return 1; } - DrawModelEx( *state->models[ modelId ], position, rotationAxis, rotationAngle, scale, tint ); lua_pushboolean( L, true ); @@ -2266,14 +2249,13 @@ int lmodelsSetModelMeshMaterial( lua_State *L ) { return 1; } size_t modelId = lua_tointeger( L, 1 ); - int meshId = lua_tointeger( L, 2 ); - int materialId = lua_tointeger( L, 3 ); + size_t meshId = lua_tointeger( L, 2 ); + size_t materialId = lua_tointeger( L, 3 ); - if ( !validModel( modelId ) ) { + if ( !validModel( modelId ) || !validMesh( meshId ) || !validMaterial( materialId ) ) { lua_pushboolean( L, false ); return 1; } - SetModelMeshMaterial( state->models[ modelId ], meshId, materialId ); lua_pushboolean( L, true ); @@ -2289,23 +2271,23 @@ Draw a billboard texture - Success return true */ int lmodelsDrawBillboard( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) + if ( !lua_isnumber( L, 1 ) || !isValidTexture( L, 2 ) || !lua_istable( L, 3 ) || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawBillboard( Camera camera, Texture2D texture, Vector3 position, float size, Color tint )" ); lua_pushboolean( L, false ); return 1; } size_t cameraId = lua_tointeger( L, 1 ); - size_t texId = lua_tointeger( L, 2 ); + Texture texture = uluaGetTexture( L, 2 ); Vector3 position = uluaGetVector3Index( L, 3 ); float size = lua_tonumber( L, 4 ); Color tint = uluaGetColorIndex( L, 5 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) || !validCamera3D( cameraId ) ) { + if ( !validCamera3D( cameraId ) ) { lua_pushboolean( L, false ); return 1; } - DrawBillboard( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), position, size, tint ); + DrawBillboard( *state->camera3Ds[ cameraId ], texture, position, size, tint ); lua_pushboolean( L, true ); return 1; @@ -2320,25 +2302,25 @@ Draw a billboard texture defined by source - Success return true */ int lmodelsDrawBillboardRec( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) + if ( !lua_isnumber( L, 1 ) || !isValidTexture( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) || !lua_istable( L, 5 ) || !lua_istable( L, 6 ) ) { TraceLog( LOG_WARNING, "%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; } size_t cameraId = lua_tointeger( L, 1 ); - size_t texId = lua_tointeger( L, 2 ); + Texture texture = uluaGetTexture( L, 2 ); Rectangle source = uluaGetRectangleIndex( L, 3 ); Vector3 position = uluaGetVector3Index( L, 4 ); Vector2 size = uluaGetVector2Index( L, 5 ); Color tint = uluaGetColorIndex( L, 6 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) || !validCamera3D( cameraId ) ) { + if ( !validCamera3D( cameraId ) ) { lua_pushboolean( L, false ); return 1; } // DrawBillboardRec( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, size, tint ); - DrawBillboardRecNoRatio( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, size, tint ); + DrawBillboardRecNoRatio( *state->camera3Ds[ cameraId ], texture, source, position, size, tint ); lua_pushboolean( L, true ); return 1; @@ -2353,7 +2335,7 @@ Draw a billboard texture defined by source and rotation - Success return true */ int lmodelsDrawBillboardPro( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) + if ( !lua_isnumber( L, 1 ) || !isValidTexture( L, 2 ) || !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( LOG_WARNING, "%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 )" ); @@ -2361,7 +2343,7 @@ int lmodelsDrawBillboardPro( lua_State *L ) { return 1; } size_t cameraId = lua_tointeger( L, 1 ); - size_t texId = lua_tointeger( L, 2 ); + Texture texture = uluaGetTexture( L, 2 ); Rectangle source = uluaGetRectangleIndex( L, 3 ); Vector3 position = uluaGetVector3Index( L, 4 ); Vector3 up = uluaGetVector3Index( L, 5 ); @@ -2370,12 +2352,12 @@ int lmodelsDrawBillboardPro( lua_State *L ) { float rotation = lua_tonumber( L, 8 ); Color tint = uluaGetColorIndex( L, 9 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) || !validCamera3D( cameraId ) ) { + if ( !validCamera3D( cameraId ) ) { lua_pushboolean( L, false ); return 1; } // DrawBillboardPro( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, up, size, origin, rotation, tint ); - DrawBillboardProNoRatio( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, up, size, origin, rotation, tint ); + DrawBillboardProNoRatio( *state->camera3Ds[ cameraId ], texture, source, position, up, size, origin, rotation, tint ); lua_pushboolean( L, true ); return 1; diff --git a/src/rlgl.c b/src/rlgl.c index afe2e26..f4774a8 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -3,6 +3,61 @@ #include "lua_core.h" #include "lrlgl.h" +/* +## RLGL - Framebuffer state +*/ + +/* +> success = RL.rlEnableFramebuffer( int id ) + +Enable render texture (fbo) + +- Failure return false +- Success return true +*/ +int lrlglEnableFramebuffer( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlEnableFramebuffer( int id )" ); + lua_pushboolean( L, false ); + return 1; + } + rlEnableFramebuffer( lua_tointeger( L, 1 ) ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> RL.rlDisableFramebuffer() + +Disable render texture (fbo), return to default framebuffer +*/ +int lrlglDisableFramebuffer( lua_State *L ) { + rlDisableFramebuffer(); + + return 0; +} + +/* +> success = RL.rlActiveDrawBuffers( int count ) + +Activate multiple draw color buffers + +- Failure return false +- Success return true +*/ +int lrlglActiveDrawBuffers( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlActiveDrawBuffers( int count )" ); + lua_pushboolean( L, false ); + return 1; + } + rlActiveDrawBuffers( lua_tointeger( L, 1 ) ); + lua_pushboolean( L, true ); + + return 1; +} + /* ## RLGL - General render state */ @@ -186,3 +241,167 @@ int lrlglGetVersion( lua_State *L ) { return 1; } + +/* +## RLGL - Textures management +*/ + +/* +> id = RL.rlLoadTexture( Vector2 size, int format, int mipmapCount ) + +Load texture in GPU + +- Failure return -1 +- Success return int +*/ +int lrlglLoadTexture( lua_State *L ) { + if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlLoadTexture( Vector2 size, int format, int mipmapCount )" ); + lua_pushinteger( L, -1 ); + return 1; + } + Vector2 size = uluaGetVector2Index( L, 1 ); + int format = lua_tointeger( L, 2 ); + int mipmapCount = lua_tointeger( L, 3 ); + + lua_pushinteger( L, rlLoadTexture( NULL, size.x, size.y, format, mipmapCount ) ); + + return 1; +} + +/* +> id = RL.rlLoadTextureDepth( Vector2 size, bool useRenderBuffer ) + +Load depth texture/renderbuffer ( to be attached to fbo ) + +- Failure return -1 +- Success return int +*/ +int lrlglLoadTextureDepth( lua_State *L ) { + if ( !lua_istable( L, 1 ) || !lua_isboolean( L, 2 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlLoadTextureDepth( Vector2 size, bool useRenderBuffer )" ); + lua_pushinteger( L, -1 ); + return 1; + } + Vector2 size = uluaGetVector2Index( L, 1 ); + bool useRenderBuffer = lua_toboolean( L, 2 ); + + lua_pushinteger( L, rlLoadTextureDepth( size.x, size.y, useRenderBuffer ) ); + + return 1; +} + +/* +> success = RL.rlUnloadTexture( int id ) + +Unload texture from GPU memory + +- Failure return false +- Success return true +*/ +int lrlglUnloadTexture( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlUnloadTexture( int id )" ); + lua_pushboolean( L, false ); + return 1; + } + rlUnloadTexture( lua_tointeger( L, 1 ) ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +## RLGL - Framebuffer management (fbo) +*/ + +/* +> fboId = RL.rlLoadFramebuffer( Vector2 size ) + +Load an empty framebuffer + +- Failure return -1 +- Success return int +*/ +int lrlglLoadFramebuffer( lua_State *L ) { + if ( !lua_istable( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlLoadFramebuffer( Vector2 size )" ); + lua_pushinteger( L, -1 ); + return 1; + } + Vector2 size = uluaGetVector2Index( L, 1 ); + + lua_pushinteger( L, rlLoadFramebuffer( size.x, size.y ) ); + + return 1; +} + +/* +> success = RL.rlFramebufferAttach( int fboId, int texId, int attachType, int texType, int mipLevel ) + +Attach texture/renderbuffer to a framebuffer + +- Failure return false +- Success return true +*/ +int lrlglFramebufferAttach( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) + || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlFramebufferAttach( int fboId, int texId, int attachType, int texType, int mipLevel )" ); + lua_pushboolean( L, false ); + return 1; + } + unsigned int fboId = lua_tointeger( L, 1 ); + unsigned int texId = lua_tointeger( L, 2 ); + int attachType = lua_tointeger( L, 3 ); + int texType = lua_tointeger( L, 4 ); + int mipLevel = lua_tointeger( L, 5 ); + + rlFramebufferAttach( fboId, texId, attachType, texType, mipLevel ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> isComplete = RL.rlFramebufferComplete( int id ) + +Verify framebuffer is complete + +- Failure return nil +- Success return bool +*/ +int lrlglFramebufferComplete( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlFramebufferComplete( int id )" ); + lua_pushnil( L ); + return 1; + } + unsigned int id = lua_tointeger( L, 1 ); + + lua_pushboolean( L, rlFramebufferComplete( id ) ); + + return 1; +} + +/* +> success = RL.rlUnloadFramebuffer( int id ) + +Delete framebuffer from GPU + +- Failure return nil +- Success return bool +*/ +int lrlglUnloadFramebuffer( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.rlUnloadFramebuffer( int id )" ); + lua_pushboolean( L, false ); + return 1; + } + unsigned int id = lua_tointeger( L, 1 ); + + rlUnloadFramebuffer( id ); + lua_pushboolean( L, true ); + + return 1; +} \ No newline at end of file diff --git a/src/shapes.c b/src/shapes.c index 3a06bac..36ac646 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -18,19 +18,15 @@ defining a font char white rectangle would allow drawing everything in a single - Success return true */ int lshapesSetShapesTexture( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { + if ( !isValidTexture( L, 1 ) || !lua_isnumber( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetShapesTexture( Texture2D texture, Rectangle source )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); Rectangle source = uluaGetRectangleIndex( L, 2 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - SetShapesTexture( *texturesGetSourceTexture( texId ), source ); + SetShapesTexture( texture, source ); lua_pushboolean( L, true ); return 1; diff --git a/src/textures.c b/src/textures.c index 04cd9d5..b8c67ed 100644 --- a/src/textures.c +++ b/src/textures.c @@ -44,19 +44,19 @@ bool validImage( size_t id ) { } } -bool validTexture( size_t id, int type ) { - if ( id < 0 || state->textureCount < id || state->textures[ id ] == NULL ) { - TraceLog( LOG_WARNING, "%s %d", "Invalid texture", id ); - return false; - } - else if ( type != TEXTURE_TYPE_ALL && type != state->textures[ id ]->type ) { - TraceLog( LOG_WARNING, "%s %d", "Wrong texture type", type ); - return false; - } - else { - return true; - } -} +// bool validTexture( size_t id, int type ) { +// if ( id < 0 || state->textureCount < id || state->textures[ id ] == NULL ) { +// TraceLog( LOG_WARNING, "%s %d", "Invalid texture", id ); +// return false; +// } +// else if ( type != TEXTURE_TYPE_ALL && type != state->textures[ id ]->type ) { +// TraceLog( LOG_WARNING, "%s %d", "Wrong texture type", type ); +// return false; +// } +// else { +// return true; +// } +// } static int newImage() { int i = 0; @@ -154,19 +154,15 @@ Load image from GPU texture data - Success return int */ int ltexturesLoadImageFromTexture( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { + if ( !isValidTexture( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.LoadImageFromTexture( Texture2D texture )" ); lua_pushinteger( L, -1 ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushinteger( L, -1 ); - return 1; - } int i = newImage(); - *state->images[i] = LoadImageFromTexture( *texturesGetSourceTexture( texId ) ); + *state->images[i] = LoadImageFromTexture( texture ); lua_pushinteger( L, i ); return 1; @@ -1730,7 +1726,7 @@ int ltexturesLoadRenderTexture( lua_State *L ) { /* > success = RL.UnloadTexture( Texture2D texture ) -Unload texture from GPU memory ( VRAM ) +Unload texture from GPU memory ( VRAM ). NOTE! Must be texture id. - Failure return false - Success return true @@ -1743,10 +1739,6 @@ int ltexturesUnloadTexture( lua_State *L ) { } size_t texId = lua_tointeger( L, 1 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } texturesFreeTexture( texId ); lua_pushboolean( L, true ); @@ -1762,18 +1754,14 @@ Check if a texture is ready - Success return true */ int ltexturesIsTextureReady( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { + if ( !isValidTexture( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.IsTextureReady( Texture2D texture )" ); lua_pushnil( L ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); - if ( !validTexture( texId, TEXTURE_TYPE_TEXTURE ) ) { - lua_pushnil( L ); - return 1; - } - lua_pushboolean( L, IsTextureReady( state->textures[ texId ]->texture) ); + lua_pushboolean( L, IsTextureReady( texture ) ); return 1; } @@ -1788,17 +1776,13 @@ NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 25 - Success return true */ int ltexturesUpdateTexture( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { + if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.UpdateTexture( Texture2D texture, int{} pixels )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); - if ( !validTexture( texId, TEXTURE_TYPE_TEXTURE ) ) { - lua_pushboolean( L, false ); - return 1; - } size_t len = uluaGetTableLenIndex( L, 2 ); unsigned char *pixels = malloc( len * 4 * sizeof( unsigned char ) ); @@ -1822,8 +1806,7 @@ int ltexturesUpdateTexture( lua_State *L ) { i++; lua_pop( L, 1 ); } - // UpdateTexture( *state->textures[ texId ], pixels ); - UpdateTexture( state->textures[ texId ]->texture, pixels ); + UpdateTexture( texture, pixels ); lua_pushboolean( L, true ); free( pixels ); @@ -1841,17 +1824,13 @@ NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 25 - Success return true */ int ltexturesUpdateTextureRec( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) { + if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.UpdateTextureRec( Texture2D texture, Rectangle rec, int{} pixels )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); - if ( !validTexture( texId, TEXTURE_TYPE_TEXTURE ) ) { - lua_pushboolean( L, false ); - return 1; - } size_t len = uluaGetTableLenIndex( L, 3 ); unsigned char *pixels = malloc( len * 4 * sizeof( unsigned char ) ); @@ -1879,7 +1858,7 @@ int ltexturesUpdateTextureRec( lua_State *L ) { Rectangle rec = uluaGetRectangleIndex( L, 2 ); - UpdateTextureRec( state->textures[ texId ]->texture, rec, pixels ); + UpdateTextureRec( texture, rec, pixels ); lua_pushboolean( L, true ); free( pixels ); @@ -1900,21 +1879,16 @@ Draw a Texture2D - Success return true */ int ltexturesDrawTexture( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) { + if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawTexture( Texture2D texture, Vector2 position, Color tint )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); Vector2 pos = uluaGetVector2Index( L, 2 ); Color color = uluaGetColorIndex( L, 3 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - - DrawTexture( *texturesGetSourceTexture( texId ), pos.x, pos.y, color ); + DrawTexture( texture, pos.x, pos.y, color ); lua_pushboolean( L, true ); return 1; @@ -1929,22 +1903,17 @@ Draw a part of a texture defined by a rectangle - Success return true */ int ltexturesDrawTextureRec( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) { + if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawTextureRec( Texture2D texture, Rectangle source, Vector2 position, Color tint )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); Rectangle srcRect = uluaGetRectangleIndex( L, 2 ); Vector2 pos = uluaGetVector2Index( L, 3 ); Color tint = uluaGetColorIndex( L, 4 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - - DrawTextureRec( *texturesGetSourceTexture( texId ), srcRect, pos, tint ); + DrawTextureRec( texture, srcRect, pos, tint ); lua_pushboolean( L, true ); return 1; @@ -1959,25 +1928,20 @@ Draw a part of a texture defined by a rectangle with "pro" parameters - Success return true */ int ltexturesDrawTexturePro( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) + if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawTexturePro( Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); Rectangle srcRect = uluaGetRectangleIndex( L, 2 ); Rectangle dstRect = uluaGetRectangleIndex( L, 3 ); Vector2 origin = uluaGetVector2Index( L, 4 ); float rot = lua_tonumber( L, 5 ); Color color = uluaGetColorIndex( L, 6 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - - DrawTexturePro( *texturesGetSourceTexture( texId ), srcRect, dstRect, origin, rot, color ); + DrawTexturePro( texture, srcRect, dstRect, origin, rot, color ); lua_pushboolean( L, true ); return 1; @@ -1992,24 +1956,20 @@ Draws a texture ( or part of it ) that stretches or shrinks nicely - Success return true */ int ltexturesDrawTextureNPatch( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) + if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawTextureNPatch( Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); NPatchInfo nPatchInfo = uluaGetNPatchInfoIndex( L, 2 ); Rectangle dest = uluaGetRectangleIndex( L, 3 ); Vector2 origin = uluaGetVector2Index( L, 4 ); float rotation = lua_tonumber( L, 5 ); Color tint = uluaGetColorIndex( L, 6 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - DrawTextureNPatch( *texturesGetSourceTexture( texId ), nPatchInfo, dest, origin, rotation, tint ); + DrawTextureNPatch( texture, nPatchInfo, dest, origin, rotation, tint ); lua_pushboolean( L, true ); return 1; @@ -2024,19 +1984,14 @@ Begin drawing to render texture - Success return true */ int ltexturesBeginTextureMode( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { + if ( !isValidRenderTexture( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.BeginTextureMode( RenderTexture2D target )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); - - if ( !validTexture( texId, TEXTURE_TYPE_RENDER_TEXTURE ) ) { - lua_pushboolean( L, false ); - return 1; - } + RenderTexture renderTexture = uluaGetRenderTexture( L, 1 ); - BeginTextureMode( state->textures[ texId ]->renderTexture ); + BeginTextureMode( renderTexture ); lua_pushboolean( L, true ); return 1; @@ -2069,10 +2024,6 @@ int ltexturesGetTextureType( lua_State *L ) { } size_t texId = lua_tointeger( L, 1 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } lua_pushinteger( L, state->textures[ texId ]->type ); return 1; @@ -2091,18 +2042,14 @@ Generate GPU mipmaps for a texture - Success return true */ int ltexturesGenTextureMipmaps( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { + if ( !isValidTexture( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GenTextureMipmaps( Texture2D texture )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - GenTextureMipmaps( texturesGetSourceTexture( texId ) ); + GenTextureMipmaps( &texture ); lua_pushboolean( L, true ); return 1; @@ -2117,20 +2064,15 @@ Set texture scaling filter mode ( TEXTURE_FILTER_POINT, TEXTURE_FILTER_BILINEAR. - Success return true */ int ltexturesSetTextureFilter( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { + if ( !isValidTexture( L, 1 ) || !lua_isnumber( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetTextureFilter( Texture2D texture, int filter )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); int filter = lua_tointeger( L, 2 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - - SetTextureFilter( *texturesGetSourceTexture( texId ), filter ); + SetTextureFilter( texture, filter ); lua_pushboolean( L, true ); return 1; @@ -2145,21 +2087,36 @@ Set texture wrapping mode ( TEXTURE_WRAP_REPEAT, TEXTURE_WRAP_CLAMP... ) - Success return true */ int ltexturesSetTextureWrap( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { + if ( !isValidTexture( L, 1 ) || !lua_isnumber( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetTextureWrap( Texture2D texture, int wrap )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); int wrap = lua_tointeger( L, 2 ); - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { + SetTextureWrap( texture, wrap ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> id = RL.GetTextureId( Texture2D texture ) + +Get texture OpenGL id + +- Failure return false +- Success return int +*/ +int ltexturesGetTextureId( lua_State *L ) { + if ( !isValidTexture( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetTextureId( Texture2D texture )" ); lua_pushboolean( L, false ); return 1; } - - SetTextureWrap( *texturesGetSourceTexture( texId ), wrap ); - lua_pushboolean( L, true ); + Texture texture = uluaGetTexture( L, 1 ); + lua_pushinteger( L, texture.id ); return 1; } @@ -2169,22 +2126,16 @@ int ltexturesSetTextureWrap( lua_State *L ) { Get texture size -- Failure return nil +- Failure return false - Success return Vector2 */ int ltexturesGetTextureSize( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { + if ( !isValidTexture( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetTextureSize( Texture2D texture )" ); - lua_pushnil( L ); - return 1; - } - size_t texId = lua_tointeger( L, 1 ); - - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushnil( L ); + lua_pushboolean( L, false ); return 1; } - Texture2D texture = *texturesGetSourceTexture( texId ); + Texture texture = uluaGetTexture( L, 1 ); uluaPushVector2( L, (Vector2){ texture.width, texture.height } ); return 1; @@ -2199,18 +2150,12 @@ Get texture mipmaps. Mipmap levels, 1 by default - Success return int */ int ltexturesGetTextureMipmaps( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { + if ( !isValidTexture( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetTextureMipmaps( Texture2D texture )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); - - if ( !validImage( texId ) ) { - lua_pushboolean( L, false ); - return 1; - } - Texture2D texture = *texturesGetSourceTexture( texId ); + Texture texture = uluaGetTexture( L, 1 ); lua_pushinteger( L, texture.mipmaps ); return 1; @@ -2225,18 +2170,12 @@ Get texture mipmaps. Mipmap levels, 1 by default - Success return int */ int ltexturesGetTextureFormat( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { + if ( !isValidTexture( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetTextureFormat( Texture2D texture )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); - - if ( !validImage( texId ) ) { - lua_pushboolean( L, false ); - return 1; - } - Texture2D texture = *texturesGetSourceTexture( texId ); + Texture texture = uluaGetTexture( L, 1 ); lua_pushinteger( L, texture.format ); return 1; @@ -2516,20 +2455,14 @@ Get pixel color from source texture - Success return Color */ int ltexturesGetPixelColor( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { + if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetPixelColor( Texture2D texture, Vector2 position )" ); lua_pushboolean( L, false ); return 1; } - size_t texId = lua_tointeger( L, 1 ); + Texture texture = uluaGetTexture( L, 1 ); Vector2 pos = uluaGetVector2Index( L, 2 ); - - if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) { - lua_pushboolean( L, false ); - return 1; - } - Texture2D *texture = texturesGetSourceTexture( texId ); - Image srcImage = LoadImageFromTexture( *texture ); + Image srcImage = LoadImageFromTexture( texture ); uluaPushColor( L, GetImageColor( srcImage, pos.x, pos.y ) ); UnloadImage( srcImage ); -- cgit v1.2.3