[osg-users] OpenGL Shader Compile Problem: repeated #version directive

381 views
Skip to first unread message

Elias Tarasov

unread,
Jul 18, 2015, 10:31:47 AM7/18/15
to osg-...@lists.openscenegraph.org
Hello!

GPU: nVidia 540M
Driver: 353.30
OpenGL version: 4.3.
OS Windows 7

I intend to use osgHimmel library in my project.
However, when i run the app, i get the shader's compile error:

Atmopshere Precomputed (took 7.95881 s)
Warning, can't assign attribute binding as no has been array assigned to set binding
PNG lib warning : iCCP: known incorrect sRGB profile
PNG lib warning : iCCP: known incorrect sRGB profile
VERTEX glCompileShader "" FAILED
VERTEX Shader "" infolog:
0(5) : error C0204: version directive must be first statement and may not be repeated

FRAGMENT glCompileShader "" FAILED
FRAGMENT Shader "" infolog:
0(5) : error C0204: version directive must be first statement and may not be repeated

glLinkProgram "" FAILED
Program "" infolog:
Vertex info
-----------
0(5) : error C0204: version directive must be first statement and may not be repeated

Fragment info
-------------
0(5) : error C0204: version directive must be first statement and may not be repeated

VERTEX glCompileShader "" FAILED
VERTEX Shader "" infolog:
0(5) : error C0204: version directive must be first statement and may not be repeated

GEOMETRY glCompileShader "" FAILED
GEOMETRY Shader "" infolog:
0(5) : error C0204: version directive must be first statement and may not be repeated

FRAGMENT glCompileShader "" FAILED
FRAGMENT Shader "" infolog:
0(5) : error C0204: version directive must be first statement and may not be repeated

glLinkProgram "" FAILED
Program "" infolog:
Vertex info
-----------
0(5) : error C0204: version directive must be first statement and may not be repeated

Geometry info
-------------
0(5) : error C0204: version directive must be first statement and may not be repeated

Fragment info
-------------
0(5) : error C0204: version directive must be first statement and may not be repeated

VERTEX glCompileShader "" FAILED
VERTEX Shader "" infolog:
0(5) : error C0204: version directive must be first statement and may not be repeated

FRAGMENT glCompileShader "" FAILED
FRAGMENT Shader "" infolog:
0(5) : error C0204: version directive must be first statement and may not be repeated

glLinkProgram "" FAILED
Program "" infolog:
Vertex info
-----------
0(5) : error C0204: version directive must be first statement and may not be repeated

Fragment info
-------------
0(5) : error C0204: version directive must be first statement and may not be repeated

VERTEX glCompileShader "" FAILED
VERTEX Shader "" infolog:
0(5) : error C0204: version directive must be first statement and may not be repeated

FRAGMENT glCompileShader "" FAILED
FRAGMENT Shader "" infolog:
0(5) : error C0204: version directive must be first statement and may not be repeated

glLinkProgram "" FAILED
Program "" infolog:
Vertex info
-----------
0(5) : error C0204: version directive must be first statement and may not be repeated

Fragment info
-------------
0(5) : error C0204: version directive must be first statement and may not be repeated

Warning: detected OpenGL error 'invalid enumerant' at after RenderBin::draw(..)
Warning: detected OpenGL error 'invalid value' at after RenderBin::draw(..)

I have several objects, each of which uses Vertex, Fragment, and Geometry shaders.
With a help of community's members here, i found the place where the error might be:

const std::string glsl_version_150()
{
static const std::string source(PRAGMA_ONCE(version,"#version 150 compatibility\n\n"));
return source;
};

This function is called every time to create any shader. And therefore #version directive is realy called multiple times.
According to OpenGL SL #version must be the first line and cannot be repeated.
However, this definition is unclear: Is #version must be the one and only one for the entire host OpenGL program? For the host object that uses shader? Or for every single main() entry of the shader?

Can anybody pointed out how to solve that issue?

Thank you!

Cheers,
Elias

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64358#64358





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Sebastian Messerschmidt

unread,
Jul 19, 2015, 11:22:12 AM7/19/15
to osg-...@lists.openscenegraph.org
Am 18.07.2015 um 16:32 schrieb Elias Tarasov:
> Hello!
>
> GPU: nVidia 540M
> Driver: 353.30
> OpenGL version: 4.3.
> OS Windows 7
>
> I intend to use osgHimmel library in my project.
> However, when i run the app, i get the shader's compile error:
>
> Atmopshere Precomputed (took 7.95881 s)
> Warning, can't assign attribute binding as no has been array assigned to set binding
> PNG lib warning : iCCP: known incorrect sRGB profile
> PNG lib warning : iCCP: known incorrect sRGB profile

