chore: add parsing of usertextures

This commit is contained in:
Almamu 2025-08-23 17:42:01 +02:00
parent fc865499fc
commit 9c62125a1f
6 changed files with 32 additions and 2 deletions

View File

@ -22,6 +22,8 @@ struct MaterialPass {
std::string shader; std::string shader;
/** List of textures defined for this pass */ /** List of textures defined for this pass */
TextureMap textures; TextureMap textures;
/** List of user textures defined for this pass */
TextureMap usertextures;
/** The combos and their values to pass onto the shader */ /** The combos and their values to pass onto the shader */
ComboMap combos; ComboMap combos;
}; };

View File

@ -135,4 +135,18 @@ class PropertyText : public Property {
return this->text; return this->text;
} }
}; };
class PropertySceneTexture : public Property {
public:
explicit PropertySceneTexture (PropertyData data, std::string value) : Property (std::move(data)) {
this->update (value);
}
void update(const std::string& value) override {
this->m_value = value;
}
private:
std::string m_value;
};
} }

View File

@ -35,6 +35,7 @@ std::vector <MaterialPassUniquePtr> MaterialParser::parsePasses (const JSON& it,
MaterialPassUniquePtr MaterialParser::parsePass (const JSON& it, Project& project) { MaterialPassUniquePtr MaterialParser::parsePass (const JSON& it, Project& project) {
const auto textures = it.optional ("textures"); const auto textures = it.optional ("textures");
const auto usertextures = it.optional ("usertextures");
const auto combos = it.optional ("combos"); const auto combos = it.optional ("combos");
const auto constants = it.optional ("constants"); const auto constants = it.optional ("constants");
@ -45,8 +46,9 @@ MaterialPassUniquePtr MaterialParser::parsePass (const JSON& it, Project& projec
.depthtest = it.optional ("depthtest", std::string ("disabled")), .depthtest = it.optional ("depthtest", std::string ("disabled")),
.depthwrite = it.optional ("depthwrite", std::string ("disabled")), .depthwrite = it.optional ("depthwrite", std::string ("disabled")),
.shader = it.require <std::string> ("shader", "Material pass must have a shader"), .shader = it.require <std::string> ("shader", "Material pass must have a shader"),
.textures = textures.has_value () ? parseTextures (*textures) : std::map <int, std::string> {}, .textures = textures.has_value () ? parseTextures (*textures) : TextureMap {},
.combos = combos.has_value () ? parseCombos (*combos) : std::map <std::string, int> {}, .usertextures = usertextures.has_value () ? parseTextures (*usertextures) : TextureMap {},
.combos = combos.has_value () ? parseCombos (*combos) : ComboMap {},
}); });
} }

View File

@ -22,6 +22,9 @@ PropertySharedPtr PropertyParser::parse (const JSON& it, std::string name) {
if (type == "text") { if (type == "text") {
return parseText (it, name); return parseText (it, name);
} }
if (type == "scenetexture") {
return parseSceneTexture (it, name);
}
if (type != "group") { if (type != "group") {
// show the error and ignore this property // show the error and ignore this property
@ -95,4 +98,11 @@ PropertySharedPtr PropertyParser::parseText (const JSON& it, std::string name) {
.name = name, .name = name,
.text = it.optional <std::string> ("text", ""), .text = it.optional <std::string> ("text", ""),
}); });
}
PropertySharedPtr PropertyParser::parseSceneTexture (const JSON& it, std::string name) {
return std::make_shared <PropertySceneTexture> (PropertyData {
.name = name,
.text = it.optional <std::string> ("text", ""),
}, it.require ("value", "Property must have a value"));
} }

View File

@ -16,5 +16,6 @@ class PropertyParser {
static PropertySharedPtr parseBoolean (const JSON& it, std::string name); static PropertySharedPtr parseBoolean (const JSON& it, std::string name);
static PropertySharedPtr parseSlider (const JSON& it, std::string name); static PropertySharedPtr parseSlider (const JSON& it, std::string name);
static PropertySharedPtr parseText (const JSON& it, std::string name); static PropertySharedPtr parseText (const JSON& it, std::string name);
static PropertySharedPtr parseSceneTexture (const JSON& it, std::string name);
}; };
} }

View File

@ -409,6 +409,7 @@ void CShaderUnit::parseParameterConfiguration (
// now convert it to integer // now convert it to integer
// TODO: BETTER CONVERSION HERE // TODO: BETTER CONVERSION HERE
size_t index = value - '0'; size_t index = value - '0';
// TODO: SUPPORT USER TEXTURES!!
if (combo != data.end ()) { if (combo != data.end ()) {
// TODO: CLEANUP HOW THIS IS DETERMINED FIRST // TODO: CLEANUP HOW THIS IS DETERMINED FIRST