sprite_resource.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "allocator.h"
  25. #include "bundle.h"
  26. #include "container_types.h"
  27. #include "device.h"
  28. #include "file.h"
  29. #include "os.h"
  30. #include "reader_writer.h"
  31. #include "resource_manager.h"
  32. #include "string_utils.h"
  33. #include "types.h"
  34. #include <cstring>
  35. #include <inttypes.h>
  36. #include <bgfx.h>
  37. namespace crown
  38. {
  39. const uint32_t SPRITE_VERSION = 1;
  40. struct SpriteHeader
  41. {
  42. uint32_t version;
  43. };
  44. // header
  45. // num_verts
  46. // verts[num_verts]
  47. // num_inds
  48. // inds[num_inds]
  49. struct SpriteResource
  50. {
  51. const bgfx::Memory* vbmem;
  52. const bgfx::Memory* ibmem;
  53. bgfx::VertexBufferHandle vb;
  54. bgfx::IndexBufferHandle ib;
  55. };
  56. //-----------------------------------------------------------------------------
  57. namespace sprite_resource
  58. {
  59. void compile(crown::Filesystem&, char const*, crown::File*);
  60. void* load(Allocator& allocator, Bundle& bundle, ResourceId id);
  61. void online(StringId64 id, ResourceManager& rm);
  62. void offline(StringId64 id, ResourceManager& rm);
  63. void unload(Allocator& a, void* resource);
  64. } // namespace sprite_resource
  65. struct SpriteAnimationResource
  66. {
  67. uint32_t version;
  68. uint32_t num_animations;
  69. uint32_t num_frames;
  70. uint32_t frames_offset;
  71. };
  72. struct SpriteAnimationName
  73. {
  74. StringId32 id;
  75. };
  76. struct SpriteAnimationData
  77. {
  78. uint32_t num_frames;
  79. uint32_t first_frame;
  80. float time;
  81. };
  82. namespace sprite_animation_resource
  83. {
  84. void compile(crown::Filesystem&, char const*, crown::File*);
  85. void* load(Allocator& allocator, Bundle& bundle, ResourceId id);
  86. void online(StringId64 id, ResourceManager& rm);
  87. void offline(StringId64 id, ResourceManager& rm);
  88. void unload(Allocator& a, void* resource);
  89. const SpriteAnimationData* get_animation(const SpriteAnimationResource* sar, StringId32 name);
  90. const uint32_t* get_animation_frames(const SpriteAnimationResource* sar);
  91. }
  92. } // namespace crown