Jump to content
  • Advertisement
Sign in to follow this  
X Abstract X

GLSL Type Qualifiers

This topic is 2989 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just started reading up on GLSL but I haven't been able to find any information on using "in" and "out" qualifiers. The examples I've seen all use "attribute" "varying" and "uniform". From what I understand, using "in" and "out" replaces the need to use any of the other special type qualifiers but, I'm probably confused and wrong. So can someone please point out the correct, most up-to-date way to use type qualifiers in GLSL? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
No you're pretty much right.

Attribute, Varying, Uniform used to be the definitions, but in newer versions of glsl they were just replaced by "in" and "out".

Vertex Shader:
"uniform" becomes "in"
"attribute" becomes "in"
"varying" becomes "out"

Fragment Shader:
"uniform" becomes "in"
"varying" becomes "in"


Share this post


Link to post
Share on other sites
Alright cool, thanks for clarifying. I've got another small question. I noticed there's some variables that seem to get/set values directly by interacting with OpenGL automatically, is this correct?

gl_ProjectionMatrix
gl_Position
gl_FragColor

The values I assign to gl_Position and gl_FragColor will be sent to OpenGL as the final vertex position and the final fragment color automatically. Is this right? If this is true, how can I tell the Shader what my projection matrix is?

Share this post


Link to post
Share on other sites
Quote:
Original post by X Abstract X
The values I assign to gl_Position and gl_FragColor will be sent to OpenGL as the final vertex position and the final fragment color automatically. Is this right?
Yes, but only for older versions of OpenGL (or the compatibility profile). Newer versions of OpenGL have removed all implicit attributes and uniforms, so you have to setup all of this functionality yourself.
Quote:
If this is true, how can I tell the Shader what my projection matrix is?
glMatrixMode(GL_PROJECTION);
glLoadMatrix(matrix);

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Quote:
Original post by X Abstract X
The values I assign to gl_Position and gl_FragColor will be sent to OpenGL as the final vertex position and the final fragment color automatically. Is this right?
Yes, but only for older versions of OpenGL (or the compatibility profile). Newer versions of OpenGL have removed all implicit attributes and uniforms, so you have to setup all of this functionality yourself.
Quote:
If this is true, how can I tell the Shader what my projection matrix is?
*** Source Snippet Removed ***


Ok thanks but I was under the impression that glMatrixMode() was deprecated. Is it?

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Yes, but only for older versions of OpenGL (or the compatibility profile). Newer versions of OpenGL have removed all implicit attributes and uniforms, so you have to setup all of this functionality yourself.
Just out of curiosity (currently I'm still using OpenGL 2.0, my graphics card sucks...), do you have an example at hand that shows how to do that? I've been getting rid of most of the fixed function stuff in my code lately and I was wondering how this would be done...

Share this post


Link to post
Share on other sites
Quote:
Ok thanks but I was under the impression that glMatrixMode() was deprecated. Is it?


Yes it is depreciated.

For core profile you have to send matrices yourself to the shader via 4x4 uniforms.

Share this post


Link to post
Share on other sites
Quote:
Original post by karwosts
Quote:
Ok thanks but I was under the impression that glMatrixMode() was deprecated. Is it?


Yes it is depreciated.

For core profile you have to send matrices yourself to the shader via 4x4 uniforms.


Thanks. This is a rediculous question but, how do you send data to a shader? I understand how to send vertex data from a VBO but not matrices like that.

Edit: Oh I guess you use glUniformMatrix4fv()

[Edited by - X Abstract X on April 11, 2010 8:11:13 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by kloffy
Just out of curiosity (currently I'm still using OpenGL 2.0, my graphics card sucks...), do you have an example at hand that shows how to do that? I've been getting rid of most of the fixed function stuff in my code lately and I was wondering how this would be done...
Retrieve the attribute binding point by name from the shader with glGetAttribLocation(), enable the relevant attribute array with glEnableVertexAttribArray(), and provide the data with glVertexAttribPointer().

Under 3.0 or greater you need to use VBO to store your attribute arrays, but for 2.0 or 3.0 compatability profile, you can continue to use vertex array, or even fixed function with glVertexAttrib*().

See here for more details.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!