Reputation: 719
Some of my vertex attributes are single unsigned bytes, I need them in my GLSL fragment shader, not for any "real" calculations, but for comparing them (like enums if you will). I didnt find any unsigned byte or even byte data type in GLSL, so is there a way as using it as an input? If not (which at the moment it seems to be) what is the purpose of GL_UNSIGNED_BYTE?
Upvotes: 15
Views: 15576
Reputation: 473537
GLSL doesn't deal in sized types (well, not sized types smaller than 32-bits). It only has signed/unsigned integers, floats, doubles, booleans, and vectors/matrices of them. If you pass an unsigned byte as an integer vertex attribute to a vertex shader, then it can read it as a uint
type, which is 32-bits in size. Passing integral attributes requires the use of glVertexAttribIPointer/IFormat
(note the "I").
The vertex shader can then pass this value to the fragment shader as a uint
type (but only with the flat
interpolation qualifier). Of course, every fragment for a triangle will get the same value.
Upvotes: 19