isValidRenderTexture fix.

This commit is contained in:
jussi
2023-10-11 15:19:54 +03:00
parent 8311dfd354
commit c3352b8ed7
8 changed files with 72 additions and 75 deletions

View File

@@ -100,6 +100,7 @@ Detailed changes:
- ADDED: Values for API.md - ADDED: Values for API.md
- ADDED: GetFontTexture - ADDED: GetFontTexture
- CHANGED: Renamed doc_parser.lua to docgen.lua - CHANGED: Renamed doc_parser.lua to docgen.lua
- FIXED: isValidRenderTexture checks that it is TEXTURE_TYPE_RENDER_TEXTURE
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.4.0 Using Raylib 4.2 Release: ReiLua version 0.4.0 Using Raylib 4.2

View File

@@ -36,10 +36,16 @@ end
function RL.draw() function RL.draw()
RL.ClearBackground( { 50, 20, 75 } ) RL.ClearBackground( { 50, 20, 75 } )
-- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 10 )
if RL.GuiButton( { 112, 16, 96, 32 }, RL.GuiIconText( 113, "Exit" ) ) then if RL.GuiButton( { 112, 16, 96, 32 }, RL.GuiIconText( 113, "Exit" ) ) then
RL.CloseWindow() RL.CloseWindow()
end end
-- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 )
RL.GuiButton( { 112, 64, 96, 32 }, RL.GuiIconText( 113, "Kissa" ) )
-- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 10 )
if windowOpen and RL.GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) then if windowOpen and RL.GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) then
windowOpen = false windowOpen = false
end end

View File

@@ -2,8 +2,6 @@
local monitor = 0 local monitor = 0
local texture = -1 local texture = -1
local vaoId = -1
local vboId = -1
local triSize = 32.0 local triSize = 32.0
local vertices = { local vertices = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
@@ -16,6 +14,39 @@ local colors = {
RL.BLUE, RL.BLUE, RL.BLUE RL.BLUE, RL.BLUE, RL.BLUE
} }
local VBO_VERTEX_POS = 0
local VBO_COLOR_POS = 1
local mesh = {
vaoId = -1,
vboIds = {
vertices = -1,
colors = -1,
}
}
function uploadMesh()
mesh.vaoId = RL.rlLoadVertexArray()
RL.rlEnableVertexArray( mesh.vaoId )
-- Vertices.
mesh.vboIds.vertices = RL.rlLoadVertexBuffer( vertices, RL.RL_FLOAT, false )
RL.rlSetVertexAttribute( VBO_VERTEX_POS, 3, RL.RL_FLOAT, false, 0, 0 )
RL.rlEnableVertexAttribute( VBO_VERTEX_POS )
-- Colors.
mesh.vboIds.colors = RL.rlLoadVertexBuffer( vertices, RL.RL_UNSIGNED_BYTE, false )
RL.rlSetVertexAttribute( VBO_COLOR_POS, 4, RL.RL_UNSIGNED_BYTE, false, 0, 0 )
RL.rlEnableVertexAttribute( VBO_COLOR_POS )
RL.rlDisableVertexArray()
print( "Mesh:" )
print( "\tvaoId: "..mesh.vaoId )
print( "\tvboIds.vertices: "..mesh.vboIds.vertices )
print( "\tvboIds.colors: "..mesh.vboIds.colors )
end
function RL.init() function RL.init()
local mPos = RL.GetMonitorPosition( monitor ) local mPos = RL.GetMonitorPosition( monitor )
local mSize = RL.GetMonitorSize( monitor ) local mSize = RL.GetMonitorSize( monitor )
@@ -25,32 +56,25 @@ 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 } )
vaoId = RL.rlLoadVertexArray() uploadMesh()
end
RL.rlEnableVertexArray( vaoId ) function drawMesh()
-- vboId = RL.rlLoadVertexBuffer( vertexBuffer, RL.RL_UNSIGNED_BYTE, false )
vboId = RL.rlLoadVertexBuffer( vertices, RL.RL_FLOAT, false )
RL.rlSetVertexAttribute( 0, 3, RL.RL_FLOAT, false, 0, 0 )
RL.rlEnableVertexAttribute( 0 )
RL.rlDisableVertexArray()
-- RL.DrawMesh( )
-- print( "vaoId", vaoId )
-- print( "vboId", vboId )
end end
function RL.draw() function RL.draw()
RL.ClearBackground( { 100, 150, 100 } ) RL.ClearBackground( { 100, 150, 100 } )
end end
-- You need to manually free resources.
function RL.exit() function RL.exit()
if 0 <= vaoId then if 0 <= mesh.vaoId then
RL.rlUnloadVertexArray( vaoId ) RL.rlUnloadVertexArray( mesh.vaoId )
end end
if 0 <= vboId then for _, vboId in pairs( mesh.vboIds ) do
RL.rlUnloadVertexBuffer( vboId ) if 0 <= vboId then
RL.rlUnloadVertexBuffer( vboId )
end
end end
end end

