glVertexAttribP4uiv

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(shader_data.psId,"position"));
	glVertexAttribPointer(glGetAttribLocation(shader_data.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(shader_data.psId,"color"));
//	glVertexAttribPointer(glGetAttribLocation(shader_data.psId,"color"), 4,GL_INT_2_10_10_10_REV,GL_TRUE, 0,0);
      glVertexAttribP4uiv(glGetAttribLocation(shader_data.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?

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.

thanks for the quick one… :slight_smile:
Now, i commented glEnableVertexAttribArray() call keeping rest same. now i get a black color…

[QUOTE=Alfonse Reinheart;1250854]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.[/QUOTE]

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

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.

Then show the statement where you’re doing that. It isn’t in the code you posted:

glVertexAttribP4uiv(glGetAttribLocation(shader_data.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.

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.

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.

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.

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.

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.