Buffer userdata object and rlgl Vertex buffers management.

This commit is contained in:
jussi
2023-10-26 20:09:16 +03:00
parent 168f4959d4
commit 56c365c8cc
14 changed files with 1070 additions and 91 deletions

619
API.md

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,7 @@ Included submodules.
* Raymath * Raymath
* Lights * Lights
* Easings * Easings
* RLGL WIP
List of some MISSING features that are planned to be included. For specific function, check API. List of some MISSING features that are planned to be included. For specific function, check API.

View File

@@ -707,6 +707,13 @@ RL.GLFW_RELEASE=0
RL.GLFW_PRESS=1 RL.GLFW_PRESS=1
RL.GLFW_REPEAT=2 RL.GLFW_REPEAT=2
-- Globals - CBuffer
RL.BUFFER_UNSIGNED_CHAR=0
RL.BUFFER_UNSIGNED_SHORT=1
RL.BUFFER_UNSIGNED_INT=2
RL.BUFFER_FLOAT=3
-- Globals - Window -- Globals - Window
RL.EVENT_WINDOW_SIZE=0 RL.EVENT_WINDOW_SIZE=0
@@ -1907,6 +1914,14 @@ function RL.GetWorldToScreen2D( position, camera ) end
---@return any position ---@return any position
function RL.GetScreenToWorld2D( position, camera ) end function RL.GetScreenToWorld2D( position, camera ) end
---Creates buffer as userdata. Type should be one of the Buffer types
---- Failure return false
---- Success return Buffer
---@param buffer any
---@param type integer
---@return any buffer
function RL.LoadBuffer( buffer, type ) end
-- Shapes - Drawing -- Shapes - Drawing
---Set texture and rectangle to be used on shapes drawing ---Set texture and rectangle to be used on shapes drawing
@@ -6063,14 +6078,39 @@ function RL.rlSetTexture( id ) end
---@return any vaoId ---@return any vaoId
function RL.rlLoadVertexArray() end function RL.rlLoadVertexArray() end
---Load a vertex buffer attribute. Type should be RL_UNSIGNED_BYTE or RL_FLOAT ---Load a vertex buffer attribute
---- Failure return -1 ---- Failure return -1
---- Success return int ---- Success return int
---@param buffer any ---@param buffer any
---@param type integer
---@param dynamic boolean ---@param dynamic boolean
---@return any vboId ---@return any vboId
function RL.rlLoadVertexBuffer( buffer, type, dynamic ) end function RL.rlLoadVertexBuffer( buffer, dynamic ) end
---Load a new attributes element buffer
---- Failure return -1
---- Success return int
---@param buffer any
---@param dynamic boolean
---@return any vboId
function RL.rlLoadVertexBufferElement( buffer, dynamic ) end
---Update GPU buffer with new data
---- Failure return false
---- Success return true
---@param bufferId integer
---@param buffer any
---@param offset integer
---@return any success
function RL.rlUpdateVertexBuffer( bufferId, buffer, offset ) end
---Update vertex buffer elements with new data
---- Failure return false
---- Success return true
---@param id integer
---@param buffer any
---@param offset integer
---@return any success
function RL.rlUpdateVertexBufferElements( id, buffer, offset ) end
---Unload vertex array object (VAO) ---Unload vertex array object (VAO)
---- Failure return false ---- Failure return false
@@ -6098,6 +6138,23 @@ function RL.rlUnloadVertexBuffer( vboId ) end
---@return any success ---@return any success
function RL.rlSetVertexAttribute( index, compSize, type, normalized, stride, pointer ) end function RL.rlSetVertexAttribute( index, compSize, type, normalized, stride, pointer ) end
---Set vertex attribute divisor
---- Failure return false
---- Success return true
---@param index integer
---@param divisor integer
---@return any success
function RL.rlSetVertexAttributeDivisor( index, divisor ) end
---Set vertex attribute default value
---- Failure return false
---- Success return true
---@param locIndex integer
---@param value any
---@param attribType integer
---@return any success
function RL.rlSetVertexAttributeDefault( locIndex, value, attribType ) end
---Draw vertex array ---Draw vertex array
---- Failure return false ---- Failure return false
---- Success return true ---- Success return true
@@ -6106,6 +6163,34 @@ function RL.rlSetVertexAttribute( index, compSize, type, normalized, stride, poi
---@return any success ---@return any success
function RL.rlDrawVertexArray( offset, count ) end function RL.rlDrawVertexArray( offset, count ) end
---Draw vertex array elements
---- Failure return false
---- Success return true
---@param offset integer
---@param count integer
---@param buffer any
---@return any success
function RL.rlDrawVertexArrayElements( offset, count, buffer ) end
---Draw vertex array instanced
---- Failure return false
---- Success return true
---@param offset integer
---@param count integer
---@param instances integer
---@return any success
function RL.rlDrawVertexArrayInstanced( offset, count, instances ) end
---Draw vertex array elements instanced
---- Failure return false
---- Success return true
---@param offset integer
---@param count integer
---@param buffer any
---@param instances integer
---@return any success
function RL.rlDrawVertexArrayElementsInstanced( offset, count, buffer, instances ) end
-- RLGL - Textures management -- RLGL - Textures management
---Load texture in GPU ---Load texture in GPU

View File

@@ -35,6 +35,8 @@ KEY CHANGES:
- ADDED: RL.event function with input events. - ADDED: RL.event function with input events.
- ADDED: Window events. - ADDED: Window events.
- ADDED: rlgl Matrix state management. - ADDED: rlgl Matrix state management.
- ADDED: Buffer userdata object.
- ADDED: rlgl Vertex buffers management.
Detailed changes: Detailed changes:
- FIXED: uluaGetRay was looking for integers instead of tables - FIXED: uluaGetRay was looking for integers instead of tables

View File

@@ -1,6 +1,5 @@
Current { Current {
* rlgl * rlgl
* Vertex buffers management
* Shaders management * Shaders management
* Compute shader management * Compute shader management
} }
@@ -22,17 +21,20 @@ Backlog {
* Models * Models
* LoadMaterials (Load materials from model file) * LoadMaterials (Load materials from model file)
* LoadMaterialsFromModel (Could then for example edit and set back to model) * LoadMaterialsFromModel (Could then for example edit and set back to model)
* Needs Testing
* UpdateTexture
* UpdateTextureRec
* LoadSoundFromWave
* LoadFont
* LoadFontEx
* LoadFontFromImage
* UpdateMesh
* LoadModelFromMesh
} }
Bugs { Bugs {
* CameraLib. Lateral movement is slower if looking down or up. * CameraLib. Lateral movement is slower if looking down or up.
} }
Needs Testing {
* UpdateTexture
* UpdateTextureRec
* LoadSoundFromWave
* LoadFont
* LoadFontEx
* LoadFontFromImage
* UpdateMesh
* LoadModelFromMesh
* RLGL - Matrix state management
}

