Danny Ruijters
Danny Ruijters

Reputation: 3429

GLSL: What version is used when no version is specified?

When there is no version specified in the first line of a GLSL shader (so nothing like "#version 330", which version is actually used?

Is it vendor (or even driver) specific?

Upvotes: 2

Views: 1610

Answers (1)

vallentin
vallentin

Reputation: 26245

What is the default GLSL version?

  • Assume the default version is 1.10
  • Note that the #version directive always must be on the first line

The #version directive must appear before anything else in a shader, save for whitespace and comments. If a #version directive does not appear at the top, then it assumes 1.10, which is almost certainly not what you want.

OpenGL Wiki

If it's in relation to combining sources, then you could leave out the #version directive and do something like this:

const GLsizei stringCount = 2;
const GLchar *strings[stringCount] = {
    "#version 330 core\n",
    shaderSource,
};

glShaderSource(shader, stringCount, strings, NULL);

Upvotes: 6

Related Questions