OpenGL data transfer to graphics card

Viewed 63

Why do you need buffers in OpenGL, when you can just transfer all the data to the graphics card via uniform. As an example:

#version 330

layout (location = 0) in vec2 pos;

void main()
{
    gl_Position = vec4(pos, 0.0, 1.0);
}

why would you need the above code, when you can just have the following:

#version 330

uniform vec2 pos;

void main()
{
    gl_Position = vec4(pos, 0.0, 1.0);
}

i really cant see the use of vao, vbo, ebo, etc.

1 Answers

Let's forget for the moment the fact that uniforms are uniform: their values do not change within a drawing call (and therefore what you're asking for is not possible).

Uniform variables of this sort are set by calling glUniform of some form. So to make this "work", you must call glUniform once for every vertex you want to render in your entire scene. A number that may well number in the millions for the entire scene. So every frame of rendering, you need to call glUniform millions of times.

Plus, that only provides a single value, in this case a position. If a vertex has a normal, color, texture coordinate, or any combination of the above (or other things), then you need to make a glUniform call for each of those values.

If you have a 100 million vertices in a scene, and each vertex has 6 attributes, that's 600 million calls of that one function. Every frame. This is not a recipe for performance.

It would be far faster if the GPU could just look at its own storage for the data, wouldn't it? Rather than having the CPU shepherd every quantum of data individually? This would be especially true if you want to render the same model in multiple places. With your way, each time you draw that model, you have to make all the glUniform calls again. If the GPU just has the data, you can say "render that model over here, with these parameters".

Related