IMaterialRenderer.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef IRR_I_MATERIAL_RENDERER_H_INCLUDED
  5. #define IRR_I_MATERIAL_RENDERER_H_INCLUDED
  6. #include "IReferenceCounted.h"
  7. #include "SMaterial.h"
  8. #include "S3DVertex.h"
  9. namespace irr
  10. {
  11. namespace video
  12. {
  13. class IVideoDriver;
  14. class IMaterialRendererServices;
  15. class IShaderConstantSetCallBack;
  16. //! Interface for material rendering.
  17. /** Can be used to extend the engine with new materials. Refer to
  18. IVideoDriver::addMaterialRenderer() for more information on how to extend the
  19. engine with new materials. */
  20. class IMaterialRenderer : public virtual IReferenceCounted
  21. {
  22. public:
  23. //! Called by the IVideoDriver implementation the let the renderer set its needed render states.
  24. /** This is called during the IVideoDriver::setMaterial() call.
  25. When overriding this, you can set some renderstates or for example a
  26. vertex or pixel shader if you like.
  27. \param material: The new material parameters to be set. The renderer
  28. may change the material flags in this material. For example if this
  29. material does not accept the zbuffer = true, it can set it to false.
  30. This is useful, because in the next lastMaterial will be just the
  31. material in this call.
  32. \param lastMaterial: The material parameters which have been set before
  33. this material.
  34. \param resetAllRenderstates: True if all renderstates should really be
  35. reset. This is usually true if the last rendering mode was not a usual
  36. 3d rendering mode, but for example a 2d rendering mode.
  37. You should reset really all renderstates if this is true, no matter if
  38. the lastMaterial had some similar settings. This is used because in
  39. most cases, some common renderstates are not changed if they are
  40. already there, for example bilinear filtering, wireframe,
  41. gouraudshading, lighting, zbuffer, zwriteenable, backfaceculling and
  42. fogenable.
  43. \param services: Interface providing some methods for changing
  44. advanced, internal states of a IVideoDriver. */
  45. virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
  46. bool resetAllRenderstates, IMaterialRendererServices* services) {}
  47. //! Called every time before a new bunch of geometry is being drawn using this material with for example drawIndexedTriangleList() call.
  48. /** OnSetMaterial should normally only be called if the renderer decides
  49. that the renderstates should be changed, it won't be called if for
  50. example two drawIndexedTriangleList() will be called with the same
  51. material set. This method will be called every time. This is useful for
  52. example for materials with shaders, which don't only set new
  53. renderstates but also shader constants.
  54. \param service: Pointer to interface providing methods for setting
  55. constants and other things.
  56. \param vtxtype: Vertex type with which the next rendering will be done.
  57. This can be used by the material renderer to set some specific
  58. optimized shaders or if this is an incompatible vertex type for this
  59. renderer, to refuse rendering for example.
  60. \return Returns true if everything is OK, and false if nothing should
  61. be rendered. The material renderer can choose to return false for
  62. example if he doesn't support the specified vertex type. This is
  63. actually done in D3D9 when using a normal mapped material with
  64. a vertex type other than EVT_TANGENTS. */
  65. virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) { return true; }
  66. //! Called by the IVideoDriver to unset this material.
  67. /** Called during the IVideoDriver::setMaterial() call before the new
  68. material will get the OnSetMaterial() call. */
  69. virtual void OnUnsetMaterial() {}
  70. //! Returns if the material is transparent.
  71. /** The scene management needs to know this
  72. for being able to sort the materials by opaque and transparent. */
  73. virtual bool isTransparent() const { return false; }
  74. //! Returns the render capability of the material.
  75. /** Because some more complex materials
  76. are implemented in multiple ways and need special hardware capabilities, it is possible
  77. to query how the current material renderer is performing on the current hardware with this
  78. function.
  79. \return Returns 0 if everything is running fine. Any other value is material renderer
  80. specific and means for example that the renderer switched back to a fall back material because
  81. it cannot use the latest shaders. More specific examples:
  82. Fixed function pipeline materials should return 0 in most cases, parallax mapped
  83. material will only return 0 when at least pixel shader 1.4 is available on that machine. */
  84. virtual s32 getRenderCapability() const { return 0; }
  85. //! Access the callback provided by the users when creating shader materials
  86. /** \returns Returns either the users provided callback or 0 when no such
  87. callback exists. Non-shader materials will always return 0. */
  88. virtual IShaderConstantSetCallBack* getShaderConstantSetCallBack() const { return 0; }
  89. };
  90. } // end namespace video
  91. } // end namespace irr
  92. #endif