<p>I'm rendering some UI using an immediate-mode UI library, so each frame it produces some meshes, which I then load into buffers and render, only to get some strange errors from Renderdoc:
<a href="https://i.sstatic.net/I69FU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/I69FU.png" alt="" /></a></p>
<p>You can see in the API inspector the list of calls preceding the draw.</p>
<p>I'm deeply puzzled by this, because of the following facts:</p>
<p><strong>This problem only happens when the UI library returns more than one mesh.</strong>
That is, the API calls for multiple meshes would go as follows:</p>
<pre><code>// First mesh
glUseProgram
// set textures
// bind vertex array
glNamedBufferData // for the vertex buffer
glNamedBufferData // for the index buffer
glDrawElements

// Second mesh
glNamedBufferData // for the vertex buffer
glNamedBufferData // for the index buffer
glDrawElements

...    
</code></pre>
<p><strong>If I call glVertexArrayVertexBuffer even once per frame, the errors are not reported</strong>, regardless of how many meshes the UI returns.
First mesh draw:
<a href="https://i.sstatic.net/THh3I.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/THh3I.png" alt="" /></a>
Second mesh draw:
<a href="https://i.sstatic.net/dGkMC.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dGkMC.png" alt="" /></a></p>
<p><strong>Why I find this strange:</strong></p>
<ol>
<li>The vertex array object is fully set up at the start of the program, including the call to glVertexArrayVertexBuffer, and the binding of vbo to vao is never supposed to change, together with offset and stride.</li>
<li>I removed every other draw call from the program for testing and left only those for the UI, so nothing should interfere</li>
<li>The UI renders just fine in the program, it's only RenderDoc that complains</li>
</ol>
<p>I see 2 possibilities - 1) I am using the API incorrectly, and 2) there's a bug in RenderDoc.</p>
<p>Would really appreciate if someone could shed some light onto this issue.</p>
<p>UPDATE:</p>
<p>Nicol Bolas commented below</p>
<blockquote>
<p>&quot;including the call to glVertexArrayVertexBuffer&quot; Are you sure about that?</p>
</blockquote>
<p>I have captured Frame #0 and Frame #1815 in Renderdoc to illustrate that the call is made (see the image below) and noticed that in the second frame no errors were reported! It strongly suggests that if Frame #0 is not captured, then Renderdoc just doesn't know that the appropriate calls have been made and reports false errors.</p>
<p>Also quite expectedly, if I remove the call to glVertexArrayVertexBuffer, then nothing gets drawn and OpenGL complains. I almost think we've solved the mystery.</p>
<p><a href="https://i.sstatic.net/fkDMY.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fkDMY.png" alt="" /></a></p>
<p>UPDATE 2.</p>
<p>As per Nicol Bolas's suggestion I have rewritten the code so that all the meshes are packed into one vertex buffer and are loaded there once per frame. After this change Renderdoc stopped complaining. I mostly consider the issue solved, but one thing is still not clear:</p>
<p>If the assumption that Renderdoc needed Frame #0 to &quot;know&quot; about the call to <code>glVertexArrayVertexBuffer</code> is correct, then why did it not complain when there was only 1 mesh to draw (i.e. there were no multiple draw calls with <code>glNamedBufferData</code> between them).</p>
<p>If no one knows for sure why this is happening, I will probably raise an issue with Renderdoc and mark this question as done.</p>

CC BY-SA 4.0
2021-11-06T18:10:55.330Z
"*including the call to glVertexArrayVertexBuffer*" Are you sure about that?
Nicol Bolas
CC BY-SA 4.0
2021-11-06T18:17:55.843Z
It should be noted that uploading to a region of a buffer immediately after issuing a call that reads from that buffer is a bad idea for performance. I know you're re-specifying the buffer with `BufferData` each time, but it's still much better to allocate a big slab of memory, do a single upload to it per-frame, and then do a bunch of draw operations from it.
Nicol Bolas
CC BY-SA 4.0
2021-11-06T22:18:09.530Z
@NicolBolas thank you for your comment. I have updated the post with more info, which may explain what's going on. I also appreciate your note about performance and I will change it so that all the meshes are put into a single buffer once per frame.
Ivan Ivanov
CC BY-SA 4.0
2021-11-06T22:21:20.250Z
And where is your `glCreateVertexArrays` call?
Nicol Bolas
CC BY-SA 4.0
2021-11-06T22:32:56.430Z
@NicolBolas I'm very new to Renderdoc so took me a while to find it - it seems it puts all initialization calls into a separate window - I've updated the screenshot with the call highlighted. Thanks!
Ivan Ivanov
CC BY-SA 4.0
2021-11-07T19:13:16.230Z
I've edited the question once again. Thank you @NicolBolas, I appreciate you help very much.
Ivan Ivanov
<opengl>
Renderdoc reports incorrect OpenGL API usage, can't figure out why
Ivan Ivanov
# Renderdoc reports incorrect OpenGL API usage, can't figure out why

