Deki 1.3.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches

Editor-only asset utilities for GPU resource management. More...

#include <EditorAssets.h>

Public Types

using ImageLoaderFn = uint8_t* (*)(const char* path, int32_t& outWidth, int32_t& outHeight, bool& outHasAlpha)
 Load a .dtex image file as RGBA pixel data. Caller must free() the returned buffer.
using FontFromDfontFn = void* (*)(const char* dfontPath, uint8_t** outAtlasRGBA, int32_t& outAtlasW, int32_t& outAtlasH)
 Load a .dfont file, returning an opaque BitmapFont* and the atlas RGBA data for GPU upload.
using FontDestroyFn = void (*)(void* font)
 Destroy an opaque BitmapFont* returned by FontFromDfontFn.
using FontBakeCallback = std::function<BitmapFont*(const std::string&, int)>
 Callback for font baking.
using FontAtlasCallback = std::function<uint32_t(const std::string&, int, uint32_t*, uint32_t*)>
 Callback for getting font atlas texture.

Public Member Functions

uint32_t LoadTexture (const std::string &guid, uint32_t *outWidth=nullptr, uint32_t *outHeight=nullptr)
 Load texture by GUID and upload to GPU.
void InvalidateTexture (const std::string &guid)
 Invalidate cached texture (forces reload on next access).
void ClearTextureCache ()
 Clear all cached textures (frees GPU memory).
uint32_t LoadFontAtlas (const std::string &bakedGuid, uint32_t *outWidth=nullptr, uint32_t *outHeight=nullptr)
 Load font atlas by baked GUID and upload to GPU.
uint32_t LoadFontAtlasFromPath (const std::string &dfontPath, uint32_t *outWidth=nullptr, uint32_t *outHeight=nullptr)
 Load font atlas from filesystem path.
BitmapFont * GetBitmapFont (const std::string &bakedGuid)
 Get BitmapFont by baked GUID (for glyph metrics).
void InvalidateFontAtlas (const std::string &bakedGuid)
 Invalidate cached font (forces reload on next access).
void ClearFontCache ()
 Clear all cached fonts (frees GPU memory).
void SetFontBakingCallbacks (FontBakeCallback bakeFont, FontAtlasCallback getAtlas)
 Set callbacks for font baking (called by editor on startup).
void ClearFontBakingCallbacks ()
 Clear font baking callbacks before package DLL unload.
BitmapFont * GetBitmapFontWithBaking (const std::string &sourceGuid, int fontSize)
 Get BitmapFont by source GUID and size (triggers baking if needed).
uint32_t LoadFontAtlasWithBaking (const std::string &sourceGuid, int fontSize, uint32_t *outWidth=nullptr, uint32_t *outHeight=nullptr)
 Load font atlas by source GUID and size (triggers baking if needed).
bool LoadSpriteSettings (const std::string &guid, int *outFrameWidth=nullptr, int *outFrameHeight=nullptr)
 Load sprite settings (frame dimensions) from .data file.
uint32_t LoadFrameTexture (const std::string &frameGuid, uint32_t *outWidth=nullptr, uint32_t *outHeight=nullptr)
 Load texture for a frame sprite (loads parent spritesheet texture).
bool GetFrameUVs (const std::string &frameGuid, float *outU0, float *outV0, float *outU1, float *outV1)
 Get UV coordinates for a frame sprite.

Static Public Member Functions

static void RegisterImageLoader (ImageLoaderFn fn)
static void RegisterFontFactory (FontFromDfontFn factory, FontDestroyFn destroyer)
static ImageLoaderFn GetImageLoader ()
static void ClearPackageInjectedCallbacks ()
 Null all package-injected function pointers.
static EditorAssets * Get ()
 Get singleton instance.
static void Shutdown ()
 Shutdown and cleanup all GPU resources.

Detailed Description

Editor-only asset utilities for GPU resource management.

Provides Unity-like asset loading for editor use: uint32_t texId = EditorAssets::Get()->LoadTexture(guid, &w, &h); BitmapFont* font = EditorAssets::Get()->GetBitmapFont(bakedGuid);

Features:

  • GPU texture caching by GUID
  • Automatic texture upload to OpenGL
  • Font atlas loading and caching

Note: Uses AssetManager's GUID table for path resolution. The editor must populate the GUID table on project load.

Member Typedef Documentation

◆ ImageLoaderFn

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

Load a .dtex image file as RGBA pixel data. Caller must free() the returned buffer.

◆ FontFromDfontFn

using DekiEditor::EditorAssets::FontFromDfontFn = void* (*)(const char* dfontPath, uint8_t** outAtlasRGBA, int32_t& outAtlasW, int32_t& outAtlasH)

Load a .dfont file, returning an opaque BitmapFont* and the atlas RGBA data for GPU upload.

The caller must free() outAtlasRGBA after uploading. The returned font is owned by the caller.