View File

@@ -155,18 +155,18 @@ repeat
globalVariableCount = globalVariableCount + 1 globalVariableCount = globalVariableCount + 1
if value == nil then if value == nil then
apiFile:write( "\n"..globalName.." = nil\n" ) apiFile:write( "\n"..globalName.." = nil\n\n" )
luaApiFile:write( "RL."..globalName.."=nil\n" ) luaApiFile:write( "RL."..globalName.."=nil\n" )
elseif type( value ) == "table" then elseif type( value ) == "table" then
-- All tables are colors. -- All tables are colors.
apiFile:write( globalName.." = { " apiFile:write( globalName.." = { "
..math.tointeger( value[1] )..", "..math.tointeger( value[2] )..", " ..math.tointeger( value[1] )..", "..math.tointeger( value[2] )..", "
..math.tointeger( value[3] )..", "..math.tointeger( value[4] ).." }\n" ) ..math.tointeger( value[3] )..", "..math.tointeger( value[4] ).." }\n\n" )
luaApiFile:write( "RL."..globalName.."={" luaApiFile:write( "RL."..globalName.."={"
..math.tointeger( value[1] )..","..math.tointeger( value[2] ).."," ..math.tointeger( value[1] )..","..math.tointeger( value[2] )..","
..math.tointeger( value[3] )..","..math.tointeger( value[4] ).."}\n" ) ..math.tointeger( value[3] )..","..math.tointeger( value[4] ).."}\n" )
else else
apiFile:write( globalName.." = "..value.."\n" ) apiFile:write( globalName.." = "..value.."\n\n" )
luaApiFile:write( "RL."..globalName.."="..value.."\n" ) luaApiFile:write( "RL."..globalName.."="..value.."\n" )
end end
end end
@@ -257,6 +257,8 @@ apiFile:write( "\n> NPatchInfo = { { 0, 0, 24, 24 }, 8, 8, 8, 8, NPATCH_NINE_PAT
{ Texture source rectangle, Left border offset, Top border offset, Right border offset, Bottom border offset, Layout of the n-patch: 3x3, 1x3 or 3x1 }\n\n---\n" ) { Texture source rectangle, Left border offset, Top border offset, Right border offset, Bottom border offset, Layout of the n-patch: 3x3, 1x3 or 3x1 }\n\n---\n" )
apiFile:write( "\n> ModelAnimations = ModelAnimationsId\n\ apiFile:write( "\n> ModelAnimations = ModelAnimationsId\n\
int id. ModelAnimations\n\n---\n" ) int id. ModelAnimations\n\n---\n" )
apiFile:write( "\n> Buffer = Buffer userdata\n\
Userdata.\n\n---\n" )
-- Events. -- Events.

