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: GetFontTexture
- 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

View File

@@ -36,10 +36,16 @@ end
function RL.draw()
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
RL.CloseWindow()
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
windowOpen = false
end

View File

@@ -2,8 +2,6 @@
local monitor = 0
local texture = -1
local vaoId = -1
local vboId = -1
local triSize = 32.0
local vertices = {
0.0, 0.0, 0.0,
@@ -16,6 +14,39 @@ local colors = {
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()
local mPos = RL.GetMonitorPosition( monitor )
local mSize = RL.GetMonitorSize( monitor )
@@ -25,32 +56,25 @@ function RL.init()
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
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 )
-- 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 )
function drawMesh()
end
function RL.draw()
RL.ClearBackground( { 100, 150, 100 } )
end
-- You need to manually free resources.
function RL.exit()
if 0 <= vaoId then
RL.rlUnloadVertexArray( vaoId )
if 0 <= mesh.vaoId then
RL.rlUnloadVertexArray( mesh.vaoId )
end
for _, vboId in pairs( mesh.vboIds ) do
if 0 <= vboId then
RL.rlUnloadVertexBuffer( vboId )
end
end
end

View File

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

View File

@@ -46,9 +46,9 @@
#endif
#else
#ifdef SHARED
#include <lua/lua.h>
#include <lua/lualib.h>
#include <lua/lauxlib.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#else
#include "lua/lua.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 );
}
void defineGlobals() {
static void defineGlobals() {
lua_State *L = state->luaState;
lua_newtable( state->luaState );
lua_newtable( L );
lua_setglobal( L, "RL" );
lua_getglobal( L, "RL" );
@@ -637,7 +637,7 @@ void defineGlobals() {
}
// 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 msg[ STRING_LEN ] = {'\0'};
@@ -1993,61 +1993,47 @@ bool isValidTexture( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) {
int id = lua_tointeger( L, index );
if ( ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL ) ) {
if ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL ) {
return true;
}
else {
return false;
}
}
else if ( allowTable && lua_istable( L, index ) ) {
return true;
}
else {
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Texture." );
return false;
}
}
bool isValidRenderTexture( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) {
int id = lua_tointeger( L, index );
if ( ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL ) ) {
if ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL
&& state->textures[ id ]->type == TEXTURE_TYPE_RENDER_TEXTURE ) {
return true;
}
else {
return false;
}
}
else if ( allowTable && lua_istable( L, index ) ) {
return true;
}
else {
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid RenderTexture." );
return false;
}
}
bool isValidCamera2D( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) {
int id = lua_tointeger( L, index );
if ( ( 0 <= id && id < state->camera2DCount && state->camera2Ds[ id ] != NULL ) ) {
if ( 0 <= id && id < state->camera2DCount && state->camera2Ds[ id ] != NULL ) {
return true;
}
else {
return false;
}
}
else if ( allowTable && lua_istable( L, index ) ) {
return true;
}
else {
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera2D." );
return false;
}
}
bool isValidCamera3D( lua_State *L, int index, bool allowTable ) {
if ( lua_isnumber( L, index ) ) {
@@ -2056,18 +2042,13 @@ bool isValidCamera3D( lua_State *L, int index, bool allowTable ) {
if ( ( 0 <= id && id < state->camera3DCount && state->camera3Ds[ id ] != NULL ) ) {
return true;
}
else {
return false;
}
}
else if ( allowTable && lua_istable( L, index ) ) {
return true;
}
else {
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera3D." );
return false;
}
}
/* 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 }" );
return color;
}
// int t = lua_gettop( L ), i = 0;
int t = index, i = 0;
lua_pushnil( L );

View File

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

View File

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