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