View File

@@ -14,9 +14,6 @@ enum EventType {
EVENT_CURSOR_ENTER EVENT_CURSOR_ENTER
}; };
void defineGlobals();
void logCustom( int logLevel, const char *text, va_list args );
bool luaInit(); bool luaInit();
int luaTraceback( lua_State *L ); int luaTraceback( lua_State *L );
bool luaCallMain(); bool luaCallMain();

View File

@@ -46,9 +46,9 @@
#endif #endif
#else #else
#ifdef SHARED #ifdef SHARED
#include <lua/lua.h> #include <lua.h>
#include <lua/lualib.h> #include <lualib.h>
#include <lua/lauxlib.h> #include <lauxlib.h>
#else #else
#include "lua/lua.h" #include "lua/lua.h"
#include "lua/lualib.h" #include "lua/lualib.h"

View File

@@ -44,10 +44,10 @@ static void assingGlobalFunction( const char *name, int ( *functionPtr )( lua_St
lua_setfield( L, -2, name ); lua_setfield( L, -2, name );
} }
void defineGlobals() { static void defineGlobals() {
lua_State *L = state->luaState; lua_State *L = state->luaState;
lua_newtable( state->luaState ); lua_newtable( L );
lua_setglobal( L, "RL" ); lua_setglobal( L, "RL" );
lua_getglobal( L, "RL" ); lua_getglobal( L, "RL" );
@@ -637,7 +637,7 @@ void defineGlobals() {
} }
// Custom logging funtion. // Custom logging funtion.
void logCustom( int logLevel, const char *text, va_list args ) { static void logCustom( int logLevel, const char *text, va_list args ) {
char string[ STRING_LEN ] = {'\0'}; char string[ STRING_LEN ] = {'\0'};
char msg[ STRING_LEN ] = {'\0'}; char msg[ STRING_LEN ] = {'\0'};
@@ -1993,60 +1993,46 @@ bool isValidTexture( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) { if ( lua_isnumber( L, index ) ) {
int id = lua_tointeger( L, index ); int id = lua_tointeger( L, index );
if ( ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL ) ) { if ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL ) {
return true; return true;
} }
else {
return false;
}
} }
else if ( allowTable && lua_istable( L, index ) ) { else if ( allowTable && lua_istable( L, index ) ) {
return true; return true;
} }
else { TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Texture." );
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Texture." ); return false;
return false;
}
} }
bool isValidRenderTexture( lua_State *L, int index, bool allowTable ) { bool isValidRenderTexture( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) { if ( lua_isnumber( L, index ) ) {
int id = lua_tointeger( L, index ); int id = lua_tointeger( L, index );
if ( ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL ) ) { if ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL
&& state->textures[ id ]->type == TEXTURE_TYPE_RENDER_TEXTURE ) {
return true; return true;
} }
else {
return false;
}
} }
else if ( allowTable && lua_istable( L, index ) ) { else if ( allowTable && lua_istable( L, index ) ) {
return true; return true;
} }
else { TraceLog( state->logLevelInvalid, "%s", "Error. Invalid RenderTexture." );
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid RenderTexture." ); return false;
return false;
}
} }
bool isValidCamera2D( lua_State *L, int index, bool allowTable ) { bool isValidCamera2D( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) { if ( lua_isnumber( L, index ) ) {
int id = lua_tointeger( L, index ); int id = lua_tointeger( L, index );
if ( ( 0 <= id && id < state->camera2DCount && state->camera2Ds[ id ] != NULL ) ) { if ( 0 <= id && id < state->camera2DCount && state->camera2Ds[ id ] != NULL ) {
return true; return true;
} }
else {
return false;
}
} }
else if ( allowTable && lua_istable( L, index ) ) { else if ( allowTable && lua_istable( L, index ) ) {
return true; return true;
} }
else { TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera2D." );
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera2D." ); return false;
return false;
}
} }
bool isValidCamera3D( lua_State *L, int index, bool allowTable ) { bool isValidCamera3D( lua_State *L, int index, bool allowTable ) {
@@ -2056,17 +2042,12 @@ bool isValidCamera3D( lua_State *L, int index, bool allowTable ) {
if ( ( 0 <= id && id < state->camera3DCount && state->camera3Ds[ id ] != NULL ) ) { if ( ( 0 <= id && id < state->camera3DCount && state->camera3Ds[ id ] != NULL ) ) {
return true; return true;
} }
else {
return false;
}
} }
else if ( allowTable && lua_istable( L, index ) ) { else if ( allowTable && lua_istable( L, index ) ) {
return true; return true;
} }
else { TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera3D." );
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera3D." ); return false;
return false;
}
} }
/* Lua util functions. */ /* Lua util functions. */
@@ -2082,7 +2063,6 @@ Color uluaGetColorIndex( lua_State *L, int index ) {
TraceLog( state->logLevelInvalid, "%s", "Error. Wrong color value. Returning { 0, 0, 0, 255 }" ); TraceLog( state->logLevelInvalid, "%s", "Error. Wrong color value. Returning { 0, 0, 0, 255 }" );
return color; return color;
} }
// int t = lua_gettop( L ), i = 0;
int t = index, i = 0; int t = index, i = 0;
lua_pushnil( L ); lua_pushnil( L );

