diff --git a/src/Graphics_3DS.c b/src/Graphics_3DS.c index 94c24b940..f864cc292 100644 --- a/src/Graphics_3DS.c +++ b/src/Graphics_3DS.c @@ -243,10 +243,12 @@ struct GPUTexture { }; static struct GPUTexture* del_textures_head; static struct GPUTexture* del_textures_tail; + struct GPUTexture* GPUTexture_Alloc(void) { struct GPUTexture* tex = Mem_AllocCleared(1, sizeof(struct GPUTexture), "GPU texture"); return tex; } + // can't delete textures until not used in any frames static void GPUTexture_Unref(GfxResourceID* resource) { struct GPUTexture* tex = (struct GPUTexture*)(*resource); @@ -255,10 +257,12 @@ static void GPUTexture_Unref(GfxResourceID* resource) { LinkedList_Append(tex, del_textures_head, del_textures_tail); } + static void GPUTexture_Free(struct GPUTexture* tex) { C3D_TexDelete(&tex->texture); Mem_Free(tex); } + static void GPUTextures_DeleteUnreferenced(void) { if (!del_textures_head) return; @@ -314,6 +318,15 @@ static bool CreateNativeTexture(C3D_Tex* tex, u32 width, u32 height) { return true; } +static void TryTransferToVRAM(C3D_Tex* tex) { + void* vram = vramAlloc(tex->size); + if (!vram) return; + + C3D_SyncTextureCopy((u32*)tex->data, 0, (u32*)vram, 0, tex->size, 8); + linearFree(tex->data); + tex->data = vram; +} + /*static inline cc_uint32 CalcZOrder(cc_uint32 x, cc_uint32 y) { // Simplified "Interleave bits by Binary Magic Numbers" from // http://graphics.stanford.edu/~seander/bithacks.html#InterleaveTableObvious @@ -375,6 +388,7 @@ static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, cc_uint8 flags, cc_boo if (!success) return NULL; ToMortonTexture(&tex->texture, 0, 0, bmp, bmp->width); + if (!(flags & TEXTURE_FLAG_DYNAMIC)) TryTransferToVRAM(&tex->texture); return tex; } diff --git a/third_party/citro3d.c b/third_party/citro3d.c index 16ca2f659..41d639501 100644 --- a/third_party/citro3d.c +++ b/third_party/citro3d.c @@ -885,7 +885,7 @@ static void C3D_FrameBufClear(C3D_FrameBuf* frameBuf, C3D_ClearBits clearBits, u if (clearBits & C3D_CLEAR_COLOR) { if (clearBits & C3D_CLEAR_DEPTH) - GX_gMemoryFill( + GX_MemoryFill( (u32*)frameBuf->colorBuf, clearColor, (u32*)colorBufEnd, BIT(0) | (cfs << 8), (u32*)frameBuf->depthBuf, clearDepth, (u32*)depthBufEnd, BIT(0) | (dfs << 8)); else