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

Revision 1125, 2.4 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
47protected:
48
49        /**
50                        @brief Returns if this run needs update
51                       
52                        @param frameNum current frame number                   
53                */
54                virtual bool needUpdate(unsigned long frameNum )
55                {
56                        if(frameNum == lastupdated )
57                                return false;                   
58
59                        if ( updateInterval == 0 ) //update only once
60                        {
61                                if( lastupdated == 0)
62                                {
63                                        return true;
64                                }
65                                return false;
66                        }
67                        else
68                        {
69                                return ((frameNum - startFrame) % updateInterval == 0);
70                        }
71                }
72
73        /**
74                @brief The number of the last frame this run was updated.
75        */
76        unsigned long lastupdated;
77        /**
78                @brief The number of the frame this run should be updated first.
79        */
80        unsigned long startFrame;
81        /**
82                @brief Refresh frequency in frames.
83        */
84        unsigned long updateInterval;
85        /**
86                @brief This function does the actual update in a frame.
87               
88                @param frameNum current frame number
89        */
90        virtual void updateFrame(unsigned long frameNum){}
91       
92};
Note: See TracBrowser for help on using the repository browser.