source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreRenderTarget.h @ 1812

Revision 1812, 15.2 KB checked in by gumbau, 18 years ago (diff)
RevLine 
[1812]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __RenderTarget_H__
26#define __RenderTarget_H__
27
28#include "OgrePrerequisites.h"
29
30#include "OgreString.h"
31#include "OgreTextureManager.h"
32#include "OgreViewport.h"
33#include "OgreTimer.h"
34
35/* Define the number of priority groups for the render system's render targets. */
36#ifndef OGRE_NUM_RENDERTARGET_GROUPS
37        #define OGRE_NUM_RENDERTARGET_GROUPS 10
38        #define OGRE_DEFAULT_RT_GROUP 4
39        #define OGRE_REND_TO_TEX_RT_GROUP 2
40#endif
41
42namespace Ogre {
43
44    /** A 'canvas' which can receive the results of a rendering
45        operation.
46        @remarks
47            This abstract class defines a common root to all targets of rendering operations. A
48            render target could be a window on a screen, or another
49            offscreen surface like a texture or bump map etc.
50        @author
51            Steven Streeting
52        @version
53            1.0
54     */
55    class _OgreExport RenderTarget
56    {
57    public:
58        enum StatFlags
59        {
60            SF_NONE           = 0,
61            SF_FPS            = 1,
62            SF_AVG_FPS        = 2,
63            SF_BEST_FPS       = 4,
64            SF_WORST_FPS      = 8,
65            SF_TRIANGLE_COUNT = 16,
66            SF_ALL            = 0xFFFF
67        };
68
69        struct FrameStats
70        {
71            float lastFPS;
72            float avgFPS;
73            float bestFPS;
74            float worstFPS;
75            unsigned long bestFrameTime;
76            unsigned long worstFrameTime;
77            size_t triangleCount;
78        };
79
80        RenderTarget();
81        virtual ~RenderTarget();
82
83        /// Retrieve target's name.
84        virtual const String& getName(void) const;
85
86        /// Retrieve information about the render target.
87        virtual void getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth);
88
89        virtual unsigned int getWidth(void) const;
90        virtual unsigned int getHeight(void) const;
91        virtual unsigned int getColourDepth(void) const;
92
93        /** Tells the target to update it's contents.
94            @remarks
95                If OGRE is not running in an automatic rendering loop
96                (started using Root::startRendering),
97                the user of the library is responsible for asking each render
98                target to refresh. This is the method used to do this. It automatically
99                re-renders the contents of the target using whatever cameras have been
100                pointed at it (using Camera::setRenderTarget).
101            @par
102                This allows OGRE to be used in multi-windowed utilities
103                and for contents to be refreshed only when required, rather than
104                constantly as with the automatic rendering loop.
105        */
106        virtual void update(void);
107
108        /** Adds a viewport to the rendering target.
109            @remarks
110                A viewport is the rectangle into which redering output is sent. This method adds
111                a viewport to the render target, rendering from the supplied camera. The
112                rest of the parameters are only required if you wish to add more than one viewport
113                to a single rendering target. Note that size information passed to this method is
114                passed as a parametric, i.e. it is relative rather than absolute. This is to allow
115                viewports to automatically resize along with the target.
116            @param
117                cam The camera from which the viewport contents will be rendered (mandatory)
118            @param
119                ZOrder The relative order of the viewport with others on the target (allows overlapping
120                viewports i.e. picture-in-picture). Higher ZOrders are on top of lower ones. The actual number
121                is irrelevant, only the relative ZOrder matters (you can leave gaps in the numbering)
122            @param
123                left The relative position of the left of the viewport on the target, as a value between 0 and 1.
124            @param
125                top The relative position of the top of the viewport on the target, as a value between 0 and 1.
126            @param
127                width The relative width of the viewport on the target, as a value between 0 and 1.
128            @param
129                height The relative height of the viewport on the target, as a value between 0 and 1.
130        */
131        virtual Viewport* addViewport(Camera* cam, int ZOrder = 0, float left = 0.0f, float top = 0.0f ,
132            float width = 1.0f, float height = 1.0f);
133
134        /** Returns the number of viewports attached to this target.*/
135        virtual unsigned short getNumViewports(void) const;
136
137        /** Retrieves a pointer to the viewport with the given index. */
138        virtual Viewport* getViewport(unsigned short index);
139
140        /** Removes a viewport at a given ZOrder.
141        */
142        virtual void removeViewport(int ZOrder);
143
144        /** Removes all viewports on this target.
145        */
146        virtual void removeAllViewports(void);
147
148        /** Retieves details of current rendering performance.
149            @remarks
150                If the user application wishes to do it's own performance
151                display, or use performance for some other means, this
152                method allows it to retrieve the statistics.
153                @param
154                    lastFPS Pointer to a float to receive the number of frames per second (FPS)
155                    based on the last frame rendered.
156                @param
157                    avgFPS Pointer to a float to receive the FPS rating based on an average of all
158                    the frames rendered since rendering began (the call to
159                    Root::startRendering).
160                @param
161                    bestFPS Pointer to a float to receive the best FPS rating that has been achieved
162                    since rendering began.
163                @param
164                    worstFPS Pointer to a float to receive the worst FPS rating seen so far.
165        */
166        virtual void getStatistics(float& lastFPS, float& avgFPS,
167            float& bestFPS, float& worstFPS) const;  // Access to stats
168
169        virtual const FrameStats& getStatistics(void) const;
170
171        /** Individual stats access - gets the number of frames per second (FPS) based on the last frame rendered.
172        */
173        virtual float getLastFPS() const;
174
175        /** Individual stats access - gets the average frames per second (FPS) since call to Root::startRendering.
176        */
177        virtual float getAverageFPS() const;
178
179        /** Individual stats access - gets the best frames per second (FPS) since call to Root::startRendering.
180        */
181        virtual float getBestFPS() const;
182
183        /** Individual stats access - gets the worst frames per second (FPS) since call to Root::startRendering.
184        */
185        virtual float getWorstFPS() const;
186
187        /** Individual stats access - gets the best frame time
188        */
189        virtual float getBestFrameTime() const;
190
191        /** Individual stats access - gets the worst frame time
192        */
193        virtual float getWorstFrameTime() const;
194
195        /** Resets saved frame-rate statistices.
196        */
197        virtual void resetStatistics(void);
198
199        /** Gets a custom (maybe platform-specific) attribute.
200            @remarks
201                This is a nasty way of satisfying any API's need to see platform-specific details.
202                It horrid, but D3D needs this kind of info. At least it's abstracted.
203            @param
204                name The name of the attribute.
205            @param
206                pData Pointer to memory of the right kind of structure to receive the info.
207        */
208        virtual void getCustomAttribute(const String& name, void* pData);
209
210        /** Adds debug text to this window. */
211        virtual void setDebugText(const String& text);
212
213                /** Returns the debug text. */
214                const String& getDebugText() const;
215
216        /** Add a listener to this RenderTarget which will be called back before & after rendering.
217        @remarks
218            If you want notifications before and after a target is updated by the system, use
219            this method to register your own custom RenderTargetListener class. This is useful
220            for potentially adding your own manual rendering commands before and after the
221            'normal' system rendering.
222        @par NB this should not be used for frame-based scene updates, use Root::addFrameListener for that.
223        */
224        virtual void addListener(RenderTargetListener* listener);
225        /** Removes a RenderTargetListener previously registered using addListener. */
226        virtual void removeListener(RenderTargetListener* listener);
227        /** Removes all listeners from this instance. */
228        virtual void removeAllListeners(void);
229
230                /** Sets the priority of this render target in relation to the others.
231        @remarks
232            This can be used in order to schedule render target updates. Lower
233            priorities will be rendered first. Note that the priority must be set
234            at the time the render target is attached to the render system, changes
235            afterwards will not affect the ordering.
236        */
237        virtual void setPriority( uchar priority ) { mPriority = priority; }
238        /** Gets the priority of a render target. */
239                virtual uchar getPriority() const { return mPriority; }
240
241        /** Used to retrieve or set the active state of the render target.
242        */
243        virtual bool isActive() const;
244
245        /** Used to set the active state of the render target.
246        */
247        virtual void setActive( bool state );
248
249        /** Sets whether this target should be automatically updated if Ogre's rendering
250            loop or Root::_updateAllRenderTargets is being used.
251        @remarks
252            By default, if you use Ogre's own rendering loop (Root::startRendering)
253            or call Root::_updateAllRenderTargets, all render targets are updated
254            automatically. This method allows you to control that behaviour, if
255            for example you have a render target which you only want to update periodically.
256        @param autoupdate If true, the render target is updated during the automatic render
257            loop or when Root::_updateAllRenderTargets is called. If false, the
258            target is only updated when its update() method is called explicitly.
259        */
260        virtual void setAutoUpdated(bool autoupdate);
261        /** Gets whether this target is automatically updated if Ogre's rendering
262            loop or Root::_updateAllRenderTargets is being used.
263        */
264        virtual bool isAutoUpdated(void) const;
265
266        /** Writes the current contents of the render target to the named file. */
267        virtual void writeContentsToFile(const String& filename) = 0;
268
269        /** Writes the current contents of the render target to the (PREFIX)(time-stamp)(SUFFIX) file.
270                @returns the name of the file used.*/
271        virtual String writeContentsToTimestampedFile(const String& filenamePrefix, const String& filenameSuffix);
272
273                virtual bool requiresTextureFlipping() const = 0;
274
275                /** Gets the number of triangles rendered in the last update() call. */
276                virtual size_t getTriangleCount(void) const;
277        /** Utility method to notify a render target that a camera has been removed,
278        incase it was referring to it as a viewer.
279        */
280        virtual void _notifyCameraRemoved(const Camera* cam);
281
282        /** Indicates whether this target is the primary window. The
283            primary window is special in that it is destroyed when
284            ogre is shut down, and cannot be destroyed directly.
285            This is the case because it holds the context for vertex,
286            index buffers and textures.
287        */
288        virtual bool isPrimary(void) const;
289
290
291        /** RenderSystem specific interface for a RenderTarget;
292            this should be subclassed by RenderSystems.
293        */
294        class Impl
295        {
296        protected:
297            /** Declared protected as interface is never used for destruction.
298                gcc will issue a warning here: `class Impl' has virtual functions
299                but non-virtual destructor. This is no problem because this interface
300                is never used to delete an object.
301            */
302            ~Impl() { };
303        };
304        /** Get rendersystem specific interface for this RenderTarget.
305            This is used by the RenderSystem to (un)bind this target,
306            and to get specific information like surfaces
307            and framebuffer objects.
308        */
309        virtual Impl *_getImpl();
310    protected:
311        /// The name of this target.
312        String mName;
313                /// The priority of the render target.
314                uchar mPriority;
315
316        unsigned int mWidth;
317        unsigned int mHeight;
318        unsigned int mColourDepth;
319        bool mIsDepthBuffered;
320
321        // Stats
322                FrameStats mStats;
323       
324        Timer* mTimer ;
325        String mDebugText;
326        unsigned long mLastSecond;
327        unsigned long mLastTime;
328        size_t mFrameCount;
329
330        bool mActive;
331        bool mAutoUpdate;
332
333        void updateStats(void);
334
335        typedef std::map<int, Viewport*, std::less<int> > ViewportList;
336        /// List of viewports, map on Z-order
337        ViewportList mViewportList;
338
339        typedef std::vector<RenderTargetListener*> RenderTargetListenerList;
340        RenderTargetListenerList mListeners;
341       
342
343        /// internal method for firing events
344        virtual void firePreUpdate(void);
345        /// internal method for firing events
346        virtual void firePostUpdate(void);
347        /// internal method for firing events
348        virtual void fireViewportPreUpdate(Viewport* vp);
349        /// internal method for firing events
350        virtual void fireViewportPostUpdate(Viewport* vp);
351                /// internal method for firing events
352                virtual void fireViewportAdded(Viewport* vp);
353                /// internal method for firing events
354                virtual void fireViewportRemoved(Viewport* vp);
355    };
356
357} // Namespace
358
359#endif
Note: See TracBrowser for help on using the repository browser.