Add a GetVariableInfo helper method.
This method replaces the similar logic in storing uniforms,
varyings, and interface blocks when collecting variable info.
We can also re-use this method for both GLSL and HLSL programs.
BUG=angle:466
Change-Id: Ie6c13abe0f09f38b2f9b36e117caae4833eaccbf
Reviewed-on: https://chromium-review.googlesource.com/206566
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index 226d025..7d14070 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -2900,31 +2900,29 @@
return constUnion;
}
-void OutputHLSL::declareVaryingToList(const TType &type, TQualifier baseTypeQualifier, const TString &name, std::vector<Varying> &fieldsOut)
+class DeclareVaryingTraverser : public GetVariableTraverser<Varying>
{
- const TStructure *structure = type.getStruct();
+ public:
+ DeclareVaryingTraverser(std::vector<Varying> *output,
+ InterpolationType interpolation)
+ : GetVariableTraverser(output),
+ mInterpolation(interpolation)
+ {}
- InterpolationType interpolation = GetInterpolationType(baseTypeQualifier);
- if (!structure)
+ private:
+ void visitVariable(Varying *varying)
{
- sh::Varying varying(GLVariableType(type), GLVariablePrecision(type), name.c_str(), (unsigned int)type.getArraySize(), interpolation);
- fieldsOut.push_back(varying);
+ varying->interpolation = mInterpolation;
}
- else
- {
- sh::Varying structVarying(GL_STRUCT_ANGLEX, GL_NONE, name.c_str(), (unsigned int)type.getArraySize(), interpolation);
- const TFieldList &fields = structure->fields();
- structVarying.structName = structure->name().c_str();
+ InterpolationType mInterpolation;
+};
- for (size_t fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++)
- {
- const TField &field = *fields[fieldIndex];
- declareVaryingToList(*field.type(), baseTypeQualifier, field.name(), structVarying.fields);
- }
-
- fieldsOut.push_back(structVarying);
- }
+void OutputHLSL::declareVaryingToList(const TType &type, TQualifier baseTypeQualifier,
+ const TString &name, std::vector<Varying> &fieldsOut)
+{
+ DeclareVaryingTraverser traverser(&fieldsOut, GetInterpolationType(baseTypeQualifier));
+ traverser.traverse(type, name);
}
}