Texture now can be either Texture or RenderTexture. No need to change texture source anymore.

This commit is contained in:
jussi
2023-05-01 18:23:36 +03:00
parent 8b6337446d
commit acc56fc7c2
18 changed files with 160 additions and 251 deletions

29
API.md
View File

@@ -675,9 +675,9 @@ NPATCH_THREE_PATCH_HORIZONTAL
## Globals - TextureModes ## Globals - TextureModes
TEXTURE_SOURCE_TEXTURE TEXTURE_TYPE_TEXTURE
TEXTURE_SOURCE_RENDER_TEXTURE TEXTURE_TYPE_RENDER_TEXTURE
## Globals - Colors ## Globals - Colors
@@ -3560,19 +3560,10 @@ Unload texture from GPU memory ( VRAM )
--- ---
> success = RL.UnloadRenderTexture( RenderTexture2D target )
Unload render texture from GPU memory ( VRAM )
- Failure return false
- Success return true
---
> success = RL.UpdateTexture( Texture2D texture, int{} pixels ) > success = RL.UpdateTexture( Texture2D texture, int{} pixels )
Update GPU texture with new data 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 - Failure return false
- Success return true - Success return true
@@ -3582,7 +3573,7 @@ NOTE! Should be TEXTURE_SOURCE_TEXTURE. Pixel should be in format { { 255, 255,
> success = RL.UpdateTextureRec( Texture2D texture, Rectangle rec, int{} pixels ) > success = RL.UpdateTextureRec( Texture2D texture, Rectangle rec, int{} pixels )
Update GPU texture rectangle with new data 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 - Failure return false
- Success return true - Success return true
@@ -3644,19 +3635,11 @@ Ends drawing to render texture
--- ---
> 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 - Failure return false
- Success return true
---
> textureSource = RL.GetTextureSource()
Get current texture source type ( TEXTURE_SOURCE_TEXTURE or TEXTURE_SOURCE_RENDER_TEXTURE )
- Success return int - Success return int
--- ---

View File

@@ -381,8 +381,8 @@ RL.NPATCH_THREE_PATCH_HORIZONTAL=2
-- Globals - TextureModes -- Globals - TextureModes
RL.TEXTURE_SOURCE_TEXTURE=0 RL.TEXTURE_TYPE_TEXTURE=0
RL.TEXTURE_SOURCE_RENDER_TEXTURE=1 RL.TEXTURE_TYPE_RENDER_TEXTURE=1
-- Globals - Colors -- Globals - Colors
@@ -2639,15 +2639,8 @@ function RL.LoadRenderTexture( size ) end
---@return any success ---@return any success
function RL.UnloadTexture( texture ) end function RL.UnloadTexture( texture ) end
---Unload render texture from GPU memory ( VRAM )
---- Failure return false
---- Success return true
---@param target any
---@return any success
function RL.UnloadRenderTexture( target ) end
---Update GPU texture with new data ---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 ---- Failure return false
---- Success return true ---- Success return true
---@param texture any ---@param texture any
@@ -2656,7 +2649,7 @@ function RL.UnloadRenderTexture( target ) end
function RL.UpdateTexture( texture, pixels ) end function RL.UpdateTexture( texture, pixels ) end
---Update GPU texture rectangle with new data ---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 ---- Failure return false
---- Success return true ---- Success return true
---@param texture any ---@param texture any
@@ -2721,17 +2714,12 @@ function RL.BeginTextureMode( target ) end
---@return any RL.EndTextureMode ---@return any RL.EndTextureMode
function RL.EndTextureMode() end function RL.EndTextureMode() end
---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 ---- Failure return false
---- Success return true
---@param textureSource integer
---@return any success
function RL.SetTextureSource( textureSource ) end
---Get current texture source type ( TEXTURE_SOURCE_TEXTURE or TEXTURE_SOURCE_RENDER_TEXTURE )
---- Success return int ---- Success return int
---@return any textureSource ---@param texture any
function RL.GetTextureSource() end ---@return any type
function RL.GetTextureType( texture ) end
-- Textures - Texture Configuration -- Textures - Texture Configuration

View File

@@ -11,6 +11,7 @@ KEY CHANGES:
- ADDED: Camera3D Lua lib. - ADDED: Camera3D Lua lib.
- ADDED: Raygui wrapper lib. - ADDED: Raygui wrapper lib.
- CHANGED: Can now have multiple Music objects like other Raylib objects instead of just one. - CHANGED: Can now have multiple Music objects like other Raylib objects instead of just one.
- CHANGED: Texture now can be either Texture or RenderTexture. No need to change texture source anymore.
Detailed changes: Detailed changes:
- FIXED: uluaGetRay was looking for integers instead of tables. - FIXED: uluaGetRay was looking for integers instead of tables.
@@ -59,6 +60,10 @@ Detailed changes:
- ADDED: GetMusicLooping - ADDED: GetMusicLooping
- ADDED: DrawCapsule and DrawCapsuleWires - ADDED: DrawCapsule and DrawCapsuleWires
- ADDED: Free Camera3D example - ADDED: Free Camera3D example
- REMOVED: SetTextureSource
- REMOVED: GetTextureSource
- REMOVED: UnloadRenderTexture
- ADDED: GetTextureType
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.4.0 Using Raylib 4.2 Release: ReiLua version 0.4.0 Using Raylib 4.2

View File

@@ -121,7 +121,5 @@ function RL.draw()
RL.EndMode3D() RL.EndMode3D()
-- RL.EndTextureMode() -- RL.EndTextureMode()
-- RL.SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE )
-- RL.DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE ) -- RL.DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE )
-- RL.SetTextureSource( TEXTURE_SOURCE_TEXTURE )
end end

