2
0

IMaterialRenderer.h 4.9 KB

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