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 
5 #ifndef __I_MATERIAL_RENDERER_H_INCLUDED__
6 #define __I_MATERIAL_RENDERER_H_INCLUDED__
7 
8 #include "IReferenceCounted.h"
9 #include "SMaterial.h"
10 #include "S3DVertex.h"
11 
12 namespace irr
13 {
14 namespace video
15 {
16 
17 class IVideoDriver;
18 class IMaterialRendererServices;
19 
20 //! Interface for material rendering.
21 /** Can be used to extend the engine with new materials. Refer to
22 IVideoDriver::addMaterialRenderer() for more informations on how to extend the
23 engine with new materials. */
24 class IMaterialRenderer : public virtual IReferenceCounted
25 {
26 public:
27 
28 	//! Called by the IVideoDriver implementation the let the renderer set its needed render states.
29 	/** This is called during the IVideoDriver::setMaterial() call.
30 	When overriding this, you can set some renderstates or for example a
31 	vertex or pixel shader if you like.
32 	\param material: The new material parameters to be set. The renderer
33 	may change the material flags in this material. For example if this
34 	material does not accept the zbuffer = true, it can set it to false.
35 	This is useful, because in the next lastMaterial will be just the
36 	material in this call.
37 	\param lastMaterial: The material parameters which have been set before
38 	this material.
39 	\param resetAllRenderstates: True if all renderstates should really be
40 	reset. This is usually true if the last rendering mode was not a usual
41 	3d rendering mode, but for example a 2d rendering mode.
42 	You should reset really all renderstates if this is true, no matter if
43 	the lastMaterial had some similar settings. This is used because in
44 	most cases, some common renderstates are not changed if they are
45 	already there, for example bilinear filtering, wireframe,
46 	gouraudshading, lighting, zbuffer, zwriteenable, backfaceculling and
47 	fogenable.
48 	\param services: Interface providing some methods for changing
49 	advanced, internal states of a IVideoDriver. */
OnSetMaterial(const SMaterial & material,const SMaterial & lastMaterial,bool resetAllRenderstates,IMaterialRendererServices * services)50 	virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
51 		bool resetAllRenderstates, IMaterialRendererServices* services) {}
52 
53 	//! Called every time before a new bunch of geometry is being drawn using this material with for example drawIndexedTriangleList() call.
54 	/** OnSetMaterial should normally only be called if the renderer decides
55 	that the renderstates should be changed, it won't be called if for
56 	example two drawIndexedTriangleList() will be called with the same
57 	material set. This method will be called every time. This is useful for
58 	example for materials with shaders, which don't only set new
59 	renderstates but also shader constants.
60 	\param service: Pointer to interface providing methos for setting
61 	constants and other things.
62 	\param vtxtype: Vertex type with which the next rendering will be done.
63 	This can be used by the material renderer to set some specific
64 	optimized shaders or if this is an incompatible vertex type for this
65 	renderer, to refuse rendering for example.
66 	\return Returns true if everything is ok, and false if nothing should
67 	be rendered. The material renderer can choose to return false for
68 	example if he doesn't support the specified vertex type. This is
69 	actually done in D3D8 and D3D9 when using a normal mapped material with
70 	a vertex type other than EVT_TANGENTS. */
OnRender(IMaterialRendererServices * service,E_VERTEX_TYPE vtxtype)71 	virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) { return true; }
72 
73 	//! Called by the IVideoDriver to unset this material.
74 	/** Called during the IVideoDriver::setMaterial() call before the new
75 	material will get the OnSetMaterial() call. */
OnUnsetMaterial()76 	virtual void OnUnsetMaterial() {}
77 
78 	//! Returns if the material is transparent.
79 	/** The scene managment needs to know this
80 	for being able to sort the materials by opaque and transparent. */
isTransparent()81 	virtual bool isTransparent() const { return false; }
82 
83 	//! Returns the render capability of the material.
84 	/** Because some more complex materials
85 	are implemented in multiple ways and need special hardware capabilities, it is possible
86 	to query how the current material renderer is performing on the current hardware with this
87 	function.
88 	\return Returns 0 if everything is running fine. Any other value is material renderer
89 	specific and means for example that the renderer switched back to a fall back material because
90 	it cannot use the latest shaders. More specific examples:
91 	Fixed function pipeline materials should return 0 in most cases, parallax mapped
92 	material will only return 0 when at least pixel shader 1.4 is available on that machine. */
getRenderCapability()93 	virtual s32 getRenderCapability() const { return 0; }
94 };
95 
96 
97 } // end namespace video
98 } // end namespace irr
99 
100 #endif
101 
102