IMaterialRendererServices.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 __I_MATERIAL_RENDERER_SERVICES_H_INCLUDED__
  5. #define __I_MATERIAL_RENDERER_SERVICES_H_INCLUDED__
  6. #include "SMaterial.h"
  7. #include "S3DVertex.h"
  8. namespace irr
  9. {
  10. namespace video
  11. {
  12. class IVideoDriver;
  13. //! Interface providing some methods for changing advanced, internal states of a IVideoDriver.
  14. class IMaterialRendererServices
  15. {
  16. public:
  17. //! Destructor
  18. virtual ~IMaterialRendererServices() {}
  19. //! Can be called by an IMaterialRenderer to make its work easier.
  20. /** Sets all basic renderstates if needed.
  21. Basic render states are diffuse, ambient, specular, and emissive color,
  22. specular power, bilinear and trilinear filtering, wireframe mode,
  23. grouraudshading, lighting, zbuffer, zwriteenable, backfaceculling and
  24. fog enabling.
  25. \param material The new material to be used.
  26. \param lastMaterial The material used until now.
  27. \param resetAllRenderstates Set to true if all renderstates should be
  28. set, regardless of their current state. */
  29. virtual void setBasicRenderStates(const SMaterial& material,
  30. const SMaterial& lastMaterial,
  31. bool resetAllRenderstates) = 0;
  32. //! Sets a constant for the vertex shader based on a name.
  33. /** This can be used if you used a high level shader language like GLSL
  34. or HLSL to create a shader. Example: If you created a shader which has
  35. variables named 'mWorldViewProj' (containing the WorldViewProjection
  36. matrix) and another one named 'fTime' containing one float, you can set
  37. them in your IShaderConstantSetCallBack derived class like this:
  38. \code
  39. virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
  40. {
  41. video::IVideoDriver* driver = services->getVideoDriver();
  42. f32 time = (f32)os::Timer::getTime()/100000.0f;
  43. services->setVertexShaderConstant("fTime", &time, 1);
  44. core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION));
  45. worldViewProj *= driver->getTransform(video::ETS_VIEW);
  46. worldViewProj *= driver->getTransform(video::ETS_WORLD);
  47. services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
  48. }
  49. \endcode
  50. \param name Name of the variable
  51. \param floats Pointer to array of floats
  52. \param count Amount of floats in array.
  53. \return True if successful.
  54. */
  55. virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count) = 0;
  56. //! Bool interface for the above.
  57. virtual bool setVertexShaderConstant(const c8* name, const bool* bools, int count) = 0;
  58. //! Int interface for the above.
  59. virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count) = 0;
  60. //! Sets a vertex shader constant.
  61. /** Can be used if you created a shader using pixel/vertex shader
  62. assembler or ARB_fragment_program or ARB_vertex_program.
  63. \param data: Data to be set in the constants
  64. \param startRegister: First register to be set
  65. \param constantAmount: Amount of registers to be set. One register consists of 4 floats. */
  66. virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
  67. //! Sets a constant for the pixel shader based on a name.
  68. /** This can be used if you used a high level shader language like GLSL
  69. or HLSL to create a shader. See setVertexShaderConstant() for an
  70. example on how to use this.
  71. \param name Name of the variable
  72. \param floats Pointer to array of floats
  73. \param count Amount of floats in array.
  74. \return True if successful. */
  75. virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count) = 0;
  76. //! Bool interface for the above.
  77. virtual bool setPixelShaderConstant(const c8* name, const bool* bools, int count) = 0;
  78. //! Int interface for the above.
  79. virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count) = 0;
  80. //! Sets a pixel shader constant.
  81. /** Can be used if you created a shader using pixel/vertex shader
  82. assembler or ARB_fragment_program or ARB_vertex_program.
  83. \param data Data to be set in the constants
  84. \param startRegister First register to be set.
  85. \param constantAmount Amount of registers to be set. One register consists of 4 floats. */
  86. virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
  87. //! Get pointer to the IVideoDriver interface
  88. /** \return Pointer to the IVideoDriver interface */
  89. virtual IVideoDriver* getVideoDriver() = 0;
  90. };
  91. } // end namespace video
  92. } // end namespace irr
  93. #endif