Skip to content

Commit

Permalink
tr_image: deep rewrite of the image loading code
Browse files Browse the repository at this point in the history
- do not use R_FindImageLoader with cube maps
- only use home read for KTX with IF_HOMEPATH
- load home KTX with IF_HOMEPATH before doing any lookup
- do not do any other home loading
- test multifile cubemaps before singlefile ones (or preview may be loaded as cubemap instead)
- fix a crash when singlefile cubemap is freed because it was loaded but not created
- look for cubemap file with explicit extension
- add many debug logs and factorize them
  • Loading branch information
illwieckz committed Oct 26, 2024
1 parent b8873df commit eab6a6a
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 207 deletions.
11 changes: 8 additions & 3 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4462,9 +4462,11 @@ static bool R_LoadCubeMaps() {
imageParams.filterType = filterType_t::FT_DEFAULT;
imageParams.wrapType = wrapTypeEnum_t::WT_EDGE_CLAMP;

image_t* cubemap = R_FindCubeImage( Str::Format( "%s%u", dirPath, i ).c_str(), imageParams );
std::string imageName = Str::Format( "%s%u", dirPath, i );

image_t* cubemap = R_FindCubeImage( imageName.c_str(), imageParams );
if ( !cubemap ) {
Log::Warn( "Failed to load cubemap %s%u", dirPath, i );
Log::Warn( "Failed to load cubemap %s", imageName );
return false;
}
cubeProbe.cubemap = cubemap;
Expand Down Expand Up @@ -4502,7 +4504,10 @@ static bool R_SaveCubeMaps() {

for ( uint32_t i = 1; i < tr.cubeProbes.size(); i++ ) {
cubemapGridFile.Printf( "%f %f %f\n", tr.cubeProbes[i].origin[0], tr.cubeProbes[i].origin[1], tr.cubeProbes[i].origin[2] );
SaveImageKTX( Str::Format( "%s%u.ktx", dirPath, i - 1 ).c_str(), tr.cubeProbes[i].cubemap );

std::string imagePath = Str::Format( "%s%u.ktx", dirPath, i - 1 );

SaveImageKTX( imagePath.c_str(), tr.cubeProbes[i].cubemap );
}

for ( uint32_t i = 0; i < tr.cubeProbeGrid.size; i++ ) {
Expand Down
Loading

0 comments on commit eab6a6a

Please sign in to comment.