View File

@@ -94,7 +94,6 @@ bool stateInit( const char *exePath ) {
state->materials[i] = NULL; state->materials[i] = NULL;
} }
} }
InitWindow( state->resolution.x, state->resolution.y, "ReiLua" ); InitWindow( state->resolution.x, state->resolution.y, "ReiLua" );
/* Has to be after InitWindod where opengl context is created. */ /* Has to be after InitWindod where opengl context is created. */
state->materials[0] = malloc( sizeof( Material ) ); state->materials[0] = malloc( sizeof( Material ) );
@@ -123,13 +122,13 @@ void stateFree() {
for ( int i = 0; i < state->imageCount; ++i ) { for ( int i = 0; i < state->imageCount; ++i ) {
if ( state->images[i] != NULL ) { if ( state->images[i] != NULL ) {
UnloadImage( *state->images[i] ); UnloadImage( *state->images[i] );
// free( state->images[i] ); free( state->images[i] );
} }
} }
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 ) {
texturesFreeTexture(i); texturesFreeTexture(i);
// free( state->textures[i] ); free( state->textures[i] );
} }
} }
for ( int i = 0; i < state->fontCount; ++i ) { for ( int i = 0; i < state->fontCount; ++i ) {
@@ -209,7 +208,6 @@ void stateFree() {
} }
} }
#endif #endif
if ( IsAudioDeviceReady() ) { if ( IsAudioDeviceReady() ) {
CloseAudioDevice(); CloseAudioDevice();
} }

