DEKI/ENGINE docs
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches

Loads assets onto the GPU for the editor, cached by GUID: uint32_t texId = EditorAssets::Get()->LoadTexture(guid, &w, &h); Deki2D::BitmapFont* font = EditorAssets::Get()->GetBitmapFont(bakedGuid);. More...

#include <C:/Users/kirby/Documents/Github/deki/deki-editor/deki-editor/include/deki-editor/EditorAssets.h>

Public Types

using ImageLoaderFn = uint8_t* (*)(const char* path, int32_t& outWidth, int32_t& outHeight, bool& outHasAlpha)
 Loads a .dtex image file as RGBA pixels. The caller must free() the buffer.
using FontFromDfontFn
 Loads a .dfont file, returning an opaque Deki2D::BitmapFont* and the atlas RGBA data to upload.
using FontDestroyFn = void (*)(void* font)
 Destroys a font returned by FontFromDfontFn.
using FontBakeCallback = std::function<Deki2D::BitmapFont*(const std::string&, int)>
 Bakes a TTF asset (GUID) at a pixel size.
using FontAtlasCallback = std::function<uint32_t(const std::string&, int, uint32_t*, uint32_t*)>
 The OpenGL atlas texture of a TTF asset (GUID) at a pixel size, with its width and height, or 0 on failure.

Public Member Functions

uint32_t LoadTexture (const std::string &guid, uint32_t *outWidth=nullptr, uint32_t *outHeight=nullptr)
 The OpenGL texture for an asset GUID (resolved through AssetManager), uploading it on first use, or 0 on failure.
void InvalidateTexture (const std::string &guid)
 Drops a cached texture so the next access reloads it.
void ClearTextureCache ()
 Drops every cached texture, freeing GPU memory.
uint32_t LoadFontAtlas (const std::string &bakedGuid, uint32_t *outWidth=nullptr, uint32_t *outHeight=nullptr)
 The OpenGL atlas texture for a baked font (font.guid, resolved to a .dfont through AssetManager::LookupPath()), or 0 on failure.
uint32_t LoadFontAtlasFromPath (const std::string &dfontPath, uint32_t *outWidth=nullptr, uint32_t *outHeight=nullptr)
 The OpenGL atlas texture for the .dfont at a full path, or 0 on failure.
Deki2D::BitmapFont * GetBitmapFont (const std::string &bakedGuid)
 The BitmapFont of a baked font, for glyph metrics, or nullptr if it is not cached.
void InvalidateFontAtlas (const std::string &bakedGuid)
 Drops a cached font so the next access reloads it.
void ClearFontCache ()
 Drops every cached font, freeing GPU memory.
void SetFontBakingCallbacks (FontBakeCallback bakeFont, FontAtlasCallback getAtlas)
 Called by the editor at startup.
void ClearFontBakingCallbacks ()
 Must be called BEFORE FreeLibrary on the package that set the callbacks: the std::function destructor runs the callable's manager function, which must still be mapped.
Deki2D::BitmapFont * GetBitmapFontWithBaking (const std::string &sourceGuid, int fontSize)
 The BitmapFont of a TTF asset at a pixel size, baking it if needed, or nullptr if not found.
uint32_t LoadFontAtlasWithBaking (const std::string &sourceGuid, int fontSize, uint32_t *outWidth=nullptr, uint32_t *outHeight=nullptr)
 The OpenGL atlas texture of a TTF asset at a pixel size, baking it if needed, or 0 on failure.
bool LoadSpriteSettings (const std::string &guid, int *outFrameWidth=nullptr, int *outFrameHeight=nullptr)
 Reads a spritesheet's frame size from the asset's .data file.
uint32_t LoadFrameTexture (const std::string &frameGuid, uint32_t *outWidth=nullptr, uint32_t *outHeight=nullptr)
 The OpenGL texture of a frame's parent spritesheet, or 0 on failure.
bool GetFrameUVs (const std::string &frameGuid, float *outU0, float *outV0, float *outU1, float *outV1)
 The normalized UVs (0 to 1) of a frame ("parent:frame-N") within its parent texture: (U0, V0) top-left, (U1, V1) bottom-right.

Static Public Member Functions

static void RegisterImageLoader (ImageLoaderFn fn)
static void RegisterFontFactory (FontFromDfontFn factory, FontDestroyFn destroyer)
static ImageLoaderFn GetImageLoader ()
static void ClearPackageInjectedCallbacks ()
 Clears every function pointer packages registered.
static EditorAssets * Get ()
static void Shutdown ()
 Frees every GPU resource.

Detailed Description

Loads assets onto the GPU for the editor, cached by GUID: uint32_t texId = EditorAssets::Get()->LoadTexture(guid, &w, &h); Deki2D::BitmapFont* font = EditorAssets::Get()->GetBitmapFont(bakedGuid);.

Paths come from AssetManager's GUID table, which the editor must fill when a project loads.

Member Typedef Documentation

◆ ImageLoaderFn

using DekiEditor::EditorAssets::ImageLoaderFn = uint8_t* (*)(const char* path, int32_t& outWidth, int32_t& outHeight, bool& outHasAlpha)

Loads a .dtex image file as RGBA pixels. The caller must free() the buffer.

◆ FontFromDfontFn

Initial value:
void* (*)(const char* dfontPath, uint8_t** outAtlasRGBA, int32_t& outAtlasW,
int32_t& outAtlasH)

Loads a .dfont file, returning an opaque Deki2D::BitmapFont* and the atlas RGBA data to upload.

The caller owns the font and must free() outAtlasRGBA after uploading.

◆ FontDestroyFn

using DekiEditor::EditorAssets::FontDestroyFn = void (*)(void* font)

Destroys a font returned by FontFromDfontFn.

