Implemented support for user-defined structures

TRAC #11730 Signed-off-by: Andrew Lewycky Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@116 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent f52561c2
......@@ -774,7 +774,7 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
// Base assumption: just make the type the same as the left
// operand. Then only deviations from this need be coded.
//
setType(TType(type, EvqTemporary, left->getNominalSize(), left->isMatrix()));
setType(left->getType());
//
// Array operations.
......@@ -1394,4 +1394,3 @@ void TIntermAggregate::addToPragmaTable(const TPragmaTable& pTable)
pragmaTable = new TPragmaTable();
*pragmaTable = pTable;
}
......@@ -54,7 +54,7 @@ void OutputHLSL::header()
varyingInput += " " + typeString(type) + " " + name + arrayString(type) + semantic + ";\n";
varyingGlobals += "static " + typeString(type) + " " + name + arrayString(type) + " = " + initializer(type) + ";\n";
}
else if (qualifier == EvqGlobal)
else if (qualifier == EvqGlobal || qualifier == EvqTemporary)
{
// Globals are declared and intialized as an aggregate node
}
......@@ -152,7 +152,7 @@ void OutputHLSL::header()
varyingOutput += " " + typeString(type) + " " + name + arrayString(type) + " : TEXCOORD0;\n"; // Actual semantic index assigned during link
varyingGlobals += "static " + typeString(type) + " " + name + arrayString(type) + " = " + initializer(type) + ";\n";
}
else if (qualifier == EvqGlobal)
else if (qualifier == EvqGlobal || qualifier == EvqTemporary)
{
// Globals are declared and intialized as an aggregate node
}
......@@ -810,6 +810,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
if (variable && (variable->getQualifier() == EvqTemporary || variable->getQualifier() == EvqGlobal))
{
if (!variable->getAsSymbolNode() || variable->getAsSymbolNode()->getSymbol() != "") // Variable declaration
{
out << typeString(variable->getType()) + " ";
for (TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); sit++)
......@@ -841,6 +843,25 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
this->visitAggregate(PostVisit, node);
}
}
else if (variable->getAsSymbolNode() && variable->getAsSymbolNode()->getSymbol() == "") // Type (struct) declaration
{
const TType &type = variable->getType();
const TTypeList &fields = *type.getStruct();
out << "struct " + type.getTypeName() + "\n"
"{\n";
for (unsigned int i = 0; i < fields.size(); i++)
{
const TType &field = *fields[i].type;
out << " " + typeString(field) + " " + field.getFieldName() + ";\n";
}
out << "};\n";
}
else UNREACHABLE();
}
return false;
}
......@@ -970,7 +991,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpConstructMat2: outputTriplet(visit, "float2x2(", ", ", ")"); break;
case EOpConstructMat3: outputTriplet(visit, "float3x3(", ", ", ")"); break;
case EOpConstructMat4: outputTriplet(visit, "float4x4(", ", ", ")"); break;
case EOpConstructStruct: UNIMPLEMENTED(); /* FIXME */ out << "Construct structure"; break;
case EOpConstructStruct: outputTriplet(visit, "{", ", ", "}"); break;
case EOpLessThan: outputTriplet(visit, "(", " < ", ")"); break;
case EOpGreaterThan: outputTriplet(visit, "(", " > ", ")"); break;
case EOpLessThanEqual: outputTriplet(visit, "(", " <= ", ")"); break;
......@@ -1063,10 +1084,17 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
else
{
int size = type.getObjectSize();
if (type.getBasicType() == EbtStruct)
{
out << "{";
}
else
{
bool matrix = type.isMatrix();
TBasicType basicType = node->getUnionArrayPointer()[0].getType();
TBasicType elementType = node->getUnionArrayPointer()[0].getType();
switch (basicType)
switch (elementType)
{
case EbtBool:
if (!matrix)
......@@ -1128,10 +1156,11 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
default:
UNIMPLEMENTED(); // FIXME
}
}
for (int i = 0; i < size; i++)
{
switch (basicType)
switch (node->getUnionArrayPointer()[i].getType())
{
case EbtBool:
if (node->getUnionArrayPointer()[i].getBConst())
......@@ -1159,8 +1188,15 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
}
}
if (type.getBasicType() == EbtStruct)
{
out << "}";
}
else
{
out << ")";
}
}
}
bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node)
......@@ -1443,7 +1479,11 @@ void OutputHLSL::outputTriplet(Visit visit, const char *preString, const char *i
TString OutputHLSL::typeString(const TType &type)
{
if (type.isMatrix())
if (type.getBasicType() == EbtStruct)
{
return type.getTypeName();
}
else if (type.isMatrix())
{
switch (type.getNominalSize())
{
......
......@@ -1331,7 +1331,7 @@ init_declarator_list
single_declaration
: fully_specified_type {
$$.type = $1;
$$.intermAggregate = 0;
$$.intermAggregate = parseContext->intermediate.makeAggregate(parseContext->intermediate.addSymbol(0, "", TType($1), $1.line), $1.line);;
}
| fully_specified_type IDENTIFIER {
$$.intermAggregate = parseContext->intermediate.makeAggregate(parseContext->intermediate.addSymbol(0, *$2.string, TType($1), $2.line), $2.line);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment