IGPUProgrammingServices.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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 "EShaderTypes.h"
  6. #include "EMaterialTypes.h"
  7. #include "EPrimitiveTypes.h"
  8. #include "path.h"
  9. namespace irr
  10. {
  11. namespace io
  12. {
  13. class IReadFile;
  14. } // end namespace io
  15. namespace video
  16. {
  17. class IVideoDriver;
  18. class IShaderConstantSetCallBack;
  19. //! Interface making it possible to create and use programs running on the GPU.
  20. class IGPUProgrammingServices
  21. {
  22. public:
  23. //! Destructor
  24. virtual ~IGPUProgrammingServices() {}
  25. //! Adds a new high-level shading material renderer to the VideoDriver.
  26. /** Currently only HLSL/D3D9 and GLSL/OpenGL are supported.
  27. \param vertexShaderProgram String containing the source of the vertex
  28. shader program. This can be 0 if no vertex program shall be used.
  29. \param vertexShaderEntryPointName Name of the entry function of the
  30. vertexShaderProgram (p.e. "main")
  31. \param vsCompileTarget Vertex shader version the high level shader
  32. shall be compiled to.
  33. \param pixelShaderProgram String containing the source of the pixel
  34. shader program. This can be 0 if no pixel shader shall be used.
  35. \param pixelShaderEntryPointName Entry name of the function of the
  36. pixelShaderProgram (p.e. "main")
  37. \param psCompileTarget Pixel shader version the high level shader
  38. shall be compiled to.
  39. \param geometryShaderProgram String containing the source of the
  40. geometry shader program. This can be 0 if no geometry shader shall be
  41. used.
  42. \param geometryShaderEntryPointName Entry name of the function of the
  43. geometryShaderProgram (p.e. "main")
  44. \param gsCompileTarget Geometry shader version the high level shader
  45. shall be compiled to.
  46. \param inType Type of vertices passed to geometry shader
  47. \param outType Type of vertices created by geometry shader
  48. \param verticesOut Maximal number of vertices created by geometry
  49. shader. If 0, maximal number supported is assumed.
  50. \param callback Pointer to an implementation of
  51. IShaderConstantSetCallBack in which you can set the needed vertex,
  52. pixel, and geometry shader program constants. Set this to 0 if you
  53. don't need this.
  54. \param baseMaterial Base material which renderstates will be used to
  55. shade the material.
  56. \param userData a user data int. This int can be set to any value and
  57. will be set as parameter in the callback method when calling
  58. OnSetConstants(). In this way it is easily possible to use the same
  59. callback method for multiple materials and distinguish between them
  60. during the call.
  61. \return Number of the material type which can be set in
  62. SMaterial::MaterialType to use the renderer. -1 is returned if an error
  63. occurred, e.g. if a shader program could not be compiled or a compile
  64. target is not reachable. The error strings are then printed to the
  65. error log and can be caught with a custom event receiver. */
  66. virtual s32 addHighLevelShaderMaterial(
  67. const c8 *vertexShaderProgram,
  68. const c8 *vertexShaderEntryPointName,
  69. E_VERTEX_SHADER_TYPE vsCompileTarget,
  70. const c8 *pixelShaderProgram,
  71. const c8 *pixelShaderEntryPointName,
  72. E_PIXEL_SHADER_TYPE psCompileTarget,
  73. const c8 *geometryShaderProgram,
  74. const c8 *geometryShaderEntryPointName = "main",
  75. E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
  76. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  77. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  78. u32 verticesOut = 0,
  79. IShaderConstantSetCallBack *callback = 0,
  80. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  81. s32 userData = 0) = 0;
  82. //! convenience function for use without geometry shaders
  83. s32 addHighLevelShaderMaterial(
  84. const c8 *vertexShaderProgram,
  85. const c8 *vertexShaderEntryPointName = "main",
  86. E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,
  87. const c8 *pixelShaderProgram = 0,
  88. const c8 *pixelShaderEntryPointName = "main",
  89. E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,
  90. IShaderConstantSetCallBack *callback = 0,
  91. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  92. s32 userData = 0)
  93. {
  94. return addHighLevelShaderMaterial(
  95. vertexShaderProgram, vertexShaderEntryPointName,
  96. vsCompileTarget, pixelShaderProgram,
  97. pixelShaderEntryPointName, psCompileTarget,
  98. 0, "main", EGST_GS_4_0,
  99. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  100. callback, baseMaterial, userData);
  101. }
  102. //! convenience function for use with many defaults, without geometry shader
  103. /** All shader names are set to "main" and compile targets are shader
  104. type 1.1.
  105. */
  106. s32 addHighLevelShaderMaterial(
  107. const c8 *vertexShaderProgram,
  108. const c8 *pixelShaderProgram = 0,
  109. IShaderConstantSetCallBack *callback = 0,
  110. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  111. s32 userData = 0)
  112. {
  113. return addHighLevelShaderMaterial(
  114. vertexShaderProgram, "main",
  115. EVST_VS_1_1, pixelShaderProgram,
  116. "main", EPST_PS_1_1,
  117. 0, "main", EGST_GS_4_0,
  118. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  119. callback, baseMaterial, userData);
  120. }
  121. //! convenience function for use with many defaults, with geometry shader
  122. /** All shader names are set to "main" and compile targets are shader
  123. type 1.1 and geometry shader 4.0.
  124. */
  125. s32 addHighLevelShaderMaterial(
  126. const c8 *vertexShaderProgram,
  127. const c8 *pixelShaderProgram = 0,
  128. const c8 *geometryShaderProgram = 0,
  129. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  130. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  131. u32 verticesOut = 0,
  132. IShaderConstantSetCallBack *callback = 0,
  133. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  134. s32 userData = 0)
  135. {
  136. return addHighLevelShaderMaterial(
  137. vertexShaderProgram, "main",
  138. EVST_VS_1_1, pixelShaderProgram,
  139. "main", EPST_PS_1_1,
  140. geometryShaderProgram, "main", EGST_GS_4_0,
  141. inType, outType, verticesOut,
  142. callback, baseMaterial, userData);
  143. }
  144. //! Like addHighLevelShaderMaterial(), but loads from files.
  145. /** \param vertexShaderProgramFileName Text file containing the source
  146. of the vertex shader program. Set to empty string if no vertex shader
  147. shall be created.
  148. \param vertexShaderEntryPointName Name of the entry function of the
  149. vertexShaderProgram (p.e. "main")
  150. \param vsCompileTarget Vertex shader version the high level shader
  151. shall be compiled to.
  152. \param pixelShaderProgramFileName Text file containing the source of
  153. the pixel shader program. Set to empty string if no pixel shader shall
  154. be created.
  155. \param pixelShaderEntryPointName Entry name of the function of the
  156. pixelShaderProgram (p.e. "main")
  157. \param psCompileTarget Pixel shader version the high level shader
  158. shall be compiled to.
  159. \param geometryShaderProgramFileName Name of the source of
  160. the geometry shader program. Set to empty string if no geometry shader
  161. shall be created.
  162. \param geometryShaderEntryPointName Entry name of the function of the
  163. geometryShaderProgram (p.e. "main")
  164. \param gsCompileTarget Geometry shader version the high level shader
  165. shall be compiled to.
  166. \param inType Type of vertices passed to geometry shader
  167. \param outType Type of vertices created by geometry shader
  168. \param verticesOut Maximal number of vertices created by geometry
  169. shader. If 0, maximal number supported is assumed.
  170. \param callback Pointer to an implementation of
  171. IShaderConstantSetCallBack in which you can set the needed vertex,
  172. pixel, and geometry shader program constants. Set this to 0 if you
  173. don't need this.
  174. \param baseMaterial Base material which renderstates will be used to
  175. shade the material.
  176. \param userData a user data int. This int can be set to any value and
  177. will be set as parameter in the callback method when calling
  178. OnSetConstants(). In this way it is easily possible to use the same
  179. callback method for multiple materials and distinguish between them
  180. during the call.
  181. \return Number of the material type which can be set in
  182. SMaterial::MaterialType to use the renderer. -1 is returned if an error
  183. occurred, e.g. if a shader program could not be compiled or a compile
  184. target is not reachable. The error strings are then printed to the
  185. error log and can be caught with a custom event receiver. */
  186. virtual s32 addHighLevelShaderMaterialFromFiles(
  187. const io::path &vertexShaderProgramFileName,
  188. const c8 *vertexShaderEntryPointName,
  189. E_VERTEX_SHADER_TYPE vsCompileTarget,
  190. const io::path &pixelShaderProgramFileName,
  191. const c8 *pixelShaderEntryPointName,
  192. E_PIXEL_SHADER_TYPE psCompileTarget,
  193. const io::path &geometryShaderProgramFileName,
  194. const c8 *geometryShaderEntryPointName = "main",
  195. E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
  196. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  197. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  198. u32 verticesOut = 0,
  199. IShaderConstantSetCallBack *callback = 0,
  200. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  201. s32 userData = 0) = 0;
  202. //! convenience function for use without geometry shaders
  203. s32 addHighLevelShaderMaterialFromFiles(
  204. const io::path &vertexShaderProgramFileName,
  205. const c8 *vertexShaderEntryPointName = "main",
  206. E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,
  207. const io::path &pixelShaderProgramFileName = "",
  208. const c8 *pixelShaderEntryPointName = "main",
  209. E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,
  210. IShaderConstantSetCallBack *callback = 0,
  211. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  212. s32 userData = 0)
  213. {
  214. return addHighLevelShaderMaterialFromFiles(
  215. vertexShaderProgramFileName, vertexShaderEntryPointName,
  216. vsCompileTarget, pixelShaderProgramFileName,
  217. pixelShaderEntryPointName, psCompileTarget,
  218. "", "main", EGST_GS_4_0,
  219. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  220. callback, baseMaterial, userData);
  221. }
  222. //! convenience function for use with many defaults, without geometry shader
  223. /** All shader names are set to "main" and compile targets are shader
  224. type 1.1.
  225. */
  226. s32 addHighLevelShaderMaterialFromFiles(
  227. const io::path &vertexShaderProgramFileName,
  228. const io::path &pixelShaderProgramFileName = "",
  229. IShaderConstantSetCallBack *callback = 0,
  230. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  231. s32 userData = 0)
  232. {
  233. return addHighLevelShaderMaterialFromFiles(
  234. vertexShaderProgramFileName, "main",
  235. EVST_VS_1_1, pixelShaderProgramFileName,
  236. "main", EPST_PS_1_1,
  237. "", "main", EGST_GS_4_0,
  238. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  239. callback, baseMaterial, userData);
  240. }
  241. //! convenience function for use with many defaults, with geometry shader
  242. /** All shader names are set to "main" and compile targets are shader
  243. type 1.1 and geometry shader 4.0.
  244. */
  245. s32 addHighLevelShaderMaterialFromFiles(
  246. const io::path &vertexShaderProgramFileName,
  247. const io::path &pixelShaderProgramFileName = "",
  248. const io::path &geometryShaderProgramFileName = "",
  249. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  250. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  251. u32 verticesOut = 0,
  252. IShaderConstantSetCallBack *callback = 0,
  253. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  254. s32 userData = 0)
  255. {
  256. return addHighLevelShaderMaterialFromFiles(
  257. vertexShaderProgramFileName, "main",
  258. EVST_VS_1_1, pixelShaderProgramFileName,
  259. "main", EPST_PS_1_1,
  260. geometryShaderProgramFileName, "main", EGST_GS_4_0,
  261. inType, outType, verticesOut,
  262. callback, baseMaterial, userData);
  263. }
  264. //! Like addHighLevelShaderMaterial(), but loads from files.
  265. /** \param vertexShaderProgram Text file handle containing the source
  266. of the vertex shader program. Set to 0 if no vertex shader shall be
  267. created.
  268. \param vertexShaderEntryPointName Name of the entry function of the
  269. vertexShaderProgram
  270. \param vsCompileTarget Vertex shader version the high level shader
  271. shall be compiled to.
  272. \param pixelShaderProgram Text file handle containing the source of
  273. the pixel shader program. Set to 0 if no pixel shader shall be created.
  274. \param pixelShaderEntryPointName Entry name of the function of the
  275. pixelShaderProgram (p.e. "main")
  276. \param psCompileTarget Pixel shader version the high level shader
  277. shall be compiled to.
  278. \param geometryShaderProgram Text file handle containing the source of
  279. the geometry shader program. Set to 0 if no geometry shader shall be
  280. created.
  281. \param geometryShaderEntryPointName Entry name of the function of the
  282. geometryShaderProgram (p.e. "main")
  283. \param gsCompileTarget Geometry shader version the high level shader
  284. shall be compiled to.
  285. \param inType Type of vertices passed to geometry shader
  286. \param outType Type of vertices created by geometry shader
  287. \param verticesOut Maximal number of vertices created by geometry
  288. shader. If 0, maximal number supported is assumed.
  289. \param callback Pointer to an implementation of
  290. IShaderConstantSetCallBack in which you can set the needed vertex and
  291. pixel shader program constants. Set this to 0 if you don't need this.
  292. \param baseMaterial Base material which renderstates will be used to
  293. shade the material.
  294. \param userData a user data int. This int can be set to any value and
  295. will be set as parameter in the callback method when calling
  296. OnSetConstants(). In this way it is easily possible to use the same
  297. callback method for multiple materials and distinguish between them
  298. during the call.
  299. \return Number of the material type which can be set in
  300. SMaterial::MaterialType to use the renderer. -1 is returned if an
  301. error occurred, e.g. if a shader program could not be compiled or a
  302. compile target is not reachable. The error strings are then printed to
  303. the error log and can be caught with a custom event receiver. */
  304. virtual s32 addHighLevelShaderMaterialFromFiles(
  305. io::IReadFile *vertexShaderProgram,
  306. const c8 *vertexShaderEntryPointName,
  307. E_VERTEX_SHADER_TYPE vsCompileTarget,
  308. io::IReadFile *pixelShaderProgram,
  309. const c8 *pixelShaderEntryPointName,
  310. E_PIXEL_SHADER_TYPE psCompileTarget,
  311. io::IReadFile *geometryShaderProgram,
  312. const c8 *geometryShaderEntryPointName = "main",
  313. E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
  314. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  315. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  316. u32 verticesOut = 0,
  317. IShaderConstantSetCallBack *callback = 0,
  318. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  319. s32 userData = 0) = 0;
  320. //! convenience function for use without geometry shaders
  321. s32 addHighLevelShaderMaterialFromFiles(
  322. io::IReadFile *vertexShaderProgram,
  323. const c8 *vertexShaderEntryPointName = "main",
  324. E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,
  325. io::IReadFile *pixelShaderProgram = 0,
  326. const c8 *pixelShaderEntryPointName = "main",
  327. E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,
  328. IShaderConstantSetCallBack *callback = 0,
  329. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  330. s32 userData = 0)
  331. {
  332. return addHighLevelShaderMaterialFromFiles(
  333. vertexShaderProgram, vertexShaderEntryPointName,
  334. vsCompileTarget, pixelShaderProgram,
  335. pixelShaderEntryPointName, psCompileTarget,
  336. 0, "main", EGST_GS_4_0,
  337. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  338. callback, baseMaterial, userData);
  339. }
  340. //! Delete a shader material and associated data.
  341. /**
  342. After you have deleted a material it is invalid to still use and doing
  343. so might result in a crash. The ID may be reused in the future when new
  344. materials are added.
  345. \param material Number of the material type. Must not be a built-in
  346. material. */
  347. virtual void deleteShaderMaterial(s32 material) = 0;
  348. };
  349. } // end namespace video
  350. } // end namespace irr