1
$\begingroup$

When binding an attribute index using glVertexAttribPointer, what happens when a later bound program does not contain an attribute at said index?

Is the behaviour undefined, or is the attribute ignored altogether?

I have searched the docs quite extensively, and have not been able to find much info about the link between programs and dynamic attribute bindings.

$\endgroup$
1
  • $\begingroup$ Hi Christian, thanks for updating my answer. I understand now that the phrase "thanks all" is only appropriate for letters to close family and the bereaved, and will try to do better in future. $\endgroup$ Sep 24, 2023 at 11:08

1 Answer 1

1
$\begingroup$

...have not been able to find much info about the link between programs and dynamic attribute bindings.

That is because there really is no link between them. Your vertex array data, i.e. the enabled attribute arrays and the buffers which they source their data from, don't really care at all which future shader programs they'll be used with.

If they enable attribute arrays that are not needed by the program, that data is just ignored. It's not like the attributes are read from the buffers and will spill out of your GPU when the program doesn't consume them ;-), they're just not read at all.

If on the other hand the program uses attributes for which you don't have an array/buffer enabled, that isn't an error either. Instead, the attribute data will be sourced from a single value that is constant over the entire draw call and can be set with the often somewhat forgotten glVertexAttrib functions.

$\endgroup$
8
  • $\begingroup$ "they're just not read at all" They are read. They simply aren't read into anywhere. $\endgroup$ Sep 23, 2023 at 14:25
  • $\begingroup$ @NicolBolas just for the record, what is it called when something is read but not into anywhere? Doesn't the activity of reading involve that a subject takes the information into account somehow? Otherwise it might be described as a passive verb, like scanning. $\endgroup$ Sep 24, 2023 at 11:02
  • $\begingroup$ In any case, thank you both for the clarifications. I think I realise my mistake now. For any others that (either actively or passively) read this, I thoroughly recommend learning OpenGL through the spec. It taught me how to fly, and not into hasty conclusions. $\endgroup$ Sep 24, 2023 at 11:23
  • $\begingroup$ @invertedPanda: "just for the record, what is it called when something is read but not into anywhere?" There isn't a word for that. Technically, the read goes into cache memory, but that doesn't really matter. It won't affect the shader itself, merely the performance of having to read useless data. $\endgroup$ Sep 24, 2023 at 13:21
  • $\begingroup$ @NicolBolas Ah, I see now. Is it possible for the OpenGL driver to optimise away any performance cost, and does that tend to happen in reality? Or is it negligible, in the grand scheme of things? $\endgroup$ Sep 25, 2023 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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