## Name

glClearBuffer — clear individual buffers of a framebuffer

## C Specification

`void glClearBufferiv(` | GLenum buffer,
| GLint drawbuffer,
| const GLint * value`)`;

`void glClearBufferuiv(` | GLenum buffer,
| GLint drawbuffer,
| const GLuint * value`)`;

`void glClearBufferfv(` | GLenum buffer,
| GLint drawbuffer,
| const GLfloat * value`)`;

`void glClearBufferfi(` | GLenum buffer,
| GLint drawbuffer,
| GLfloat depth,
| GLint stencil`)`;

`void glClearNamedFramebufferiv(` | GLuint framebuffer,
| GLenum buffer,
| GLint drawbuffer,
| const GLint *value`)`;

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

`void glClearNamedFramebufferfv(` | GLuint framebuffer,
| GLenum buffer,
| GLint drawbuffer,
| const GLfloat *value`)`;

`void glClearNamedFramebufferfi(` | GLuint framebuffer,
| GLenum buffer,
| GLint drawbuffer,
| GLfloat depth,
| GLint stencil`)`;

## Parameters

`framebuffer`

  Specifies the name of the framebuffer object for `glClearNamedFramebuffer*`.

`buffer`

  Specify the buffer to clear.

`drawbuffer`

  Specify a particular draw buffer to clear.

`value`

  A pointer to the value or values to clear the buffer to.

`depth`

  The value to clear the depth buffer to.

`stencil`

  The value to clear the stencil buffer to.

## Description

These commands clear a specified buffer of a framebuffer to specified value(s). For `glClearBuffer*`, the framebuffer is the currently bound draw framebuffer object. For `glClearNamedFramebuffer*`, `framebuffer` is zero, indicating the default draw framebuffer, or the name of a framebuffer object.

`buffer` and `drawbuffer` identify the buffer to clear.

If `buffer` is `GL_COLOR`, a particular draw buffer `GL_DRAW_BUFFER` `i` is specified by passing `i` as `drawbuffer`, and `value` points to a four-element vector specifying the R, G, B and A color to clear that draw buffer to. If the value of `GL_DRAW_BUFFER` `i` is `GL_NONE`, the command has no effect. Otherwise, the value of `GL_DRAW_BUFFER` `i` identifies one or more color buffers, each of which is cleared to the same value. Clamping and type conversion for fixed-point color buffers are performed in the same fashion as for glClearColor. The `*fv`, `*iv` and `*uiv` forms of these commands should be used to clear fixed- and floating-point, signed integer, and unsigned integer color buffers respectively.

If `buffer` is `GL_DEPTH`, `drawbuffer` must be zero, and `value` points to a single value to clear the depth buffer to. Clamping and type conversion for fixed-point depth buffers are performed in the same fashion as for glClearDepth. Only the `*fv` forms of these commands should be used to clear depth buffers; other forms do not accept a `buffer` of `GL_DEPTH`.

If `buffer` is `GL_STENCIL`, `drawbuffer` must be zero, and `value` points to a single value to clear the stencil buffer to. Masking is performed in the same fashion as for glClearStencil. Only the `*iv` forms of these commands should be used to clear stencil buffers; be used to clear stencil buffers; other forms do not accept a `buffer` of `GL_STENCIL`.

`glClearBufferfi` and `glClearNamedFramebufferfi` are used to clear the depth and stencil buffers simultaneously. `buffer` must be `GL_DEPTH_STENCIL` and `drawbuffer` must be zero. `depth` and `stencil` are the values to clear the depth and stencil buffers to, respectively. Clamping and type conversion of `depth` for fixed-point depth buffers are performed in the same fashion as for glClearDepth. Masking of `stencil` for stencil buffers is performed in the same fashion as for glClearStencil. These commands are equivalent to clearing the depth and stencil buffers separately, but may be faster when a buffer of internal format `GL_DEPTH_STENCIL` is being cleared. The same per-fragment and masking operations defined for `glClear` are applied.

The result of these commands is undefined if no conversion between the type of the specified `value` and the type of the buffer being cleared is defined (for example, if `glClearBufferiv` is called for a fixed- or floating-point buffer, or if `glClearBufferfv` is called for a signed or unsigned integer buffer). This is not an error.

## Errors

`GL_INVALID_OPERATION` is generated by `glClearNamedFramebuffer*` if `framebuffer` is not zero or the name of an existing framebuffer object.

`GL_INVALID_ENUM` is generated by `glClearBufferiv` and `glClearNamedFramebufferiv` `buffer` is not `GL_COLOR` or `GL_STENCIL`.

`GL_INVALID_ENUM` is generated by `glClearBufferuiv` and `glClearNamedFramebufferuiv` `buffer` is not `GL_COLOR`.

`GL_INVALID_ENUM` is generated by `glClearBufferfv` and `glClearNamedFramebufferfv` `buffer` is not `GL_COLOR` or `GL_DEPTH`.

`GL_INVALID_ENUM` is generated by `glClearBufferfi` and `glClearNamedFramebufferfi` `buffer` is not `GL_DEPTH_STENCIL`.

`GL_INVALID_VALUE` is generated if `buffer` is `GL_COLOR` `drawbuffer` is negative, or greater than the value of `GL_MAX_DRAW_BUFFERS` minus one.

`GL_INVALID_VALUE` is generated if `buffer` is `GL_DEPTH`, `GL_STENCIL` or `GL_DEPTH_STENCIL` and `drawbuffer` is not zero.

## Version Support

| OpenGL Version
--- | ---
Function / Feature Name | 2.0 | 2.1 | 3.0 | 3.1 | 3.2 | 3.3 | 4.0 | 4.1 | 4.2 | 4.3 | 4.4 | 4.5
`glClearBufferfi` | - | - | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
`glClearBufferfv` | - | - | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
`glClearBufferiv` | - | - | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
`glClearBufferuiv` | - | - | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
`glClearNamedFramebufferfi` | - | - | - | - | - | - | - | - | - | - | - | ✔
`glClearNamedFramebufferfv` | - | - | - | - | - | - | - | - | - | - | - | ✔
`glClearNamedFramebufferiv` | - | - | - | - | - | - | - | - | - | - | - | ✔
`glClearNamedFramebufferuiv` | - | - | - | - | - | - | - | - | - | - | - | ✔

## See Also

glClearColor, glClearDepth, glClearStencil, glClear

## Copyright

Copyright © 2010-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.