Hopefully this fixes a few misconceptions and gives you a slightly better idea of how the general-purpose shader repository is configured.
What you need to understand is how buffer objects really work in GL. You often hear people discern things like vertex buffer objects and unified buffer objects. In fact, there is no fundamental difference - the buffer object is processed the same way, regardless of what it stores. This is just a general data warehouse, and it takes on special meaning as long as it is tied to a specific point (for example, GL_ARRAY_BUFFER or GL_UNIFORM_BUFFER ).
Do not think about special vertex buffers located on the GPU, think more generally - this is actually unformatted memory that you can read / write if you know the structure. Calls of type glVertexAttribPointer (...) describe the data structure of the buffer object enough for glDrawArrays (...) to significantly pull the vertex attributes from the buffer object memory for each vertex shader call.
You need to do the same to calculate the shaders, as shown below. To fully understand the following data structure, you need to familiarize yourself with the rules described in 7.6.2.2 - the standard format of a single unit .
A description of the vertex data structure using Shader storage blocks can be done as follows:
This allows the interleaved vertex buffer to be used in a computational shader with the data structure indicated above. You have to be careful with data alignment when you do this ... you could accidentally use whatever alignment / step you wanted for an array of alternating vertices, but here you want to comply with the std140 layout std140 . This means that using ternary vectors is not always a wise use of memory; you need things that need to be aligned at the borders of N ( float ), 2N ( vec2 ) or 4N ( vec3 / vec4 ), and this often requires input pads and / or smart data packaging. In the above example, you can put the entire three-component vector value of the data into the entire space spent by the empty alignment.
Pseudo code showing how the buffer will be created and bound for double use:
struct Vertex { GLfloat pos [4]; GLfloat normal [3]; GLfloat padding7; GLfloat st [2]; GLfloat padding10 [2]; } *verts; [... code to allocate and fill verts ...] GLuint vbo; glGenBuffers (1, &vbo); glBindBuffer (GL_ARRAY_BUFFER, vbo); glBufferData (GL_ARRAY_BUFFER, sizeof (Vertex) * num_verts, verts, GL_STATIC_DRAW); glVertexAttribPointer (0, 4, GL_FLOAT, GL_FALSE, 48, 0);
source share