OgreGenUtilites.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <Ogre.h>
  17. #include "Logger.h"
  18. #include "Vram.h"
  19. /**
  20. * Mesh data
  21. */
  22. struct MeshData{
  23. /**
  24. * Mesh name
  25. */
  26. Ogre::String name;
  27. /**
  28. * Width of the texture for the mesh.
  29. */
  30. int tex_width;
  31. /**
  32. * Height of the texture for the mesh.
  33. */
  34. int tex_height;
  35. };
  36. /**
  37. * Bits per pixel modes.
  38. */
  39. enum BPP{
  40. /**
  41. * 4 bites per pixel.
  42. */
  43. BPP_4 = 0,
  44. /**
  45. * 8 bits per pixel.
  46. */
  47. BPP_8 = 1,
  48. /**
  49. * No color data, always black.
  50. */
  51. BPP_BLACK = -1
  52. };
  53. /**
  54. * Texture data.
  55. */
  56. struct TexForGen{
  57. /**
  58. * Texture X coordinate.
  59. */
  60. u16 texture_x;
  61. /**
  62. * Texture Y coordinate.
  63. */
  64. u16 texture_y;
  65. /**
  66. * X coordinate of the texture palette.
  67. */
  68. u16 palette_y;
  69. /**
  70. * X coordinate of the texture palette.
  71. */
  72. u16 palette_x;
  73. /**
  74. * BPP mode of the texture colour.
  75. */
  76. BPP bpp;
  77. /**
  78. * @todo Understand and document.
  79. */
  80. int start_x;
  81. /**
  82. * @todo Understand and document.
  83. */
  84. int start_y;
  85. /**
  86. * Texture comparator.
  87. *
  88. * It compares texture coordinates, palette coordinates and colour BPP
  89. * modes.
  90. *
  91. * @param i[in] Texture to compare this one with
  92. * @return True if the texture coordinates, palette coordinates and colour
  93. * BPP modes of both textures are equal, false otherwise.
  94. */
  95. bool operator==(const TexForGen& i ) const{
  96. return
  97. i.texture_x == texture_x
  98. && i.texture_y == texture_y
  99. && i.palette_y == palette_y
  100. && i.palette_x == palette_x
  101. && i.bpp == bpp;
  102. }
  103. };
  104. typedef std::vector< TexForGen > VectorTexForGen;
  105. /**
  106. * Creates a texture from video memory and saves it to a file.
  107. *
  108. * @param vram[in] Memory block to load the texture from.
  109. * @param mesh_data[in] Information about the mesh the texture is assigned to.
  110. * @param texture_file_name[in] Path to the texture file to save.
  111. * @parm textures[in] @todo It's used to get some coordinates, but for what?
  112. */
  113. void CreateTexture(
  114. Vram* vram, const MeshData& mesh_data,
  115. const Ogre::String& texture_file_name, const VectorTexForGen& textures
  116. );
  117. /**
  118. * Creates a material from video memory and saves it to a file.
  119. *
  120. * @param vram[in] Memory block to load the material from.
  121. * @param texture_file_name[in] Path to the texture file to save.
  122. * @param texture_name[in] Name of the texture to assign to the material.
  123. * @param vertex_program[in] @todo Understand and document. Can be empty.
  124. * @param fragment_program[in] @todo Understand and document. Can be empty.
  125. */
  126. void CreateMaterial(
  127. const Ogre::String& material_name, const Ogre::String& material_file_name,
  128. const Ogre::String& texture_name, const Ogre::String& vertex_program,
  129. const Ogre::String& fragment_program
  130. );
  131. /**
  132. * Creates a material from video memory and adds it to the texture list.
  133. *
  134. * @param pixel_box[in] Texture image descriptor.
  135. * @param vram[in] Memory block to load the material from.
  136. * @param start_x[in] X coordinate for the texture.
  137. * @param start_y[in] Y coordinate for the texture.
  138. * @param clut_x[in] X coordinate for the texture CLUT.
  139. * @param clut_y[in] Y coordinate for the texture CLUT.
  140. * @param texture_x[in] X coordinate for the texture.
  141. * @param texture_y[in] Y coordinate for the texture.
  142. * @param bpp[in] BPP mode for the texture colour.
  143. * @param transparency[in] Indicates if the texture has transparencies.
  144. * @todo What's the difference between start_x/start_y and texture_x/texture_y?
  145. */
  146. void CreateTextureFromVram(
  147. const Ogre::PixelBox& pixel_box, Vram* vram, const int start_x, const int start_y,
  148. const int clut_x, const int clut_y, const int texture_x, const int texture_y,
  149. const BPP bpp, const bool transparency
  150. );
  151. /**
  152. * Adds a texture to the list.
  153. *
  154. * @param texture[in] Texture information/
  155. * @param data[in] Mesh information.
  156. * @param textures[in|out] The texture will be added to this list.
  157. * @param logger[in] Custom logger to print info about the process. It can be
  158. * NULL, but then nothing will be printed.
  159. */
  160. void AddTexture(
  161. TexForGen& texture, const MeshData& data, VectorTexForGen& textures, Logger* logger
  162. );
  163. /**
  164. * Adds or removes a transparency to a colour.
  165. *
  166. * @param colour[in|out] The colour to add or remove the transparency to.
  167. * @param transparency[in] True to add transparency, false to remove it.
  168. * @param stp @todo Understand and document.
  169. */
  170. void AddTransparency(u32& colour, const bool transparency, const bool stp);