I'm trying to draw some points with GL_POINTS, and have it work as fast as possible. I have two variables that need to be passed to the shader - a position (vec2) as well as a point size (float) - and I'm not sure of the quickest way to pass them over.
Before I was using glVertexAttribPointer two times, the first time to pass the position and the second to pass the size. This lets me write the vertex shader code as follows:
attribute mediump vec4 Position;
attribute lowp float Size;
void main(void) {
gl_PointSize = Size;
gl_Position = Position;
}
I thought this was good as it worked and looked nice, but then I read somewhere that you should try to keep glVertexAttribPointer calls to a minimum. This led me to decide to pass the position and the size in a single vec3, which makes it so I only need to do one glVertexAttribPointer call.
However, this means I need to rewrite the vertex shader to this:
attribute mediump vec3 Position;
void main(void) {
gl_PointSize = Position.z;
gl_Position = vec4(Position.x, Position.y, 0.0, 1.0);
}
To me this looks uglier but it makes the glVertexAttribPointer calls much simpler.
My question is, does passing it as a vec3 actually make a performance difference, and if it does, is there a way for me to rewrite it to look a bit less ugly? I was hoping to do something like
gl_Position = vec4(vec2(Position));
But that doesn't work sadly.
gl_Position = vec4(Position.xy, 0.0, 1.0);
. About the performance: You already implemented it. So why not profile it and test if it got faster? – BDL