I'm trying to write a blur filter in GLSL ES 2.0 and I'm getting an Error with the line assigning gl_FragColor. I've not been able to figure out why
#extension GL_OES_EGL_image_external : require
precision mediump float;
varying vec2 textureCoordinate;
uniform samplerExternalOES s_texture;
void main() {
float gaus[25] = float[25](0.01739, 0.03478, 0.04347, 0.03478, 0.01739,
0.03478, 0.07282, 0.10434, 0.07282, 0.03478,
0.04347, 0.10434, 0.13043, 0.10434, 0.04347,
0.03478, 0.07282, 0.10434, 0.07282, 0.03478,
0.01739, 0.03478, 0.04347, 0.03478, 0.01739);
float offset[5] = float[5](-2.0, -1.0, 0.0, 1.0, 2.0);
vec4 outSum = vec4(0.0);
int rowi = 0;
for(int i = 0; i < 5; i++){
vec4 inSum = vec4(0.0);
for(int j = 0; j < 5; j++){
inSum += texture2D(s_texture, textureCoordinate + vec2(offset[i], offset[j]))*gaus[j*5+i];
}
outSum += inSum*gaus[rowi+i];
rowi += 3;
}
gl_FragColor = outSum;
}
The assignment of gl_FragColor
causes calls to glUseProgram
to error with GL_INVALID_OPERATION
. I've tried this without it and it compiles and operates without the error. I'm hoping someone can point me in a direction i haven't looked yet at least because I can't see any reason this isn't working.
EDIT: I solved this. As best I can tell the GLSL-ES on android doesn't allow indexing arrays with non-constant variables. GLSE-ES 2.0 specification page 97 10.25 states it's not directly supported by all implementations and on page 109 it states that loop indices can be considered constant-expressions but not must. I rolled out my loop and it's linking fine now.
Thank you everyone who responded, I was able to narrow this down thanks to your insight.