Reputation: 2204
I have normals which are (x,y,z) as 3 floats, and I want to pack these into a VBO array as GL_INT_2_10_10_10_REVs in order to reduce memory consumption on the graphics card. Can anyone provide an example of how to do this in C++ / C#?
The OpenGL documentation says you can do this - https://www.opengl.org/wiki/Vertex_Specification_Best_Practices
However, I can't find any examples of how to place the three floats (which can be positive or negative) into the single packed 4 byte structure.
Upvotes: 1
Views: 1097
Reputation: 52167
Check the spec, section 10.3.8, "Packed Vertex Data Formats", page 343:
For
INT_2_10_10_10_REV
, the x, y and z components are represented as 10-bit signed two’s complement integer values and the w component is represented as a 2-bit signed two’s complement integer value.
Upvotes: 1
Reputation: 48226
You'll need to pack them in a bitfield that looks something like:
struct norm{
int a:2;
int Z:10;
int y:10;
int X:10; //order may need to be different
}
ensure the field you put in are scaled to -512
to 511
Upvotes: 5