View File

@@ -9,9 +9,9 @@ local vertices = {
triSize, 0.0, triSize triSize, 0.0, triSize
} }
local colors = { local colors = {
RL.RED, RL.RED, RL.RED, 255, 0, 0,
RL.GREEN, RL.GREEN, RL.GREEN, 0, 255, 0,
RL.BLUE, RL.BLUE, RL.BLUE 0, 0, 255
} }
local VBO_VERTEX_POS = 0 local VBO_VERTEX_POS = 0
@@ -25,23 +25,26 @@ local mesh = {
} }
} }
function uploadMesh() local function uploadMesh()
mesh.vaoId = RL.rlLoadVertexArray() mesh.vaoId = RL.rlLoadVertexArray()
RL.rlEnableVertexArray( mesh.vaoId ) RL.rlEnableVertexArray( mesh.vaoId )
-- Vertices. -- Vertices.
mesh.vboIds.vertices = RL.rlLoadVertexBuffer( vertices, RL.RL_FLOAT, false ) local vertexBuffer = RL.LoadBuffer( vertices, RL.BUFFER_FLOAT )
mesh.vboIds.vertices = RL.rlLoadVertexBuffer( vertexBuffer, false )
RL.rlSetVertexAttribute( VBO_VERTEX_POS, 3, RL.RL_FLOAT, false, 0, 0 ) RL.rlSetVertexAttribute( VBO_VERTEX_POS, 3, RL.RL_FLOAT, false, 0, 0 )
RL.rlEnableVertexAttribute( VBO_VERTEX_POS ) RL.rlEnableVertexAttribute( VBO_VERTEX_POS )
-- Colors. -- Colors.
mesh.vboIds.colors = RL.rlLoadVertexBuffer( vertices, RL.RL_UNSIGNED_BYTE, false ) local colorBuffer = RL.LoadBuffer( colors, RL.BUFFER_UNSIGNED_CHAR )
mesh.vboIds.colors = RL.rlLoadVertexBuffer( colorBuffer, false )
RL.rlSetVertexAttribute( VBO_COLOR_POS, 4, RL.RL_UNSIGNED_BYTE, false, 0, 0 ) RL.rlSetVertexAttribute( VBO_COLOR_POS, 4, RL.RL_UNSIGNED_BYTE, false, 0, 0 )
RL.rlEnableVertexAttribute( VBO_COLOR_POS ) RL.rlEnableVertexAttribute( VBO_COLOR_POS )
RL.rlDisableVertexArray() RL.rlDisableVertexArray()
print( "Mesh:" ) print( "\nMesh:" )
print( "\tvaoId: "..mesh.vaoId ) print( "\tvaoId: "..mesh.vaoId )
print( "\tvboIds.vertices: "..mesh.vboIds.vertices ) print( "\tvboIds.vertices: "..mesh.vboIds.vertices )
print( "\tvboIds.colors: "..mesh.vboIds.colors ) print( "\tvboIds.colors: "..mesh.vboIds.colors )
@@ -59,7 +62,7 @@ function RL.init()
uploadMesh() uploadMesh()
end end
function drawMesh() local function drawMesh()
end end
function RL.draw() function RL.draw()