View File

@@ -75,11 +75,9 @@ function RL.init()
RL.EndTextureMode() RL.EndTextureMode()
material = RL.LoadMaterialDefault() material = RL.LoadMaterialDefault()
RL.SetTextureSource( RL.TEXTURE_SOURCE_RENDER_TEXTURE )
-- RL.GenTextureMipmaps( groundTexture ) -- RL.GenTextureMipmaps( groundTexture )
-- RL.SetTextureFilter( groundTexture, RL.TEXTURE_FILTER_TRILINEAR ) -- RL.SetTextureFilter( groundTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetMaterialTexture( material, RL.MATERIAL_MAP_ALBEDO, groundTexture ) RL.SetMaterialTexture( material, RL.MATERIAL_MAP_ALBEDO, groundTexture )
RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE )
matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) ) matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) )
end end

View File

@@ -1,3 +1,7 @@
package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
Cam3D = require( "camera3d" )
local PLANE_SIZE = 8 local PLANE_SIZE = 8
local monitor = 0 local monitor = 0
@@ -19,10 +23,18 @@ function RL.init()
RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
camera = RL.CreateCamera3D() -- camera = RL.CreateCamera3D()
RL.SetCamera3DPosition( camera, { 0, 8, 16 } ) -- RL.SetCamera3DPosition( camera, { 0, 8, 16 } )
RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) -- RL.SetCamera3DTarget( camera, { 0, 0, 0 } )
RL.SetCamera3DUp( camera, { 0, 1, 0 } ) -- RL.SetCamera3DUp( camera, { 0, 1, 0 } )
camera = Cam3D:new()
camera:setPosition( { 0, 8, 16 } )
camera:setTarget( { 0, 0, 0 } )
camera:setUp( { 0, 1, 0 } )
camera.mode = camera.MODES.ORBITAL
-- camera.mode = camera.MODES.FREE
-- camera.mode = camera.MODES.FIRST_PERSON
local ts = PLANE_SIZE local ts = PLANE_SIZE
local meshData = { local meshData = {
@@ -76,13 +88,25 @@ function RL.init()
matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) ) matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) )
end end
function RL.process( delta )
camera:process( delta )
if RL.IsKeyPressed( RL.KEY_SPACE ) then
if camera.mode == camera.MODES.FREE then
camera.mode = camera.MODES.FIRST_PERSON
else
camera.mode = camera.MODES.FREE
end
end
end
function RL.draw() function RL.draw()
RL.ClearBackground( { 25, 50, 50 } ) RL.ClearBackground( { 25, 50, 50 } )
-- RL.UpdateCamera3D( camera, RL.CAMERA_ORBITAL ) -- RL.UpdateCamera3D( camera, RL.CAMERA_ORBITAL )
-- RL.UpdateCamera3D( camera, RL.CAMERA_FREE ) -- RL.UpdateCamera3D( camera, RL.CAMERA_FREE )
RL.UpdateCamera3D( camera, RL.CAMERA_FIRST_PERSON ) -- RL.UpdateCamera3D( camera, RL.CAMERA_FIRST_PERSON )
RL.BeginMode3D( camera ) camera:beginMode3D()
RL.DrawMesh( mesh, material, matrix ) RL.DrawMesh( mesh, material, matrix )
RL.EndMode3D() camera:endMode3D()
end end

View File

@@ -50,7 +50,5 @@ function RL.draw()
RL.DrawTriangle( { 0, 32 }, { 32, 16 }, { 0, 0 }, RL.RED ) RL.DrawTriangle( { 0, 32 }, { 32, 16 }, { 0, 0 }, RL.RED )
RL.EndTextureMode() RL.EndTextureMode()
RL.SetTextureSource( RL.TEXTURE_SOURCE_RENDER_TEXTURE )
RL.DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, { 255, 255, 255 } ) RL.DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, { 255, 255, 255 } )
RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE )
end end

View File

