easy-gl › Renderbuffer

Renderbuffer

Manages an OpenGL Renderbuffer Object (RBO). Renderbuffers are optimised storage for framebuffer attachments that do not need to be sampled in shaders — typically depth and stencil.

When to use Renderbuffer vs Texture

UseRenderbufferTexture
Sample in shaderNoYes
Driver storage efficiencyUsually betterGeneral purpose
MSAA storageYesYes (Texture2DMultisample)
Depth/stencilCommon choiceNeeded for shadow maps

Depth renderbuffer

easygl::Renderbuffer depthRbo;
depthRbo.create();
depthRbo.bind();
depthRbo.set_storage(easygl::InternalFormat::DepthComponent24, width, height);

Depth + stencil packed

depthStencilRbo.set_storage(
    easygl::InternalFormat::Depth24Stencil8, width, height);

MSAA renderbuffer

easygl::Renderbuffer msColor;
msColor.create();
msColor.bind();
msColor.set_storage_multisample(
    4,                                    // 4× MSAA samples
    easygl::InternalFormat::Rgba8,
    width, height);

Attaching to a framebuffer

fbo.attach_renderbuffer(
    easygl::FramebufferTarget::Framebuffer,
    easygl::FramebufferAttachment::Depth,
    depthRbo.native_handle());

Method reference

MethodDescription
create()Allocate GL RBO handle.
destroy()Free handle. Noexcept.
bind()Bind to GL_RENDERBUFFER target.
unbind() [static]Bind renderbuffer 0.
set_storage(format, width, height)Allocate storage for the renderbuffer.
set_storage_multisample(samples, format, w, h)Allocate MSAA storage.
is_created()True if GL handle allocated.
native_handle()Raw GL integer ID.
reset_handle_no_gl()Context-loss recovery.