TextureResource.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "Types.h"
  25. #include "Resource.h"
  26. #include "PixelFormat.h"
  27. #include "Texture.h"
  28. namespace crown
  29. {
  30. // Bump the version whenever a change in the header is made
  31. const uint32_t TEXTURE_VERSION = 1;
  32. struct TextureHeader
  33. {
  34. uint32_t version; // Texture file version
  35. uint32_t format; // Format of the pixels
  36. uint32_t width; // Width in pixels
  37. uint32_t height; // Height in pixels
  38. };
  39. class Bundle;
  40. class Allocator;
  41. class TextureResource
  42. {
  43. public:
  44. static void* load(Allocator& allocator, Bundle& bundle, ResourceId id);
  45. static void online(void* resource);
  46. static void unload(Allocator& allocator, void* resource);
  47. static void offline();
  48. public:
  49. PixelFormat format() const { return (PixelFormat) m_header.format; }
  50. uint32_t width() const { return m_header.width; }
  51. uint32_t height() const { return m_header.height; }
  52. const uint8_t* data() const { return m_data; }
  53. private:
  54. TextureHeader m_header;
  55. uint8_t* m_data;
  56. };
  57. } // namespace crown