Skip to content

Commit

Permalink
--revert change to user-def ptr attributes;
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner65 committed Apr 27, 2023
1 parent fdeb016 commit 60bc656
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
7 changes: 4 additions & 3 deletions src/esp/assets/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2360,7 +2360,7 @@ Mn::Trade::MaterialData ResourceManager::setDefaultMaterialUserAttributes(
arrayAppend(newAttributes, Cr::InPlaceInit, "hasPerVertexObjectId",
hasVertObjID);
if (hasTxtrObjID) {
arrayAppend(newAttributes, Cr::InPlaceInit, "objectIdTexture",
arrayAppend(newAttributes, Cr::InPlaceInit, "objectIdTexturePtr",
textures_.at(txtrIdx).get());
}
arrayAppend(newAttributes, Cr::InPlaceInit, "shaderTypeToUse",
Expand Down Expand Up @@ -2608,7 +2608,8 @@ void ResourceManager::loadMaterials(Importer& importer,
// copy texture into new attributes tagged with lowercase material
// name
auto newAttrName = Cr::Utility::formatString(
"{}{}", Cr::Utility::String::lowercase(attrName.slice(0, 1)),
"{}{}Ptr",
Cr::Utility::String::lowercase(attrName.slice(0, 1)),
attrName.slice(1, attrName.size()));
// Temporary debug message
Cr::Utility::formatInto(debugStr, debugStr.size(),
Expand Down Expand Up @@ -2673,7 +2674,7 @@ Mn::Trade::MaterialData ResourceManager::buildCustomAttributeFlatMaterial(
// material
if (flatMat.hasTexture()) {
arrayAppend(custAttributes,
{"ambientTexture",
{"ambientTexturePtr",
textures_.at(textureBaseIndex + flatMat.texture()).get()});
}
// Merge new attributes with those specified in original material
Expand Down
30 changes: 15 additions & 15 deletions src/esp/gfx/GenericDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@ GenericDrawable::GenericDrawable(
/* If texture transformation is specified, enable it only if the material is
actually textured -- it's an error otherwise */
if (materialData_->commonTextureMatrix() != Mn::Matrix3{} &&
(materialData_->hasAttribute("ambientTexture") ||
materialData_->hasAttribute("baseColorTexture") ||
materialData_->hasAttribute("diffuseTexture") ||
materialData_->hasAttribute("specularTexture") ||
materialData_->hasAttribute("objectIdTexture"))) {
(materialData_->hasAttribute("ambientTexturePtr") ||
materialData_->hasAttribute("baseColorTexturePtr") ||
materialData_->hasAttribute("diffuseTexturePtr") ||
materialData_->hasAttribute("specularTexturePtr") ||
materialData_->hasAttribute("objectIdTexturePtr"))) {
flags_ |= Mn::Shaders::PhongGL::Flag::TextureTransformation;
}
if (materialData_->hasAttribute("ambientTexture")) {
if (materialData_->hasAttribute("ambientTexturePtr")) {
flags_ |= Mn::Shaders::PhongGL::Flag::AmbientTexture;
}
if (materialData_->hasAttribute("diffuseTexture")) {
if (materialData_->hasAttribute("diffuseTexturePtr")) {
flags_ |= Mn::Shaders::PhongGL::Flag::DiffuseTexture;
}
if (materialData_->hasAttribute("specularTexture")) {
if (materialData_->hasAttribute("specularTexturePtr")) {
flags_ |= Mn::Shaders::PhongGL::Flag::SpecularTexture;
}

if (materialData_->hasAttribute("normalTexture")) {
if (materialData_->hasAttribute("normalTexturePtr")) {
if (meshAttributeFlags & Drawable::Flag::HasTangent) {
flags_ |= Mn::Shaders::PhongGL::Flag::NormalTexture;
if (meshAttributeFlags & Drawable::Flag::HasSeparateBitangent) {
Expand All @@ -76,7 +76,7 @@ GenericDrawable::GenericDrawable(
if (materialData_->attribute<bool>("hasPerVertexObjectId")) {
flags_ |= Mn::Shaders::PhongGL::Flag::InstancedObjectId;
}
if (materialData_->hasAttribute("objectIdTexture")) {
if (materialData_->hasAttribute("objectIdTexturePtr")) {
flags_ |= Mn::Shaders::PhongGL::Flag::ObjectIdTexture;
}
if (meshAttributeFlags & Drawable::Flag::HasVertexColor) {
Expand Down Expand Up @@ -184,23 +184,23 @@ void GenericDrawable::draw(const Mn::Matrix4& transformationMatrix,

if (flags_ & Mn::Shaders::PhongGL::Flag::AmbientTexture) {
shader_->bindAmbientTexture(
*(materialData_->attribute<Mn::GL::Texture2D*>("ambientTexture")));
*(materialData_->attribute<Mn::GL::Texture2D*>("ambientTexturePtr")));
}
if (flags_ & Mn::Shaders::PhongGL::Flag::DiffuseTexture) {
shader_->bindDiffuseTexture(
*(materialData_->attribute<Mn::GL::Texture2D*>("diffuseTexture")));
*(materialData_->attribute<Mn::GL::Texture2D*>("diffuseTexturePtr")));
}
if (flags_ & Mn::Shaders::PhongGL::Flag::SpecularTexture) {
shader_->bindSpecularTexture(
*(materialData_->attribute<Mn::GL::Texture2D*>("specularTexture")));
*(materialData_->attribute<Mn::GL::Texture2D*>("specularTexturePtr")));
}
if (flags_ & Mn::Shaders::PhongGL::Flag::NormalTexture) {
shader_->bindNormalTexture(
*(materialData_->attribute<Mn::GL::Texture2D*>("normalTexture")));
*(materialData_->attribute<Mn::GL::Texture2D*>("normalTexturePtr")));
}
if (flags_ >= Mn::Shaders::PhongGL::Flag::ObjectIdTexture) {
shader_->bindObjectIdTexture(
*(materialData_->attribute<Mn::GL::Texture2D*>("objectIdTexture")));
*(materialData_->attribute<Mn::GL::Texture2D*>("objectIdTexturePtr")));
}

if (skinData_) {
Expand Down
34 changes: 17 additions & 17 deletions src/esp/gfx/PbrDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ PbrDrawable::PbrDrawable(scene::SceneNode& node,
materialData_{
shaderManager.get<Mn::Trade::MaterialData>(materialDataKey)},
pbrIbl_(pbrIbl) {
if (materialData_->hasAttribute("metallicTexture") &&
materialData_->hasAttribute("roughnessTexture")) {
if (materialData_->hasAttribute("metallicTexturePtr") &&
materialData_->hasAttribute("roughnessTexturePtr")) {
CORRADE_ASSERT(
materialData_->attribute<Mn::GL::Texture2D*>("metallicTexture") ==
materialData_->attribute<Mn::GL::Texture2D*>("roughnessTexture"),
materialData_->attribute<Mn::GL::Texture2D*>("metallicTexturePtr") ==
materialData_->attribute<Mn::GL::Texture2D*>("roughnessTexturePtr"),
"PbrDrawable::PbrDrawable(): if both the metallic and roughness "
"texture exist, they must be packed in the same texture based on glTF "
"2.0 Spec.", );
Expand All @@ -46,16 +46,16 @@ PbrDrawable::PbrDrawable(scene::SceneNode& node,
if (tmpMaterialData.commonTextureMatrix() != Mn::Matrix3{}) {
flags_ |= PbrShader::Flag::TextureTransformation;
}
if (materialData_->hasAttribute("baseColorTexture")) {
if (materialData_->hasAttribute("baseColorTexturePtr")) {
flags_ |= PbrShader::Flag::BaseColorTexture;
}
if (materialData_->hasAttribute("roughnessTexture")) {
if (materialData_->hasAttribute("roughnessTexturePtr")) {
flags_ |= PbrShader::Flag::RoughnessTexture;
}
if (materialData_->hasAttribute("metallicTexture")) {
if (materialData_->hasAttribute("metallicTexturePtr")) {
flags_ |= PbrShader::Flag::MetallicTexture;
}
if (materialData_->hasAttribute("normalTexture")) {
if (materialData_->hasAttribute("normalTexturePtr")) {
flags_ |= PbrShader::Flag::NormalTexture;
if (meshAttributeFlags & gfx::Drawable::Flag::HasTangent) {
flags_ |= PbrShader::Flag::PrecomputedTangent;
Expand All @@ -67,7 +67,7 @@ PbrDrawable::PbrDrawable(scene::SceneNode& node,
"must be positive.", );
}
}
if (materialData_->hasAttribute("emissiveTexture")) {
if (materialData_->hasAttribute("emissiveTexturePtr")) {
flags_ |= PbrShader::Flag::EmissiveTexture;
}
if (materialData_->attribute<bool>("hasPerVertexObjectId")) {
Expand Down Expand Up @@ -165,19 +165,19 @@ void PbrDrawable::draw(const Mn::Matrix4& transformationMatrix,
// just in case user would like to do so during the run-time.

if ((flags_ & PbrShader::Flag::BaseColorTexture) &&
(materialData_->attribute<Mn::GL::Texture2D*>("baseColorTexture") !=
(materialData_->attribute<Mn::GL::Texture2D*>("baseColorTexturePtr") !=
nullptr)) {
shader_->bindBaseColorTexture(
*materialData_->attribute<Mn::GL::Texture2D*>("baseColorTexture"));
*materialData_->attribute<Mn::GL::Texture2D*>("baseColorTexturePtr"));
}

if (flags_ &
(PbrShader::Flag::RoughnessTexture | PbrShader::Flag::MetallicTexture)) {
Mn::GL::Texture2D* metallicRoughnessTexture =
materialData_->attribute<Mn::GL::Texture2D*>("roughnessTexture");
materialData_->attribute<Mn::GL::Texture2D*>("roughnessTexturePtr");
if (!metallicRoughnessTexture) {
metallicRoughnessTexture =
materialData_->attribute<Mn::GL::Texture2D*>("metallicTexture");
materialData_->attribute<Mn::GL::Texture2D*>("metallicTexturePtr");
}
CORRADE_ASSERT(metallicRoughnessTexture,
"PbrDrawable::draw(): texture pointer cannot be nullptr if "
Expand All @@ -186,17 +186,17 @@ void PbrDrawable::draw(const Mn::Matrix4& transformationMatrix,
}

if ((flags_ & PbrShader::Flag::NormalTexture) &&
(materialData_->attribute<Mn::GL::Texture2D*>("normalTexture") !=
(materialData_->attribute<Mn::GL::Texture2D*>("normalTexturePtr") !=
nullptr)) {
shader_->bindNormalTexture(
*materialData_->attribute<Mn::GL::Texture2D*>("normalTexture"));
*materialData_->attribute<Mn::GL::Texture2D*>("normalTexturePtr"));
}

if ((flags_ & PbrShader::Flag::EmissiveTexture) &&
(materialData_->attribute<Mn::GL::Texture2D*>("emissiveTexture") !=
(materialData_->attribute<Mn::GL::Texture2D*>("emissiveTexturePtr") !=
nullptr)) {
shader_->bindEmissiveTexture(
*materialData_->attribute<Mn::GL::Texture2D*>("emissiveTexture"));
*materialData_->attribute<Mn::GL::Texture2D*>("emissiveTexturePtr"));
}

if ((flags_ & PbrShader::Flag::TextureTransformation) &&
Expand Down

0 comments on commit 60bc656

Please sign in to comment.