Hello!
I had a problem with shader compilation. The vertex and fragment shaders are in the same file between #ifdef macros and the same string is passed to compilation with different #defined macros.
For example:
shader:
/////////////
varying mediump vec2 texCoords;
varying lowp vec3 color;
#if defined(VERTEX_SHADER)
//attributes, uniforms
void main()
{
//shader code, (I skipped the actual code because it didn't seem to make any difference)
}
#endif
#if defined(FRAGMENT_SHADER)
//attributes, uniforms
void main()
{
//shader code
}
#endif
///////////////
then later in code:
const char *sources[] =
{
"#define VERTEX_SHADER\n",
"#define RUNTIME\n",
source // this is the shader itself
};
glShaderSource(vertexShader, 3, sources, NULL);
glCompileShader(vertexShader);
...
sources[0] = "#define FRAGMENT_SHADER\n";
glShaderSource(fragmentShader, 3, sources, NULL);
glCompileShader(fragmentShader);
This worked on pc, mac, ios and on android on Tegra and PowerVR chips but I got a shader compilation error on a Galaxy S4 device (i think it has an Adreno 320 chip). The shader error log was empty. According to some printf debug messages, the vertex shader compiles but the fragment shader doesn't. I attached a logcat excerpt but it doesn't seem very helpful.
I could compile the shader when I manually separated the fragment and vertex shader part. Is there some kind of limitation on the preprocessor directives? I checked the samples in the sdk and that also has #ifdef commands in some shaders so I don't understand the difference.
I guess I can go with the workaround I'm just curious.
Thanks!
Sounds like an odd problem, we'd like to look at in more detail.
1) Can you try removing the parathesis from the #if defined.. Also try using just #ifdef
2) Is there an apk you could share that we can try to duplicate on?
thanks,
Thank you for the reply. We solved the problem by inserting an endline character at the end of the source string. It was just a bit strange because the same string worked on other devices and the shader compiler failed without an error log.