◆ FontBakeCallback

using DekiEditor::EditorAssets::FontBakeCallback = std::function<Deki2D::BitmapFont*(const std::string&, int)>

Bakes a TTF asset (GUID) at a pixel size.

Returns the font, owned by the caller's cache, or nullptr on failure.

◆ FontAtlasCallback

using DekiEditor::EditorAssets::FontAtlasCallback = std::function<uint32_t(const std::string&, int, uint32_t*, uint32_t*)>

The OpenGL atlas texture of a TTF asset (GUID) at a pixel size, with its width and height, or 0 on failure.

Member Function Documentation

◆ RegisterImageLoader()

void DekiEditor::EditorAssets::RegisterImageLoader ( ImageLoaderFn fn)
static

◆ RegisterFontFactory()

void DekiEditor::EditorAssets::RegisterFontFactory ( FontFromDfontFn factory,
FontDestroyFn destroyer )
static

◆ GetImageLoader()

ImageLoaderFn DekiEditor::EditorAssets::GetImageLoader ( )
static

◆ ClearPackageInjectedCallbacks()

void DekiEditor::EditorAssets::ClearPackageInjectedCallbacks ( )
static

Clears every function pointer packages registered.

Must be called before a package DLL unloads, or the next LoadTexture/LoadFontAtlas calls code that is gone and the editor crashes.

◆ Get()

EditorAssets * DekiEditor::EditorAssets::Get ( )
static

◆ Shutdown()

void DekiEditor::EditorAssets::Shutdown ( )
static

Frees every GPU resource.

◆ LoadTexture()

uint32_t DekiEditor::EditorAssets::LoadTexture ( const std::string & guid,
uint32_t * outWidth = nullptr,
uint32_t * outHeight = nullptr )

The OpenGL texture for an asset GUID (resolved through AssetManager), uploading it on first use, or 0 on failure.

Width and height are written to the optional outputs.

◆ InvalidateTexture()

void DekiEditor::EditorAssets::InvalidateTexture ( const std::string & guid)

Drops a cached texture so the next access reloads it.

◆ ClearTextureCache()

void DekiEditor::EditorAssets::ClearTextureCache ( )

Drops every cached texture, freeing GPU memory.

◆ LoadFontAtlas()

uint32_t DekiEditor::EditorAssets::LoadFontAtlas ( const std::string & bakedGuid,
uint32_t * outWidth = nullptr,
uint32_t * outHeight = nullptr )

The OpenGL atlas texture for a baked font (font.guid, resolved to a .dfont through AssetManager::LookupPath()), or 0 on failure.

◆ LoadFontAtlasFromPath()

uint32_t DekiEditor::EditorAssets::LoadFontAtlasFromPath ( const std::string & dfontPath,
uint32_t * outWidth = nullptr,
uint32_t * outHeight = nullptr )

The OpenGL atlas texture for the .dfont at a full path, or 0 on failure.

◆ GetBitmapFont()

Deki2D::BitmapFont * DekiEditor::EditorAssets::GetBitmapFont ( const std::string & bakedGuid)

The BitmapFont of a baked font, for glyph metrics, or nullptr if it is not cached.

◆ InvalidateFontAtlas()

void DekiEditor::EditorAssets::InvalidateFontAtlas ( const std::string & bakedGuid)

Drops a cached font so the next access reloads it.

◆ ClearFontCache()

void DekiEditor::EditorAssets::ClearFontCache ( )

Drops every cached font, freeing GPU memory.

◆ SetFontBakingCallbacks()

void DekiEditor::EditorAssets::SetFontBakingCallbacks ( FontBakeCallback bakeFont,
FontAtlasCallback getAtlas )

Called by the editor at startup.

◆ ClearFontBakingCallbacks()

void DekiEditor::EditorAssets::ClearFontBakingCallbacks ( )

Must be called BEFORE FreeLibrary on the package that set the callbacks: the std::function destructor runs the callable's manager function, which must still be mapped.

◆ GetBitmapFontWithBaking()

Deki2D::BitmapFont * DekiEditor::EditorAssets::GetBitmapFontWithBaking ( const std::string & sourceGuid,
int fontSize )

The BitmapFont of a TTF asset at a pixel size, baking it if needed, or nullptr if not found.

◆ LoadFontAtlasWithBaking()

uint32_t DekiEditor::EditorAssets::LoadFontAtlasWithBaking ( const std::string & sourceGuid,
int fontSize,
uint32_t * outWidth = nullptr,
uint32_t * outHeight = nullptr )

The OpenGL atlas texture of a TTF asset at a pixel size, baking it if needed, or 0 on failure.

◆ LoadSpriteSettings()

bool DekiEditor::EditorAssets::LoadSpriteSettings ( const std::string & guid,
int * outFrameWidth = nullptr,
int * outFrameHeight = nullptr )

Reads a spritesheet's frame size from the asset's .data file.

Returns false for a texture without sprite settings.

◆ LoadFrameTexture()

uint32_t DekiEditor::EditorAssets::LoadFrameTexture ( const std::string & frameGuid,
uint32_t * outWidth = nullptr,
uint32_t * outHeight = nullptr )

The OpenGL texture of a frame's parent spritesheet, or 0 on failure.

frameGuid has the form "parent:frame-N"; the size outputs get the parent texture's size. Use GetFrameUVs() for the frame's place in it.

◆ GetFrameUVs()

bool DekiEditor::EditorAssets::GetFrameUVs ( const std::string & frameGuid,
float * outU0,
float * outV0,
float * outU1,
float * outV1 )

The normalized UVs (0 to 1) of a frame ("parent:frame-N") within its parent texture: (U0, V0) top-left, (U1, V1) bottom-right.

Returns false when the frame is not found.


The documentation for this class was generated from the following file: