Kemena3D
Loading...
Searching...
No Matches
kemena::kOffscreenRenderer Class Reference

Renders to an offscreen FBO for thumbnails, previews, and image export. More...

#include <koffscreenrenderer.h>

Public Member Functions

 kOffscreenRenderer (int width=256, int height=256)
 Construct the renderer and allocate its offscreen FBO.
 ~kOffscreenRenderer ()
 Destroy the renderer and release all GPU resources (FBO, textures, shaders).
void resize (int newWidth, int newHeight)
 Resize the offscreen buffer.
void setBackgroundColor (kVec4 color)
 Set the background clear color and alpha (default: opaque dark grey).
kVec4 getBackgroundColor () const
 Get the current background clear color and alpha.
void render (kWorld *world, kScene *scene, kCamera *camera)
 Render the full scene to the offscreen buffer.
void renderMesh (kMesh *mesh, kCamera *camera=nullptr)
 Render a single mesh to the offscreen buffer.
void renderMeshWithMaterial (kMesh *mesh, kCamera *camera=nullptr)
 Render a mesh using its assigned material shader and uniforms.
uint32_t getTexture () const
 GPU texture ID of the current render result.
int getWidth () const
 Get the output texture width in pixels.
int getHeight () const
 Get the output texture height in pixels.
bool saveToFile (const kString &filePath) const
 Save the current render result to an image file.

Detailed Description

Renders to an offscreen FBO for thumbnails, previews, and image export.

Usage:

kOffscreenRenderer offscreen(256, 256);
// Full scene render from a custom camera
offscreen.render(world, scene, &myCamera);
// Single mesh with auto-framed camera
offscreen.renderMesh(mesh);
// Use as ImGui thumbnail
ImGui::Image((ImTextureID)(uintptr_t)offscreen.getTexture(), {256, 256});
// Save to file
offscreen.saveToFile("thumbnail.png");
kOffscreenRenderer(int width=256, int height=256)
Construct the renderer and allocate its offscreen FBO.

Constructor & Destructor Documentation

◆ kOffscreenRenderer()

kemena::kOffscreenRenderer::kOffscreenRenderer ( int width = 256,
int height = 256 )

Construct the renderer and allocate its offscreen FBO.

Parameters
widthOutput texture width in pixels.
heightOutput texture height in pixels.

◆ ~kOffscreenRenderer()

kemena::kOffscreenRenderer::~kOffscreenRenderer ( )

Destroy the renderer and release all GPU resources (FBO, textures, shaders).

Member Function Documentation

◆ getBackgroundColor()

kVec4 kemena::kOffscreenRenderer::getBackgroundColor ( ) const
inline

Get the current background clear color and alpha.

Returns
The RGBA background color.

◆ getHeight()

int kemena::kOffscreenRenderer::getHeight ( ) const
inline

Get the output texture height in pixels.

Returns
Buffer height.

◆ getTexture()

uint32_t kemena::kOffscreenRenderer::getTexture ( ) const
inline

GPU texture ID of the current render result.

Pass directly to ImGui::Image as (ImTextureID)(uintptr_t)getTexture(). Valid until the next resize() call.

◆ getWidth()

int kemena::kOffscreenRenderer::getWidth ( ) const
inline

Get the output texture width in pixels.

Returns
Buffer width.

◆ render()

void kemena::kOffscreenRenderer::render ( kWorld * world,
kScene * scene,
kCamera * camera )

Render the full scene to the offscreen buffer.

Uses the provided camera for view/projection. All scene lights, materials, and textures are applied. Shadows are not included.

Parameters
worldWorld (used only for skinning state, may be nullptr).
sceneScene to render.
cameraCamera defining the viewpoint.

◆ renderMesh()

void kemena::kOffscreenRenderer::renderMesh ( kMesh * mesh,
kCamera * camera = nullptr )

Render a single mesh to the offscreen buffer.

If camera is nullptr, a camera is auto-positioned to frame the mesh's world AABB from a 3/4 view angle.

A simple three-point directional light setup is used. The mesh's own material and shader are applied if present.

Parameters
meshMesh to render (must be loaded and have a material).
cameraOverride camera, or nullptr for auto-framing.

◆ renderMeshWithMaterial()

void kemena::kOffscreenRenderer::renderMeshWithMaterial ( kMesh * mesh,
kCamera * camera = nullptr )

Render a mesh using its assigned material shader and uniforms.

Unlike renderMesh(), which uses the built-in preview shader, this method binds the mesh's own kMaterial and kShader so that material properties (diffuse, metallic, textures, etc.) are visible in the result. A simple sun light is injected so the result is shaded.

The mesh must have a material with a compiled shader; if not, nothing is drawn.

Parameters
meshMesh to render.
cameraOverride camera, or nullptr for auto-framing.

◆ resize()

void kemena::kOffscreenRenderer::resize ( int newWidth,
int newHeight )

Resize the offscreen buffer.

Destroys and recreates the FBO. Any previous render result is lost.

Parameters
newWidthNew output texture width in pixels.
newHeightNew output texture height in pixels.

◆ saveToFile()

bool kemena::kOffscreenRenderer::saveToFile ( const kString & filePath) const

Save the current render result to an image file.

The format is determined by the file extension: .png — lossless, recommended .jpg — lossy, smaller .bmp — uncompressed .tga — uncompressed with alpha

Parameters
filePathDestination path including extension.
Returns
true on success.

◆ setBackgroundColor()

void kemena::kOffscreenRenderer::setBackgroundColor ( kVec4 color)
inline

Set the background clear color and alpha (default: opaque dark grey).

Set alpha to 0 for a fully transparent background — useful when compositing the thumbnail over other UI elements.

Parameters
colorRGBA clear color in linear/normalized [0,1] components.

The documentation for this class was generated from the following file: