summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjussi2023-05-01 18:23:36 +0300
committerjussi2023-05-01 18:23:36 +0300
commitacc56fc7c2bedde6eced005eab0a37b6281b9a23 (patch)
tree6298f7eeee27469f20d6d992c93118aa162b49a8 /src
parent8b6337446dd79faf226ea9df40d4d06d81c38436 (diff)
downloadreilua-enhanced-acc56fc7c2bedde6eced005eab0a37b6281b9a23.tar.gz
reilua-enhanced-acc56fc7c2bedde6eced005eab0a37b6281b9a23.tar.bz2
reilua-enhanced-acc56fc7c2bedde6eced005eab0a37b6281b9a23.zip
Texture now can be either Texture or RenderTexture. No need to change texture source anymore.
Diffstat (limited to 'src')
-rw-r--r--src/core.c5
-rw-r--r--src/gl.c8
-rw-r--r--src/lua_core.c8
-rw-r--r--src/models.c11
-rw-r--r--src/shapes.c2
-rw-r--r--src/state.c17
-rw-r--r--src/textures.c206
7 files changed, 88 insertions, 169 deletions
diff --git a/src/core.c b/src/core.c
index c04fb93..a0ea6ce 100644
--- a/src/core.c
+++ b/src/core.c
@@ -1247,11 +1247,12 @@ int lcoreSetShaderValueTexture( lua_State *L ) {
int locIndex = lua_tointeger( L, 2 );
size_t textureId = lua_tointeger( L, 3 );
- if ( !validShader( shaderId ) || !validTexture( textureId ) ) {
+ if ( !validShader( shaderId ) || !validTexture( textureId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
- SetShaderValueTexture( *state->shaders[ shaderId ], locIndex, *state->textures[ textureId ] );
+ // SetShaderValueTexture( *state->shaders[ shaderId ], locIndex, *state->textures[ textureId ] );
+ SetShaderValueTexture( *state->shaders[ shaderId ], locIndex, *texturesGetSourceTexture( textureId ) );
lua_pushboolean( L, true );
return 1;
diff --git a/src/gl.c b/src/gl.c
index a6777a9..6bd8a03 100644
--- a/src/gl.c
+++ b/src/gl.c
@@ -31,7 +31,9 @@ int lglBlitFramebuffer( lua_State *L ) {
int mask = lua_tointeger( L, 5 );
int filter = lua_tointeger( L, 6 );
- if ( ( !validRenderTexture( srcTexId ) && srcTexId != -1 ) && ( !validRenderTexture( dstTexId ) && dstTexId != -1 ) ) {
+ // 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;
}
@@ -40,14 +42,14 @@ int lglBlitFramebuffer( lua_State *L ) {
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
}
else {
- glBindFramebuffer( GL_READ_FRAMEBUFFER, state->renderTextures[ srcTexId ]->id );
+ glBindFramebuffer( GL_READ_FRAMEBUFFER, state->textures[ srcTexId ]->renderTexture.id );
}
if ( dstTexId == -1 ) {
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
}
else {
- glBindFramebuffer( GL_DRAW_FRAMEBUFFER, state->renderTextures[ dstTexId ]->id );
+ glBindFramebuffer( GL_DRAW_FRAMEBUFFER, state->textures[ dstTexId ]->renderTexture.id );
}
glBlitFramebuffer(
diff --git a/src/lua_core.c b/src/lua_core.c
index 8aeeafe..020f3e5 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -369,8 +369,8 @@ void defineGlobals() {
assignGlobalInt( NPATCH_THREE_PATCH_VERTICAL, "NPATCH_THREE_PATCH_VERTICAL" );
assignGlobalInt( NPATCH_THREE_PATCH_HORIZONTAL, "NPATCH_THREE_PATCH_HORIZONTAL" );
/* TextureModes */
- assignGlobalInt( TEXTURE_SOURCE_TEXTURE, "TEXTURE_SOURCE_TEXTURE" );
- assignGlobalInt( TEXTURE_SOURCE_RENDER_TEXTURE, "TEXTURE_SOURCE_RENDER_TEXTURE" );
+ assignGlobalInt( TEXTURE_TYPE_TEXTURE, "TEXTURE_TYPE_TEXTURE" );
+ assignGlobalInt( TEXTURE_TYPE_RENDER_TEXTURE, "TEXTURE_TYPE_RENDER_TEXTURE" );
/* Colors */
assignGlobalColor( LIGHTGRAY, "LIGHTGRAY" );
assignGlobalColor( GRAY, "GRAY" );
@@ -1000,7 +1000,6 @@ void luaRegister() {
assingGlobalFunction( "LoadTextureCubemap", ltexturesLoadTextureCubemap );
assingGlobalFunction( "LoadRenderTexture", ltexturesLoadRenderTexture );
assingGlobalFunction( "UnloadTexture", ltexturesUnloadTexture );
- assingGlobalFunction( "UnloadRenderTexture", ltexturesUnloadRenderTexture );
assingGlobalFunction( "UpdateTexture", ltexturesUpdateTexture );
assingGlobalFunction( "UpdateTextureRec", ltexturesUpdateTextureRec );
/* Texture Drawing. */
@@ -1010,8 +1009,7 @@ void luaRegister() {
assingGlobalFunction( "DrawTextureNPatch", ltexturesDrawTextureNPatch );
assingGlobalFunction( "BeginTextureMode", ltexturesBeginTextureMode );
assingGlobalFunction( "EndTextureMode", ltexturesEndTextureMode );
- assingGlobalFunction( "SetTextureSource", ltexturesSetTextureSource );
- assingGlobalFunction( "GetTextureSource", ltexturesGetTextureSource );
+ assingGlobalFunction( "GetTextureType", ltexturesGetTextureType );
/* Texture Configuration. */
assingGlobalFunction( "GenTextureMipmaps", ltexturesGenTextureMipmaps );
assingGlobalFunction( "SetTextureFilter", ltexturesSetTextureFilter );
diff --git a/src/models.c b/src/models.c
index 6b0ff0a..3f69001 100644
--- a/src/models.c
+++ b/src/models.c
@@ -665,7 +665,7 @@ int lmodelDrawQuad3DTexture( lua_State *L ) {
//TODO Normals. maybe something like Vector3Normalize(Vector3CrossProduct(Vector3Subtract(vB, vA), Vector3Subtract(vC, vA)));
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -1138,7 +1138,6 @@ int lmodelsGenMeshCustom( lua_State *L ) {
}
lua_pop( L, 1 );
}
-
bool dynamic = lua_toboolean( L, 2 );
UploadMesh( &mesh, dynamic );
@@ -1575,7 +1574,7 @@ int lmodelsCreateMaterial( lua_State *L ) {
if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) {
size_t texId = lua_tointeger( L, -1 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -1669,7 +1668,7 @@ int lmodelsSetMaterialTexture( lua_State *L ) {
int mapType = lua_tointeger( L, 2 );
size_t texId = lua_tointeger( L, 3 );
- if ( !validMaterial( materialId ) || !validSourceTexture( texId ) ) {
+ if ( !validMaterial( materialId ) || !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -2014,7 +2013,7 @@ int lmodelsDrawBillboard( lua_State *L ) {
float size = lua_tonumber( L, 4 );
Color tint = uluaGetColorIndex( L, 5 );
- if ( !validSourceTexture( texId ) || !validCamera3D( cameraId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) || !validCamera3D( cameraId ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -2046,7 +2045,7 @@ int lmodelsDrawBillboardRec( lua_State *L ) {
Vector2 size = uluaGetVector2Index( L, 5 );
Color tint = uluaGetColorIndex( L, 6 );
- if ( !validSourceTexture( texId ) || !validCamera3D( cameraId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) || !validCamera3D( cameraId ) ) {
lua_pushboolean( L, false );
return 1;
}
diff --git a/src/shapes.c b/src/shapes.c
index ef857ea..3a06bac 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -26,7 +26,7 @@ int lshapesSetShapesTexture( lua_State *L ) {
size_t texId = lua_tointeger( L, 1 );
Rectangle source = uluaGetRectangleIndex( L, 2 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
diff --git a/src/state.c b/src/state.c
index ed96115..6db0812 100644
--- a/src/state.c
+++ b/src/state.c
@@ -16,7 +16,6 @@ bool stateInit( const char *exePath ) {
state->run = true;
state->resolution = (Vector2){ 800, 600 };
state->luaState = NULL;
- state->textureSource = TEXTURE_SOURCE_TEXTURE;
state->guiFont = 0;
/* Images. */
state->imageAlloc = ALLOC_PAGE_SIZE;
@@ -25,11 +24,7 @@ bool stateInit( const char *exePath ) {
/* Textures. */
state->textureAlloc = ALLOC_PAGE_SIZE;
state->textureCount = 0;
- state->textures = malloc( state->textureAlloc * sizeof( Texture2D* ) );
- /* RenderTextures. */
- state->renderTextureAlloc = ALLOC_PAGE_SIZE;
- state->renderTextureCount = 0;
- state->renderTextures = malloc( state->renderTextureAlloc * sizeof( RenderTexture2D* ) );
+ state->textures = malloc( state->textureAlloc * sizeof( ReiTexture* ) );
/* Fonts. */
state->fontAlloc = ALLOC_PAGE_SIZE;
state->fontCount = 1;
@@ -82,7 +77,6 @@ bool stateInit( const char *exePath ) {
for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) {
state->images[i] = NULL;
state->textures[i] = NULL;
- state->renderTextures[i] = NULL;
state->waves[i] = NULL;
state->sounds[i] = NULL;
state->camera2Ds[i] = NULL;
@@ -133,16 +127,10 @@ void stateFree() {
}
for ( int i = 0; i < state->textureCount; ++i ) {
if ( state->textures[i] != NULL ) {
- UnloadTexture( *state->textures[i] );
+ texturesFreeTexture(i);
free( state->textures[i] );
}
}
- for ( int i = 0; i < state->renderTextureCount; ++i ) {
- if ( state->renderTextures[i] != NULL ) {
- UnloadRenderTexture( *state->renderTextures[i] );
- free( state->renderTextures[i] );
- }
- }
for ( int i = 0; i < state->fontCount; ++i ) {
if ( state->fonts[i] != NULL ) {
UnloadFont( *state->fonts[i] );
@@ -232,7 +220,6 @@ void stateFree() {
}
free( state->images );
free( state->textures );
- free( state->renderTextures );
free( state->fonts );
free( state->waves );
free( state->sounds );
diff --git a/src/textures.c b/src/textures.c
index b96bb5b..4def06e 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -26,7 +26,7 @@ static void checkTextureRealloc( int i ) {
if ( state->textureCount == state->textureAlloc ) {
state->textureAlloc += ALLOC_PAGE_SIZE;
- state->textures = realloc( state->textures, state->textureAlloc * sizeof( Texture2D* ) );
+ state->textures = realloc( state->textures, state->textureAlloc * sizeof( ReiTexture* ) );
for ( i = state->textureCount; i < state->textureAlloc; i++ ) {
state->textures[i] = NULL;
@@ -34,21 +34,6 @@ static void checkTextureRealloc( int i ) {
}
}
-static void checkRenderTextureRealloc( int i ) {
- if ( i == state->renderTextureCount ) {
- state->renderTextureCount++;
- }
-
- if ( state->renderTextureCount == state->renderTextureAlloc ) {
- state->renderTextureAlloc += ALLOC_PAGE_SIZE;
- state->renderTextures = realloc( state->renderTextures, state->renderTextureAlloc * sizeof( RenderTexture2D* ) );
-
- for ( i = state->renderTextureCount; i < state->renderTextureAlloc; i++ ) {
- state->renderTextures[i] = NULL;
- }
- }
-}
-
bool validImage( size_t id ) {
if ( id < 0 || state->imageCount < id || state->images[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid image", id );
@@ -59,19 +44,13 @@ bool validImage( size_t id ) {
}
}
-bool validTexture( 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 {
- return true;
- }
-}
-
-bool validRenderTexture( size_t id ) {
- if ( id < 0 || state->renderTextureCount < id || state->renderTextures[ id ] == NULL ) {
- TraceLog( LOG_WARNING, "%s %d", "Invalid renderTexture", id );
+ else if ( type != TEXTURE_TYPE_ALL && type != state->textures[ id ]->type ) {
+ TraceLog( LOG_WARNING, "%s %d", "Wrong texture type", type );
return false;
}
else {
@@ -79,18 +58,6 @@ bool validRenderTexture( size_t id ) {
}
}
-bool validSourceTexture( size_t id ) {
- switch ( state->textureSource ) {
- case TEXTURE_SOURCE_TEXTURE:
- return validTexture( id );
- case TEXTURE_SOURCE_RENDER_TEXTURE:
- return validRenderTexture( id );
- default:
- return validTexture( id );
- break;
- }
-}
-
static int newImage() {
int i = 0;
@@ -105,7 +72,7 @@ static int newImage() {
return i;
}
-static int newTexture() {
+static int newTexture( int type ) {
int i = 0;
for ( i = 0; i < state->textureCount; i++ ) {
@@ -113,24 +80,39 @@ static int newTexture() {
break;
}
}
- state->textures[i] = malloc( sizeof( Texture2D ) );
+ state->textures[i] = malloc( sizeof( ReiTexture ) );
+ state->textures[i]->type = type;
+
checkTextureRealloc( i );
return i;
}
-Texture2D* texturesGetSourceTexture( size_t index ) {
- switch ( state->textureSource ) {
- case TEXTURE_SOURCE_TEXTURE:
- return state->textures[ index ];
- case TEXTURE_SOURCE_RENDER_TEXTURE:
- return &state->renderTextures[ index ]->texture;
- default:
- return state->textures[ index ];
- break;
+Texture2D* texturesGetSourceTexture( size_t id ) {
+ if ( state->textures[id] != NULL ) {
+ switch ( state->textures[id]->type ) {
+ case TEXTURE_TYPE_TEXTURE:
+ return &state->textures[id]->texture;
+ break;
+ case TEXTURE_TYPE_RENDER_TEXTURE:
+ return &state->textures[id]->renderTexture.texture;
+ break;
+ }
}
}
+void texturesFreeTexture( size_t id ) {
+ if ( state->textures[id] != NULL ) {
+ switch ( state->textures[id]->type ) {
+ case TEXTURE_TYPE_TEXTURE:
+ UnloadTexture( state->textures[id]->texture );
+ break;
+ case TEXTURE_TYPE_RENDER_TEXTURE:
+ UnloadRenderTexture( state->textures[id]->renderTexture );
+ break;
+ }
+ }
+}
/*
## Textures - Image Loading
*/
@@ -178,7 +160,7 @@ int ltexturesLoadImageFromTexture( lua_State *L ) {
}
size_t texId = lua_tointeger( L, 1 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushinteger( L, -1 );
return 1;
}
@@ -1654,10 +1636,9 @@ int ltexturesLoadTexture( lua_State *L ) {
lua_pushinteger( L, -1 );
return 1;
}
-
if ( FileExists( lua_tostring( L, 1 ) ) ) {
- int i = newTexture();
- *state->textures[i] = LoadTexture( lua_tostring( L, 1 ) );
+ int i = newTexture( TEXTURE_TYPE_TEXTURE );
+ state->textures[i]->texture = LoadTexture( lua_tostring( L, 1 ) );
lua_pushinteger( L, i );
return 1;
}
@@ -1687,8 +1668,8 @@ int ltexturesLoadTextureFromImage( lua_State *L ) {
lua_pushboolean( L, false );
return 1;
}
- int i = newTexture();
- *state->textures[i] = LoadTextureFromImage( *state->images[ imageId ] );
+ int i = newTexture( TEXTURE_TYPE_TEXTURE );
+ state->textures[i]->texture = LoadTextureFromImage( *state->images[ imageId ] );
lua_pushinteger( L, i );
return 1;
@@ -1715,8 +1696,8 @@ int ltexturesLoadTextureCubemap( lua_State *L ) {
lua_pushboolean( L, false );
return 1;
}
- int i = newTexture();
- *state->textures[i] = LoadTextureCubemap( *state->images[ imageId ], layout );
+ int i = newTexture( TEXTURE_TYPE_TEXTURE );
+ state->textures[i]->texture = LoadTextureCubemap( *state->images[ imageId ], layout );
lua_pushinteger( L, i );
return 1;
@@ -1737,17 +1718,10 @@ int ltexturesLoadRenderTexture( lua_State *L ) {
return 1;
}
Vector2 size = uluaGetVector2Index( L, 1 );
- int i = 0;
- for ( i = 0; i < state->renderTextureCount; i++ ) {
- if ( state->renderTextures[i] == NULL ) {
- break;
- }
- }
- state->renderTextures[i] = malloc( sizeof( RenderTexture2D ) );
- *state->renderTextures[i] = LoadRenderTexture( (int)size.x, (int)size.y );
+ int i = newTexture( TEXTURE_TYPE_RENDER_TEXTURE );
+ state->textures[i]->renderTexture = LoadRenderTexture( (int)size.x, (int)size.y );
lua_pushinteger( L, i );
- checkRenderTextureRealloc( i );
return 1;
}
@@ -1768,39 +1742,13 @@ int ltexturesUnloadTexture( lua_State *L ) {
}
size_t id = lua_tointeger( L, 1 );
- if ( !validTexture( id ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- UnloadTexture( *state->textures[ id ] );
- state->textures[ id ] = NULL;
- lua_pushboolean( L, true );
-
- return 1;
-}
-
-/*
-> success = RL.UnloadRenderTexture( RenderTexture2D target )
-
-Unload render texture from GPU memory ( VRAM )
-
-- Failure return false
-- Success return true
-*/
-int ltexturesUnloadRenderTexture( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.UnloadRenderTexture( RenderTexture2D target )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t id = lua_tointeger( L, 1 );
-
- if ( !validRenderTexture( id ) ) {
+ if ( !validTexture( id, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
- UnloadRenderTexture( *state->renderTextures[ id ] );
- state->renderTextures[ id ] = NULL;
+ // UnloadTexture( *state->textures[ id ] );
+ texturesFreeTexture( id );
+ // state->textures[ id ] = NULL;
lua_pushboolean( L, true );
return 1;
@@ -1810,7 +1758,7 @@ int ltexturesUnloadRenderTexture( lua_State *L ) {
> success = RL.UpdateTexture( Texture2D texture, int{} pixels )
Update GPU texture with new data
-NOTE! Should be TEXTURE_SOURCE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
+NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
- Failure return false
- Success return true
@@ -1823,7 +1771,7 @@ int ltexturesUpdateTexture( lua_State *L ) {
}
size_t texId = lua_tointeger( L, 1 );
- if ( !validTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_TEXTURE ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -1850,7 +1798,8 @@ int ltexturesUpdateTexture( lua_State *L ) {
i++;
lua_pop( L, 1 );
}
- UpdateTexture( *state->textures[ texId ], pixels );
+ // UpdateTexture( *state->textures[ texId ], pixels );
+ UpdateTexture( state->textures[ texId ]->texture, pixels );
lua_pushboolean( L, true );
free( pixels );
@@ -1862,7 +1811,7 @@ int ltexturesUpdateTexture( lua_State *L ) {
> success = RL.UpdateTextureRec( Texture2D texture, Rectangle rec, int{} pixels )
Update GPU texture rectangle with new data
-NOTE! Should be TEXTURE_SOURCE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
+NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
- Failure return false
- Success return true
@@ -1875,7 +1824,7 @@ int ltexturesUpdateTextureRec( lua_State *L ) {
}
size_t texId = lua_tointeger( L, 1 );
- if ( !validTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_TEXTURE ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -1906,7 +1855,7 @@ int ltexturesUpdateTextureRec( lua_State *L ) {
Rectangle rec = uluaGetRectangleIndex( L, 2 );
- UpdateTextureRec( *state->textures[ texId ], rec, pixels );
+ UpdateTextureRec( state->textures[ texId ]->texture, rec, pixels );
lua_pushboolean( L, true );
free( pixels );
@@ -1936,7 +1885,7 @@ int ltexturesDrawTexture( lua_State *L ) {
Vector2 pos = uluaGetVector2Index( L, 2 );
Color color = uluaGetColorIndex( L, 3 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -1966,7 +1915,7 @@ int ltexturesDrawTextureRec( lua_State *L ) {
Vector2 pos = uluaGetVector2Index( L, 3 );
Color tint = uluaGetColorIndex( L, 4 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -1999,7 +1948,7 @@ int ltexturesDrawTexturePro( lua_State *L ) {
float rot = lua_tonumber( L, 5 );
Color color = uluaGetColorIndex( L, 6 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -2032,7 +1981,7 @@ int ltexturesDrawTextureNPatch( lua_State *L ) {
float rotation = lua_tonumber( L, 5 );
Color tint = uluaGetColorIndex( L, 6 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -2058,12 +2007,12 @@ int ltexturesBeginTextureMode( lua_State *L ) {
}
size_t texId = lua_tointeger( L, 1 );
- if ( !validRenderTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_RENDER_TEXTURE ) ) {
lua_pushboolean( L, false );
return 1;
}
- BeginTextureMode( *state->renderTextures[ texId ] );
+ BeginTextureMode( state->textures[ texId ]->renderTexture );
lua_pushboolean( L, true );
return 1;
@@ -2081,42 +2030,26 @@ int ltexturesEndTextureMode( lua_State *L ) {
}
/*
-> success = RL.SetTextureSource( int textureSource )
+> type = RL.GetTextureType( Texture2D texture )
-Set what texture source to use ( TEXTURE_SOURCE_TEXTURE or TEXTURE_SOURCE_RENDER_TEXTURE )
+Get texture type ( TEXTURE_TYPE_TEXTURE or TEXTURE_TYPE_RENDER_TEXTURE )
- Failure return false
-- Success return true
+- Success return int
*/
-int ltexturesSetTextureSource( lua_State *L ) {
+int ltexturesGetTextureType( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetTextureSource( int textureSource )" );
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetTextureType( Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
}
- int texSource = lua_tointeger( L, 1 );
+ size_t texId = lua_tointeger( L, 1 );
- if ( texSource != TEXTURE_SOURCE_TEXTURE && texSource != TEXTURE_SOURCE_RENDER_TEXTURE ) {
- TraceLog( LOG_WARNING, "%s %d", "Invalid source texture", texSource );
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
-
- state->textureSource = texSource;
- lua_pushboolean( L, true );
-
- return 1;
-}
-
-/*
-> textureSource = RL.GetTextureSource()
-
-Get current texture source type ( TEXTURE_SOURCE_TEXTURE or TEXTURE_SOURCE_RENDER_TEXTURE )
-
-- Success return int
-*/
-int ltexturesGetTextureSource( lua_State *L ) {
- lua_pushinteger( L, state->textureSource );
+ lua_pushinteger( L, state->textures[ texId ]->type );
return 1;
}
@@ -2141,11 +2074,10 @@ int ltexturesGenTextureMipmaps( lua_State *L ) {
}
size_t texId = lua_tointeger( L, 1 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
-
GenTextureMipmaps( texturesGetSourceTexture( texId ) );
lua_pushboolean( L, true );
@@ -2169,7 +2101,7 @@ int ltexturesSetTextureFilter( lua_State *L ) {
size_t texId = lua_tointeger( L, 1 );
int filter = lua_tointeger( L, 2 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -2197,7 +2129,7 @@ int ltexturesSetTextureWrap( lua_State *L ) {
size_t texId = lua_tointeger( L, 1 );
int wrap = lua_tointeger( L, 2 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -2224,7 +2156,7 @@ int ltexturesGetTextureSize( lua_State *L ) {
}
size_t texId = lua_tointeger( L, 1 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushnil( L );
return 1;
}
@@ -2568,7 +2500,7 @@ int ltexturesGetPixelColor( lua_State *L ) {
size_t texId = lua_tointeger( L, 1 );
Vector2 pos = uluaGetVector2Index( L, 2 );
- if ( !validSourceTexture( texId ) ) {
+ if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false );
return 1;
}