Hash :
24c08c4e
Author :
Date :
2011-05-27T17:40:48
Fix the bug that long varying varibales are mapped into different names in fragment/vertex shaders. ANGLEBUG=144 TEST=the same long varying variable name in fragment/vertex shaders map to the same shortened name if using the same translator. Review URL: http://codereview.appspot.com/4547063 git-svn-id: https://angleproject.googlecode.com/svn/trunk@660 736b8ea6-26fd-11df-bfd4-992fa37f6226
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
//
// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/MapLongVariableNames.h"
namespace {
TString mapLongName(int id, const TString& name, bool isVarying)
{
ASSERT(name.size() > MAX_IDENTIFIER_NAME_SIZE);
TStringStream stream;
stream << "webgl_";
if (isVarying)
stream << "v";
stream << id << "_";
stream << name.substr(0, MAX_IDENTIFIER_NAME_SIZE - stream.str().size());
return stream.str();
}
} // anonymous namespace
MapLongVariableNames::MapLongVariableNames(
TMap<TString, TString>& varyingLongNameMap)
: mVaryingLongNameMap(varyingLongNameMap)
{
}
void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
{
ASSERT(symbol != NULL);
if (symbol->getSymbol().size() > MAX_IDENTIFIER_NAME_SIZE) {
switch (symbol->getQualifier()) {
case EvqVaryingIn:
case EvqVaryingOut:
case EvqInvariantVaryingIn:
case EvqInvariantVaryingOut:
symbol->setSymbol(
mapVaryingLongName(symbol->getSymbol()));
break;
default:
symbol->setSymbol(
mapLongName(symbol->getId(), symbol->getSymbol(), false));
break;
};
}
}
void MapLongVariableNames::visitConstantUnion(TIntermConstantUnion*)
{
}
bool MapLongVariableNames::visitBinary(Visit, TIntermBinary*)
{
return true;
}
bool MapLongVariableNames::visitUnary(Visit, TIntermUnary*)
{
return true;
}
bool MapLongVariableNames::visitSelection(Visit, TIntermSelection*)
{
return true;
}
bool MapLongVariableNames::visitAggregate(Visit, TIntermAggregate* node)
{
return true;
}
bool MapLongVariableNames::visitLoop(Visit, TIntermLoop*)
{
return true;
}
bool MapLongVariableNames::visitBranch(Visit, TIntermBranch*)
{
return true;
}
TString MapLongVariableNames::mapVaryingLongName(const TString& name)
{
TMap<TString, TString>::const_iterator it = mVaryingLongNameMap.find(name);
if (it != mVaryingLongNameMap.end())
return (*it).second;
int id = mVaryingLongNameMap.size();
TString mappedName = mapLongName(id, name, true);
mVaryingLongNameMap.insert(
TMap<TString, TString>::value_type(name, mappedName));
return mappedName;
}