PDA

View Full Version : glVertexAttribPointer



artariel
04-30-2012, 09:48 AM
void glVertexAttribPointer( GLuint index,
GLint size,
GLenum type,
GLboolean normalized,
GLsizei stride,
const GLvoid * pointer);

from official site


about first parameter, what are the options for it ? and is it used instead of specifically defining glvertexpointer, gltexcoordpointer, glcolorpointer and glnormalpointer ?

so should I use it instead of them, same performance ?

V-man
04-30-2012, 02:56 PM
For the first parameter, the values are from 0 to whatever the maximum your card supports. Check the value with a call to glGetInteger.
http://www.opengl.org/wiki/GlVertexAttribPointer

The function became available in GL 2 and it should probably be the only choice starting GL 3.
It is a matter of API cleanup and making the API more generic. This change has nothing to do with performance.

artariel
04-30-2012, 07:55 PM
For the first parameter, the values are from 0 to whatever the maximum your card supports. Check the value with a call to glGetInteger.
http://www.opengl.org/wiki/GlVertexAttribPointer

The function became available in GL 2 and it should probably be the only choice starting GL 3.
It is a matter of API cleanup and making the API more generic. This change has nothing to do with performance.

Thanks again.

By the way, can i fill stride parameter with sizeof the entire vertex array instead of 0 ? what is the exceptions of this parameter is used differently ?


and also, there is still no enough explanation about index parameter about it's values.

edit : oh god i think i got glvertexattribpointer wrong.. i didn't know it was GLSL thing lol. i think i won't use it for a long time.

raybender
04-30-2012, 09:12 PM
For the first parameter, the values are from 0 to whatever the maximum your card supports. Check the value with a call to glGetInteger.
http://www.opengl.org/wiki/GlVertexAttribPointer

The function became available in GL 2 and it should probably be the only choice starting GL 3.
It is a matter of API cleanup and making the API more generic. This change has nothing to do with performance.

I am teaching myself OpenGL and I would greatly appreciate help interpreting the man page reference above.

The Description section begins with the following sentence.


glVertexAttribPointer, glVertexAttribIPointer and glVertexAttribLPointer
specify the location and data format of the array of generic vertex attributes at index _index_ to use when rendering.


Is the "array of generic vertex attributes" the same as the VertexAttribArray part of the function name glEnableVertexAttribArray()?
If not, what array is this referring to?

In the Function Definition section, pointer argument, there is the following sentence.


Specifies a offset of the first component of the first generic vertex attribute in the array
in the data store of the buffer currently bound to the GL_ARRAY_BUFFER target.


Is the array in "the first generic vertex attribute in the array in the data store of the buffer"
the same array referred to in "array of generic vertex attributes" mentioned from the Description?

The pointer argument definition states that the attribute array is part of the buffer object; however, the language is nearly identical
to the attribute array mentioned at the beginning of the Description (which I suspect is a different array).

V-man
05-01-2012, 04:34 AM
Yes, it is the same thing. And yes, you can specify large values for the stride parameter. That is explained on another page of the wiki.

artariel
05-01-2012, 05:51 AM
Yes, it is the same thing. And yes, you can specify large values for the stride parameter. That is explained on another page of the wiki.

thanks.

so i must keep using glvertexpointer, gltexcoordpointer, glcolorpointer and glnormalpointer ?

By the way, i will convert a glbegin/end based obj loader/renderer to VBOs. Will I get performance gain ?

mhagain
05-01-2012, 06:45 AM
glVertexAttribPointer was originally introduced with the old GL_ARB_vertex_program extension, which defines mappings between conventional attributes and generic attributes, like so:

Generic
Attribute Conventional Attribute Conventional Attribute Command
--------- ------------------------ ------------------------------
0 vertex position Vertex
1 vertex weights 0-3 WeightARB, VertexWeightEXT
2 normal Normal
3 primary color Color
4 secondary color SecondaryColorEXT
5 fog coordinate FogCoordEXT
6 - -
7 - -
8 texture coordinate set 0 MultiTexCoord(TEXTURE0, ...)
9 texture coordinate set 1 MultiTexCoord(TEXTURE1, ...)
10 texture coordinate set 2 MultiTexCoord(TEXTURE2, ...)
11 texture coordinate set 3 MultiTexCoord(TEXTURE3, ...)
12 texture coordinate set 4 MultiTexCoord(TEXTURE4, ...)
13 texture coordinate set 5 MultiTexCoord(TEXTURE5, ...)
14 texture coordinate set 6 MultiTexCoord(TEXTURE6, ...)
15 texture coordinate set 7 MultiTexCoord(TEXTURE7, ...)
8+n texture coordinate set n MultiTexCoord(TEXTURE0+n, ...)

(See: http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_program.txt). In general, these might work on all hardware, and if they work on yours and if you're not intending to distribute your program then you could try them and see what happens. Otherwise it would be wise not to depend on them at this stage.

Converting to VBOs you may or may not get a performance gain. With VBOs you need to be careful of cases where you must update buffer contents every frame, so if your data is not static then you'll be better to write some test programs and become familiar with the specification, use cases and hardware performance characteristics first. Also, if vertex submission/bandwidth is not a bottleneck in your program then even in the best case you're not likely to see much in the way of a performance gain.

kyle_
05-01-2012, 07:05 AM
Be wary however that the mappings hold only for ARB programs - not GLSL programs. In GLSL only attribute 0 is kind of aliased with conventional attribute for vertex position.

artariel
05-01-2012, 07:21 AM
glVertexAttribPointer was originally introduced with the old GL_ARB_vertex_program extension, which defines mappings between conventional attributes and generic attributes, like so:

In general, these might work on all hardware, and if they work on yours and if you're not intending to distribute your program then you could try them and see what happens. Otherwise it would be wise not to depend on them at this stage.

Thanks for detailed info.

Are you talking about the glVertexAttribPointer or the other methods (might work on all hardware part) ? So, Are the classical methods like gltexcoordp, glvertexp still safe to use on all hardwares?

artariel
05-01-2012, 08:23 AM
Oh I have just realized that there's no such function as glBindBuffer and all of the buffer functions in VS2010. I didn't want to start another thread. I get identifier not found error ?!

carsten neumann
05-01-2012, 08:45 AM
See the Getting Started wiki page (http://www.opengl.org/wiki/Getting_started) in the section "Getting Functions".

artariel
05-01-2012, 09:20 PM
See the Getting Started wiki page (http://www.opengl.org/wiki/Getting_started) in the section "Getting Functions".

i still couldn't get it work.. even wglGetProcAddress gives errors.

BionicBytes
05-02-2012, 02:08 AM
check your GL version with glGetversion and check your GL function initialisation code carefully

artariel
05-02-2012, 05:51 AM
check your GL version with glGetversion and check your GL function initialisation code carefully



i got glee.h and it works perfect now, i can use vbo functions with no error. my ogl version is 2.1, i think enough for using vbos (?)

artariel
05-02-2012, 08:16 PM
yep success, i have converted glbegin based terrain renderer to vbo based. it works great.