Commit 01df23e7 by Nicolas Capens

Add constant casting support.

BUG=380353 Change-Id: I5a350ca09e2b7e7abb9fa079365adb5aad5af607 Reviewed-on: https://chromium-review.googlesource.com/203450Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarNicolas Capens <nicolascapens@chromium.org>
parent f7f7616b
// //
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -18,6 +18,67 @@ public: ...@@ -18,6 +18,67 @@ public:
type = EbtVoid; type = EbtVoid;
} }
bool cast(TBasicType newType, const ConstantUnion &constant)
{
switch (newType)
{
case EbtFloat:
switch (constant.type)
{
case EbtInt: setFConst(static_cast<float>(constant.getIConst())); break;
case EbtUInt: setFConst(static_cast<float>(constant.getUConst())); break;
case EbtBool: setFConst(static_cast<float>(constant.getBConst())); break;
case EbtFloat: setFConst(static_cast<float>(constant.getFConst())); break;
default: return false;
}
break;
case EbtInt:
switch (constant.type)
{
case EbtInt: setIConst(static_cast<int>(constant.getIConst())); break;
case EbtUInt: setIConst(static_cast<int>(constant.getUConst())); break;
case EbtBool: setIConst(static_cast<int>(constant.getBConst())); break;
case EbtFloat: setIConst(static_cast<int>(constant.getFConst())); break;
default: return false;
}
break;
case EbtUInt:
switch (constant.type)
{
case EbtInt: setUConst(static_cast<unsigned int>(constant.getIConst())); break;
case EbtUInt: setUConst(static_cast<unsigned int>(constant.getUConst())); break;
case EbtBool: setUConst(static_cast<unsigned int>(constant.getBConst())); break;
case EbtFloat: setUConst(static_cast<unsigned int>(constant.getFConst())); break;
default: return false;
}
break;
case EbtBool:
switch (constant.type)
{
case EbtInt: setBConst(constant.getIConst() != 0); break;
case EbtUInt: setBConst(constant.getUConst() != 0); break;
case EbtBool: setBConst(constant.getBConst()); break;
case EbtFloat: setBConst(constant.getFConst() != 0.0f); break;
default: return false;
}
break;
case EbtStruct: // Struct fields don't get cast
switch (constant.type)
{
case EbtInt: setIConst(constant.getIConst()); break;
case EbtUInt: setUConst(constant.getUConst()); break;
case EbtBool: setBConst(constant.getBConst()); break;
case EbtFloat: setFConst(constant.getFConst()); break;
default: return false;
}
break;
default:
return false;
}
return true;
}
void setIConst(int i) {iConst = i; type = EbtInt; } void setIConst(int i) {iConst = i; type = EbtInt; }
void setUConst(unsigned int u) { uConst = u; type = EbtUInt; } void setUConst(unsigned int u) { uConst = u; type = EbtUInt; }
void setFConst(float f) {fConst = f; type = EbtFloat; } void setFConst(float f) {fConst = f; type = EbtFloat; }
......
// //
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -162,6 +162,7 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -162,6 +162,7 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
ConstantUnion* leftUnionArray = unionArray; ConstantUnion* leftUnionArray = unionArray;
size_t instanceSize = type.getObjectSize(); size_t instanceSize = type.getObjectSize();
TBasicType basicType = type.getBasicType();
if (index >= instanceSize) if (index >= instanceSize)
return; return;
...@@ -173,7 +174,7 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -173,7 +174,7 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
for (size_t i=0; i < objectSize; i++) { for (size_t i=0; i < objectSize; i++) {
if (index >= instanceSize) if (index >= instanceSize)
return; return;
leftUnionArray[index] = rightUnionArray[i]; leftUnionArray[index].cast(basicType, rightUnionArray[i]);
(index)++; (index)++;
} }
...@@ -186,7 +187,7 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -186,7 +187,7 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
if (i >= instanceSize) if (i >= instanceSize)
return; return;
leftUnionArray[i] = rightUnionArray[count]; leftUnionArray[i].cast(basicType, rightUnionArray[count]);
(index)++; (index)++;
...@@ -203,7 +204,7 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -203,7 +204,7 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
{ {
if (col == row) if (col == row)
{ {
leftUnionArray[i] = rightUnionArray[0]; leftUnionArray[i].cast(basicType, rightUnionArray[0]);
} }
else else
{ {
......
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