GLSL & "Out" qualifier question. Hopefully Easy

Now that ‘varying’ is depreciated, trying to move my code to the new standard of ‘in’ and ‘out’. I can get the new in syntax to work just fine, but any time I touch the ‘out’ qualifier my shader fails to compile.

Lets say I have two shaders, vertex and fragment:

VERTEX SHADER
out float TestVar;
void main() {
TestVar = 1.0f;
// Set the position of the current vertex
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

FRAGMENT SHADER
in float TestVar;
void main() {
// Set the output color of our current pixel
gl_FragColor = Somecolor;
}

Am I missing something here? Do i need to bind out variables like I do ‘In’ variables? Or somehow allocate space for them, I have a feeling that I’m missing something in the OpenGL to GLSL interface.

Hope this is an easy one for someone here. The old depreciated ‘varying’ qualifier still works perfectly fine.

any time I touch the ‘out’ qualifier my shader fails to compile.

What is the compiler log?

error C5060: out can’t be used with non-varying TestVar

Which is why I’m baffled, the whole point of out is to get RID of the ‘varying’ qualifier.

Running OpenGL 3.3 and
GLSL…
glGetString(GL_SHADING_LANGUAGE_VERSION)
returns: “3.30 NVIDIA via Cg compiler”

You’ve got to use GLSL 1.3 or greater to get in/out (e.g. “#version 130”). Turns out with 1.3 though you lose the legacy built-in uniforms/attributes. So your vertex shader becomes:


#version 130

uniform mat4 my_ModelViewProjectionMatrix ;

in  vec4  my_Vertex;
out float TestVar;

void main() {
TestVar = 1.0f;
// Set the position of the current vertex
gl_Position = my_ModelViewProjectionMatrix * my_Vertex;
}

That fixed it, thank you. Glad to ditch the legacy stuff too.

You’ll need to specify the GLSL version (330), and you cannot use gl_FragColor, instead use a custom variable bound to location 0.

In the shader:


#version 330
out vec4 fragColour;
...
fragColour = vec4(...)

In your source file:


glBindFragDataLocation(fProgramID, 0, "fragColour");

You could also do:


#version 330 compatibility

if you wish to use GL state values that are in the compatibility profile (such as gl_ModelViewMatrix, etc)

instead use a custom variable bound to location 0.

If you only have one output variable in a fragment shader, OpenGL automatically assigns it to location 0. So there’s no need to do that.

Just wanted to say thank you for the feedback from this forum, trying my best to contribute as well, but being new here, well, everything is pretty new.

Anyways, here’s an update of the project. Basically it’s OpenGL 3.2 and GLSL version 150, which means defining your own 3d structural paramters (Quaternions in this case) and how they interact with your custom shaders to get stuff on screen.

My implementation pretty much mimics that of the old client side OpenGL only everything has been moved to Server Side with no dependency on any depreciated functions.

Works perfectly well, working on dynamic lights next, have some ideas that are very non standard. Loving GLSL.

Ah, and another thing, perhaps I haven’t gotten to this yet. (Still working my way through the GLSL book, wish it wasn’t based on 140, later chapters to go)

Can you access the current color of the x y coord of your fragments current draw buffer before you draw over whatever is at that x y screen coord? (I realize that you still enable blending ect in OpenGL 3.2)

Can you access the current color of the x y coord of your fragments current draw buffer before you draw over whatever is at that x y screen coord? (I realize that you still enable blending ect in OpenGL 3.2)

In unextended GL the answer is a resounding no. However, there are a few things hanging around that let you do some things:

GL4 hardware: GL_EXT_shader_image_load_store
This does NOT give you access to the previous fragment value, but rather random read and write access to a GL texture.

GL3 NVIDIA hardware: GL_NV_texture_barrier
This extension lets you, with strong limitations, bind a texture for reading and use that texture at the same time as a render target of an FBO. Read the spec to check it out.

In the mobile space, for NVIDIA Tegra, there is the ability to read the previous value of the fragment: GL_NV_shader_framebuffer_fetch, you’ll need to go to developer.tegra.com and download the pdf’s to read up on it.

all good info, thank you. more PDFs for the kindle.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.