🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to use a non-standard vertex format?

Started by
5 comments, last by idinev 14 years, 6 months ago
(Using OpenGL 3.2) When specifying the vertex format for a VBO using glVertexPointer, glNormalPointer, ect..., you specify the number of components (usually) as well as a data type (short, int, float, or double). My question is, is there any way to specify data types other than this *very* limited set? In directx for example, I can use half floats as well as numerous compressed types. So I *know* the hardware can do it, but is this functionality exposed in OpenGL? The data type I'm most interested in using is R10G10B10A2 for my normals, though I don't see any way of specifying this with glNormalPointer...
Advertisement
There's no support for R10G10B10A2 as vtx attribs yet. Though, you can get much nicer precision with 2 half-floats and computing the z.

Btw, you shouldn't be using glVertexPointer/etc with 3.2 .
Half float is sopported : GL_HALF_FLOAT
That other format you mentioned is a texture format. I don't think you can use that as a attribute but you can make such a texture with GL and sample it with a vertex shader.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote: Original post by coderchris
So I *know* the hardware can do it, but is this functionality exposed in OpenGL?

Yes, OpenGL has no problems with half-floats for vertex attributes.
Ah ok so I can use halfs, I guess this page is out of date: http://www.opengl.org/sdk/docs/man/xhtml/glVertexPointer.xml

I could use 2 half floats and compute Z, but how will I know which direction its in? Won't I need one more bit to indicate positive or negative?
Unless theres some quick spherical coordinate transformation I can do...

What do I use instead of glVertexPointer?
BTW, 3.2 Core Profile doesn't have gl*Pointer, only glVertexAttribPointer. Looks you're using the compatibility profile.
Quote: ...and compute Z, but how will I know which direction its in? Won't I need one more bit to indicate positive or negative?

2 ways I recall:
- use a free byte-sized attrib that would have been simple padding anyway. Hard to fit with all shaders.
- add 4.0f to x when encoding and the z<0.0f, detect and subtract the 4.0f when decoding. 3 extra gpu cycles.

This topic is closed to new replies.

Advertisement