PDA

View Full Version : Vertex color using GLubyte



icebeat
04-15-2013, 01:14 PM
Hi all,

I am painting over 3 millions of triangles with vertex color information in this way:



struct vertex
{
GLfloat x,y,z;
GLubyte r,g,b;
};

....
{
.....

pMesh->BindBuffer();
glEnableVertexAttribArray (nPosition);
glVertexAttribPointer(nPosition, 3, GL_FLOAT, GL_FALSE, nStride, 0 );
glEnableVertexAttribArray (nColor);
glVertexAttribPointer(nColor, 3, GL_UNSIGNED_BYTE, GL_TRUE, nStride, BUFFER_OFFSET (nColorOffset) );
glDrawElements (pMesh->GetMeshType(), nPrimitives, GL_UNSIGNED_INT, BUFFER_OFFSET(_Start*sizeof(GLuint)) );

....
}


and my vertex shader:



#version 330

uniform mat4 MVP_Matrix;

layout(location = 0) in vec4 VertexPosition;
layout(location = 1) in vec3 VertexColor;

out vec4 fragColor;

void main(void)
{
fragColor = vec4 (VertexColor,1.0);
gl_Position = MVP_Matrix * VertexPosition;
}


With Nvidia (Quadro 600) the frame rate is about 60 fps, but with Amd (FirePro V4900) the performance drop to 20 fps.
This issue only happens with GLubyte, changing the vertex color type to GLFloat, the performance with Amd is equal to Nvdia.

I am using GLubyte to reduce the memory size of my vertex (geometry could be millions of triangles).

Will someone please give me some advice on what to do.

Thanks,

mhagain
04-15-2013, 02:47 PM
Switch to 4 bytes (or pad your struct with an extra unused byte) for your color pointer; GPUs don't like 24-bit data and the AMD may be dropping back to software emulation in the per-vertex part of the pipeline. See further here: http://www.opengl.org/wiki/Common_Mistakes:_Deprecated#Misaligned_vertex_form ats (the specific calls discussed here are deprecated but the principle behind the advice remains valid).

icebeat
04-15-2013, 03:26 PM
Thanks, you saved my day.:D

Alfonse Reinheart
04-15-2013, 04:53 PM
A better citation would be the Wiki article on best practices for vertex specification (http://www.opengl.org/wiki/Vertex_Specification_Best_Practices).