<blockquote>
<p>...have not been able to find much info about the link between programs and dynamic attribute bindings.</p>
</blockquote>
<p>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.</p>
<p>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.</p>
<p>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 <a href="https://registry.khronos.org/OpenGL-Refpages/gl4/html/glVertexAttrib.xhtml" rel="nofollow noreferrer"><code>glVertexAttrib</code></a> functions.</p>

CC BY-SA 4.0
2023-09-23T14:25:47.617Z
"*they're just not read at all*" They *are* read. They simply aren't read *into* anywhere.
Nicol Bolas
CC BY-SA 4.0
2023-09-24T11:02:19.880Z
@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_.
invertedPanda
CC BY-SA 4.0
2023-09-24T11:23:26.800Z
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.
invertedPanda
CC BY-SA 4.0
2023-09-24T13:21:06.483Z
@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.
Nicol Bolas
CC BY-SA 4.0
2023-09-25T05:46:44.283Z
@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?
invertedPanda
CC BY-SA 4.0
2023-09-25T05:59:07.147Z
@NicolBolas That is interesting to know. Is that guaranteed to happen? I honestly thought the driver should be smart enough to know which attributes the shader needs and not read irrelevant data.
Christian Rau
CC BY-SA 4.0
2023-09-25T06:38:31.263Z
@ChristianRau: Memory isn't read bytewise; it's read by cache lines. So if the GPU needs to read the neighboring bytes, it *must* read the unused ones too.
Nicol Bolas
CC BY-SA 4.0
2023-09-25T10:23:57.250Z
@NicolBolas Well, of course if the attributes are tightly packed in the same buffer, some additional data will inevitably be read, but that would be the case regardless if the attribute array is enabled or not. But in case the irrelevant attributes are sourced from different buffers, there doesn't seem to be a need to touch those.
Christian Rau
CC BY-SA 4.0
2023-09-23T09:46:42.530Z
2023-09-23T09:46:42.530Z
Christian Rau
<p>When binding an attribute index using glVertexAttribPointer, what happens when a later bound program does not contain an attribute at said index?</p>
<p>Is the behaviour undefined, or is the attribute ignored altogether?</p>
<p>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.</p>

CC BY-SA 4.0
2023-09-24T11:08:02.557Z
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.
invertedPanda
<opengl><shader><vertex-buffer-object>
Confusion about glVertexAttribPointer and non-active attributes
invertedPanda
# Confusion about glVertexAttribPointer and non-active attributes

(Asked by: username_0 on 2019-09-22)

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.

**Tags:** opengl, shader, vertex-buffer-object

> **Comments:**
> **username_0**: Hi username_1, 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.  

---

## 1 answers

### Answer by username_1 on 2023-09-23. Score: 1 | Accepted answer

> ...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`](https://registry.khronos.org/OpenGL-Refpages/gl4/html/glVertexAttrib.xhtml) functions.

> **Comments:**
> **username_2**: "*they're just not read at all*" They *are* read. They simply aren't read *into* anywhere.  
> **username_0**: @username_2 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_.  
> **username_0**: 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.  
> **username_2**: @username_0: "*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.  
> **username_0**: @username_2 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?  
> **username_1**: @username_2 That is interesting to know. Is that guaranteed to happen? I honestly thought the driver should be smart enough to know which attributes the shader needs and not read irrelevant data.  
> **username_2**: @username_1: Memory isn't read bytewise; it's read by cache lines. So if the GPU needs to read the neighboring bytes, it *must* read the unused ones too.  
> **username_1**: @username_2 Well, of course if the attributes are tightly packed in the same buffer, some additional data will inevitably be read, but that would be the case regardless if the attribute array is enabled or not. But in case the irrelevant attributes are sourced from different buffers, there doesn't seem to be a need to touch those.  

---

