MaterialResource.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. namespace crown
  32. {
  33. /// Max texture layers supported by the material.
  34. /// @note The maximum number of usable layers depends on the graphic card/Renderer config.
  35. const uint32_t MAX_TEXTURE_LAYERS = 8;
  36. class Bundle;
  37. class Allocator;
  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. static void* load(Allocator& allocator, Bundle& bundle, ResourceId id);
  45. static void online(void* resource);
  46. static void unload(Allocator& allocator, void* texture);
  47. static void offline();
  48. private:
  49. Color4 m_ambient;
  50. Color4 m_diffuse;
  51. Color4 m_specular;
  52. Color4 m_emission;
  53. int32_t m_shininess;
  54. bool m_lighting : 1; // Lighting enabled
  55. bool m_texturing : 1; // Texturing enabled
  56. bool m_backface_culling : 1; // Backface-culling enabled
  57. bool m_separate_specular_color : 1; // Separate specular color enabled
  58. bool m_depth_test : 1; // Depth test enabled
  59. bool m_depth_write : 1; // Depth write enabled
  60. bool m_rescale_normals : 1; // Auto normal rescaling enabled
  61. bool m_blending : 1; // Blending enabled
  62. bool m_color_write : 1; // Writing into color buffer enabled
  63. bool m_fog : 1; // Fog enabled
  64. bool m_alpha_test : 1; // Alpha test enabled
  65. bool m_point_sprite : 1; // Point sprite enabled
  66. ShadingType m_shading_type;
  67. PolygonMode m_polygon_mode;
  68. FrontFace m_front_face;
  69. CompareFunction m_depth_func;
  70. FogMode m_fog_mode;
  71. float m_fog_density;
  72. float m_fog_start;
  73. float m_fog_end;
  74. Color4 m_fog_color;
  75. CompareFunction m_alpha_func;
  76. float m_alpha_ref;
  77. float m_point_size;
  78. float m_point_size_min;
  79. float m_point_size_max;
  80. BlendEquation m_blend_equation;
  81. BlendFunction m_blend_src;
  82. BlendFunction m_blend_dst;
  83. Color4 m_blend_color;
  84. // A material can contain up to MAX_TEXTURE_LAYERS texture layers.
  85. // However, the maximum number of texture layers actually usable is Renderer-dependent.
  86. ResourceId m_textures[MAX_TEXTURE_LAYERS];
  87. };
  88. } // namespace crown