BredaUniversityGames / DXX-Raytracer

DXX Raytracer is a fork of the DXX Retro project for Windows. DXX Raytracer uses modern raytracing techniques to update the graphics of the beloved retro game known as Descent.
Other
216 stars 10 forks source link

New Feature: Dynamic Texture Loading #24

Closed Lehm2000 closed 3 months ago

Lehm2000 commented 3 months ago

Added dynamic texture loading during level load to reduce memory footprint on the GPU. Now only loads textures needed for level instead of entire texture library.

Changes:

Renderer.h Add new enum RT_MaterialTextureLoadState to specify if material textures are loaded or unloaded. Add new fields texture_load_state, texture_load_state_next to RT_Material track current/future state of textures.

RTmaterials.h Add new variable g_rt_material_paths_exist to track if individual textures exist. Add new method RT_VerifyMaterialTexturesFromPaths to populate g_rt_material_paths_exist

RTmaterials.c Updated RT_InitAllBitmaps to only load material information, no longer loads texture maps. Added Function RT_SyncMaterialStates to compare current/future state of material and load/unload it accordingly.

level.c Updated RT_UploadLevelGeometry() to record what textures are need for the level and then call RT_SyncMaterialStates() Updated RT_LoadLevel to call RT_ResetLightEmission() to fix bug where blinking end levels lights would not get reset during level warp.

gameseq.c Updated LoadLevel to move display of Loading (Prepare for Descent) box before the level attempts to load to act as a loading screen now that it takes longer due to textures loading. Updated StartNewLevelSub to move reset_special_effects() before level load so that wall textures are reset and correct textures will be loaded in.

RenderBackend.cpp Updated ReleaseTexture to add line g_d3d.resource_tracker.Release(texture_resource->texture) to fix issue with GPU not releasing texture memory. I found this through trial and error and not 100% certain this is the correct way to deal with this.

NOTE: This PR also contains fixes for compressed textures with less than 1 byte per pixel. May want to review/approve that PR first before this one.