So I'm about to loose my mind.
I'm writing an android app, a native activity to be exact. All is fine except that attributes and uniforms seems to be optimized out in my shader.
Vertex Shader:
#version 100
attribute vec3 position;
void main() {
gl_Position = vec4(position, 1);
}
Fragment Shader:
#version 100
precision highp float;
uniform vec3 color;
void main() {
gl_FragColor = vec4(color, 1);
}
Shader Compilation:
unsigned int shader = glCreateProgram();
unsigned int v = glCreateShader(GL_VERTEX_SHADER);
unsigned int f = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(v, 1, &vertex, nullptr);
glShaderSource(f, 1, &fragment, nullptr);
glCompileShader(v);
if (check_error(v, GL_COMPILE_STATUS, false)) {
LOGE("Failed to compile vertex shader");
}
glCompileShader(f);
if (check_error(f, GL_COMPILE_STATUS, false)) {
LOGE("Failed to compile fragment shader");
}
glAttachShader(shader, v);
glAttachShader(shader, f);
glLinkProgram(shader);
if (check_error(shader, GL_LINK_STATUS, true)) {
LOGE("Failed to link shader");
}
glValidateProgram(shader);
if (check_error(shader, GL_VALIDATE_STATUS, true)) {
LOGE("Failed to validate shader");
}
Error Checking Code:
static bool check_error(unsigned int shader, unsigned int param, bool isProgram) {
int res = 123;
char log[2048] = { 0 };
if (isProgram) {
glGetProgramiv(shader, param, &res);
if (res == 0) {
glGetProgramInfoLog(shader, sizeof(log), 0, log);
LOGE("Shader: %s", log);
return true;
}
} else {
glGetShaderiv(shader, param, &res);
if (res == 0) {
glGetShaderInfoLog(shader, sizeof(log), 0, log);
LOGD("Shader %s", log);
return true;
}
}
return false;
}
Everything compiles just fine. But when I later call glGetAttribLocation to get the index of position, it return -1. I've also tried binding it before linking with glBindAttribLocation.
Querying all attributs with glGetActiveAttrib just return some junk. Same goes for the uniform "color" in the fragment shader.
I've tried running it on my phone (Galaxy S3) and on the Visual Studio Emulator For Android, same result on both of them.
My guess is that they get optimized out, but they shouldn't since I'm clearly using them and they contribute to the output.
Thanks in advance!