[780] | 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 | */
|
---|
| 13 | class RenderingRun
|
---|
| 14 | {
|
---|
| 15 | public:
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | @brief Constructor.
|
---|
[790] | 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
|
---|
[780] | 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 | */
|
---|
[949] | 29 | bool update(unsigned long frameNum)
|
---|
[780] | 30 | {
|
---|
[949] | 31 | bool needupdate = needUpdate(frameNum);
|
---|
| 32 | if(needupdate)
|
---|
[780] | 33 | {
|
---|
| 34 | updateFrame(frameNum);
|
---|
| 35 | lastupdated = frameNum;
|
---|
| 36 | }
|
---|
[949] | 37 | return needupdate;
|
---|
[780] | 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 | protected:
|
---|
| 48 |
|
---|
| 49 | /**
|
---|
| 50 | @brief Returns if this run needs update
|
---|
| 51 |
|
---|
| 52 | @param frameNum current frame number
|
---|
| 53 | */
|
---|
[1125] | 54 | virtual bool needUpdate(unsigned long frameNum )
|
---|
[780] | 55 | {
|
---|
| 56 | if(frameNum == lastupdated )
|
---|
| 57 | return false;
|
---|
| 58 |
|
---|
| 59 | if ( updateInterval == 0 ) //update only once
|
---|
| 60 | {
|
---|
[874] | 61 | if( lastupdated == 0)
|
---|
[780] | 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 | };
|
---|