formatting
This commit is contained in:
parent
b14ce157b8
commit
938f4e701c
@ -402,7 +402,7 @@ void ASE_Inflate(u8 *dst, u8 *encoded)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Error handling
|
//~ Error helpers
|
||||||
|
|
||||||
void ASE_PushError(Arena *arena, ASE_ErrorList *list, String msg_src)
|
void ASE_PushError(Arena *arena, ASE_ErrorList *list, String msg_src)
|
||||||
{
|
{
|
||||||
@ -421,7 +421,7 @@ void ASE_PushError(Arena *arena, ASE_ErrorList *list, String msg_src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Decode image
|
//~ Decode helpers
|
||||||
|
|
||||||
u32 ASE_BlendMulU8(u32 a, u32 b)
|
u32 ASE_BlendMulU8(u32 a, u32 b)
|
||||||
{
|
{
|
||||||
@ -482,6 +482,9 @@ void ASE_MakeDimensionsSquareish(ASE_Header *header, u32 *frames_x, u32 *frames_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ Decode image
|
||||||
|
|
||||||
ASE_DecodedImage ASE_DecodeImage(Arena *arena, String encoded)
|
ASE_DecodedImage ASE_DecodeImage(Arena *arena, String encoded)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
|
|||||||
@ -226,16 +226,23 @@ u16 ASE_DecodeHuffDict(ASE_HuffDict *huffman, ASE_Bitbuff *bb);
|
|||||||
void ASE_Inflate(u8 *dst, u8 *encoded);
|
void ASE_Inflate(u8 *dst, u8 *encoded);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Error handling operations
|
//~ Error helpers
|
||||||
|
|
||||||
//- Helpers
|
|
||||||
void ASE_PushError(Arena *arena, ASE_ErrorList *list, String msg_src);
|
void ASE_PushError(Arena *arena, ASE_ErrorList *list, String msg_src);
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ Decode helpers
|
||||||
|
|
||||||
u32 ASE_BlendMulU8(u32 a, u32 b);
|
u32 ASE_BlendMulU8(u32 a, u32 b);
|
||||||
u32 ASE_Blend(u32 src, u32 dst, u8 opacity);
|
u32 ASE_Blend(u32 src, u32 dst, u8 opacity);
|
||||||
void ASE_MakeDimensionsSquareish(ASE_Header *header, u32 *frames_x, u32 *frames_y, u64 *image_width, u64 *image_height);
|
void ASE_MakeDimensionsSquareish(ASE_Header *header, u32 *frames_x, u32 *frames_y, u64 *image_width, u64 *image_height);
|
||||||
|
|
||||||
//- Decode image
|
////////////////////////////////
|
||||||
|
//~ Decode image
|
||||||
|
|
||||||
ASE_DecodedImage ASE_DecodeImage(Arena *arena, String encoded);
|
ASE_DecodedImage ASE_DecodeImage(Arena *arena, String encoded);
|
||||||
|
|
||||||
//- Decode sheet
|
////////////////////////////////
|
||||||
|
//~ Decode sheet
|
||||||
|
|
||||||
ASE_DecodedSheet ASE_DecodeSheet(Arena *arena, String encoded);
|
ASE_DecodedSheet ASE_DecodeSheet(Arena *arena, String encoded);
|
||||||
|
|||||||
@ -671,7 +671,7 @@ void SignalExit(i32 code);
|
|||||||
void ExitNow(i32 code);
|
void ExitNow(i32 code);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ @hookdecl Layer initialization hook (defined by metaprogram)
|
//~ @hookdecl Meta hooks
|
||||||
|
|
||||||
void StartupLayers(void);
|
void StartupLayers(void);
|
||||||
|
|
||||||
|
|||||||
@ -173,7 +173,7 @@ void SignalCv(Cv *cv, i32 count)
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Counter
|
//~ Counter
|
||||||
|
|
||||||
u64 ValueFromCounter(Counter *counter)
|
i64 ValueFromCounter(Counter *counter)
|
||||||
{
|
{
|
||||||
return Atomic64Fetch(&counter->v);
|
return Atomic64Fetch(&counter->v);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,6 +79,6 @@ void SignalCv(Cv *cv, i32 count);
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Counter operations
|
//~ Counter operations
|
||||||
|
|
||||||
u64 ValueFromCounter(Counter *counter);
|
i64 ValueFromCounter(Counter *counter);
|
||||||
void AddCounter(Counter *counter, i64 x);
|
void AddCounter(Counter *counter, i64 x);
|
||||||
void YieldOnCounter(Counter *counter);
|
void YieldOnCounter(Counter *counter);
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
@ -10,18 +10,54 @@ void S_Startup(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Load texture job
|
//~ Load jobs
|
||||||
|
|
||||||
JobDef(S_LoadTextureJob, sig, _)
|
JobDef(S_LoadTextureJob, sig, _)
|
||||||
{
|
{
|
||||||
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
S_Entry *entry = sig->entry;
|
S_Entry *entry = sig->entry;
|
||||||
|
Resource resource = entry->resource;
|
||||||
|
b32 success = 1;
|
||||||
|
S_Texture *texture = &entry->texture;
|
||||||
|
texture->valid = 1;
|
||||||
|
|
||||||
|
String name = NameFromResource(resource);
|
||||||
|
String data = DataFromResource(resource);
|
||||||
|
|
||||||
|
ASE_DecodedImage decoded = ASE_DecodeImage(scratch.arena, data);
|
||||||
|
success = decoded.success;
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
GPU_ResourceDesc desc = ZI;
|
||||||
|
desc.kind = GPU_ResourceKind_Texture2D;
|
||||||
|
desc.flags = GPU_ResourceFlag_AllowSrv;
|
||||||
|
desc.flags = GPU_ResourceFlag_AllowUav;
|
||||||
|
desc.flags = GPU_ResourceFlag_AllowRtv;
|
||||||
|
desc.texture.format = GPU_Format_R8G8B8A8_Unorm_Srgb;
|
||||||
|
desc.texture.size = VEC3I32(decoded.width, decoded.height, 1);
|
||||||
|
desc.texture.mip_levels = 1;
|
||||||
|
texture->gpu_resource = GPU_AcquireResource(desc);
|
||||||
|
texture->width = decoded.width;
|
||||||
|
texture->height = decoded.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
texture->loaded = 1;
|
||||||
AddCounter(&entry->texture_load_counter, -1);
|
AddCounter(&entry->texture_load_counter, -1);
|
||||||
|
EndScratch(scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
JobDef(S_LoadSheetJob, sig, _)
|
JobDef(S_LoadSheetJob, sig, _)
|
||||||
{
|
{
|
||||||
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
S_Entry *entry = sig->entry;
|
S_Entry *entry = sig->entry;
|
||||||
|
Resource resource = entry->resource;
|
||||||
|
b32 success = 1;
|
||||||
|
S_Sheet *sheet = &entry->sheet;
|
||||||
|
sheet->valid = 1;
|
||||||
|
|
||||||
AddCounter(&entry->sheet_load_counter, -1);
|
AddCounter(&entry->sheet_load_counter, -1);
|
||||||
|
EndScratch(scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
@ -69,8 +105,6 @@ S_Entry *S_FetchEntry(Resource resource, JobPool pool, S_FetchFlag flags)
|
|||||||
{
|
{
|
||||||
entry = PushStruct(PermArena, S_Entry);
|
entry = PushStruct(PermArena, S_Entry);
|
||||||
entry->resource = resource;
|
entry->resource = resource;
|
||||||
entry->texture = &S_NilTexture;
|
|
||||||
entry->sheet = &S_NilSheet;
|
|
||||||
AddCounter(&entry->texture_load_counter, 1);
|
AddCounter(&entry->texture_load_counter, 1);
|
||||||
AddCounter(&entry->sheet_load_counter, 1);
|
AddCounter(&entry->sheet_load_counter, 1);
|
||||||
QueuePush_N(bin->first, bin->last, entry, next_in_bin);
|
QueuePush_N(bin->first, bin->last, entry, next_in_bin);
|
||||||
@ -102,7 +136,7 @@ S_Texture *S_TextureFromResource(Resource resource)
|
|||||||
{
|
{
|
||||||
S_Entry *entry = S_FetchEntry(resource, JobPool_Inherit, S_FetchFlag_Texture);
|
S_Entry *entry = S_FetchEntry(resource, JobPool_Inherit, S_FetchFlag_Texture);
|
||||||
YieldOnCounter(&entry->texture_load_counter);
|
YieldOnCounter(&entry->texture_load_counter);
|
||||||
return entry->texture;
|
return &entry->texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
S_Texture *S_TextureFromResourceAsync(Resource resource)
|
S_Texture *S_TextureFromResourceAsync(Resource resource)
|
||||||
@ -111,7 +145,7 @@ S_Texture *S_TextureFromResourceAsync(Resource resource)
|
|||||||
S_Entry *entry = S_FetchEntry(resource, JobPool_Inherit, S_FetchFlag_Texture);
|
S_Entry *entry = S_FetchEntry(resource, JobPool_Inherit, S_FetchFlag_Texture);
|
||||||
if (ValueFromCounter(&entry->texture_load_counter) <= 0)
|
if (ValueFromCounter(&entry->texture_load_counter) <= 0)
|
||||||
{
|
{
|
||||||
result = entry->texture;
|
result = &entry->texture;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -120,7 +154,7 @@ S_Sheet *S_SheetFromResource(Resource resource)
|
|||||||
{
|
{
|
||||||
S_Entry *entry = S_FetchEntry(resource, JobPool_Inherit, S_FetchFlag_Sheet);
|
S_Entry *entry = S_FetchEntry(resource, JobPool_Inherit, S_FetchFlag_Sheet);
|
||||||
YieldOnCounter(&entry->sheet_load_counter);
|
YieldOnCounter(&entry->sheet_load_counter);
|
||||||
return entry->sheet;
|
return &entry->sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
S_Sheet *S_SheetFromResourceAsync(Resource resource)
|
S_Sheet *S_SheetFromResourceAsync(Resource resource)
|
||||||
@ -129,7 +163,7 @@ S_Sheet *S_SheetFromResourceAsync(Resource resource)
|
|||||||
S_Entry *entry = S_FetchEntry(resource, JobPool_Inherit, S_FetchFlag_Sheet);
|
S_Entry *entry = S_FetchEntry(resource, JobPool_Inherit, S_FetchFlag_Sheet);
|
||||||
if (ValueFromCounter(&entry->sheet_load_counter) <= 0)
|
if (ValueFromCounter(&entry->sheet_load_counter) <= 0)
|
||||||
{
|
{
|
||||||
result = entry->sheet;
|
result = &entry->sheet;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,35 +1,10 @@
|
|||||||
////////////////////////////////
|
|
||||||
//~ Cache types
|
|
||||||
|
|
||||||
Struct(S_Entry)
|
|
||||||
{
|
|
||||||
S_Entry *next_in_bin;
|
|
||||||
|
|
||||||
struct S_Texture *texture;
|
|
||||||
struct S_Sheet *sheet;
|
|
||||||
|
|
||||||
Atomic32 texture_touched;
|
|
||||||
Atomic32 sheet_touched;
|
|
||||||
|
|
||||||
Resource resource;
|
|
||||||
Counter texture_load_counter;
|
|
||||||
Counter sheet_load_counter;
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(S_EntryBin)
|
|
||||||
{
|
|
||||||
S_Entry *first;
|
|
||||||
S_Entry *last;
|
|
||||||
Mutex mutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Texture types
|
//~ Texture types
|
||||||
|
|
||||||
Struct(S_Texture)
|
Struct(S_Texture)
|
||||||
{
|
{
|
||||||
b32 loaded;
|
|
||||||
b32 valid;
|
b32 valid;
|
||||||
|
b32 loaded;
|
||||||
GPU_Resource *gpu_resource;
|
GPU_Resource *gpu_resource;
|
||||||
u32 width;
|
u32 width;
|
||||||
u32 height;
|
u32 height;
|
||||||
@ -91,8 +66,8 @@ Struct(S_SheetSliceGroup)
|
|||||||
|
|
||||||
Struct(S_Sheet)
|
Struct(S_Sheet)
|
||||||
{
|
{
|
||||||
b32 loaded;
|
|
||||||
b32 valid;
|
b32 valid;
|
||||||
|
b32 loaded;
|
||||||
Vec2 image_size;
|
Vec2 image_size;
|
||||||
Vec2 frame_size;
|
Vec2 frame_size;
|
||||||
|
|
||||||
@ -110,6 +85,31 @@ Struct(S_Sheet)
|
|||||||
|
|
||||||
extern Readonly S_Sheet S_NilSheet;
|
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;
|
||||||
|
|
||||||
|
Resource resource;
|
||||||
|
Counter texture_load_counter;
|
||||||
|
Counter sheet_load_counter;
|
||||||
|
};
|
||||||
|
|
||||||
|
Struct(S_EntryBin)
|
||||||
|
{
|
||||||
|
S_Entry *first;
|
||||||
|
S_Entry *last;
|
||||||
|
Mutex mutex;
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Shared state
|
//~ Shared state
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user