Skip to content

Commit feb6b39

Browse files
cosmic-lindenakleshchev
authored andcommitted
#2991: Fix PBR terrain sometimes not loading textures
1 parent 9f86209 commit feb6b39

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

indra/newview/llfetchedgltfmaterial.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@
3131
#include "llviewertexture.h"
3232

3333
class LLGLSLShader;
34+
class LLGLTFMaterialList;
35+
class LLTerrainMaterials;
3436

3537
class LLFetchedGLTFMaterial: public LLGLTFMaterial
3638
{
37-
friend class LLGLTFMaterialList; // for lifetime management
39+
// for lifetime management
40+
friend class LLGLTFMaterialList;
41+
friend class LLTerrainMaterials;
3842
public:
3943
LLFetchedGLTFMaterial();
4044
virtual ~LLFetchedGLTFMaterial();

indra/newview/llvlcomposition.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ namespace
102102
}
103103
};
104104

105-
LLTerrainMaterials::LLTerrainMaterials()
106-
{
107-
for (S32 i = 0; i < ASSET_COUNT; ++i)
108-
{
109-
mMaterialTexturesSet[i] = false;
110-
}
111-
}
112-
113105
LLTerrainMaterials::~LLTerrainMaterials()
114106
{
115107
unboost();
@@ -199,7 +191,6 @@ void LLTerrainMaterials::setDetailAssetID(S32 asset, const LLUUID& id)
199191
LLPointer<LLFetchedGLTFMaterial>& mat = mDetailMaterials[asset];
200192
mat = id.isNull() ? nullptr : gGLTFMaterialList.getMaterial(id);
201193
mDetailRenderMaterials[asset] = nullptr;
202-
mMaterialTexturesSet[asset] = false;
203194
}
204195

205196
const LLGLTFMaterial* LLTerrainMaterials::getMaterialOverride(S32 asset) const
@@ -262,11 +253,17 @@ bool LLTerrainMaterials::makeMaterialsReady(bool boost, bool strict)
262253
if (!material_asset_ready(mat)) { continue; }
263254

264255
LLPointer<LLFetchedGLTFMaterial>& render_mat = mDetailRenderMaterials[i];
256+
// This will be mutated by materialTexturesReady, due to the way that
257+
// function is implemented.
258+
bool render_material_textures_set = bool(render_mat);
265259
if (!render_mat)
266260
{
267261
render_mat = new LLFetchedGLTFMaterial();
268262
*render_mat = *mat;
269263
// This render_mat is effectively already loaded, because it gets its data from mat.
264+
// However, its textures may not be loaded yet.
265+
render_mat->materialBegin();
266+
render_mat->materialComplete(true);
270267

271268
LLPointer<LLGLTFMaterial>& override_mat = mDetailMaterialOverrides[i];
272269
if (override_mat)
@@ -275,7 +272,8 @@ bool LLTerrainMaterials::makeMaterialsReady(bool boost, bool strict)
275272
}
276273
}
277274

278-
ready[i] = materialTexturesReady(render_mat, mMaterialTexturesSet[i], boost, strict);
275+
ready[i] = materialTexturesReady(render_mat, render_material_textures_set, boost, strict);
276+
llassert(render_material_textures_set);
279277
}
280278

281279
#if 1
@@ -414,16 +412,6 @@ bool LLTerrainMaterials::materialTexturesReady(LLPointer<LLFetchedGLTFMaterial>&
414412
return true;
415413
}
416414

417-
// Boost the loading priority of every known texture in the material
418-
// Return true when ready to use
419-
// static
420-
bool LLTerrainMaterials::makeMaterialReady(LLPointer<LLFetchedGLTFMaterial> &mat, bool &textures_set, bool boost, bool strict)
421-
{
422-
if (!material_asset_ready(mat)) { return false; }
423-
424-
return materialTexturesReady(mat, textures_set, boost, strict);
425-
}
426-
427415
// static
428416
const LLUUID (&LLVLComposition::getDefaultTextures())[ASSET_COUNT]
429417
{

indra/newview/llvlcomposition.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@
2727
#ifndef LL_LLVLCOMPOSITION_H
2828
#define LL_LLVLCOMPOSITION_H
2929

30+
#include "llfetchedgltfmaterial.h"
31+
#include "llimage.h"
32+
#include "llpointer.h"
33+
#include "llterrainpaintmap.h"
3034
#include "llviewerlayer.h"
3135
#include "llviewershadermgr.h"
3236
#include "llviewertexture.h"
33-
#include "llpointer.h"
34-
35-
#include "llimage.h"
3637

3738
class LLSurface;
3839

3940
class LLViewerFetchedTexture;
40-
class LLGLTFMaterial;
41-
class LLFetchedGLTFMaterial;
4241

4342
class LLModifyRegion
4443
{
@@ -52,7 +51,7 @@ class LLTerrainMaterials : public LLModifyRegion
5251
public:
5352
friend class LLDrawPoolTerrain;
5453

55-
LLTerrainMaterials();
54+
LLTerrainMaterials() {}
5655
virtual ~LLTerrainMaterials();
5756

5857
void apply(const LLModifyRegion& other);
@@ -93,15 +92,15 @@ class LLTerrainMaterials : public LLModifyRegion
9392
static bool makeTextureReady(LLPointer<LLViewerFetchedTexture>& tex, bool boost);
9493
// strict = true -> all materials must be sufficiently loaded
9594
// strict = false -> at least one material must be loaded
96-
static bool makeMaterialReady(LLPointer<LLFetchedGLTFMaterial>& mat, bool& textures_set, bool boost, bool strict);
97-
// *NOTE: Prefer calling makeMaterialReady if mat is known to be LLFetchedGLTFMaterial
9895
static bool materialTexturesReady(LLPointer<LLFetchedGLTFMaterial>& mat, bool& textures_set, bool boost, bool strict);
9996

10097
LLPointer<LLViewerFetchedTexture> mDetailTextures[ASSET_COUNT];
98+
// *NOTE: Unlike mDetailRenderMaterials, the textures in this are not
99+
// guaranteed to be set or loaded after a true return from
100+
// makeMaterialsReady.
101101
LLPointer<LLFetchedGLTFMaterial> mDetailMaterials[ASSET_COUNT];
102102
LLPointer<LLGLTFMaterial> mDetailMaterialOverrides[ASSET_COUNT];
103103
LLPointer<LLFetchedGLTFMaterial> mDetailRenderMaterials[ASSET_COUNT];
104-
bool mMaterialTexturesSet[ASSET_COUNT];
105104

106105
U32 mPaintType = TERRAIN_PAINT_TYPE_HEIGHTMAP_WITH_NOISE;
107106
LLPointer<LLViewerTexture> mPaintMap;

0 commit comments

Comments
 (0)