Commit d7468be1 by zmo@google.com

Add long name mapping option to the translator test.

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