GLSL setAttributePointer

I'm trying to set an array in the draw method for each mesh i'm drawing with a shader:


rs.setAttributePointer("centers",3,true,0,centers);



"centers" is a FloatBuffer the same size as the vertexBuffer.

I'm getting the following error:

org.lwjgl.opengl.OpenGLException: Invalid value (1281)
        at org.lwjgl.opengl.Util.checkGLError(Util.java:56)
        at org.lwjgl.opengl.Display.update(Display.java:567)
        at com.jme.renderer.lwjgl.LWJGLRenderer.displayBackBuffer(Unknown Source)



Anyone know why  :?

usage:

setAttributePointer(String var, int size, boolean normalized, int stride, FloatBuffer data)



size of 3 might be right in your case but a stride of 0 sounds scary...just found from a post that that's the way renanse did in a glsltest post here though...
so.setAttributePointer("Tangent", 3, true, 0, data); dunno how that works...

Heres what i know about those parameters so far:



var = name of the shader attribute

size = number of data/vertex, 3 means a vec3 attribute

normalized = not sure, guess either a flag to request normalization or flag to note a normalized vector

stride = how many data units to skip after each size number of data. I think 0 means that no data should be skipped.

data = the FloatBuffer



By definition shader attributes are changeable anytime. What bothers me is that in renanse's code:


        FloatBuffer data = genTangents(planet);
        so.setAttributePointer("Tangent", 3, true, 0, data);
        so.relinkProgram();



The relinkProgram is called after setting the attribute pointer. Is this an issue of attribute pointers beeing transferred only when programs are relinked?



at least the source says that you have to call relink after setting a shaderattribute

As a workaround i pass data instead of color, for now. By looking into source of relinkProgram, it does not set the actual data pointers, only links opengl id numbers with string names. The actual passing of data is in apply of glsl renderstate. What i miss is putting the data on the graphics card as VBO. After searching the opengl docs, it seems that there is no command for putting glsl attribute arrays into VBO like vertex/normal/color/tex arrays. I'm not sure, but i guess that the attribute array is passed each time the pointer changes. And using relinkProgram each time when switching to another model drastically reduces frame rate. Another option would be loading/compiling/linking a shader for each model separately.



It seems that passing attribute data in gl_Color is a good option, if vertex color is not needed.