glGetAttribLocation返回-1,检查着色器是否编译成功,若编译不成功,打印原因
static int loadShader(int shaderType, const char* code){
int shader = glCreateShader(shaderType);
glShaderSource(shader, 1, &code, 0);
glCompileShader(shader);
// 获取着色器编译结果
GLint compiled = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
// 若编译失败,获取编译日志
if (!compiled)
{
// 获取编译日志的长度
GLint infoLen = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
if (infoLen)
{
// 获取编译日志
char* buf = (char*) malloc((size_t)infoLen);
if (buf)
{
glGetShaderInfoLog(shader, infoLen, NULL, buf);
LOGD("GLUtils::LoadShader Could not compile shader %d:\n%s\n", shaderType, buf);
free(buf);
}
glDeleteShader(shader);
shader = 0;
}
}
return shader;
}
|