UnloadMaterial can also optionally free textures and shader.

This commit is contained in:
jussi
2024-09-25 20:54:32 +03:00
parent cd6471d339
commit 45e11be96a
10 changed files with 42 additions and 33 deletions

8
API.md
View File

@@ -2782,7 +2782,7 @@ Default projection matrix near cull distance
---
> RL_CULL_DISTANCE_FAR = 1000.0
> RL_CULL_DISTANCE_FAR = 1000
Default projection matrix far cull distance
@@ -7381,7 +7381,7 @@ Check if a model is ready
> RL.UnloadModel( Model model )
Unload model (including meshes) from memory (RAM and/or VRAM)
Unload model (meshes/materials) from memory (RAM and/or VRAM)
---
@@ -7774,9 +7774,9 @@ Check if a material is ready
---
> RL.UnloadMaterial( Material material )
> RL.UnloadMaterial( Material material, bool freeAll )
Unload material from GPU memory (VRAM)
Unload material from GPU memory (VRAM). Note! Use freeAll to unload shaders and textures
---

View File

@@ -944,7 +944,7 @@ RL.RL_MAX_SHADER_LOCATIONS=32
---Default projection matrix near cull distance
RL.RL_CULL_DISTANCE_NEAR=0.01
---Default projection matrix far cull distance
RL.RL_CULL_DISTANCE_FAR=1000.0
RL.RL_CULL_DISTANCE_FAR=1000
-- Defines - RLGL Texture parameters
@@ -4557,7 +4557,7 @@ function RL.LoadModelFromMesh( mesh ) end
---@return any isReady
function RL.IsModelReady( model ) end
---Unload model (including meshes) from memory (RAM and/or VRAM)
---Unload model (meshes/materials) from memory (RAM and/or VRAM)
---@param model any
---@return any RL.UnloadModel
function RL.UnloadModel( model ) end
@@ -4936,10 +4936,11 @@ function RL.CreateMaterial( materialData ) end
---@return any isReady
function RL.IsMaterialReady( material ) end
---Unload material from GPU memory (VRAM)
---Unload material from GPU memory (VRAM). Note! Use freeAll to unload shaders and textures
---@param material any
---@param freeAll boolean
---@return any RL.UnloadMaterial
function RL.UnloadMaterial( material ) end
function RL.UnloadMaterial( material, freeAll ) end
---Set texture for a material map type (MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS...)
---@param material any

View File

@@ -63,8 +63,8 @@ DETAILED CHANGES:
- ADDED: GetMouseOffset and GetMouseScale.
- CHANGE: Raymath *Equals functions return bool instead of int.
- FIXED: ColorToInt cast to unsigned int.
- ADDED: Many Gui controls accept now nil for text.
- ADDED: Some raygui controls return 1 instead of 0 when pressed or scrolled.
- CHANGE: Many Gui controls accept now nil for text.
- CHANGE: Some raygui controls return 1 instead of 0 when pressed or scrolled.
- ADDED: DrawGridEx.
- ADDED: GetRayBoxCells.
- FIXED: GenImageColor color was also argument 1.
@@ -72,6 +72,7 @@ DETAILED CHANGES:
- ADDED: LoadBufferFormatted, SetBufferData and CopyBufferData. Compressed resource file example.
- ADDED: GetBufferAsString.
- FIXED: rlSetVertexAttribute takes pointer as Buffer.
- CHANGE: UnloadMaterial can also optionally free textures and shader.
------------------------------------------------------------------------
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0

View File

