TextureResource.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "TextureResource.h"
  2. #include "ResourceArchive.h"
  3. #include "Log.h"
  4. #include "FileStream.h"
  5. #include "Assert.h"
  6. #include "Allocator.h"
  7. #include "Device.h"
  8. #include "Renderer.h"
  9. namespace crown
  10. {
  11. //-----------------------------------------------------------------------------
  12. void* TextureResource::load(Allocator& allocator, ResourceArchive& archive, ResourceId id)
  13. {
  14. FileStream* stream = archive.open(id);
  15. ce_assert(stream != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
  16. TextureResource* resource = (TextureResource*)allocator.allocate(sizeof(TextureResource));
  17. stream->read(&resource->m_format, sizeof(PixelFormat));
  18. stream->read(&resource->m_width, sizeof(uint16_t));
  19. stream->read(&resource->m_height, sizeof(uint16_t));
  20. size_t size = resource->m_width * resource->m_height * Pixel::bytes_per_pixel(resource->m_format);
  21. resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
  22. stream->read(resource->m_data, size);
  23. archive.close(stream);
  24. return resource;
  25. }
  26. //-----------------------------------------------------------------------------
  27. void TextureResource::online(void* resource)
  28. {
  29. ce_assert(resource != NULL, "Resource not loaded");
  30. }
  31. //-----------------------------------------------------------------------------
  32. void TextureResource::unload(Allocator& allocator, void* resource)
  33. {
  34. ce_assert(resource != NULL, "Resource not loaded");
  35. allocator.deallocate(((TextureResource*)resource)->m_data);
  36. allocator.deallocate(resource);
  37. }
  38. //-----------------------------------------------------------------------------
  39. void TextureResource::offline()
  40. {
  41. }
  42. } // namespace crown