In my OpenGL ES 2.0 program on iOS I compile my shaders as follows:
setShaderState(state);//enables or disables GL_BLEND
GLuint vertexShader = compileShaderPart(vertexShader, GL_VERTEX_SHADER, state);
GLuint fragmentShader = compileShaderPart(fragmentShader, GL_FRAGMENT_SHADER, state);
//linking
GLuint programHandle = glCreateProgram();
Assert(programHandle != 0, "Program handle 0");
for(auto shaderAttribute : shaderAttributeList){
if(isVertexAttribute(shaderAttribute.attribute())){
glBindAttribLocation(programHandle, shaderAttribute.attribute(), shaderAttribute.attributeName(1).c_str());
}
}
glAttachShader(programHandle, vertexShader);
glAttachShader(programHandle, fragmentShader);
glLinkProgram(programHandle);
Assert(glGetError() == GL_NO_ERROR, "Could not link program");
GLint linkSuccess;
glGetProgramiv(programHandle, GL_LINK_STATUS, &linkSuccess);
if (linkSuccess == GL_FALSE) {
GLchar messages[256];
glGetProgramInfoLog(programHandle, sizeof(messages), 0, &messages[0]);
ELog << messages;
Assert(0, "Error compiling shader");
}
ShaderUniformHandleMap shaderUniformMap;
Shader *shader = new Shader(programHandle, availableShader.name, shaderUniformMap, state);
glUseProgram(programHandle);
auto mesh = Mesh::load("quad");
shader->bindMesh(mesh);
auto temp_texture = Texture2D::load("checker");
for(auto uniform : shader->texture){
glUniform1i(uniform.handle, shader->bindTexture(temp_texture->textureId()));
}
glDrawElements(GL_TRIANGLES, mesh->indexDataSize(), GL_UNSIGNED_SHORT, 0);
I left the uniform reading part out for readability and the compileShaderPart function is as straight forward as can be.
Running the app in the openGL ES Analyzer in instruments yields hundreds of occurances of the "Shader compiled outside of a prewarming phase" problem. Shouldn't the glDrawElements call take care of that?
I've read that changing states like GL_Blend can have that impact, so I'm compiling the same shader twice, once with GL_Blend enabled and once disabled, but it didn't make any difference.
What's the problem here? I also find it difficult to find Information about this prewarming stuff, so far I've gathered that the shader is only really compiled after the first draw call, which is why I'm drawing that quad in the end.