194 lines
3.3 KiB
C
194 lines
3.3 KiB
C
////////////////////////////////////////////////////////////
|
|
//~ Key types
|
|
|
|
Struct(SPR_SheetKey) { ResourceKey r; };
|
|
Struct(SPR_SpanKey) { u64 v; };
|
|
|
|
#define SPR_NilSheetKey ((SPR_SheetKey) { 0 })
|
|
#define SPR_NilSpanKey ((SPR_SpanKey) { 0 })
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Atlas types
|
|
|
|
Struct(SPR_Atlas)
|
|
{
|
|
SPR_Atlas *next;
|
|
|
|
Vec2I32 dims;
|
|
G_ResourceHandle tex;
|
|
G_Texture2DRef tex_ref;
|
|
Vec2I32 cur_pos;
|
|
i32 cur_row_height;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Ray types
|
|
|
|
#define SPR_RayKindXMacro(X) \
|
|
X(Origin, .origin) \
|
|
X(Ap, .ap) \
|
|
/* ----------------------------- */
|
|
|
|
Enum(SPR_RayKind)
|
|
{
|
|
#define X(kind_name, ...) SPR_RayKind_##kind_name,
|
|
SPR_RayKindXMacro(X)
|
|
#undef X
|
|
SPR_RayKind_COUNT
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Layer types
|
|
|
|
Enum(SPR_LayerKind)
|
|
{
|
|
SPR_LayerKind_Visual,
|
|
SPR_LayerKind_Hidden,
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Lookup result types
|
|
|
|
Struct(SPR_Slice)
|
|
{
|
|
Xform rays[SPR_RayKind_COUNT];
|
|
|
|
G_Texture2DRef tex;
|
|
Rng2 tex_rect_uv;
|
|
Rng2 bounds;
|
|
|
|
b32 exists;
|
|
b32 ready;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Cache types
|
|
|
|
//- Slice
|
|
|
|
Struct(SPR_SliceEntry)
|
|
{
|
|
SPR_SliceEntry *next_in_bin;
|
|
|
|
Xform rays[SPR_RayKind_COUNT];
|
|
|
|
SPR_Atlas *atlas;
|
|
Rng2 atlas_rect_uv;
|
|
Rng2 bounds;
|
|
Atomic64 atlas_copy_completion_target;
|
|
};
|
|
|
|
//- Span
|
|
|
|
Struct(SPR_SpanEntry)
|
|
{
|
|
SPR_SpanEntry *next;
|
|
SPR_SpanEntry *next_in_bin;
|
|
SPR_SpanKey key;
|
|
|
|
i64 from;
|
|
i64 to;
|
|
};
|
|
|
|
Struct(SPR_SpanBin)
|
|
{
|
|
SPR_SpanEntry *first;
|
|
};
|
|
|
|
//- Sheet
|
|
|
|
Struct(SPR_SheetEntry)
|
|
{
|
|
SPR_SheetEntry *next_in_bin;
|
|
SPR_SheetKey key;
|
|
|
|
i64 slices_count;
|
|
SPR_SliceEntry *slices;
|
|
|
|
i64 span_bins_count;
|
|
SPR_SpanBin *span_bins;
|
|
SPR_SpanEntry *first_span;
|
|
SPR_SpanEntry *last_span;
|
|
|
|
ASE_Meta meta;
|
|
b32 ok;
|
|
};
|
|
|
|
Struct(SPR_SheetBin)
|
|
{
|
|
Mutex mutex;
|
|
SPR_SheetEntry *first;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Async cmd types
|
|
|
|
Struct(SPR_Cmd)
|
|
{
|
|
SPR_SheetEntry *sheet;
|
|
i64 slice_idx;
|
|
};
|
|
|
|
Struct(SPR_CmdNode)
|
|
{
|
|
SPR_CmdNode *next;
|
|
SPR_Cmd cmd;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ State types
|
|
|
|
Struct(SPR_AsyncCtx)
|
|
{
|
|
i32 _;
|
|
};
|
|
|
|
Struct(SPR_Ctx)
|
|
{
|
|
SPR_SheetBin sheet_bins[Kibi(16)];
|
|
|
|
// FIXME: Initialize this
|
|
G_Texture2DRef unready_tex;
|
|
Vec2 unready_tex_dims;
|
|
|
|
i64 atlases_count;
|
|
SPR_Atlas *first_atlas;
|
|
|
|
struct
|
|
{
|
|
Mutex mutex;
|
|
SPR_CmdNode *first;
|
|
SPR_CmdNode *last;
|
|
SPR_CmdNode *first_free;
|
|
i64 count;
|
|
} submit;
|
|
|
|
SPR_AsyncCtx async;
|
|
};
|
|
|
|
extern SPR_Ctx SPR;
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Bootstrap
|
|
|
|
void SPR_Bootstrap(void);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Helpers
|
|
|
|
SPR_SheetKey SPR_SheetKeyFromResource(ResourceKey resource);
|
|
SPR_SpanKey SPR_SpanKeyFromName(String name);
|
|
|
|
String SPR_NameFromRayKind(SPR_RayKind kind);
|
|
SPR_LayerKind SPR_LayerKindFromName(String name);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Lookup
|
|
|
|
SPR_Slice SPR_SliceFromSheet(SPR_SheetKey sheet_key, SPR_SpanKey span_key, i64 frame_seq);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Async
|
|
|
|
void SPR_TickAsync(WaveLaneCtx *lane, AsyncFrameLaneCtx *base_async_lane_frame);
|