Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secondlife/viewer#2991: Fix PBR terrain sometimes not loading textures #3150

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion indra/newview/llfetchedgltfmaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@
#include "llviewertexture.h"

class LLGLSLShader;
class LLGLTFMaterialList;
class LLTerrainMaterials;

class LLFetchedGLTFMaterial: public LLGLTFMaterial
{
friend class LLGLTFMaterialList; // for lifetime management
// for lifetime management
friend class LLGLTFMaterialList;
friend class LLTerrainMaterials;
public:
LLFetchedGLTFMaterial();
virtual ~LLFetchedGLTFMaterial();
Expand Down
28 changes: 8 additions & 20 deletions indra/newview/llvlcomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ namespace
}
};

LLTerrainMaterials::LLTerrainMaterials()
{
for (S32 i = 0; i < ASSET_COUNT; ++i)
{
mMaterialTexturesSet[i] = false;
}
}

LLTerrainMaterials::~LLTerrainMaterials()
{
unboost();
Expand Down Expand Up @@ -199,7 +191,6 @@ void LLTerrainMaterials::setDetailAssetID(S32 asset, const LLUUID& id)
LLPointer<LLFetchedGLTFMaterial>& mat = mDetailMaterials[asset];
mat = id.isNull() ? nullptr : gGLTFMaterialList.getMaterial(id);
mDetailRenderMaterials[asset] = nullptr;
mMaterialTexturesSet[asset] = false;
}

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

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

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

ready[i] = materialTexturesReady(render_mat, mMaterialTexturesSet[i], boost, strict);
ready[i] = materialTexturesReady(render_mat, render_material_textures_set, boost, strict);
llassert(render_material_textures_set);
}

#if 1
Expand Down Expand Up @@ -414,16 +412,6 @@ bool LLTerrainMaterials::materialTexturesReady(LLPointer<LLFetchedGLTFMaterial>&
return true;
}

// Boost the loading priority of every known texture in the material
// Return true when ready to use
// static
bool LLTerrainMaterials::makeMaterialReady(LLPointer<LLFetchedGLTFMaterial> &mat, bool &textures_set, bool boost, bool strict)
{
if (!material_asset_ready(mat)) { return false; }

return materialTexturesReady(mat, textures_set, boost, strict);
}

// static
const LLUUID (&LLVLComposition::getDefaultTextures())[ASSET_COUNT]
{
Expand Down
17 changes: 8 additions & 9 deletions indra/newview/llvlcomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@
#ifndef LL_LLVLCOMPOSITION_H
#define LL_LLVLCOMPOSITION_H

#include "llfetchedgltfmaterial.h"
#include "llimage.h"
#include "llpointer.h"
#include "llterrainpaintmap.h"
#include "llviewerlayer.h"
#include "llviewershadermgr.h"
#include "llviewertexture.h"
#include "llpointer.h"

#include "llimage.h"

class LLSurface;

class LLViewerFetchedTexture;
class LLGLTFMaterial;
class LLFetchedGLTFMaterial;

class LLModifyRegion
{
Expand All @@ -52,7 +51,7 @@ class LLTerrainMaterials : public LLModifyRegion
public:
friend class LLDrawPoolTerrain;

LLTerrainMaterials();
LLTerrainMaterials() {}
virtual ~LLTerrainMaterials();

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

LLPointer<LLViewerFetchedTexture> mDetailTextures[ASSET_COUNT];
// *NOTE: Unlike mDetailRenderMaterials, the textures in this are not
// guaranteed to be set or loaded after a true return from
// makeMaterialsReady.
LLPointer<LLFetchedGLTFMaterial> mDetailMaterials[ASSET_COUNT];
LLPointer<LLGLTFMaterial> mDetailMaterialOverrides[ASSET_COUNT];
LLPointer<LLFetchedGLTFMaterial> mDetailRenderMaterials[ASSET_COUNT];
bool mMaterialTexturesSet[ASSET_COUNT];

U32 mPaintType = TERRAIN_PAINT_TYPE_HEIGHTMAP_WITH_NOISE;
LLPointer<LLViewerTexture> mPaintMap;
Expand Down