|
|
@@ -3,22 +3,21 @@
|
|
|
#include "Log.h"
|
|
|
#include "FileStream.h"
|
|
|
#include <cassert>
|
|
|
+#include "Allocator.h"
|
|
|
|
|
|
namespace crown
|
|
|
{
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-TextureResource* TextureResource::load(ResourceArchive* archive, ResourceId id)
|
|
|
+TextureResource* TextureResource::load(Allocator& allocator, ResourceArchive* archive, ResourceId id)
|
|
|
{
|
|
|
assert(archive != NULL);
|
|
|
|
|
|
- Log::D("TextureResource::load called.");
|
|
|
-
|
|
|
FileStream* stream = archive->find(id);
|
|
|
|
|
|
if (stream != NULL)
|
|
|
{
|
|
|
- TextureResource* resource = new TextureResource;
|
|
|
+ TextureResource* resource = (TextureResource*)allocator.allocate(sizeof(TextureResource));
|
|
|
|
|
|
stream->read(&resource->format, sizeof(PixelFormat));
|
|
|
stream->read(&resource->width, sizeof(uint16_t));
|
|
|
@@ -27,17 +26,10 @@ TextureResource* TextureResource::load(ResourceArchive* archive, ResourceId id)
|
|
|
stream->read(&resource->mode, sizeof(TextureMode));
|
|
|
stream->read(&resource->filter, sizeof(TextureFilter));
|
|
|
stream->read(&resource->wrap, sizeof(TextureWrap));
|
|
|
-
|
|
|
- printf("Debug: Format = %d\n", resource->format);
|
|
|
- printf("Debug: Width = %d\n", resource->width);
|
|
|
- printf("Debug: Height = %d\n", resource->height);
|
|
|
- printf("Debug: Mode = %d\n", resource->mode);
|
|
|
- printf("Debug: Filter = %d\n", resource->filter);
|
|
|
- printf("Debug: Wrap = %d\n", resource->wrap);
|
|
|
|
|
|
size_t size = resource->width * resource->height * Pixel::GetBytesPerPixel(resource->format);
|
|
|
|
|
|
- resource->data = new uint8_t[size];
|
|
|
+ resource->data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
|
|
|
|
|
|
stream->read(resource->data, size);
|
|
|
|
|
|
@@ -48,10 +40,12 @@ TextureResource* TextureResource::load(ResourceArchive* archive, ResourceId id)
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void TextureResource::unload(TextureResource* resource)
|
|
|
+void TextureResource::unload(Allocator& allocator, TextureResource* resource)
|
|
|
{
|
|
|
- // TODO
|
|
|
+ assert(resource != NULL);
|
|
|
+
|
|
|
+ allocator.deallocate(resource->data);
|
|
|
+ allocator.deallocate(resource);
|
|
|
}
|
|
|
-
|
|
|
-} // namespace crown
|
|
|
|
|
|
+} // namespace crown
|