How to fix the delay when using the shader for the first time?

I ran the OpenGL ES analysis tool from the tools in my application, and it stated that after compiling the shader I should make a glDrawArrays call in a prewarm pass. Therefore, I checked the time of some shaders that I wrote, and indeed, the first time the program starts, it is much slower.

In my code, I have a common shader loader that does not know the shader form / attributes, it just compiles it. And it seems like the best place to pre-heat the shader is (so I don't need to add glDrawArrays everywhere). I tried adding this to my shader loader:

glUseProgram(prog);
glDrawArrays(GL_TRIANGLES, 0, 0);

He fixed the delay, but since I am not setting any uniforms / attributes, I am not sure if it is safe. Also, it kind of looks like a workaround. What is the best way to pre-program a program?

+5
source share
1 answer

your code is (almost) completely safe. The form is not a problem, as they contain some default values. As for attributes, this is not a problem since you are not radiating any vertices.

, , . , ( ). , . , , Unreal Tournament, "Precaching" . .

+2

All Articles