Bug 748112 - WebGL Water demo broken by long identifier mapping - r=jgilbert

This commit is contained in:
Benoit Jacob 2012-04-24 16:05:11 -04:00
parent 42d97b9780
commit a41f9f50e8

View File

@ -14,12 +14,18 @@ TString mapLongName(int id, const TString& name, bool isGlobal)
ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE);
TStringStream stream;
uint64 hash = SpookyHash::Hash64(name.data(), name.length(), 0);
stream << "webgl_"
// We want to avoid producing a string with a double underscore,
// which would be an illegal GLSL identifier. We can assume that the
// original identifier doesn't have a double underscore, otherwise
// it's illegal anyway.
stream << (name[0] == '_' ? "webgl" : "webgl_")
<< name.substr(0, 9)
<< "_"
<< (name[8] == '_' ? "" : "_")
<< std::hex
<< hash;
ASSERT(stream.str().length() == MAX_SHORTENED_IDENTIFIER_SIZE);
ASSERT(stream.str().length() <= MAX_SHORTENED_IDENTIFIER_SIZE);
ASSERT(stream.str().length() >= MAX_SHORTENED_IDENTIFIER_SIZE - 2);
return stream.str();
}