# Vertex attributes with strides between them vs blocks of data

Using opengl, does it make a difference if I upload plain vertex attribute structs, and then define the strides between them using glVertexAttribPointer, or if I do something like this

//we have position, texCoords, and normal vertex attributes
//allocate enough room for all attributes, set it to null for now
glBufferData(GL_ARRAY_BUFFER, positions.size() + normals.size() + textCoords.size(), NULL, BUFFER_USAGE);

//set positions data
glBufferSubData(GL_ARRAY_BUFFER, 0, positions.size(), positions.data());

//... call glBufferSubData for normals and texCoords as well


This "problem" (it's more of a choice than a problem) is something I've bashed against before, so I did some reading on it.

First of all, you still need to call glVertexAttribPointer(...) in both cases, because OpenGL has no other way of knowing how to interpret the data in the buffers.

Second, there is no significant difference(that is, the performance impact is insignificant to non-existent) between the two methods. If you can use both to reach a goal, use the one that you find easier to understand, debug, and extend.

Third, and last, there are some cases in which you can only use one method. For example, you can encode huge amounts of data into a texture using a framebuffer and send it to the GPU, where you just use the data, as it was already "decoded" by setting the right attribute pointers. This is a clear example of a case in which you'll want to use glBufferData(...) and glBufferSubdata(...) among other OpenGL calls.

There's still some more stuff about it, but you can refer to this great tutorial article to better understand the concepts (note: passing data around using textures is a technique out of the scope of this question or the following article): Tutorial

If you're using separate arrays for different attributes, you can just use a different buffer object for each. Just bind each one before setting the attrib pointer.

• That's bad though. It requires me to call even more gl commands before drawing in each frame. – Pilpel Jul 16 '17 at 19:57
• So bind them in a Vertex Array Object. – Jimmy Jul 17 '17 at 1:00