PDA

View Full Version : Unchanged shader suddenly refuses to compile



CainitePrince
03-11-2015, 03:43 AM
Hi all,

I have a weird shader compilation issue that seems to come and go. The actual error message is this:

ERROR: 0:1: '' : version '150' is not supported
ERROR: 0:1: '' : syntax error #version

This is the shader:

std::string geometryVertexProgram =
"#version 150 core \n"
" \n"
"in vec4 position; \n"
"in vec3 normal; \n"
"uniform mat4 mvp; \n"
"uniform vec4 plane1; \n"
"uniform vec4 plane2; \n"
"uniform vec4 plane3; \n"
"uniform vec4 plane4; \n"
"uniform vec4 plane5; \n"
"uniform vec4 plane6; \n"
"out vec4 wsPosition; \n"
"out vec3 wsNormal; \n"
" \n"
"void main(void) \n"
"{ \n"
" wsPosition = position; \n"
" wsNormal = normal; \n"
" gl_ClipDistance[0] = dot(plane1, wsPosition); \n"
" gl_ClipDistance[1] = dot(plane2, wsPosition); \n"
" gl_ClipDistance[2] = dot(plane3, wsPosition); \n"
" gl_ClipDistance[3] = dot(plane4, wsPosition); \n"
" gl_ClipDistance[4] = dot(plane5, wsPosition); \n"
" gl_ClipDistance[5] = dot(plane6, wsPosition); \n"
" gl_Position = mvp * position; \n"
"} \n";

std::string geometryFragmentProgram =
"#version 150 core \n"
" \n"
"in vec4 wsPosition; \n"
"in vec3 wsNormal; \n"
"out vec4 color; \n"
"uniform vec3 lightdir1; \n"
"uniform vec3 lightdir2; \n"
"uniform vec3 lightdir3; \n"
"uniform vec3 camerapos; \n"
"uniform vec4 diffuse; \n"
"uniform vec4 ambient; \n"
"uniform vec4 specular; \n"
"uniform float shininess; \n"
"uniform float transparency; \n"
" \n"
"void main(void) \n"
"{ \n"
" vec3 n = normalize(wsNormal.xyz); \n"
" vec3 l1 = normalize(-lightdir1); \n"
" vec3 l2 = normalize(-lightdir2); \n"
" vec3 l3 = normalize(-lightdir3); \n"
" vec3 v = normalize(camerapos - wsPosition.xyz); \n"
" vec3 r1 = normalize(-reflect(l1, n)); \n"
" vec3 r2 = normalize(-reflect(l2, n)); \n"
" vec3 r3 = normalize(-reflect(l3, n)); \n"
" //mat3 m = mat3(l1, l2, l3); \n"
" float dotNL1 = dot(n, l1); \n"
" float dotNL2 = dot(n, l2); \n"
" float dotNL3 = dot(n, l3); \n"
" float lamb1 = 0.9 * clamp(dotNL1, 0.0, 1.0); \n"
" float lamb2 = 0.7 * clamp(dotNL2, 0.0, 1.0); \n"
" float lamb3 = 0.5 * clamp(dotNL3, 0.0, 1.0); \n"
" float phong1 = 0.9 * pow(max(dot(r1,v), 0.0), shininess); \n"
" float phong3 = 0.7 * pow(max(dot(r3,v), 0.0), shininess); \n"
" vec3 c; \n"
#ifdef WIN
" vec3 exp = vec3(2.2, 2.2, 2.2); \n"
#elif defined OSX
" vec3 exp = vec3(2.0, 2.0, 2.0); \n"
#endif
" c = (lamb1 + lamb2 + lamb3) * pow(diffuse.rgb, exp); \n"
" c += 0.2 * pow(ambient.rgb, exp); \n"
" c += (phong1 + phong3) * pow(specular.rgb, exp); \n"
" color = vec4(pow(c, vec3(1.0, 1.0, 1.0) / exp), transparency); \n"
"} \n";


The weird part is that other shaders, that also have the same version compile just fine. In fact some are nearly identical to this shader. The shader itself has been in use for a while and has previously compiled on the machine in question.

I'm compiling the shader like this:

OpenGLShader::OpenGLShader() : Shader(),
_vertexProgramCompiled(false),
_fragmentProgramCompiled(false)
{

_program = glCreateProgram();

assert(glGetError() == 0);
}

OpenGLShader::~OpenGLShader()
{

VERIFY(glDeleteProgram(_program));
}

