Vertex buffers state and Shader state functions. Vertex buffers management WIP.

This commit is contained in:
jussi
2023-08-17 18:33:50 +03:00
parent 5438a70b0a
commit b7b46ada04
14 changed files with 830 additions and 16 deletions

161
API.md
View File

@@ -3482,6 +3482,15 @@ Premultiply alpha channel
---
> success = RL.ImageBlurGaussian( Image image, int blurSize )
Apply Gaussian blur using a box blur approximation
- Failure return false
- Success return true
---
> success = RL.ImageResize( Image image, Vector2 size )
Resize image ( Bicubic scaling algorithm )
@@ -3693,6 +3702,15 @@ Draw circle within an image
---
> success = RL.ImageDrawCircleLines( Image dst, Vector2 center, int radius, Color color )
Draw circle outline within an image
- Failure return false
- Success return true
---
> success = RL.ImageDrawRectangle( Image dst, Rectangle rec, Color color )
Draw rectangle within an image
@@ -7027,6 +7045,73 @@ Define one vertex ( color ) - 4 float
---
## RLGL - Vertex buffers state
---
> supported = RL.rlEnableVertexArray( int vaoId )
Enable vertex array ( VAO, if supported )
- Failure return nil
- Success return bool
---
> RL.rlDisableVertexArray()
Disable vertex array ( VAO, if supported )
---
> success = RL.rlEnableVertexBuffer( int id )
Enable vertex buffer ( VBO )
- Failure return false
- Success return true
---
> RL.rlDisableVertexBuffer()
Disable vertex buffer ( VBO )
---
> success = RL.rlEnableVertexBufferElement( int id )
Enable vertex buffer element ( VBO element )
- Failure return false
- Success return true
---
> RL.rlDisableVertexBufferElement()
Disable vertex buffer element ( VBO element )
---
> success = RL.rlEnableVertexAttribute( int index )
Enable vertex attribute index
- Failure return false
- Success return true
---
> success = RL.rlDisableVertexAttribute( int index )
Disable vertex attribute index
- Failure return false
- Success return true
---
## RLGL - Textures state
---
@@ -7088,6 +7173,25 @@ Set cubemap parameters ( filter, wrap )
---
## RLGL - Shader state
---
> success = RL.rlEnableShader( int id )
Enable shader program
- Failure return false
- Success return true
---
> RL.rlDisableShader()
Disable shader program
---
## RLGL - Framebuffer state
---
@@ -7347,6 +7451,63 @@ Set current texture for render batch and check buffers limits
---
## RLGL - Vertex buffers management
---
> vaoId = RL.rlLoadVertexArray()
Load vertex array (vao) if supported
- Success return int
---
> vboId = RL.rlLoadVertexBuffer( Buffer{} buffer, int type, bool dynamic )
Load a vertex buffer attribute. Type should be RL_UNSIGNED_BYTE or RL_FLOAT
- Failure return -1
- Success return int
---
> success = RL.rlUnloadVertexArray( int vaoId )
Unload vertex array object (VAO)
- Failure return false
- Success return true
---
> success = RL.rlUnloadVertexBuffer( int vboId )
Unload vertex buffer (VBO)
- Failure return false
- Success return true
---
> success = RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer )
Set vertex attribute
- Failure return false
- Success return true
---
> success = RL.rlDrawVertexArray( int offset, int count )
Draw vertex array
- Failure return false
- Success return true
---
## RLGL - Textures management
---

View File