View File

@@ -46,6 +46,7 @@ int lcoreSetTraceLogLevel( lua_State *L );
int lcoreSetLogLevelInvalid( lua_State *L ); int lcoreSetLogLevelInvalid( lua_State *L );
int lcoreGetLogLevelInvalid( lua_State *L ); int lcoreGetLogLevelInvalid( lua_State *L );
int lcoreOpenURL( lua_State *L ); int lcoreOpenURL( lua_State *L );
int lcoreLoadBuffer( lua_State *L );
/* Cursor. */ /* Cursor. */
int lcoreShowCursor( lua_State *L ); int lcoreShowCursor( lua_State *L );
int lcoreHideCursor( lua_State *L ); int lcoreHideCursor( lua_State *L );

View File

@@ -83,10 +83,18 @@ int lrlglSetTexture( lua_State *L );
/* Vertex buffers management */ /* Vertex buffers management */
int lrlglLoadVertexArray( lua_State *L ); int lrlglLoadVertexArray( lua_State *L );
int lrlglLoadVertexBuffer( lua_State *L ); int lrlglLoadVertexBuffer( lua_State *L );
int lrlglLoadVertexBufferElement( lua_State *L );
int lrlglUpdateVertexBuffer( lua_State *L );
int lrlglUpdateVertexBufferElements( lua_State *L );
int lrlglUnloadVertexArray( lua_State *L ); int lrlglUnloadVertexArray( lua_State *L );
int lrlglUnloadVertexBuffer( lua_State *L ); int lrlglUnloadVertexBuffer( lua_State *L );
int lrlglSetVertexAttribute( lua_State *L ); int lrlglSetVertexAttribute( lua_State *L );
int lrlglSetVertexAttributeDivisor( lua_State *L );
int lrlglSetVertexAttributeDefault( lua_State *L );
int lrlglDrawVertexArray( lua_State *L ); int lrlglDrawVertexArray( lua_State *L );
int lrlglDrawVertexArrayElements( lua_State *L );
int lrlglDrawVertexArrayInstanced( lua_State *L );
int lrlglDrawVertexArrayElementsInstanced( lua_State *L );
/* Textures management */ /* Textures management */
int lrlglLoadTexture( lua_State *L ); int lrlglLoadTexture( lua_State *L );
int lrlglLoadTextureDepth( lua_State *L ); int lrlglLoadTextureDepth( lua_State *L );

View File

@@ -14,6 +14,20 @@ enum EventType {
EVENT_CURSOR_ENTER EVENT_CURSOR_ENTER
}; };
enum BufferType {
BUFFER_UNSIGNED_CHAR,
BUFFER_UNSIGNED_SHORT,
BUFFER_UNSIGNED_INT,
BUFFER_FLOAT,
};
typedef struct {
size_t size;
void *data;
int x;
int y;
} Buffer;
bool luaInit( int argn, const char **argc ); bool luaInit( int argn, const char **argc );
int luaTraceback( lua_State *L ); int luaTraceback( lua_State *L );
bool luaCallMain(); bool luaCallMain();

View File

