Skip to main content

System API

Headers: src/system/hwlayer.h, src/system/resources.h, src/system/console.h, src/system/pakReader.h
Namespaces: glitter::system, glitter


glitter::system::HWLayer

Platform and windowing layer. Created first during engine init (before the renderer). Retrieve via engine::hwlayer().

Constructor

Methods

MemberReturnsDescription
createWindow(title, width, height, framelimit, type)Window&Create the primary SDL window with the given frame rate limit and window type
getRenderer()Renderer&Access the active renderer (throws if none is set)
getRendererPtr()Renderer*Raw pointer to the renderer (nullptr before a renderer is attached)
setRenderer(renderer)voidAttach a renderer to this hardware layer
getMonitors()monitorArray&List of detected monitors and their display modes
getPaths()ospaths&Platform path helpers — base (executable dir) and pref (user prefs dir)
clearDrawBuffer()voidClear the current draw buffer

glitter::system::windowType

ValueDescription
FULLSCREENTrue exclusive fullscreen
FAKE_FULLSCREENBorderless fullscreen at desktop resolution
WINDOWEDNormal windowed mode

glitter::system::Window

The main SDL application window. Retrieve via engine::mainWindow().

Title

MemberReturnsDescription
setTitle(str)voidSet the window title
setTitle(str, save)voidSet the window title; if save = true, also save it as the persistent base title
getTitle()std::stringGet the current window title

Display mode

MemberReturnsDescription
makeFullscreen()voidSwitch to true exclusive fullscreen
makeFakeFullscreen()voidSwitch to borderless fullscreen at desktop resolution
makeWindowed()voidReturn to windowed mode

Size

MemberReturnsDescription
getWidth()intCurrent window width in pixels
getHeight()intCurrent window height in pixels

Rendering & timing

MemberReturnsDescription
makeCurrent()voidMake the renderer context current on the calling thread
swap()voidPresent the back buffer immediately
swapTick()boolPresent the back buffer and enforce the frame rate limit. Returns true while the application is running; false when a quit has been signalled.
getDelta()doubleFrame delta time in seconds since the last swapTick()

Events

MemberReturnsDescription
pollEvents()voidPump the SDL event queue into the internal queue
hasEvents()booltrue if there are unprocessed events in the queue
currentEvent()SDL_EventPeek at the front event (call hasEvents() first)
popEvent()voidRemove the front event from the queue
hasQuitSignal()booltrue if a quit or window-close event was received

Input capture

MemberReturnsDescription
setRelativeMouseMode(enable)voidHide the cursor and use relative motion (true) or restore it (false). Used by the free-fly camera.

glitter::resources

URI-based resource system. All game data is accessed through scheme-mapped URIs. Retrieve via engine::resources().

Scheme registration

MemberReturnsDescription
setAbsolutePath(scheme, directory)voidMap a URI scheme to an absolute filesystem directory (read-write)
setAbsolutePath(scheme, directory, readonly)voidMap a URI scheme to a directory; readonly = true prevents writes
deleteSchemeResources(scheme)voidUnmap a scheme and release any cached data associated with it

Reading resources

MemberReturnsDescription
getResourceBytes(uri)std::vector<std::byte>Read raw bytes; throws on failure
tryGetResourceBytes(uri)expected<vector<byte>, string>Read raw bytes; returns an error string on failure
getResourceString(uri)std::stringRead as a UTF-8 string; throws on failure
tryGetResourceString(uri)expected<string, string>Read as string; returns an error string on failure
getResourceJSON(uri)nlohmann::jsonParse as JSON; throws on failure
tryGetResourceJSON(uri)expected<json, string>Parse as JSON; returns an error string on failure

Writing resources

MemberReturnsDescription
setResourceData(uri, data)voidWrite raw byte data to a URI (writable schemes only)
writeResourcePointer(uri)SDL_IOStream*Open a write stream to a URI; close with SDL_CloseIO when done
readResourcePointer(uri)SDL_IOStream*Open a read stream from a URI; close with SDL_CloseIO when done

Discovery

MemberReturnsDescription
resourceExists(uri)boolReturns true if the resource file exists on disk
listFiles(directoryUri)std::vector<uri<void>>List all entries (files and subdirectories) under a scheme directory
getFilesystemPath(uri)boost::filesystem::pathResolve a URI to its absolute native filesystem path

glitter::uri<T>

Lightweight URI handle used by all resource APIs. The base uri<void> accepts any full "scheme://address" string. Typed variants (e.g. uri<res::shader>) prepend the scheme automatically.

uri<void> — base untyped URI

src/system/resources.h
uri(const std::string& uriStr)
uri(const char* s)
uri(const uri<void>& parent, const std::string& child) // child path relative to parent
MemberReturnsDescription
getScheme()std::stringScheme component (e.g. "scenes", "textures")
getAddress()std::stringAddress component (path within the scheme)
getNative()std::stringAbsolute native filesystem path
getUri()std::stringFull URI string ("scheme://address")
getFilename()std::stringFilename component only (no directory, no scheme)
getParentUri()uri<void>Parent directory as a URI
isFile()booltrue when the address has a file extension
isDirectory()booltrue when the address has no file extension
contentType()std::string_viewRFC 2046 MIME type derived from the file extension

uri<Tag> — typed URI

src/system/resources.h
template<typename Tag>
class uri : public uri<void> {
explicit uri(const std::string& filename); // Tag::scheme() prepended automatically
explicit uri(const char* filename);
};

Typed URIs convert implicitly to uri<void> so all resource APIs accept them without any changes at the call site.

Well-known MIME types (glitter::mime)

ConstantMIME type
mime::jsonapplication/json
mime::pngimage/png
mime::jpegimage/jpeg
mime::hdrimage/x-hdr
mime::ktx2image/ktx2
mime::gltfBinarymodel/gltf-binary
mime::gltfJsonmodel/gltf+json
mime::spirvapplication/spirv
mime::glsltext/x-glsl
mime::texttext/plain
mime::octetStreamapplication/octet-stream
mime::directoryinode/directory

glitter::system::Console

Valve-style developer console with a scrollable log pane and command line. Header: src/system/console.h.

Methods

MemberReturnsDescription
registerCommand(name, description, handler)voidRegister a named command (stored lowercase)
addLine(text, level)voidAppend a line to the log pane. Thread-safe — called from the spdlog sink.
execute(line)voidParse and execute a command string
draw()voidDraw the ImGui console window. Call inside an active ImGui frame.
toggle()voidToggle console open/closed
isOpen()boolWhether the console is currently open
entryCount()size_tNumber of buffered log entries

CommandArgs

MemberReturnsDescription
positionalvector<string>Positional (non-flag) arguments
hasFlag(flag)boolCheck if a --flag was present
get(key)optional<string_view>Get a --key=value arg, or nullopt if absent

glitter::system::PakReader

Reads .glitterpak archives (binary asset packages). Header: src/system/pakReader.h.

Static factory

src/system/pakReader.h
static tl::expected<PakReader, std::string> PakReader::open(std::vector<std::byte> archiveData);

Methods

MemberReturnsDescription
findFile(path)optional<FileInfo>O(1) hash lookup for a file entry
readFile(info)expected<vector<byte>, string>Read and decompress a file entry
listDirectory(path)vector<string>List entries under a directory path