mirror of
https://github.com/luanti-org/luanti.git
synced 2025-12-02 22:05:20 +01:00
Don't generate more node shaders than needed
This commit is contained in:
@@ -22,11 +22,7 @@ struct TileAttribContext {
|
|||||||
const TextureSettings &tsettings;
|
const TextureSettings &tsettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ShaderIds {
|
using GetShaderCallback = std::function<u32 /* shader id */ (bool /* array_texture */)>;
|
||||||
u32 normal;
|
|
||||||
// Shader that will handle an array texture and texture_layer_idx
|
|
||||||
u32 with_layers;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Texture pool and related
|
Texture pool and related
|
||||||
@@ -78,7 +74,7 @@ void PreLoadedTextures::printStats(std::ostream &to) const
|
|||||||
|
|
||||||
static void fillTileAttribs(TileLayer *layer, TileAttribContext context,
|
static void fillTileAttribs(TileLayer *layer, TileAttribContext context,
|
||||||
const TileSpec &tile, const TileDef &tiledef,
|
const TileSpec &tile, const TileDef &tiledef,
|
||||||
MaterialType material_type, ShaderIds shader)
|
MaterialType material_type, GetShaderCallback get_shader)
|
||||||
{
|
{
|
||||||
auto *tsrc = context.tsrc;
|
auto *tsrc = context.tsrc;
|
||||||
const auto &tsettings = context.tsettings;
|
const auto &tsettings = context.tsettings;
|
||||||
@@ -167,8 +163,7 @@ static void fillTileAttribs(TileLayer *layer, TileAttribContext context,
|
|||||||
|
|
||||||
// Decide on shader to use
|
// Decide on shader to use
|
||||||
if (layer->texture) {
|
if (layer->texture) {
|
||||||
layer->shader_id = (layer->texture->getType() == video::ETT_2D_ARRAY) ?
|
layer->shader_id = get_shader(layer->texture->getType() == video::ETT_2D_ARRAY);
|
||||||
shader.with_layers : shader.normal;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,21 +407,15 @@ void NodeVisuals::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc, Cl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool texture_2d_array = getArrayTextureMax(shdsrc) > 1;
|
GetShaderCallback tile_shader = [&] (bool array_texture) {
|
||||||
const auto &getNodeShader = [&] (MaterialType my_material, NodeDrawType my_drawtype) {
|
return shdsrc->getShader("nodes_shader", material_type, drawtype, array_texture);
|
||||||
ShaderIds ret;
|
|
||||||
ret.normal = shdsrc->getShader("nodes_shader", my_material, my_drawtype);
|
|
||||||
// need to avoid generating the shader if unsupported
|
|
||||||
if (texture_2d_array)
|
|
||||||
ret.with_layers = shdsrc->getShader("nodes_shader", my_material, my_drawtype, true);
|
|
||||||
return ret;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ShaderIds tile_shader = getNodeShader(material_type, drawtype);
|
|
||||||
|
|
||||||
MaterialType overlay_material = material_type_with_alpha(material_type);
|
MaterialType overlay_material = material_type_with_alpha(material_type);
|
||||||
|
|
||||||
ShaderIds overlay_shader = getNodeShader(overlay_material, drawtype);
|
GetShaderCallback overlay_shader = [&] (bool array_texture) {
|
||||||
|
return shdsrc->getShader("nodes_shader", overlay_material, drawtype, array_texture);
|
||||||
|
};
|
||||||
|
|
||||||
// minimap pixel color = average color of top tile
|
// minimap pixel color = average color of top tile
|
||||||
if (tsettings.enable_minimap && drawtype != NDT_AIRLIKE && !tdef[0].name.empty())
|
if (tsettings.enable_minimap && drawtype != NDT_AIRLIKE && !tdef[0].name.empty())
|
||||||
@@ -477,7 +466,9 @@ void NodeVisuals::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc, Cl
|
|||||||
special_material = TILE_MATERIAL_WAVING_LEAVES;
|
special_material = TILE_MATERIAL_WAVING_LEAVES;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderIds special_shader = getNodeShader(special_material, drawtype);
|
GetShaderCallback special_shader = [&] (bool array_texture) {
|
||||||
|
return shdsrc->getShader("nodes_shader", special_material, drawtype, array_texture);
|
||||||
|
};
|
||||||
|
|
||||||
// Special tiles (fill in f->special_tiles[])
|
// Special tiles (fill in f->special_tiles[])
|
||||||
for (u16 j = 0; j < CF_SPECIAL_COUNT; j++) {
|
for (u16 j = 0; j < CF_SPECIAL_COUNT; j++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user