|
Kemena3D
|
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. | |
Renders to an offscreen FBO for thumbnails, previews, and image export.
Usage:
| kemena::kOffscreenRenderer::kOffscreenRenderer | ( | int | width = 256, |
| int | height = 256 ) |
Construct the renderer and allocate its offscreen FBO.
| width | Output texture width in pixels. |
| height | Output texture height in pixels. |
| kemena::kOffscreenRenderer::~kOffscreenRenderer | ( | ) |
Destroy the renderer and release all GPU resources (FBO, textures, shaders).
|
inline |
Get the current background clear color and alpha.
|
inline |
Get the output texture height in pixels.
|
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.
|
inline |
Get the output texture width in pixels.
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.
| world | World (used only for skinning state, may be nullptr). |
| scene | Scene to render. |
| camera | Camera defining the viewpoint. |
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.
| mesh | Mesh to render (must be loaded and have a material). |
| camera | Override camera, or nullptr for auto-framing. |
| 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.
| mesh | Mesh to render. |
| camera | Override camera, or nullptr for auto-framing. |
| void kemena::kOffscreenRenderer::resize | ( | int | newWidth, |
| int | newHeight ) |
Resize the offscreen buffer.
Destroys and recreates the FBO. Any previous render result is lost.
| newWidth | New output texture width in pixels. |
| newHeight | New output texture height in pixels. |
| 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
| filePath | Destination path including extension. |
|
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.
| color | RGBA clear color in linear/normalized [0,1] components. |