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 Default projection matrix far cull distance
@@ -7381,7 +7381,7 @@ Check if a model is ready
> RL.UnloadModel( Model model ) > 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 ---Default projection matrix near cull distance
RL.RL_CULL_DISTANCE_NEAR=0.01 RL.RL_CULL_DISTANCE_NEAR=0.01
---Default projection matrix far cull distance ---Default projection matrix far cull distance
RL.RL_CULL_DISTANCE_FAR=1000.0 RL.RL_CULL_DISTANCE_FAR=1000
-- Defines - RLGL Texture parameters -- Defines - RLGL Texture parameters
@@ -4557,7 +4557,7 @@ function RL.LoadModelFromMesh( mesh ) end
---@return any isReady ---@return any isReady
function RL.IsModelReady( model ) end 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 ---@param model any
---@return any RL.UnloadModel ---@return any RL.UnloadModel
function RL.UnloadModel( model ) end function RL.UnloadModel( model ) end
@@ -4936,10 +4936,11 @@ function RL.CreateMaterial( materialData ) end
---@return any isReady ---@return any isReady
function RL.IsMaterialReady( material ) end 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 material any
---@param freeAll boolean
---@return any RL.UnloadMaterial ---@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...) ---Set texture for a material map type (MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS...)
---@param material any ---@param material any

View File

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

View File

@@ -14,7 +14,11 @@ Backlog {
* AudioStream. * AudioStream.
* Models * Models
* Mesh bone weight management? * Mesh bone weight management?
* CBuffer
* Check endianess.
* Textures
* Try making atlas packer with stbrp_pack_rects.
* Examples * Examples
* Improve Dungeon crawler example by generating custom mesh instead of drawing 3D quads. * Improve Dungeon crawler example by generating custom mesh instead of drawing 3D quads.
* Platformer example physics update for true framerate independence. * 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 elseif type( value ) == "table" then
-- All tables are colors. -- All tables are colors.
apiFile:write( defineName.." = { " apiFile:write( defineName.." = { "
..math.tointeger( value[1] )..", "..math.tointeger( value[2] )..", " ..math.floor( value[1] )..", "..math.floor( value[2] )..", "
..math.tointeger( value[3] )..", "..math.tointeger( value[4] ).." }\n\n" ) ..math.floor( value[3] )..", "..math.floor( value[4] ).." }\n\n" )
luaApiFile:write( "RL."..defineName.."={" luaApiFile:write( "RL."..defineName.."={"
..math.tointeger( value[1] )..","..math.tointeger( value[2] ).."," ..math.floor( value[1] )..","..math.floor( value[2] )..","
..math.tointeger( value[3] )..","..math.tointeger( value[4] ).."}\n" ) ..math.floor( value[3] )..","..math.floor( value[4] ).."}\n" )
else else
apiFile:write( "> "..defineName.." = "..value.."\n\n" ) apiFile:write( "> "..defineName.." = "..value.."\n\n" )
luaApiFile:write( "RL."..defineName.."="..value.."\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" ) model = RL.LoadModel( RL.GetBasePath().."../resources/iqm/monkey.iqm" )
-- Unload old material. -- Unload old material.
RL.UnloadMaterial( RL.GetModelMaterial( model, 0 ) ) RL.UnloadMaterial( RL.GetModelMaterial( model, 0 ), true )
RL.SetModelMaterial( model, 0, material ) RL.SetModelMaterial( model, 0, material )
animations = RL.LoadModelAnimations( RL.GetBasePath().."../resources/iqm/monkey.iqm" ) animations = RL.LoadModelAnimations( RL.GetBasePath().."../resources/iqm/monkey.iqm" )

View File

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

View File

@@ -21,4 +21,3 @@ void main() {
finalColor = texelColor * colDiffuse; finalColor = texelColor * colDiffuse;
} }

View File

@@ -605,7 +605,7 @@ int lmodelsIsModelReady( lua_State* L ) {
/* /*
> RL.UnloadModel( Model model ) > 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 ) { int lmodelsUnloadModel( lua_State* L ) {
Model* model = uluaGetModel( L, 1 ); 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 ) { int lmodelsUnloadMaterial( lua_State* L ) {
Material* material = uluaGetMaterial( L, 1 ); Material* material = uluaGetMaterial( L, 1 );
bool freeAll = lua_toboolean( L, 2 );
/* Custom UnloadMaterial since we don't want to free Shaders or Textures. */ if ( freeAll ) {
UnloadMaterial( *material );
}
/* Custom UnloadMaterial if we don't want to free Shaders or Textures. */
else {
unloadMaterial( material ); unloadMaterial( material );
}
memset( material, 0, sizeof( Material ) ); memset( material, 0, sizeof( Material ) );
// UnloadMaterial( *material );
return 0; return 0;
} }