OgreRenderTarget.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE 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 
46 namespace Ogre {
47 
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 
92  {
95  FB_AUTO
96  };
97 
98  RenderTarget();
99  virtual ~RenderTarget();
100 
102  virtual const String& getName(void) const;
103 
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 
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 
134  virtual void _detachDepthBuffer();
135 
158  virtual void update(bool swapBuffers = true);
167  virtual void swapBuffers() {}
168 
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 
196  virtual unsigned short getNumViewports(void) const;
197 
199  virtual Viewport* getViewport(unsigned short index);
200 
204  virtual Viewport* getViewportByZOrder(int ZOrder);
205 
207  virtual bool hasViewportWithZOrder(int ZOrder);
208 
211  virtual void removeViewport(int ZOrder);
212 
215  virtual void removeAllViewports(void);
216 
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 
242  virtual float getLastFPS() const;
243 
246  virtual float getAverageFPS() const;
247 
250  virtual float getBestFPS() const;
251 
254  virtual float getWorstFPS() const;
255 
258  virtual float getBestFrameTime() const;
259 
262  virtual float getWorstFrameTime() const;
263 
266  virtual void resetStatistics(void);
267 
277  virtual void getCustomAttribute(const String& name, void* pData);
278 
287  virtual void addListener(RenderTargetListener* listener);
289  virtual void removeListener(RenderTargetListener* listener);
291  virtual void removeAllListeners(void);
292 
300  virtual void setPriority( uchar priority ) { mPriority = priority; }
302  virtual uchar getPriority() const { return mPriority; }
303 
306  virtual bool isActive() const;
307 
310  virtual void setActive( bool state );
311 
323  virtual void setAutoUpdated(bool autoupdate);
327  virtual bool isAutoUpdated(void) const;
328 
334  virtual void copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer = FB_AUTO) = 0;
335 
339  virtual PixelFormat suggestPixelFormat() const { return PF_BYTE_RGBA; }
340 
342  void writeContentsToFile(const String& filename);
343 
346  virtual String writeContentsToTimestampedFile(const String& filenamePrefix, const String& filenameSuffix);
347 
348  virtual bool requiresTextureFlipping() const = 0;
349 
351  virtual size_t getTriangleCount(void) const;
353  virtual size_t getBatchCount(void) const;
357  virtual void _notifyCameraRemoved(const Camera* cam);
358 
365  virtual bool isPrimary(void) const;
366 
374  virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
375 
378  virtual uint getFSAA() const { return mFSAA; }
379 
382  virtual const String& getFSAAHint() const { return mFSAAHint; }
383 
387  class Impl
388  {
389  protected:
390  ~Impl() { }
391  };
397  virtual Impl *_getImpl();
398 
422  virtual void _beginUpdate();
423 
433  virtual void _updateViewport(int zorder, bool updateStatistics = true);
434 
443  virtual void _updateViewport(Viewport* viewport, bool updateStatistics = true);
444 
453  virtual void _updateAutoUpdatedViewports(bool updateStatistics = true);
454 
461  virtual void _endUpdate();
462 
463  protected:
468 
474 
475  // Stats
477 
479  unsigned long mLastSecond;
480  unsigned long mLastTime;
481  size_t mFrameCount;
482 
483  bool mActive;
485  // Hardware sRGB gamma conversion done on write?
486  bool mHwGamma;
487  // FSAA performed?
490 
491  void updateStats(void);
492 
496 
499 
500 
502  virtual void firePreUpdate(void);
504  virtual void firePostUpdate(void);
506  virtual void fireViewportPreUpdate(Viewport* vp);
508  virtual void fireViewportPostUpdate(Viewport* vp);
510  virtual void fireViewportAdded(Viewport* vp);
512  virtual void fireViewportRemoved(Viewport* vp);
513 
515  virtual void updateImpl();
516  };
520 } // Namespace
521 
522 #include "OgreHeaderSuffix.h"
523 
524 #endif
OgreHeaderSuffix.h
Ogre::RenderTarget::mListeners
RenderTargetListenerList mListeners
Definition: OgreRenderTarget.h:498
Ogre::RenderTarget::mViewportList
ViewportList mViewportList
List of viewports, map on Z-order.
Definition: OgreRenderTarget.h:495
Ogre::RenderTarget::mActive
bool mActive
Definition: OgreRenderTarget.h:483
Ogre::RenderTarget::StatFlags
StatFlags
Definition: OgreRenderTarget.h:68
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::RenderTarget::FB_BACK
Definition: OgreRenderTarget.h:94
Ogre::DepthBuffer
An abstract class that contains a depth/stencil buffer.
Definition: OgreDepthBuffer.h:82
Ogre::RenderTarget::FrameStats::worstFrameTime
unsigned long worstFrameTime
Definition: OgreRenderTarget.h:86
Ogre::RenderTarget::mStats
FrameStats mStats
Definition: OgreRenderTarget.h:476
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::Camera
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
Ogre::RenderTarget::getFSAAHint
virtual const String & getFSAAHint() const
Gets the FSAA hint (.
Definition: OgreRenderTarget.h:382
Ogre::RenderTarget::FrameStats::triangleCount
size_t triangleCount
Definition: OgreRenderTarget.h:87
Ogre::PF_BYTE_RGBA
4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha
Definition: OgrePixelFormat.h:105
Ogre::RenderTarget::isHardwareGammaEnabled
virtual bool isHardwareGammaEnabled() const
Indicates whether on rendering, linear colour space is converted to sRGB gamma colour space.
Definition: OgreRenderTarget.h:374
OgreViewport.h
Ogre::RenderTarget::mColourDepth
uint32 mColourDepth
Definition: OgreRenderTarget.h:471
OgreTimer.h
Ogre::RenderTarget::mTimer
Timer * mTimer
Definition: OgreRenderTarget.h:478
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::RenderTarget::FrameStats::lastFPS
float lastFPS
Definition: OgreRenderTarget.h:81
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::RenderTarget::mName
String mName
The name of this target.
Definition: OgreRenderTarget.h:465
Ogre::RenderTarget::FrameStats::avgFPS
float avgFPS
Definition: OgreRenderTarget.h:82
Ogre::RenderTarget::mHeight
uint32 mHeight
Definition: OgreRenderTarget.h:470
Ogre::RenderTarget::getFSAA
virtual uint getFSAA() const
Indicates whether multisampling is performed on rendering and at what level.
Definition: OgreRenderTarget.h:378
Ogre::Timer
Timer class.
Definition: Android/OgreTimerImp.h:37
Ogre::RenderTarget::mHwGamma
bool mHwGamma
Definition: OgreRenderTarget.h:486
Ogre::RenderTarget::mWidth
uint32 mWidth
Definition: OgreRenderTarget.h:469
Ogre::RenderTargetListener
A interface class defining a listener which can be used to receive notifications of RenderTarget even...
Definition: OgreRenderTargetListener.h:77
OgreHeaderPrefix.h
Ogre::RenderTarget
A 'canvas' which can receive the results of a rendering operation.
Definition: OgreRenderTarget.h:65
Ogre::PixelFormat
PixelFormat
The pixel format used for images, textures, and render surfaces.
Definition: OgrePixelFormat.h:43
Ogre::RenderTarget::RenderTargetListenerList
vector< RenderTargetListener * >::type RenderTargetListenerList
Definition: OgreRenderTarget.h:497
Ogre::Viewport
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:57
Ogre::RenderTarget::mDepthBufferPoolId
uint16 mDepthBufferPoolId
Definition: OgreRenderTarget.h:472
Ogre::RenderTarget::mLastSecond
unsigned long mLastSecond
Definition: OgreRenderTarget.h:479
OgrePrerequisites.h
Ogre::uchar
unsigned char uchar
In order to avoid finger-aches :)
Definition: OgrePrerequisites.h:112
Ogre::RenderTarget::ViewportList
map< int, Viewport * >::type ViewportList
Definition: OgreRenderTarget.h:493
Ogre::RenderTarget::mFSAAHint
String mFSAAHint
Definition: OgreRenderTarget.h:489
Ogre::RenderTarget::FrameStats::bestFPS
float bestFPS
Definition: OgreRenderTarget.h:83
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::RenderTarget::FrameBuffer
FrameBuffer
Definition: OgreRenderTarget.h:91
Ogre::RenderTarget::mDepthBuffer
DepthBuffer * mDepthBuffer
Definition: OgreRenderTarget.h:473
Ogre::RenderTarget::mFrameCount
size_t mFrameCount
Definition: OgreRenderTarget.h:481
Ogre::RenderTarget::getPriority
virtual uchar getPriority() const
Gets the priority of a render target.
Definition: OgreRenderTarget.h:302
Ogre::RenderTarget::FrameStats::batchCount
size_t batchCount
Definition: OgreRenderTarget.h:88
OgreTextureManager.h
Ogre::uint
unsigned int uint
Definition: OgrePrerequisites.h:114
Ogre::RenderTarget::mLastTime
unsigned long mLastTime
Definition: OgreRenderTarget.h:480
Ogre::PixelBox
A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
Definition: OgrePixelFormat.h:304
Ogre::RenderTarget::FB_FRONT
Definition: OgreRenderTarget.h:93
Ogre::RenderTarget::FrameStats
Definition: OgreRenderTarget.h:79
Ogre::RenderTarget::Impl
RenderSystem specific interface for a RenderTarget; this should be subclassed by RenderSystems.
Definition: OgreRenderTarget.h:387
Ogre::RenderTarget::mFSAA
uint mFSAA
Definition: OgreRenderTarget.h:488
Ogre::RenderTarget::mPriority
uchar mPriority
The priority of the render target.
Definition: OgreRenderTarget.h:467
Ogre::RenderTarget::setPriority
virtual void setPriority(uchar priority)
Sets the priority of this render target in relation to the others.
Definition: OgreRenderTarget.h:300
Ogre::RenderTarget::Impl::~Impl
~Impl()
Definition: OgreRenderTarget.h:390
Ogre::RenderTarget::FrameStats::bestFrameTime
unsigned long bestFrameTime
Definition: OgreRenderTarget.h:85
Ogre::RenderTarget::mAutoUpdate
bool mAutoUpdate
Definition: OgreRenderTarget.h:484
OgreString.h
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::RenderTarget::FrameStats::worstFPS
float worstFPS
Definition: OgreRenderTarget.h:84
Ogre::RenderTarget::suggestPixelFormat
virtual PixelFormat suggestPixelFormat() const
Suggests a pixel format to use for extracting the data in this target, when calling copyContentsToMem...
Definition: OgreRenderTarget.h:339
Ogre::RenderTarget::swapBuffers
virtual void swapBuffers()
Swaps the frame buffers to display the next frame.
Definition: OgreRenderTarget.h:167

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.