@@ -560,8 +560,8 @@ RL.RL_MAX_SHADER_LOCATIONS=32
-- Globals - RLGL
RL.RL_CULL_DISTANCE_NEAR=0
RL.RL_CULL_DISTANCE_FAR=1000
RL.RL_CULL_DISTANCE_NEAR=0.01
RL.RL_CULL_DISTANCE_FAR=1000.0
-- Globals - RLGL
@@ -2506,6 +2506,14 @@ function RL.ImageAlphaMask( image, alphaMask ) end
---@return any success
function RL.ImageAlphaPremultiply( image ) end
---Apply Gaussian blur using a box blur approximation
---- Failure return false
---- Success return true
---@param image any
---@param blurSize integer
---@return any success
function RL.ImageBlurGaussian( image, blurSize ) end
---Resize image ( Bicubic scaling algorithm )
---- Failure return false
---- Success return true
@@ -2692,6 +2700,16 @@ function RL.ImageDrawLine( dst, start, end, color ) end
---@return any success
function RL.ImageDrawCircle( dst, center, radius, color ) end
---Draw circle outline within an image
---- Failure return false
---- Success return true
---@param dst any
---@param center table
---@param radius integer
---@param color table
---@return any success
function RL.ImageDrawCircleLines( dst, center, radius, color ) end
---Draw rectangle within an image
---- Failure return false
---- Success return true
@@ -5705,6 +5723,55 @@ function RL.rlColor3f( color ) end
---@return any success
function RL.rlColor4f( color ) end
-- RLGL - Vertex buffers state
---Enable vertex array ( VAO, if supported )
---- Failure return nil
---- Success return bool
---@param vaoId integer
---@return any supported
function RL.rlEnableVertexArray( vaoId ) end
---Disable vertex array ( VAO, if supported )
---@return any RL.rlDisableVertexArray
function RL.rlDisableVertexArray() end
---Enable vertex buffer ( VBO )
---- Failure return false
---- Success return true
---@param id integer
---@return any success
function RL.rlEnableVertexBuffer( id ) end
---Disable vertex buffer ( VBO )
---@return any RL.rlDisableVertexBuffer
function RL.rlDisableVertexBuffer() end
---Enable vertex buffer element ( VBO element )
---- Failure return false
---- Success return true
---@param id integer
---@return any success
function RL.rlEnableVertexBufferElement( id ) end
---Disable vertex buffer element ( VBO element )
---@return any RL.rlDisableVertexBufferElement
function RL.rlDisableVertexBufferElement() end
---Enable vertex attribute index
---- Failure return false
---- Success return true
---@param index integer
---@return any success
function RL.rlEnableVertexAttribute( index ) end
---Disable vertex attribute index
---- Failure return false
---- Success return true
---@param index integer
---@return any success
function RL.rlDisableVertexAttribute( index ) end
-- RLGL - Textures state
---Select and active a texture slot
@@ -5754,6 +5821,19 @@ function RL.rlTextureParameters( id, param, value ) end
---@return any success
function RL.rlCubemapParameters( id, param, value ) end
-- RLGL - Shader state
---Enable shader program
---- Failure return false
---- Success return true
---@param id integer
---@return any success
function RL.rlEnableShader( id ) end
---Disable shader program
---@return any RL.rlDisableShader
function RL.rlDisableShader() end
-- RLGL - Framebuffer state
---Enable render texture (fbo)
@@ -5941,6 +6021,56 @@ function RL.rlCheckRenderBatchLimit( vCount ) end
---@return any success
function RL.rlSetTexture( id ) end
-- RLGL - Vertex buffers management
---Load vertex array (vao) if supported
---- Success return int
---@return any vaoId
function RL.rlLoadVertexArray() end
---Load a vertex buffer attribute. Type should be RL_UNSIGNED_BYTE or RL_FLOAT
---- Failure return -1
---- Success return int
---@param buffer any
---@param type integer
---@param dynamic boolean
---@return any vboId
function RL.rlLoadVertexBuffer( buffer, type, dynamic ) end
---Unload vertex array object (VAO)
---- Failure return false
---- Success return true
---@param vaoId integer
---@return any success
function RL.rlUnloadVertexArray( vaoId ) end
---Unload vertex buffer (VBO)
---- Failure return false
---- Success return true
---@param vboId integer
---@return any success
function RL.rlUnloadVertexBuffer( vboId ) end
---Set vertex attribute
---- Failure return false
---- Success return true
---@param index integer
---@param compSize integer
---@param type integer
---@param normalized boolean
---@param stride integer
---@param pointer integer
---@return any success
function RL.rlSetVertexAttribute( index, compSize, type, normalized, stride, pointer ) end
---Draw vertex array
---- Failure return false
---- Success return true
---@param offset integer
---@param count integer
---@return any success
function RL.rlDrawVertexArray( offset, count ) end
-- RLGL - Textures management
---Load texture in GPU

View File