@@ -288,15 +288,12 @@ end
function RL.draw() function RL.draw()
RL.ClearBackground( RL.RED ) RL.ClearBackground( RL.RED )
RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE )
RL.BeginTextureMode( framebuffer ) RL.BeginTextureMode( framebuffer )
drawMap() drawMap()
drawPlayer() drawPlayer()
RL.EndTextureMode() RL.EndTextureMode()
-- RL.SetTextureSource( RL.TEXTURE_SOURCE_RENDER_TEXTURE ) RL.DrawTexturePro( framebuffer, { 0, 0, res.x, -res.y }, { 0, 0, winSize.x, winSize.y }, { 0, 0 }, 0.0, RL.WHITE )
-- RL.DrawTexturePro( framebuffer, { 0, 0, res.x, -res.y }, { 0, 0, winSize.x, winSize.y }, { 0, 0 }, 0.0, RL.WHITE )
-- RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE )
RL.glBlitFramebuffer( framebuffer, -1, res, winSize, RL.GL_COLOR_BUFFER_BIT, RL.GL_NEAREST ) RL.glBlitFramebuffer( framebuffer, -1, res, winSize, RL.GL_COLOR_BUFFER_BIT, RL.GL_NEAREST )
end end

View File

@@ -218,7 +218,5 @@ function RL.draw()
RL.EndTextureMode() RL.EndTextureMode()
-- Draw framebuffer to window. -- Draw framebuffer to window.
RL.SetTextureSource( RL.TEXTURE_SOURCE_RENDER_TEXTURE )
RL.DrawTexturePro( framebuffer, { 0, 0, RESOLUTION[1], -RESOLUTION[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, RL.WHITE ) RL.DrawTexturePro( framebuffer, { 0, 0, RESOLUTION[1], -RESOLUTION[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, RL.WHITE )
RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE )
end end

View File

@@ -7,13 +7,18 @@ typedef struct {
unsigned int animCount; unsigned int animCount;
} ModelAnimations; } ModelAnimations;
typedef struct {
int type;
Texture texture;
RenderTexture renderTexture;
} ReiTexture;
typedef struct { typedef struct {
char *exePath; char *exePath;
bool hasWindow; bool hasWindow;
bool run; bool run;
lua_State *luaState; lua_State *luaState;
Vector2 resolution; Vector2 resolution;
int textureSource;
size_t guiFont; size_t guiFont;
/* Resources. */ /* Resources. */
/* Images. */ /* Images. */
@@ -21,13 +26,9 @@ typedef struct {
size_t imageCount; size_t imageCount;
size_t imageAlloc; size_t imageAlloc;
/* Textures. */ /* Textures. */
Texture **textures; ReiTexture **textures;
size_t textureCount; size_t textureCount;
size_t textureAlloc; size_t textureAlloc;
/* RenderTextures. */
RenderTexture **renderTextures;
size_t renderTextureCount;
size_t renderTextureAlloc;
/* Fonts. */ /* Fonts. */
Font **fonts; Font **fonts;
size_t fontCount; size_t fontCount;

View File

@@ -1,13 +1,15 @@
#pragma once #pragma once
enum TEXTURE_SOURCES { TEXTURE_SOURCE_TEXTURE, TEXTURE_SOURCE_RENDER_TEXTURE }; /* TEXTURE_TYPE_ALL is internal and used for accepting every type. */
enum TEXTURE_TYPE { TEXTURE_TYPE_TEXTURE, TEXTURE_TYPE_RENDER_TEXTURE, TEXTURE_TYPE_ALL };
/* Validators. */ /* Validators. */
bool validImage( size_t id ); bool validImage( size_t id );
bool validTexture( size_t id ); bool validTexture( size_t id, int type );
bool validRenderTexture( size_t id ); bool validRenderTexture( size_t id );
bool validSourceTexture( size_t id ); bool validSourceTexture( size_t id );
Texture2D* texturesGetSourceTexture( size_t index ); Texture2D* texturesGetSourceTexture( size_t id );
void texturesFreeTexture( size_t id );
/* Image Loading. */ /* Image Loading. */
int ltexturesLoadImage( lua_State *L ); int ltexturesLoadImage( lua_State *L );
int ltexturesLoadImageFromTexture( lua_State *L ); int ltexturesLoadImageFromTexture( lua_State *L );
@@ -74,7 +76,6 @@ int ltexturesLoadTextureFromImage( lua_State *L );
int ltexturesLoadTextureCubemap( lua_State *L ); int ltexturesLoadTextureCubemap( lua_State *L );
int ltexturesLoadRenderTexture( lua_State *L ); int ltexturesLoadRenderTexture( lua_State *L );
int ltexturesUnloadTexture( lua_State *L ); int ltexturesUnloadTexture( lua_State *L );
int ltexturesUnloadRenderTexture( lua_State *L );
int ltexturesUpdateTexture( lua_State *L ); int ltexturesUpdateTexture( lua_State *L );
int ltexturesUpdateTextureRec( lua_State *L ); int ltexturesUpdateTextureRec( lua_State *L );
/* Texture Drawing. */ /* Texture Drawing. */
@@ -84,8 +85,7 @@ int ltexturesDrawTexturePro( lua_State *L );
int ltexturesDrawTextureNPatch( lua_State *L ); int ltexturesDrawTextureNPatch( lua_State *L );
int ltexturesBeginTextureMode( lua_State *L ); int ltexturesBeginTextureMode( lua_State *L );
int ltexturesEndTextureMode( lua_State *L ); int ltexturesEndTextureMode( lua_State *L );
int ltexturesSetTextureSource( lua_State *L ); int ltexturesGetTextureType( lua_State *L );
int ltexturesGetTextureSource( lua_State *L );
/* Texture Configuration. */ /* Texture Configuration. */
int ltexturesGenTextureMipmaps( lua_State *L ); int ltexturesGenTextureMipmaps( lua_State *L );
int ltexturesSetTextureFilter( lua_State *L ); int ltexturesSetTextureFilter( lua_State *L );

View File

@@ -1247,11 +1247,12 @@ int lcoreSetShaderValueTexture( lua_State *L ) {
int locIndex = lua_tointeger( L, 2 ); int locIndex = lua_tointeger( L, 2 );
size_t textureId = lua_tointeger( L, 3 ); size_t textureId = lua_tointeger( L, 3 );
if ( !validShader( shaderId ) || !validTexture( textureId ) ) { if ( !validShader( shaderId ) || !validTexture( textureId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; 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 ); lua_pushboolean( L, true );
return 1; return 1;

View File

@@ -31,7 +31,9 @@ int lglBlitFramebuffer( lua_State *L ) {
int mask = lua_tointeger( L, 5 ); int mask = lua_tointeger( L, 5 );
int filter = lua_tointeger( L, 6 ); 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 ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -40,14 +42,14 @@ int lglBlitFramebuffer( lua_State *L ) {
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
} }
else { else {
glBindFramebuffer( GL_READ_FRAMEBUFFER, state->renderTextures[ srcTexId ]->id ); glBindFramebuffer( GL_READ_FRAMEBUFFER, state->textures[ srcTexId ]->renderTexture.id );
} }
if ( dstTexId == -1 ) { if ( dstTexId == -1 ) {
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
} }
else { else {
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, state->renderTextures[ dstTexId ]->id ); glBindFramebuffer( GL_DRAW_FRAMEBUFFER, state->textures[ dstTexId ]->renderTexture.id );
} }
glBlitFramebuffer( glBlitFramebuffer(

View File

@@ -369,8 +369,8 @@ void defineGlobals() {
assignGlobalInt( NPATCH_THREE_PATCH_VERTICAL, "NPATCH_THREE_PATCH_VERTICAL" ); assignGlobalInt( NPATCH_THREE_PATCH_VERTICAL, "NPATCH_THREE_PATCH_VERTICAL" );
assignGlobalInt( NPATCH_THREE_PATCH_HORIZONTAL, "NPATCH_THREE_PATCH_HORIZONTAL" ); assignGlobalInt( NPATCH_THREE_PATCH_HORIZONTAL, "NPATCH_THREE_PATCH_HORIZONTAL" );
/* TextureModes */ /* TextureModes */
assignGlobalInt( TEXTURE_SOURCE_TEXTURE, "TEXTURE_SOURCE_TEXTURE" ); assignGlobalInt( TEXTURE_TYPE_TEXTURE, "TEXTURE_TYPE_TEXTURE" );
assignGlobalInt( TEXTURE_SOURCE_RENDER_TEXTURE, "TEXTURE_SOURCE_RENDER_TEXTURE" ); assignGlobalInt( TEXTURE_TYPE_RENDER_TEXTURE, "TEXTURE_TYPE_RENDER_TEXTURE" );
/* Colors */ /* Colors */
assignGlobalColor( LIGHTGRAY, "LIGHTGRAY" ); assignGlobalColor( LIGHTGRAY, "LIGHTGRAY" );
assignGlobalColor( GRAY, "GRAY" ); assignGlobalColor( GRAY, "GRAY" );
@@ -1000,7 +1000,6 @@ void luaRegister() {
assingGlobalFunction( "LoadTextureCubemap", ltexturesLoadTextureCubemap ); assingGlobalFunction( "LoadTextureCubemap", ltexturesLoadTextureCubemap );
assingGlobalFunction( "LoadRenderTexture", ltexturesLoadRenderTexture ); assingGlobalFunction( "LoadRenderTexture", ltexturesLoadRenderTexture );
assingGlobalFunction( "UnloadTexture", ltexturesUnloadTexture ); assingGlobalFunction( "UnloadTexture", ltexturesUnloadTexture );
assingGlobalFunction( "UnloadRenderTexture", ltexturesUnloadRenderTexture );
assingGlobalFunction( "UpdateTexture", ltexturesUpdateTexture ); assingGlobalFunction( "UpdateTexture", ltexturesUpdateTexture );
assingGlobalFunction( "UpdateTextureRec", ltexturesUpdateTextureRec ); assingGlobalFunction( "UpdateTextureRec", ltexturesUpdateTextureRec );
/* Texture Drawing. */ /* Texture Drawing. */
@@ -1010,8 +1009,7 @@ void luaRegister() {
assingGlobalFunction( "DrawTextureNPatch", ltexturesDrawTextureNPatch ); assingGlobalFunction( "DrawTextureNPatch", ltexturesDrawTextureNPatch );
assingGlobalFunction( "BeginTextureMode", ltexturesBeginTextureMode ); assingGlobalFunction( "BeginTextureMode", ltexturesBeginTextureMode );
assingGlobalFunction( "EndTextureMode", ltexturesEndTextureMode ); assingGlobalFunction( "EndTextureMode", ltexturesEndTextureMode );
assingGlobalFunction( "SetTextureSource", ltexturesSetTextureSource ); assingGlobalFunction( "GetTextureType", ltexturesGetTextureType );
assingGlobalFunction( "GetTextureSource", ltexturesGetTextureSource );
/* Texture Configuration. */ /* Texture Configuration. */
assingGlobalFunction( "GenTextureMipmaps", ltexturesGenTextureMipmaps ); assingGlobalFunction( "GenTextureMipmaps", ltexturesGenTextureMipmaps );
assingGlobalFunction( "SetTextureFilter", ltexturesSetTextureFilter ); assingGlobalFunction( "SetTextureFilter", ltexturesSetTextureFilter );

View File

@@ -665,7 +665,7 @@ int lmodelDrawQuad3DTexture( lua_State *L ) {
//TODO Normals. maybe something like Vector3Normalize(Vector3CrossProduct(Vector3Subtract(vB, vA), Vector3Subtract(vC, vA))); //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 ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -1138,7 +1138,6 @@ int lmodelsGenMeshCustom( lua_State *L ) {
} }
lua_pop( L, 1 ); lua_pop( L, 1 );
} }
bool dynamic = lua_toboolean( L, 2 ); bool dynamic = lua_toboolean( L, 2 );
UploadMesh( &mesh, dynamic ); 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 ) ) { if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) {
size_t texId = lua_tointeger( L, -1 ); size_t texId = lua_tointeger( L, -1 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -1669,7 +1668,7 @@ int lmodelsSetMaterialTexture( lua_State *L ) {
int mapType = lua_tointeger( L, 2 ); int mapType = lua_tointeger( L, 2 );
size_t texId = lua_tointeger( L, 3 ); size_t texId = lua_tointeger( L, 3 );
if ( !validMaterial( materialId ) || !validSourceTexture( texId ) ) { if ( !validMaterial( materialId ) || !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -2014,7 +2013,7 @@ int lmodelsDrawBillboard( lua_State *L ) {
float size = lua_tonumber( L, 4 ); float size = lua_tonumber( L, 4 );
Color tint = uluaGetColorIndex( L, 5 ); Color tint = uluaGetColorIndex( L, 5 );
if ( !validSourceTexture( texId ) || !validCamera3D( cameraId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) || !validCamera3D( cameraId ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -2046,7 +2045,7 @@ int lmodelsDrawBillboardRec( lua_State *L ) {
Vector2 size = uluaGetVector2Index( L, 5 ); Vector2 size = uluaGetVector2Index( L, 5 );
Color tint = uluaGetColorIndex( L, 6 ); Color tint = uluaGetColorIndex( L, 6 );
if ( !validSourceTexture( texId ) || !validCamera3D( cameraId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) || !validCamera3D( cameraId ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }

View File

@@ -26,7 +26,7 @@ int lshapesSetShapesTexture( lua_State *L ) {
size_t texId = lua_tointeger( L, 1 ); size_t texId = lua_tointeger( L, 1 );
Rectangle source = uluaGetRectangleIndex( L, 2 ); Rectangle source = uluaGetRectangleIndex( L, 2 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }

View File

@@ -16,7 +16,6 @@ bool stateInit( const char *exePath ) {
state->run = true; state->run = true;
state->resolution = (Vector2){ 800, 600 }; state->resolution = (Vector2){ 800, 600 };
state->luaState = NULL; state->luaState = NULL;
state->textureSource = TEXTURE_SOURCE_TEXTURE;
state->guiFont = 0; state->guiFont = 0;
/* Images. */ /* Images. */
state->imageAlloc = ALLOC_PAGE_SIZE; state->imageAlloc = ALLOC_PAGE_SIZE;
@@ -25,11 +24,7 @@ bool stateInit( const char *exePath ) {
/* Textures. */ /* Textures. */
state->textureAlloc = ALLOC_PAGE_SIZE; state->textureAlloc = ALLOC_PAGE_SIZE;
state->textureCount = 0; state->textureCount = 0;
state->textures = malloc( state->textureAlloc * sizeof( Texture2D* ) ); state->textures = malloc( state->textureAlloc * sizeof( ReiTexture* ) );
/* RenderTextures. */
state->renderTextureAlloc = ALLOC_PAGE_SIZE;
state->renderTextureCount = 0;
state->renderTextures = malloc( state->renderTextureAlloc * sizeof( RenderTexture2D* ) );
/* Fonts. */ /* Fonts. */
state->fontAlloc = ALLOC_PAGE_SIZE; state->fontAlloc = ALLOC_PAGE_SIZE;
state->fontCount = 1; state->fontCount = 1;
@@ -82,7 +77,6 @@ bool stateInit( const char *exePath ) {
for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) { for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) {
state->images[i] = NULL; state->images[i] = NULL;
state->textures[i] = NULL; state->textures[i] = NULL;
state->renderTextures[i] = NULL;
state->waves[i] = NULL; state->waves[i] = NULL;
state->sounds[i] = NULL; state->sounds[i] = NULL;
state->camera2Ds[i] = NULL; state->camera2Ds[i] = NULL;
@@ -133,16 +127,10 @@ void stateFree() {
} }
for ( int i = 0; i < state->textureCount; ++i ) { for ( int i = 0; i < state->textureCount; ++i ) {
if ( state->textures[i] != NULL ) { if ( state->textures[i] != NULL ) {
UnloadTexture( *state->textures[i] ); texturesFreeTexture(i);
free( state->textures[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 ) { for ( int i = 0; i < state->fontCount; ++i ) {
if ( state->fonts[i] != NULL ) { if ( state->fonts[i] != NULL ) {
UnloadFont( *state->fonts[i] ); UnloadFont( *state->fonts[i] );
@@ -232,7 +220,6 @@ void stateFree() {
} }
free( state->images ); free( state->images );
free( state->textures ); free( state->textures );
free( state->renderTextures );
free( state->fonts ); free( state->fonts );
free( state->waves ); free( state->waves );
free( state->sounds ); free( state->sounds );

View File

@@ -26,7 +26,7 @@ static void checkTextureRealloc( int i ) {
if ( state->textureCount == state->textureAlloc ) { if ( state->textureCount == state->textureAlloc ) {
state->textureAlloc += ALLOC_PAGE_SIZE; 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++ ) { for ( i = state->textureCount; i < state->textureAlloc; i++ ) {
state->textures[i] = NULL; 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 ) { bool validImage( size_t id ) {
if ( id < 0 || state->imageCount < id || state->images[ id ] == NULL ) { if ( id < 0 || state->imageCount < id || state->images[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid image", id ); 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 ) { if ( id < 0 || state->textureCount < id || state->textures[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid texture", id ); TraceLog( LOG_WARNING, "%s %d", "Invalid texture", id );
return false; return false;
} }
else { else if ( type != TEXTURE_TYPE_ALL && type != state->textures[ id ]->type ) {
return true; TraceLog( LOG_WARNING, "%s %d", "Wrong texture type", type );
}
}
bool validRenderTexture( size_t id ) {
if ( id < 0 || state->renderTextureCount < id || state->renderTextures[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid renderTexture", id );
return false; return false;
} }
else { 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() { static int newImage() {
int i = 0; int i = 0;
@@ -105,7 +72,7 @@ static int newImage() {
return i; return i;
} }
static int newTexture() { static int newTexture( int type ) {
int i = 0; int i = 0;
for ( i = 0; i < state->textureCount; i++ ) { for ( i = 0; i < state->textureCount; i++ ) {
@@ -113,24 +80,39 @@ static int newTexture() {
break; break;
} }
} }
state->textures[i] = malloc( sizeof( Texture2D ) ); state->textures[i] = malloc( sizeof( ReiTexture ) );
state->textures[i]->type = type;
checkTextureRealloc( i ); checkTextureRealloc( i );
return i; return i;
} }
Texture2D* texturesGetSourceTexture( size_t index ) { Texture2D* texturesGetSourceTexture( size_t id ) {
switch ( state->textureSource ) { if ( state->textures[id] != NULL ) {
case TEXTURE_SOURCE_TEXTURE: switch ( state->textures[id]->type ) {
return state->textures[ index ]; case TEXTURE_TYPE_TEXTURE:
case TEXTURE_SOURCE_RENDER_TEXTURE: return &state->textures[id]->texture;
return &state->renderTextures[ index ]->texture; break;
default: case TEXTURE_TYPE_RENDER_TEXTURE:
return state->textures[ index ]; return &state->textures[id]->renderTexture.texture;
break; 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 ## Textures - Image Loading
*/ */
@@ -178,7 +160,7 @@ int ltexturesLoadImageFromTexture( lua_State *L ) {
} }
size_t texId = lua_tointeger( L, 1 ); size_t texId = lua_tointeger( L, 1 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushinteger( L, -1 ); lua_pushinteger( L, -1 );
return 1; return 1;
} }
@@ -1654,10 +1636,9 @@ int ltexturesLoadTexture( lua_State *L ) {
lua_pushinteger( L, -1 ); lua_pushinteger( L, -1 );
return 1; return 1;
} }
if ( FileExists( lua_tostring( L, 1 ) ) ) { if ( FileExists( lua_tostring( L, 1 ) ) ) {
int i = newTexture(); int i = newTexture( TEXTURE_TYPE_TEXTURE );
*state->textures[i] = LoadTexture( lua_tostring( L, 1 ) ); state->textures[i]->texture = LoadTexture( lua_tostring( L, 1 ) );
lua_pushinteger( L, i ); lua_pushinteger( L, i );
return 1; return 1;
} }
@@ -1687,8 +1668,8 @@ int ltexturesLoadTextureFromImage( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
int i = newTexture(); int i = newTexture( TEXTURE_TYPE_TEXTURE );
*state->textures[i] = LoadTextureFromImage( *state->images[ imageId ] ); state->textures[i]->texture = LoadTextureFromImage( *state->images[ imageId ] );
lua_pushinteger( L, i ); lua_pushinteger( L, i );
return 1; return 1;
@@ -1715,8 +1696,8 @@ int ltexturesLoadTextureCubemap( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
int i = newTexture(); int i = newTexture( TEXTURE_TYPE_TEXTURE );
*state->textures[i] = LoadTextureCubemap( *state->images[ imageId ], layout ); state->textures[i]->texture = LoadTextureCubemap( *state->images[ imageId ], layout );
lua_pushinteger( L, i ); lua_pushinteger( L, i );
return 1; return 1;
@@ -1737,17 +1718,10 @@ int ltexturesLoadRenderTexture( lua_State *L ) {
return 1; return 1;
} }
Vector2 size = uluaGetVector2Index( L, 1 ); Vector2 size = uluaGetVector2Index( L, 1 );
int i = 0;
for ( i = 0; i < state->renderTextureCount; i++ ) { int i = newTexture( TEXTURE_TYPE_RENDER_TEXTURE );
if ( state->renderTextures[i] == NULL ) { state->textures[i]->renderTexture = LoadRenderTexture( (int)size.x, (int)size.y );
break;
}
}
state->renderTextures[i] = malloc( sizeof( RenderTexture2D ) );
*state->renderTextures[i] = LoadRenderTexture( (int)size.x, (int)size.y );
lua_pushinteger( L, i ); lua_pushinteger( L, i );
checkRenderTextureRealloc( i );
return 1; return 1;
} }
@@ -1768,39 +1742,13 @@ int ltexturesUnloadTexture( lua_State *L ) {
} }
size_t id = lua_tointeger( L, 1 ); size_t id = lua_tointeger( L, 1 );
if ( !validTexture( id ) ) { if ( !validTexture( id, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
UnloadTexture( *state->textures[ id ] ); // UnloadTexture( *state->textures[ id ] );
state->textures[ id ] = NULL; texturesFreeTexture( id );
lua_pushboolean( L, true ); // state->textures[ id ] = NULL;
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 ) ) {
lua_pushboolean( L, false );
return 1;
}
UnloadRenderTexture( *state->renderTextures[ id ] );
state->renderTextures[ id ] = NULL;
lua_pushboolean( L, true ); lua_pushboolean( L, true );
return 1; return 1;
@@ -1810,7 +1758,7 @@ int ltexturesUnloadRenderTexture( lua_State *L ) {
> success = RL.UpdateTexture( Texture2D texture, int{} pixels ) > success = RL.UpdateTexture( Texture2D texture, int{} pixels )
Update GPU texture with new data 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 - Failure return false
- Success return true - Success return true
@@ -1823,7 +1771,7 @@ int ltexturesUpdateTexture( lua_State *L ) {
} }
size_t texId = lua_tointeger( L, 1 ); size_t texId = lua_tointeger( L, 1 );
if ( !validTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_TEXTURE ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -1850,7 +1798,8 @@ int ltexturesUpdateTexture( lua_State *L ) {
i++; i++;
lua_pop( L, 1 ); lua_pop( L, 1 );
} }
UpdateTexture( *state->textures[ texId ], pixels ); // UpdateTexture( *state->textures[ texId ], pixels );
UpdateTexture( state->textures[ texId ]->texture, pixels );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
free( pixels ); free( pixels );
@@ -1862,7 +1811,7 @@ int ltexturesUpdateTexture( lua_State *L ) {
> success = RL.UpdateTextureRec( Texture2D texture, Rectangle rec, int{} pixels ) > success = RL.UpdateTextureRec( Texture2D texture, Rectangle rec, int{} pixels )
Update GPU texture rectangle with new data 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 - Failure return false
- Success return true - Success return true
@@ -1875,7 +1824,7 @@ int ltexturesUpdateTextureRec( lua_State *L ) {
} }
size_t texId = lua_tointeger( L, 1 ); size_t texId = lua_tointeger( L, 1 );
if ( !validTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_TEXTURE ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -1906,7 +1855,7 @@ int ltexturesUpdateTextureRec( lua_State *L ) {
Rectangle rec = uluaGetRectangleIndex( L, 2 ); Rectangle rec = uluaGetRectangleIndex( L, 2 );
UpdateTextureRec( *state->textures[ texId ], rec, pixels ); UpdateTextureRec( state->textures[ texId ]->texture, rec, pixels );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
free( pixels ); free( pixels );
@@ -1936,7 +1885,7 @@ int ltexturesDrawTexture( lua_State *L ) {
Vector2 pos = uluaGetVector2Index( L, 2 ); Vector2 pos = uluaGetVector2Index( L, 2 );
Color color = uluaGetColorIndex( L, 3 ); Color color = uluaGetColorIndex( L, 3 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -1966,7 +1915,7 @@ int ltexturesDrawTextureRec( lua_State *L ) {
Vector2 pos = uluaGetVector2Index( L, 3 ); Vector2 pos = uluaGetVector2Index( L, 3 );
Color tint = uluaGetColorIndex( L, 4 ); Color tint = uluaGetColorIndex( L, 4 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -1999,7 +1948,7 @@ int ltexturesDrawTexturePro( lua_State *L ) {
float rot = lua_tonumber( L, 5 ); float rot = lua_tonumber( L, 5 );
Color color = uluaGetColorIndex( L, 6 ); Color color = uluaGetColorIndex( L, 6 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -2032,7 +1981,7 @@ int ltexturesDrawTextureNPatch( lua_State *L ) {
float rotation = lua_tonumber( L, 5 ); float rotation = lua_tonumber( L, 5 );
Color tint = uluaGetColorIndex( L, 6 ); Color tint = uluaGetColorIndex( L, 6 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -2058,12 +2007,12 @@ int ltexturesBeginTextureMode( lua_State *L ) {
} }
size_t texId = lua_tointeger( L, 1 ); size_t texId = lua_tointeger( L, 1 );
if ( !validRenderTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_RENDER_TEXTURE ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
BeginTextureMode( *state->renderTextures[ texId ] ); BeginTextureMode( state->textures[ texId ]->renderTexture );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
return 1; 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 - Failure return false
- Success return true
*/
int ltexturesSetTextureSource( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetTextureSource( int textureSource )" );
lua_pushboolean( L, false );
return 1;
}
int texSource = lua_tointeger( L, 1 );
if ( texSource != TEXTURE_SOURCE_TEXTURE && texSource != TEXTURE_SOURCE_RENDER_TEXTURE ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid source texture", texSource );
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 - Success return int
*/ */
int ltexturesGetTextureSource( lua_State *L ) { int ltexturesGetTextureType( lua_State *L ) {
lua_pushinteger( L, state->textureSource ); if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetTextureType( Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
}
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; return 1;
} }
@@ -2141,11 +2074,10 @@ int ltexturesGenTextureMipmaps( lua_State *L ) {
} }
size_t texId = lua_tointeger( L, 1 ); size_t texId = lua_tointeger( L, 1 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
GenTextureMipmaps( texturesGetSourceTexture( texId ) ); GenTextureMipmaps( texturesGetSourceTexture( texId ) );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
@@ -2169,7 +2101,7 @@ int ltexturesSetTextureFilter( lua_State *L ) {
size_t texId = lua_tointeger( L, 1 ); size_t texId = lua_tointeger( L, 1 );
int filter = lua_tointeger( L, 2 ); int filter = lua_tointeger( L, 2 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -2197,7 +2129,7 @@ int ltexturesSetTextureWrap( lua_State *L ) {
size_t texId = lua_tointeger( L, 1 ); size_t texId = lua_tointeger( L, 1 );
int wrap = lua_tointeger( L, 2 ); int wrap = lua_tointeger( L, 2 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
@@ -2224,7 +2156,7 @@ int ltexturesGetTextureSize( lua_State *L ) {
} }
size_t texId = lua_tointeger( L, 1 ); size_t texId = lua_tointeger( L, 1 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushnil( L ); lua_pushnil( L );
return 1; return 1;
} }
@@ -2568,7 +2500,7 @@ int ltexturesGetPixelColor( lua_State *L ) {
size_t texId = lua_tointeger( L, 1 ); size_t texId = lua_tointeger( L, 1 );
Vector2 pos = uluaGetVector2Index( L, 2 ); Vector2 pos = uluaGetVector2Index( L, 2 );
if ( !validSourceTexture( texId ) ) { if ( !validTexture( texId, TEXTURE_TYPE_ALL ) ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }