Reputation: 406
I can't seem to find out how to get the size, in scalars, (or bytes) of a uniform in GLSL.
Currently I call glGetActiveUniform as I enumerate all my shader constants, but the size parameter it returns is an array size, not a variable size.
Is there a function to get the data size? Or a function that maps the ConstantType to its size?
Here's my code, for completeness:
char ConstantName[ 128 ];
GLint ConstantArraySize;
GLenum ConstantType;
glGetActiveUniform( Program, ConstantIndex, 128, nullptr, &ConstantArraySize, &ConstantType, ConstantName );
Upvotes: 2
Views: 4016
Reputation: 474406
The size of a uniform in GLSL is only relevant if that uniform is stored in a uniform block. For non-block uniforms, you don't care; you upload them with glUniform*
and let OpenGL handle any conversions.
For uniform block members, each uniform of basic type has a specific byte size. Individual integers and floats are 32-bits in size. Vectors of those types are that size * the number of components. Matrices are more complex; they are stored as column/row (you can pick) vectors. The stride between columns/rows issomething you have to query, with glGetActiveUniformsiv
(note the "s").
Unless you use std140 layout of course, in which case the matrix stride is always 4 * the number of the basic component type. So in std140 layout, a mat4x2
, stored column-major, represents 4 column vectors of vec2
s, but the stride between individual column vectors is 4 * sizeof(float), not 2 * sizeof(float). So there's 2 floats worth of padding.
In short, there's no reason to care. If it's a non-block uniform, the size is irrelevant. If it's a uniform block uniform, then you should be using std140 layout anyway and thus can compute it a priori.
Upvotes: 3
Reputation: 839
To my knowledge, the size of all data types in OpenGL are standardized. floats and ints are 32 bits, doubles are 64. Using the information given to you by glGetActiveUniform()
, you can work out the size of a uniform variable yourself. Having a GL function to do that for you would be superfluous.
Upvotes: 1