|
Kemena3D
|
Orchestrates the full render pipeline for a scene. More...
#include <krenderer.h>
Public Member Functions | |
| kRenderer () | |
| bool | init (kWindow *window=nullptr, kRendererType type=kRendererType::RENDERER_GL) |
| Initialises the renderer and creates the graphics driver. | |
| void | destroy () |
| Destroys all GPU resources and the driver. | |
| void | setEngineInfo (const kString name, uint32_t version) |
| Stores an optional application name/version for driver diagnostics. | |
| kWindow * | getWindow () |
| Returns the window the renderer was initialised with. | |
| kDriver * | getDriver () |
| Returns the active graphics driver. | |
| void | clear () |
| Clears the active framebuffer to the clear colour. | |
| void | render (kWorld *world, kScene *scene, int x, int y, int width, int height, float deltaTime=0.0f, bool autoClearSwapWindow=true) |
| Renders the scene from the world's main camera. | |
| kVec4 | getClearColor () |
| Returns the background clear colour. | |
| void | setClearColor (kVec4 newColor) |
| Sets the background clear colour. | |
| void | setEnableScreenBuffer (bool newEnable, bool useDefaultShader=true) |
| Enables or disables the off-screen screen buffer (post-process FBO). | |
| bool | getEnableScreenBuffer () |
| Returns whether the screen buffer post-process FBO is active. | |
| void | setScreenShader (kShader *newShader) |
| Sets a custom screen-space shader for post-processing. | |
| kShader * | getScreenShader () |
| Returns the current screen-space shader. | |
| void | setEnableShadow (bool newEnable, bool useDefaultShader=true) |
| Enables or disables shadow mapping. | |
| bool | getEnableShadow () |
| Returns whether shadow mapping is active. | |
| void | setShadowShader (kShader *newShader) |
| Sets the shadow-map depth shader. | |
| kShader * | getShadowShader () |
| Returns the current shadow-map shader. | |
| void | setShadowCascadeCount (int count) |
| Sets the number of cascades (1..4). Cheap; the underlying texture array always allocates the maximum, so no realloc. | |
| int | getShadowCascadeCount () const |
| Returns the active cascade count. | |
| void | setShadowResolution (int resolution) |
| Sets the per-cascade shadow-map resolution (e.g. 1024/2048/4096). Rebuilds the shadow texture if shadows are enabled. | |
| int | getShadowResolution () const |
| Returns the per-cascade shadow-map resolution. | |
| void | setShadowSplitLambda (float lambda) |
| Sets the cascade split blend: 0 = uniform, 1 = logarithmic. | |
| float | getShadowSplitLambda () const |
| Returns the cascade split blend factor. | |
| void | setShadowDebug (bool enable) |
| Toggles a debug view that tints each cascade a distinct colour. | |
| bool | getShadowDebug () const |
| Returns whether the cascade debug view is active. | |
| void | setShadowBias (float bias) |
| Sets the constant shadow bias passed to lit shaders. | |
| float | getShadowBias () const |
| Returns the constant shadow bias. | |
| void | setShadowNormalBias (float bias) |
| Sets the slope-scaled (normal) shadow bias passed to lit shaders. | |
| float | getShadowNormalBias () const |
| Returns the slope-scaled shadow bias. | |
| void | setShadowSoftness (float softness) |
| Sets the PCF tap spacing (in shadow-map texels) passed to lit shaders. | |
| float | getShadowSoftness () const |
| Returns the PCF tap spacing. | |
| void | setEnableAutoExposure (bool newEnable) |
| Enables or disables automatic exposure adjustment. | |
| bool | getEnableAutoExposure () |
| Returns whether automatic exposure adjustment is active. | |
| void | resizeFbo (int newWidth, int newHeight) |
| Resizes the screen-buffer FBOs to match a new viewport size. | |
| uint32_t | getFboTexture () |
| Returns the resolved (single-sample) FBO colour texture handle. | |
| int | getFboWidth () |
| Returns the current FBO width in pixels. | |
| int | getFboHeight () |
| Returns the current FBO height in pixels. | |
| float | srgbToLinear (float c) |
| Converts an sRGB component value to linear space. | |
| kVec3 | idToRgb (unsigned int i) |
| Converts a packed integer ID to an RGB colour for object picking. | |
| unsigned int | rgbToId (unsigned int r, unsigned int g, unsigned int b) |
| Converts an RGB colour read back from the GPU to an object ID. | |
| void | setEnableObjectPicking (bool enable, bool useDefaultShader=true) |
| Enables or disables the color-ID picking FBO and compiles the built-in picking shader. | |
| bool | getEnableObjectPicking () |
| Returns whether color-ID object picking is active. | |
| void | setOctreeCullingEnabled (bool enable) |
| Enable or disable octree-based frustum culling (default: enabled). | |
| void | setOctreeDirty () |
| Marks the static-mesh octree as needing a rebuild. | |
| bool | getOctreeCullingEnabled () const |
| Returns whether octree frustum culling is active. | |
| void | setCullingCamera (kCamera *camera) |
| Override the camera used to compute the culling frustum. | |
| kCamera * | getCullingCamera () const |
| Returns the override culling camera, or nullptr if using main camera. | |
| const kOctree & | getOctree () const |
| Returns a reference to the scene octree (read-only). | |
| kObject * | pickObject (kWorld *world, kScene *scene, int mouseX, int mouseY, int viewWidth, int viewHeight) |
| Returns the scene object under the given viewport-relative pixel coordinate using a color-ID render pass. | |
| void | renderPickingPass (kWorld *world, kScene *scene, int viewWidth, int viewHeight) |
| Renders the color-ID picking pass into the picking FBO. | |
| void | setRenderMode (kRenderMode mode) |
| Sets the debug visualization mode for subsequent render() calls. | |
| kRenderMode | getRenderMode () |
| Returns the current debug visualization mode. | |
| void | renderOutline (kWorld *world, kScene *scene, const std::vector< kString > &selectedUuids, kVec4 color=kVec4(1.0f, 0.6f, 0.0f, 1.0f), float thickness=3.0f) |
| Renders a color-ID-based outline around selected objects. | |
| void | renderDebugShapes (kWorld *world, kScene *scene, const std::vector< kString > &selectedUuids) |
| Draws editor debug shapes for selected lights and cameras. | |
| void | setOctreeDebugEnabled (bool enable) |
| Enable or disable octree AABB wireframe debug visualization. | |
| bool | getOctreeDebugEnabled () const |
| Returns whether octree debug visualization is active. | |
| void | renderOctreeDebug (kWorld *world, kScene *scene) |
| Draws octree node AABBs and mesh world AABBs as wireframe boxes. | |
| void | renderDebugLines (kWorld *world, const std::vector< kVec3 > &segments, kVec3 color) |
| Draws world-space line segments in a single colour into the view FBO. Used for editor debug overlays (e.g. nav-mesh wireframe). Each consecutive pair of points is one line. | |
Orchestrates the full render pipeline for a scene.
Usage outline:
| kemena::kRenderer::kRenderer | ( | ) |
| void kemena::kRenderer::clear | ( | ) |
Clears the active framebuffer to the clear colour.
Binds the screen FBO (if enabled) before clearing so that subsequent render() calls draw into the same buffer.
| void kemena::kRenderer::destroy | ( | ) |
Destroys all GPU resources and the driver.
| kVec4 kemena::kRenderer::getClearColor | ( | ) |
Returns the background clear colour.
|
inline |
Returns the override culling camera, or nullptr if using main camera.
| kDriver * kemena::kRenderer::getDriver | ( | ) |
Returns the active graphics driver.
| bool kemena::kRenderer::getEnableAutoExposure | ( | ) |
Returns whether automatic exposure adjustment is active.
| bool kemena::kRenderer::getEnableObjectPicking | ( | ) |
Returns whether color-ID object picking is active.
| bool kemena::kRenderer::getEnableScreenBuffer | ( | ) |
Returns whether the screen buffer post-process FBO is active.
| bool kemena::kRenderer::getEnableShadow | ( | ) |
Returns whether shadow mapping is active.
| int kemena::kRenderer::getFboHeight | ( | ) |
Returns the current FBO height in pixels.
| uint32_t kemena::kRenderer::getFboTexture | ( | ) |
Returns the resolved (single-sample) FBO colour texture handle.
| int kemena::kRenderer::getFboWidth | ( | ) |
Returns the current FBO width in pixels.
|
inline |
Returns a reference to the scene octree (read-only).
|
inline |
Returns whether octree frustum culling is active.
|
inline |
Returns whether octree debug visualization is active.
| kRenderMode kemena::kRenderer::getRenderMode | ( | ) |
Returns the current debug visualization mode.
| kShader * kemena::kRenderer::getScreenShader | ( | ) |
Returns the current screen-space shader.
|
inline |
Returns the constant shadow bias.
|
inline |
Returns the active cascade count.
|
inline |
Returns whether the cascade debug view is active.
|
inline |
Returns the slope-scaled shadow bias.
|
inline |
Returns the per-cascade shadow-map resolution.
| kShader * kemena::kRenderer::getShadowShader | ( | ) |
Returns the current shadow-map shader.
|
inline |
Returns the PCF tap spacing.
|
inline |
Returns the cascade split blend factor.
| kWindow * kemena::kRenderer::getWindow | ( | ) |
Returns the window the renderer was initialised with.
| kVec3 kemena::kRenderer::idToRgb | ( | unsigned int | i | ) |
Converts a packed integer ID to an RGB colour for object picking.
| i | Object ID. |
| bool kemena::kRenderer::init | ( | kWindow * | window = nullptr, |
| kRendererType | type = kRendererType::RENDERER_GL ) |
Initialises the renderer and creates the graphics driver.
| window | Target window (may be nullptr for off-screen rendering). |
| type | Graphics backend to use. |
| kObject * kemena::kRenderer::pickObject | ( | kWorld * | world, |
| kScene * | scene, | ||
| int | mouseX, | ||
| int | mouseY, | ||
| int | viewWidth, | ||
| int | viewHeight ) |
Returns the scene object under the given viewport-relative pixel coordinate using a color-ID render pass.
Renders all mesh nodes into a dedicated picking FBO with each mesh colored by its unique ID, reads the pixel at (mouseX, mouseY), decodes the ID, and returns the corresponding kObject.
| world | World containing the active camera. |
| scene | Scene to pick from. |
| mouseX | Viewport-relative X coordinate (0 = left edge). |
| mouseY | Viewport-relative Y coordinate (0 = top edge). |
| viewWidth | Viewport width in pixels. |
| viewHeight | Viewport height in pixels. |
| void kemena::kRenderer::render | ( | kWorld * | world, |
| kScene * | scene, | ||
| int | x, | ||
| int | y, | ||
| int | width, | ||
| int | height, | ||
| float | deltaTime = 0.0f, | ||
| bool | autoClearSwapWindow = true ) |
Renders the scene from the world's main camera.
The render order is:
| world | World containing the main camera. |
| scene | Scene to render (lights, meshes, etc.). |
| x,y | Viewport origin in pixels. |
| width,height | Viewport dimensions in pixels. |
| deltaTime | Frame delta time in seconds (used for animation). |
| autoClearSwapWindow | If true, automatically clears and swaps the window. |
| void kemena::kRenderer::renderDebugLines | ( | kWorld * | world, |
| const std::vector< kVec3 > & | segments, | ||
| kVec3 | color ) |
Draws world-space line segments in a single colour into the view FBO. Used for editor debug overlays (e.g. nav-mesh wireframe). Each consecutive pair of points is one line.
| world | Supplies the main camera (view/projection). |
| segments | Flat list of point pairs. |
| color | Line colour (RGB). |
| void kemena::kRenderer::renderDebugShapes | ( | kWorld * | world, |
| kScene * | scene, | ||
| const std::vector< kString > & | selectedUuids ) |
Draws editor debug shapes for selected lights and cameras.
Renders wire shapes (light range spheres/cones, camera frustums, sun direction arrows) for any selected light or camera node.
Must be called after render() and before the final ImGui pass. Requires setEnableScreenBuffer(true).
| world | World containing the active editor camera. |
| scene | Scene whose lights and cameras are inspected. |
| selectedUuids | UUIDs of currently selected objects. |
Draws octree node AABBs and mesh world AABBs as wireframe boxes.
Octree leaf nodes: green, internal nodes: grey. Static mesh AABBs: yellow, dynamic mesh AABBs: cyan. Call after renderDebugShapes each frame.
| void kemena::kRenderer::renderOutline | ( | kWorld * | world, |
| kScene * | scene, | ||
| const std::vector< kString > & | selectedUuids, | ||
| kVec4 | color = kVec4(1.0f, 0.6f, 0.0f, 1.0f), | ||
| float | thickness = 3.0f ) |
Renders a color-ID-based outline around selected objects.
Requires renderPickingPass() to have been called this frame. Uses the picking texture to detect selection boundaries in screen space, then composites an outline with alpha blending — gives uniform pixel-width outlines on any mesh shape.
| world | World containing the active camera. |
| scene | Scene owning the selected objects. |
| selectedUuids | UUIDs of selected objects to outline. |
| color | Outline RGBA colour (default: orange). |
| thickness | Outline radius in pixels (default: 3). |
| void kemena::kRenderer::renderPickingPass | ( | kWorld * | world, |
| kScene * | scene, | ||
| int | viewWidth, | ||
| int | viewHeight ) |
Renders the color-ID picking pass into the picking FBO.
Should be called once per frame so the picking texture is always fresh. pickObject() will read from this texture instead of re-rendering.
| world | World containing the active camera. |
| scene | Scene to render. |
| viewWidth | Viewport width in physical pixels. |
| viewHeight | Viewport height in physical pixels. |
| void kemena::kRenderer::resizeFbo | ( | int | newWidth, |
| int | newHeight ) |
Resizes the screen-buffer FBOs to match a new viewport size.
Called automatically by render() when the viewport dimensions change.
| newWidth | New FBO width in pixels. |
| newHeight | New FBO height in pixels. |
| unsigned int kemena::kRenderer::rgbToId | ( | unsigned int | r, |
| unsigned int | g, | ||
| unsigned int | b ) |
Converts an RGB colour read back from the GPU to an object ID.
| r | Red channel value [0, 255]. |
| g | Green channel value [0, 255]. |
| b | Blue channel value [0, 255]. |
| void kemena::kRenderer::setClearColor | ( | kVec4 | newColor | ) |
Sets the background clear colour.
The input is expected to be in sRGB space and is converted to linear before being stored.
| newColor | sRGB RGBA colour. |
|
inline |
Override the camera used to compute the culling frustum.
By default (nullptr) the world's main camera is used. Set a different camera here to freeze or redirect the frustum — useful for debugging culling without changing the render viewpoint.
| camera | Camera to use for frustum extraction, or nullptr to revert to the main camera. |
| void kemena::kRenderer::setEnableAutoExposure | ( | bool | newEnable | ) |
Enables or disables automatic exposure adjustment.
When enabled, the average luminance of the resolved FBO colour texture is sampled each frame (via mipmaps) and used to drive an exposure value that is passed to the screen shader.
| newEnable | true to enable. |
| void kemena::kRenderer::setEnableObjectPicking | ( | bool | enable, |
| bool | useDefaultShader = true ) |
Enables or disables the color-ID picking FBO and compiles the built-in picking shader.
When enabled, pickObject() can be called to determine which scene object is under a given screen coordinate by rendering all meshes with unique solid ID colors and reading back the clicked pixel.
Intended for editor use — works for any object regardless of whether it has a physics body attached.
| enable | true to enable. |
| useDefaultShader | If true, a built-in picking shader is compiled automatically. |
| void kemena::kRenderer::setEnableScreenBuffer | ( | bool | newEnable, |
| bool | useDefaultShader = true ) |
Enables or disables the off-screen screen buffer (post-process FBO).
When enabled the scene is first rendered into an MSAA FBO, resolved to a single-sample texture, and then drawn to the screen via a full-screen quad shader.
| newEnable | true to enable. |
| useDefaultShader | If true, a built-in tone-mapping/gamma shader is compiled and set automatically. |
| void kemena::kRenderer::setEnableShadow | ( | bool | newEnable, |
| bool | useDefaultShader = true ) |
Enables or disables shadow mapping.
| newEnable | true to enable. |
| useDefaultShader | If true, a built-in depth-only shadow shader is compiled and set automatically. |
| void kemena::kRenderer::setEngineInfo | ( | const kString | name, |
| uint32_t | version ) |
Stores an optional application name/version for driver diagnostics.
| name | Application name. |
| version | Application version number. |
|
inline |
Enable or disable octree-based frustum culling (default: enabled).
When enabled, an octree is rebuilt each frame from all scene meshes and only meshes whose world AABB intersects the camera frustum are rendered.
|
inline |
Enable or disable octree AABB wireframe debug visualization.
|
inline |
Marks the static-mesh octree as needing a rebuild.
Call this whenever a static mesh is added, removed, or moved. The octree rebuilds once on the next rendered frame, then stays valid until marked dirty again.
| void kemena::kRenderer::setRenderMode | ( | kRenderMode | mode | ) |
Sets the debug visualization mode for subsequent render() calls.
| mode | One of the kRenderMode values. |
| void kemena::kRenderer::setScreenShader | ( | kShader * | newShader | ) |
Sets a custom screen-space shader for post-processing.
| newShader | Shader to use; the renderer takes ownership. |
|
inline |
Sets the constant shadow bias passed to lit shaders.
| void kemena::kRenderer::setShadowCascadeCount | ( | int | count | ) |
Sets the number of cascades (1..4). Cheap; the underlying texture array always allocates the maximum, so no realloc.
|
inline |
Toggles a debug view that tints each cascade a distinct colour.
|
inline |
Sets the slope-scaled (normal) shadow bias passed to lit shaders.
| void kemena::kRenderer::setShadowResolution | ( | int | resolution | ) |
Sets the per-cascade shadow-map resolution (e.g. 1024/2048/4096). Rebuilds the shadow texture if shadows are enabled.
| void kemena::kRenderer::setShadowShader | ( | kShader * | newShader | ) |
Sets the shadow-map depth shader.
| newShader | Shader used for the shadow pass. |
|
inline |
Sets the PCF tap spacing (in shadow-map texels) passed to lit shaders.
|
inline |
Sets the cascade split blend: 0 = uniform, 1 = logarithmic.
| float kemena::kRenderer::srgbToLinear | ( | float | c | ) |
Converts an sRGB component value to linear space.
| c | sRGB channel value in [0, 1]. |