Graphics & compute

CRender

Render models, procedural geometry, lighting, and animation into a bitmap.

C++23 mc/CRender.h macOS
#include <mc/CRender.h>

Link Catalyst::MacShared or Catalyst::MacStatic. A supplied output buffer is borrowed and must hold width × height × 4 bytes.

Create or load a model to obtain its ID, submit it with draw(), then call render(). Keep model IDs within the renderer that created them.

Jump to a declaration · 52

CRender

class CRender

Types, constants & data

using Colors = CVector<double4>;
enum class WrapMode { Repeat, Clamp };
enum class FilterMode { Nearest, Linear };

Methods

CRender

CRender(size_t width, size_t height, unsigned char* buf = nullptr);
CRender(const CRender&) = delete;

Creates a renderer and output bitmap. A supplied buffer is borrowed and must hold width × height × 4 bytes; omit it for renderer-owned storage.

buffer

unsigned char* buffer();

Returns borrowed pixel storage; keep the renderer alive while using it.

clear

void clear();

Resets the output bitmap to the background and resets depth storage. It retains loaded models and queued draw commands.

render

void render();

Renders the submitted model instances into the bitmap and consumes the draw-command list. Submit the instances again for another frame.

setTextureWrap

void setTextureWrap(WrapMode wrapU, WrapMode wrapV);

Selects repeat or edge-clamp behavior independently for the U and V texture coordinates.

setTextureFilter

void setTextureFilter(FilterMode filter);

Selects nearest or linear texture sampling for rendered model textures.

setRaytracingBounces

void setRaytracingBounces(size_t bounces);

Sets the allowed reflection/path bounce depth for the raytracing path. More bounces can increase rendering work.

setToneMapping

void setToneMapping(bool enabled);

Enables or disables the tone-mapping step used to bring rendered brightness into the display range.

setExposure

void setExposure(double exposure);

Sets a positive brightness multiplier for output color processing. This is a multiplier, not a value in photographic stops.

setGamma

void setGamma(double gamma);

Sets a positive gamma value for output color processing.

loadGLB

size_t loadGLB(const cstr& path);

Loads a binary glTF model and returns a renderer-local model ID.

animationCount

size_t animationCount(size_t modelId) const;

Returns the number of animation clips in a loaded model. Animation IDs are zero-based within that model.

animationName

cstr animationName(size_t modelId, size_t animationId) const;

Returns the loaded clip’s name. The model and animation IDs must be valid.

setAnimation

void setAnimation(size_t modelId, size_t animationId);

Selects a model’s active animation without resetting its time or speed. Use setAnimationTime() when an explicit starting position is needed.

clearAnimation

void clearAnimation(size_t modelId);

Disables the model’s selected animation and restores its unanimated pose on the next render.

setAnimationTime

void setAnimationTime(size_t modelId, double seconds);

Sets the animation time in seconds for the next render. Call this each frame to drive playback explicitly; rendering does not advance animation time automatically.

setAnimationLoop

void setAnimationLoop(size_t modelId, bool enabled);

Controls whether sampling wraps at the end of the clip or stops at its boundary.

setAnimationSpeed

void setAnimationSpeed(size_t modelId, double speed);

Sets the multiplier applied to animation sampling time. The actual frame position is controlled with setAnimationTime().

playAnimation

void playAnimation(size_t modelId, size_t animationId, double speed = 1.0, bool loop = true);

Selects a clip, clears blending, sets its speed and loop mode, and unpauses it. It does not start a rendering thread or reset the animation time.

setAnimationPaused

void setAnimationPaused(size_t modelId, bool paused);

Sets the model’s playback pause flag. Drawing and rendering remain explicit operations.

animationDuration

double animationDuration(size_t modelId, size_t animationId) const;

Returns the selected clip’s duration in seconds. Both model and clip IDs must be valid.

draw

void draw(size_t modelId, const double3& pos, const double3& size, const double4& rot);
void draw(size_t modelId, const double3& pos, const double3& size);
void draw(size_t modelId, const double3& pos);

Queues an instance of a loaded model at pos with per-axis scale size and quaternion rotation (x, y, z, w). Omitted scale is (1,1,1) and omitted rotation is identity; no pixels are produced until render().

lookAt

void lookAt(const double3& pos);

Sets the world-space point toward which the camera looks. Use setCamera() to change the camera’s position.

setCamera

void setCamera(const double3& pos);

Sets the camera position in world coordinates without changing its target.

setProjection

void setProjection(double verticalFovDegrees, double nearClip, double farClip);

Sets vertical field of view in degrees and the near/far clipping planes.

setBackfaceCulling

void setBackfaceCulling(bool flag);

Controls whether triangles facing away from the camera are discarded during rendering.

setFrustumCulling

void setFrustumCulling(bool flag);

Controls rejection of geometry outside the camera’s visible volume.

setRaytracing

void setRaytracing(bool flag);

Switches between Metal ray tracing and Metal raster rendering. Enabling ray tracing throws when it is unavailable on the current Mac.

setAntialiasing

void setAntialiasing(bool flag);

Controls the renderer’s antialiasing step for smoother image edges.

unload

void unload(size_t modelId);

Releases a loaded model and removes its queued instances. An unknown model ID is a no-op; a released ID must not be reused for drawing.

setLightDirection

void setLightDirection(const double3& dir);

Sets the direction used for directional lighting. Supply a nonzero direction vector.

setLight

void setLight(double ambient, double diffuse);

Sets the ambient and diffuse lighting strengths used when shading geometry.

box

size_t box(const Colors& faceColors, const double3& size);
size_t box(const double4& color, const double3& size);

Creates box geometry and returns its model ID. The color overload applies one RGBA color throughout; the vector overload supplies per-face colors.

sphere

size_t sphere(const double4& color, double radius, size_t nlat, size_t nlon);

Creates sphere geometry and returns its model ID. nlat and nlon control latitude and longitude tessellation.

capsule

size_t capsule(const double4& color, double radius, double height, size_t slices, size_t stacks);

Creates capsule geometry and returns its model ID. Radius, height, slices, and stacks control its dimensions and tessellation.

cylinder

size_t cylinder(const double4& color, double radius, double height, size_t slices);

Creates cylinder geometry and returns its model ID. slices controls radial tessellation.

cone

size_t cone(const double4& color, double radius, double height, size_t slices);

Creates cone geometry and returns its model ID. slices controls radial tessellation.

plane

size_t plane(const double4& color, const double2& size);
size_t plane(const double4& color, const double2& size, size_t nx, size_t ny);

Creates plane geometry and returns its model ID. The nx/ny overload subdivides the plane along its two axes.

torus

size_t torus(const double4& color, double majorRadius, double minorRadius, size_t majorSegments, size_t minorSegments);

Creates torus geometry and returns its model ID. Major/minor radii describe the ring and tube; segment counts control their tessellation.

icosphere

size_t icosphere(const double4& color, double radius, size_t subdivisions);

Creates a sphere by subdividing an icosahedron and returns its model ID. Increasing subdivisions increases geometry rapidly.

roundedBox

size_t roundedBox(const double4& color, const double3& size, double radius, size_t segments);

Creates rounded-box geometry and returns its model ID. Radius sets the corner rounding and segments control its approximation.