Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreRenderTarget.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 21.5 KB
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-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __RenderTarget_H__
29#define __RenderTarget_H__
30
31#include "OgrePrerequisites.h"
32
33#include "OgreString.h"
34#include "OgreTextureManager.h"
35#include "OgreViewport.h"
36#include "OgreTimer.h"
37#include "OgreHeaderPrefix.h"
38
39/* Define the number of priority groups for the render system's render targets. */
40#ifndef OGRE_NUM_RENDERTARGET_GROUPS
41        #define OGRE_NUM_RENDERTARGET_GROUPS 10
42        #define OGRE_DEFAULT_RT_GROUP 4
43        #define OGRE_REND_TO_TEX_RT_GROUP 2
44#endif
45
46namespace Ogre {
47
48        /** \addtogroup Core
49        *  @{
50        */
51        /** \addtogroup RenderSystem
52        *  @{
53        */
54        /** A 'canvas' which can receive the results of a rendering
55        operation.
56        @remarks
57            This abstract class defines a common root to all targets of rendering operations. A
58            render target could be a window on a screen, or another
59            offscreen surface like a texture or bump map etc.
60        @author
61            Steven Streeting
62        @version
63            1.0
64     */
65    class _OgreExport RenderTarget : public RenderSysAlloc
66    {
67    public:
68        enum StatFlags
69        {
70            SF_NONE           = 0,
71            SF_FPS            = 1,
72            SF_AVG_FPS        = 2,
73            SF_BEST_FPS       = 4,
74            SF_WORST_FPS      = 8,
75            SF_TRIANGLE_COUNT = 16,
76            SF_ALL            = 0xFFFF
77        };
78
79        struct FrameStats
80        {
81            float lastFPS;
82            float avgFPS;
83            float bestFPS;
84            float worstFPS;
85            unsigned long bestFrameTime;
86            unsigned long worstFrameTime;
87            size_t triangleCount;
88            size_t batchCount;
89        };
90
91                enum FrameBuffer
92                {
93                        FB_FRONT,
94                        FB_BACK,
95                        FB_AUTO
96                };
97
98        RenderTarget();
99        virtual ~RenderTarget();
100
101        /// Retrieve target's name.
102        virtual const String& getName(void) const;
103
104        /// Retrieve information about the render target.
105        virtual void getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth);
106
107        virtual uint32 getWidth(void) const;
108        virtual uint32 getHeight(void) const;
109        virtual uint32 getColourDepth(void) const;
110
111                /**
112                 * Sets the pool ID this RenderTarget should query from. Default value is POOL_DEFAULT.
113                 * Set to POOL_NO_DEPTH to avoid using a DepthBuffer (or manually controlling it) @see DepthBuffer
114                 *      @remarks
115                 *              Changing the pool Id will cause the current depth buffer to be detached unless the old
116                 *              id and the new one are the same
117                 */
118                void setDepthBufferPool( uint16 poolId );
119
120                //Returns the pool ID this RenderTarget should query from. @see DepthBuffer
121                uint16 getDepthBufferPool() const;
122
123                DepthBuffer* getDepthBuffer() const;
124
125                //Returns false if couldn't attach
126                virtual bool attachDepthBuffer( DepthBuffer *depthBuffer );
127
128                virtual void detachDepthBuffer();
129
130                /** Detaches DepthBuffer without notifying it from the detach.
131                        Useful when called from the DepthBuffer while it iterates through attached
132                        RenderTargets (@see DepthBuffer::_setPoolId())
133                */
134                virtual void _detachDepthBuffer();
135
136        /** Tells the target to update it's contents.
137            @remarks
138                If OGRE is not running in an automatic rendering loop
139                (started using Root::startRendering),
140                the user of the library is responsible for asking each render
141                target to refresh. This is the method used to do this. It automatically
142                re-renders the contents of the target using whatever cameras have been
143                pointed at it (using Camera::setRenderTarget).
144            @par
145                This allows OGRE to be used in multi-windowed utilities
146                and for contents to be refreshed only when required, rather than
147                constantly as with the automatic rendering loop.
148                        @param swapBuffers For targets that support double-buffering, if set
149                                to true, the target will immediately
150                                swap it's buffers after update. Otherwise, the buffers are
151                                not swapped, and you have to call swapBuffers yourself sometime
152                                later. You might want to do this on some rendersystems which
153                                pause for queued rendering commands to complete before accepting
154                                swap buffers calls - so you could do other CPU tasks whilst the
155                                queued commands complete. Or, you might do this if you want custom
156                                control over your windows, such as for externally created windows.
157        */
158        virtual void update(bool swapBuffers = true);
159        /** Swaps the frame buffers to display the next frame.
160            @remarks
161                For targets that are double-buffered so that no
162                'in-progress' versions of the scene are displayed
163                during rendering. Once rendering has completed (to
164                an off-screen version of the window) the buffers
165                are swapped to display the new frame.
166        */
167        virtual void swapBuffers() {}
168
169        /** Adds a viewport to the rendering target.
170            @remarks
171                A viewport is the rectangle into which rendering output is sent. This method adds
172                a viewport to the render target, rendering from the supplied camera. The
173                rest of the parameters are only required if you wish to add more than one viewport
174                to a single rendering target. Note that size information passed to this method is
175                passed as a parametric, i.e. it is relative rather than absolute. This is to allow
176                viewports to automatically resize along with the target.
177            @param
178                cam The camera from which the viewport contents will be rendered (mandatory)
179            @param
180                ZOrder The relative order of the viewport with others on the target (allows overlapping
181                viewports i.e. picture-in-picture). Higher Z-orders are on top of lower ones. The actual number
182                is irrelevant, only the relative Z-order matters (you can leave gaps in the numbering)
183            @param
184                left The relative position of the left of the viewport on the target, as a value between 0 and 1.
185            @param
186                top The relative position of the top of the viewport on the target, as a value between 0 and 1.
187            @param
188                width The relative width of the viewport on the target, as a value between 0 and 1.
189            @param
190                height The relative height of the viewport on the target, as a value between 0 and 1.
191        */
192        virtual Viewport* addViewport(Camera* cam, int ZOrder = 0, float left = 0.0f, float top = 0.0f ,
193            float width = 1.0f, float height = 1.0f);
194
195        /** Returns the number of viewports attached to this target.*/
196        virtual unsigned short getNumViewports(void) const;
197
198        /** Retrieves a pointer to the viewport with the given index. */
199        virtual Viewport* getViewport(unsigned short index);
200
201                /** Retrieves a pointer to the viewport with the given Z-order.
202                        @remarks throws if not found.
203                */
204        virtual Viewport* getViewportByZOrder(int ZOrder);
205
206                /** Returns true if and only if a viewport exists at the given Z-order. */
207                virtual bool hasViewportWithZOrder(int ZOrder);
208
209        /** Removes a viewport at a given Z-order.
210        */
211        virtual void removeViewport(int ZOrder);
212
213        /** Removes all viewports on this target.
214        */
215        virtual void removeAllViewports(void);
216
217        /** Retieves details of current rendering performance.
218            @remarks
219                If the user application wishes to do it's own performance
220                display, or use performance for some other means, this
221                method allows it to retrieve the statistics.
222                @param
223                    lastFPS Pointer to a float to receive the number of frames per second (FPS)
224                    based on the last frame rendered.
225                @param
226                    avgFPS Pointer to a float to receive the FPS rating based on an average of all
227                    the frames rendered since rendering began (the call to
228                    Root::startRendering).
229                @param
230                    bestFPS Pointer to a float to receive the best FPS rating that has been achieved
231                    since rendering began.
232                @param
233                    worstFPS Pointer to a float to receive the worst FPS rating seen so far.
234        */
235        virtual void getStatistics(float& lastFPS, float& avgFPS,
236            float& bestFPS, float& worstFPS) const;  // Access to stats
237
238        virtual const FrameStats& getStatistics(void) const;
239
240        /** Individual stats access - gets the number of frames per second (FPS) based on the last frame rendered.
241        */
242        virtual float getLastFPS() const;
243
244        /** Individual stats access - gets the average frames per second (FPS) since call to Root::startRendering.
245        */
246        virtual float getAverageFPS() const;
247
248        /** Individual stats access - gets the best frames per second (FPS) since call to Root::startRendering.
249        */
250        virtual float getBestFPS() const;
251
252        /** Individual stats access - gets the worst frames per second (FPS) since call to Root::startRendering.
253        */
254        virtual float getWorstFPS() const;
255
256        /** Individual stats access - gets the best frame time
257        */
258        virtual float getBestFrameTime() const;
259
260        /** Individual stats access - gets the worst frame time
261        */
262        virtual float getWorstFrameTime() const;
263
264        /** Resets saved frame-rate statistices.
265        */
266        virtual void resetStatistics(void);
267
268        /** Gets a custom (maybe platform-specific) attribute.
269            @remarks
270                This is a nasty way of satisfying any API's need to see platform-specific details.
271                It horrid, but D3D needs this kind of info. At least it's abstracted.
272            @param
273                name The name of the attribute.
274            @param
275                pData Pointer to memory of the right kind of structure to receive the info.
276        */
277        virtual void getCustomAttribute(const String& name, void* pData);
278
279        /** Add a listener to this RenderTarget which will be called back before & after rendering.
280        @remarks
281            If you want notifications before and after a target is updated by the system, use
282            this method to register your own custom RenderTargetListener class. This is useful
283            for potentially adding your own manual rendering commands before and after the
284            'normal' system rendering.
285        @par NB this should not be used for frame-based scene updates, use Root::addFrameListener for that.
286        */
287        virtual void addListener(RenderTargetListener* listener);
288        /** Removes a RenderTargetListener previously registered using addListener. */
289        virtual void removeListener(RenderTargetListener* listener);
290        /** Removes all listeners from this instance. */
291        virtual void removeAllListeners(void);
292
293                /** Sets the priority of this render target in relation to the others.
294        @remarks
295            This can be used in order to schedule render target updates. Lower
296            priorities will be rendered first. Note that the priority must be set
297            at the time the render target is attached to the render system, changes
298            afterwards will not affect the ordering.
299        */
300        virtual void setPriority( uchar priority ) { mPriority = priority; }
301        /** Gets the priority of a render target. */
302                virtual uchar getPriority() const { return mPriority; }
303
304        /** Used to retrieve or set the active state of the render target.
305        */
306        virtual bool isActive() const;
307
308        /** Used to set the active state of the render target.
309        */
310        virtual void setActive( bool state );
311
312        /** Sets whether this target should be automatically updated if Ogre's rendering
313            loop or Root::_updateAllRenderTargets is being used.
314        @remarks
315            By default, if you use Ogre's own rendering loop (Root::startRendering)
316            or call Root::_updateAllRenderTargets, all render targets are updated
317            automatically. This method allows you to control that behaviour, if
318            for example you have a render target which you only want to update periodically.
319        @param autoupdate If true, the render target is updated during the automatic render
320            loop or when Root::_updateAllRenderTargets is called. If false, the
321            target is only updated when its update() method is called explicitly.
322        */
323        virtual void setAutoUpdated(bool autoupdate);
324        /** Gets whether this target is automatically updated if Ogre's rendering
325            loop or Root::_updateAllRenderTargets is being used.
326        */
327        virtual bool isAutoUpdated(void) const;
328
329                /** Copies the current contents of the render target to a pixelbox.
330                @remarks See suggestPixelFormat for a tip as to the best pixel format to
331                        extract into, although you can use whatever format you like and the
332                        results will be converted.
333                */
334                virtual void copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer = FB_AUTO) = 0;
335
336                /** Suggests a pixel format to use for extracting the data in this target,
337                        when calling copyContentsToMemory.
338                */
339                virtual PixelFormat suggestPixelFormat() const { return PF_BYTE_RGBA; }
340               
341        /** Writes the current contents of the render target to the named file. */
342        void writeContentsToFile(const String& filename);
343
344                /** Writes the current contents of the render target to the (PREFIX)(time-stamp)(SUFFIX) file.
345                        @return the name of the file used.*/
346                virtual String writeContentsToTimestampedFile(const String& filenamePrefix, const String& filenameSuffix);
347
348                virtual bool requiresTextureFlipping() const = 0;
349
350                /** Gets the number of triangles rendered in the last update() call. */
351                virtual size_t getTriangleCount(void) const;
352        /** Gets the number of batches rendered in the last update() call. */
353                virtual size_t getBatchCount(void) const;
354        /** Utility method to notify a render target that a camera has been removed,
355        incase it was referring to it as a viewer.
356        */
357        virtual void _notifyCameraRemoved(const Camera* cam);
358
359        /** Indicates whether this target is the primary window. The
360            primary window is special in that it is destroyed when
361            ogre is shut down, and cannot be destroyed directly.
362            This is the case because it holds the context for vertex,
363            index buffers and textures.
364        */
365        virtual bool isPrimary(void) const;
366
367                /** Indicates whether on rendering, linear colour space is converted to
368                        sRGB gamma colour space. This is the exact opposite conversion of
369                        what is indicated by Texture::isHardwareGammaEnabled, and can only
370                        be enabled on creation of the render target. For render windows, it's
371                        enabled through the 'gamma' creation misc parameter. For textures,
372                        it is enabled through the hwGamma parameter to the create call.
373                */
374                virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
375
376                /** Indicates whether multisampling is performed on rendering and at what level.
377                */
378                virtual uint getFSAA() const { return mFSAA; }
379
380                /** Gets the FSAA hint (@see Root::createRenderWindow)
381                */
382                virtual const String& getFSAAHint() const { return mFSAAHint; }
383
384        /** RenderSystem specific interface for a RenderTarget;
385            this should be subclassed by RenderSystems.
386        */
387        class Impl
388        {
389        protected:
390            ~Impl() { }
391        };
392        /** Get rendersystem specific interface for this RenderTarget.
393            This is used by the RenderSystem to (un)bind this target,
394            and to get specific information like surfaces
395            and framebuffer objects.
396        */
397        virtual Impl *_getImpl();
398
399                /** Method for manual management of rendering : fires 'preRenderTargetUpdate'
400                        and initialises statistics etc.
401                @remarks
402                <ul>
403                <li>_beginUpdate resets statistics and fires 'preRenderTargetUpdate'.</li>
404                <li>_updateViewport renders the given viewport (even if it is not autoupdated),
405                fires preViewportUpdate and postViewportUpdate and manages statistics.</li>
406                <li>_updateAutoUpdatedViewports renders only viewports that are auto updated,
407                fires preViewportUpdate and postViewportUpdate and manages statistics.</li>
408                <li>_endUpdate() ends statistics calculation and fires postRenderTargetUpdate.</li>
409                </ul>
410                you can use it like this for example :
411                <pre>
412                        renderTarget->_beginUpdate();
413                        renderTarget->_updateViewport(1); // which is not auto updated
414                        renderTarget->_updateViewport(2); // which is not auto updated
415                        renderTarget->_updateAutoUpdatedViewports();
416                        renderTarget->_endUpdate();
417                        renderTarget->swapBuffers();
418                </pre>
419                        Please note that in that case, the zorder may not work as you expect,
420                        since you are responsible for calling _updateViewport in the correct order.
421        */
422                virtual void _beginUpdate();
423
424                /** Method for manual management of rendering - renders the given
425                viewport (even if it is not autoupdated)
426                @remarks
427                This also fires preViewportUpdate and postViewportUpdate, and manages statistics.
428                You should call it between _beginUpdate() and _endUpdate().
429                @see _beginUpdate for more details.
430                @param zorder The zorder of the viewport to update.
431                @param updateStatistics Whether you want to update statistics or not.
432                */
433                virtual void _updateViewport(int zorder, bool updateStatistics = true);
434
435                /** Method for manual management of rendering - renders the given viewport (even if it is not autoupdated)
436                @remarks
437                This also fires preViewportUpdate and postViewportUpdate, and manages statistics
438                if needed. You should call it between _beginUpdate() and _endUpdate().
439                @see _beginUpdate for more details.
440                @param viewport The viewport you want to update, it must be bound to the rendertarget.
441                @param updateStatistics Whether you want to update statistics or not.
442                */
443                virtual void _updateViewport(Viewport* viewport, bool updateStatistics = true);
444
445                /** Method for manual management of rendering - renders only viewports that are auto updated
446                @remarks
447                This also fires preViewportUpdate and postViewportUpdate, and manages statistics.
448                You should call it between _beginUpdate() and _endUpdate().
449                See _beginUpdate for more details.
450                @param updateStatistics Whether you want to update statistics or not.
451                @see _beginUpdate()
452                */
453                virtual void _updateAutoUpdatedViewports(bool updateStatistics = true);
454               
455                /** Method for manual management of rendering - finishes statistics calculation
456                        and fires 'postRenderTargetUpdate'.
457                @remarks
458                You should call it after a _beginUpdate
459                @see _beginUpdate for more details.
460                */
461                virtual void _endUpdate();
462
463    protected:
464        /// The name of this target.
465        String mName;
466                /// The priority of the render target.
467                uchar mPriority;
468
469        uint32 mWidth;
470        uint32 mHeight;
471        uint32 mColourDepth;
472                uint16           mDepthBufferPoolId;
473        DepthBuffer     *mDepthBuffer;
474
475        // Stats
476                FrameStats mStats;
477       
478        Timer* mTimer ;
479        unsigned long mLastSecond;
480        unsigned long mLastTime;
481        size_t mFrameCount;
482
483        bool mActive;
484        bool mAutoUpdate;
485                // Hardware sRGB gamma conversion done on write?
486                bool mHwGamma;
487                // FSAA performed?
488                uint mFSAA;
489                String mFSAAHint;
490
491        void updateStats(void);
492
493                typedef map<int, Viewport*>::type ViewportList;
494        /// List of viewports, map on Z-order
495        ViewportList mViewportList;
496
497        typedef vector<RenderTargetListener*>::type RenderTargetListenerList;
498        RenderTargetListenerList mListeners;
499       
500
501        /// internal method for firing events
502        virtual void firePreUpdate(void);
503        /// internal method for firing events
504        virtual void firePostUpdate(void);
505        /// internal method for firing events
506        virtual void fireViewportPreUpdate(Viewport* vp);
507        /// internal method for firing events
508        virtual void fireViewportPostUpdate(Viewport* vp);
509                /// internal method for firing events
510                virtual void fireViewportAdded(Viewport* vp);
511                /// internal method for firing events
512                virtual void fireViewportRemoved(Viewport* vp);
513               
514                /// Internal implementation of update()
515                virtual void updateImpl();
516    };
517        /** @} */
518        /** @} */
519
520} // Namespace
521
522#include "OgreHeaderSuffix.h"
523
524#endif
Note: See TracBrowser for help on using the repository browser.