Vertex Attributes

I’m attempting to assign an array of integers to each vertex and pass that to the shader via a vertex attribute. Currently when I try :

attribute float nodelocations[ ];

in the Shader InfoLog I get

0(15) : Warning C7507: OpenGL does not allow attributes of type float[ ]

Is using a vertex attribute the correct procedure for this task? And if so, why does it not allow the Vertex Array?

Thanks

As pointed out in your other thread, attributes (2.0) and vertex shader inputs (3.0+) can’t be arrays or structures.

Look at UBO (uniform buffer object), TBO (texture buffer object) or more recently NV’s bindless graphics for alternative LUT indexing schemes.

Brolingstanz,

That’s good to know that they can’t be arrays. Your suggestion for using UBO, TBO or bindless graphics is able to assign each vertex a different value?

I wasn’t sure what you were referring to by LUT indexing scheme.

Apologize for the basic questions, but thanks for pointing me in the right direction.

void VertexAttribIPointerEXT(uint index, int size, enum type,
sizei stride, const void *pointer);

Can this be used to pass in a list of integers specific for each vertex?

Can this be used to pass in a list of integers specific for each vertex?

You can only pass at most a vec4 per vertex in one vertex attribute array. However you can set multiple vertex attribute arrays to set multiple attributes per vertex.
You can also use TBO if your hardware supports it.

For TBO uses example you can look at this recent thread:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=259190&page=1

And the extension spec:
http://www.opengl.org/registry/specs/EXT/texture_buffer_object.txt

Nvidia sample code and documentation:

http://developer.download.nvidia.com/SDK/10.5/opengl/OpenGL_SDK_Guide.pdf

http://developer.download.nvidia.com/SDK/10.5/Samples/simple_texture_buffer_object.zip

dletozeun,

thank you so much for responding! I ran across a few of those links but wasn’t sure if TBO were the “norm” for passing data to vertices on a per vertex level.

If the attribute vec4 is a limitation my only option is store the data via a TBO and use that for pulling data?

Again, thanks for responding. For someone who is learning openGL and GLSL it really helps out.

I do not know if it is the norm but it is a quite sophisticated and easy way to access buffer objects from a shader. The problem is that it is for the moment only supported on high end graphic hardware and I am not sure whether it is implemented in ATI drivers yet.

Another option is to use regular 1D or 2D textures that you can fetch from the vertex shader (VTF). This one is more widely supported but need a little bit more setup on the application side.

Ah, I was afraid of that. Looks like I’m going to have to stick with 1D or 2D textures.

I’m sure there is a lot of documentation on 2D textures, and I have a 1D texture implemented right now for a color map.

It is unfortunate the TBO is not widely supported. Too bad I couldn’t go with Occam’s razor on this one :(!

These calls, I believe, are the correct to set up a Vertex Attribute for float.

I used a integer that is not already for an attribute,6, and then bind location to the variable name in my shader.

glEnableVertexAttribArray(6);
glBindAttribLocation(p,vertattrib,“nodelocations”);
glVertexAttrib1f(6,9.0); // to assign variable

The shader value for the float is not 9.0, it appears to be 1.0 everytime.

Any ideas?
Thanks in advance everyone

“it appears”
are you sure? how do you debug? one good tool is glslDevil to debug GLSL shaders runtime.

Have been using the infoLog for debugging and if statements inside the shader.

I’ll look into glslDevil

What is vertattrib here? I assume it is equal to 6. I mean you set everywhere generic attribute index as 6 and just in the glBindAttribLocation you use a variable, that looks a bit suspicious.

All you have to do is:

  • Compile and link your shader program successfully

  • Bind generic vertex attribute to your custom names as declared in the vertex shader (glBindAttribLocation)

  • Beside your vbo and ibo bindings, enable generic vertex attribute arrays with glEnableVertexAttribArray and the attribute location.

  • Render the scene

In addition, I am not sure to understand why you call glVertexAttrib1f since you are apparently using vertex attribute arrays. Either you use vertex arrays and vertex attribute arrays or you use immediate mode and call glVertexAttrib* for each vertex declaration.

From the specs:

BindAttribLocation has no effect until the
program is linked. In particular, it doesn’t modify the bindings of active attribute variables in a program that has already been linked.

This means, after calling glBindAttribLocation you have to link your shader program once more. That’s why your sequence of commands looks suspicious to me. Usually, you’ll call glBindAttribLocation somewhere near the creation and linking of the shader program, not near where you actually load up attribute values.

Either you use vertex arrays and vertex attribute arrays or you use immediate mode and call glVertexAttrib* for each vertex declaration.

glVertexAttrib() is a nice way to provide default-values for attributes that have no VBO attached. They are called “dangling attributes”; used in earlier days to fake instancing, because they provided a very fast way to provide per-batch constants to the vertex shader. No glBegin()/glEnd() is needed to call glVertexAttrib. I’m glad they left it in for OGL3.0+ :slight_smile:

This means, after calling glBindAttribLocation you have to link your shader program once more

Thanks for that considerable precision.

glVertexAttrib() is a nice way to provide default-values for attributes that have no VBO attached. They are called “dangling attributes”; used in earlier days to fake instancing, because they provided a very fast way to provide per-batch constants to the vertex shader. No glBegin()/glEnd() is needed to call glVertexAttrib. I’m glad they left it in for OGL3.0+ :slight_smile:

That’s true but it’s a hack that relies on the state machine nature of OpenGL. IMHO, it is quite confusing to use an attribute as vertex constant, it is not its first purpose and in this case you should use a uniform.
Does the 3.0 spec clearly states about that? I must admit that’s a useful thing to make things quick or even for debugging.

because they provided a very fast way to provide per-batch constants to the vertex shader

I do not understand how this justify your suggestion… per-batch constants are uniforms and are very fast.

Got the attributes to work thanks to you guys! Looking back on my code I wasn’t sure why it was so sloppy, putting in 6 for two attribute calls but using ‘vertattrib’ for another.

Thanks for clarifying the usage of the vertex attributes.

I ran into attribute limit so I will have to be implementing textures for the data.

I’m posting on a new thread so hopefully, someone else can benefit from the knowledge of the group.