@@ -30,6 +30,8 @@ KEY CHANGES:
- ADDED: LuaJIT compatibility.
- CHANGED Bitwise operators moved from utillib to bitlib for better luaJIT support.
- ADDED: logLevelInvalid for bad function calls and invalid data formats.
- ADDED: rlgl Vertex buffers state.
- ADDED: rlgl Shader state.
Detailed changes:
- FIXED: uluaGetRay was looking for integers instead of tables
@@ -91,6 +93,8 @@ Detailed changes:
- ADDED: GetMaterialTexture, GetMaterialColor, GetMaterialValue and GetMaterialShader
- ADDED: SetMaterialParams and GetMaterialParams
- ADDED: GetTextureId
- ADDED: ImageDrawCircleLines
- ADDED: ImageBlurGaussian
------------------------------------------------------------------------
Release: ReiLua version 0.4.0 Using Raylib 4.2

View File

@@ -1,9 +1,8 @@
Current {
* rlgl
* Vertex buffers state.
* Vertex buffers management
* Shaders management
* Matrix state management
* Shaders management
* Compute shader management
}
@@ -21,9 +20,6 @@ Backlog {
* Core.
* Compression/Encoding functionality.
* SetWindowIcons.
* Textures
* ImageDrawCircleLines
* ImageBlurGaussian
* Models
* LoadMaterials (Load materials from model file)
* LoadMaterialsFromModel (Could then for example edit and set back to model)

View File

@@ -36,15 +36,15 @@ function RL.process( delta )
cameraPos[2] = cameraPos[2] - cameraSpeed * delta
end
-- Rotate.
if RL.IsKeyDown( string.byte( "E" ) ) then -- Or RL.IsKeyDown( KEY_E )
if RL.IsKeyDown( RL.KEY_E ) then -- Or RL.IsKeyDown( KEY_E )
cameraRot = cameraRot + cameraRotSpeed * delta
elseif RL.IsKeyDown( string.byte( "Q" ) ) then
elseif RL.IsKeyDown( RL.KEY_Q ) then
cameraRot = cameraRot - cameraRotSpeed * delta
end
-- Zoom.
if RL.IsKeyDown( string.byte( "R" ) ) then
if RL.IsKeyDown( RL.KEY_R ) then
cameraZoom = cameraZoom + cameraZoomSpeed * delta
elseif RL.IsKeyDown( string.byte( "F" ) ) then
elseif RL.IsKeyDown( RL.KEY_F ) then
cameraZoom = cameraZoom - cameraZoomSpeed * delta
end
end
@@ -62,6 +62,7 @@ function RL.draw()
RL.DrawTextureRec( tileTexture, { 0, 0, 32, 32 }, { x * 32, y * 32 }, RL.WHITE )
end
end
-- Draw hero.
RL.DrawTextureRec( tileTexture, { 3 * 32, 0, 32, 32 }, { cameraPos[1] - 16, cameraPos[2] - 16 }, RL.WHITE )
RL.EndMode2D()

56
examples/rlgl/main.lua Normal file
View File

@@ -0,0 +1,56 @@
-- Work In Progress!
local monitor = 0
local texture = -1
local vaoId = -1
local vboId = -1
local triSize = 32.0
local vertices = {
0.0, 0.0, 0.0,
0.0, 0.0, triSize,
triSize, 0.0, triSize
}
local colors = {
RL.RED, RL.RED, RL.RED,
RL.GREEN, RL.GREEN, RL.GREEN,
RL.BLUE, RL.BLUE, RL.BLUE
}
function RL.init()
local mPos = RL.GetMonitorPosition( monitor )
local mSize = RL.GetMonitorSize( monitor )
local winSize = RL.GetScreenSize()
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
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()
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 )
end
function RL.draw()
RL.ClearBackground( { 100, 150, 100 } )
end
function RL.exit()
if 0 <= vaoId then
RL.rlUnloadVertexArray( vaoId )
end
if 0 <= vboId then
RL.rlUnloadVertexBuffer( vboId )
end
end

View File