@@ -3558,3 +3558,77 @@ int lcoreGetScreenToWorld2D( lua_State *L ) {
return 1; return 1;
} }
/*
> buffer = RL.LoadBuffer( data{} buffer, int type )
Creates buffer as userdata. Type should be one of the Buffer types
- Failure return false
- Success return Buffer
*/
int lcoreLoadBuffer( lua_State *L ) {
if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadBuffer( data{} buffer, int type )" );
lua_pushboolean( L, false );
return 1;
}
int type = lua_tointeger( L, 2 );
Buffer *buffer = lua_newuserdata( L, sizeof( Buffer ) );
int len = uluaGetTableLenIndex( L, 1 );
switch ( type ) {
case BUFFER_UNSIGNED_CHAR:
buffer->size = len * sizeof( unsigned char );
break;
case BUFFER_UNSIGNED_SHORT:
buffer->size = len * sizeof( unsigned short );
break;
case BUFFER_UNSIGNED_INT:
buffer->size = len * sizeof( unsigned int );
break;
case BUFFER_FLOAT:
buffer->size = len * sizeof( float );
break;
default:
break;
}
buffer->data = malloc( buffer->size );
int t = 1;
int i = 0;
unsigned char *up = buffer->data;
unsigned short *sp = buffer->data;
unsigned int *ip = buffer->data;
float *fp = buffer->data;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
switch ( type ) {
case BUFFER_UNSIGNED_CHAR:
*up = (unsigned char)lua_tointeger( L, -1 );
up++;
break;
case BUFFER_UNSIGNED_SHORT:
*sp = (unsigned short)lua_tointeger( L, -1 );
up++;
break;
case BUFFER_UNSIGNED_INT:
*ip = (unsigned int)lua_tointeger( L, -1 );
up++;
break;
case BUFFER_FLOAT:
*fp = (float)lua_tonumber( L, -1 );
fp++;
break;
default:
break;
}
lua_pop( L, 1 );
i++;
}
luaL_setmetatable( L, "Buffer" );
return 1;
}

View File

@@ -58,4 +58,4 @@ int lglBlitFramebuffer( lua_State *L ) {
lua_pushboolean( L, true ); lua_pushboolean( L, true );
return 1; return 1;
} }

View File

