Vertex color using GLubyte

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;


    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.


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: (the specific calls discussed here are deprecated but the principle behind the advice remains valid).

Thanks, you saved my day.:smiley:

A better citation would be the Wiki article on best practices for vertex specification.