ImFusion SDK 4.3
OffscreenRenderHelper Class Reference

#include <ImFusion/Core/GL/OffscreenRenderHelper.h>

Helper class to perform deferred off-screen rendering. More...

+ Inheritance diagram for OffscreenRenderHelper:

Detailed Description

Helper class to perform deferred off-screen rendering.

This class helps you to accumulate your rendering calls into a temporary texture before eventually copying/blending the accumulated pixels back to the original/parent framebuffer. Internally, the temporary textures and framebuffer objects are cached and reused if compatible to avoid performance issues due to constant reallocation.

A typical usage scenario looks like this:

// setup custom FBO and attach temporary texture to render into
auto renderBuffer = GL::OffscreenRenderHelper::cachedInstance().create(viewportSize);
// render scene
renderX();
renderY();
...
// stop using the temporary FBO and copy/blend its contents back to the original framebuffer
renderBuffer.blendToParent();
static OffscreenRenderHelper & cachedInstance()
Definition InstanceManager.h:80
RenderBuffer create(const vec2i &viewportSize, GL::InternalFormat colorFormat=GL::InternalFormat::RGBA8, GL::InternalFormat depthFormat=GL::InternalFormat::DepthComponent24)
Creates a new temporary render buffer of the given configuration for off-screen rendering.
Note
This interface is still experimental and its API may change significantly in the future.

Classes

struct  RenderBuffer
 Helper structure to encapsulate OpenGL objects representing the temporary rendering buffer. More...
 

Public Types

enum class  ColorPostProcessing { None = 0 , DivideByAlpha = 1 , DivideBySqrtAlpha = 2 }
 Enumeration of optional additional color processing steps to perform in the copy shader. More...
 

Public Member Functions

RenderBuffer create (const vec2i &viewportSize, GL::InternalFormat colorFormat=GL::InternalFormat::RGBA8, GL::InternalFormat depthFormat=GL::InternalFormat::DepthComponent24)
 Creates a new temporary render buffer of the given configuration for off-screen rendering.
 
int cacheSize () const
 Returns the maximum number of RenderBuffer instances that are cached by OffscreenRenderHelper.
 
void setCacheSize (int numElements)
 Sets the maximum number of RenderBuffer instances that are cached by OffscreenRenderHelper; must not be negative.
 

Additional Inherited Members

- Static Public Member Functions inherited from InstanceManager< OffscreenRenderHelper >
static OffscreenRenderHelpercachedInstance ()
 Returns the cached instance of type T for the currently active OpenGL context.
 

Member Enumeration Documentation

◆ ColorPostProcessing

enum class ColorPostProcessing
strong

Enumeration of optional additional color processing steps to perform in the copy shader.

Enumerator
None 

Write the original RGBA value of the color texture to the fragment shader output.

DivideByAlpha 

Divide the RGB value by the alpha component.

This is useful if you are using pre-multiplied alpha blending and want to reverse the pre-multiplication process in a single pass.

DivideBySqrtAlpha 

Divide the RGBA value by sqrt(A).

If your blending setup is (SrcAlpha, OneMinusSourceAlpha) this option allows for the final result after blendToParentAndDispose() being the same as if you would directly render to the parent framebuffer without usage of OffscreenRenderHelper.

Member Function Documentation

◆ create()

RenderBuffer create ( const vec2i & viewportSize,
GL::InternalFormat colorFormat = GL::InternalFormat::RGBA8,
GL::InternalFormat depthFormat = GL::InternalFormat::DepthComponent24 )
nodiscard

Creates a new temporary render buffer of the given configuration for off-screen rendering.

After calling this function and capturing the returned RenderBuffer the current OpenGL context will have bound a dedicated FBO with one color and one depth texture of the given formats attached. The textures will be cleared with color vec4(0, 0, 0, 0) and depth 1 and the OpenGL viewport will be set to size viewportSize with offset (0, 0).

The original FBO and viewport state will be restored when the RenderBuffer is destroyed or you call RenderBuffer::blendToParent().

Parameters
viewportSizeSize in pixels of the temporary render buffer
colorFormatInternal texture format to use for the color attachment.
depthFormatInternal texture format to use for the depth attachment.

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close