]> git.lizzy.rs Git - irrlicht.git/blob - include/IShaderConstantSetCallBack.h
Restore obsolete constants as they are still used in some code I don’t want to touch
[irrlicht.git] / include / IShaderConstantSetCallBack.h
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
4 \r
5 #ifndef __I_SHADER_CONSTANT_SET_CALLBACT_H_INCLUDED__\r
6 #define __I_SHADER_CONSTANT_SET_CALLBACT_H_INCLUDED__\r
7 \r
8 #include "IReferenceCounted.h"\r
9 \r
10 namespace irr\r
11 {\r
12 namespace video\r
13 {\r
14         class IMaterialRendererServices;\r
15         class SMaterial;\r
16 \r
17 //! Interface making it possible to set constants for gpu programs every frame.\r
18 /** Implement this interface in an own class and pass a pointer to it to one of\r
19 the methods in IGPUProgrammingServices when creating a shader. The\r
20 OnSetConstants method will be called every frame now. */\r
21 class IShaderConstantSetCallBack : public virtual IReferenceCounted\r
22 {\r
23 public:\r
24 \r
25         //! Called to let the callBack know the used material (optional method)\r
26         /**\r
27          \code\r
28         class MyCallBack : public IShaderConstantSetCallBack\r
29         {\r
30                 const video::SMaterial *UsedMaterial;\r
31 \r
32                 OnSetMaterial(const video::SMaterial& material)\r
33                 {\r
34                         UsedMaterial=&material;\r
35                 }\r
36 \r
37                 OnSetConstants(IMaterialRendererServices* services, s32 userData)\r
38                 {\r
39                         services->setVertexShaderConstant("myColor", reinterpret_cast<f32*>(&UsedMaterial->color), 4);\r
40                 }\r
41         }\r
42         \endcode\r
43         */\r
44         virtual void OnSetMaterial(const SMaterial& material) { }\r
45 \r
46         //! Called by the engine when the vertex and/or pixel shader constants for an material renderer should be set.\r
47         /**\r
48         Implement the IShaderConstantSetCallBack in an own class and implement your own\r
49         OnSetConstants method using the given IMaterialRendererServices interface.\r
50         Pass a pointer to this class to one of the methods in IGPUProgrammingServices\r
51         when creating a shader. The OnSetConstants method will now be called every time\r
52         before geometry is being drawn using your shader material. A sample implementation\r
53         would look like this:\r
54         \code\r
55         virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)\r
56         {\r
57                 video::IVideoDriver* driver = services->getVideoDriver();\r
58 \r
59                 // set clip matrix at register 4\r
60                 core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION));\r
61                 worldViewProj *= driver->getTransform(video::ETS_VIEW);\r
62                 worldViewProj *= driver->getTransform(video::ETS_WORLD);\r
63                 services->setVertexShaderConstant(&worldViewProj.M[0], 4, 4);\r
64                 // for high level shading languages, this would be another solution:\r
65                 //services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);\r
66 \r
67                 // set some light color at register 9\r
68                 video::SColorf col(0.0f,1.0f,1.0f,0.0f);\r
69                 services->setVertexShaderConstant(reinterpret_cast<const f32*>(&col), 9, 1);\r
70                 // for high level shading languages, this would be another solution:\r
71                 //services->setVertexShaderConstant("myColor", reinterpret_cast<f32*>(&col), 4);\r
72         }\r
73         \endcode\r
74         \param services: Pointer to an interface providing methods to set the constants for the shader.\r
75         \param userData: Userdata int which can be specified when creating the shader.\r
76         */\r
77         virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData) = 0;\r
78 };\r
79 \r
80 \r
81 } // end namespace video\r
82 } // end namespace irr\r
83 \r
84 #endif\r
85 \r