<p><a href="https://www.khronos.org/opengl/wiki/Buffer_Object#Clearing" rel="nofollow noreferrer">Buffer clears</a> are defined as a form of pixel transfer operation. Essentially, you are specifying data as if you were specifying packed pixel data to be copied. So you must specify the <a href="https://www.khronos.org/opengl/wiki/Pixel_Transfer#Pixel_transfer_arguments" rel="nofollow noreferrer">pixel transfer format and type parameters</a>, as well as the &quot;internal format&quot; equivalent to be used in the buffer.</p>
<p>But this means that all of the rules of pixel transfers apply, <em>including</em> the fact that transferring data to an integer internal format must use the <code>*_INTEGER</code> pixel transfer formats. That's the mismatch: you have to use <code>GL_RED_INTEGER</code> because you're writing to an integer internal format.</p>

CC BY-SA 4.0
2021-08-17T18:35:04.547Z
2021-08-17T18:35:04.547Z
Nicol Bolas
<p>Under OpenGL 4.5 on <code>AMD RENOIR (DRM 3.40.0, 5.10.56-1-lts, LLVM 12.0.1)</code>, running</p>
<pre><code>glCreateBuffers(1, &amp;result_buffer);
glNamedBufferData(result_buffer, count * 4, NULL, GL_STATIC_DRAW);
glClearNamedBufferData(result_buffer, GL_R32UI, GL_RED, GL_UNSIGNED_INT, NULL);
</code></pre>
<p>results in <code>GL_INVALID_OPERATION in glClearNamedBufferData(integer vs non-integer)</code>.</p>
<p>It works fine if I use <code>GL_R32F</code>instead, but that is not the format I want here.</p>
<p><a href="https://khronos.org/registry/OpenGL-Refpages/gl4/html/glClearBufferData.xhtml" rel="nofollow noreferrer">The spec</a> states that <code>GL_INVALID_OPERATION</code> can only occur if <code>result_buffer</code> were mapped or not the name of an existing buffer object; neither seems to be the case.</p>
<p>What am I doing wrong? What is &quot;integer vs non-integer&quot; getting at?</p>

<opengl><api>
Unexpected INVALID_OPERATION on glClearNamedBufferData
Tau
# Unexpected INVALID_OPERATION on glClearNamedBufferData

(Asked by: username_0 on 2021-08-17)

Under OpenGL 4.5 on `AMD RENOIR (DRM 3.40.0, 5.10.56-1-lts, LLVM 12.0.1)`, running

```
glCreateBuffers(1, &result_buffer);
glNamedBufferData(result_buffer, count * 4, NULL, GL_STATIC_DRAW);
glClearNamedBufferData(result_buffer, GL_R32UI, GL_RED, GL_UNSIGNED_INT, NULL);

```

results in `GL_INVALID_OPERATION in glClearNamedBufferData(integer vs non-integer)`.

It works fine if I use `GL_R32F`instead, but that is not the format I want here.

[The spec](https://khronos.org/registry/OpenGL-Refpages/gl4/html/glClearBufferData.xhtml) states that `GL_INVALID_OPERATION` can only occur if `result_buffer` were mapped or not the name of an existing buffer object; neither seems to be the case.

What am I doing wrong? What is "integer vs non-integer" getting at?

**Tags:** opengl, api


---

## 1 answers

### Answer by username_1 on 2021-08-17. Score: 2 | Accepted answer

[Buffer clears](https://www.khronos.org/opengl/wiki/Buffer_Object#Clearing) are defined as a form of pixel transfer operation. Essentially, you are specifying data as if you were specifying packed pixel data to be copied. So you must specify the [pixel transfer format and type parameters](https://www.khronos.org/opengl/wiki/Pixel_Transfer#Pixel_transfer_arguments), as well as the "internal format" equivalent to be used in the buffer.

But this means that all of the rules of pixel transfers apply, *including* the fact that transferring data to an integer internal format must use the `*_INTEGER` pixel transfer formats. That's the mismatch: you have to use `GL_RED_INTEGER` because you're writing to an integer internal format.


---

