snapfractalpop
snapfractalpop

Reputation: 2134

Why do we compile shaders at runtime in OpenGL 2?

I have been trying to learn OpenGL, specifically for Android. I have seen various tutorials online, and I noticed that many of the tutorials for OpenGL 1.0, or 1.2 do not require compilation of shader programs, while the only tutorials I could find for OpenGL 2.0 all involve creating a custom shader to render shapes in the view.

The process of using a string to hold code (GLSL) and then compiling and linking this code at run-time feels cumbersome (hacky even). Is this necessary because GPU architectures can vary greatly?

Is there a way to use some kind of default shaders that don't require this step (like a built in shader)? I just want to be able to draw primitives like GL_POINTS, GL_LINES, etc.

Upvotes: 4

Views: 2581

Answers (1)

ratchet freak
ratchet freak

Reputation: 48196

Is this necessary because GPU architectures can vary greatly?

Yes indeed and while there has been mentioning of an IR version of shaders there hasn't been a proper consensus about how it should look.

You can use glShaderBinary to precompile the shader in a previous run and reuse the compiled output.

Upvotes: 7

Related Questions