OpenGL - jgoffeney/Cesium4Unreal GitHub Wiki

Back

References

API

Topics

Resource Types

Texture

A typical texture is a 2D image which is applied to geometry to give it an appearance. An example is using an image of bricks on a rectangle to create a wall.

Framebuffer

A framebuffer is essentially a collection of memory buffers with specific uses that act as targets for rendering.

Default Framebuffer

A framebuffer automatically exists for general purpose rendering containing multiple color buffers, a depth buffer, a stencil buffer and potentially others. The buffer sizes are tied to the output window size and will resize with it.

Color Buffers

Color buffers are allocated as RGB or RGBA per pixel for rendering color information. For double buffering there are two color buffers and rendering is performed on the "back" buffer which is then swapped with the "front" buffer. For stereoscopic rendering there are "left" and "right" buffers for each of the "front" and "back" buffers.

In terms of the shaders a color buffer is a target for the fragment color output.

Depth Buffer

A depth buffer is single channel with the same dimensions as the color buffers of 16, 24 or 32 bit floats. Rather than containing color information it contains the depth value for each fragment. It is typically used for depth testing to determine if a fragment should be discarded. The fragment depth value is compared against the corresponding depth buffer value and is kept or discarded based on the specified depth function.

The depth values are between 0 and 1.0

To use the depth buffer:

glEnable(GL_DEPTH_TEST);

To clear the depth buffer:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

To visualize the depth buffer you simply need to get the fragment's z value and write to the output fragment color.

Renderbuffer

Usage Patterns

Resource Allocation

When allocating a resource in OpenGL two type of functions are invoked (usually together) as glGenXs and glBindX where X is the name of the OpenGL resource. X can be Texture, Framebuffer, RenderBuffer, etc.

Generate Resource Names

The glGenXs functions generate unallocated "names" for the resource X. OpenGL documentation uses "name" to refer to an integer value which maps to a resource instance.

Example:

// Allocate a single texture name
GLuint texId;
glGenTextures(1, &texId);

// Allocate multiple texture names
GLuint texIdsArray[3];
glGenTextures(3, &texIdsArray);

Bind Resource

The glBindX functions creates or uses a "named" resource. Its first parameter defines the target of the resource and only one resource can be bound to a target. If another resource is already bound to the target then binding a new resource will break the previous binding.

Example:

// Bind an allocated texture name to GL_TEXTURE_2D
GLuint texId;
glGenTextures(1, &texId);
glBindTexture(GL_TEXTURE_2D, texId);

// Bind an allocated framebuffer to GL_FRAMEBUFFFER
GLuint framebufferId;
glGenFramebuffers(1, &framebufferId);
glBindFramebuffer(GL_FRAMEBUFFER, framebufferId);