bool OpenGLShader::SetVertexProgram(const std::string& src)
{

_vertexProgramCompiled = false;

const GLchar *source = (const GLchar *) src.c_str();

_vertexProgram = glCreateShader(GL_VERTEX_SHADER);
assert(glGetError() == 0);

VERIFY(glShaderSource(_vertexProgram, 1, &source, nullptr));
VERIFY(glCompileShader(_vertexProgram));
GLint isCompiled = 0;
VERIFY(glGetShaderiv(_vertexProgram, GL_COMPILE_STATUS, &isCompiled));
if (isCompiled == GL_FALSE)
{
PrintShaderLog(_vertexProgram);
VERIFY(glDeleteShader(_vertexProgram));
return false;
}

_vertexProgramCompiled = true;
return true;
}

bool OpenGLShader::SetFragmentProgram(const std::string& src)
{

_fragmentProgramCompiled = false;

const GLchar *source = (const GLchar *)src.c_str();

_fragmentProgram = glCreateShader(GL_FRAGMENT_SHADER);
assert(glGetError() == 0);

VERIFY(glShaderSource(_fragmentProgram, 1, &source, nullptr));
VERIFY(glCompileShader(_fragmentProgram));
GLint isCompiled = 0;
VERIFY(glGetShaderiv(_fragmentProgram, GL_COMPILE_STATUS, &isCompiled));
if (isCompiled == GL_FALSE)
{
PrintShaderLog(_fragmentProgram);
VERIFY(glDeleteShader(_fragmentProgram));
return false;
}

_fragmentProgramCompiled = true;
return true;
}

bool OpenGLShader::CompileShader()
{

if (false == _vertexProgramCompiled || false == _fragmentProgramCompiled)
{
return false;
}

VERIFY(glAttachShader(_program, _vertexProgram));
VERIFY(glAttachShader(_program, _fragmentProgram));

VERIFY(glBindAttribLocation(_program, 0, "position"));
VERIFY(glBindAttribLocation(_program, 1, "normal"));

VERIFY(glLinkProgram(_program));

GLint isLinked = 0;
VERIFY(glGetProgramiv(_program, GL_LINK_STATUS, &isLinked));
if (isLinked == GL_FALSE)
{
PrintProgramLog(_program);
}

VERIFY(glDetachShader(_program, _vertexProgram));
VERIFY(glDeleteShader(_vertexProgram));

VERIFY(glDetachShader(_program, _fragmentProgram));
VERIFY(glDeleteShader(_fragmentProgram));

return isLinked;
}


The OpenGL context is created like this:

NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
{
NSOpenGLPFAColorSize, 32,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFAStencilSize, 8,
NSOpenGLPFAAccelerated,
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
NSOpenGLPFAMultisample,
NSOpenGLPFASampleAlpha,
NSOpenGLPFASampleBuffers, 1,
NSOpenGLPFASamples, 8,
0
};
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc]
initWithAttributes: pixelFormatAttributes];
NSOpenGLContext* openGLContext = [[NSOpenGLContext alloc]
initWithFormat: pixelFormat shareContext:nil];

if (!(self = [super initWithCoder: aDecoder]))
{
return nil;
}

[self setPixelFormat: pixelFormat];
[self setOpenGLContext: openGLContext];
[openGLContext makeCurrentContext];


Info about the computer:

OS X 10.9.5
HW Vendor: Intel Inc.
Renderer: Intel HD Graphics 4000 OpenGL Engine
OpenGL 4.1 INTEL-8.28.32
GLSL 4.10

I'm stuck on this issue so any help will be greatly appreciated!

Greets,

Floris

arekkusu
03-11-2015, 02:23 PM
ERROR: 0:1: '' : version '150' is not supported


The only way you will get this error is with a legacy 2.1 context. When the error occurs, verify glGetString(GL_VERSION). Also check CGLGetCurrentContext(); contexts are set per-thread, perhaps you call some OS functionality which is making another context current?

CainitePrince
03-12-2015, 07:29 AM
The only way you will get this error is with a legacy 2.1 context. When the error occurs, verify glGetString(GL_VERSION). Also check CGLGetCurrentContext(); contexts are set per-thread, perhaps you call some OS functionality which is making another context current?

This info is pulled from OpenGL and inserted into the log, but it's pulled a lot earlier.

Intel Inc.
Intel HD Graphics 4000 OpenGL Engine
OpenGL 4.1 INTEL-8.28.32
GLSL 4.10

I will explicitly try glGetVersion just before the shader that fails. I will also try making our context current again before the shader is compiled.

Thanks for the ideas!

Greets,

Floris

CainitePrince
03-13-2015, 04:27 AM
Thx, making our context active again solved the problem. D'oh, such an easy fix, but it didn't occur to me. It makes sense, because the GUI uses OpenGL for rendering too and there's a file dialog displayed before loading.

Greets,

Floris