Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

Surface.cpp 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "resource/Surface.h"
  19. #include "resource/ImgColor.h"
  20. #include "resource/ImgTex.h"
  21. #include "BinReader.h"
  22. #include "Core.h"
  23. #include "ResourceCache.h"
  24. enum SurfaceType
  25. {
  26. kBase1Solid = 0x00000001,
  27. kBase1Image = 0x00000002,
  28. kBase1Clipmap = 0x00000004,
  29. kTranslucent = 0x00000010,
  30. kDiffuse = 0x00000020,
  31. kLuminous = 0x00000040,
  32. kAlpha = 0x00000100,
  33. kInvAlpha = 0x00000200,
  34. kAdditive = 0x00010000,
  35. kDetail = 0x00020000,
  36. kGouraud = 0x10000000,
  37. kStippled = 0x40000000,
  38. kPerspective = 0x80000000
  39. };
  40. Surface::Surface(uint32_t id, const void* data, size_t size) : ResourceImpl{id}
  41. {
  42. BinReader reader(data, size);
  43. uint32_t flags = reader.readInt();
  44. if(flags & kBase1Solid)
  45. {
  46. uint32_t bgra = reader.readInt();
  47. ResourcePtr imgColor{new ImgColor{bgra}};
  48. imgTex.reset(new ImgTex{imgColor});
  49. }
  50. else if(flags & (kBase1Image | kBase1Clipmap))
  51. {
  52. uint32_t textureId = reader.readInt();
  53. imgTex = Core::get().resourceCache().get(textureId);
  54. assert(imgTex->resourceType() == ResourceType::kImgTex);
  55. uint32_t paletteId = reader.readInt();
  56. assert(paletteId == 0);
  57. UNUSED(paletteId);
  58. }
  59. else
  60. {
  61. assert(false);
  62. }
  63. translucency = reader.readFloat();
  64. luminosity = reader.readFloat();
  65. diffuse = reader.readFloat();
  66. assert(reader.remaining() == 0);
  67. }
  68. Surface::Surface(ResourcePtr imgTex) : ResourceImpl{static_cast<uint32_t>(ResourceType::kSurface) | 0xFFFF}, imgTex{imgTex}
  69. {
  70. assert(imgTex->resourceType() == ResourceType::kImgTex);
  71. }