MaterialResource.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 "TextureResource.h"
  26. #include "Resource.h"
  27. #include "Vec3.h"
  28. #include "Color4.h"
  29. #include "Material.h"
  30. #include "Texture.h"
  31. #include "Bundle.h"
  32. #include "Allocator.h"
  33. namespace crown
  34. {
  35. /// Max texture layers supported by the material.
  36. /// @note The maximum number of usable layers depends on the graphic card/Renderer config.
  37. const uint32_t MAX_TEXTURE_LAYERS = 8;
  38. /// A material describes the visual properties of a surface.
  39. /// It is primarly intended for rendering purposes but can
  40. /// also be used to drive other types of systems such as sounds or physics.
  41. class MaterialResource
  42. {
  43. public:
  44. //-----------------------------------------------------------------------------
  45. static void* load(Allocator& /*allocator*/, Bundle& /*bundle*/, ResourceId /*id*/)
  46. {
  47. return NULL;
  48. }
  49. //-----------------------------------------------------------------------------
  50. static void online(void* material)
  51. {
  52. (void)material;
  53. // TODO
  54. }
  55. //-----------------------------------------------------------------------------
  56. static void unload(Allocator& /*allocator*/, void* /*material*/)
  57. {
  58. // TODO
  59. }
  60. //-----------------------------------------------------------------------------
  61. static void offline(void* /*resource*/)
  62. {
  63. // TODO
  64. }
  65. private:
  66. Color4 m_ambient;
  67. Color4 m_diffuse;
  68. Color4 m_specular;
  69. Color4 m_emission;
  70. int32_t m_shininess;
  71. bool m_lighting : 1; // Lighting enabled
  72. bool m_texturing : 1; // Texturing enabled
  73. bool m_backface_culling : 1; // Backface-culling enabled
  74. bool m_separate_specular_color : 1; // Separate specular color enabled
  75. bool m_depth_test : 1; // Depth test enabled
  76. bool m_depth_write : 1; // Depth write enabled
  77. bool m_rescale_normals : 1; // Auto normal rescaling enabled
  78. bool m_blending : 1; // Blending enabled
  79. bool m_color_write : 1; // Writing into color buffer enabled
  80. bool m_fog : 1; // Fog enabled
  81. bool m_alpha_test : 1; // Alpha test enabled
  82. bool m_point_sprite : 1; // Point sprite enabled
  83. ShadingType m_shading_type;
  84. PolygonMode m_polygon_mode;
  85. FrontFace m_front_face;
  86. CompareFunction m_depth_func;
  87. FogMode m_fog_mode;
  88. float m_fog_density;
  89. float m_fog_start;
  90. float m_fog_end;
  91. Color4 m_fog_color;
  92. CompareFunction m_alpha_func;
  93. float m_alpha_ref;
  94. float m_point_size;
  95. float m_point_size_min;
  96. float m_point_size_max;
  97. BlendEquation m_blend_equation;
  98. BlendFunction m_blend_src;
  99. BlendFunction m_blend_dst;
  100. Color4 m_blend_color;
  101. // A material can contain up to MAX_TEXTURE_LAYERS texture layers.
  102. // However, the maximum number of texture layers actually usable is Renderer-dependent.
  103. ResourceId m_textures[MAX_TEXTURE_LAYERS];
  104. };
  105. } // namespace crown