PDA

View Full Version : glVertexAttribP4uiv



debonair
05-16-2013, 02:57 AM
i have been trying to use glVertexAttribP with GL_UNSIGNED_INT_2_10_10_10_REV but stuck up at some point.

here is my code



GLuint red=0,green=511,blue=511,alpha=3;
GLuint val = 0;

val = val | (alpha << 30);
val = val | (blue << 20);
val = val | (green << 10);
val = val | (red << 0);
GLfloat vertices[]={-0.9f, -0.9f, 0.0f,1.0f,
-0.9f, 0.6f, 0.0f,1.0f,
0.6f,0.6f,0.0f,1.0f,
0.6f,-0.9f,0.0f,1.0f};


GLuint test_data[]={val,val,val,val};
glGenBuffers(1, &BufferId);
glBindBuffer(GL_ARRAY_BUFFER, BufferId);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glEnableVertexAttribArray(glGetAttribLocation(shad er_data.psId,"position"));
glVertexAttribPointer(glGetAttribLocation(shader_d ata.psId,"position"), 4,GL_FLOAT,GL_FALSE, 0,0);


glGenBuffers(1, &BufferId1);
glBindBuffer(GL_ARRAY_BUFFER, BufferId1);
glBufferData(GL_ARRAY_BUFFER, sizeof(test_data), test_data, GL_STATIC_DRAW);

glEnableVertexAttribArray(glGetAttribLocation(shad er_data.psId,"color"));
// glVertexAttribPointer(glGetAttribLocation(shader_d ata.psId,"color"), 4,GL_INT_2_10_10_10_REV,GL_TRUE, 0,0);
glVertexAttribP4uiv(glGetAttribLocation(shader_dat a.psId,"color"),GL_UNSIGNED_INT_2_10_10_10_REV ,GL_TRUE,0);


glDrawArrays(GL_TRIANGLE_FAN,0,4);



it gives Access violation at glDraw call. code works fine with glVertexAttribPointer. what am i missing here?

Alfonse Reinheart
05-16-2013, 03:39 AM
`glEnableVertexAttribArray` says that you're using an array for that attribute. But you're not using an array. So OpenGL tries to access an array that you haven't specified. Hence the boom.

Disable the array instead of enabling it.

debonair
05-16-2013, 03:53 AM
thanks for the quick one.. :)
Now, i commented glEnableVertexAttribArray() call keeping rest same. now i get a black color..

debonair
05-16-2013, 10:30 PM
`glEnableVertexAttribArray` says that you're using an array for that attribute. But you're not using an array. So OpenGL tries to access an array that you haven't specified. Hence the boom.

Disable the array instead of enabling it.

when i comment glEnableVertexAttribArray() i get a black color. Seems that it fails to take color values.

Alfonse Reinheart
05-16-2013, 11:10 PM
You get black because that's what you set the color to.

debonair
05-17-2013, 12:08 AM
You get black because that's what you set the color to.

Sorry, i didn't get you.
I am setting it to non zero values though red, green, blue variables in my code and finally doing bit-wise operations. Please correct me if wrong.

Alfonse Reinheart
05-17-2013, 01:09 AM
Then show the statement where you're doing that. It isn't in the code you posted:


glVertexAttribP4uiv(glGetAttribLocation(shader_dat a.psId,"color"),GL_UNSIGNED_INT_2_10_10_10_REV ,GL_TRUE,0);

That sets the value to 0. Which means that it's 0 for all four components.

arekkusu
05-17-2013, 09:32 AM
glVertexAttribP4uiv sets the constant current-vertex attribute. Since you passed "0" it should immediately dereference NULL and crash, not set all black.
glVertexAttribP4ui (no 'v') on the other hand would have set the attribute to all black.

debonair
05-19-2013, 10:44 PM
Thanks a lot guys.
I thought glVertexAttribP4ui works with buffer objects so i was passing it 0 as offset. I didn't understand 'y'. And when i passed array into it, it was giving black because AMD is buggy. Later tried on nvidia and it worked.
Seems that i need to read some more stuff to get insight how it actually works.

Alfonse Reinheart
05-19-2013, 11:30 PM
And when i passed array into it, it was giving black because AMD is buggy. Later tried on nvidia and it worked.

It doesn't take an array. Well, it kind of does, but it's only an array with one unsigned integer element in length. Really, I have no idea why they even added the `v` versions of these functions.

The functions that take real arrays of values are the glVertexAttribPointer functions.

debonair
05-20-2013, 01:54 AM
One more concern, i was using glVertexAttribP4uiv with GL_INT_2_10_10_10_REV. For signed data type, we have to use same API. So i was calling it with GL_INT_2_10_10_10_REV enum and data which i used is:


GLint red=0,green=511,blue=511,alpha=1;
GLint val = 0;

val = val | (alpha << 30);
val = val | (blue << 20);
val = val | (green << 10);
val = val | (red << 0);
GLuint test_data[]={val,val,val,val};


Now, this gives me black color. I must be going wrong with the data types. Please let me know the correct one to use GL_INT_2_10_10_10_REV.

Alfonse Reinheart
05-20-2013, 02:35 AM
GLuint test_data[]={val,val,val,val};

Remember where I said that it doesn't take an array? That's what I was talking about. It takes a pointer to a single `GLuint`.

As previously stated, the `Puiv` functions serve no functional purpose. Just use the `Pui` functions.