TextureResource.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "TextureResource.h"
  2. #include "ResourceArchive.h"
  3. #include "Log.h"
  4. #include "FileStream.h"
  5. #include <cassert>
  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. if (stream != NULL)
  16. {
  17. TextureResource* resource = (TextureResource*)allocator.allocate(sizeof(TextureResource));
  18. stream->read(&resource->m_format, sizeof(PixelFormat));
  19. stream->read(&resource->m_width, sizeof(uint16_t));
  20. stream->read(&resource->m_height, sizeof(uint16_t));
  21. size_t size = resource->m_width * resource->m_height * Pixel::bytes_per_pixel(resource->m_format);
  22. resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
  23. stream->read(resource->m_data, size);
  24. archive.close(stream);
  25. return resource;
  26. }
  27. return NULL;
  28. }
  29. //-----------------------------------------------------------------------------
  30. void TextureResource::online(void* resource)
  31. {
  32. assert(resource != NULL);
  33. }
  34. //-----------------------------------------------------------------------------
  35. void TextureResource::unload(Allocator& allocator, void* resource)
  36. {
  37. assert(resource != NULL);
  38. allocator.deallocate(((TextureResource*)resource)->m_data);
  39. allocator.deallocate(resource);
  40. }
  41. //-----------------------------------------------------------------------------
  42. void TextureResource::offline()
  43. {
  44. }
  45. } // namespace crown