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
7 #include "IReferenceCounted.h"
13 class IMaterialRendererServices
;
16 //! Interface making it possible to set constants for gpu programs every frame.
17 /** Implement this interface in an own class and pass a pointer to it to one of
18 the methods in IGPUProgrammingServices when creating a shader. The
19 OnSetConstants method will be called every frame now. */
20 class IShaderConstantSetCallBack
: public virtual IReferenceCounted
23 //! Called to let the callBack know the used material (optional method)
26 class MyCallBack : public IShaderConstantSetCallBack
28 const video::SMaterial *UsedMaterial;
30 OnSetMaterial(const video::SMaterial& material)
32 UsedMaterial=&material;
35 OnSetConstants(IMaterialRendererServices* services, s32 userData)
37 services->setVertexShaderConstant("myColor", reinterpret_cast<f32*>(&UsedMaterial->color), 4);
42 virtual void OnSetMaterial(const SMaterial
&material
) {}
44 //! Called by the engine when the vertex and/or pixel shader constants for an material renderer should be set.
46 Implement the IShaderConstantSetCallBack in an own class and implement your own
47 OnSetConstants method using the given IMaterialRendererServices interface.
48 Pass a pointer to this class to one of the methods in IGPUProgrammingServices
49 when creating a shader. The OnSetConstants method will now be called every time
50 before geometry is being drawn using your shader material. A sample implementation
53 virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
55 video::IVideoDriver* driver = services->getVideoDriver();
57 // set clip matrix at register 4
58 core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION));
59 worldViewProj *= driver->getTransform(video::ETS_VIEW);
60 worldViewProj *= driver->getTransform(video::ETS_WORLD);
61 services->setVertexShaderConstant(&worldViewProj.M[0], 4, 4);
62 // for high level shading languages, this would be another solution:
63 //services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
65 // set some light color at register 9
66 video::SColorf col(0.0f,1.0f,1.0f,0.0f);
67 services->setVertexShaderConstant(reinterpret_cast<const f32*>(&col), 9, 1);
68 // for high level shading languages, this would be another solution:
69 //services->setVertexShaderConstant("myColor", reinterpret_cast<f32*>(&col), 4);
72 \param services: Pointer to an interface providing methods to set the constants for the shader.
73 \param userData: Userdata int which can be specified when creating the shader.
75 virtual void OnSetConstants(IMaterialRendererServices
*services
, s32 userData
) = 0;
78 } // end namespace video
79 } // end namespace irr