You already mentioned the correct sized internal format for unsigned ints: R32UI
. The permissible formats are enumerated in table 8.15, found in section 8.9 of the OpenGL 4.4 Core Profile Specification. Please note that the contents of the buffer store will not be normalized when using texelFetch
on a buffer texture with the above internal format! That means, you don't get values in the range [0, 1] but in the range [0, 2^(n-1)] when doing lookups.
Instead of a samplerBuffer
you will also need a usamplerBuffer
.
If you do a texelFetch
on a samplerBuffer
with an internal format of R32UI
, as specified in the aforementioned table, will return an uvec4 where the components returned will contain the following values: uvec4(R, 0, 0, 1)
.
int vector1 = texelFetch(samplerObj, 0);
This will lead to a compile-time error, because there is no implicit conversion from uvec4
to int
.
int vector1 = texelFetch(samplerObj, 0).r;
this swizzle-mask will return the R-component of the uvec4 returned by texelFetch
and do an implicit conversion from uint
to int
. Semantically, it also doesn't make sense to name a scalar value a vector. ;)
What you actually want is something like
uint displacement = texelFetch(samplerObj, 0).r;
where samplerObj
is a usamplerBuffer
.
EDIT: Just to clarify, texelFetch
will always return a gvec4 - where g will simply by empty (fixed- and floating-point formats), i or u. How the vector is filled depends on the internal format of the buffer texture. If you choose R32F, you'll get a non-normalized vec4(R, 0, 0, 1), for RGBA16 you'll get a normalized vec4(R, G, B, A).
To avoid further confusion: you don't allocate memory for 4-component vectors when using a single-component format! They're all only expanded to a gvec4 on lookup!