IGPUProgrammingServices.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "EMaterialTypes.h"
  6. #include "EPrimitiveTypes.h"
  7. #include "path.h"
  8. namespace irr
  9. {
  10. namespace io
  11. {
  12. class IReadFile;
  13. } // end namespace io
  14. namespace video
  15. {
  16. class IVideoDriver;
  17. class IShaderConstantSetCallBack;
  18. //! Interface making it possible to create and use programs running on the GPU.
  19. class IGPUProgrammingServices
  20. {
  21. public:
  22. //! Destructor
  23. virtual ~IGPUProgrammingServices() {}
  24. //! Adds a new high-level shading material renderer to the VideoDriver.
  25. /**
  26. \param vertexShaderProgram String containing the source of the vertex
  27. shader program. This can be 0 if no vertex program shall be used.
  28. \param pixelShaderProgram String containing the source of the pixel
  29. shader program. This can be 0 if no pixel shader shall be used.
  30. \param geometryShaderProgram String containing the source of the
  31. geometry shader program. This can be 0 if no geometry shader shall be
  32. used.
  33. \param shaderName Name of the shader for debug purposes
  34. \param inType Type of vertices passed to geometry shader
  35. \param outType Type of vertices created by geometry shader
  36. \param verticesOut Maximal number of vertices created by geometry
  37. shader. If 0, maximal number supported is assumed.
  38. \param callback Pointer to an implementation of
  39. IShaderConstantSetCallBack in which you can set the needed vertex,
  40. pixel, and geometry shader program constants. Set this to 0 if you
  41. don't need this.
  42. \param baseMaterial Base material which renderstates will be used to
  43. shade the material.
  44. \param userData a user data int. This int can be set to any value and
  45. will be set as parameter in the callback method when calling
  46. OnSetConstants(). In this way it is easily possible to use the same
  47. callback method for multiple materials and distinguish between them
  48. during the call.
  49. \return Number of the material type which can be set in
  50. SMaterial::MaterialType to use the renderer. -1 is returned if an error
  51. occurred, e.g. if a shader program could not be compiled or a compile
  52. target is not reachable. The error strings are then printed to the
  53. error log and can be caught with a custom event receiver. */
  54. virtual s32 addHighLevelShaderMaterial(
  55. const c8 *vertexShaderProgram,
  56. const c8 *pixelShaderProgram,
  57. const c8 *geometryShaderProgram,
  58. const c8 *shaderName = nullptr,
  59. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  60. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  61. u32 verticesOut = 0,
  62. IShaderConstantSetCallBack *callback = nullptr,
  63. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  64. s32 userData = 0) = 0;
  65. //! convenience function for use without geometry shaders
  66. s32 addHighLevelShaderMaterial(
  67. const c8 *vertexShaderProgram,
  68. const c8 *pixelShaderProgram = nullptr,
  69. const c8 *shaderName = nullptr,
  70. IShaderConstantSetCallBack *callback = nullptr,
  71. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  72. s32 userData = 0)
  73. {
  74. return addHighLevelShaderMaterial(
  75. vertexShaderProgram, pixelShaderProgram,
  76. nullptr, shaderName,
  77. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  78. callback, baseMaterial, userData);
  79. }
  80. //! Like addHighLevelShaderMaterial(), but loads from files.
  81. /** \param vertexShaderProgramFileName Text file containing the source
  82. of the vertex shader program. Set to empty string if no vertex shader
  83. shall be created.
  84. \param pixelShaderProgramFileName Text file containing the source of
  85. the pixel shader program. Set to empty string if no pixel shader shall
  86. be created.
  87. \param geometryShaderProgramFileName Name of the source of
  88. the geometry shader program. Set to empty string if no geometry shader
  89. shall be created.
  90. \param shaderName Name of the shader for debug purposes
  91. \param inType Type of vertices passed to geometry shader
  92. \param outType Type of vertices created by geometry shader
  93. \param verticesOut Maximal number of vertices created by geometry
  94. shader. If 0, maximal number supported is assumed.
  95. \param callback Pointer to an implementation of
  96. IShaderConstantSetCallBack in which you can set the needed vertex,
  97. pixel, and geometry shader program constants. Set this to 0 if you
  98. don't need this.
  99. \param baseMaterial Base material which renderstates will be used to
  100. shade the material.
  101. \param userData a user data int. This int can be set to any value and
  102. will be set as parameter in the callback method when calling
  103. OnSetConstants(). In this way it is easily possible to use the same
  104. callback method for multiple materials and distinguish between them
  105. during the call.
  106. \return Number of the material type which can be set in
  107. SMaterial::MaterialType to use the renderer. -1 is returned if an error
  108. occurred, e.g. if a shader program could not be compiled or a compile
  109. target is not reachable. The error strings are then printed to the
  110. error log and can be caught with a custom event receiver. */
  111. virtual s32 addHighLevelShaderMaterialFromFiles(
  112. const io::path &vertexShaderProgramFileName,
  113. const io::path &pixelShaderProgramFileName,
  114. const io::path &geometryShaderProgramFileName,
  115. const c8 *shaderName = nullptr,
  116. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  117. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  118. u32 verticesOut = 0,
  119. IShaderConstantSetCallBack *callback = nullptr,
  120. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  121. s32 userData = 0) = 0;
  122. //! Delete a shader material and associated data.
  123. /**
  124. After you have deleted a material it is invalid to still use and doing
  125. so might result in a crash. The ID may be reused in the future when new
  126. materials are added.
  127. \param material Number of the material type. Must not be a built-in
  128. material. */
  129. virtual void deleteShaderMaterial(s32 material) = 0;
  130. };
  131. } // end namespace video
  132. } // end namespace irr