> </snip>
> 0(5) : error C0204: version directive must be first statement and may not be repeated
>
> Warning: detected OpenGL error 'invalid enumerant' at after RenderBin::draw(..)
> Warning: detected OpenGL error 'invalid value' at after RenderBin::draw(..)
>
> I have several objects, each of which uses Vertex, Fragment, and Geometry shaders.
> With a help of community's members here, i found the place where the error might be:
>
> const std::string glsl_version_150()
> {
> static const std::string source(PRAGMA_ONCE(version,"#version 150 compatibility\n\n"));
> return source;
> };

Where is this line of code? Inside your code?
>
> This function is called every time to create any shader. And therefore #version directive is realy called multiple times.
> According to OpenGL SL #version must be the first line and cannot be repeated.
> However, this definition is unclear: Is #version must be the one and only one for the entire host OpenGL program? For the host object that uses shader? Or for every single main() entry of the shader?
Each source string needs to have the version line once and at the
beginning. Basically everything you load via loadShaderSource or
setShaderSource. (glShaderSource basically)
>
> Can anybody pointed out how to solve that issue?
I'm afraid you will need to check the osgHimmel code for this if it is
setting up the shaders. Have you tried to comment out the line above?
Have you debugged with geDebugger or glIntercept to see which shader
source is sent to the driver? (You can also check the osg::Shader apply
i think).
Also check the osgShader example. Is it running as expected?

As long as you don't provide more information on what is going wrong on
your side, chances are slim we can help you

Elias Tarasov

unread,
Jul 19, 2015, 9:44:52 PM7/19/15
to osg-...@lists.openscenegraph.org
Hi!

1.

>
>
> >
> > </snip>
> > 0(5) : error C0204: version directive must be first statement and may not be repeated
> >
>
> Where is this line of code? Inside your code?
>


No, that line is in osgHimmel code.

2.

>
> Have you tried to comment out the line above?
>


Yes, and in this case the error is:

Atmopshere Precomputed (took 7.45826 s)
Warning, can't assign attribute binding as no has been array assigned to set binding for.
PNG lib warning : iCCP: known incorrect sRGB profile
PNG lib warning : iCCP: known incorrect sRGB profile
VERTEX glCompileShader "" FAILED
VERTEX Shader "" infolog:
0(27) : error C5060: out can't be used with non-varying m_eye
0(28) : error C5060: out can't be used with non-varying m_ray

glLinkProgram "" FAILED
Program "" infolog:
Vertex info
-----------
0(27) : error C5060: out can't be used with non-varying m_eye
0(28) : error C5060: out can't be used with non-varying m_ray

Fragment info
-------------
0(106) : warning C7011: implicit cast from "int" to "float"
0(106) : warning C7011: implicit cast from "int" to "float"

VERTEX glCompileShader "" FAILED
VERTEX Shader "" infolog:
0(90) : error C5060: out can't be used with non-varying v_k
0(91) : error C5060: out can't be used with non-varying v_color
0(98) : warning C7011: implicit cast from "int" to "float"
0(113) : warning C7011: implicit cast from "int" to "float"
0(113) : warning C7011: implicit cast from "int" to "float"
0(119) : warning C7011: implicit cast from "int" to "float"
0(124) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(124) : warning C7011: implicit cast from "int" to "float"
0(124) : warning C7011: implicit cast from "int" to "float"
0(125) : warning C7532: global function texture requires "#version 130" or later

GEOMETRY glCompileShader "" FAILED
GEOMETRY Shader "" infolog:
0(46) : error C0000: syntax error, unexpected '(', expecting "::" at token "("
0(54) : error C5060: out can't be used with non-varying g_color
0(58) : warning C7011: implicit cast from "int" to "float"
0(63) : warning C7532: global variable gl_in requires "#version 150" or later
0(63) : warning C7532: global variable gl_Position requires "#version 150" or later