View File

@@ -102,6 +102,7 @@ void texturesFreeTexture( size_t id ) {
state->textures[id] = NULL; state->textures[id] = NULL;
} }
} }
/* /*
## Textures - Image Loading ## Textures - Image Loading
*/ */
@@ -1329,7 +1330,6 @@ int ltexturesImageClearBackground( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
ImageClearBackground( state->images[ imageId ], color ); ImageClearBackground( state->images[ imageId ], color );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
@@ -1358,7 +1358,6 @@ int ltexturesImageDrawPixel( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
ImageDrawPixelV( state->images[ imageId ], position, color ); ImageDrawPixelV( state->images[ imageId ], position, color );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
@@ -1388,7 +1387,6 @@ int ltexturesImageDrawLine( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
ImageDrawLineV( state->images[ imageId ], start, end, color ); ImageDrawLineV( state->images[ imageId ], start, end, color );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
@@ -1418,7 +1416,6 @@ int ltexturesImageDrawCircle( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
ImageDrawCircleV( state->images[ imageId ], center, radius, color ); ImageDrawCircleV( state->images[ imageId ], center, radius, color );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
@@ -1448,7 +1445,6 @@ int ltexturesImageDrawCircleLines( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
ImageDrawCircleLinesV( state->images[ imageId ], center, radius, color ); ImageDrawCircleLinesV( state->images[ imageId ], center, radius, color );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
@@ -1477,7 +1473,6 @@ int ltexturesImageDrawRectangle( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
ImageDrawRectangleRec( state->images[ imageId ], rec, color ); ImageDrawRectangleRec( state->images[ imageId ], rec, color );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
@@ -1507,7 +1502,6 @@ int ltexturesImageDrawRectangleLines( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
ImageDrawRectangleLines( state->images[ imageId ], rec, thick, color ); ImageDrawRectangleLines( state->images[ imageId ], rec, thick, color );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
@@ -1530,7 +1524,7 @@ int ltexturesImageDraw( lua_State *L ) {
return 1; return 1;
} }
size_t imageDstId = lua_tointeger( L, 1 ); size_t imageDstId = lua_tointeger( L, 1 );
size_t imageSrcId = lua_tointeger( L, 2); size_t imageSrcId = lua_tointeger( L, 2 );
Rectangle srcRec = uluaGetRectangleIndex( L, 3 ); Rectangle srcRec = uluaGetRectangleIndex( L, 3 );
Rectangle dstRec = uluaGetRectangleIndex( L, 4 ); Rectangle dstRec = uluaGetRectangleIndex( L, 4 );
Color tint = uluaGetColorIndex( L, 5 ); Color tint = uluaGetColorIndex( L, 5 );
@@ -1539,7 +1533,6 @@ int ltexturesImageDraw( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
ImageDraw( state->images[ imageDstId ], *state->images[ imageSrcId ], srcRec, dstRec, tint ); ImageDraw( state->images[ imageDstId ], *state->images[ imageSrcId ], srcRec, dstRec, tint );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
@@ -1572,7 +1565,6 @@ int ltexturesImageDrawTextEx( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
ImageDrawTextEx( state->images[ imageId ], *state->fonts[ fontId ], lua_tostring( L, 3 ), position, fontSize, spacing, tint ); ImageDrawTextEx( state->images[ imageId ], *state->fonts[ fontId ], lua_tostring( L, 3 ), position, fontSize, spacing, tint );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
@@ -1603,7 +1595,6 @@ int ltexturesGetImageSize( lua_State *L ) {
lua_pushnil( L ); lua_pushnil( L );
return 1; return 1;
} }
Image *image = state->images[ imageId ]; Image *image = state->images[ imageId ];
uluaPushVector2( L, (Vector2){ image->width, image->height } ); uluaPushVector2( L, (Vector2){ image->width, image->height } );