Skip to content

Commit

Permalink
Address Jonathans formatting notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ld-kerley committed Oct 21, 2024
1 parent 9e6f230 commit 9801db0
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 53 deletions.
6 changes: 3 additions & 3 deletions source/MaterialXCore/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,16 @@ template <class T> ValuePtr TypedValue<T>::createFromString(const string& value)
// Value methods
//

ValuePtr Value::createValueFromStrings(const string& value, const string& type, ConstTypeDefPtr typeDefPtr)
ValuePtr Value::createValueFromStrings(const string& value, const string& type, ConstTypeDefPtr typeDef)
{
CreatorMap::iterator it = _creatorMap.find(type);
if (it != _creatorMap.end())
return it->second(value);

if (typeDefPtr && !typeDefPtr->getMembers().empty())
if (typeDef && !typeDef->getMembers().empty())
{
// If we're given a TypeDef pointer that has child members, then we can create a new AggregateValue.
return AggregateValue::createAggregateValueFromString(value, type, typeDefPtr);
return AggregateValue::createAggregateValueFromString(value, type, typeDef);
}

return TypedValue<string>::createFromString(value);
Expand Down
13 changes: 8 additions & 5 deletions source/MaterialXCore/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MX_CORE_API Value
/// Create a new value instance from value and type strings.
/// @return A shared pointer to a typed value, or an empty shared pointer
/// if the conversion to the given data type cannot be performed.
static ValuePtr createValueFromStrings(const string& value, const string& type, ConstTypeDefPtr typeDefPtr = nullptr);
static ValuePtr createValueFromStrings(const string& value, const string& type, ConstTypeDefPtr typeDef = nullptr);

/// Create a deep copy of the value.
virtual ValuePtr copy() const = 0;
Expand Down Expand Up @@ -216,21 +216,24 @@ class MX_CORE_API AggregateValue : public Value
}

