~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to include/IShaderConstantSetCallBack.h

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

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