GLSL Type Qualifiers

Started by
14 comments, last by rewolfer 14 years ago
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.
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"


[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
AFAIK, uniform still stands in the core profile.
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?
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);

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

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?

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...
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.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
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]
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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement