29 static void LogMsg(
const char* msg,
const char*
name,
const int num,
const char* logName);
59 int main(
int argc,
char* argv[])
63 int compileOptions = 0;
69 int numAttribs = 0, numUniforms = 0;
80 for (; (argc >= 1) && (failCode ==
ESuccess); argc--, argv++) {
81 if (argv[0][0] ==
'-') {
92 if (argv[0][2] ==
'=') {
104 if (argv[0][2] ==
'=') {
105 switch (argv[0][3]) {
109 if (argv[0][4] ==
'1' && argv[0][5] ==
'1')
125 if (argv[0][2] ==
'=') {
126 switch (argv[0][3]) {
142 if (vertexCompiler == 0)
145 compiler = vertexCompiler;
148 if (fragmentCompiler == 0)
151 compiler = fragmentCompiler;
156 bool compiled =
CompileFile(argv[0], compiler, compileOptions);
158 LogMsg(
"BEGIN",
"COMPILER", numCompiles,
"INFO LOG");
160 buffer = (
char*)
realloc(buffer, bufferLen *
sizeof(
char));
163 LogMsg(
"END",
"COMPILER", numCompiles,
"INFO LOG");
167 LogMsg(
"BEGIN",
"COMPILER", numCompiles,
"OBJ CODE");
169 buffer = (
char*)
realloc(buffer, bufferLen *
sizeof(
char));
172 LogMsg(
"END",
"COMPILER", numCompiles,
"OBJ CODE");
176 LogMsg(
"BEGIN",
"COMPILER", numCompiles,
"ACTIVE ATTRIBS");
178 LogMsg(
"END",
"COMPILER", numCompiles,
"ACTIVE ATTRIBS");
181 LogMsg(
"BEGIN",
"COMPILER", numCompiles,
"ACTIVE UNIFORMS");
183 LogMsg(
"END",
"COMPILER", numCompiles,
"ACTIVE UNIFORMS");
195 if ((vertexCompiler == 0) && (fragmentCompiler == 0))
202 if (fragmentCompiler)
216 printf(
"Usage: translate [-i -m -o -u -l -e -b=e -b=g -b=h -x=i -x=d] file1 file2 ...\n"
217 "Where: filename : filename ending in .frag or .vert\n"
218 " -i : print intermediate tree\n"
219 " -m : map long variable names\n"
220 " -o : print translated code\n"
221 " -u : print active attribs and uniforms\n"
222 " -l : unroll for-loops with integer indices\n"
223 " -e : emulate certain built-in functions (workaround for driver bugs)\n"
224 " -t : enforce experimental timing restrictions\n"
225 " -d : print dependency graph used to enforce timing restrictions\n"
226 " -s=e : use GLES2 spec (this is by default)\n"
227 " -s=w : use WebGL spec\n"
228 " -s=c : use CSS Shaders spec\n"
229 " -b=e : output GLSL ES code (this is by default)\n"
230 " -b=g : output GLSL code\n"
231 " -b=h9 : output HLSL9 code\n"
232 " -b=h11 : output HLSL11 code\n"
233 " -x=i : enable GL_OES_EGL_image_external\n"
234 " -x=d : enable GL_OES_EGL_standard_derivatives\n"
235 " -x=r : enable ARB_texture_rectangle\n");
249 const char* ext = strrchr(fileName,
'.');
251 if (ext && strcmp(ext,
".sl") == 0)
252 for (; ext > fileName && ext[0] !=
'.'; ext--);
254 ext = strrchr(fileName,
'.');
272 int ret =
ShCompile(compiler, &source[0], source.size(), compileOptions);
275 return ret ?
true :
false;
278 void LogMsg(
const char* msg,
const char*
name,
const int num,
const char* logName)
280 printf(
"#### %s %s %d %s ####\n", msg, name, num, logName);
295 if (nameSize <= 1)
return;
296 char*
name =
new char[nameSize];
298 char* mappedName =
NULL;
299 if (mapLongVariableNames) {
300 size_t mappedNameSize = 0;
302 mappedName =
new char[mappedNameSize];
305 size_t activeVars = 0;
308 const char* typeName =
NULL;
309 ShGetInfo(compiler, varType, &activeVars);
310 for (
size_t i = 0;
i < activeVars; ++
i) {
321 case SH_FLOAT: typeName =
"GL_FLOAT";
break;
325 case SH_INT: typeName =
"GL_INT";
break;
329 case SH_BOOL: typeName =
"GL_BOOL";
break;
341 printf(
"%u: name:%s type:%s size:%d",
i, name, typeName, size);
342 if (mapLongVariableNames)
343 printf(
" mapped name:%s", mappedName);
348 delete [] mappedName;
352 FILE*
in = fopen(fileName,
"rb");
354 printf(
"Error: unable to open input file: %s\n", fileName);
360 int count = ftell(in);
364 source.reserve(NUM_SOURCE_STRINGS);
369 char*
data =
new char[len + 1];
370 int nread = fread(data, 1, len, in);
372 source.push_back(data);
382 for (ShaderSource::size_type
i = 0;
i < source.size(); ++
i) {
void GenerateResources(ShBuiltInResources *resources)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
int main(int argc, char **argv)
COMPILER_EXPORT int ShCompile(const ShHandle handle, const char *const shaderStrings[], size_t numStrings, int compileOptions)
static void LogMsg(const char *msg, const char *name, const int num, const char *logName)
static void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType, bool mapLongVariableNames)
int MaxVertexUniformVectors
COMPILER_EXPORT ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output, const ShBuiltInResources *resources)
int ARB_texture_rectangle
int MaxFragmentUniformVectors
int MaxVertexTextureImageUnits
EGLImageKHR EGLint * name
static bool ReadShaderSource(const char *fileName, ShaderSource &source)
EGLContext EGLenum EGLClientBuffer buffer
static bool CompileFile(char *fileName, ShHandle compiler, int compileOptions)
COMPILER_EXPORT void ShGetActiveAttrib(const ShHandle handle, int index, size_t *length, int *size, ShDataType *type, char *name, char *mappedName)
const unsigned int NUM_SOURCE_STRINGS
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
COMPILER_EXPORT void ShDestruct(ShHandle handle)
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources)
COMPILER_EXPORT int ShFinalize()
COMPILER_EXPORT void ShGetInfoLog(const ShHandle handle, char *infoLog)
COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char *objCode)
int MaxCombinedTextureImageUnits
std::vector< char * > ShaderSource
static void FreeShaderSource(ShaderSource &source)
COMPILER_EXPORT void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t *params)
static ShShaderType FindShaderType(const char *fileName)
COMPILER_EXPORT int ShInitialize()
int OES_EGL_image_external
GLsizei GLsizei GLchar * source
COMPILER_EXPORT void ShGetActiveUniform(const ShHandle handle, int index, size_t *length, int *size, ShDataType *type, char *name, char *mappedName)
GLsizeiptr const GLvoid GLenum usage
int OES_standard_derivatives