@@ -618,6 +618,11 @@ static void defineGlobals() {
assignGlobalInt( GLFW_RELEASE, "GLFW_RELEASE" ); assignGlobalInt( GLFW_RELEASE, "GLFW_RELEASE" );
assignGlobalInt( GLFW_PRESS, "GLFW_PRESS" ); assignGlobalInt( GLFW_PRESS, "GLFW_PRESS" );
assignGlobalInt( GLFW_REPEAT, "GLFW_REPEAT" ); assignGlobalInt( GLFW_REPEAT, "GLFW_REPEAT" );
/* CBuffer Data Types */
assignGlobalInt( BUFFER_UNSIGNED_CHAR, "BUFFER_UNSIGNED_CHAR" );
assignGlobalInt( BUFFER_UNSIGNED_SHORT, "BUFFER_UNSIGNED_SHORT" );
assignGlobalInt( BUFFER_UNSIGNED_INT, "BUFFER_UNSIGNED_INT" );
assignGlobalInt( BUFFER_FLOAT, "BUFFER_FLOAT" );
/* Window Events. */ /* Window Events. */
assignGlobalInt( EVENT_WINDOW_SIZE, "EVENT_WINDOW_SIZE" ); assignGlobalInt( EVENT_WINDOW_SIZE, "EVENT_WINDOW_SIZE" );
assignGlobalInt( EVENT_WINDOW_MAXIMIZE, "EVENT_WINDOW_MAXIMIZE" ); assignGlobalInt( EVENT_WINDOW_MAXIMIZE, "EVENT_WINDOW_MAXIMIZE" );
@@ -636,6 +641,21 @@ static void defineGlobals() {
lua_pop( L, -1 ); lua_pop( L, -1 );
} }
static int freeBuffer( lua_State *L ) {
Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" );
free( buffer->data );
}
static void defineCBuffer() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "Buffer" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, freeBuffer );
lua_setfield( L, -2, "__gc" );
}
// Custom logging funtion. // Custom logging funtion.
static 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'};
@@ -1019,6 +1039,7 @@ bool luaInit( int argn, const char **argc ) {
return false; return false;
} }
defineGlobals(); defineGlobals();
defineCBuffer();
/* Set arguments. */ /* Set arguments. */
lua_getglobal( L, "RL" ); lua_getglobal( L, "RL" );
@@ -1235,6 +1256,7 @@ void luaRegister() {
assingGlobalFunction( "SetLogLevelInvalid", lcoreSetLogLevelInvalid ); assingGlobalFunction( "SetLogLevelInvalid", lcoreSetLogLevelInvalid );
assingGlobalFunction( "GetLogLevelInvalid", lcoreGetLogLevelInvalid ); assingGlobalFunction( "GetLogLevelInvalid", lcoreGetLogLevelInvalid );
assingGlobalFunction( "OpenURL", lcoreOpenURL ); assingGlobalFunction( "OpenURL", lcoreOpenURL );
assingGlobalFunction( "LoadBuffer", lcoreLoadBuffer );
/* Cursor. */ /* Cursor. */
assingGlobalFunction( "ShowCursor", lcoreShowCursor ); assingGlobalFunction( "ShowCursor", lcoreShowCursor );
assingGlobalFunction( "HideCursor", lcoreHideCursor ); assingGlobalFunction( "HideCursor", lcoreHideCursor );
@@ -1944,10 +1966,18 @@ void luaRegister() {
/* Vertex buffers management. */ /* Vertex buffers management. */
assingGlobalFunction( "rlLoadVertexArray", lrlglLoadVertexArray ); assingGlobalFunction( "rlLoadVertexArray", lrlglLoadVertexArray );
assingGlobalFunction( "rlLoadVertexBuffer", lrlglLoadVertexBuffer ); assingGlobalFunction( "rlLoadVertexBuffer", lrlglLoadVertexBuffer );
assingGlobalFunction( "rlLoadVertexBufferElement", lrlglLoadVertexBufferElement );
assingGlobalFunction( "rlUpdateVertexBuffer", lrlglUpdateVertexBuffer );
assingGlobalFunction( "rlUpdateVertexBufferElements", lrlglUpdateVertexBufferElements );
assingGlobalFunction( "rlUnloadVertexArray", lrlglUnloadVertexArray ); assingGlobalFunction( "rlUnloadVertexArray", lrlglUnloadVertexArray );
assingGlobalFunction( "rlUnloadVertexBuffer", lrlglUnloadVertexBuffer ); assingGlobalFunction( "rlUnloadVertexBuffer", lrlglUnloadVertexBuffer );
assingGlobalFunction( "rlSetVertexAttribute", lrlglSetVertexAttribute ); assingGlobalFunction( "rlSetVertexAttribute", lrlglSetVertexAttribute );
assingGlobalFunction( "rlSetVertexAttributeDivisor", lrlglSetVertexAttributeDivisor );
assingGlobalFunction( "rlSetVertexAttributeDefault", lrlglSetVertexAttributeDefault );
assingGlobalFunction( "rlDrawVertexArray", lrlglDrawVertexArray ); assingGlobalFunction( "rlDrawVertexArray", lrlglDrawVertexArray );
assingGlobalFunction( "rlDrawVertexArrayElements", lrlglDrawVertexArrayElements );
assingGlobalFunction( "rlDrawVertexArrayInstanced", lrlglDrawVertexArrayInstanced );
assingGlobalFunction( "rlDrawVertexArrayElementsInstanced", lrlglDrawVertexArrayElementsInstanced );
/* Textures management. */ /* Textures management. */
assingGlobalFunction( "rlLoadTexture", lrlglLoadTexture ); assingGlobalFunction( "rlLoadTexture", lrlglLoadTexture );
assingGlobalFunction( "rlLoadTextureDepth", lrlglLoadTextureDepth ); assingGlobalFunction( "rlLoadTextureDepth", lrlglLoadTextureDepth );

View File

@@ -3,58 +3,6 @@
#include "lua_core.h" #include "lua_core.h"
#include "lrlgl.h" #include "lrlgl.h"
static void* getVertexBuffer( lua_State *L, int *type, unsigned int *size ) {
*type = lua_tointeger( L, 2 );
size_t len = uluaGetTableLenIndex( L, 1 );
unsigned char *uByteArray;
float *floatArray;
switch ( *type ) {
case RL_UNSIGNED_BYTE:
*size = len * sizeof( unsigned char );
uByteArray = MemAlloc( *size );
break;
case RL_FLOAT:
*size = len * sizeof( float );
floatArray = MemAlloc( *size );
break;
default:
break;
}
int t = 1;
int i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
switch ( *type ) {
case RL_UNSIGNED_BYTE:
uByteArray[i] = lua_tointeger( L, -1 );
break;
case RL_FLOAT:
floatArray[i] = lua_tointeger( L, -1 );
break;
default:
break;
}
lua_pop( L, 1 );
i++;
}
switch ( *type ) {
case RL_UNSIGNED_BYTE:
return uByteArray;
break;
case RL_FLOAT:
return floatArray;
break;
default:
return NULL;
break;
}
}
/* /*
## RLGL - Matrix operations ## RLGL - Matrix operations
*/ */
@@ -1308,29 +1256,93 @@ int lrlglLoadVertexArray( lua_State *L ) {
} }
/* /*
> vboId = RL.rlLoadVertexBuffer( Buffer{} buffer, int type, bool dynamic ) > vboId = RL.rlLoadVertexBuffer( Buffer buffer, bool dynamic )
Load a vertex buffer attribute. Type should be RL_UNSIGNED_BYTE or RL_FLOAT Load a vertex buffer attribute
- Failure return -1 - Failure return -1
- Success return int - Success return int
*/ */
int lrlglLoadVertexBuffer( lua_State *L ) { int lrlglLoadVertexBuffer( lua_State *L ) {
if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) { if ( !lua_isuserdata( L, 1 ) || !lua_isboolean( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadVertexBuffer( Buffer{} buffer, int type, bool dynamic )" ); TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadVertexBuffer( Buffer buffer, bool dynamic )" );
lua_pushinteger( L, -1 ); lua_pushinteger( L, -1 );
return 1; return 1;
} }
unsigned int size = 0; Buffer *buffer = luaL_checkudata( L, 1, "Buffer" );
int type = 0; bool dynamic = lua_tointeger( L, 2 );
void *vertexBuffer = getVertexBuffer( L, &type, &size );
bool dynamic = lua_tointeger( L, 3 );
lua_pushinteger( L, rlLoadVertexBuffer( vertexBuffer, size, dynamic ) ); lua_pushinteger( L, rlLoadVertexBuffer( buffer->data, buffer->size, dynamic ) );
if ( vertexBuffer != NULL ) { return 1;
MemFree( vertexBuffer ); }
/*
> vboId = RL.rlLoadVertexBufferElement( Buffer buffer, bool dynamic )
Load a new attributes element buffer
- Failure return -1
- Success return int
*/
int lrlglLoadVertexBufferElement( lua_State *L ) {
if ( !lua_isuserdata( L, 1 ) || !lua_isboolean( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadVertexBufferElement( Buffer buffer, bool dynamic )" );
lua_pushinteger( L, -1 );
return 1;
} }
Buffer *buffer = luaL_checkudata( L, 1, "Buffer" );
bool dynamic = lua_tointeger( L, 2 );
lua_pushinteger( L, rlLoadVertexBufferElement( buffer->data, buffer->size, dynamic ) );
return 1;
}
/*
> success = RL.rlUpdateVertexBuffer( int bufferId, Buffer buffer, int offset )
Update GPU buffer with new data
- Failure return false
- Success return true
*/
int lrlglUpdateVertexBuffer( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isuserdata( L, 2 ) || !lua_isnumber( L, 3 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUpdateVertexBuffer( int bufferId, Buffer buffer, int offset )" );
lua_pushboolean( L, false );
return 1;
}
int bufferId = lua_tointeger( L, 1 );
Buffer *buffer = luaL_checkudata( L, 2, "Buffer" );
int offset = lua_tointeger( L, 3 );
rlUpdateVertexBuffer( bufferId, buffer->data, buffer->size, offset );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlUpdateVertexBufferElements( int id, Buffer buffer, int offset )
Update vertex buffer elements with new data
- Failure return false
- Success return true
*/
int lrlglUpdateVertexBufferElements( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isuserdata( L, 2 ) || !lua_isnumber( L, 3 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUpdateVertexBufferElements( int id, Buffer buffer, int offset )" );
lua_pushboolean( L, false );
return 1;
}
int bufferId = lua_tointeger( L, 1 );
Buffer *buffer = luaL_checkudata( L, 2, "Buffer" );
int offset = lua_tointeger( L, 3 );
rlUpdateVertexBufferElements( bufferId, buffer->data, buffer->size, offset );
lua_pushboolean( L, true );
return 1; return 1;
} }
@@ -1403,6 +1415,63 @@ int lrlglSetVertexAttribute( lua_State *L ) {
return 1; return 1;
} }
/*
> success = RL.rlSetVertexAttributeDivisor( int index, int divisor )
Set vertex attribute divisor
- Failure return false
- Success return true
*/
int lrlglSetVertexAttributeDivisor( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetVertexAttributeDivisor( int index, int divisor )" );
lua_pushboolean( L, false );
return 1;
}
unsigned int index = (unsigned int)lua_tointeger( L, 1 );
int divisor = lua_tointeger( L, 2 );
rlSetVertexAttributeDivisor( index, divisor );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlSetVertexAttributeDefault( int locIndex, float{} value, int attribType )
Set vertex attribute default value
- Failure return false
- Success return true
*/
int lrlglSetVertexAttributeDefault( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetVertexAttributeDefault( int locIndex, float{} value, int attribType )" );
lua_pushboolean( L, false );
return 1;
}
int locIndex = lua_tointeger( L, 1 );
int attribType = lua_tointeger( L, 3 );
int count = uluaGetTableLenIndex( L, 2 );
float value[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
int t = 2;
int i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
value[i] = lua_tonumber( L, -1 );
lua_pop( L, 1 );
i++;
}
rlSetVertexAttributeDefault( locIndex, value, attribType, count );
lua_pushboolean( L, true );
return 1;
}
/* /*
> success = RL.rlDrawVertexArray( int offset, int count ) > success = RL.rlDrawVertexArray( int offset, int count )
@@ -1426,6 +1495,79 @@ int lrlglDrawVertexArray( lua_State *L ) {
return 1; return 1;
} }
/*
> success = RL.rlDrawVertexArrayElements( int offset, int count, Buffer buffer )
Draw vertex array elements
- Failure return false
- Success return true
*/
int lrlglDrawVertexArrayElements( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isuserdata( L, 3 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArrayElements( int offset, int count, Buffer buffer )" );
lua_pushboolean( L, false );
return 1;
}
int offset = lua_tointeger( L, 1 );
int count = lua_tointeger( L, 2 );
Buffer *buffer = luaL_checkudata( L, 3, "Buffer" );
rlDrawVertexArrayElements( offset, count, buffer->data );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlDrawVertexArrayInstanced( int offset, int count, int instances )
Draw vertex array instanced
- Failure return false
- Success return true
*/
int lrlglDrawVertexArrayInstanced( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArrayInstanced( int offset, int count, int instances )" );
lua_pushboolean( L, false );
return 1;
}
int offset = lua_tointeger( L, 1 );
int count = lua_tointeger( L, 2 );
int instances = lua_tointeger( L, 3 );
rlDrawVertexArrayInstanced( offset, count, instances );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlDrawVertexArrayElementsInstanced( int offset, int count, Buffer buffer, int instances )
Draw vertex array elements instanced
- Failure return false
- Success return true
*/
int lrlglDrawVertexArrayElementsInstanced( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isuserdata( L, 3 ) || !lua_isnumber( L, 4 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArrayElementsInstanced( int offset, int count, Buffer buffer, int instances )" );
lua_pushboolean( L, false );
return 1;
}
int offset = lua_tointeger( L, 1 );
int count = lua_tointeger( L, 2 );
Buffer *buffer = luaL_checkudata( L, 3, "Buffer" );
int instances = lua_tointeger( L, 4 );
rlDrawVertexArrayElementsInstanced( offset, count, buffer->data, instances );
lua_pushboolean( L, true );
return 1;
}
/* /*
## RLGL - Textures management ## RLGL - Textures management
*/ */