mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-12 16:21:04 +02:00
87 lines
2.4 KiB
C++
87 lines
2.4 KiB
C++
/*
|
|
===========================================================================
|
|
|
|
Render-world terrain loading
|
|
|
|
===========================================================================
|
|
*/
|
|
|
|
#include "precompiled.h"
|
|
#pragma hdrstop
|
|
|
|
#include "tr_local.h"
|
|
|
|
static idStr R_WorldTerrainFileName( const char *mapName ) {
|
|
return idTerrainModel::FileNameForMap( mapName );
|
|
}
|
|
|
|
void idRenderWorldLocal::ClearWorldTerrain() {
|
|
for ( int i = 0; i < terrainModel.NumTerrains(); i++ ) {
|
|
idTerrainPatch *terrain = terrainModel.Terrain( i );
|
|
if ( terrain && terrain->paintTexture != 0 ) {
|
|
GLuint texture = terrain->paintTexture;
|
|
glDeleteTextures( 1, &texture );
|
|
terrain->paintTexture = 0;
|
|
}
|
|
}
|
|
terrainModel.Clear();
|
|
terrainTimeStamp = FILE_NOT_FOUND_TIMESTAMP;
|
|
}
|
|
|
|
void idRenderWorldLocal::TouchWorldTerrainMaterials() {
|
|
for ( int i = 0; i < terrainModel.NumTerrains(); i++ ) {
|
|
idTerrainPatch *terrain = terrainModel.Terrain( i );
|
|
if ( !terrain ) {
|
|
continue;
|
|
}
|
|
terrain->EnsureLayerData( "textures/common/caulk" );
|
|
for ( int layer = 0; layer < TERRAIN_MAX_LAYERS; layer++ ) {
|
|
if ( terrain->layerMaterials[layer].IsEmpty() ) {
|
|
continue;
|
|
}
|
|
const idMaterial *material = declManager->FindMaterial( terrain->layerMaterials[layer].c_str(), false );
|
|
if ( material && !material->TestMaterialFlag( MF_DEFAULTED ) ) {
|
|
const_cast<idMaterial *>( material )->AddReference();
|
|
material->GetDiffuseImage( NULL );
|
|
material->GetBumpStage();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void idRenderWorldLocal::LoadWorldTerrain() {
|
|
ClearWorldTerrain();
|
|
if ( mapName.IsEmpty() ) {
|
|
return;
|
|
}
|
|
|
|
idStr filename = R_WorldTerrainFileName( mapName.c_str() );
|
|
fileSystem->ReadFile( filename, NULL, &terrainTimeStamp );
|
|
if ( terrainTimeStamp == FILE_NOT_FOUND_TIMESTAMP ) {
|
|
return;
|
|
}
|
|
|
|
if ( !terrainModel.LoadFile( filename.c_str(), "textures/common/caulk" ) ) {
|
|
common->Warning( "idRenderWorldLocal::LoadWorldTerrain: failed to load %s", filename.c_str() );
|
|
ClearWorldTerrain();
|
|
return;
|
|
}
|
|
|
|
for ( int i = 0; i < terrainModel.NumTerrains(); i++ ) {
|
|
idTerrainPatch *terrain = terrainModel.Terrain( i );
|
|
if ( !terrain ) {
|
|
continue;
|
|
}
|
|
terrain->paintTexture = 0;
|
|
terrain->EnsureLayerData( "textures/common/caulk" );
|
|
terrain->MarkPaintTextureDirty();
|
|
terrain->UpdateBounds();
|
|
}
|
|
TouchWorldTerrainMaterials();
|
|
|
|
common->Printf( "loaded %i terrain patch%s from %s\n",
|
|
terrainModel.NumTerrains(),
|
|
terrainModel.NumTerrains() == 1 ? "" : "es",
|
|
filename.c_str() );
|
|
}
|