Direct State AccessGL 4.5

glClearNamedFramebufferuiv

Clears an unsigned-integer colour attachment (an object-ID buffer, for example) to an integer value.

Signature

void glClearNamedFramebufferuiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer,
                                const GLuint *value);

How it works

Integer textures like GL_R32UI hold exact whole numbers, which is what mouse picking needs: each object writes its ID, and reading the pixel under the cursor gives the object. glClearColor is a float and cannot clear them reliably; this clears to an exact integer, usually 0 for "no object".

Parameters

framebufferGLuint

The framebuffer.

bufferGLenum

GL_COLOR (or GL_STENCIL with glClearNamedFramebufferiv).

drawbufferGLint

Index in the draw-buffer list.

valueconst GLuint *

4 unsigned integers (only the first is used by a one-channel format).

Tips & pitfalls

  • Direct State Access (GL 4.5): the object is passed as a parameter, so nothing needs to be bound and no global state is disturbed.

Example

example.cpp
1const GLuint none[4] = { 0, 0, 0, 0 };
2glClearNamedFramebufferuiv(idFbo, GL_COLOR, 0, none);
Official Khronos documentation