[3255] | 1 | #pragma once
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | @brief Base class __declspec( dllexport ) 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 __declspec( dllexport ) RenderingRun
|
---|
| 14 | {
|
---|
| 15 | public:
|
---|
| 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 __declspec( dllexport ) OgreRenderingRun* asOgreRenderingRun(){return 0;}
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | @brief Returns true if two runs can be joined.
|
---|
| 49 |
|
---|
| 50 | In some cases special requirements should stand to join two runs (even if they have the same type).
|
---|
| 51 | Eg.: two caustic cube map generation technique should only be joined if they use the same material
|
---|
| 52 | when rendering the caustic cubemap.
|
---|
| 53 | */
|
---|
| 54 | virtual bool canJoin(RenderingRun* run){return true;}
|
---|
| 55 |
|
---|
| 56 | virtual void freeAllResources()=0;
|
---|
| 57 |
|
---|
| 58 | protected:
|
---|
| 59 |
|
---|
| 60 | /**
|
---|
| 61 | @brief Returns if this run needs update
|
---|
| 62 |
|
---|
| 63 | This tipically depends on the upate interval and the starting frame number.
|
---|
| 64 |
|
---|
| 65 | @param frameNum current frame number
|
---|
| 66 | */
|
---|
| 67 | virtual bool needUpdate(unsigned long frameNum )
|
---|
| 68 | {
|
---|
| 69 | if(frameNum == lastupdated )
|
---|
| 70 | return false;
|
---|
| 71 |
|
---|
| 72 | if ( updateInterval == 0 ) //update only once
|
---|
| 73 | {
|
---|
| 74 | if( lastupdated == 0)
|
---|
| 75 | {
|
---|
| 76 | return true;
|
---|
| 77 | }
|
---|
| 78 | return false;
|
---|
| 79 | }
|
---|
| 80 | else
|
---|
| 81 | {
|
---|
| 82 | return ((frameNum - startFrame) % updateInterval == 0);
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /**
|
---|
| 87 | @brief The number of the last frame this run was updated.
|
---|
| 88 | */
|
---|
| 89 | unsigned long lastupdated;
|
---|
| 90 | /**
|
---|
| 91 | @brief The number of the frame this run should be updated first.
|
---|
| 92 | */
|
---|
| 93 | unsigned long startFrame;
|
---|
| 94 | /**
|
---|
| 95 | @brief Refresh frequency in frames.
|
---|
| 96 | */
|
---|
| 97 | unsigned long updateInterval;
|
---|
| 98 | /**
|
---|
| 99 | @brief This function does the actual update in a frame.
|
---|
| 100 |
|
---|
| 101 | @param frameNum current frame number
|
---|
| 102 | */
|
---|
| 103 | virtual void updateFrame(unsigned long frameNum){}
|
---|
| 104 |
|
---|
| 105 | };
|
---|