API reference
Getting started
RASM is a static C++20 library. Your program creates one Engine, asks it for scenes, meshes, materials, cameras and lights, and gets small handles back. Then it calls one function per frame. This page shows how to link RASM, a first program, and the three ways to run a frame.
In short
- Link with CMake:
find_package(rasm)andrasm::rasm, orfind_package(rasm COMPONENTS renderer)andrasm::rendererfor the renderer alone, without SDL3 and the file loaders' libraries. Ship the shaders next to your executable. - Include one header:
rasm/rasm.h. Everything is innamespace rasm. - From C, or from Python, C#, Rust or Zig: the C API,
rasm/rasm_c.hwith the shared libraryrasm_c(find_package(rasm COMPONENTS c)andrasm::c). - Every object is a handle. A function that fails logs an error and returns an invalid handle (
isValid()is false). - Files load in the background. You can use a mesh or texture handle at once; the object is drawn when its data is ready.
- Call the engine from one thread only. It has no locks.
- No window needed: a
Rendererwithout a window (or anEnginewithPlatformType::HEADLESS) renders frames offscreen, andreadFramecopies them back to the CPU (headless).
1The objects you work with
Engine functions and keep their handles. The engine keeps the GPU copies (amber) up to date. You never write the GPU tables yourself.| Object | Create it with | Details |
|---|---|---|
| Scene | createScene | scene.html |
| Entity (one object in the world) | createEntity | scene.html |
| Mesh | loadMesh (OBJ, glTF) or createMesh (your vertices) | scene.html |
| Light | createLight | scene.html |
| Material | createMaterial | materials.html |
| Texture | loadTexture | materials.html |
| Camera | createCamera | camera.html |
2Build RASM and link it
- Install the tools. CMake 3.23 or newer, Ninja, Clang and vcpkg, with the VCPKG_ROOT environment variable set to it. The Vulkan SDK (1.4) gives the validation layer and the tools; the build does not need it. To run, the machine needs a GPU driver with Vulkan 1.4: RASM loads the Vulkan loader when the engine starts (The Vulkan loader). The step-by-step setup is in
docs/build_guide.md. - Build and install RASM. The presets use Ninja and
clang++, and vcpkg builds the dependencies.cmake --installcopies the library, the public headers and the shaders toinstall/in the repo. Debug and Release share that folder, so install both if your project builds both.cmake --preset x64-debug # macOS: --preset macOS cmake --build --preset x64-debug cmake --install build/x64-debug cmake --install build/x64-release # if you built it too - Find it from your project. Point CMake at the install folder with
-DCMAKE_PREFIX_PATH=<repo>/install. To use a build folder without installing, setrasm_DIRto it instead (for example-Drasm_DIR=<repo>/build/x64-debug).cmake_minimum_required(VERSION 3.21) project(my_app CXX) find_package(rasm 0.1 CONFIG REQUIRED) add_executable(my_app main.cpp) target_link_libraries(my_app PRIVATE rasm::rasm) # adds C++20, glm # The renderer alone (rasm::Renderer, no Engine or AssetLoader): find_package(rasm 0.1 CONFIG REQUIRED COMPONENTS renderer) # and rasm::renderer, which needs no SDL3, tinyobjloader, libktx or LASzip. # Shaders are compiled at runtime: copy them next to the executable. add_custom_command(TARGET my_app POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${rasm_SHADER_DIR}" "$<TARGET_FILE_DIR:my_app>/shaders") - Give your project RASM's dependencies. RASM is static, so your executable links its dependencies too.
find_package(rasm)looks for them. With vcpkg, add to your manifest:volk,vulkan-headers,vk-bootstrap,vulkan-memory-allocator,glm,sdl3,tracy[on-demand],spdlog,tinyobjloader,meshoptimizer,shader-slang,ktx,laszipandzlib(sdl3,tinyobjloader,ktxandlasziponly forrasm::rasm; RASM installs aFindlaszip.cmakebeside its config, as the port has no CMake package), andimguiwhen RASM was built withRASM_IMGUI(the default): the same version as RASM's (1.92.6), built with IMGUI_DISABLE_OBSOLETE_FUNCTIONS in its imconfig.h as RASM's is (copy RASM's overlay portports/imguiinto your overlay ports), or the engine starts with the UI off and logs which struct size differs. Nothing links the Vulkan loader, so your executable runs on a machine without Vulkan until it creates anEngine, which then logs a clear error.
add_subdirectory(rasm) works too and gives the same rasm::rasm and rasm::renderer targets. Then examples, tests and install rules are off by default. The options are -DRASM_BUILD_EXAMPLES=ON, -DRASM_BUILD_TESTS=ON, -DRASM_INSTALL=ON, -DRASM_ENABLE_AVX2=ON (x86 only), -DRASM_WARNINGS=ON (extra compiler warnings on RASM's own targets), -DRASM_IMGUI=OFF (no Dear ImGui: nothing installed or linked, UI with Dear ImGui), -DRASM_C_IMGUI_EXAMPLE=ON (downloads cimgui for examples/33_c_render_graph's window from C, Dear ImGui from another language) and -DRASM_SHADER_DIR=<path> (the default shader folder, shaders beside the executable).
On Windows the executable needs the dependency DLLs next to it. The examples copy them with rasm_copy_runtime_dlls in cmake/RasmRuntimeDlls.cmake, because vcpkg's own copy misses TracyClient.dll in Debug.
3A first program
This is examples/00_hello_scene/main.cpp made shorter. It loads a mesh and a texture, puts one entity, a camera and a light into a scene, and renders until the window closes (or Esc).
#include "rasm/rasm.h"
int main()
{
rasm::EngineConfig config = {
.appName = "my_app",
.windowWidth = 1280,
.windowHeight = 720,
.enableValidation = true,
.assetRoot = "assets", // relative paths start beside the executable
};
rasm::Engine engine(config);
if (!engine.running())
return 1; // the reason is in the log
rasm::SceneHandle scene = engine.createScene();
// Both return at once. The files are read on a worker thread.
rasm::MeshHandle mesh = engine.loadMesh("models/obj/bunny/bunny.obj");
rasm::TextureHandle albedo = engine.loadTexture("models/obj/bunny/bunny-atlas.jpg");
if (!mesh.isValid() || !albedo.isValid())
return 1; // unknown format or missing file
rasm::MaterialHandle material = engine.createMaterial(rasm::MaterialType::PBR, {albedo});
rasm::EntityHandle bunny = engine.createEntity("bunny", mesh, material,
rasm::Transform{.position = glm::vec3(0.0f, 0.0f, -10.0f), .scale = glm::vec3(0.005f)});
rasm::CameraHandle camera = engine.createCamera(
rasm::CameraProjection{.type = rasm::CameraProjection::Type::PERSPECTIVE,
.perspective{.fovY = 45.0f, .aspect = 1280.0f / 720.0f, .nearZ = 0.1f}},
rasm::Transform{.position = glm::vec3(0.0f, 0.0f, 4.0f)});
const glm::vec3 sunDirection = glm::normalize(glm::vec3(-0.5f, -0.8f, -1.0f));
rasm::LightHandle sun = engine.createLight(rasm::LightType::DIRECTIONAL, glm::vec3(1.0f),
glm::vec3(0.0f), sunDirection, 3.0f);
engine.addEntityToScene(scene, bunny);
engine.addCameraToScene(scene, camera);
engine.addLightToScene(scene, sun);
while (engine.running())
engine.render(scene, camera); // the bunny appears once its files are loaded
return 0;
}
What you see
The first frames are empty (dark gray). The bunny appears when its mesh and its texture are both loaded. Drag with the mouse to orbit the camera, scroll to zoom. F1 shows the stats overlay.
What to check when it fails
Read the log (spdlog, on the console). Common causes: no shaders/ folder beside the executable, a wrong assetRoot, or a GPU without Vulkan 1.4. Keep enableValidation on while you develop.
4Handles
| Fact | What it means for you |
|---|---|
A handle is two numbers, index and generation | Copy it freely, store it, compare it with ==. It is not a pointer. |
{} is the invalid handle | isValid() is false. Many functions take one as "none", for example createEntity without a material. |
| Errors return the invalid handle | The function logs the reason and returns {}. Check isValid() after creating or loading. |
| Each kind has its own type | MeshHandle and TextureHandle do not convert into each other, so you cannot pass the wrong kind. |
| A handle is valid until you destroy its object | Every object has a destroy* call. A call with a destroyed object's handle logs an error and does nothing, even when a new object took its index. What the GPU may still use is freed once it is done (deferred destruction). |
All handle types are listed in Types, handles and limits, with every limit.
5Three ways to run a frame
beginFrame returns false: the frame is skipped (window minimized, swapchain out of date).| Way | Use it for | Example | Reference |
|---|---|---|---|
A · render | One scene, one camera, straight to the window. | 00_hello_scene, 02_gltf, 03_instances, 05_city | engine.html#render |
B · beginFrame / endFrame | A few passes in a fixed order, your own pipelines. It cannot draw a scene: the scene is drawn by graph passes. | none | engine.html#beginFrame |
C · RenderGraph | Offscreen render targets, post effects, compute work, a scene into a render target (addScenePasses). The graph orders the passes and records their barriers. | 01_render_graph, 04_compute, 06_shadows | render-graph.html |
// B: your own frame. Inside a pass, record with the frame's command buffer.
while (engine.running())
{
if (!engine.beginFrame(camera))
continue; // skipped: record nothing, no endFrame
engine.beginPass("Main");
// engine.getRenderContext() records draws into
// engine.getCurrentFrameResources().commandBuffer here
engine.endPass();
engine.endFrame();
}
6Where to go next
MAX_* constant.
How the engine worksThe guides explain the inside, for engine developers.