166 lines
3.2 KiB
C
166 lines
3.2 KiB
C
////////////////////////////////////////////////////////////
|
|
//~ Texture types
|
|
|
|
Struct(S_Texture)
|
|
{
|
|
b32 valid;
|
|
b32 loaded;
|
|
GPU_Resource *gpu_texture;
|
|
u32 width;
|
|
u32 height;
|
|
};
|
|
|
|
extern Readonly S_Texture S_NilTexture;
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Sheet types
|
|
|
|
Struct(S_Frame)
|
|
{
|
|
u32 index;
|
|
f64 duration;
|
|
ClipRect clip;
|
|
};
|
|
|
|
Struct(S_Span)
|
|
{
|
|
S_Span *next_in_bin;
|
|
u64 hash;
|
|
String name;
|
|
u32 start;
|
|
u32 end;
|
|
};
|
|
|
|
Struct(S_SpanBin)
|
|
{
|
|
S_Span *first;
|
|
S_Span *last;
|
|
};
|
|
|
|
Struct(S_Slice)
|
|
{
|
|
/* If 1, this slice was not copied over from another frame in the sprite sheet */
|
|
b32 is_original;
|
|
|
|
/* If 1, the slice has a corresponding '.ray' slice affecting the 'dir' fields */
|
|
b32 has_dir;
|
|
|
|
/* Values are in the range -0.5 (top / left edge) -> +0.5 (bottom / right edge) */
|
|
Rect rect;
|
|
Vec2 center;
|
|
Vec2 dir;
|
|
|
|
/* '_px' values retain the original sprite pixel dimensions */
|
|
Rect rect_px;
|
|
Vec2 center_px;
|
|
Vec2 dir_px;
|
|
};
|
|
|
|
Struct(S_SliceGroup)
|
|
{
|
|
S_SliceGroup *next_in_bin;
|
|
u64 hash;
|
|
String name;
|
|
S_Slice *slices;
|
|
};
|
|
|
|
Struct(S_SliceGroupBin)
|
|
{
|
|
S_SliceGroup *first;
|
|
S_SliceGroup *last;
|
|
};
|
|
|
|
Struct(S_Sheet)
|
|
{
|
|
b32 valid;
|
|
b32 loaded;
|
|
Vec2 image_size;
|
|
Vec2 frame_size;
|
|
|
|
u32 frames_count;
|
|
S_Frame *frames;
|
|
|
|
u32 spans_count;
|
|
S_Span *spans;
|
|
|
|
u32 slice_groups_count;
|
|
S_SliceGroup *slice_groups;
|
|
|
|
u32 span_bins_count;
|
|
S_SpanBin *span_bins;
|
|
|
|
u32 slice_group_bins_count;
|
|
S_SliceGroupBin *slice_group_bins;
|
|
};
|
|
|
|
extern Readonly S_Sheet S_NilSheet;
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Cache types
|
|
|
|
Struct(S_Entry)
|
|
{
|
|
S_Entry *next_in_bin;
|
|
|
|
S_Texture texture;
|
|
S_Sheet sheet;
|
|
|
|
Atomic32 texture_touched;
|
|
Atomic32 sheet_touched;
|
|
|
|
ResourceKey resource;
|
|
Fence texture_ready_fence;
|
|
Fence sheet_ready_fence;
|
|
};
|
|
|
|
Struct(S_EntryBin)
|
|
{
|
|
S_Entry *first;
|
|
S_Entry *last;
|
|
Mutex mutex;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ State types
|
|
|
|
#define S_EntryBinsCount 1024
|
|
|
|
Struct(S_SharedState)
|
|
{
|
|
S_EntryBin entry_bins[S_EntryBinsCount];
|
|
} extern S_shared_state;
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Load jobs
|
|
|
|
JobDecl(S_LoadTexture, { S_Entry *entry; });
|
|
JobDecl(S_LoadSheet, { S_Entry *entry; });
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Cache operations
|
|
|
|
Enum(S_FetchFlag)
|
|
{
|
|
S_FetchFlag_None = 0,
|
|
S_FetchFlag_Texture = (1 << 0),
|
|
S_FetchFlag_Sheet = (1 << 1),
|
|
};
|
|
|
|
S_Entry *S_FetchEntry(ResourceKey resource, JobPoolId pool, S_FetchFlag flags);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Sprite data retrieval operations
|
|
|
|
S_Texture *S_TextureFromResource(ResourceKey resource);
|
|
S_Texture *S_TextureFromResourceAsync(ResourceKey resource);
|
|
|
|
S_Sheet *S_SheetFromResource(ResourceKey resource);
|
|
S_Sheet *S_SheetFromResourceAsync(ResourceKey resource);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Sheet access operations
|
|
|
|
S_Span S_SpanFromName(S_Sheet *sheet, String name);
|
|
S_Frame S_FrameFromIndex(S_Sheet *sheet, u64 index);
|
|
S_Slice S_SliceFromName(S_Sheet *sheet, String name, u64 frame_index);
|