glLinkProgram "" FAILED
Program "" infolog:
Vertex info
-----------
0(90) : error C5060: out can't be used with non-varying v_k
0(91) : error C5060: out can't be used with non-varying v_color
0(98) : warning C7011: implicit cast from "int" to "float"
0(113) : warning C7011: implicit cast from "int" to "float"
0(113) : warning C7011: implicit cast from "int" to "float"
0(119) : warning C7011: implicit cast from "int" to "float"
0(124) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(124) : warning C7011: implicit cast from "int" to "float"
0(124) : warning C7011: implicit cast from "int" to "float"
0(125) : warning C7532: global function texture requires "#version 130" or later

Geometry info
-------------
0(46) : error C0000: syntax error, unexpected '(', expecting "::" at token "("
0(54) : error C5060: out can't be used with non-varying g_color
0(58) : warning C7011: implicit cast from "int" to "float"
0(63) : warning C7532: global variable gl_in requires "#version 150" or later
0(63) : warning C7532: global variable gl_Position requires "#version 150" or later

Fragment info
-------------
0(18) : warning C7011: implicit cast from "int" to "float"
0(20) : warning C7011: implicit cast from "int" to "float"
0(27) : warning C7011: implicit cast from "int" to "float"
0(28) : warning C7011: implicit cast from "int" to "float"

VERTEX glCompileShader "" FAILED
VERTEX Shader "" infolog:
0(8) : error C5060: out can't be used with non-varying m_tangent
0(9) : error C5060: out can't be used with non-varying m_eye

glLinkProgram "" FAILED
Program "" infolog:
Vertex info
-----------
0(8) : error C5060: out can't be used with non-varying m_tangent
0(9) : error C5060: out can't be used with non-varying m_eye

Fragment info
-------------
0(114) : warning C7011: implicit cast from "int" to "float"
0(118) : warning C7011: implicit cast from "int" to "float"
0(120) : warning C7011: implicit cast from "int" to "float"
0(120) : warning C7011: implicit cast from "int" to "float"
0(120) : warning C7011: implicit cast from "int" to "float"
0(120) : warning C7011: implicit cast from "int" to "float"
0(120) : warning C7011: implicit cast from "int" to "float"
0(122) : warning C7011: implicit cast from "int" to "float"
0(123) : warning C7011: implicit cast from "int" to "float"
0(123) : warning C7011: implicit cast from "int" to "float"
0(127) : warning C7011: implicit cast from "int" to "float"
0(129) : warning C7011: implicit cast from "int" to "float"
0(135) : warning C7011: implicit cast from "int" to "float"
0(144) : warning C7011: implicit cast from "int" to "float"
0(171) : warning C7011: implicit cast from "int" to "float"
0(171) : warning C7011: implicit cast from "int" to "float"
0(171) : warning C7011: implicit cast from "int" to "float"
0(171) : warning C7011: implicit cast from "int" to "float"
0(187) : warning C7011: implicit cast from "int" to "float"
0(187) : warning C7011: implicit cast from "int" to "float"
0(198) : warning C7011: implicit cast from "int" to "float"
0(198) : warning C7011: implicit cast from "int" to "float"

VERTEX glCompileShader "" FAILED
VERTEX Shader "" infolog:
0(27) : error C5060: out can't be used with non-varying m_ray

glLinkProgram "" FAILED
Program "" infolog:
Vertex info
-----------
0(27) : error C5060: out can't be used with non-varying m_ray

Fragment info
-------------
0(19) : warning C7011: implicit cast from "int" to "float"
0(20) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(20) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(22) : warning C7011: implicit cast from "int" to "float"
0(23) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(23) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(26) : warning C7548: '&' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(60) : warning C7532: global type uvec4 requires "#version 130" or later
0(60) : warning C0000: ... or #extension GL_EXT_gpu_shader4 : enable
0(60) : warning C7532: global type uint requires "#version 130" or later
0(60) : warning C0000: ... or #extension GL_EXT_gpu_shader4 : enable
0(60) : warning C7011: implicit cast from "int" to "float"
0(62) : warning C7548: '%' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(62) : warning C7011: implicit cast from "int" to "float"
0(351) : warning C7011: implicit cast from "int" to "float"
0(355) : warning C7011: implicit cast from "int" to "float"
0(20) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(20) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(23) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(23) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(26) : warning C7548: '&' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(62) : warning C7548: '%' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(62) : warning C7548: '%' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(20) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(20) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(23) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(23) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(26) : warning C7548: '&' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '%' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '&' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '&' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '%' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '%' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '&' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '<<' requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(355) : warning C7548: '^' requires "#extension GL_EXT_gpu_shader4 : enable" before use

Warning: detected OpenGL error 'invalid enumerant' at after RenderBin::draw(..)

3.