@@ -22,6 +22,15 @@ int lrlglNormal3f( lua_State *L );
int lrlglColor4ub( lua_State *L );
int lrlglColor3f( lua_State *L );
int lrlglColor4f( lua_State *L );
/* Vertex buffers state */
int lrlglEnableVertexArray( lua_State *L );
int lrlglDisableVertexArray( lua_State *L );
int lrlglEnableVertexBuffer( lua_State *L );
int lrlglDisableVertexBuffer( lua_State *L );
int lrlglEnableVertexBufferElement( lua_State *L );
int lrlglDisableVertexBufferElement( lua_State *L );
int lrlglEnableVertexAttribute( lua_State *L );
int lrlglDisableVertexAttribute( lua_State *L );
/* Textures state */
int lrlglActiveTextureSlot( lua_State *L );
int lrlglEnableTexture( lua_State *L );
@@ -30,6 +39,9 @@ int lrlglEnableTextureCubemap( lua_State *L );
int lrlglDisableTextureCubemap( lua_State *L );
int lrlglTextureParameters( lua_State *L );
int lrlglCubemapParameters( lua_State *L );
/* Shader state. */
int lrlglEnableShader( lua_State *L );
int lrlglDisableShader( lua_State *L );
/* Framebuffer state. */
int lrlglEnableFramebuffer( lua_State *L );
int lrlglDisableFramebuffer( lua_State *L );
@@ -68,6 +80,13 @@ int lrlglGetVersion( lua_State *L );
int lrlglDrawRenderBatchActive( lua_State *L );
int lrlglCheckRenderBatchLimit( lua_State *L );
int lrlglSetTexture( lua_State *L );
/* Vertex buffers management */
int lrlglLoadVertexArray( lua_State *L );
int lrlglLoadVertexBuffer( lua_State *L );
int lrlglUnloadVertexArray( lua_State *L );
int lrlglUnloadVertexBuffer( lua_State *L );
int lrlglSetVertexAttribute( lua_State *L );
int lrlglDrawVertexArray( lua_State *L );
/* Textures management */
int lrlglLoadTexture( lua_State *L );
int lrlglLoadTextureDepth( lua_State *L );

View File

