summaryrefslogtreecommitdiff
path: root/indra/newview/llvlcomposition.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llvlcomposition.cpp')
-rw-r--r--indra/newview/llvlcomposition.cpp100
1 files changed, 74 insertions, 26 deletions
diff --git a/indra/newview/llvlcomposition.cpp b/indra/newview/llvlcomposition.cpp
index 8d3b5cc8a5..c161c42256 100644
--- a/indra/newview/llvlcomposition.cpp
+++ b/indra/newview/llvlcomposition.cpp
@@ -188,9 +188,24 @@ void LLTerrainMaterials::setDetailAssetID(S32 asset, const LLUUID& id)
mDetailTextures[asset] = fetch_terrain_texture(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)
+{
+ return mDetailMaterialOverrides[asset];
+}
+
+void LLTerrainMaterials::setMaterialOverride(S32 asset, LLGLTFMaterial* mat_override)
+{
+ // Non-null overrides must be nontrivial. Otherwise, please set the override to null instead.
+ llassert(!mat_override || *mat_override != LLGLTFMaterial::sDefault);
+
+ mDetailMaterialOverrides[asset] = mat_override;
+ mDetailRenderMaterials[asset] = nullptr;
+}
+
LLTerrainMaterials::Type LLTerrainMaterials::getMaterialType()
{
LL_PROFILE_ZONE_SCOPED;
@@ -221,13 +236,36 @@ bool LLTerrainMaterials::texturesReady(bool boost, bool strict)
return one_ready;
}
+namespace
+{
+ bool material_asset_ready(LLFetchedGLTFMaterial* mat) { return mat && mat->isLoaded(); }
+};
+
bool LLTerrainMaterials::materialsReady(bool boost, bool strict)
{
bool ready[ASSET_COUNT];
- // *NOTE: Calls to materialReady may boost materials/textures. Do not early-return.
+ // *NOTE: This section may boost materials/textures. Do not early-return if ready[i] is false.
for (S32 i = 0; i < ASSET_COUNT; i++)
{
- ready[i] = materialReady(mDetailMaterials[i], mMaterialTexturesSet[i], boost, strict);
+ ready[i] = false;
+ LLPointer<LLFetchedGLTFMaterial>& mat = mDetailMaterials[i];
+ if (!material_asset_ready(mat)) { continue; }
+
+ LLPointer<LLFetchedGLTFMaterial>& render_mat = mDetailRenderMaterials[i];
+ if (!render_mat)
+ {
+ render_mat = new LLFetchedGLTFMaterial();
+ *render_mat = *mat;
+ // This render_mat is effectively already loaded, because it gets its data from mat.
+
+ LLPointer<LLGLTFMaterial>& override_mat = mDetailMaterialOverrides[i];
+ if (override_mat)
+ {
+ render_mat->applyOverride(*override_mat);
+ }
+ }
+
+ ready[i] = materialTexturesReady(render_mat, mMaterialTexturesSet[i], boost, strict);
}
#if 1
@@ -308,15 +346,13 @@ bool LLTerrainMaterials::textureReady(LLPointer<LLViewerFetchedTexture>& tex, bo
return true;
}
-// Boost the loading priority of every known texture in the material
-// Return true when ready to use
+// Make sure to call material_asset_ready first
+// strict = true -> all materials must be sufficiently loaded
+// strict = false -> at least one material must be loaded
// static
-bool LLTerrainMaterials::materialReady(LLPointer<LLFetchedGLTFMaterial> &mat, bool &textures_set, bool boost, bool strict)
+bool LLTerrainMaterials::materialTexturesReady(LLPointer<LLFetchedGLTFMaterial>& mat, bool& textures_set, bool boost, bool strict)
{
- if (!mat || !mat->isLoaded())
- {
- return false;
- }
+ llassert(mat);
// Material is loaded, but textures may not be
if (!textures_set)
@@ -357,6 +393,16 @@ bool LLTerrainMaterials::materialReady(LLPointer<LLFetchedGLTFMaterial> &mat, bo
return true;
}
+// Boost the loading priority of every known texture in the material
+// Return true when ready to use
+// static
+bool LLTerrainMaterials::materialReady(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]
{
@@ -372,7 +418,8 @@ const LLUUID (&LLVLComposition::getDefaultTextures())[ASSET_COUNT]
LLVLComposition::LLVLComposition(LLSurface *surfacep, const U32 width, const F32 scale) :
LLTerrainMaterials(),
- LLViewerLayer(width, scale)
+ LLViewerLayer(width, scale),
+ mParamsReady(false)
{
// Load Terrain Textures - Original ones
const LLUUID (&default_textures)[LLVLComposition::ASSET_COUNT] = LLVLComposition::getDefaultTextures();
@@ -403,13 +450,13 @@ void LLVLComposition::setSurface(LLSurface *surfacep)
mSurfacep = surfacep;
}
-BOOL LLVLComposition::generateHeights(const F32 x, const F32 y,
+bool LLVLComposition::generateHeights(const F32 x, const F32 y,
const F32 width, const F32 height)
{
if (!mParamsReady)
{
// All the parameters haven't been set yet (we haven't gotten the message from the sim)
- return FALSE;
+ return false;
}
llassert(mSurfacep);
@@ -417,7 +464,7 @@ BOOL LLVLComposition::generateHeights(const F32 x, const F32 y,
if (!mSurfacep || !mSurfacep->getRegion())
{
// We don't always have the region yet here....
- return FALSE;
+ return false;
}
S32 x_begin, y_begin, x_end, y_end;
@@ -499,17 +546,17 @@ BOOL LLVLComposition::generateHeights(const F32 x, const F32 y,
*(mDatap + i + j*mWidth) = scaled_noisy_height;
}
}
- return TRUE;
+ return true;
}
LLTerrainMaterials gLocalTerrainMaterials;
-BOOL LLVLComposition::generateComposition()
+bool LLVLComposition::generateComposition()
{
if (!mParamsReady)
{
// All the parameters haven't been set yet (we haven't gotten the message from the sim)
- return FALSE;
+ return false;
}
return LLTerrainMaterials::generateMaterials();
@@ -586,7 +633,7 @@ namespace
};
PendingImage* pending_image = new PendingImage(raw_image, ddiscard, tex->getID());
- loaded_callback_func cb = [](BOOL success, LLViewerFetchedTexture * src_vi, LLImageRaw * src, LLImageRaw * src_aux, S32 discard_level, BOOL is_final, void* userdata) {
+ loaded_callback_func cb = [](bool success, LLViewerFetchedTexture * src_vi, LLImageRaw * src, LLImageRaw * src_aux, S32 discard_level, bool is_final, void* userdata) {
PendingImage* pending = (PendingImage*)userdata;
// Owning LLVLComposition still exists
@@ -617,7 +664,7 @@ namespace
}
};
-BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
+bool LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
const F32 width, const F32 height)
{
LL_PROFILE_ZONE_SCOPED
@@ -668,19 +715,20 @@ BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
}
else
{
- tex = mDetailMaterials[i]->mBaseColorTexture;
- tex_emissive = mDetailMaterials[i]->mEmissiveTexture;
- base_color_factor = LLColor3(mDetailMaterials[i]->mBaseColor);
+ LLPointer<LLFetchedGLTFMaterial>& mat = mDetailRenderMaterials[i];
+ tex = mat->mBaseColorTexture;
+ tex_emissive = mat->mEmissiveTexture;
+ base_color_factor = LLColor3(mat->mBaseColor);
// *HACK: Treat alpha as black
- base_color_factor *= (mDetailMaterials[i]->mBaseColor.mV[VW]);
- emissive_factor = mDetailMaterials[i]->mEmissiveColor;
+ base_color_factor *= (mat->mBaseColor.mV[VW]);
+ emissive_factor = mat->mEmissiveColor;
has_base_color_factor = (base_color_factor.mV[VX] != 1.f ||
base_color_factor.mV[VY] != 1.f ||
base_color_factor.mV[VZ] != 1.f);
has_emissive_factor = (emissive_factor.mV[VX] != 1.f ||
emissive_factor.mV[VY] != 1.f ||
emissive_factor.mV[VZ] != 1.f);
- has_alpha = mDetailMaterials[i]->mAlphaMode != LLGLTFMaterial::ALPHA_MODE_OPAQUE;
+ has_alpha = mat->mAlphaMode != LLGLTFMaterial::ALPHA_MODE_OPAQUE;
}
if (!tex) { tex = LLViewerFetchedTexture::sWhiteImagep; }
@@ -819,7 +867,7 @@ BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
if (tex_comps != st_comps)
{
llassert(false);
- return FALSE;
+ return false;
}
tex_x_scalef = (F32)tex_width / (F32)mWidth;
@@ -921,7 +969,7 @@ BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
unboost_minimap_material(mDetailMaterials[i]);
}
- return TRUE;
+ return true;
}
F32 LLVLComposition::getStartHeight(S32 corner)