>
> Have you debugged with geDebugger or glIntercept to see which shader
> source is sent to the driver? (You can also check the osg::Shader apply
> i think).
>


Here is the header pattern of all osgHimmel shaders under gDEBugger:

#ifndef __version__
#define __version__

#version 150 compatibility

#endif // __version__

4.

>
> Also check the osgShader example. Is it running as expected?
>


Yes, osgShaders works fine.

5. Also, i found that link:
https://www.opengl.org/discussion_boards/showthread.php/185603-Managing-several-versions-in-a-single-shader-file
There is a solution that maybe works: somehow pass version number through API.

Or something else maybe?

Thanks for help and patience!

Cheers,
Elias

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64364#64364

Sebastian Messerschmidt

unread,
Jul 20, 2015, 3:24:09 AM7/20/15
to osg-...@lists.openscenegraph.org
Hi Elias,

First of all, please try to condense the error logs to a minimum when
posting them. (and maybe attach them if you think someone wants to read
them ;-))

> Hi!
>
> 1.
>
>>
>>> </snip>
>>> 0(5) : error C0204: version directive must be first statement and may not be repeated
>>>
>> Where is this line of code? Inside your code?
>>
>
> No, that line is in osgHimmel code.
>
> 2.
>
>> Have you tried to comment out the line above?
>>
>
> Yes, and in this case the error is:
>
> Atmopshere Precomputed (took 7.45826 s)
> Warning, can't assign attribute binding as no has been array assigned to set binding for.
> PNG lib warning : iCCP: known incorrect sRGB profile
> PNG lib warning : iCCP: known incorrect sRGB profile
> VERTEX glCompileShader "" FAILED
> VERTEX Shader "" infolog:
> 0(27) : error C5060: out can't be used with non-varying m_eye
> 0(28) : error C5060: out can't be used with non-varying m_ray
Okay that means you really need version 1.5 or above.
> ...
> 3.
>
>> Have you debugged with geDebugger or glIntercept to see which shader
>> source is sent to the driver? (You can also check the osg::Shader apply
>> i think).
>>
>
> Here is the header pattern of all osgHimmel shaders under gDEBugger:
>
> #ifndef __version__
> #define __version__
>
> #version 150 compatibility
>
> #endif // __version__
Okay if I understand your initial error message correctly, the above
code is the troublemaker
the first line is #ifndef and not the #version ...
I believe the above construct might be considered invalid as #version
and #ifdef are both preprocessor tags. So first line literally means
first line of the source.
> 4.
>
>> Also check the osgShader example. Is it running as expected?
>>
>
> Yes, osgShaders works fine.
>
> 5. Also, i found that link:
> https://www.opengl.org/discussion_boards/showthread.php/185603-Managing-several-versions-in-a-single-shader-file
> There is a solution that maybe works: somehow pass version number through API.
I would contact the author of osgHimmel to fix the above problem. You
could try yourself by removing the #ifdef and put the version in the
first line for a quick check.
Unfortunately I cannot help you further with this as it seems specific
to osgHimmel.

Cheers
Sebastian

Elias Tarasov

unread,
Jul 20, 2015, 3:41:55 AM7/20/15
to osg-...@lists.openscenegraph.org
That would be great if you contact osgHimmel authors :)
Meanwhile of course i try to fix it by myself.

...

Thank you!

Cheers,
Elias

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64368#64368

Sebastian Messerschmidt

unread,
Jul 20, 2015, 4:42:35 AM7/20/15
to osg-...@lists.openscenegraph.org
Am 20.07.2015 um 09:42 schrieb Elias Tarasov:
> That would be great if you contact osgHimmel authors :)
> Meanwhile of course i try to fix it by myself.
Can't you do this yourself? I can delay some information to them or
explain what might be the problem, but you should establish the contact

Cheers
Sebastian

Elias Tarasov

unread,
Jul 20, 2015, 5:14:08 AM7/20/15
to osg-...@lists.openscenegraph.org
Fixed! :)
The solution (in that particular case) is straightforward.
The code:

Code:

const std::string glsl_version_150()
{
static const std::string source(PRAGMA_ONCE(version,"#version 150 compatibility\n\n"));
return source;
};




must be replaced by:


Code:

const std::string glsl_version_150()
{
static const std::string source("#version 150 compatibility\n\n");
return source;
};




Thank you for help and great patience!

Cheers,
Elias

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64378#64378
Reply all
Reply to author
Forward
0 new messages