Add long name mapping option to the translator test.
Review URL: http://codereview.appspot.com/4529091
git-svn-id: http://angleproject.googlecode.com/svn/trunk@658 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/samples/translator/translator.cpp b/samples/translator/translator.cpp
index 7e0dff6..03cdcdb 100644
--- a/samples/translator/translator.cpp
+++ b/samples/translator/translator.cpp
@@ -27,7 +27,7 @@
static ShShaderType FindShaderType(const char* fileName);
static bool CompileFile(char* fileName, ShHandle compiler, int compileOptions);
static void LogMsg(char* msg, const char* name, const int num, const char* logName);
-static void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType);
+static void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType, bool mapLongVariableNames);
// If NUM_SOURCE_STRINGS is set to a value > 1, the input file data is
// broken into that many chunks.
@@ -78,6 +78,7 @@
if (argv[0][0] == '-' || argv[0][0] == '/') {
switch (argv[0][1]) {
case 'i': compileOptions |= SH_INTERMEDIATE_TREE; break;
+ case 'm': compileOptions |= SH_MAP_LONG_VARIABLE_NAMES; break;
case 'o': compileOptions |= SH_OBJECT_CODE; break;
case 'u': compileOptions |= SH_ATTRIBUTES_UNIFORMS; break;
default: failCode = EFailUsage;
@@ -119,12 +120,12 @@
}
if (compiled && (compileOptions & SH_ATTRIBUTES_UNIFORMS)) {
LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE ATTRIBS");
- PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES);
+ PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES, compileOptions & SH_MAP_LONG_VARIABLE_NAMES);
LogMsg("END", "COMPILER", numCompiles, "ACTIVE ATTRIBS");
printf("\n\n");
LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE UNIFORMS");
- PrintActiveVariables(compiler, SH_ACTIVE_UNIFORMS);
+ PrintActiveVariables(compiler, SH_ACTIVE_UNIFORMS, compileOptions & SH_MAP_LONG_VARIABLE_NAMES);
LogMsg("END", "COMPILER", numCompiles, "ACTIVE UNIFORMS");
printf("\n\n");
}
@@ -158,9 +159,10 @@
//
void usage()
{
- printf("Usage: translate [-i -o -u] file1 file2 ...\n"
+ printf("Usage: translate [-i -m -o -u] file1 file2 ...\n"
"Where: filename = filename ending in .frag or .vert\n"
" -i = print intermediate tree\n"
+ " -m = map long variable names\n"
" -o = print translated code\n"
" -u = print active attribs and uniforms\n");
}
@@ -209,7 +211,7 @@
printf("#### %s %s %d %s ####\n", msg, name, num, logName);
}
-void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType)
+void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType, bool mapLongVariableNames)
{
int nameSize = 0;
switch (varType) {
@@ -224,6 +226,13 @@
if (nameSize <= 1) return;
char* name = new char[nameSize];
+ char* mappedName = NULL;
+ if (mapLongVariableNames) {
+ int mappedNameSize = 0;
+ ShGetInfo(compiler, SH_MAPPED_NAME_MAX_LENGTH, &mappedNameSize);
+ mappedName = new char[mappedNameSize];
+ }
+
int activeVars = 0, size = 0;
ShDataType type = SH_NONE;
char* typeName = NULL;
@@ -231,10 +240,10 @@
for (int i = 0; i < activeVars; ++i) {
switch (varType) {
case SH_ACTIVE_ATTRIBUTES:
- ShGetActiveAttrib(compiler, i, NULL, &size, &type, name, NULL);
+ ShGetActiveAttrib(compiler, i, NULL, &size, &type, name, mappedName);
break;
case SH_ACTIVE_UNIFORMS:
- ShGetActiveUniform(compiler, i, NULL, &size, &type, name, NULL);
+ ShGetActiveUniform(compiler, i, NULL, &size, &type, name, mappedName);
break;
default: assert(0);
}
@@ -258,9 +267,14 @@
case SH_SAMPLER_CUBE: typeName = "GL_SAMPLER_CUBE"; break;
default: assert(0);
}
- printf("%d: name:%s type:%s size:%d\n", i, name, typeName, size);
+ printf("%d: name:%s type:%s size:%d", i, name, typeName, size);
+ if (mapLongVariableNames)
+ printf(" mapped name:%s", mappedName);
+ printf("\n");
}
delete [] name;
+ if (mappedName)
+ delete [] mappedName;
}
static bool ReadShaderSource(const char* fileName, ShaderSource& source) {