---
title: "【CG】Front, Back, and Other Buffers"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/cg-front-back-other-buffers/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/05-游戏图形与运行时/渲染基础/【CG】Front, Back, and Other Buffers.md"
content_hash: 9275ba12b12c04c691374b9a51faae6b2c74b2edef1944f23d488e42520b0b2c
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# 【CG】Front, Back, and Other Buffers

> 创建时间：2020/12/7 17:14

  * 【CG】Front, Back, and Other Buffers
    * frame buffer
    * color buffer
      * double buffering
    * Buffer Functions
      * Creating a framebuffer
    * related links
    * Ref

OpenGL stores and manipulates pixel data in a framebuffer.

## frame buffer

The **framebuffer** consists of a set of logical buffers:

  * color buffer - for writing color values

  * depth - buffer to write and test depth information

  * stencil buffers - allows us to discard certain fragments based on some condition.

The combination of these buffers is stored somewhere in **GPU memory** and is called a **framebuffer**.

## color buffer

The **color buffer** itself consists of a set of logical buffers; this set can include a front-left, a front-right, a back-left, a back-right, and some number of auxiliary buffers.

> A particular pixel format or OpenGL implementation may not supply all of these buffers. For example, the current version of Microsoft’s implementation of OpenGL in Windows does not support stereoscopic images, so a pixel format cannot have left and right color buffers.

### double buffering

Two color buffers are available to applications that use double buffering: a front buffer and a back buffer.
By default, drawing commands are directed to the **back buffer** (the **off-screen buffer** ), while the **front buffer** is displayed on the screen. When the off-screen buffer is ready for display, you call SwapBuffers, and Windows copies the contents of the off-screen buffer to the on-screen buffer.

> The generic implementation uses a device-independent bitmap (DIB) as the back buffer and the screen display as the front buffer. Hardware devices and their drivers may use different approaches.

The OpenGL core function, glDrawBuffer, selects buffers for writing and clearing.

## Buffer Functions

To copy the contents of an off-screen buffer to an on-screen buffer, call SwapBuffers.

The following illustration shows how the contents of the buffers are copied when calling SwapBuffers.

![Alt text](/media/bdbe84e8a47a684a4f2e.png)

The following functions also affect buffers:
glReadBuffer
glReadPixels
glCopyPixels
glAccum
glColorMask
glDepthMask
glIndexMask
glStencilMask
glClearAccum
glClearColor
glClearDepth
glClearIndex
glClearStencil

### Creating a framebuffer

Just like any other object in OpenGL we can create a framebuffer object (abbreviated to **FBO** ) by using a function called glGenFramebuffers:

## related links

<https://www.khronos.org/opengl/wiki/Default_Framebuffer>
<https://learnopengl.com/Advanced-OpenGL/Framebuffers>

## Ref

[https://docs.microsoft.com/en-us/windows/win32/opengl/front–back–and-other-buffers](https://docs.microsoft.com/en-us/windows/win32/opengl/front--back--and-other-buffers)
