whb: Add GFD texture loading with WHBGfxLoadGFDTexture, WHBGfxFreeTexture.

This commit is contained in:
James Benton 2017-05-28 12:00:51 +01:00
parent 3c47d28082
commit cef331cc09
2 changed files with 59 additions and 0 deletions

View File

@ -80,6 +80,13 @@ WHBGfxInitFetchShader(WHBGfxShaderGroup *group);
BOOL
WHBGfxFreeShaderGroup(WHBGfxShaderGroup *group);
GX2Texture *
WHBGfxLoadGFDTexture(uint32_t index,
const void *file);
BOOL
WHBGfxFreeTexture(GX2Texture *texture);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,52 @@
#include "gfx_heap.h"
#include <gfd.h>
#include <gx2r/surface.h>
#include <gx2/texture.h>
#include <whb/gfx.h>
GX2Texture *
WHBGfxLoadGFDTexture(uint32_t index,
const void *file)
{
uint32_t headerSize, imageSize;
GX2Texture *texture = NULL;
void *image = NULL;
if (index >= GFDGetTextureCount(file)) {
goto error;
}
headerSize = GFDGetTextureHeaderSize(index, file);
imageSize = GFDGetTextureImageSize(index, file);
if (!headerSize || !imageSize) {
goto error;
}
texture = (GX2Texture *)GfxHeapAllocMEM2(headerSize, 64);
if (!texture) {
goto error;
}
if (!GFDGetGX2RTexture(texture, index, file)) {
goto error;
}
return texture;
error:
if (texture) {
GX2RDestroySurfaceEx(&texture->surface, 0);
GfxHeapFreeMEM2(texture);
}
return NULL;
}
BOOL
WHBGfxFreeTexture(GX2Texture *texture)
{
GX2RDestroySurfaceEx(&texture->surface, 0);
GfxHeapFreeMEM2(texture);
return TRUE;
}