Compiler - access struct fields

TRAC #11379 Signed-off-by: Daniel Koch Author: Nicolas Capens <nicolas@transgaming.com> git-svn-id: https://angleproject.googlecode.com/svn/trunk@14 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent fbb6dfa3
...@@ -405,7 +405,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -405,7 +405,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
case EOpRightShiftAssign: UNIMPLEMENTED(); /* FIXME */ out << "right shift second child into first child"; break; case EOpRightShiftAssign: UNIMPLEMENTED(); /* FIXME */ out << "right shift second child into first child"; break;
case EOpIndexDirect: outputTriplet(visit, NULL, "[", "]"); break; case EOpIndexDirect: outputTriplet(visit, NULL, "[", "]"); break;
case EOpIndexIndirect: outputTriplet(visit, NULL, "[", "]"); break; case EOpIndexIndirect: outputTriplet(visit, NULL, "[", "]"); break;
case EOpIndexDirectStruct: UNIMPLEMENTED(); /* FIXME */ out << "direct index for structure"; break; case EOpIndexDirectStruct: outputTriplet(visit, NULL, ".", NULL); break;
case EOpVectorSwizzle: case EOpVectorSwizzle:
if (visit == InVisit) if (visit == InVisit)
{ {
...@@ -919,11 +919,19 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node) ...@@ -919,11 +919,19 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
{ {
TInfoSinkBase &out = context.infoSink.obj; TInfoSinkBase &out = context.infoSink.obj;
int size = node->getType().getObjectSize(); TType &type = node->getType();
bool matrix = node->getType().isMatrix();
TBasicType type = node->getUnionArrayPointer()[0].getType();
switch (type) if(type.isField())
{
out << type.getFieldName();
}
else
{
int size = type.getObjectSize();
bool matrix = type.isMatrix();
TBasicType basicType = node->getUnionArrayPointer()[0].getType();
switch (basicType)
{ {
case EbtBool: case EbtBool:
if (!matrix) if (!matrix)
...@@ -988,7 +996,7 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node) ...@@ -988,7 +996,7 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
switch (type) switch (basicType)
{ {
case EbtBool: case EbtBool:
if (node->getUnionArrayPointer()[i].getBConst()) if (node->getUnionArrayPointer()[i].getBConst())
...@@ -1015,6 +1023,7 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node) ...@@ -1015,6 +1023,7 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
out << ", "; out << ", ";
} }
} }
}
out << ")"; out << ")";
} }
......
...@@ -205,6 +205,7 @@ public: ...@@ -205,6 +205,7 @@ public:
virtual bool isMatrix() const { return matrix ? true : false; } virtual bool isMatrix() const { return matrix ? true : false; }
virtual bool isArray() const { return array ? true : false; } virtual bool isArray() const { return array ? true : false; }
bool isField() const { return fieldName != 0; }
int getArraySize() const { return arraySize; } int getArraySize() const { return arraySize; }
void setArraySize(int s) { array = true; arraySize = s; } void setArraySize(int s) { array = true; arraySize = s; }
void setMaxArraySize (int s) { maxArraySize = s; } void setMaxArraySize (int s) { maxArraySize = s; }
......
...@@ -422,7 +422,7 @@ postfix_expression ...@@ -422,7 +422,7 @@ postfix_expression
} else { } else {
constUnion *unionArray = new constUnion[1]; constUnion *unionArray = new constUnion[1];
unionArray->setIConst(i); unionArray->setIConst(i);
TIntermTyped* index = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), $3.line); TIntermTyped* index = parseContext.intermediate.addConstantUnion(unionArray, *(*fields)[i].type, $3.line);
$$ = parseContext.intermediate.addIndex(EOpIndexDirectStruct, $1, index, $2.line); $$ = parseContext.intermediate.addIndex(EOpIndexDirectStruct, $1, index, $2.line);
$$->setType(*(*fields)[i].type); $$->setType(*(*fields)[i].type);
} }
......
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