API reference
C API
RASM is a C++ library, but a C program, or a binding in Python, C#, Rust or Zig, can use it through rasm/rasm_c.h and one shared library. This page shows how to link it, the rules the header keeps so old programs keep working with new libraries, every function, and which C++ call each one forwards to. The ideas behind the rules are in A stable C ABI.
In short
- Link exactly one of two shared libraries:
rasm_c(renderer,Engine,AssetLoader) orrasm_c_renderer(the renderer alone: no SDL3, no file loaders). Both export the same renderer functions. - Objects are opaque pointers (
rasm_renderer,rasm_engine, ...). Scene objects are 64-bit handles in a typed struct,{ uint64_t id; }, and 0 is invalid. - A struct that starts with
sizecan grow: fill it with its _init function, which setssize = sizeof. - A call that can fail returns a
rasm_result(RASM_OKis 0), or a 0 handle.rasm_get_last_errorsays why, for this thread. - No exception, no C++ type and no allocator crosses the boundary. Your memory stays yours; the library's stays the library's.
- A frame of your own: a
rasm_render_graphwith RASM's passes and yours, each a C function the graph calls with arasm_commandsthat is valid only during the call (the render graph). - Dear ImGui windows from C or a binding: RASM calls your UI callback each frame, and your binding's own Dear ImGui (cimgui, ImGui.NET, imgui-rs) draws into RASM's context (Dear ImGui from another language).
1Link it
RASM builds both libraries when the CMake option RASM_C_API is on (the default, but off under add_subdirectory). cmake --install puts them into bin/ on Windows and lib/ elsewhere, with a shaders/ folder beside them, the header in include/rasm/, and on Windows the DLLs they load. A CMake project finds them as the component c, which needs no vcpkg and no other package:
cmake_minimum_required(VERSION 3.23)
project(my_app C)
find_package(rasm 0.1 CONFIG REQUIRED COMPONENTS c)
add_executable(my_app main.c)
target_link_libraries(my_app PRIVATE rasm::c) # or rasm::c_renderer
| Library | CMake target | Has | Does not have |
|---|---|---|---|
rasm_c | rasm::c | every function: the renderer, rasm_engine_* (an SDL window, native or headless) and rasm_asset_loader_* (glTF, OBJ, PNG, JPEG, KTX2, HDR files) | — |
rasm_c_renderer | rasm::c_renderer | the renderer functions: your window or offscreen images, meshes and textures from memory | SDL3, the file loaders and libktx; no rasm_engine_* or rasm_asset_loader_*, and their _init functions |
rasm_* renderer functions, each from its own copy of RASM. A program that loads both gets whichever one the loader finds first, for each function.Relative paths resolve against the folder of the binary that holds RASM. For a C++ program linked to the static libraries that is the executable's folder. For rasm_c and rasm_c_renderer it is the shared library's own folder, whatever program loaded it (python.exe, a game engine's editor). So shader_dir left at NULL finds the installed shaders/ beside the library. rasm_get_base_path gives that folder. Pass your own assets as absolute paths, or set asset_root to an absolute folder: a binding rarely ships its assets beside the library.
2A first program
A headless renderer that draws one triangle and writes it to a PNG. It needs no file but the shaders. examples/22_c_api/main.c is the bigger version: an engine with an SDL window, files from the asset loader, a mesh and a texture from memory, and a ground streamed as tiles.
#include "rasm/rasm_c.h"
#include <stdio.h>
int main(void)
{
rasm_renderer_config config;
rasm_renderer_config_init(&config, sizeof(config));
config.window_width = 640;
config.window_height = 480;
rasm_renderer *renderer = NULL;
if (rasm_renderer_create(RASM_C_API_VERSION, &config, &renderer) != RASM_OK)
{
fprintf(stderr, "%s\n", rasm_get_last_error());
return 1;
}
const rasm_vertex vertices[3] = {
{.position = {-1.0f, -1.0f, 0.0f}, .normal = {0.0f, 0.0f, 1.0f}},
{.position = {1.0f, -1.0f, 0.0f}, .normal = {0.0f, 0.0f, 1.0f}},
{.position = {0.0f, 1.0f, 0.0f}, .normal = {0.0f, 0.0f, 1.0f}},
};
const uint32_t indices[3] = {0, 1, 2};
const rasm_scene scene = rasm_create_scene(renderer);
const rasm_mesh mesh = rasm_create_mesh(renderer, vertices, 3, indices, 3, NULL);
rasm_add_entity_to_scene(renderer, scene, rasm_create_entity(renderer, "triangle", mesh, (rasm_material){0}, NULL));
rasm_light_desc sun;
rasm_light_desc_init(&sun, sizeof(sun));
sun.direction = (rasm_vec3){0.0f, 0.0f, -1.0f};
sun.range = 0.0f;
rasm_add_light_to_scene(renderer, scene, rasm_create_light(renderer, &sun));
rasm_camera_projection projection;
rasm_camera_projection_init(&projection, sizeof(projection));
projection.aspect = 640.0f / 480.0f;
const rasm_transform eye = {{0.0f, 0.0f, 3.0f}, {0.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 1.0f}};
const rasm_camera camera = rasm_create_camera(renderer, &projection, &eye);
rasm_add_camera_to_scene(renderer, scene, camera);
rasm_render(renderer, scene, camera);
const rasm_readback readback = rasm_read_frame(renderer, RASM_READBACK_FORMAT_RGBA8_SRGB);
rasm_render(renderer, scene, camera);
rasm_image *image = rasm_image_create();
if (rasm_take_readback(renderer, readback, image) == RASM_OK)
rasm_image_write_png(image, "triangle.png");
rasm_image_destroy(image);
rasm_renderer_destroy(renderer);
return 0;
}
From Python, the same calls go through ctypes: declare each struct with the header's fields in order, then load the library. tests/c_api/ctypes_smoke.py is a whole script, which CI runs against the installed rasm_c.
lib = ctypes.CDLL("bin/rasm_c.dll")
config = RendererConfig()
lib.rasm_renderer_config_init(ctypes.byref(config), ctypes.sizeof(config))
renderer = ctypes.c_void_p()
lib.rasm_renderer_create((1 << 16) | 0, ctypes.byref(config), ctypes.byref(renderer))
3The rules of the header
Versions
RASM_C_API_VERSION is major << 16 | minor: RASM_C_API_VERSION_MAJOR and RASM_C_API_VERSION_MINOR, 1.16 today: 1.1 added windows, input, views, render targets, camera helpers, animation and stats to 1.0, 1.2 added positions in doubles (below), a free-fly controller's up axis and an environment's orientation, 1.3 tile streaming (below) and the renderer config's max_bindless_textures, and 1.4 terrain tiles (below), the formats RASM_FORMAT_R16_UNORM and RASM_FORMAT_R32_SFLOAT, the material type RASM_MATERIAL_TYPE_TERRAIN and the material desc's terrain, and 1.5 meshes built on any thread and vector features (below), RASM_MATERIAL_TYPE_VECTOR and the material desc's vector, and 1.6 fonts and labels (below), RASM_FORMAT_R8_UNORM and the material desc's font, and 1.7 picking (below) and RASM_FORMAT_R32G32B32A32_UINT, and 1.8 orthographic controls and reference grids (below) and the camera input's pan_start, pan_end and pointer, and 1.9 a line shape's drape_width, and 1.10 colormaps and point clouds (below), RASM_MATERIAL_TYPE_POINTS, the material desc's points, the renderer config's geometry_pool_points, RASM_PICK_SKIP_POINTS and RASM_PICK_HIT_POINT, and 1.11 small points by compute (below, the renderer config's compute_points), and 1.12 point cloud streaming (below), the point material's size_mode and max_size, the chunk desc's spacing and the pool stats' points, all at the end of the header, and 1.13 the renderer config's shader_threads (RendererConfig::shaderThreads), and 1.14 instanced glyphs and data lines (below), RASM_MATERIAL_TYPE_GLYPHS, the material desc's glyphs and vector_colors, the frame stats' glyphs and glyphs_visible, RASM_PICK_SKIP_GLYPHS and RASM_PICK_HIT_GLYPH, and 1.15 the material desc's blend_method (below), and 1.16 offscreen export at any size (below). Within one major version the API only grows at its end: new functions, new enum constants, new struct fields after the last one. Nothing is renumbered, reordered or removed. rasm_renderer_create and rasm_engine_create take your RASM_C_API_VERSION and fail with RASM_ERROR_VERSION when the major versions differ, or when your minor version is newer than the library's: a newer header may use fields or functions the library does not have.
Structs that grow
size field says how much of the struct your program knows. The library never reads or writes past it: a light from a 1.1 program is at its float position plus 0.- Fill a sized struct with its _init function, which writes the defaults and sets
size:rasm_renderer_config_init(&config, sizeof(config)). The defaults are the C++ API's. - Create (
rasm_create_light,rasm_renderer_create): a field past yoursizetakes its default. Update (rasm_update_light,rasm_update_material): it keeps its current value. Get (rasm_get_light,rasm_get_material): setsizebefore the call; the library writes only that much. - A
sizebelow the struct's 1.0 size fails withRASM_ERROR_INVALID_ARGUMENT. - In an array of sized structs, every element must have the
sizeof the first one: the library steps through the array by it. - Small value structs have no
size:rasm_vec2,rasm_vec3,rasm_vec4,rasm_quat,rasm_mat4(column-major),rasm_transform,rasm_native_window,rasm_vertex,rasm_texture_transform,rasm_image_data,rasm_view_rect,rasm_view_pixels,rasm_input_area,rasm_ui_input_capture. A change to one of them would be a new struct and new functions.
Types and handles
- Fixed sizes only:
uint32_t,int32_t,uint64_t,float,double, pointers. An enum is atypedef uint32_t(rasm_format,rasm_light_type, ...) withRASM_*constants of fixed values, because a Cenumhas no fixed size. A boolean israsm_bool, auint32_twithRASM_TRUEandRASM_FALSE. - Opaque objects:
rasm_renderer,rasm_engine,rasm_asset_loader,rasm_image,rasm_camera_rig,rasm_camera_input_state. You hold pointers; their layout is the library's. - Handles:
rasm_scene,rasm_entity,rasm_mesh,rasm_material,rasm_texture,rasm_light,rasm_camera,rasm_environment,rasm_readback,rasm_window,rasm_render_target. Each is{ uint64_t id; }: a distinct type in C, a plain 64-bit integer for a binding. The id is the C++ handle'sgeneration << 32 | index(Generational handles); a generation starts at 1 and stops atMAX_HANDLE_GENERATION, so a valid handle is never 0 and always fits.(rasm_material){0}is "no material", as an invalid C++ handle is. - Every function is
RASM_C_API(exported) andRASM_CALL:__cdeclon 32-bit Windows, the platform's C convention elsewhere. A binding declares the same;rasm_log_callbackuses it too.
Errors
| Code | Value | Means |
|---|---|---|
RASM_OK | 0 | done |
RASM_ERROR_INVALID_ARGUMENT | -1 | a NULL pointer, a size too small, a value that is none of its constants |
RASM_ERROR_FAILED | -2 | RASM refused the call or it failed: a stale handle, a GPU error. RASM logged why. |
RASM_ERROR_OUT_OF_MEMORY | -3 | an allocation failed |
RASM_ERROR_INTERNAL | -4 | an exception reached the C layer, which caught it |
RASM_ERROR_VERSION | -5 | your RASM_C_API_VERSION does not fit this library |
- A call on an object rejects the handle 0 with
RASM_ERROR_INVALID_ARGUMENT, so a failed create is not mistaken for an object. - A creation call returns a 0 handle when it fails. A call whose C++ counterpart returns nothing returns
RASM_ERROR_FAILEDwhen RASM logged an error during it, sorasm_destroy_entityof a stale handle tells you. rasm_get_last_errorgives the last error of the calling thread, from the C layer or from RASM's log: "rasm_create_scene: renderer is NULL.". A call that succeeds does not clear it;rasm_clear_last_errordoes.
Memory and threads
- In: pointers you pass are read during the call only: strings (UTF-8, NUL-terminated), arrays (a pointer and a count), structs. RASM copies what it keeps.
- Out: into your structs, or into your buffer for a string: a
char* buffer, uint32_t capacitypair works likesnprintf. It writes what fits with its NUL and returns the whole length, so call it withNULL, 0first to size the buffer. - Library objects: what _create returns lives until its _destroy.
rasm_image_getgives a pointer into the image, valid until the image is filled again or destroyed. An engine's renderer and loader (rasm_engine_get_renderer,rasm_engine_get_asset_loader) belong to it:rasm_engine_destroydestroys them, and their own destroy calls refuse. - Threads: the rules of the C++ API. Call a renderer, its engine and its loader from one thread. The last error is per thread. The log callback can run on the loader's worker threads, and on two threads at once; RASM holds no lock while it runs, so it may call RASM on its own thread.
4Functions
Each function forwards to the C++ call of the same name, documented on the other API pages; the notes here are only what differs in C. A renderer function takes the renderer first: rasm_create_entity(renderer, ...) is renderer.createEntity(...). A NULL renderer is an error, never a crash.
uint32_t rasm_get_version(void); const char* rasm_get_last_error(void); void rasm_clear_last_error(void); void rasm_set_log_callback(rasm_log_callback callback, void* user_data); uint32_t rasm_get_base_path(char* buffer, uint32_t capacity); typedef void (RASM_CALL* rasm_log_callback)(void* user_data, rasm_log_level level, const char* message);
rasm_get_version is the library's RASM_C_API_VERSION. rasm_get_last_error never returns NULL; the text is valid until the thread's next error. rasm_set_log_callback gets every line RASM logs (rasm_log_level: RASM_LOG_LEVEL_TRACE 0 to RASM_LOG_LEVEL_CRITICAL 5), besides the console; NULL turns it off. The message is valid during the call.
rasm_get_base_path is the folder relative paths resolve against: the shared library's folder, UTF-8 with / separators.
rasm_result rasm_renderer_config_init(rasm_renderer_config* config, uint32_t size); rasm_result rasm_renderer_create(uint32_t api_version, const rasm_renderer_config* config, rasm_renderer** renderer); void rasm_renderer_destroy(rasm_renderer* renderer);
A rasm::Renderer (engine.html). rasm_renderer_config has the fields of RendererConfig in snake case, in the same order but max_bindless_textures (1.3), geometry_pool_points (1.10), compute_points (1.11) and shader_threads (1.13), which come last; its strings may be NULL for empty, and cache_dir starts as the library's "cache". With native_window.type set it draws into your window; without, into offscreen images of window_width × window_height pixels. It fails with RASM_ERROR_FAILED and sets *renderer to NULL when the renderer did not start (no Vulkan 1.4 device, no shaders). Destroying an engine's renderer is refused.
rasm_result rasm_engine_config_init(rasm_engine_config* config, uint32_t size); rasm_result rasm_asset_loader_config_init(rasm_asset_loader_config* config, uint32_t size); rasm_result rasm_engine_create(uint32_t api_version, const rasm_engine_config* config, rasm_engine** engine); void rasm_engine_destroy(rasm_engine* engine); rasm_renderer* rasm_engine_get_renderer(rasm_engine* engine); rasm_asset_loader* rasm_engine_get_asset_loader(rasm_engine* engine);
rasm_c only. A rasm::Engine (engine.html). rasm_engine_config is {size, platform, renderer, loader}: a rasm_platform_type (RASM_PLATFORM_TYPE_SDL, RASM_PLATFORM_TYPE_HEADLESS, RASM_PLATFORM_TYPE_NATIVE) and pointers to the two parts, each a sized struct of its own; a NULL loader takes its defaults. Every renderer function works on rasm_engine_get_renderer(engine), and every load on rasm_engine_get_asset_loader(engine).
rasm_result rasm_asset_loader_create(rasm_renderer* renderer, const rasm_asset_loader_config* config, rasm_asset_loader** loader); void rasm_asset_loader_destroy(rasm_asset_loader* loader); rasm_mesh rasm_asset_loader_load_mesh(rasm_asset_loader* loader, const char* path); rasm_mesh rasm_asset_loader_load_gltf(rasm_asset_loader* loader, const char* path); rasm_texture rasm_asset_loader_load_texture(rasm_asset_loader* loader, const char* path, rasm_format format); rasm_environment rasm_asset_loader_load_environment(rasm_asset_loader* loader, const char* path); void rasm_asset_loader_wait_for_loads(rasm_asset_loader* loader); uint32_t rasm_asset_loader_resolve_asset_path(rasm_asset_loader* loader, const char* path, char* buffer, uint32_t capacity);
rasm_c only. An AssetLoader for a renderer you made with rasm_renderer_create (a NULL config takes the defaults); the renderer must outlive it. rasm_asset_loader_config is {size, asset_root, load_threads, load_memory_budget}. Each load returns its handle at once; rasm_is_mesh_loaded says when it is in. format of a texture names the slot: RASM_FORMAT_R8G8B8A8_SRGB for color, RASM_FORMAT_R8G8B8A8_UNORM for data.
rasm_bool rasm_running(rasm_renderer* renderer); void rasm_render(rasm_renderer* renderer, rasm_scene scene, rasm_camera camera); void rasm_wait_for_loads(rasm_renderer* renderer); rasm_bool rasm_is_mesh_loaded(rasm_renderer* renderer, rasm_mesh mesh); rasm_bool rasm_is_texture_loaded(rasm_renderer* renderer, rasm_texture texture); rasm_bool rasm_is_environment_loaded(rasm_renderer* renderer, rasm_environment environment);
One frame of one scene through one camera into the main window, like render(scene, camera): it polls the window's events, uploads what changed, draws and presents. Loop while rasm_running is true; with the SDL platform it turns false when the window closes. The rasm_is_*_loaded calls are the overloads of isLoaded.
rasm_scene rasm_create_scene(rasm_renderer* renderer); rasm_result rasm_destroy_scene(rasm_renderer* renderer, rasm_scene scene); rasm_result rasm_add_entity_to_scene(rasm_renderer* renderer, rasm_scene scene, rasm_entity entity); rasm_result rasm_remove_entity_from_scene(rasm_renderer* renderer, rasm_scene scene, rasm_entity entity); rasm_result rasm_add_camera_to_scene(rasm_renderer* renderer, rasm_scene scene, rasm_camera camera); rasm_result rasm_add_light_to_scene(rasm_renderer* renderer, rasm_scene scene, rasm_light light); rasm_result rasm_remove_light_from_scene(rasm_renderer* renderer, rasm_scene scene, rasm_light light); rasm_result rasm_scene_environment_init(rasm_scene_environment* environment, uint32_t size); rasm_result rasm_set_scene_environment(rasm_renderer* renderer, rasm_scene scene, const rasm_scene_environment* environment); rasm_result rasm_destroy_environment(rasm_renderer* renderer, rasm_environment environment);
See scene.html. rasm_scene_environment is SceneEnvironment: {size, environment, intensity, rotation, sky, orientation}; orientation (1.2, a rasm_quat, identity by default, and all zeros counts as the identity, so a zero-filled struct works) turns the environment into a local frame, such as a globe's east, up and south.
rasm_entity rasm_create_entity(rasm_renderer* renderer, const char* name, rasm_mesh mesh, rasm_material material, const rasm_transform* transform); rasm_result rasm_destroy_entity(rasm_renderer* renderer, rasm_entity entity); rasm_result rasm_get_transform(rasm_renderer* renderer, rasm_entity entity, rasm_transform* transform); rasm_result rasm_update_transform(rasm_renderer* renderer, rasm_entity entity, const rasm_transform* transform);
See scene.html. A NULL transform is the identity: position 0, rotation {0, 0, 0, 1} (x, y, z, w), scale 1. A 0 material draws with the mesh's own glTF materials, or the default one.
rasm_transform's position is three floats, while the engine keeps doubles: rasm_get_transform rounds a far position, and writing it back moves the entity. Far from the origin use rasm_get_transform_d and rasm_update_transform_d (1.2).
rasm_mesh rasm_create_mesh(rasm_renderer* renderer, const rasm_vertex* vertices, uint32_t vertex_count, const uint32_t* indices, uint32_t index_count, const uint32_t* colors); rasm_result rasm_destroy_mesh(rasm_renderer* renderer, rasm_mesh mesh); uint32_t rasm_pack_vertex_color(rasm_vec4 linear_color);
createMesh from your arrays. rasm_vertex has the layout of rasm::Vertex (64 bytes: position, normal, uv[RASM_MAX_VERTEX_UV_SETS], tangent), so the library copies it as it is, once, into the vectors the C++ call takes. colors is NULL, or one packed color per vertex from rasm_pack_vertex_color.
rasm_material rasm_create_material(rasm_renderer* renderer, rasm_material_type type, const rasm_texture* textures, uint32_t texture_count, rasm_bool double_sided); rasm_result rasm_get_material(rasm_renderer* renderer, rasm_material material, rasm_material_desc* desc); rasm_result rasm_update_material(rasm_renderer* renderer, rasm_material material, const rasm_material_desc* desc); rasm_result rasm_destroy_material(rasm_renderer* renderer, rasm_material material); rasm_result rasm_texture_desc_init(rasm_texture_desc* desc, uint32_t size); rasm_texture rasm_create_texture(rasm_renderer* renderer, const rasm_texture_desc* desc, const void* pixels); rasm_result rasm_destroy_texture(rasm_renderer* renderer, rasm_texture texture);
See materials.html. rasm_material_desc is Material without its name and handle: type, textures, tex_coords and texture_transforms per rasm_pbr_slot, params[RASM_MAX_PARAM_SLOTS] indexed by rasm_pbr_param (RASM_PBR_PARAM_ALBEDO is 4 floats), double_sided, alpha_mode, alpha_cutoff. Get it, change fields, update it:
rasm_material_desc desc;
desc.size = sizeof(desc);
rasm_get_material(renderer, material, &desc);
desc.params[RASM_PBR_PARAM_ROUGHNESS] = 0.85f;
rasm_update_material(renderer, material, &desc);
1.15: rasm_material_desc::blend_method, the last field, is BlendMethod for a RASM_ALPHA_MODE_BLEND material: RASM_BLEND_METHOD_SORTED (the default), RASM_BLEND_METHOD_WEIGHTED (weighted blended transparency) or RASM_BLEND_METHOD_ADDITIVE. A desc whose size ends before it keeps the material's method; a value past RASM_BLEND_METHOD_ADDITIVE is RASM_ERROR_INVALID_ARGUMENT.
rasm_create_texture makes a texture from your RGBA8 pixels, rows top to bottom, and its mips: rasm_texture_desc is {size, name, width, height, format} with RASM_FORMAT_R8G8B8A8_SRGB (color, the default) or RASM_FORMAT_R8G8B8A8_UNORM (data). Compressed textures come from KTX2 files through the loader.
rasm_result rasm_light_desc_init(rasm_light_desc* desc, uint32_t size); rasm_light rasm_create_light(rasm_renderer* renderer, const rasm_light_desc* desc); rasm_result rasm_get_light(rasm_renderer* renderer, rasm_light light, rasm_light_desc* desc); rasm_result rasm_update_light(rasm_renderer* renderer, rasm_light light, const rasm_light_desc* desc); rasm_result rasm_destroy_light(rasm_renderer* renderer, rasm_light light);
See scene.html. rasm_light_desc is Light without its handle: type (RASM_LIGHT_TYPE_DIRECTIONAL, RASM_LIGHT_TYPE_POINT, RASM_LIGHT_TYPE_SPOT), intensity, range, color, position, direction, inner_cone_angle, outer_cone_angle, and from 1.2 position_d, a rasm_dvec3 added to position: the light is at position + position_d, in doubles. rasm_get_light gives the float nearest to the position and the rest, so a get and an update keep it bit for bit. A 1.1 caller's update keeps the exact position when it leaves position as it got it, and puts the light at the float position otherwise; rasm_set_camera_controller does the same with a trackball's center. Its init gives a directional light.
rasm_result rasm_camera_projection_init(rasm_camera_projection* projection, uint32_t size); rasm_camera rasm_create_camera(rasm_renderer* renderer, const rasm_camera_projection* projection, const rasm_transform* transform); rasm_result rasm_destroy_camera(rasm_renderer* renderer, rasm_camera camera); rasm_result rasm_get_camera_transform(rasm_renderer* renderer, rasm_camera camera, rasm_transform* transform); rasm_result rasm_set_camera_transform(rasm_renderer* renderer, rasm_camera camera, const rasm_transform* transform); rasm_result rasm_get_camera_projection(rasm_renderer* renderer, rasm_camera camera, rasm_camera_projection* projection); rasm_result rasm_set_camera_projection(rasm_renderer* renderer, rasm_camera camera, const rasm_camera_projection* projection); float rasm_get_camera_exposure(rasm_renderer* renderer, rasm_camera camera); rasm_result rasm_set_camera_exposure(rasm_renderer* renderer, rasm_camera camera, float exposure); float rasm_get_camera_bloom_strength(rasm_renderer* renderer, rasm_camera camera); rasm_result rasm_set_camera_bloom_strength(rasm_renderer* renderer, rasm_camera camera, float strength); rasm_result rasm_reset_camera_history(rasm_renderer* renderer, rasm_camera camera); rasm_result rasm_get_view_matrix(rasm_renderer* renderer, rasm_camera camera, rasm_mat4* matrix); rasm_result rasm_get_projection_matrix(rasm_renderer* renderer, rasm_camera camera, float aspect, rasm_mat4* matrix);
See camera.html. rasm_camera_projection is CameraProjection without its union, a sized struct: type (RASM_PROJECTION_TYPE_PERSPECTIVE or RASM_PROJECTION_TYPE_ORTHOGRAPHIC), fov_y (degrees) and aspect for a perspective, left, right, bottom, top for an orthographic one, near_z and far_z for both (a perspective far_z of 0 is infinite). Its init gives a perspective of 45 degrees, aspect 1, near_z 0.1 and an infinite far plane. A camera has no controller in C yet: place it with rasm_set_camera_transform. rasm_get_projection_matrix with an aspect of 0 uses the camera's own.
rasm_readback rasm_read_frame(rasm_renderer* renderer, rasm_readback_format format); rasm_bool rasm_is_readback_ready(rasm_renderer* renderer, rasm_readback readback); rasm_result rasm_take_readback(rasm_renderer* renderer, rasm_readback readback, rasm_image* image); rasm_image* rasm_image_create(void); void rasm_image_destroy(rasm_image* image); rasm_image_data rasm_image_get(const rasm_image* image); rasm_result rasm_image_write_png(const rasm_image* image, const char* path); rasm_result rasm_image_read_png(rasm_image* image, const char* path);
readFrame and takeReadback (Headless rendering and readback). The pixels go into a rasm_image you own and can fill again every frame: it keeps its memory, so a frame-by-frame capture allocates nothing after the first. rasm_image_data is {width, height, format, pixels, byte_size}, the rows top to bottom; pixels is NULL for an empty image. rasm_readback_format is RASM_READBACK_FORMAT_RGBA8_SRGB (4 bytes per pixel, what rasm_image_write_png writes) or RASM_READBACK_FORMAT_RGBA32_FLOAT.
rasm_result rasm_window_desc_init(rasm_window_desc* desc, uint32_t size); rasm_window rasm_get_main_window(rasm_renderer* renderer); rasm_window rasm_add_window(rasm_renderer* renderer, const rasm_window_desc* desc); rasm_result rasm_remove_window(rasm_renderer* renderer, rasm_window window); rasm_result rasm_get_window(rasm_renderer* renderer, rasm_window window, rasm_window_info* info); rasm_result rasm_set_window_size(rasm_renderer* renderer, rasm_window window, uint32_t width, uint32_t height, uint32_t pixel_width, uint32_t pixel_height); rasm_result rasm_set_window_content_scale(rasm_renderer* renderer, rasm_window window, float scale); rasm_readback rasm_read_window_frame(rasm_renderer* renderer, rasm_window window, rasm_readback_format format);
1.1. See engine.html. rasm_window_desc is WindowDesc: {size, title, width, height, native, hidden}, a NULL title for the default; what it opens depends on the platform, as in C++: an SDL window, your native window, or an offscreen image headless. rasm_window_info is Window: window, platform_window, native, the sizes in points and pixels, content_scale, resized, minimized. The window 0 is the main one everywhere, as an invalid C++ handle is; rasm_get_window fails for a removed window. rasm_set_window_size and rasm_set_window_content_scale are for your own windows and headless ones: the SDL platform reads its own.
rasm_result rasm_input_event_init(rasm_input_event* event, uint32_t size); void rasm_poll_events(rasm_renderer* renderer); rasm_result rasm_add_input_event(rasm_renderer* renderer, const rasm_input_event* event); uint32_t rasm_get_input_event_count(rasm_renderer* renderer); rasm_result rasm_get_input_event(rasm_renderer* renderer, uint32_t index, rasm_input_event* event); rasm_result rasm_get_camera_input(rasm_renderer* renderer, rasm_camera_input* input); rasm_ui_input_capture rasm_get_ui_input_capture(rasm_renderer* renderer); float rasm_get_delta_time(rasm_renderer* renderer);
1.1. See camera.html and The platform layer. rasm_input_event is InputEvent: type (RASM_INPUT_EVENT_TYPE_KEY, RASM_INPUT_EVENT_TYPE_MOUSE_BUTTON, RASM_INPUT_EVENT_TYPE_MOUSE_MOVE, ...), window (0: the main one), key and physical_key (rasm_key: RASM_KEY_A to RASM_KEY_KEYPAD_EQUAL, RASM_KEY_COUNT of them), down, repeat, modifiers (RASM_KEY_MOD_SHIFT, RASM_KEY_MOD_CTRL, RASM_KEY_MOD_ALT, RASM_KEY_MOD_SUPER), button (rasm_mouse_button), x, y in window points, codepoint. A value past its constants is refused.
The frame's events are read one at a time, rasm_get_input_event(renderer, i, &event) for i below the count, so a binding never steps through an array of a size it does not know. They are valid until the next frame polls. rasm_camera_input is CameraInput, a sized struct: mouse_start, mouse_end (NDC), wheel_delta, delta_time, forward, backward, left, right, and from 1.8 pan_start, pan_end and pointer. rasm_ui_input_capture is {mouse, keyboard, text}.
// A drag that turns the main camera, sent as an application's event loop would.
rasm_input_event event;
rasm_input_event_init(&event, sizeof(event));
event.type = RASM_INPUT_EVENT_TYPE_MOUSE_BUTTON;
event.button = RASM_MOUSE_BUTTON_LEFT;
event.down = RASM_TRUE;
event.x = 640.0f;
event.y = 360.0f;
rasm_add_input_event(renderer, &event);
rasm_result rasm_camera_controller_init(rasm_camera_controller* controller, uint32_t size); rasm_result rasm_camera_input_init(rasm_camera_input* input, uint32_t size); rasm_result rasm_get_camera_controller(rasm_renderer* renderer, rasm_camera camera, rasm_camera_controller* controller); rasm_result rasm_set_camera_controller(rasm_renderer* renderer, rasm_camera camera, const rasm_camera_controller* controller); rasm_result rasm_update_camera(rasm_renderer* renderer, rasm_camera camera, const rasm_camera_input* input); rasm_camera_rig* rasm_camera_rig_create(const rasm_camera_controller* controller, const rasm_transform* transform); void rasm_camera_rig_destroy(rasm_camera_rig* rig); rasm_result rasm_camera_rig_update(rasm_camera_rig* rig, const rasm_camera_input* input); rasm_result rasm_camera_rig_get_transform(const rasm_camera_rig* rig, rasm_transform* transform, rasm_transform* target_transform); rasm_camera_input_state* rasm_camera_input_state_create(void); void rasm_camera_input_state_destroy(rasm_camera_input_state* state); rasm_result rasm_camera_input_state_add_event(rasm_camera_input_state* state, const rasm_input_event* event, const rasm_input_area* area, const rasm_ui_input_capture* capture); rasm_result rasm_camera_input_state_take(rasm_camera_input_state* state, const rasm_ui_input_capture* capture, float delta_time, rasm_camera_input* input); rasm_vec2 rasm_to_input_ndc(float x, float y, const rasm_input_area* area); rasm_input_area rasm_get_input_area(rasm_renderer* renderer, rasm_window window, const rasm_view_rect* rect);
1.1. See camera.html and Camera controllers and easing. rasm_camera_controller is CameraController without its union, flat: type (RASM_CAMERA_CONTROLLER_TYPE_TRACK_BALL, RASM_CAMERA_CONTROLLER_TYPE_FREE_FLY, RASM_CAMERA_CONTROLLER_TYPE_NONE), easing_speed, the track_ball_* fields and the free_fly_* fields; only the type's own fields are read. 1.2 added track_ball_center_d, a rasm_dvec3 added to track_ball_center (the center is their sum, in doubles), and free_fly_up, the axis the free-fly controller yaws around. Its init gives NONE, easing 12, a trackball radius of 5, a free-fly speed of 5 and an up of (0, 1, 0). Setting a controller replaces it whole: a field past your size takes its default.
The helpers an application drives itself, with no renderer: a rasm_camera_rig holds CameraRig (create it from a controller and a pose, update it with a frame's input, read the eased transform and the target_transform, either may be NULL), and a rasm_camera_input_state holds CameraInputState (add a frame's events for one rasm_input_area, then take its rasm_camera_input). Both are made once and reused, so a frame allocates nothing. A NULL capture means the UI took nothing.
rasm_result rasm_view_init(rasm_view* view, uint32_t size); rasm_result rasm_render_views(rasm_renderer* renderer, const rasm_view* views, uint32_t view_count); rasm_view_pixels rasm_get_view_pixels(const rasm_view_rect* rect, uint32_t width, uint32_t height); rasm_result rasm_render_target_desc_init(rasm_render_target_desc* desc, uint32_t size); rasm_render_target rasm_create_render_target(rasm_renderer* renderer, const rasm_render_target_desc* desc); rasm_result rasm_resize_render_target(rasm_renderer* renderer, rasm_render_target target, uint32_t width, uint32_t height); rasm_result rasm_destroy_render_target(rasm_renderer* renderer, rasm_render_target target); rasm_texture rasm_get_render_target_texture(rasm_renderer* renderer, rasm_render_target target);
1.1. render(views, count) and Many views of one scene. rasm_view is View, flat: scene, camera, rect (a rasm_view_rect, fractions from the top-left corner), target (a view texture), window (0: the main one), bloom (RASM_VIEW_TOGGLE_DEFAULT, RASM_VIEW_TOGGLE_OFF, RASM_VIEW_TOGGLE_ON) and anti_aliasing. Its init is the whole main window with the config's settings. Every element of views has the first one's size; there are at most RASM_MAX_VIEWS. The library turns them into C++ views in an array on its stack, so a frame allocates nothing.
1.18 adds shadow_count (0 to RASM_MAX_VIEW_SHADOWS, 4; 0 by default) and shadows, a pointer to that many sized rasm_shadow_descs (each the first one's size), which the call reads and does not keep: View::shadows. Each view draws them fitted to its own camera, before its scene passes; views of different cameras draw one set of maps in turn (Shadows per view). A 1.17 view, shorter, has none. rasm_export_view draws no shadows (D58).
A view texture is a rasm_render_target: rasm_render_target_desc is {size, name, width, height, format, clear_color, readable}, one color and no depth, RASM_FORMAT_R8G8B8A8_SRGB by default (a picture), cleared to opaque black. Its rasm_get_render_target_texture is one texture handle for its whole life, kept across a resize: give it to a material.
rasm_view views[2];
rasm_view_init(&views[0], sizeof(views[0]));
views[0].scene = scene;
views[0].camera = map;
views[0].target = mapTarget;
rasm_view_init(&views[1], sizeof(views[1]));
views[1].scene = scene;
views[1].camera = camera;
rasm_render_views(renderer, views, 2);
rasm_shadow_desc sun;
rasm_shadow_desc_init(&sun, sizeof(sun));
sun.light = sunLight;
views[1].shadows = &sun;
views[1].shadow_count = 1;
rasm_result rasm_animation_play_init(rasm_animation_play* play, uint32_t size); void rasm_set_animation_time(rasm_renderer* renderer, double seconds); rasm_result rasm_play_animation(rasm_renderer* renderer, rasm_entity entity, const rasm_animation_play* play); rasm_result rasm_stop_animation(rasm_renderer* renderer, rasm_entity entity); uint32_t rasm_get_animation_count(rasm_renderer* renderer, rasm_mesh mesh); uint32_t rasm_get_animation_name(rasm_renderer* renderer, rasm_mesh mesh, uint32_t index, char* buffer, uint32_t capacity); float rasm_get_animation_duration(rasm_renderer* renderer, rasm_mesh mesh, uint32_t index); int32_t rasm_find_animation(rasm_renderer* renderer, rasm_mesh mesh, const char* name); rasm_result rasm_set_morph_weights(rasm_renderer* renderer, rasm_entity entity, const float* weights, uint32_t count); rasm_result rasm_clear_morph_weights(rasm_renderer* renderer, rasm_entity entity); uint32_t rasm_get_morph_target_count(rasm_renderer* renderer, rasm_mesh mesh); uint32_t rasm_get_morph_target_name(rasm_renderer* renderer, rasm_mesh mesh, uint32_t index, char* buffer, uint32_t capacity);
1.1. See scene.html. rasm_animation_play is AnimationPlay: {size, clip, start_time, clip_time, speed, loop}, with clip an index or RASM_ALL_ANIMATION_CLIPS. getAnimations is a count, a name and a duration by index; rasm_find_animation gives -1 for an unknown name.
rasm_result rasm_get_frame_stats(rasm_renderer* renderer, rasm_frame_stats* stats); rasm_result rasm_get_pool_stats(rasm_renderer* renderer, rasm_pool_stats* stats); rasm_result rasm_get_load_stats(rasm_renderer* renderer, rasm_load_stats* stats); rasm_result rasm_asset_loader_get_load_stats(rasm_asset_loader* loader, rasm_load_stats* stats);
1.1. See engine.html. Sized structs you fill with size set: rasm_frame_stats is FrameStats without its GPU timers and memory (cpu_frame_ms, gpu_frame_ms, upload_gpu_ms, the draw, triangle, LOD (draws_per_lod[RASM_MAX_MESH_LODS]), meshlet and light counts); rasm_pool_stats is PoolStats and rasm_load_stats is LoadStats. As in C++, the first rasm_get_frame_stats turns measuring on, and the numbers fill in a few frames later.
typedef struct rasm_dvec3 { double x, y, z; } rasm_dvec3;
typedef struct rasm_transform_d { rasm_dvec3 position; rasm_quat rotation; rasm_vec3 scale; } rasm_transform_d;
rasm_result rasm_get_transform_d(rasm_renderer* renderer, rasm_entity entity, rasm_transform_d* transform);
rasm_result rasm_update_transform_d(rasm_renderer* renderer, rasm_entity entity, const rasm_transform_d* transform);
rasm_result rasm_get_camera_transform_d(rasm_renderer* renderer, rasm_camera camera, rasm_transform_d* transform);
rasm_result rasm_set_camera_transform_d(rasm_renderer* renderer, rasm_camera camera, const rasm_transform_d* transform);
rasm_result rasm_get_light_position_d(rasm_renderer* renderer, rasm_light light, rasm_dvec3* position);
rasm_result rasm_set_light_position_d(rasm_renderer* renderer, rasm_light light, const rasm_dvec3* position);
rasm_camera_rig* rasm_camera_rig_create_d(const rasm_camera_controller* controller, const rasm_transform_d* transform);
rasm_result rasm_camera_rig_get_transform_d(const rasm_camera_rig* rig, rasm_transform_d* transform, rasm_transform_d* target_transform);
rasm_result rasm_camera_rig_set_free_fly_up(rasm_camera_rig* rig, rasm_vec3 up);
rasm_vec3 rasm_to_render_position(rasm_dvec3 world_position, rasm_dvec3 origin);
rasm_dvec3 rasm_to_world_position(rasm_vec3 render_position, rasm_dvec3 origin);
1.2. Positions in doubles, as the engine keeps them (Large worlds): an entity, a camera, a light or a rig millions of metres from the origin, in Earth-centred coordinates for example, goes in and comes out bit for bit. The 1.0 calls with a rasm_transform keep working and round the position to floats. rasm_camera_rig_set_free_fly_up gives a free-fly rig a new up, a globe's normal under the camera as it flies. A position that is not finite is refused. rasm_to_render_position and rasm_to_world_position are toRenderPosition and toWorldPosition: a view's origin is its camera's position in the frame it drew.
const rasm_dvec3 paris = {4197000.25, 168000.5, 4786000.75};
const rasm_transform_d at = {paris, {0.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 1.0f}};
rasm_update_transform_d(renderer, entity, &at);
rasm_result rasm_tile_streamer_config_init(rasm_tile_streamer_config* config, uint32_t size); rasm_result rasm_tile_desc_init(rasm_tile_desc* desc, uint32_t size); rasm_result rasm_tile_content_init(rasm_tile_content* content, uint32_t size); rasm_result rasm_tile_streamer_create(rasm_renderer* renderer, rasm_scene scene, const rasm_tile_streamer_config* config, rasm_tile_streamer** streamer); void rasm_tile_streamer_destroy(rasm_tile_streamer* streamer); rasm_tile rasm_tile_streamer_create_tile(rasm_tile_streamer* streamer, const rasm_tile_desc* desc); rasm_result rasm_tile_streamer_destroy_tile(rasm_tile_streamer* streamer, rasm_tile tile); rasm_result rasm_tile_streamer_set_views(rasm_tile_streamer* streamer, const rasm_view* views, uint32_t view_count); double rasm_tile_streamer_get_screen_error(rasm_tile_streamer* streamer, rasm_dvec3 center, double radius, double geometric_error); double rasm_tile_streamer_get_tile_screen_error(rasm_tile_streamer* streamer, rasm_tile tile); rasm_result rasm_tile_streamer_update(rasm_tile_streamer* streamer, const rasm_tile* wanted, uint32_t wanted_count); const rasm_tile* rasm_tile_streamer_get_tiles_to_load(rasm_tile_streamer* streamer, uint32_t* count); rasm_result rasm_tile_streamer_set_tile_content(rasm_tile_streamer* streamer, rasm_tile tile, const rasm_tile_content* content); rasm_tile_state rasm_tile_streamer_get_tile_state(rasm_tile_streamer* streamer, rasm_tile tile); rasm_bool rasm_tile_streamer_is_tile_drawn(rasm_tile_streamer* streamer, rasm_tile tile); rasm_result rasm_tile_streamer_get_stats(rasm_tile_streamer* streamer, rasm_tile_streamer_stats* stats);
1.3. TileStreamer and Tile streaming under a memory budget, in both libraries. rasm_tile is a handle; rasm_tile_streamer_config, rasm_tile_desc (parent, center a rasm_dvec3, radius, geometric_error, refine: RASM_TILE_REFINE_REPLACE or RASM_TILE_REFINE_ADD, estimated_bytes), rasm_tile_content (an array and a count of entities, meshes, materials and textures) and rasm_tile_streamer_stats are the C++ structs, flat and sized. A NULL config takes the defaults. The tiles to load stay valid until the next update. rasm_tile_streamer_set_tile_content returns RASM_ERROR_FAILED where C++ returns false, and the content is the streamer's either way; an argument error (a NULL streamer, a size too small, a NULL array with a count) returns RASM_ERROR_INVALID_ARGUMENT and takes nothing. rasm_tile_state is RASM_TILE_STATE_EMPTY, RASM_TILE_STATE_REQUESTED, RASM_TILE_STATE_LOADING, RASM_TILE_STATE_READY or RASM_TILE_STATE_FAILED. Destroy the streamer before its renderer. examples/22_c_api streams its ground as a root tile and its four quarters.
rasm_tile_streamer *tiles = NULL;
rasm_tile_streamer_create(renderer, scene, NULL, &tiles);
// each frame, before rasm_render_views:
rasm_tile_streamer_set_views(tiles, views, 3);
rasm_tile_streamer_update(tiles, wanted, wantedCount);
uint32_t count = 0;
const rasm_tile *toLoad = rasm_tile_streamer_get_tiles_to_load(tiles, &count);
rasm_result rasm_terrain_tile_desc_init(rasm_terrain_tile_desc* desc, uint32_t size); rasm_mesh rasm_get_terrain_mesh(rasm_renderer* renderer, uint32_t cells); rasm_result rasm_create_terrain_tile(rasm_renderer* renderer, const rasm_terrain_tile_desc* desc, rasm_entity* entity, rasm_material* material); rasm_result rasm_get_terrain_transform(const rasm_terrain_tile_desc* desc, rasm_transform_d* transform); double rasm_sample_terrain_height(const rasm_terrain_heights* heights, const rasm_terrain_material* terrain, double u, double v); rasm_result rasm_get_terrain_position(const rasm_terrain_tile_desc* desc, const rasm_terrain_heights* heights, double u, double v, rasm_dvec3* position);
1.4. createTerrainTile, getTerrainMesh and the CPU helpers of Terrain from height maps, in both libraries. rasm_terrain_material is TerrainMaterial (heights, height_scale, height_offset, min_height, max_height, skirt, sphere_radius), also the last field of rasm_material_desc, so an older caller's update keeps it. rasm_terrain_tile_desc is sized: center a rasm_dvec3, orientation, tile_size (C++ size), terrain, imagery, imagery_rect, roughness. rasm_terrain_heights points at one of unorm16 and floats, with a width of 4 to RASM_MAX_TERRAIN_CELLS + 3. rasm_create_terrain_tile returns RASM_ERROR_FAILED where C++ returns invalid handles. rasm_create_texture takes the two height formats, one level.
rasm_terrain_tile_desc tile;
rasm_terrain_tile_desc_init(&tile, sizeof(tile));
tile.tile_size = 256.0;
tile.terrain.heights = heights; // a 35 x 35 RASM_FORMAT_R16_UNORM texture
tile.terrain.height_scale = 1.0f / 16.0f;
tile.terrain.min_height = 120.0f;
tile.terrain.max_height = 380.0f;
rasm_entity entity;
rasm_material material;
rasm_create_terrain_tile(renderer, &tile, &entity, &material);
rasm_result rasm_mesh_build_options_init(rasm_mesh_build_options* options, uint32_t size); rasm_result rasm_build_mesh(const rasm_vertex* vertices, uint32_t vertex_count, const uint32_t* indices, uint32_t index_count, const uint32_t* colors, const rasm_mesh_build_options* options, rasm_mesh_build** build); void rasm_mesh_build_destroy(rasm_mesh_build* build); rasm_mesh rasm_create_mesh_from_build(rasm_renderer* renderer, rasm_mesh_build* build); rasm_result rasm_line_shape_init(rasm_line_shape* shape, uint32_t size); rasm_result rasm_vector_placement_init(rasm_vector_placement* placement, uint32_t size); rasm_result rasm_vector_geometry_create(rasm_vector_geometry** geometry); void rasm_vector_geometry_destroy(rasm_vector_geometry* geometry); rasm_result rasm_vector_geometry_get_size(const rasm_vector_geometry* geometry, uint32_t* vertex_count, uint32_t* index_count); rasm_result rasm_vector_add_lines(rasm_vector_geometry* geometry, rasm_dvec3 origin, const rasm_dvec3* points, const uint32_t* line_sizes, uint32_t line_count, const rasm_line_shape* shape, const rasm_vector_placement* placement, const uint32_t* feature_ids); rasm_result rasm_vector_add_polygons(rasm_vector_geometry* geometry, rasm_dvec3 origin, const rasm_dvec3* points, const uint32_t* ring_sizes, const uint32_t* ring_counts, uint32_t polygon_count, const rasm_vector_placement* placement, const uint32_t* feature_ids); rasm_result rasm_vector_add_points(rasm_vector_geometry* geometry, rasm_dvec3 origin, const rasm_dvec3* points, uint32_t point_count, const rasm_vector_placement* placement, const uint32_t* feature_ids, const rasm_vec4* icon_rects); rasm_result rasm_build_vector_mesh(rasm_vector_geometry* geometry, rasm_mesh_build** build);
1.5. buildMesh and the vector features, in both libraries. rasm_mesh_build and rasm_vector_geometry are opaque. rasm_build_mesh and the rasm_vector_* functions touch no renderer, so any thread may call them, one thread per geometry; rasm_build_mesh returns RASM_ERROR_FAILED for data buildMesh refuses. rasm_create_mesh_from_build runs on the renderer's thread and destroys the build whatever it returns. rasm_build_vector_mesh empties the geometry. rasm_mesh_build_options (lods, meshlets), rasm_line_shape (join: RASM_LINE_JOIN_MITER, RASM_LINE_JOIN_BEVEL or RASM_LINE_JOIN_ROUND; cap: RASM_LINE_CAP_BUTT, RASM_LINE_CAP_SQUARE or RASM_LINE_CAP_ROUND; miter_limit; 1.9: drape_width, LineShape::drapeWidth) and rasm_vector_placement (up, drape_tile a rasm_terrain_tile_desc or NULL, drape_heights) are sized; NULL takes the defaults. rasm_vector_material is VectorMaterial, the last field of rasm_material_desc: width_unit RASM_VECTOR_UNIT_PIXELS or RASM_VECTOR_UNIT_METRES, facing RASM_VECTOR_FACING_SCREEN or RASM_VECTOR_FACING_GROUND, depth RASM_VECTOR_DEPTH_TESTED or RASM_VECTOR_DEPTH_OVERLAY.
rasm_vector_geometry *geometry = NULL;
rasm_vector_geometry_create(&geometry);
rasm_vector_add_lines(geometry, origin, points, sizes, lineCount, NULL, NULL, NULL); // on a worker thread
rasm_mesh_build *build = NULL;
rasm_build_vector_mesh(geometry, &build);
rasm_mesh roads = rasm_create_mesh_from_build(renderer, build); // on the renderer's thread
rasm_result rasm_font_load_options_init(rasm_font_load_options* options, uint32_t size); rasm_result rasm_label_desc_init(rasm_label_desc* desc, uint32_t size); rasm_result rasm_build_font_atlas(const void* data, uint64_t data_size, const rasm_font_load_options* options, rasm_font_atlas** atlas); rasm_result rasm_asset_loader_load_font(rasm_asset_loader* loader, const char* path, const rasm_font_load_options* options, rasm_font_atlas** atlas); void rasm_font_atlas_destroy(rasm_font_atlas* atlas); rasm_font rasm_create_font(rasm_renderer* renderer, const rasm_font_atlas* atlas); rasm_result rasm_destroy_font(rasm_renderer* renderer, rasm_font font); rasm_result rasm_vector_add_labels(rasm_vector_geometry* geometry, rasm_dvec3 origin, const rasm_font_atlas* atlas, const rasm_label_desc* labels, uint32_t label_count, const rasm_vector_placement* placement);
1.6. Labels and their fonts. rasm_font_atlas is opaque (FontAtlas); rasm_font a handle (FontHandle). rasm_build_font_atlas (buildFontAtlas, any thread) and rasm_asset_loader_load_font (loadFont) are in rasm_c only and return RASM_ERROR_FAILED for data that is no font; the others are in both libraries. rasm_vector_add_labels lays the labels out on any thread, one thread per geometry; labels is an array of sized structs, each the size of the first. rasm_font_load_options (em_size, distance_range, codepoints, codepoint_count) and rasm_label_desc (position a rasm_dvec3, text UTF-8, priority, anchor one of RASM_LABEL_ANCHOR_CENTER, RASM_LABEL_ANCHOR_BOTTOM, RASM_LABEL_ANCHOR_TOP, RASM_LABEL_ANCHOR_LEFT and RASM_LABEL_ANCHOR_RIGHT, offset, feature_id) are sized. The material desc's last field, font, names a VECTOR material's font. RASM_MAX_FONTS, RASM_MAX_LABELS and RASM_MAX_LABEL_REACH mirror the C++ constants; RASM_FORMAT_R8_UNORM is the atlas's format.
rasm_font_atlas *atlas = NULL;
rasm_asset_loader_load_font(loader, "fonts/Roboto-Medium.ttf", NULL, &atlas);
rasm_font font = rasm_create_font(renderer, atlas);
rasm_label_desc label;
rasm_label_desc_init(&label, sizeof(label));
label.position = place;
label.text = "Harbour";
rasm_vector_add_labels(geometry, origin, atlas, &label, 1, NULL); // on a worker thread
rasm_result rasm_pick_desc_init(rasm_pick_desc* desc, uint32_t size); rasm_result rasm_pick_hit_init(rasm_pick_hit* hit, uint32_t size); rasm_pick rasm_pick_view(rasm_renderer* renderer, const rasm_view* view, const rasm_pick_desc* desc); rasm_pick rasm_pick_target(rasm_renderer* renderer, rasm_scene scene, rasm_camera camera, rasm_render_target target, const rasm_pick_desc* desc); rasm_bool rasm_is_pick_ready(rasm_renderer* renderer, rasm_pick pick); rasm_result rasm_take_pick(rasm_renderer* renderer, rasm_pick pick, rasm_pick_hit* hits, uint32_t capacity, uint32_t* hit_count); rasm_bool rasm_is_entity_alive(rasm_renderer* renderer, rasm_entity entity); rasm_bool rasm_get_view_pixel(rasm_renderer* renderer, rasm_window window, const rasm_view_rect* rect, float x, float y, uint32_t* pixel_x, uint32_t* pixel_y);
1.7. Picking: rasm_pick is a handle (PickHandle). rasm_pick_view is pick of a view of rasm_render_views, rasm_pick_target the one of your own graph's scene target; a NULL desc is the defaults. rasm_pick_desc (rect a rasm_view_pixels, min_alpha, skip of RASM_PICK_SKIP_MESHES, RASM_PICK_SKIP_BLEND, RASM_PICK_SKIP_TERRAIN, RASM_PICK_SKIP_VECTORS, RASM_PICK_SKIP_LABELS, RASM_PICK_SKIP_OVERLAYS, RASM_PICK_SKIP_ALL) and rasm_pick_hit (entity, sub_mesh, feature, flags of RASM_PICK_HIT_FEATURE, RASM_PICK_HIT_LABEL, RASM_PICK_HIT_OVERLAY, RASM_PICK_HIT_TERRAIN, RASM_PICK_HIT_BACK_FACE, pixels, x, y, position a rasm_dvec3, normal, distance) are sized. rasm_take_pick writes into an array whose elements have the size of the first: set hits[0].size (rasm_pick_hit_init); every element gets the fields that size reaches, and its size set to it. It returns RASM_ERROR_FAILED for a pick that failed or that no frame has drawn yet, and allocates nothing for up to 64 hits. rasm_is_entity_alive is isAlive; rasm_get_view_pixel is getViewPixel for a window (0: the main one). RASM_MAX_PICK_SIZE mirrors MAX_PICK_SIZE.
rasm_pick_desc desc;
rasm_pick_desc_init(&desc, sizeof(desc));
if (rasm_get_view_pixel(renderer, window, &views[1].rect, mouse_x, mouse_y, &desc.rect.x, &desc.rect.y))
pending = rasm_pick_view(renderer, &views[1], &desc);
/* a couple of frames later */
if (pending.id != 0 && rasm_is_pick_ready(renderer, pending))
{
rasm_pick_hit hit;
uint32_t count = 0;
rasm_pick_hit_init(&hit, sizeof(hit));
if (rasm_take_pick(renderer, pending, &hit, 1, &count) == RASM_OK && count > 0)
select(hit.entity, hit.position);
pending.id = 0;
}
rasm_result rasm_camera_buttons_init(rasm_camera_buttons* buttons, uint32_t size); rasm_result rasm_set_camera_buttons(rasm_renderer* renderer, const rasm_camera_buttons* buttons); rasm_result rasm_camera_input_state_set_buttons(rasm_camera_input_state* state, const rasm_camera_buttons* buttons); rasm_result rasm_set_mouse_grab(rasm_renderer* renderer, rasm_window window, rasm_bool on); rasm_result rasm_camera_rig_update_projection(rasm_camera_rig* rig, rasm_camera_projection* projection, const rasm_camera_input* input); rasm_result rasm_grid_init(rasm_grid* grid, uint32_t size); rasm_result rasm_set_camera_grid(rasm_renderer* renderer, rasm_camera camera, const rasm_grid* grid); rasm_result rasm_get_camera_grid(rasm_renderer* renderer, rasm_camera camera, rasm_grid* grid);
1.8. Orthographic controls and reference grids. rasm_camera_buttons is CameraButtons, a sized struct of rasm_camera_drag values (RASM_CAMERA_DRAG_NONE, RASM_CAMERA_DRAG_ORBIT, RASM_CAMERA_DRAG_PAN) for left, right, middle, back, forward and shift_left: rasm_set_camera_buttons sets the renderer's own (setCameraButtons), rasm_camera_input_state_set_buttons a state's. rasm_update_camera passes the camera's projection, so it pans by it and zooms an orthographic box at the pointer; rasm_camera_rig_update_projection is updateCameraRig with a projection it reads and writes back. rasm_camera_controller gains track_ball_style (RASM_ORBIT_STYLE_TURNTABLE, the default, or RASM_ORBIT_STYLE_ARCBALL) and track_ball_up; rasm_input_event gains dx and dy, a move's motion; rasm_set_mouse_grab is setMouseGrab. RASM_CAMERA_WHEEL_ZOOM and RASM_MIN_TRACK_BALL_RADIUS mirror CAMERA_WHEEL_ZOOM and MIN_TRACK_BALL_RADIUS. rasm_grid is Grid (enabled, origin a rasm_dvec3, orientation, cell_size a double, subdivisions, extent, minor_color, major_color, line_width, major_line_width, axes, x_axis_color, z_axis_color, fade_distance); rasm_set_camera_grid returns RASM_ERROR_INVALID_ARGUMENT for a grid setCameraGrid refuses. A 1.7 program sees three changes: a trackball orbits as a turntable (set track_ball_style to RASM_ORBIT_STYLE_ARCBALL for a free rotation like before, now smooth past the rim), its wheel scales the radius instead of subtracting from it, and the right and middle buttons and Shift + left pan; every button set to RASM_CAMERA_DRAG_ORBIT orbits as before.
rasm_grid grid;
rasm_grid_init(&grid, sizeof(grid));
grid.enabled = RASM_TRUE;
grid.cell_size = 0.5;
grid.subdivisions = 2;
rasm_set_camera_grid(renderer, map, &grid);
rasm_texture rasm_create_colormap(rasm_renderer* renderer, const rasm_vec4* colors, uint32_t count); rasm_texture rasm_create_colormap_preset(rasm_renderer* renderer, rasm_colormap_preset preset); rasm_result rasm_point_cloud_chunk_desc_init(rasm_point_cloud_chunk_desc* desc, uint32_t size); rasm_result rasm_build_point_cloud_chunk(const rasm_point_cloud_chunk_desc* desc, rasm_mesh_build** build);
1.10. Point clouds and colormaps. rasm_create_colormap and rasm_create_colormap_preset are createColormap (RASM_COLORMAP_VIRIDIS, RASM_COLORMAP_TURBO, RASM_COLORMAP_MAGMA, RASM_COLORMAP_INFERNO, RASM_COLORMAP_PLASMA, RASM_COLORMAP_CIVIDIS, RASM_COLORMAP_GRAY; RASM_COLORMAP_SIZE); destroy the texture with rasm_destroy_texture. rasm_point_cloud_chunk_desc (positions a rasm_vec3 array, colors, scalars, count up to RASM_MAX_POINT_CHUNK_POINTS) is sized; rasm_build_point_cloud_chunk is buildPointCloudChunk, on any thread, and returns RASM_ERROR_INVALID_ARGUMENT for points it refuses; upload the build with rasm_create_mesh_from_build. rasm_point_material is PointMaterial, the last field of rasm_material_desc: size_unit a rasm_vector_unit, shape RASM_POINT_SHAPE_SQUARE, RASM_POINT_SHAPE_ROUND or RASM_POINT_SHAPE_SPHERE, color_mode RASM_POINT_COLOR_MODE_COLOR or RASM_POINT_COLOR_MODE_SCALAR, colormap, range a rasm_scalar_range (min, max, log, clamp), density.
rasm_point_cloud_chunk_desc desc;
rasm_point_cloud_chunk_desc_init(&desc, sizeof(desc));
desc.positions = points;
desc.scalars = heights;
desc.count = count;
rasm_mesh_build *build = NULL;
if (rasm_build_point_cloud_chunk(&desc, &build) == RASM_OK)
mesh = rasm_create_mesh_from_build(renderer, build);
rasm_result rasm_set_compute_points(rasm_renderer* renderer, rasm_bool on); rasm_bool rasm_get_compute_points(rasm_renderer* renderer);
1.11. setComputePoints and getComputePoints: small points (up to 6 pixels at a chunk's centre and 8 at its nearest point; 4 in an orthographic view, 2 under MSAA) by the compute path (point clouds) where the GPU has 64-bit buffer atomics, or every point by triangles. rasm_renderer_config::compute_points (RASM_TRUE by default) is the start value. Both return RASM_ERROR_INVALID_ARGUMENT or RASM_FALSE for a NULL renderer.
rasm_result rasm_point_chunk_lod_init(rasm_point_chunk_lod* lod, uint32_t size); rasm_result rasm_set_point_chunk_lod(rasm_renderer* renderer, rasm_entity entity, const rasm_point_chunk_lod* lod); rasm_result rasm_point_cloud_octree_desc_init(rasm_point_cloud_octree_desc* desc, uint32_t size); rasm_result rasm_build_point_cloud_octree(const rasm_point_cloud_octree_desc* desc, rasm_point_cloud_octree** octree); void rasm_point_cloud_octree_destroy(rasm_point_cloud_octree* octree); uint32_t rasm_get_point_cloud_node_count(const rasm_point_cloud_octree* octree); rasm_result rasm_get_point_cloud_node(const rasm_point_cloud_octree* octree, uint32_t node, rasm_point_cloud_node* record); rasm_result rasm_get_point_cloud_node_chunk(const rasm_point_cloud_octree* octree, uint32_t node, rasm_point_cloud_chunk_desc* desc); const uint32_t* rasm_get_point_cloud_octree_indices(const rasm_point_cloud_octree* octree, uint32_t* count); rasm_result rasm_point_cloud_load_options_init(rasm_point_cloud_load_options* options, uint32_t size); rasm_result rasm_asset_loader_load_point_cloud(rasm_asset_loader* loader, const char* path, const rasm_point_cloud_load_options* options, rasm_point_cloud** cloud); rasm_result rasm_get_point_cloud_info(const rasm_point_cloud* cloud, rasm_point_cloud_info* info); void rasm_point_cloud_destroy(rasm_point_cloud* cloud);
1.12. Octrees of points and LAS and LAZ files (Streaming point clouds). rasm_point_chunk_lod (drawn, finer[8]) is PointChunkLod, rasm_set_point_chunk_lod setPointChunkLod. rasm_build_point_cloud_octree is buildPointCloudOctree on any thread, from a sized rasm_point_cloud_octree_desc (positions a rasm_dvec3 array, colors, scalars, count, cells, max_node_points); the octree is opaque: read its nodes with rasm_get_point_cloud_node (a sized rasm_point_cloud_node, RASM_POINT_NODE_NONE for no parent or child), a node's chunk desc with rasm_get_point_cloud_node_chunk (its arrays the octree's, for rasm_build_point_cloud_chunk), and its points' indices in the desc with rasm_get_point_cloud_octree_indices, all valid until rasm_point_cloud_octree_destroy. With rasm_c only, rasm_asset_loader_load_point_cloud is loadPointCloud (NULL options: the defaults; scalar a rasm_point_cloud_scalar, RASM_POINT_CLOUD_SCALAR_NONE to RASM_POINT_CLOUD_SCALAR_RETURN_NUMBER, and z_up_to_y_up), and rasm_get_point_cloud_info fills a sized rasm_point_cloud_info whose arrays and coordinate_system stay valid until rasm_point_cloud_destroy. rasm_point_material's size_mode is RASM_POINT_SIZE_MODE_FIXED or RASM_POINT_SIZE_MODE_ADAPTIVE.
rasm_point_cloud *cloud = NULL;
rasm_point_cloud_info info;
info.size = sizeof(info);
if (rasm_asset_loader_load_point_cloud(loader, "scans/tile.laz", NULL, &cloud) != RASM_OK || rasm_get_point_cloud_info(cloud, &info) != RASM_OK)
return 1;
rasm_point_cloud_octree_desc desc;
rasm_point_cloud_octree_desc_init(&desc, sizeof(desc));
desc.positions = info.positions;
desc.colors = info.colors;
desc.count = info.count;
rasm_point_cloud_octree *octree = NULL;
rasm_build_point_cloud_octree(&desc, &octree);
rasm_result rasm_glyph_chunk_desc_init(rasm_glyph_chunk_desc* desc, uint32_t size); rasm_result rasm_build_glyph_chunk(const rasm_glyph_chunk_desc* desc, rasm_mesh_build** build); rasm_result rasm_build_glyph_shape(rasm_glyph_shape shape, uint32_t segments, rasm_mesh_build** build); rasm_quat rasm_get_glyph_orientation(rasm_vec3 direction); rasm_result rasm_vector_add_data_lines(rasm_vector_geometry* geometry, rasm_dvec3 origin, const rasm_dvec3* points, const uint32_t* line_sizes, uint32_t line_count, const rasm_line_shape* shape, const rasm_vector_placement* placement, const uint32_t* feature_ids, const uint32_t* colors, const float* scalars);
1.14. Glyphs and data lines (Instanced glyphs). rasm_glyph_chunk_desc is sized: shape a rasm_mesh, positions and scales rasm_vec3 arrays, orientations a rasm_quat array, colors or scalars, count up to RASM_MAX_GLYPH_CHUNK_GLYPHS. rasm_build_glyph_chunk is buildGlyphChunk on any thread and returns RASM_ERROR_INVALID_ARGUMENT for glyphs it refuses (no shape, colors and scalars both, ...); upload the build with rasm_create_mesh_from_build. rasm_build_glyph_shape is buildGlyphShape (RASM_GLYPH_SHAPE_ARROW, RASM_GLYPH_SHAPE_SPHERE, RASM_GLYPH_SHAPE_CUBE), rasm_get_glyph_orientation getGlyphOrientation. Draw a chunk with a RASM_MATERIAL_TYPE_GLYPHS material; rasm_material_desc::glyphs, a rasm_scalar_colors (color_mode, colormap, range), is GlyphMaterial. rasm_vector_add_data_lines is rasm_vector_add_lines with a color or a scalar per point (addVectorLines; both: RASM_ERROR_INVALID_ARGUMENT), and rasm_material_desc::vector_colors is the VECTOR material's colorMode, colormap and range. A pick's feature on a chunk is the glyph's index, with RASM_PICK_HIT_GLYPH; RASM_PICK_SKIP_GLYPHS looks through them. rasm_frame_stats ends with glyphs and glyphs_visible.
rasm_mesh_build *shape = NULL;
rasm_build_glyph_shape(RASM_GLYPH_SHAPE_ARROW, 16, &shape);
rasm_mesh arrow = rasm_create_mesh_from_build(renderer, shape);
rasm_glyph_chunk_desc desc;
rasm_glyph_chunk_desc_init(&desc, sizeof(desc));
desc.shape = arrow;
desc.positions = positions;
desc.orientations = orientations;
desc.scalars = speeds;
desc.count = count;
rasm_mesh_build *build = NULL;
if (rasm_build_glyph_chunk(&desc, &build) == RASM_OK)
chunk = rasm_create_mesh_from_build(renderer, build);
rasm_result rasm_export_desc_init(rasm_export_desc* desc, uint32_t size); rasm_result rasm_export_progress_init(rasm_export_progress* progress, uint32_t size); rasm_export rasm_export_view(rasm_renderer* renderer, const rasm_view* view, const rasm_export_desc* desc); rasm_result rasm_get_export_progress(rasm_renderer* renderer, rasm_export export_handle, rasm_export_progress* progress); rasm_result rasm_cancel_export(rasm_renderer* renderer, rasm_export export_handle); rasm_result rasm_take_export(rasm_renderer* renderer, rasm_export export_handle, rasm_image* image);
1.16. Exporting a still at any size: rasm_export is a handle (ExportHandle). rasm_export_view is exportView; it runs in the frames of rasm_render_views, one sample a frame. rasm_export_desc is sized: width, height, path (UTF-8, copied; NULL or "" keeps the image in memory), format (RASM_EXPORT_FORMAT_PNG8, RASM_EXPORT_FORMAT_PNG16, RASM_EXPORT_FORMAT_EXR_HALF, RASM_EXPORT_FORMAT_EXR_FLOAT), samples (16, up to RASM_MAX_EXPORT_SAMPLES), pixel_scale (1), tone_map (true), transparent, msaa, tile_size (0: RASM_DEFAULT_EXPORT_TILE_SIZE). rasm_get_export_progress fills a sized rasm_export_progress (state of RASM_EXPORT_STATE_RUNNING, RASM_EXPORT_STATE_DONE, RASM_EXPORT_STATE_FAILED; tiles_done, tile_count, fraction) and never waits. rasm_take_export moves a DONE export's image into image (NULL for a file export) and forgets it; rasm_cancel_export stops one or forgets a finished one.
rasm_export_desc desc;
rasm_export_desc_init(&desc, sizeof(desc));
desc.width = 15360;
desc.height = 8640;
desc.path = "poster.exr";
desc.format = RASM_EXPORT_FORMAT_EXR_HALF;
rasm_export poster = rasm_export_view(renderer, &views[0], &desc);
rasm_export_progress progress;
rasm_export_progress_init(&progress, sizeof(progress));
while (rasm_get_export_progress(renderer, poster, &progress) == RASM_OK && progress.state == RASM_EXPORT_STATE_RUNNING)
rasm_render_views(renderer, views, 1);
rasm_take_export(renderer, poster, NULL);
rasm_result rasm_render_graph_create(rasm_renderer* renderer, rasm_render_graph** graph); void rasm_render_graph_destroy(rasm_render_graph* graph); rasm_render_target rasm_render_graph_create_render_target(rasm_render_graph* graph, const rasm_render_target_desc* desc); rasm_result rasm_render_graph_compile(rasm_render_graph* graph); rasm_result rasm_render_graph_execute(rasm_render_graph* graph, rasm_camera camera); uint32_t rasm_render_graph_dump(rasm_render_graph* graph, char* buffer, uint32_t capacity);
1.17. A RenderGraph as an opaque object (your own frame). rasm_render_graph_execute is execute: a whole frame (input, the passes in their order, submit, present), in place of rasm_render; it returns RASM_ERROR_FAILED when an error was logged during the frame, a pass callback's refused calls included. rasm_render_graph_create_render_target is the graph's createRenderTarget: the target belongs to the graph, and one without history or readable is transient. rasm_render_graph_dump gives dump by the snprintf rule. A target's colors must be formats it can draw into (8-bit RGBA or BGRA, RASM_FORMAT_R8_UNORM, RASM_FORMAT_R16_UNORM, RASM_FORMAT_R16G16_SFLOAT, RASM_FORMAT_R16G16B16A16_SFLOAT, RASM_FORMAT_R32_SFLOAT, RASM_FORMAT_R32G32_SFLOAT, RASM_FORMAT_R32G32B32A32_SFLOAT, RASM_FORMAT_R32G32B32A32_UINT) and its depth RASM_FORMAT_D24_UNORM_S8_UINT, RASM_FORMAT_D32_SFLOAT or RASM_FORMAT_D32_SFLOAT_S8_UINT. Destroy a graph before its renderer; a renderer (or engine) destroyed first detaches its graphs, whose calls then fail, and rasm_render_graph_destroy still frees them. The 1.17 fields of rasm_render_target_desc are swapchain_scale, depth_format, more_color_formats (colors 1 to 3), samples, history, storage and cube, as in RenderTargetDesc.
typedef void (RASM_CALL* rasm_pass_callback)(void* user_data, rasm_commands* commands); rasm_result rasm_pass_desc_init(rasm_pass_desc* desc, uint32_t size); rasm_result rasm_render_graph_add_pass(rasm_render_graph* graph, const rasm_pass_desc* desc);
1.17. addPass, addComputePass and addAsyncComputePass by rasm_pass_desc::type (RASM_PASS_TYPE_GRAPHICS, RASM_PASS_TYPE_COMPUTE, RASM_PASS_TYPE_ASYNC_COMPUTE). In place of a setup function, resources lists what the pass uses, each a rasm_pass_resource of an access, a face and a handle's id, which the call gives to PassBuilder: RASM_PASS_ACCESS_READ_TEXTURE, RASM_PASS_ACCESS_READ_BUFFER, RASM_PASS_ACCESS_READ_RENDER_TARGET, RASM_PASS_ACCESS_READ_PREVIOUS_RENDER_TARGET, RASM_PASS_ACCESS_READ_PREVIOUS_BUFFER, RASM_PASS_ACCESS_READ_DEPTH, RASM_PASS_ACCESS_WRITE_TEXTURE, RASM_PASS_ACCESS_WRITE_BUFFER, RASM_PASS_ACCESS_WRITE_RENDER_TARGET and RASM_PASS_ACCESS_WRITE_SWAPCHAIN (id 0: the main window). execute and user_data are the callback; the graph keeps both, so they must live as long as it. A NULL execute records nothing (a graphics pass still clears what it writes).
rasm_result rasm_shadow_desc_init(rasm_shadow_desc* desc, uint32_t size); rasm_result rasm_view_output_init(rasm_view_output* output, uint32_t size); rasm_shadow rasm_render_graph_add_shadow_passes(rasm_render_graph* graph, rasm_scene scene, rasm_camera camera, const rasm_shadow_desc* desc); rasm_result rasm_render_graph_add_scene_passes(rasm_render_graph* graph, rasm_scene scene, rasm_camera camera, rasm_render_target target, const rasm_shadow* shadows, uint32_t shadow_count, const rasm_render_target* sampled, uint32_t sampled_count); rasm_render_target rasm_render_graph_add_msaa_resolve_pass(rasm_render_graph* graph, rasm_render_target source, rasm_camera camera); rasm_render_target rasm_render_graph_add_taa_pass(rasm_render_graph* graph, rasm_render_target source, rasm_camera camera); rasm_render_target rasm_render_graph_add_bloom_passes(rasm_render_graph* graph, rasm_render_target source, rasm_camera camera); rasm_result rasm_render_graph_add_tone_map_pass(rasm_render_graph* graph, rasm_render_target source, rasm_camera camera, rasm_render_target bloom, const rasm_view_output* output); rasm_result rasm_render_graph_add_ui_pass(rasm_render_graph* graph, const rasm_render_target* shown, uint32_t shown_count);
1.17. RASM's own passes: addShadowPasses, addScenePasses, addMsaaResolvePass, addTaaPass, addBloomPasses, addToneMapPass and addUiPass. A rasm_shadow names a light's maps in this graph only, for its rasm_render_graph_add_scene_passes; rasm_shadow_desc is sized (light, cascade_count 4, map_size 2048, distance 50, split_lambda 0.7). The scene target has RASM_SCENE_COLOR_FORMAT and a depth; TAA needs RASM_MOTION_FORMAT as its second color. rasm_view_output (NULL: all of the main window) is ViewOutput: a rect, and a target or a window.
rasm_result rasm_cmd_get_info(rasm_commands* commands, rasm_pass_info* info); rasm_result rasm_cmd_bind_pipeline(rasm_commands* commands, rasm_pipeline pipeline); rasm_result rasm_cmd_push_constants(rasm_commands* commands, const void* data, uint32_t size, uint32_t offset); rasm_result rasm_cmd_set_viewport(rasm_commands* commands, float x, float y, float width, float height, float min_depth, float max_depth); rasm_result rasm_cmd_set_scissor(rasm_commands* commands, int32_t x, int32_t y, uint32_t width, uint32_t height); rasm_result rasm_cmd_set_cull_mode(rasm_commands* commands, rasm_cull_mode cull_mode); rasm_result rasm_cmd_draw(rasm_commands* commands, uint32_t vertex_count, uint32_t instance_count); rasm_result rasm_cmd_bind_index_buffer(rasm_commands* commands, rasm_buffer buffer, uint64_t offset, rasm_format index_format); rasm_result rasm_cmd_draw_indexed(rasm_commands* commands, uint32_t index_count, uint32_t instance_count, uint32_t vertex_offset, uint32_t first_index, uint32_t first_instance); rasm_result rasm_cmd_draw_indexed_indirect(rasm_commands* commands, rasm_buffer buffer, uint64_t offset, uint32_t draw_count, uint32_t stride); rasm_result rasm_cmd_draw_indexed_indirect_count(rasm_commands* commands, rasm_buffer buffer, uint64_t offset, rasm_buffer count_buffer, uint64_t count_offset, uint32_t max_draw_count, uint32_t stride); rasm_result rasm_cmd_dispatch(rasm_commands* commands, uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z); rasm_result rasm_cmd_dispatch_indirect(rasm_commands* commands, rasm_buffer buffer, uint64_t offset); rasm_result rasm_cmd_memory_barrier(rasm_commands* commands, rasm_pipeline_stage before, rasm_pipeline_stage after); uint32_t rasm_cmd_begin_gpu_timer(rasm_commands* commands, const char* name); rasm_result rasm_cmd_end_gpu_timer(rasm_commands* commands, uint32_t timer);
1.17. The low-level recording calls, on the pass's command buffer: bindPipeline (with bindDescriptorSet of the bindless set), pushConstants, setViewport, setScissor, setCullMode, draw, bindIndexBuffer (RASM_FORMAT_U16_UINT or RASM_FORMAT_U32_UINT), drawIndexed, drawIndexedIndirect, drawIndexedIndirectCount, dispatch, dispatchIndirect, memoryBarrier (compute passes, RASM_PIPELINE_STAGE_COMPUTE, RASM_PIPELINE_STAGE_GRAPHICS, RASM_PIPELINE_STAGE_HOST) and beginGpuTimer (RASM_INVALID_INDEX when nothing is measured). Only inside the callback that got commands; a call that does not fit the pass records nothing and returns RASM_ERROR_INVALID_ARGUMENT: a draw in a compute pass or a dispatch in a graphics one, no pipeline bound, a graphics pipeline made for other formats or samples than the pass writes, more than 16 bytes of push constants, an index buffer without RASM_BUFFER_USAGE_INDEX or an indirect one without RASM_BUFFER_USAGE_INDIRECT, an offset not aligned or reading past the buffer, a stride under 20 bytes, a timer the callback did not begin. A timer left open ends with the pass. rasm_cmd_get_info fills a sized rasm_pass_info: the pass's type, and the width and height of what it draws or writes.
rasm_result rasm_buffer_desc_init(rasm_buffer_desc* desc, uint32_t size); rasm_buffer rasm_create_buffer(rasm_renderer* renderer, const rasm_buffer_desc* desc); rasm_result rasm_destroy_buffer(rasm_renderer* renderer, rasm_buffer buffer); rasm_result rasm_write_buffer(rasm_renderer* renderer, rasm_buffer buffer, const void* data, uint64_t size, uint64_t offset); rasm_result rasm_read_buffer(rasm_renderer* renderer, rasm_buffer buffer, void* data, uint64_t size, uint64_t offset); uint64_t rasm_get_buffer_device_address(rasm_renderer* renderer, rasm_buffer buffer);
1.17. createBuffer, destroyBuffer, fillBuffer, readBuffer and getBufferDeviceAddress. rasm_buffer_desc is sized: name, usage (RASM_BUFFER_USAGE_STORAGE by default; RASM_BUFFER_USAGE_INDEX, RASM_BUFFER_USAGE_INDIRECT, RASM_BUFFER_USAGE_UNIFORM, RASM_BUFFER_USAGE_DEVICE_ADDRESS, RASM_BUFFER_USAGE_TRANSFER; an index buffer needs RASM_BUFFER_USAGE_INDEX, draw and dispatch arguments RASM_BUFFER_USAGE_INDIRECT, which compute shaders can still write through its address), byte_size, host_visible, host_readable, staged. A host-visible buffer is written at once, so write only what no frame in flight reads; a device-local one is written with the next frame's uploads, in order with the frames.
rasm_result rasm_pipeline_desc_init(rasm_pipeline_desc* desc, uint32_t size); rasm_pipeline rasm_create_pipeline(rasm_renderer* renderer, const rasm_pipeline_desc* desc);
1.17. A pipeline from Slang source (each stage's entry point compiled by createShader) or from SPIR-V per stage (rasm_shader_stage: entry_point, spirv, spirv_size), through RenderContext::createPipeline. Entry points default to vertMain, fragMain and compMain in source, and to main in SPIR-V, the name slangc and glslang give it. A graphics pipeline draws into targets with the formats and samples of target, or into window's swapchain format; blend_mode (RASM_BLEND_MODE_NONE ...), depth_test and depth_write (true, reversed-Z) and topology (RASM_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST ...) set the rest. Every pipeline sees the bindless set at set 0 and RASM_PUSH_CONSTANTS_SIZE (16) bytes of push constants, and has no vertex input. A pipeline lives as long as the renderer, and the same desc gives the same one.
uint32_t rasm_get_bindless_texture_index(rasm_renderer* renderer, rasm_texture texture); uint32_t rasm_add_bindless_texture(rasm_renderer* renderer, rasm_texture texture, rasm_sampler_type sampler); rasm_texture rasm_get_render_target_color(rasm_renderer* renderer, rasm_render_target target, uint32_t attachment); rasm_texture rasm_get_previous_render_target_color(rasm_renderer* renderer, rasm_render_target target, uint32_t attachment); rasm_texture rasm_get_render_target_depth(rasm_renderer* renderer, rasm_render_target target); uint32_t rasm_get_render_target_storage_index(rasm_renderer* renderer, rasm_render_target target, uint32_t attachment);
1.17. getBindlessTextureIndex (RASM_INVALID_INDEX for none), addBindlessTexture, getRenderTargetTexture, getPreviousRenderTargetTexture, getRenderTargetDepthTexture and getRenderTargetStorageIndex. A target's textures change with the frame slot: ask for them in the pass callback, every frame. There _color is the copy this frame writes, and _previous_color the one the frame before wrote.
uint32_t rasm_get_gpu_timer_count(rasm_renderer* renderer); uint32_t rasm_get_gpu_timer_name(rasm_renderer* renderer, uint32_t index, char* buffer, uint32_t capacity); float rasm_get_gpu_timer_ms(rasm_renderer* renderer, uint32_t index);
1.17. getFrameStats's gpuTimers: one per pass (by its name) and per rasm_cmd_begin_gpu_timer, of the last measured frame. The first call turns measuring on, so they fill in a few frames later.
rasm_result rasm_set_debug_view(rasm_renderer* renderer, rasm_debug_view view); rasm_debug_view rasm_get_debug_view(rasm_renderer* renderer); rasm_result rasm_set_culling_frozen(rasm_renderer* renderer, rasm_bool frozen); rasm_result rasm_set_meshlet_path(rasm_renderer* renderer, rasm_meshlet_path path); rasm_meshlet_path rasm_get_meshlet_path(rasm_renderer* renderer);
1.18. setDebugView and getDebugView (RASM_DEBUG_VIEW_NONE, RASM_DEBUG_VIEW_NORMALS, RASM_DEBUG_VIEW_UVS, RASM_DEBUG_VIEW_OVERDRAW, RASM_DEBUG_VIEW_LODS, RASM_DEBUG_VIEW_CULLING, RASM_DEBUG_VIEW_LIGHT_COUNT, RASM_DEBUG_VIEW_MESHLETS), setCullingFrozen, and setMeshletPath and getMeshletPath (the rasm_meshlet_path constants of the config). A value past the last constant is refused. See Debug views; examples/33_c_render_graph takes --debug-view normals.
rasm_result rasm_inspection_init(rasm_inspection* inspection, uint32_t size); rasm_result rasm_set_inspection(rasm_renderer* renderer, const rasm_inspection* inspection); uint32_t rasm_get_inspection(rasm_renderer* renderer, rasm_inspection* inspection, char* target_buffer, uint32_t capacity);
1.18. setInspection and getInspection: what the RASM window's Buffers section shows (Inspecting GPU resources); it needs the UI. rasm_inspection is sized and is Inspection: target (a render target's name; NULL or empty: nothing), kind (RASM_INSPECT_KIND_COLOR, RASM_INSPECT_KIND_DEPTH, RASM_INSPECT_KIND_HIZ, RASM_INSPECT_KIND_LIGHT_CLUSTERS), attachment, face, level (RASM_INSPECT_TILES for the screen tiles), sample (RASM_INSPECT_ALL_SAMPLES), channel, exposure, depth_range and entity. rasm_set_inspection copies the name. rasm_get_inspection fills the struct, copies the name into target_buffer by the snprintf rule, points target at it, and returns the name's whole length.
typedef void (RASM_CALL* rasm_ui_callback)(void* user_data); rasm_result rasm_set_ui_callback(rasm_renderer* renderer, rasm_ui_callback callback, void* user_data); uint64_t rasm_get_ui_texture(rasm_renderer* renderer, rasm_texture texture); void* rasm_get_imgui_context(rasm_renderer* renderer);
1.19. setUiCallback, getUiTexture and getUiContext; they need the UI (rasm_renderer_config's ui) and fail with RASM_ERROR_FAILED without it. The callback runs each frame between Dear ImGui's NewFrame and Render, inside rasm_render, rasm_render_views or rasm_render_graph_execute, on their thread, before the scene goes to the GPU, so what it changes shows in that frame. It has the rules of a pass callback: the queries and scene changes work, the calls that start a frame, change a graph or destroy what the frame uses are refused (the frame's call then returns RASM_ERROR_FAILED), and so is rasm_set_ui_callback itself. A NULL callback removes it. rasm_get_ui_texture gives the ImTextureID that shows a texture with ImGui's Image, or 0 while it loads. rasm_get_imgui_context gives the renderer's ImGuiContext*, or NULL while the UI is off.
typedef void* (*rasm_imgui_alloc_func)(size_t size, void* user_data); typedef void (*rasm_imgui_free_func)(void* pointer, void* user_data); rasm_result rasm_get_imgui_allocator_functions(rasm_imgui_alloc_func* alloc_func, rasm_imgui_free_func* free_func, void** user_data); const char* rasm_get_imgui_version(uint32_t* version_num); rasm_result rasm_check_imgui_layout(const char* version, uint64_t io_size, uint64_t style_size, uint64_t vec2_size, uint64_t vec4_size, uint64_t draw_vert_size, uint64_t draw_idx_size);
1.19. What a binding's own Dear ImGui needs to draw into RASM's context (below). rasm_get_imgui_allocator_functions gives the allocator of RASM's copy (ImGui::GetAllocatorFunctions). rasm_get_imgui_version returns IMGUI_VERSION, a string that lives as long as the library, and writes IMGUI_VERSION_NUM when version_num is not NULL. rasm_check_imgui_layout takes the binding's version string and the six sizes of IMGUI_CHECKVERSION (ImGuiIO, ImGuiStyle, ImVec2, ImVec4, ImDrawVert, ImDrawIdx) and returns RASM_OK when they are RASM's, else RASM_ERROR_FAILED with the first difference in rasm_get_last_error, such as "ImGuiIO is 3032 bytes in the caller's copy of Dear ImGui and 3000 in RASM's". It never asserts. In a RASM built without Dear ImGui (RASM_IMGUI=OFF) the three fail, and the version is NULL.
5Your own frame: the render graph
In place of rasm_render, a program can build the frame itself (1.17): a rasm_render_graph with RASM's passes and its own. Each pass of its own lists the resources it reads and writes, and gives a C function the graph calls while it records the frame. examples/33_c_render_graph builds this one:
static void RASM_CALL recordGrade(void *userData, rasm_commands *cmd)
{
App *app = (App *)userData;
const uint32_t source = rasm_get_bindless_texture_index(app->renderer, rasm_get_render_target_color(app->renderer, app->ldr, 0));
const uint32_t adapted = rasm_get_bindless_texture_index(app->renderer, rasm_get_render_target_color(app->renderer, app->adapt, 0));
uint32_t push[4] = {(uint32_t)app->paramsAddress, (uint32_t)(app->paramsAddress >> 32), source, adapted};
rasm_cmd_bind_pipeline(cmd, app->grade);
rasm_cmd_push_constants(cmd, push, sizeof(push), 0);
rasm_cmd_draw(cmd, 3, 1);
}
rasm_pass_resource uses[4] = {
{RASM_PASS_ACCESS_READ_RENDER_TARGET, 0, ldr.id},
{RASM_PASS_ACCESS_READ_RENDER_TARGET, 0, adapt.id},
{RASM_PASS_ACCESS_READ_BUFFER, 0, bins.id},
{RASM_PASS_ACCESS_WRITE_SWAPCHAIN, 0, 0},
};
rasm_pass_desc pass;
rasm_pass_desc_init(&pass, sizeof(pass));
pass.name = "Grade";
pass.resources = uses;
pass.resource_count = 4;
pass.execute = recordGrade;
pass.user_data = &app;
rasm_render_graph_add_pass(graph, &pass);
while (rasm_running(renderer))
rasm_render_graph_execute(graph, camera);
The rules of a pass callback
| Rule | What RASM does |
|---|---|
It runs on the thread that called rasm_render_graph_execute, during that call, in the graph's order of passes, once each frame the pass runs. | No thread of its own; a pass whose window has no image this frame is skipped. |
Its rasm_commands is valid only during the call. | A rasm_cmd_ call with it later returns RASM_ERROR_INVALID_ARGUMENT: "valid only inside the pass callback". |
| It may call the queries (bindless index, a target's textures, the GPU timers), but nothing that starts a frame, changes a graph or frees what the frame uses. | rasm_render, rasm_render_views, rasm_render_graph_execute, every graph change and destroy, rasm_resize_render_target, rasm_destroy_render_target, rasm_destroy_buffer, rasm_destroy_texture, rasm_add_window, rasm_remove_window and destroying the renderer or engine fail while a graph records; execute then returns RASM_ERROR_FAILED. |
| It returns normally. | No C++ exception, longjmp or Rust panic may leave it: catch them in the binding's trampoline. A Python exception stops in ctypes. |
The function and user_data live as long as the graph. | Python: keep the CFUNCTYPE object; C#: keep the delegate, or use [UnmanagedCallersOnly]. |
| More data than 16 bytes goes through a buffer. | Put its device address (rasm_get_buffer_device_address) in the push constants; a device-local buffer written with rasm_write_buffer is updated in order with the frames. |
6Dear ImGui from another language
RASM ships no ImGui wrapper. Your binding brings its own Dear ImGui (cimgui for C, and the cimgui-based ImGui.NET or imgui-rs), which is a second copy of the library with its own globals. Before its first ImGui call it checks that copy, then gives it RASM's allocator and context; from then on its calls in the UI callback draw into RASM's frame. Why each step is needed: Two copies of one library.
/* Once, after the renderer starts with rasm_renderer_config's ui on. */
rasm_imgui_alloc_func allocFunc;
rasm_imgui_free_func freeFunc;
void *allocData;
if (rasm_check_imgui_layout(igGetVersion(), sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) != RASM_OK)
return fail(rasm_get_last_error());
rasm_get_imgui_allocator_functions(&allocFunc, &freeFunc, &allocData);
igSetAllocatorFunctions(allocFunc, freeFunc, allocData);
igSetCurrentContext(rasm_get_imgui_context(renderer));
rasm_set_ui_callback(renderer, drawUi, &app);
/* Each frame, between NewFrame and Render. */
static void RASM_CALL drawUi(void *userData)
{
App *app = (App *)userData;
if (igBegin("Grade", NULL, 0))
igSliderFloat("Vignette", &app->vignette, 0.0f, 1.0f, "%.2f", 0);
igEnd();
}
| Rule | Why, and what happens when it breaks |
|---|---|
The same Dear ImGui version as RASM's: rasm_get_imgui_version, 1.92.6 today. | Structs change between versions. rasm_check_imgui_layout returns RASM_ERROR_FAILED and names both versions. |
| The same imconfig.h and defines: IMGUI_DISABLE_OBSOLETE_FUNCTIONS on, the default 16-bit ImDrawIdx, no IMGUI_USE_WCHAR32. | A define adds or resizes fields, and every field after them moves (the layout). The check names the first struct whose size differs. cimgui's headers are generated with obsolete functions off, as RASM builds Dear ImGui, so a stock cimgui of the same version passes. A define the six sizes do not show passes the check and still breaks: build with the same configuration. |
| RASM's allocator, set before the binding's first ImGui call. | Either copy may free what the other allocated. With two allocators a free goes to the wrong heap: a crash later, somewhere else. |
| RASM's context as the binding's current one, and ImGui calls only inside the UI callback. | Outside it, no frame is open. After the renderer is destroyed the context is gone: set the binding's current context to NULL. |
Keep the callback and user_data alive while it is set. | Python: keep the CFUNCTYPE object; C#: keep the delegate. |
examples/33_c_render_graph, built with -DRASM_C_IMGUI_EXAMPLE=ON, draws a window with sliders through cimgui this way, and a headless run clicks a slider through rasm_add_input_event and checks the window's pixels. tests/c_api/ctypes_smoke.py sets a Python UI callback, and with --cimgui draws through the cimgui shared library from Python.
7From C++ to C
| C++ | C |
|---|---|
Renderer renderer(config) | rasm_renderer_create(RASM_C_API_VERSION, &config, &renderer) |
Engine engine(config) | rasm_engine_create, then rasm_engine_get_renderer and rasm_engine_get_asset_loader |
renderer.createEntity(name, mesh, material, transform) | rasm_create_entity(renderer, name, mesh, material, &transform) |
engine.loadGLTF(path) | rasm_asset_loader_load_gltf(loader, path) |
isLoaded(mesh), isLoaded(texture) | rasm_is_mesh_loaded, rasm_is_texture_loaded |
createLight(type, color, position, ...) | rasm_create_light(renderer, &desc) with a rasm_light_desc |
createTexture(desc) + RenderContext::fillTexture | rasm_create_texture(renderer, &desc, pixels) |
ReadbackImage, writePng, readPng | rasm_image, rasm_image_write_png, rasm_image_read_png |
exportView, getExportProgress, takeExport | rasm_export_view, rasm_get_export_progress, rasm_take_export |
pick, takePick, PickHit | rasm_pick_view, rasm_take_pick, rasm_pick_hit (an array of sized structs) |
MeshHandle{} (invalid) | (rasm_mesh){0} |
render(views, count) with a View list | rasm_render_views(renderer, views, count) with a rasm_view array |
getInputEvents(count) | rasm_get_input_event_count, then rasm_get_input_event by index |
TileStreamer, TileContent | rasm_tile_streamer, an object with create and destroy; rasm_tile_content with arrays of C handles |
CameraRig, CameraInputState | rasm_camera_rig, rasm_camera_input_state: objects with create and destroy |
FontAtlas | rasm_font_atlas, an object made by rasm_build_font_atlas or rasm_asset_loader_load_font, destroyed by rasm_font_atlas_destroy |
RenderGraph, addPass(name, setup, execute) | rasm_render_graph; rasm_render_graph_add_pass with a rasm_pass_desc: the resources as a list, the execute lambda as a rasm_pass_callback and user_data |
RenderContext& and the frame's command buffer in a pass | the rasm_commands* the callback gets, for the rasm_cmd_ functions |
View::shadows, View::shadowCount | rasm_view's shadows pointer and shadow_count, read during the call |
setInspection, Inspection::target (std::string) | rasm_set_inspection with a const char* it copies; rasm_get_inspection by the snprintf rule |
setUiCallback(std::function), then ImGui:: calls | rasm_set_ui_callback with a rasm_ui_callback and user_data; the binding's own Dear ImGui, on rasm_get_imgui_context and rasm_get_imgui_allocator_functions |
getUiTexture, getUiContext, IMGUI_CHECKVERSION | rasm_get_ui_texture, rasm_get_imgui_context, rasm_check_imgui_layout |
addShadowPasses, SceneShadow | rasm_render_graph_add_shadow_passes, a graph-local rasm_shadow |
createPipeline(name, source, target), createComputePipeline | rasm_create_pipeline with a rasm_pipeline_desc, which also takes SPIR-V, a blend mode, depth and a topology |
FrameStats::gpuTimers | rasm_get_gpu_timer_count, rasm_get_gpu_timer_name, rasm_get_gpu_timer_ms |
std::string, std::vector | const char*; a pointer and a count |
C++ only: per-frame buffer pairs in a pass (FrameBuffers), and the rest of RenderContext (descriptor sets, fences, submits, copies), which a pass callback does through the rasm_cmd_ functions and buffers.