diff options
| author | jussi | 2022-12-09 16:02:28 +0200 |
|---|---|---|
| committer | jussi | 2022-12-09 16:02:28 +0200 |
| commit | e1a85f898e0781c9dd69ced6cd6ccb4e304a7bd1 (patch) | |
| tree | e6fc38ef9c149de6cd58aa43a28e1c67d0cb7317 /src | |
| parent | 973d902a16b35258629d2a0b228ad9c3f49b6198 (diff) | |
| download | reilua-enhanced-e1a85f898e0781c9dd69ced6cd6ccb4e304a7bd1.tar.gz reilua-enhanced-e1a85f898e0781c9dd69ced6cd6ccb4e304a7bd1.tar.bz2 reilua-enhanced-e1a85f898e0781c9dd69ced6cd6ccb4e304a7bd1.zip | |
Draw Mesh Instanced Example.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lua_core.c | 1 | ||||
| -rw-r--r-- | src/models.c | 37 | ||||
| -rw-r--r-- | src/rmath.c | 2 |
3 files changed, 34 insertions, 6 deletions
diff --git a/src/lua_core.c b/src/lua_core.c index 2a07a90..acf4843 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1028,6 +1028,7 @@ void luaRegister() { lua_register( L, "RL_SetMaterialTexture", lmodelsSetMaterialTexture ); lua_register( L, "RL_SetMaterialColor", lmodelsSetMaterialColor ); lua_register( L, "RL_SetMaterialValue", lmodelsSetMaterialValue ); + lua_register( L, "RL_SetMaterialShader", lmodelsSetMaterialShader ); /* Model. */ lua_register( L, "RL_LoadModel", lmodelsLoadModel ); lua_register( L, "RL_LoadModelFromMesh", lmodelsLoadModelFromMesh ); diff --git a/src/models.c b/src/models.c index bc84f6c..f2f7f2e 100644 --- a/src/models.c +++ b/src/models.c @@ -1287,12 +1287,10 @@ int lmodelsDrawMesh( lua_State *L ) { return 1; } -/* TODO Untested. */ /* > success = RL_DrawMeshInstanced( Mesh mesh, Material material, Matrix{} transforms, int instances ) Draw multiple mesh instances with material and different transforms -Note! Untested. - Failure return false - Success return true @@ -1305,14 +1303,14 @@ int lmodelsDrawMeshInstanced( lua_State *L ) { } int instances = lua_tointeger( L, -1 ); lua_pop( L, 1 ); - Matrix matrises[ instances ]; + Matrix transforms[ instances ]; int t = lua_gettop( L ), i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( lua_istable( L, -1 ) ) { - matrises[i] = uluaGetMatrix( L ); + transforms[i] = uluaGetMatrix( L ); } i++; lua_pop( L, 1 ); @@ -1326,7 +1324,7 @@ int lmodelsDrawMeshInstanced( lua_State *L ) { lua_pushboolean( L, false ); return 1; } - DrawMeshInstanced( *state->meshes[ meshId ], *state->materials[ materialId ], matrises, instances ); + DrawMeshInstanced( *state->meshes[ meshId ], *state->materials[ materialId ], transforms, instances ); lua_pushboolean( L, true ); return 1; @@ -1700,6 +1698,35 @@ int lmodelsSetMaterialValue( lua_State *L ) { } /* +> success = RL_SetMaterialShader( Material material, Shader shader ) + +Set shader for material + +- Failure return false +- Success return true +*/ +int lmodelsSetMaterialShader( lua_State *L ) { + if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetMaterialShader( Material material, Shader shader )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t shaderId = lua_tointeger( L, -1 ); + lua_pop( L, 1 ); + size_t materialId = lua_tointeger( L, -1 ); + + if ( !validMaterial( materialId || !validShader( shaderId ) ) ) { + lua_pushboolean( L, false ); + return 1; + } + + state->materials[ materialId ]->shader = *state->shaders[ shaderId ]; + lua_pushboolean( L, true ); + + return 1; +} + +/* ## Models - Model */ diff --git a/src/rmath.c b/src/rmath.c index 141f8d5..a83eac4 100644 --- a/src/rmath.c +++ b/src/rmath.c @@ -1607,7 +1607,7 @@ int lmathMatrixInvert( lua_State *L ) { } /* -> result = MatrixIdentity() +> result = RL_MatrixIdentity() Get identity matrix |
