Added an asynchronous resource loading mechanism through App_GetResourcePath and App_ResourceLoaded. Added stb_image.h and used it to parse a .png file loaded from the server and upload it to app.testTexture. There is some ugliness around the edges images with transparency, probably caused by something pre-multiplied alpha related.

This commit is contained in:
2025-09-02 11:43:19 -07:00
parent 1a9775d670
commit f2d590be13
7 changed files with 8166 additions and 1 deletions

27
cwasm.c
View File

@@ -18,6 +18,18 @@ Description:
#include "cwasm_webgl_js_imports.h"
#include "cwasm_webgl_constants.h"
#define STB_IMAGE_IMPLEMENTATION
#define STBIDEF static
#define STBI_NO_STDIO
#define STBI_ASSERT(expression) Assert(expression)
#define STBI_MALLOC(numBytes) AllocMem(&ScratchArenas[0], numBytes)
#define STBI_REALLOC_SIZED(allocPntr, oldSize, newSize) ReallocMem(&ScratchArenas[0], (allocPntr), (oldSize), (newSize))
#define STBI_FREE(allocPntr) //nothing TODO: Once we have a general purpose arena we can implement this!
#define STBI_NO_SIMD
#define STBI_ONLY_PNG
#define STBI_NO_THREAD_LOCALS
#include "stb_image.h"
void InitializeCWasm(u32 scratchArenasSize)
{
InitGlobalArenas(scratchArenasSize);
@@ -30,3 +42,18 @@ WASM_EXPORT(cAllocMem) void* cAllocMem(Arena* arenaPntr, int numBytes, int align
Assert(alignment >= 0);
return AllocMemAligned(arenaPntr, (u32)numBytes, (u32)alignment);
}
WASM_EXPORT(cGetScratchArenaPntr) Arena* cGetScratchArenaPntr(Arena* conflictArenaPntr)
{
ArenaMark scratchMark = GetScratch1(conflictArenaPntr);
return scratchMark.arena;
}
WASM_EXPORT(cGetScratchArenaMark) u32 cGetScratchArenaMark(Arena* conflictArenaPntr)
{
ArenaMark scratchMark = GetScratch1(conflictArenaPntr);
return scratchMark.mark;
}
WASM_EXPORT(cEndScratchArena) void cEndScratchArena(Arena* arenaPntr, u32 mark)
{
ResetToMark(arenaPntr, mark);
}