1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-10 11:55:27 +01:00

Introduce EMT_INVALID as safe placeholder

This commit is contained in:
sfan5
2025-11-07 13:30:26 +01:00
parent fad3a0fa6d
commit c3790dd7af
8 changed files with 16 additions and 23 deletions

View File

@@ -10,7 +10,7 @@ namespace video
{
//! Abstracted and easy to use fixed function/programmable pipeline material modes.
enum E_MATERIAL_TYPE
enum E_MATERIAL_TYPE : u32
{
//! Standard solid material.
/** Only first texture is used, which is supposed to be the
@@ -51,15 +51,15 @@ enum E_MATERIAL_TYPE
pack_textureBlendFunc (for 2D) or pack_textureBlendFuncSeparate (for 3D). */
EMT_ONETEXTURE_BLEND,
//! This value is not used. It only forces this enumeration to compile to 32 bit.
EMT_FORCE_32BIT = 0x7fffffff
//! Invalid value
EMT_INVALID = 0xffffffff,
};
//! Array holding the built in material type names
const char *const sBuiltInMaterialTypeNames[] = {
"solid",
"trans_alphach",
"trans_alphach_ref",
"trans_alpha",
"trans_alpha_ref",
"trans_vertex_alpha",
"onetexture_blend",
0,

View File

@@ -38,16 +38,6 @@ IImageWriter *createImageWriterJPG();
//! creates a writer which is able to save png images
IImageWriter *createImageWriterPNG();
namespace
{
//! no-op material renderer
class CDummyMaterialRenderer : public IMaterialRenderer
{
public:
CDummyMaterialRenderer() {}
};
}
//! constructor
CNullDriver::CNullDriver(io::IFileSystem *io, const core::dimension2d<u32> &screenSize) :
SharedRenderTarget(0), CurrentRenderTarget(0), CurrentRenderTargetSize(0, 0), FileSystem(io), MeshManipulator(0),
@@ -1505,7 +1495,7 @@ void CNullDriver::deleteShaderMaterial(s32 material)
auto &ref = MaterialRenderers[idx];
if (ref.Renderer)
ref.Renderer->drop();
ref.Renderer = new CDummyMaterialRenderer();
ref.Renderer = new IMaterialRenderer();
ref.Name.clear();
}

View File

@@ -1700,6 +1700,8 @@ void COpenGLDriver::setRenderStates3DMode()
if (static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial(
Material, LastMaterial, ResetRenderStates, this);
else
os::Printer::log("Attempt to render with invalid material", ELL_WARNING);
LastMaterial = Material;
CacheHandler->correctCacheMaterial(LastMaterial);

View File

@@ -1176,6 +1176,8 @@ void COpenGL3DriverBase::setRenderStates3DMode()
if (static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial(
Material, LastMaterial, ResetRenderStates, this);
else
os::Printer::log("Attempt to render with invalid material", ELL_WARNING);
LastMaterial = Material;
CacheHandler->correctCacheMaterial(LastMaterial);

View File

@@ -599,14 +599,14 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
m_material_type = shader_source->getShaderInfo(shader_id).material;
} else {
// Not used, so make sure it's not valid
m_material_type = EMT_INVALID;
m_material_type = video::EMT_INVALID;
}
m_matrixnode = m_smgr->addDummyTransformationSceneNode();
m_matrixnode->grab();
auto setMaterial = [this] (video::SMaterial &mat) {
if (m_material_type != EMT_INVALID)
if (m_material_type != video::EMT_INVALID)
mat.MaterialType = m_material_type;
mat.FogEnable = true;
mat.forEachTexture([] (auto &tex) {

View File

@@ -74,7 +74,6 @@ struct MeshAnimationInfo {
class GenericCAO : public ClientActiveObject
{
private:
static constexpr auto EMT_INVALID = video::EMT_FORCE_32BIT;
// Only set at initialization
std::string m_name = "";
@@ -101,7 +100,7 @@ private:
std::vector<MeshAnimationInfo> m_meshnode_animation;
// Material
video::E_MATERIAL_TYPE m_material_type = EMT_INVALID;
video::E_MATERIAL_TYPE m_material_type = video::EMT_INVALID;
// Movement
v3f m_position = v3f(0.0f, 10.0f * BS, 0);

View File

@@ -640,7 +640,7 @@ void ShaderSource::rebuildShaders()
for (ShaderInfo &i : m_shaderinfo_cache) {
if (!i.name.empty()) {
gpu->deleteShaderMaterial(i.material);
i.material = video::EMT_SOLID; // invalidate
i.material = video::EMT_INVALID;
}
}

View File

@@ -229,9 +229,9 @@ using CachedStructPixelShaderSetting = CachedStructShaderSetting<T, count, cache
struct ShaderInfo {
std::string name;
video::E_MATERIAL_TYPE base_material = video::EMT_SOLID;
video::E_MATERIAL_TYPE base_material = video::EMT_INVALID;
// Material ID the shader has received from Irrlicht
video::E_MATERIAL_TYPE material = video::EMT_SOLID;
video::E_MATERIAL_TYPE material = video::EMT_INVALID;
// Input constants
ShaderConstants input_constants;
// Extra uniform callback