source: OGRE/trunk/ogre_changes/Ogre1.2/OgreMain/include/OgreRenderTarget.h @ 1219

Revision 1219, 15.5 KB checked in by mattausch, 18 years ago (diff)
Line 
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#ifdef GTP_VISIBILITY_MODIFIED_OGRE
270                //virtual uchar *getBufferContents(int &dimx, int &dimy) = 0;
271#endif // GTP_VISIBILITY_MODIFIED_OGRE
272
273
274        /** Writes the current contents of the render target to the (PREFIX)(time-stamp)(SUFFIX) file.
275                @returns the name of the file used.*/
276        virtual String writeContentsToTimestampedFile(const String& filenamePrefix, const String& filenameSuffix);
277
278                virtual bool requiresTextureFlipping() const = 0;
279
280                /** Gets the number of triangles rendered in the last update() call. */
281                virtual size_t getTriangleCount(void) const;
282        /** Utility method to notify a render target that a camera has been removed,
283        incase it was referring to it as a viewer.
284        */
285        virtual void _notifyCameraRemoved(const Camera* cam);
286
287        /** Indicates whether this target is the primary window. The
288            primary window is special in that it is destroyed when
289            ogre is shut down, and cannot be destroyed directly.
290            This is the case because it holds the context for vertex,
291            index buffers and textures.
292        */
293        virtual bool isPrimary(void) const;
294
295
296        /** RenderSystem specific interface for a RenderTarget;
297            this should be subclassed by RenderSystems.
298        */
299        class Impl
300        {
301        protected:
302            /** Declared protected as interface is never used for destruction.
303                gcc will issue a warning here: `class Impl' has virtual functions
304                but non-virtual destructor. This is no problem because this interface
305                is never used to delete an object.
306            */
307            ~Impl() { };
308        };
309        /** Get rendersystem specific interface for this RenderTarget.
310            This is used by the RenderSystem to (un)bind this target,
311            and to get specific information like surfaces
312            and framebuffer objects.
313        */
314        virtual Impl *_getImpl();
315    protected:
316        /// The name of this target.
317        String mName;
318                /// The priority of the render target.
319                uchar mPriority;
320
321        unsigned int mWidth;
322        unsigned int mHeight;
323        unsigned int mColourDepth;
324        bool mIsDepthBuffered;
325
326        // Stats
327                FrameStats mStats;
328       
329        Timer* mTimer ;
330        String mDebugText;
331        unsigned long mLastSecond;
332        unsigned long mLastTime;
333        size_t mFrameCount;
334
335        bool mActive;
336        bool mAutoUpdate;
337
338        void updateStats(void);
339
340        typedef std::map<int, Viewport*, std::less<int> > ViewportList;
341        /// List of viewports, map on Z-order
342        ViewportList mViewportList;
343
344        typedef std::vector<RenderTargetListener*> RenderTargetListenerList;
345        RenderTargetListenerList mListeners;
346       
347
348        /// internal method for firing events
349        virtual void firePreUpdate(void);
350        /// internal method for firing events
351        virtual void firePostUpdate(void);
352        /// internal method for firing events
353        virtual void fireViewportPreUpdate(Viewport* vp);
354        /// internal method for firing events
355        virtual void fireViewportPostUpdate(Viewport* vp);
356                /// internal method for firing events
357                virtual void fireViewportAdded(Viewport* vp);
358                /// internal method for firing events
359                virtual void fireViewportRemoved(Viewport* vp);
360
361#ifdef GAMETOOLS_ILLUMINATION_MODULE
362                public:
363                        unsigned long getLastFrameNumber(){return lastFrame;}
364                protected:
365                        unsigned long lastFrame;
366#endif
367
368    };
369
370} // Namespace
371
372#endif
Note: See TracBrowser for help on using the repository browser.