@@ -84,5 +84,5 @@ typedef struct {
extern State *state;
bool stateInit( const char *exePath );
bool stateInitInterpret();
void stateInitInterpret();
void stateFree();

View File

@@ -37,6 +37,7 @@ int ltexturesImageAlphaCrop( lua_State *L );
int ltexturesImageAlphaClear( lua_State *L );
int ltexturesImageAlphaMask( lua_State *L );
int ltexturesImageAlphaPremultiply( lua_State *L );
int ltexturesImageBlurGaussian( lua_State *L );
int ltexturesImageResize( lua_State *L );
int ltexturesImageResizeNN( lua_State *L );
int ltexturesImageResizeCanvas( lua_State *L );
@@ -61,6 +62,7 @@ int ltexturesImageClearBackground( lua_State *L );
int ltexturesImageDrawPixel( lua_State *L );
int ltexturesImageDrawLine( lua_State *L );
int ltexturesImageDrawCircle( lua_State *L );
int ltexturesImageDrawCircleLines( lua_State *L );
int ltexturesImageDrawRectangle( lua_State *L );
int ltexturesImageDrawRectangleLines( lua_State *L );
int ltexturesImageDraw( lua_State *L );

View File

@@ -26,6 +26,12 @@ static void assignGlobalFloat( float value, const char *name ) {
lua_setfield( L, -2, name );
}
static void assignGlobalDouble( double value, const char *name ) {
lua_State *L = state->luaState;
lua_pushnumber( L, value );
lua_setfield( L, -2, name );
}
static void assignGlobalColor( Color color, const char *name ) {
lua_State *L = state->luaState;
uluaPushColor( L, color );
@@ -499,8 +505,8 @@ void defineGlobals() {
/* RLGL Shader limits */
assignGlobalInt( RL_MAX_SHADER_LOCATIONS, "RL_MAX_SHADER_LOCATIONS" );
/* RLGL Projection matrix culling */
assignGlobalInt( RL_CULL_DISTANCE_NEAR, "RL_CULL_DISTANCE_NEAR" );
assignGlobalInt( RL_CULL_DISTANCE_FAR, "RL_CULL_DISTANCE_FAR" );
assignGlobalDouble( RL_CULL_DISTANCE_NEAR, "RL_CULL_DISTANCE_NEAR" );
assignGlobalDouble( RL_CULL_DISTANCE_FAR, "RL_CULL_DISTANCE_FAR" );
/* RLGL Texture parameters */
assignGlobalInt( RL_TEXTURE_WRAP_S, "RL_TEXTURE_WRAP_S" );
assignGlobalInt( RL_TEXTURE_WRAP_T, "RL_TEXTURE_WRAP_T" );
@@ -1069,6 +1075,7 @@ void luaRegister() {
assingGlobalFunction( "ImageAlphaClear", ltexturesImageAlphaClear );
assingGlobalFunction( "ImageAlphaMask", ltexturesImageAlphaMask );
assingGlobalFunction( "ImageAlphaPremultiply", ltexturesImageAlphaPremultiply );
assingGlobalFunction( "ImageBlurGaussian", ltexturesImageBlurGaussian );
assingGlobalFunction( "ImageResize", ltexturesImageResize );
assingGlobalFunction( "ImageResizeNN", ltexturesImageResizeNN );
assingGlobalFunction( "ImageResizeCanvas", ltexturesImageResizeCanvas );
@@ -1093,6 +1100,7 @@ void luaRegister() {
assingGlobalFunction( "ImageDrawPixel", ltexturesImageDrawPixel );
assingGlobalFunction( "ImageDrawLine", ltexturesImageDrawLine );
assingGlobalFunction( "ImageDrawCircle", ltexturesImageDrawCircle );
assingGlobalFunction( "ImageDrawCircleLines", ltexturesImageDrawCircleLines );
assingGlobalFunction( "ImageDrawRectangle", ltexturesImageDrawRectangle );
assingGlobalFunction( "ImageDrawRectangleLines", ltexturesImageDrawRectangleLines );
assingGlobalFunction( "ImageDraw", ltexturesImageDraw );
@@ -1497,6 +1505,15 @@ void luaRegister() {
assingGlobalFunction( "rlColor4ub", lrlglColor4ub );
assingGlobalFunction( "rlColor3f", lrlglColor3f );
assingGlobalFunction( "rlColor4f", lrlglColor4f );
/* Vertex buffers state. */
assingGlobalFunction( "rlEnableVertexArray", lrlglEnableVertexArray );
assingGlobalFunction( "rlDisableVertexArray", lrlglDisableVertexArray );
assingGlobalFunction( "rlEnableVertexBuffer", lrlglEnableVertexBuffer );
assingGlobalFunction( "rlDisableVertexBuffer", lrlglDisableVertexBuffer );
assingGlobalFunction( "rlEnableVertexBufferElement", lrlglEnableVertexBufferElement );
assingGlobalFunction( "rlDisableVertexBufferElement", lrlglDisableVertexBufferElement );
assingGlobalFunction( "rlEnableVertexAttribute", lrlglEnableVertexAttribute );
assingGlobalFunction( "rlDisableVertexAttribute", lrlglDisableVertexAttribute );
/* Textures state. */
assingGlobalFunction( "rlActiveTextureSlot", lrlglActiveTextureSlot );
assingGlobalFunction( "rlEnableTexture", lrlglEnableTexture );
@@ -1505,6 +1522,9 @@ void luaRegister() {
assingGlobalFunction( "rlDisableTextureCubemap", lrlglDisableTextureCubemap );
assingGlobalFunction( "rlTextureParameters", lrlglTextureParameters );
assingGlobalFunction( "rlCubemapParameters", lrlglCubemapParameters );
/* Shader state. */
assingGlobalFunction( "rlEnableShader", lrlglEnableShader );
assingGlobalFunction( "rlDisableShader", lrlglDisableShader );
/* Framebuffer state. */
assingGlobalFunction( "rlEnableFramebuffer", lrlglEnableFramebuffer );
assingGlobalFunction( "rlDisableFramebuffer", lrlglDisableFramebuffer );
@@ -1543,6 +1563,13 @@ void luaRegister() {
assingGlobalFunction( "rlDrawRenderBatchActive", lrlglDrawRenderBatchActive );
assingGlobalFunction( "rlCheckRenderBatchLimit", lrlglCheckRenderBatchLimit );
assingGlobalFunction( "rlSetTexture", lrlglSetTexture );
/* Vertex buffers management. */
assingGlobalFunction( "rlLoadVertexArray", lrlglLoadVertexArray );
assingGlobalFunction( "rlLoadVertexBuffer", lrlglLoadVertexBuffer );
assingGlobalFunction( "rlUnloadVertexArray", lrlglUnloadVertexArray );
assingGlobalFunction( "rlUnloadVertexBuffer", lrlglUnloadVertexBuffer );
assingGlobalFunction( "rlSetVertexAttribute", lrlglSetVertexAttribute );
assingGlobalFunction( "rlDrawVertexArray", lrlglDrawVertexArray );
/* Textures management. */
assingGlobalFunction( "rlLoadTexture", lrlglLoadTexture );
assingGlobalFunction( "rlLoadTextureDepth", lrlglLoadTextureDepth );

View File

@@ -3,6 +3,58 @@
#include "lua_core.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
*/
@@ -422,6 +474,142 @@ int lrlglColor4f( lua_State *L ) {
return 1;
}
/*
## RLGL - Vertex buffers state
*/
/*
> supported = RL.rlEnableVertexArray( int vaoId )
Enable vertex array ( VAO, if supported )
- Failure return nil
- Success return bool
*/
int lrlglEnableVertexArray( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexArray( int vaoId )" );
lua_pushnil( L );
return 1;
}
lua_pushboolean( L, rlEnableVertexArray( lua_tointeger( L, 1 ) ) );
return 1;
}
/*
> RL.rlDisableVertexArray()
Disable vertex array ( VAO, if supported )
*/
int lrlglDisableVertexArray( lua_State *L ) {
rlDisableVertexArray();
return 0;
}
/*
> success = RL.rlEnableVertexBuffer( int id )
Enable vertex buffer ( VBO )
- Failure return false
- Success return true
*/
int lrlglEnableVertexBuffer( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexBuffer( int id )" );
lua_pushboolean( L, false );
return 1;
}
rlEnableVertexBuffer( lua_tointeger( L, 1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> RL.rlDisableVertexBuffer()
Disable vertex buffer ( VBO )
*/
int lrlglDisableVertexBuffer( lua_State *L ) {
rlDisableVertexBuffer();
return 0;
}
/*
> success = RL.rlEnableVertexBufferElement( int id )
Enable vertex buffer element ( VBO element )
- Failure return false
- Success return true
*/
int lrlglEnableVertexBufferElement( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexBufferElement( int id )" );
lua_pushboolean( L, false );
return 1;
}
rlEnableVertexBufferElement( lua_tointeger( L, 1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> RL.rlDisableVertexBufferElement()
Disable vertex buffer element ( VBO element )
*/
int lrlglDisableVertexBufferElement( lua_State *L ) {
rlDisableVertexBufferElement();
return 0;
}
/*
> success = RL.rlEnableVertexAttribute( int index )
Enable vertex attribute index
- Failure return false
- Success return true
*/
int lrlglEnableVertexAttribute( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexAttribute( int index )" );
lua_pushboolean( L, false );
return 1;
}
rlEnableVertexAttribute( lua_tointeger( L, 1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlDisableVertexAttribute( int index )
Disable vertex attribute index
- Failure return false
- Success return true
*/
int lrlglDisableVertexAttribute( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDisableVertexAttribute( int index )" );
lua_pushboolean( L, false );
return 1;
}
rlDisableVertexAttribute( lua_tointeger( L, 1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
## RLGL - Textures state
*/
@@ -556,6 +744,41 @@ int lrlglCubemapParameters( lua_State *L ) {
return 1;
}
/*
## RLGL - Shader state
*/
/*
> success = RL.rlEnableShader( int id )
Enable shader program
- Failure return false
- Success return true
*/
int lrlglEnableShader( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableShader( int id )" );
lua_pushboolean( L, false );
return 1;
}
rlEnableShader( lua_tointeger( L, 1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> RL.rlDisableShader()
Disable shader program
*/
int lrlglDisableShader( lua_State *L ) {
rlDisableShader();
return 0;
}
/*
## RLGL - Framebuffer state
*/
@@ -1067,6 +1290,142 @@ int lrlglSetTexture( lua_State *L ) {
return 1;
}
/*
## RLGL - Vertex buffers management
*/
/*
> vaoId = RL.rlLoadVertexArray()
Load vertex array (vao) if supported
- Success return int
*/
int lrlglLoadVertexArray( lua_State *L ) {
lua_pushinteger( L, rlLoadVertexArray() );
return 1;
}
/*
> vboId = RL.rlLoadVertexBuffer( Buffer{} buffer, int type, bool dynamic )
Load a vertex buffer attribute. Type should be RL_UNSIGNED_BYTE or RL_FLOAT
- Failure return -1
- Success return int
*/
int lrlglLoadVertexBuffer( lua_State *L ) {
if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadVertexBuffer( Buffer{} buffer, int type, bool dynamic )" );
lua_pushinteger( L, -1 );
return 1;
}
unsigned int size = 0;
int type = 0;
void *vertexBuffer = getVertexBuffer( L, &type, &size );
bool dynamic = lua_tointeger( L, 3 );
lua_pushinteger( L, rlLoadVertexBuffer( vertexBuffer, size, dynamic ) );
if ( vertexBuffer != NULL ) {
MemFree( vertexBuffer );
}
return 1;
}
/*
> success = RL.rlUnloadVertexArray( int vaoId )
Unload vertex array object (VAO)
- Failure return false
- Success return true
*/
int lrlglUnloadVertexArray( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUnloadVertexArray( int vaoId )" );
lua_pushboolean( L, false );
return 1;
}
rlUnloadVertexArray( lua_tointeger( L, 1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlUnloadVertexBuffer( int vboId )
Unload vertex buffer (VBO)
- Failure return false
- Success return true
*/
int lrlglUnloadVertexBuffer( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUnloadVertexBuffer( int vboId )" );
lua_pushboolean( L, false );
return 1;
}
rlUnloadVertexBuffer( lua_tointeger( L, 1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer )
Set vertex attribute
- Failure return false
- Success return true
*/
int lrlglSetVertexAttribute( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 )
|| !lua_isboolean( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer )" );
lua_pushboolean( L, false );
return 1;
}
int index = lua_tointeger( L, 1 );
int compSize = lua_tointeger( L, 2 );
int type = lua_tointeger( L, 3 );
bool normalized = lua_toboolean( L, 4 );
int stride = lua_tointeger( L, 5 );
int pointer = lua_tointeger( L, 6 );
rlSetVertexAttribute( index, compSize, type, normalized, stride, &pointer );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.rlDrawVertexArray( int offset, int count )
Draw vertex array
- Failure return false
- Success return true
*/
int lrlglDrawVertexArray( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArray( int offset, int count )" );
lua_pushboolean( L, false );
return 1;
}
int offset = lua_tointeger( L, 1 );
int count = lua_tointeger( L, 2 );
rlDrawVertexArray( offset, count );
lua_pushboolean( L, true );
return 1;
}
/*
## RLGL - Textures management
*/

View File

@@ -114,7 +114,7 @@ bool stateInit( const char *exePath ) {
return state->run;
}
bool stateInitInterpret() {
void stateInitInterpret() {
state = malloc( sizeof( State ) );
luaInit();
}

View File

@@ -85,6 +85,8 @@ Texture2D* texturesGetSourceTexture( size_t id ) {
break;
}
}
return &state->textures[id]->texture;
}
void texturesFreeTexture( size_t id ) {
@@ -751,6 +753,33 @@ int ltexturesImageAlphaPremultiply( lua_State *L ) {
return 1;
}
/*
> success = RL.ImageBlurGaussian( Image image, int blurSize )
Apply Gaussian blur using a box blur approximation
- Failure return false
- Success return true
*/
int ltexturesImageBlurGaussian( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageBlurGaussian( Image image, int blurSize )" );
lua_pushboolean( L, false );
return 1;
}
size_t imageId = lua_tointeger( L, 1 );
int blurSize = lua_tointeger( L, 2 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
ImageBlurGaussian( state->images[ imageId ], blurSize );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.ImageResize( Image image, Vector2 size )
@@ -1396,6 +1425,36 @@ int ltexturesImageDrawCircle( lua_State *L ) {
return 1;
}
/*
> success = RL.ImageDrawCircleLines( Image dst, Vector2 center, int radius, Color color )
Draw circle outline within an image
- Failure return false
- Success return true
*/
int ltexturesImageDrawCircleLines( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawCircleLines( Image dst, Vector2 center, int radius, Color color )" );
lua_pushboolean( L, false );
return 1;
}
size_t imageId = lua_tointeger( L, 1 );
Vector2 center = uluaGetVector2Index( L, 2 );
int radius = lua_tointeger( L, 3 );
Color color = uluaGetColorIndex( L, 4 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
ImageDrawCircleLinesV( state->images[ imageId ], center, radius, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.ImageDrawRectangle( Image dst, Rectangle rec, Color color )