◆ FontDestroyFn

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

Destroy an opaque BitmapFont* returned by FontFromDfontFn.

◆ FontBakeCallback

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

Callback for font baking.

Parameters
sourceGuidTTF asset GUID
fontSizeFont size in pixels
Returns
BitmapFont pointer (owned by caller's cache), or nullptr on failure

◆ FontAtlasCallback

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

Callback for getting font atlas texture.

Parameters
sourceGuidTTF asset GUID
fontSizeFont size in pixels
outWidthOutput atlas width
outHeightOutput atlas height
Returns
OpenGL texture ID, 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

Null all package-injected function pointers.

Must be called before a package DLL is unloaded — otherwise any subsequent LoadTexture/LoadFontAtlas would invoke code that no longer exists, crashing the editor.

◆ Get()

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

Get singleton instance.

◆ Shutdown()

void DekiEditor::EditorAssets::Shutdown ( )
static

Shutdown and cleanup all GPU resources.

◆ LoadTexture()

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

Load texture by GUID and upload to GPU.

Parameters
guidAsset GUID (looked up via AssetManager)
outWidthOptional output for texture width
outHeightOptional output for texture height
Returns
OpenGL texture ID, or 0 on failure

Textures are cached - subsequent calls with same GUID return cached texture.

◆ InvalidateTexture()

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

Invalidate cached texture (forces reload on next access).

Parameters
guidAsset GUID

◆ ClearTextureCache()

void DekiEditor::EditorAssets::ClearTextureCache ( )

Clear all cached textures (frees GPU memory).

◆ LoadFontAtlas()

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

Load font atlas by baked GUID and upload to GPU.

Parameters
bakedGuidDeterministic GUID of the baked font (font.guid)
outWidthOptional output for atlas width
outHeightOptional output for atlas height
Returns
OpenGL texture ID, or 0 on failure

Uses AssetManager::LookupPath() to resolve the baked GUID to a .dfont path.

◆ LoadFontAtlasFromPath()

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

Load font atlas from filesystem path.

Parameters
dfontPathFull path to the .dfont file
outWidthOptional output for atlas width
outHeightOptional output for atlas height
Returns
OpenGL texture ID, or 0 on failure

◆ GetBitmapFont()

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

Get BitmapFont by baked GUID (for glyph metrics).

Parameters
bakedGuidDeterministic GUID of the baked font
Returns
Pointer to BitmapFont, or nullptr if not cached

◆ InvalidateFontAtlas()

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

Invalidate cached font (forces reload on next access).

Parameters
bakedGuidBaked font GUID

◆ ClearFontCache()

void DekiEditor::EditorAssets::ClearFontCache ( )

Clear all cached fonts (frees GPU memory).

◆ SetFontBakingCallbacks()

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

Set callbacks for font baking (called by editor on startup).

◆ ClearFontBakingCallbacks()

void DekiEditor::EditorAssets::ClearFontBakingCallbacks ( )

Clear font baking callbacks before package DLL unload.

Must be called BEFORE FreeLibrary on the package that set the callbacks, so the std::function destructor can safely invoke the old callable's manager function while the DLL code is still mapped.

◆ GetBitmapFontWithBaking()

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

Get BitmapFont by source GUID and size (triggers baking if needed).

Parameters
sourceGuidTTF asset GUID
fontSizeFont size in pixels
Returns
BitmapFont pointer, 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 )

Load font atlas by source GUID and size (triggers baking if needed).

Parameters
sourceGuidTTF asset GUID
fontSizeFont size in pixels
outWidthOptional output for atlas width
outHeightOptional output for atlas height
Returns
OpenGL texture ID, or 0 on failure

◆ LoadSpriteSettings()

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

Load sprite settings (frame dimensions) from .data file.

Parameters
guidAsset GUID
outFrameWidthOptional output for frame width
outFrameHeightOptional output for frame height
Returns
True if sprite settings exist and were loaded

For spritesheets, this returns the individual frame dimensions. For regular textures without sprite settings, returns false.

◆ LoadFrameTexture()

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

Load texture for a frame sprite (loads parent spritesheet texture).

Parameters
frameGuidFrame GUID (format: "parent:frame-N")
outWidthOptional output for parent texture width
outHeightOptional output for parent texture height
Returns
OpenGL texture ID of parent spritesheet, or 0 on failure

Frame sprites reference the same texture as their parent spritesheet. Use GetFrameUVs() to get the UV coordinates for the specific frame.

◆ GetFrameUVs()

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

Get UV coordinates for a frame sprite.

Parameters
frameGuidFrame GUID (format: "parent:frame-N")
outU0Output for top-left U coordinate
outV0Output for top-left V coordinate
outU1Output for bottom-right U coordinate
outV1Output for bottom-right V coordinate
Returns
True if frame info was found and UVs calculated

UV coordinates are normalized (0.0 to 1.0) based on frame position within parent texture.


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