IMaterialRendererServices.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_SERVICES_H_INCLUDED
  5. #define IRR_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. //! Return an index constant for the vertex shader based on a uniform variable name.
  20. virtual s32 getVertexShaderConstantID(const c8* name) = 0;
  21. //! Call when you set shader constants outside of IShaderConstantSetCallBack
  22. /** Only for high-level shader functions, aka those using an index instead of
  23. an register. Shader constants are attached to shader programs, so if you want
  24. to set them you have to make sure the correct shader program is in use.
  25. IShaderConstantSetCallBack functions like OnSetConstants do that for you,
  26. but if you want to set shader constants outside of those (usually for performance
  27. reasons) call startUseProgram() before doing so and stopUseProgram() afterwards.
  28. Note: Currently only necessary in OpenGL, but no real calling costs on other drivers.
  29. */
  30. virtual void startUseProgram() {}
  31. //! Call this when you are done setting shader constants outside of OnCreate or OnSetConstants
  32. virtual void stopUseProgram() {}
  33. //! Sets a value for a vertex shader uniform variable.
  34. /**\param index Index of the variable (as received from getVertexShaderConstantID)
  35. \param floats Pointer to array of floats
  36. \param count Amount of floats in array.
  37. \return True if successful.
  38. */
  39. virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count) = 0;
  40. //! Int interface for the above.
  41. virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count) = 0;
  42. //! Uint interface for the above.
  43. /* NOTE: UINT only works with GLSL, not supported for other shaders */
  44. virtual bool setVertexShaderConstant(s32 index, const u32* ints, int count) = 0;
  45. //! Sets a vertex shader constant (or "uniform" in more modern terms)
  46. /** Can be used if you created a shader using pixel/vertex shader
  47. assembler or ARB_fragment_program or ARB_vertex_program.
  48. \param data: Data to be set in the constants
  49. \param startRegister: First register to be set
  50. \param constantAmount: Amount of registers to be set. One register consists of 4 floats. */
  51. virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
  52. //! Return an index constant for the pixel shader for the given uniform variable name
  53. virtual s32 getPixelShaderConstantID(const c8* name) = 0;
  54. //! Sets a value for the given pixel shader uniform variable
  55. /** This can be used if you used a high level shader language like GLSL
  56. or HLSL to create a shader. See setVertexShaderConstant() for an
  57. example on how to use this.
  58. \param index Index of the variable (as received from getPixelShaderConstantID)
  59. \param floats Pointer to array of floats
  60. \param count Amount of floats in array.
  61. \return True if successful. */
  62. virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count) = 0;
  63. //! Int interface for the above.
  64. virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count) = 0;
  65. //! Uint interface for the above.
  66. /* NOTE: UINT only works with GLSL, not supported for other shaders */
  67. virtual bool setPixelShaderConstant(s32 index, const u32* ints, int count) = 0;
  68. //! Sets a pixel shader constant.
  69. /** Can be used if you created a shader using pixel/vertex shader
  70. assembler or ARB_fragment_program or ARB_vertex_program.
  71. \param data Data to be set in the constants
  72. \param startRegister First register to be set.
  73. \param constantAmount Amount of registers to be set. One register consists of 4 floats. */
  74. virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
  75. //! \deprecated. This method may be removed by Irrlicht 2.0
  76. /** This can be used if you use a high level shader language like GLSL
  77. or HLSL to create a shader. Example: If you created a shader which has
  78. variables named 'mWorldViewProj' (containing the WorldViewProjection
  79. matrix) and another one named 'fTime' containing one float, you can set
  80. them in your IShaderConstantSetCallBack derived class like this:
  81. \code
  82. virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
  83. {
  84. video::IVideoDriver* driver = services->getVideoDriver();
  85. f32 time = (f32)os::Timer::getTime()/100000.0f;
  86. services->setVertexShaderConstant("fTime", &time, 1);
  87. core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION));
  88. worldViewProj *= driver->getTransform(video::ETS_VIEW);
  89. worldViewProj *= driver->getTransform(video::ETS_WORLD);
  90. services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
  91. }
  92. \endcode
  93. **/
  94. IRR_DEPRECATED bool setVertexShaderConstant(const c8* name, const f32* floats, int count)
  95. {
  96. return setVertexShaderConstant(getVertexShaderConstantID(name), floats, count);
  97. }
  98. //! \deprecated. This method may be removed by Irrlicht 2.0
  99. IRR_DEPRECATED bool setVertexShaderConstant(const c8* name, const s32* ints, int count)
  100. {
  101. return setVertexShaderConstant(getVertexShaderConstantID(name), ints, count);
  102. }
  103. //! \deprecated. This method may be removed by Irrlicht 2.0
  104. IRR_DEPRECATED bool setPixelShaderConstant(const c8* name, const f32* floats, int count)
  105. {
  106. return setPixelShaderConstant(getPixelShaderConstantID(name), floats, count);
  107. }
  108. //! \deprecated. This method may be removed by Irrlicht 2.0
  109. IRR_DEPRECATED bool setPixelShaderConstant(const c8* name, const s32* ints, int count)
  110. {
  111. return setPixelShaderConstant(getPixelShaderConstantID(name), ints, count);
  112. }
  113. //! Get pointer to the IVideoDriver interface
  114. /** \return Pointer to the IVideoDriver interface */
  115. virtual IVideoDriver* getVideoDriver() = 0;
  116. };
  117. } // end namespace video
  118. } // end namespace irr
  119. #endif