3
\$\begingroup\$

I have two different shader programs in my OpenGL code.

1- renders simple font using freetype
2- simple shader which draw primitive shapes.

I sent both of them some data using buffers, I understood that they are stored on server side, but are they associated with different programs? or any program can use any buffer data by just using gBindBuffer(); ?

\$\endgroup\$
1
  • \$\begingroup\$ buffers are memory that has been allocated in video memory, and mapped up to system memory to permit transfers to and from. a GLSL program has access to any allocated buffers on the GPU that the particular pipeline stage permits. a GLSL program however cannot access system memory directly, everything must be transferred to vram, or placed in a register. \$\endgroup\$
    – Evan
    Oct 23 '13 at 19:25
2
\$\begingroup\$

Short answer: No they aren't asscoiated with shader programs.

Long answer : Vertex and vertex attributes are stored in buffers which may or may not be located on the GPU memory depending on how you define them and how the driver decides to.

glBindBuffer binds a specific buffer object (referenced by uint) to a specific binding point like GL_ARRAY_BUFFER, think of this as how openGL are going to deal with this buffer.

GLSL shader programs take vertices and vertex attributes as input. These attibutes are not passed to the active shader program unless you do the following:

  1. Bind the buffer that contains the data. (Assuming they are already stored in the buffer).
  2. Query the location of each shader program attribute varialbe so you can bind Attribute Pointer to them in the next step (or just use a predefined locations).

  3. Decide how are you going to deference the buffer data using glVertexAttribPointer and where each AttributePointer will be bound using the queried names(uint) from step 2.

  4. Perform the actual draw operation.
\$\endgroup\$
0
\$\begingroup\$

The latter. You can bind a buffer to a slot. Programs then use these slots as input. They have no direct connection to the buffer itself, but rather to the slot that a particular buffer may be bound to. You can change shaders without changing buffer bindings and you can change buffer bindings without changing shaders.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.