@@ -14,7 +14,11 @@ Backlog {
* AudioStream.
* Models
* Mesh bone weight management?
* CBuffer
* Check endianess.
* Textures
* Try making atlas packer with stbrp_pack_rects.
* Examples
* Improve Dungeon crawler example by generating custom mesh instead of drawing 3D quads.
* Platformer example physics update for true framerate independence.

View File

@@ -330,11 +330,11 @@ for _, src in ipairs( sourceFiles ) do
elseif type( value ) == "table" then
-- All tables are colors.
apiFile:write( defineName.." = { "
..math.tointeger( value[1] )..", "..math.tointeger( value[2] )..", "
..math.tointeger( value[3] )..", "..math.tointeger( value[4] ).." }\n\n" )
..math.floor( value[1] )..", "..math.floor( value[2] )..", "
..math.floor( value[3] )..", "..math.floor( value[4] ).." }\n\n" )
luaApiFile:write( "RL."..defineName.."={"
..math.tointeger( value[1] )..","..math.tointeger( value[2] )..","
..math.tointeger( value[3] )..","..math.tointeger( value[4] ).."}\n" )
..math.floor( value[1] )..","..math.floor( value[2] )..","
..math.floor( value[3] )..","..math.floor( value[4] ).."}\n" )
else
apiFile:write( "> "..defineName.." = "..value.."\n\n" )
luaApiFile:write( "RL."..defineName.."="..value.."\n" )

View File

@@ -43,7 +43,7 @@ function RL.init()
} )
model = RL.LoadModel( RL.GetBasePath().."../resources/iqm/monkey.iqm" )
-- Unload old material.
RL.UnloadMaterial( RL.GetModelMaterial( model, 0 ) )
RL.UnloadMaterial( RL.GetModelMaterial( model, 0 ), true )
RL.SetModelMaterial( model, 0, material )
animations = RL.LoadModelAnimations( RL.GetBasePath().."../resources/iqm/monkey.iqm" )

View File

@@ -286,7 +286,7 @@ local function drawPlayer()
end
function RL.draw()
RL.ClearBackground( RL.RED )
RL.ClearBackground( RL.BLACK )
RL.BeginTextureMode( framebuffer )
drawMap()

View File

@@ -14,11 +14,10 @@ out vec4 finalColor;
// NOTE: Add here your custom variables
void main() {
// Texel color fetching from texture sampler
vec4 texelColor = texture( texture0, fragTexCoord );
// Texel color fetching from texture sampler
vec4 texelColor = texture( texture0, fragTexCoord );
// NOTE: Implement here your fragment shader code
// NOTE: Implement here your fragment shader code
finalColor = texelColor * colDiffuse;
finalColor = texelColor * colDiffuse;
}

View File

@@ -16,10 +16,10 @@ out vec4 fragColor;
// NOTE: Add here your custom variables
void main() {
// Send vertex attributes to fragment shader
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
// Send vertex attributes to fragment shader
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
// Calculate final vertex position
gl_Position = mvp * vec4( vertexPosition, 1.0 );
// Calculate final vertex position
gl_Position = mvp * vec4( vertexPosition, 1.0 );
}

View File

@@ -605,7 +605,7 @@ int lmodelsIsModelReady( lua_State* L ) {
/*
> RL.UnloadModel( Model model )
Unload model (including meshes) from memory (RAM and/or VRAM)
Unload model (meshes/materials) from memory (RAM and/or VRAM)
*/
int lmodelsUnloadModel( lua_State* L ) {
Model* model = uluaGetModel( L, 1 );
@@ -1951,19 +1951,23 @@ int lmodelsIsMaterialReady( lua_State* L ) {
}
/*
> RL.UnloadMaterial( Material material )
> RL.UnloadMaterial( Material material, bool freeAll )
Unload material from GPU memory (VRAM)
Unload material from GPU memory (VRAM). Note! Use freeAll to unload shaders and textures
*/
int lmodelsUnloadMaterial( lua_State* L ) {
Material* material = uluaGetMaterial( L, 1 );
bool freeAll = lua_toboolean( L, 2 );
/* Custom UnloadMaterial since we don't want to free Shaders or Textures. */
unloadMaterial( material );
if ( freeAll ) {
UnloadMaterial( *material );
}
/* Custom UnloadMaterial if we don't want to free Shaders or Textures. */
else {
unloadMaterial( material );
}
memset( material, 0, sizeof( Material ) );
// UnloadMaterial( *material );
return 0;
}