Jump to content
  • Advertisement
Sign in to follow this  
all_names_taken

Problem binding or creating attribute arrays

This topic is 3856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using the ARB extension for VBOs, and I'm trying to bind vertex attributes to my GLSL shader. However, it seems like it doesn't work - the data I access in the shader isn't the data I was supposed to send to it! I send 4 bone weights which should together sum to 1 and thus output red with the shader code I have below (I also send 4 bone indices, which I haven't yet tested), but when I render with this shader, the red component becomes larger than 1. Probably 2, because when I divide by 2 in the fragment shader I get RGB 1,0,0 as output and when I divide by 3 I get RGB 0.66,0,0 and so on. Rendering code:
	GLuint boneIndicesLocations;
	boneIndicesLocations = glGetAttribLocationARB(shader,"boneIndices");
	glEnableVertexAttribArrayARB(boneIndicesLocations);
	glVertexAttribPointerARB(boneIndicesLocations,4,GL_INT,false,0,0);

	GLuint boneWeightsLocations;
	boneWeightsLocations = glGetAttribLocationARB(shader,"boneWeights");
	glEnableVertexAttribArrayARB(boneWeightsLocations);
	glVertexAttribPointerARB(boneWeightsLocations,4,GL_FLOAT,false,0,0);

... removed probably irrelevant code for activating vertex indices, positions, normals, uv

	glDrawElements(GL_TRIANGLES, mesh->numIndices, GL_UNSIGNED_INT, 0);

... removed probably irrelevant code for deactivating vertex indices, positions, normals, uv

	glDisableVertexAttribArrayARB(boneIndicesLocations);
	glDisableVertexAttribArrayARB(boneWeightsLocations);






Loading code:
	glGenBuffersARB(1, &vbBoneIndices);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbBoneIndices);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(GLint)*4*mesh.numVertices, mesh.boneIndices, GL_STATIC_DRAW);

	glGenBuffersARB(1, &vbBoneWeights);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbBoneWeights);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(float)*4*mesh.numVertices, mesh.boneWeights, GL_STATIC_DRAW);






The vertex shader:
attribute int boneIndices[4];
attribute float boneWeights[4];
varying float test;

void main()
{
	test = boneWeights[0]+boneWeights[1]+boneWeights[2]+boneWeights[3];
	gl_Position = ftransform();
}






The fragment shader:
varying float test;

void main()
{
	gl_FragColor = vec4(test,0,0,1);
}






I suspect I may be doing something wrong with either the loading or rendering code. I tried writing "attribute vec4 boneWeights;" instead of "attribute float boneWeights[4];", but that caused a crash.

Share this post


Link to post
Share on other sites
Advertisement
Oh ok, so how are you supposed to get attributes with 4 floats? "attribute vec4 boneWeights" didn't work, it caused a crash. Any ideas? If all fails I guess I must have one attribute array for each separate value, as I've gotten that running in a test shader I wrote a while ago...

Share this post


Link to post
Share on other sites
"attribute vec4 boneWeights;" causes the program to crash, except when I never output the value read from the attribute (which presumably means the compiler optimizes away the reads from it, so the reads from it may be what causes the error). So perhaps it's still the binding that is not correct - the shader can't access the attribute buffer values properly.

I've tried both with array and with vec4 now and both give the same problem.

[Edited by - all_names_taken on December 2, 2007 3:41:15 PM]

Share this post


Link to post
Share on other sites
saying 'it crashes' doesn't give us any meaningful information to work with, however 'attribute vec4 boneWeight;' is the only way to supply 4 floats in one var to a vertex shader.

Secondly, as I and many others have said on the forums, removing 'probably irrelevant code' isn't any help; you don't know whats causing the problem, how are you to judge what is releveant and what isn't?

Finally; you load your source data into a VBO, yet you never rebind the VBO before telling OpenGL to use it as source data (for either the weights or the bone indices). This is probably the source of the problem...

Share this post


Link to post
Share on other sites
Ok first in rendering you have to give VBO pointers. glVertexPointer, glTexCoordPointer.

Second, I think you need all vertex data in one vbo, so indices and vertices need to be in one VBO, so just make it bigger. But you never even do step one. Therefore I'm assuming your vbo has never been drawn even without the shader.

Share this post


Link to post
Share on other sites
Just looking over your code and variable names, it seems like you have a ton of problems:

Bone weights are used for skeletal animation, yet you have no matrices for each bone.

You cant have indexed vertices if your trying to do that in a vbo.


I see that you actually did call glVertexAttributePointer() but you call it twice, so the only attribute used is the one you most recently called.

Like I said I dont know if you doing skeletal animation or wtf, but you dont even have vertex data??? for example, each vertex has (x,y,z), (normals), (color/bone weights).


Its maybe in another place in your code, but you never (in this code) call to actually use your shader.

Share this post


Link to post
Share on other sites
Quote:
Original post by dpadam450
Second, I think you need all vertex data in one vbo, so indices and vertices need to be in one VBO, so just make it bigger. But you never even do step one. Therefore I'm assuming your vbo has never been drawn even without the shader.


No, you don't. You can split vertex data across VBOs as you like, including having index data in another VBO.

Share this post


Link to post
Share on other sites
Quote:
Original post by dpadam450
I see that you actually did call glVertexAttributePointer() but you call it twice, so the only attribute used is the one you most recently called.


Yes, and if you look at the first snippet of code he gives he enables the VA for boneindices and sets the pointer, then he enables the VA for the bone weights and sets the pointer.

What he fails to do, as I've pointed out, is swap to the correct VBO for each source of data.
Quote:

Like I said I dont know if you doing skeletal animation or wtf, but you dont even have vertex data??? for example, each vertex has (x,y,z), (normals), (color/bone weights).

Its maybe in another place in your code, but you never (in this code) call to actually use your shader.


I'm gonna guess that it's in the code he 'helpfully' left out as he didn't think it was relivant (See my post above with what is probably the answer and the 3 points in it..)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!