IGPUProgrammingServices.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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_GPU_PROGRAMMING_SERVICES_H_INCLUDED
  5. #define IRR_I_GPU_PROGRAMMING_SERVICES_H_INCLUDED
  6. #include "EShaderTypes.h"
  7. #include "EMaterialTypes.h"
  8. #include "EPrimitiveTypes.h"
  9. #include "path.h"
  10. namespace irr
  11. {
  12. namespace io
  13. {
  14. class IReadFile;
  15. } // end namespace io
  16. namespace video
  17. {
  18. class IVideoDriver;
  19. class IShaderConstantSetCallBack;
  20. //! Interface making it possible to create and use programs running on the GPU.
  21. class IGPUProgrammingServices
  22. {
  23. public:
  24. //! Destructor
  25. virtual ~IGPUProgrammingServices() {}
  26. //! Adds a new high-level shading material renderer to the VideoDriver.
  27. /** Currently only HLSL/D3D9 and GLSL/OpenGL are supported.
  28. \param vertexShaderProgram String containing the source of the vertex
  29. shader program. This can be 0 if no vertex program shall be used.
  30. \param vertexShaderEntryPointName Name of the entry function of the
  31. vertexShaderProgram (p.e. "main")
  32. \param vsCompileTarget Vertex shader version the high level shader
  33. shall be compiled to.
  34. \param pixelShaderProgram String containing the source of the pixel
  35. shader program. This can be 0 if no pixel shader shall be used.
  36. \param pixelShaderEntryPointName Entry name of the function of the
  37. pixelShaderProgram (p.e. "main")
  38. \param psCompileTarget Pixel shader version the high level shader
  39. shall be compiled to.
  40. \param geometryShaderProgram String containing the source of the
  41. geometry shader program. This can be 0 if no geometry shader shall be
  42. used.
  43. \param geometryShaderEntryPointName Entry name of the function of the
  44. geometryShaderProgram (p.e. "main")
  45. \param gsCompileTarget Geometry shader version the high level shader
  46. shall be compiled to.
  47. \param inType Type of vertices passed to geometry shader
  48. \param outType Type of vertices created by geometry shader
  49. \param verticesOut Maximal number of vertices created by geometry
  50. shader. If 0, maximal number supported is assumed.
  51. \param callback Pointer to an implementation of
  52. IShaderConstantSetCallBack in which you can set the needed vertex,
  53. pixel, and geometry shader program constants. Set this to 0 if you
  54. don't need this.
  55. \param baseMaterial Base material which renderstates will be used to
  56. shade the material.
  57. \param userData a user data int. This int can be set to any value and
  58. will be set as parameter in the callback method when calling
  59. OnSetConstants(). In this way it is easily possible to use the same
  60. callback method for multiple materials and distinguish between them
  61. during the call.
  62. \return Number of the material type which can be set in
  63. SMaterial::MaterialType to use the renderer. -1 is returned if an error
  64. occurred, e.g. if a shader program could not be compiled or a compile
  65. target is not reachable. The error strings are then printed to the
  66. error log and can be caught with a custom event receiver. */
  67. virtual s32 addHighLevelShaderMaterial(
  68. const c8* vertexShaderProgram,
  69. const c8* vertexShaderEntryPointName,
  70. E_VERTEX_SHADER_TYPE vsCompileTarget,
  71. const c8* pixelShaderProgram,
  72. const c8* pixelShaderEntryPointName,
  73. E_PIXEL_SHADER_TYPE psCompileTarget,
  74. const c8* geometryShaderProgram,
  75. const c8* geometryShaderEntryPointName = "main",
  76. E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
  77. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  78. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  79. u32 verticesOut = 0,
  80. IShaderConstantSetCallBack* callback = 0,
  81. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  82. s32 userData = 0) = 0;
  83. //! convenience function for use without geometry shaders
  84. s32 addHighLevelShaderMaterial(
  85. const c8* vertexShaderProgram,
  86. const c8* vertexShaderEntryPointName="main",
  87. E_VERTEX_SHADER_TYPE vsCompileTarget=EVST_VS_1_1,
  88. const c8* pixelShaderProgram=0,
  89. const c8* pixelShaderEntryPointName="main",
  90. E_PIXEL_SHADER_TYPE psCompileTarget=EPST_PS_1_1,
  91. IShaderConstantSetCallBack* callback=0,
  92. E_MATERIAL_TYPE baseMaterial=video::EMT_SOLID,
  93. s32 userData=0)
  94. {
  95. return addHighLevelShaderMaterial(
  96. vertexShaderProgram, vertexShaderEntryPointName,
  97. vsCompileTarget, pixelShaderProgram,
  98. pixelShaderEntryPointName, psCompileTarget,
  99. 0, "main", EGST_GS_4_0,
  100. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  101. callback, baseMaterial, userData);
  102. }
  103. //! convenience function for use with many defaults, without geometry shader
  104. /** All shader names are set to "main" and compile targets are shader
  105. type 1.1.
  106. */
  107. s32 addHighLevelShaderMaterial(
  108. const c8* vertexShaderProgram,
  109. const c8* pixelShaderProgram=0,
  110. IShaderConstantSetCallBack* callback=0,
  111. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  112. s32 userData=0)
  113. {
  114. return addHighLevelShaderMaterial(
  115. vertexShaderProgram, "main",
  116. EVST_VS_1_1, pixelShaderProgram,
  117. "main", EPST_PS_1_1,
  118. 0, "main", EGST_GS_4_0,
  119. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  120. callback, baseMaterial, userData);
  121. }
  122. //! convenience function for use with many defaults, with geometry shader
  123. /** All shader names are set to "main" and compile targets are shader
  124. type 1.1 and geometry shader 4.0.
  125. */
  126. s32 addHighLevelShaderMaterial(
  127. const c8* vertexShaderProgram,
  128. const c8* pixelShaderProgram = 0,
  129. const c8* geometryShaderProgram = 0,
  130. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  131. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  132. u32 verticesOut = 0,
  133. IShaderConstantSetCallBack* callback = 0,
  134. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  135. s32 userData = 0 )
  136. {
  137. return addHighLevelShaderMaterial(
  138. vertexShaderProgram, "main",
  139. EVST_VS_1_1, pixelShaderProgram,
  140. "main", EPST_PS_1_1,
  141. geometryShaderProgram, "main", EGST_GS_4_0,
  142. inType, outType, verticesOut,
  143. callback, baseMaterial, userData);
  144. }
  145. //! Like IGPUProgrammingServices::addShaderMaterial(), but loads from files.
  146. /** \param vertexShaderProgramFileName Text file containing the source
  147. of the vertex shader program. Set to empty string if no vertex shader
  148. shall be created.
  149. \param vertexShaderEntryPointName Name of the entry function of the
  150. vertexShaderProgram (p.e. "main")
  151. \param vsCompileTarget Vertex shader version the high level shader
  152. shall be compiled to.
  153. \param pixelShaderProgramFileName Text file containing the source of
  154. the pixel shader program. Set to empty string if no pixel shader shall
  155. be created.
  156. \param pixelShaderEntryPointName Entry name of the function of the
  157. pixelShaderProgram (p.e. "main")
  158. \param psCompileTarget Pixel shader version the high level shader
  159. shall be compiled to.
  160. \param geometryShaderProgramFileName Name of the source of
  161. the geometry shader program. Set to empty string if no geometry shader
  162. shall be created.
  163. \param geometryShaderEntryPointName Entry name of the function of the
  164. geometryShaderProgram (p.e. "main")
  165. \param gsCompileTarget Geometry shader version the high level shader
  166. shall be compiled to.
  167. \param inType Type of vertices passed to geometry shader
  168. \param outType Type of vertices created by geometry shader
  169. \param verticesOut Maximal number of vertices created by geometry
  170. shader. If 0, maximal number supported is assumed.
  171. \param callback Pointer to an implementation of
  172. IShaderConstantSetCallBack in which you can set the needed vertex,
  173. pixel, and geometry shader program constants. Set this to 0 if you
  174. don't need this.
  175. \param baseMaterial Base material which renderstates will be used to
  176. shade the material.
  177. \param userData a user data int. This int can be set to any value and
  178. will be set as parameter in the callback method when calling
  179. OnSetConstants(). In this way it is easily possible to use the same
  180. callback method for multiple materials and distinguish between them
  181. during the call.
  182. \return Number of the material type which can be set in
  183. SMaterial::MaterialType to use the renderer. -1 is returned if an error
  184. occurred, e.g. if a shader program could not be compiled or a compile
  185. target is not reachable. The error strings are then printed to the
  186. error log and can be caught with a custom event receiver. */
  187. virtual s32 addHighLevelShaderMaterialFromFiles(
  188. const io::path& vertexShaderProgramFileName,
  189. const c8* vertexShaderEntryPointName,
  190. E_VERTEX_SHADER_TYPE vsCompileTarget,
  191. const io::path& pixelShaderProgramFileName,
  192. const c8* pixelShaderEntryPointName,
  193. E_PIXEL_SHADER_TYPE psCompileTarget,
  194. const io::path& geometryShaderProgramFileName,
  195. const c8* geometryShaderEntryPointName = "main",
  196. E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
  197. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  198. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  199. u32 verticesOut = 0,
  200. IShaderConstantSetCallBack* callback = 0,
  201. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  202. s32 userData = 0) = 0;
  203. //! convenience function for use without geometry shaders
  204. s32 addHighLevelShaderMaterialFromFiles(
  205. const io::path& vertexShaderProgramFileName,
  206. const c8* vertexShaderEntryPointName = "main",
  207. E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,
  208. const io::path& pixelShaderProgramFileName = "",
  209. const c8* pixelShaderEntryPointName = "main",
  210. E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,
  211. IShaderConstantSetCallBack* callback = 0,
  212. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  213. s32 userData = 0)
  214. {
  215. return addHighLevelShaderMaterialFromFiles(
  216. vertexShaderProgramFileName, vertexShaderEntryPointName,
  217. vsCompileTarget, pixelShaderProgramFileName,
  218. pixelShaderEntryPointName, psCompileTarget,
  219. "", "main", EGST_GS_4_0,
  220. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  221. callback, baseMaterial, userData);
  222. }
  223. //! convenience function for use with many defaults, without geometry shader
  224. /** All shader names are set to "main" and compile targets are shader
  225. type 1.1.
  226. */
  227. s32 addHighLevelShaderMaterialFromFiles(
  228. const io::path& vertexShaderProgramFileName,
  229. const io::path& pixelShaderProgramFileName = "",
  230. IShaderConstantSetCallBack* callback = 0,
  231. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  232. s32 userData = 0 )
  233. {
  234. return addHighLevelShaderMaterialFromFiles(
  235. vertexShaderProgramFileName, "main",
  236. EVST_VS_1_1, pixelShaderProgramFileName,
  237. "main", EPST_PS_1_1,
  238. "", "main", EGST_GS_4_0,
  239. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  240. callback, baseMaterial, userData);
  241. }
  242. //! convenience function for use with many defaults, with geometry shader
  243. /** All shader names are set to "main" and compile targets are shader
  244. type 1.1 and geometry shader 4.0.
  245. */
  246. s32 addHighLevelShaderMaterialFromFiles(
  247. const io::path& vertexShaderProgramFileName,
  248. const io::path& pixelShaderProgramFileName = "",
  249. const io::path& geometryShaderProgramFileName = "",
  250. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  251. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  252. u32 verticesOut = 0,
  253. IShaderConstantSetCallBack* callback = 0,
  254. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  255. s32 userData = 0 )
  256. {
  257. return addHighLevelShaderMaterialFromFiles(
  258. vertexShaderProgramFileName, "main",
  259. EVST_VS_1_1, pixelShaderProgramFileName,
  260. "main", EPST_PS_1_1,
  261. geometryShaderProgramFileName, "main", EGST_GS_4_0,
  262. inType, outType, verticesOut,
  263. callback, baseMaterial, userData);
  264. }
  265. //! Like IGPUProgrammingServices::addShaderMaterial(), but loads from files.
  266. /** \param vertexShaderProgram Text file handle containing the source
  267. of the vertex shader program. Set to 0 if no vertex shader shall be
  268. created.
  269. \param vertexShaderEntryPointName Name of the entry function of the
  270. vertexShaderProgram
  271. \param vsCompileTarget Vertex shader version the high level shader
  272. shall be compiled to.
  273. \param pixelShaderProgram Text file handle containing the source of
  274. the pixel shader program. Set to 0 if no pixel shader shall be created.
  275. \param pixelShaderEntryPointName Entry name of the function of the
  276. pixelShaderProgram (p.e. "main")
  277. \param psCompileTarget Pixel shader version the high level shader
  278. shall be compiled to.
  279. \param geometryShaderProgram Text file handle containing the source of
  280. the geometry shader program. Set to 0 if no geometry shader shall be
  281. created.
  282. \param geometryShaderEntryPointName Entry name of the function of the
  283. geometryShaderProgram (p.e. "main")
  284. \param gsCompileTarget Geometry shader version the high level shader
  285. shall be compiled to.
  286. \param inType Type of vertices passed to geometry shader
  287. \param outType Type of vertices created by geometry shader
  288. \param verticesOut Maximal number of vertices created by geometry
  289. shader. If 0, maximal number supported is assumed.
  290. \param callback Pointer to an implementation of
  291. IShaderConstantSetCallBack in which you can set the needed vertex and
  292. pixel shader program constants. Set this to 0 if you don't need this.
  293. \param baseMaterial Base material which renderstates will be used to
  294. shade the material.
  295. \param userData a user data int. This int can be set to any value and
  296. will be set as parameter in the callback method when calling
  297. OnSetConstants(). In this way it is easily possible to use the same
  298. callback method for multiple materials and distinguish between them
  299. during the call.
  300. \return Number of the material type which can be set in
  301. SMaterial::MaterialType to use the renderer. -1 is returned if an
  302. error occurred, e.g. if a shader program could not be compiled or a
  303. compile target is not reachable. The error strings are then printed to
  304. the error log and can be caught with a custom event receiver. */
  305. virtual s32 addHighLevelShaderMaterialFromFiles(
  306. io::IReadFile* vertexShaderProgram,
  307. const c8* vertexShaderEntryPointName,
  308. E_VERTEX_SHADER_TYPE vsCompileTarget,
  309. io::IReadFile* pixelShaderProgram,
  310. const c8* pixelShaderEntryPointName,
  311. E_PIXEL_SHADER_TYPE psCompileTarget,
  312. io::IReadFile* geometryShaderProgram,
  313. const c8* geometryShaderEntryPointName = "main",
  314. E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
  315. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  316. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  317. u32 verticesOut = 0,
  318. IShaderConstantSetCallBack* callback = 0,
  319. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  320. s32 userData = 0) = 0;
  321. //! convenience function for use without geometry shaders
  322. s32 addHighLevelShaderMaterialFromFiles(
  323. io::IReadFile* vertexShaderProgram,
  324. const c8* vertexShaderEntryPointName = "main",
  325. E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,
  326. io::IReadFile* pixelShaderProgram = 0,
  327. const c8* pixelShaderEntryPointName = "main",
  328. E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,
  329. IShaderConstantSetCallBack* callback = 0,
  330. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  331. s32 userData = 0)
  332. {
  333. return addHighLevelShaderMaterialFromFiles(
  334. vertexShaderProgram, vertexShaderEntryPointName,
  335. vsCompileTarget, pixelShaderProgram,
  336. pixelShaderEntryPointName, psCompileTarget,
  337. 0, "main", EGST_GS_4_0,
  338. scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0,
  339. callback, baseMaterial, userData);
  340. }
  341. //! Adds a new ASM shader material renderer to the VideoDriver
  342. /** Note that it is a good idea to call IVideoDriver::queryFeature() in
  343. advance to check if the IVideoDriver supports the vertex and/or pixel
  344. shader version your are using.
  345. The material is added to the VideoDriver like with
  346. IVideoDriver::addMaterialRenderer() and can be used like it had been
  347. added with that method.
  348. \param vertexShaderProgram String containing the source of the vertex
  349. shader program. This can be 0 if no vertex program shall be used.
  350. For DX8 programs, the will always input registers look like this: v0:
  351. position, v1: normal, v2: color, v3: texture coordinates, v4: texture
  352. coordinates 2 if available.
  353. For DX9 programs, you can manually set the registers using the dcl_
  354. statements.
  355. \param pixelShaderProgram String containing the source of the pixel
  356. shader program. This can be 0 if you don't want to use a pixel shader.
  357. \param callback Pointer to an implementation of
  358. IShaderConstantSetCallBack in which you can set the needed vertex and
  359. pixel shader program constants. Set this to 0 if you don't need this.
  360. \param baseMaterial Base material which renderstates will be used to
  361. shade the material.
  362. \param userData a user data int. This int can be set to any value and
  363. will be set as parameter in the callback method when calling
  364. OnSetConstants(). In this way it is easily possible to use the same
  365. callback method for multiple materials and distinguish between them
  366. during the call.
  367. \return Returns the number of the material type which can be set in
  368. SMaterial::MaterialType to use the renderer. -1 is returned if an
  369. error occurred. -1 is returned for example if a vertex or pixel shader
  370. program could not be compiled, the error strings are then printed out
  371. into the error log, and can be caught with a custom event receiver. */
  372. virtual s32 addShaderMaterial(const c8* vertexShaderProgram = 0,
  373. const c8* pixelShaderProgram = 0,
  374. IShaderConstantSetCallBack* callback = 0,
  375. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  376. s32 userData = 0) = 0;
  377. //! Like IGPUProgrammingServices::addShaderMaterial(), but loads from files.
  378. /** \param vertexShaderProgram Text file containing the source of the
  379. vertex shader program. Set to 0 if no shader shall be created.
  380. \param pixelShaderProgram Text file containing the source of the pixel
  381. shader program. Set to 0 if no shader shall be created.
  382. \param callback Pointer to an IShaderConstantSetCallback object to
  383. which the OnSetConstants function is called.
  384. \param baseMaterial baseMaterial
  385. \param userData a user data int. This int can be set to any value and
  386. will be set as parameter in the callback method when calling
  387. OnSetConstants(). In this way it is easily possible to use the same
  388. callback method for multiple materials and distinguish between them
  389. during the call.
  390. \return Returns the number of the material type which can be set in
  391. SMaterial::MaterialType to use the renderer. -1 is returned if an
  392. error occurred. -1 is returned for example if a vertex or pixel shader
  393. program could not be compiled, the error strings are then printed out
  394. into the error log, and can be caught with a custom event receiver. */
  395. virtual s32 addShaderMaterialFromFiles(io::IReadFile* vertexShaderProgram,
  396. io::IReadFile* pixelShaderProgram,
  397. IShaderConstantSetCallBack* callback = 0,
  398. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  399. s32 userData = 0) = 0;
  400. //! Like IGPUProgrammingServices::addShaderMaterial(), but loads from files.
  401. /** \param vertexShaderProgramFileName Text file name containing the
  402. source of the vertex shader program. Set to 0 if no shader shall be
  403. created.
  404. \param pixelShaderProgramFileName Text file name containing the source
  405. of the pixel shader program. Set to 0 if no shader shall be created.
  406. \param callback Pointer to an IShaderConstantSetCallback object on
  407. which the OnSetConstants function is called.
  408. \param baseMaterial baseMaterial
  409. \param userData a user data int. This int can be set to any value and
  410. will be set as parameter in the callback method when calling
  411. OnSetConstants(). In this way it is easily possible to use the same
  412. callback method for multiple materials and distinguish between them
  413. during the call.
  414. \return Returns the number of the material type which can be set in
  415. SMaterial::MaterialType to use the renderer. -1 is returned if an
  416. error occurred. -1 is returned for example if a vertex or pixel shader
  417. program could not be compiled, the error strings are then printed out
  418. into the error log, and can be caught with a custom event receiver. */
  419. virtual s32 addShaderMaterialFromFiles(const io::path& vertexShaderProgramFileName,
  420. const io::path& pixelShaderProgramFileName,
  421. IShaderConstantSetCallBack* callback = 0,
  422. E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
  423. s32 userData = 0) = 0;
  424. };
  425. } // end namespace video
  426. } // end namespace irr
  427. #endif