/// Append a member value to the aggregate.
void appendValue(ConstValuePtr valuePtr) {
void appendValue(ConstValuePtr valuePtr)
{
_data.emplace_back(valuePtr);
}

const vector<ConstValuePtr>& getMembers() const {
const vector<ConstValuePtr>& getMembers() const
{
return _data;
}

/// Query an indexed member value from the aggregate.
ConstValuePtr getMemberValue(size_t index) const {
ConstValuePtr getMemberValue(size_t index) const
{
return _data[index];
}

/// Return type string.
const string& getTypeString() const override { return _typeName; }
const string& getTypeString() const override { return _typeName; }

/// Return value string.
string getValueString() const override;
Expand Down
2 changes: 0 additions & 2 deletions source/MaterialXGenGlsl/GlslSyntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

MATERIALX_NAMESPACE_BEGIN

class GlslStructTypeSyntax;

/// Syntax class for GLSL (OpenGL Shading Language)
class MX_GENGLSL_API GlslSyntax : public Syntax
{
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXGenShader/ShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void ShaderGenerator::loadStructTypeDefs(const DocumentPtr& doc)
const auto& typeDefName = mxTypeDef->getName();
const auto& members = mxTypeDef->getMembers();

// if we don't have any member children then we're not going to consider ourselves a struct.
// If we don't have any member children then we're not going to consider ourselves a struct.
if (members.empty())
continue;

Expand Down
18 changes: 9 additions & 9 deletions source/MaterialXGenShader/Syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,17 @@ void Syntax::registerStructTypeDescSyntax()
const auto& typeDesc = TypeDesc::get(typeName);
const auto& structTypeDesc = StructTypeDesc::get(typeDesc.getStructIndex());

std::string structTypeName = typeName;
std::string defaultValue = typeName + "( ";
std::string uniformDefaultValue = EMPTY_STRING;
std::string typeAlias = EMPTY_STRING;
std::string typeDefinition = "struct " + structTypeName + " { ";
string structTypeName = typeName;
string defaultValue = typeName + "( ";
string uniformDefaultValue = EMPTY_STRING;
string typeAlias = EMPTY_STRING;
string typeDefinition = "struct " + structTypeName + " { ";

for (const auto& x : structTypeDesc.getMembers())
{
std::string memberName = x._name;
std::string memberType = x._typeDesc.getName();
std::string memberDefaultValue = x._defaultValueStr;
string memberName = x._name;
string memberType = x._typeDesc.getName();
string memberDefaultValue = x._defaultValueStr;

defaultValue += memberDefaultValue + ", ";
typeDefinition += memberType + " " + memberName + "; ";
Expand Down Expand Up @@ -299,7 +299,7 @@ string StructTypeSyntax::getValue(const Value& value, bool /*uniform*/) const
auto memberTypeName = memberValue->getTypeString();
auto memberTypeDesc = TypeDesc::get(memberTypeName);

// recursively use the syntax to generate the output, so we can supported nested structs.
// Recursively use the syntax to generate the output, so we can support nested structs.
const string valueStr = _parentSyntax->getValue(memberTypeDesc, *memberValue, true);

result += valueStr;
Expand Down
36 changes: 14 additions & 22 deletions source/MaterialXGenShader/TypeDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

#include <MaterialXGenShader/ShaderGenerator.h>

#include <sstream>

MATERIALX_NAMESPACE_BEGIN

namespace
Expand All @@ -30,17 +28,12 @@ TypeDescNameMap& typeNameMap()
return map;
}


//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

using StructTypeDescStorage = vector<StructTypeDesc>;
StructTypeDescStorage& structTypeStorage()
{
static StructTypeDescStorage storage;
return storage;
}

using StructTypeDescStorage = vector<StructTypeDesc>;
StructTypeDescStorage& structTypeStorage()
{
static StructTypeDescStorage storage;
return storage;
}

} // anonymous namespace

Expand Down Expand Up @@ -144,23 +137,22 @@ TYPEDESC_REGISTER_TYPE(MATERIAL, "material")

} // namespace Type



///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
//
// StructTypeDesc methods
//

void StructTypeDesc::addMember(const string& name, TypeDesc type, string defaultValueStr)
{
_members.emplace_back( StructTypeDesc::StructMemberTypeDesc(name, type, defaultValueStr) );
_members.emplace_back(StructTypeDesc::StructMemberTypeDesc(name, type, defaultValueStr));
}

vector<string> StructTypeDesc::getStructTypeNames()
{
StructTypeDescStorage& structs = structTypeStorage();
vector<string> structNames;
for (const auto& x : structs) {
structNames.emplace_back( x.typeDesc().getName() );
for (const auto& x : structs)
{
structNames.emplace_back(x.typeDesc().getName());
}
return structNames;
}
Expand Down Expand Up @@ -190,7 +182,7 @@ void StructTypeDesc::clear()
StructTypeDescStorage& structs = structTypeStorage();
for (const auto& structType: structs)
{
// need to add typeID to structTypeDesc - and use it here to reference back to typeDesc obj and remove it.
// Need to add typeID to structTypeDesc - and use it here to reference back to typeDesc obj and remove it.
TypeDesc::remove(structType.typeDesc().getName());
}
structs.clear();
Expand Down
14 changes: 11 additions & 3 deletions source/MaterialXGenShader/TypeDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ class MX_GENSHADER_API TypeDesc
};

/// Empty constructor.
constexpr TypeDesc() noexcept : _id(0), _basetype(BASETYPE_NONE), _semantic(SEMANTIC_NONE), _size(0), _structIndex(0) {}
constexpr TypeDesc() noexcept :
_id(0),
_basetype(BASETYPE_NONE),
_semantic(SEMANTIC_NONE),
_size(0),
_structIndex(0)
{
}

/// Constructor.
constexpr TypeDesc(std::string_view name, uint8_t basetype, uint8_t semantic = SEMANTIC_NONE, uint8_t size = 1, uint8_t structIndex = 0) noexcept :
Expand Down Expand Up @@ -177,7 +184,7 @@ class MX_GENSHADER_API TypeDesc
/// Helper class for type registration.
class MX_GENSHADER_API TypeDescRegistry
{
public:
public:
TypeDescRegistry(TypeDesc type, const string& name);
};

Expand Down Expand Up @@ -237,7 +244,8 @@ class MX_GENSHADER_API StructTypeDesc
struct StructMemberTypeDesc {
StructMemberTypeDesc(string name, TypeDesc typeDesc, string defaultValueStr) :
_name(name), _typeDesc(typeDesc), _defaultValueStr(defaultValueStr)
{}
{
}
string _name;
TypeDesc _typeDesc;
string _defaultValueStr;
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXGraphEditor/RenderView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ void RenderView::initContext(mx::GenContext& context)
context.getShaderGenerator().setUnitSystem(unitSystem);
context.getOptions().targetDistanceUnit = "meter";

// Register struct type defintions
// Register struct type definitions
context.getShaderGenerator().loadStructTypeDefs(_document);
}

Expand Down
4 changes: 2 additions & 2 deletions source/MaterialXRenderGlsl/GlslProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ const GlslProgram::InputMap& GlslProgram::updateUniformsList()
{
if (!typedesc.isStruct())
{
// handle non-struct types
// Handle non-struct types
int glType = mapTypeToOpenGLType(typedesc);

// There is no way to match with an unnamed variable
Expand Down Expand Up @@ -1006,7 +1006,7 @@ const GlslProgram::InputMap& GlslProgram::updateUniformsList()
}
else
{
// if we're a struct - we need to loop over each member
// If we're a struct - we need to loop over each member
auto structTypeDesc = StructTypeDesc::get(typedesc.getStructIndex());
auto aggregateValue = std::static_pointer_cast<const AggregateValue>(variableValue);

Expand Down
10 changes: 5 additions & 5 deletions source/MaterialXRenderMsl/MslPipelineStateObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ int GetStrideOfMetalType(MTLDataType type)
{
if (arg.type == MTLArgumentTypeBuffer && arg.bufferDataType == MTLDataTypeStruct)
{
const std::string uboObjectName = std::string(arg.name.UTF8String);
const auto uboObjectName = string(arg.name.UTF8String);

const auto addUniformToList =
[this, uboObjectName]
Expand All @@ -935,19 +935,19 @@ int GetStrideOfMetalType(MTLDataType type)
[this, uboObjectName]
(MTLStructMember* member, int index, int size, const string& memberNamePrefix, auto& addUniformToList_ref) -> void
{
std::string memberName = memberNamePrefix + member.name.UTF8String;
auto memberName = memberNamePrefix + member.name.UTF8String;

if (MTLStructType* structMember = member.structType)
{
for (MTLStructMember* subMember in structMember.members)
{
string namePrefix = memberName + ".";
auto namePrefix = memberName + ".";
addUniformToList_ref(subMember, subMember.argumentIndex, subMember.offset, namePrefix, addUniformToList_ref);
}
}
else
{
std::string uboDotMemberName = uboObjectName + "." + memberName;
auto uboDotMemberName = uboObjectName + "." + memberName;

InputPtr inputPtr = std::make_shared<Input>(index, member.dataType, size, EMPTY_STRING);
this->_uniformList[uboDotMemberName] = inputPtr;
Expand All @@ -959,7 +959,7 @@ int GetStrideOfMetalType(MTLDataType type)
{
for (MTLStructMember* ArrayOfStructMember in arrayMember.elementStructType.members)
{
string namePrefix = memberName + "[" + std::to_string(i) + "].";
auto namePrefix = memberName + "[" + std::to_string(i) + "].";
addUniformToList_ref(ArrayOfStructMember, ArrayOfStructMember.argumentIndex, ArrayOfStructMember.offset, namePrefix, addUniformToList_ref);
}
}
Expand Down

0 comments on commit 9801db0

Please sign in to comment.