source: GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRun.h @ 1722

Revision 1722, 2.5 KB checked in by szirmay, 18 years ago (diff)
Line 
1#pragma once
2
3/**
4        @brief Base class for a computation module.
5
6        A run typically - but not necessarily or exclusively - consists of a series of rendering passes.
7        A run is alway created to compute some kind of resource for a RenderTechnique. The type of the resource
8        depends on the type of the run (typically it is a Texture). Runs can be attached to only one Technique
9        (if only one of the Techniques attached to a Renderable can use this resource, and each Renderable requires a unique one),
10        or can be shared between several Techniques and Renderables (for example a cube-map).
11        Runs are updated only once in a frame, but not necessary in each frame.
12*/
13class RenderingRun
14{       
15public:
16       
17        /**
18                @brief Constructor.
19               
20                @param startFrame                       adds an offset to the current frame number to help evenly distribute updates between frames
21                @param updateInterval           photon map update frequency             
22        */
23        RenderingRun(unsigned long startFrame,
24                                        unsigned long updateInterval);
25
26        /**
27                @brief Calls updateFrame() if the run needs update according to its starting frame and update interval and has not been allready updated in this frame.                 
28        */
29        bool update(unsigned long frameNum)
30        {
31                bool needupdate = needUpdate(frameNum);
32                if(needupdate)
33                {
34                        updateFrame(frameNum);
35                        lastupdated = frameNum;                 
36                }
37                return needupdate;
38        }
39       
40        /**
41                @brief Conversion to OgreRenderRun.
42
43                This function is needed because of virtual inheritance.
44        */
45        virtual class OgreRenderingRun* asOgreRenderingRun(){return 0;}
46       
47        virtual bool canJoin(RenderingRun* run){return true;}
48
49protected:
50
51        /**
52                        @brief Returns if this run needs update
53                       
54                        @param frameNum current frame number                   
55                */
56                virtual bool needUpdate(unsigned long frameNum )
57                {
58                        if(frameNum == lastupdated )
59                                return false;                   
60
61                        if ( updateInterval == 0 ) //update only once
62                        {
63                                if( lastupdated == 0)
64                                {
65                                        return true;
66                                }
67                                return false;
68                        }
69                        else
70                        {
71                                return ((frameNum - startFrame) % updateInterval == 0);
72                        }
73                }
74
75        /**
76                @brief The number of the last frame this run was updated.
77        */
78        unsigned long lastupdated;
79        /**
80                @brief The number of the frame this run should be updated first.
81        */
82        unsigned long startFrame;
83        /**
84                @brief Refresh frequency in frames.
85        */
86        unsigned long updateInterval;
87        /**
88                @brief This function does the actual update in a frame.
89               
90                @param frameNum current frame number
91        */
92        virtual void updateFrame(unsigned long frameNum){}
93       
94};
Note: See TracBrowser for help on using the repository browser.