I've noticed my game has a lag spike whenever an object using a unique material is shown on screen for the first time.
I've read up and learned that OpenGL is "lazily" compiling the shaders when the game is already running, so a when an object using a previously unused material appears, that frame needs to wait until the shader is compiled before it can be rendered - hence stopping the game dead in it's tracks until the shader is ready.
I think these lag spikes are unacceptable as they completely break the flow of the game. So far the only solutions I've heard is to render a frame with all the materials we'll be using in our game to force the shader compilation at the beginning, so they are ready for later.
That sounds like a very crude workaround.
I believe there has to be a better way to deal with this issue. So what is it?