(Asked by: username_0 on 2021-11-05)

I'm rendering some UI using an immediate-mode UI library, so each frame it produces some meshes, which I then load into buffers and render, only to get some strange errors from Renderdoc:
[![](https://i.sstatic.net/I69FU.png)](https://i.sstatic.net/I69FU.png)

You can see in the API inspector the list of calls preceding the draw.

I'm deeply puzzled by this, because of the following facts:

**This problem only happens when the UI library returns more than one mesh.**
That is, the API calls for multiple meshes would go as follows:

```
// First mesh
glUseProgram
// set textures
// bind vertex array
glNamedBufferData // for the vertex buffer
glNamedBufferData // for the index buffer
glDrawElements

// Second mesh
glNamedBufferData // for the vertex buffer
glNamedBufferData // for the index buffer
glDrawElements

...    

```

**If I call glVertexArrayVertexBuffer even once per frame, the errors are not reported**, regardless of how many meshes the UI returns.
First mesh draw:
[![](https://i.sstatic.net/THh3I.png)](https://i.sstatic.net/THh3I.png)
Second mesh draw:
[![](https://i.sstatic.net/dGkMC.png)](https://i.sstatic.net/dGkMC.png)

**Why I find this strange:**

1. The vertex array object is fully set up at the start of the program, including the call to glVertexArrayVertexBuffer, and the binding of vbo to vao is never supposed to change, together with offset and stride.
2. I removed every other draw call from the program for testing and left only those for the UI, so nothing should interfere
3. The UI renders just fine in the program, it's only RenderDoc that complains

I see 2 possibilities - 1) I am using the API incorrectly, and 2) there's a bug in RenderDoc.

Would really appreciate if someone could shed some light onto this issue.

UPDATE:

username_1 username_1 commented below

> "including the call to glVertexArrayVertexBuffer" Are you sure about that?

I have captured Frame #0 and Frame #1815 in Renderdoc to illustrate that the call is made (see the image below) and noticed that in the second frame no errors were reported! It strongly suggests that if Frame #0 is not captured, then Renderdoc just doesn't know that the appropriate calls have been made and reports false errors.

Also quite expectedly, if I remove the call to glVertexArrayVertexBuffer, then nothing gets drawn and OpenGL complains. I almost think we've solved the mystery.

[![](https://i.sstatic.net/fkDMY.png)](https://i.sstatic.net/fkDMY.png)

UPDATE 2.

As per username_1 username_1's suggestion I have rewritten the code so that all the meshes are packed into one vertex buffer and are loaded there once per frame. After this change Renderdoc stopped complaining. I mostly consider the issue solved, but one thing is still not clear:

If the assumption that Renderdoc needed Frame #0 to "know" about the call to `glVertexArrayVertexBuffer` is correct, then why did it not complain when there was only 1 mesh to draw (i.e. there were no multiple draw calls with `glNamedBufferData` between them).

If no one knows for sure why this is happening, I will probably raise an issue with Renderdoc and mark this question as done.

**Tags:** opengl

> **Comments:**
> **username_1**: "*including the call to glVertexArrayVertexBuffer*" Are you sure about that?  
> **username_1**: It should be noted that uploading to a region of a buffer immediately after issuing a call that reads from that buffer is a bad idea for performance. I know you're re-specifying the buffer with `BufferData` each time, but it's still much better to allocate a big slab of memory, do a single upload to it per-frame, and then do a bunch of draw operations from it.  
> **username_0**: @username_1 thank you for your comment. I have updated the post with more info, which may explain what's going on. I also appreciate your note about performance and I will change it so that all the meshes are put into a single buffer once per frame.  
> **username_1**: And where is your `glCreateVertexArrays` call?  
> **username_0**: @username_1 I'm very new to Renderdoc so took me a while to find it - it seems it puts all initialization calls into a separate window - I've updated the screenshot with the call highlighted. Thanks!  
> **username_0**: I've edited the question once again. Thank you @username_1, I appreciate you help very much.  

---

## 0 answers

