OgreRenderTarget.h
Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __RenderTarget_H__
    00029 #define __RenderTarget_H__
    00030
    00031 #include "OgrePrerequisites.h"
    00032
    00033 #include "OgreString.h"
    00034 #include "OgreTextureManager.h"
    00035 #include "OgreViewport.h"
    00036 #include "OgreTimer.h"
    00037
    00038 /* Define the number of priority groups for the render system's render targets. */
    00039 #ifndef OGRE_NUM_RENDERTARGET_GROUPS
    00040     #define OGRE_NUM_RENDERTARGET_GROUPS 10
    00041     #define OGRE_DEFAULT_RT_GROUP 4
    00042     #define OGRE_REND_TO_TEX_RT_GROUP 2
    00043 #endif
    00044
    00045 namespace Ogre {
    00046
    00064     class _OgreExport RenderTarget : public RenderSysAlloc
    00065     {
    00066     public:
    00067         enum StatFlags
    00068         {
    00069             SF_NONE           = 0,
    00070             SF_FPS            = 1,
    00071             SF_AVG_FPS        = 2,
    00072             SF_BEST_FPS       = 4,
    00073             SF_WORST_FPS      = 8,
    00074             SF_TRIANGLE_COUNT = 16,
    00075             SF_ALL            = 0xFFFF
    00076         };
    00077
    00078         struct FrameStats
    00079         {
    00080             float lastFPS;
    00081             float avgFPS;
    00082             float bestFPS;
    00083             float worstFPS;
    00084             unsigned long bestFrameTime;
    00085             unsigned long worstFrameTime;
    00086             size_t triangleCount;
    00087             size_t batchCount;
    00088         };
    00089
    00090         enum FrameBuffer
    00091         {
    00092             FB_FRONT,
    00093             FB_BACK,
    00094             FB_AUTO
    00095         };
    00096
    00097         RenderTarget();
    00098         virtual ~RenderTarget();
    00099
    00101         virtual const String& getName(void) const;
    00102
    00104         virtual void getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth);
    00105
    00106         virtual unsigned int getWidth(void) const;
    00107         virtual unsigned int getHeight(void) const;
    00108         virtual unsigned int getColourDepth(void) const;
    00109
    00117         void setDepthBufferPool( uint16 poolId );
    00118
    00119         //Returns the pool ID this RenderTarget should query from. @see DepthBuffer
    00120         uint16 getDepthBufferPool() const;
    00121
    00122         DepthBuffer* getDepthBuffer() const;
    00123
    00124         //Returns false if couldn't attach
    00125         virtual bool attachDepthBuffer( DepthBuffer *depthBuffer );
    00126
    00127         virtual void detachDepthBuffer();
    00128
    00133         virtual void _detachDepthBuffer();
    00134
    00157         virtual void update(bool swapBuffers = true);
    00178         virtual void swapBuffers(bool waitForVSync = true)
    00179         { (void)waitForVSync; }
    00180
    00204         virtual Viewport* addViewport(Camera* cam, int ZOrder = 0, float left = 0.0f, float top = 0.0f ,
    00205             float width = 1.0f, float height = 1.0f);
    00206
    00208         virtual unsigned short getNumViewports(void) const;
    00209
    00211         virtual Viewport* getViewport(unsigned short index);
    00212
    00216         virtual Viewport* getViewportByZOrder(int ZOrder);
    00217
    00219         virtual bool hasViewportWithZOrder(int ZOrder);
    00220
    00223         virtual void removeViewport(int ZOrder);
    00224
    00227         virtual void removeAllViewports(void);
    00228
    00247         virtual void getStatistics(float& lastFPS, float& avgFPS,
    00248             float& bestFPS, float& worstFPS) const;  // Access to stats
    00249
    00250         virtual const FrameStats& getStatistics(void) const;
    00251
    00254         virtual float getLastFPS() const;
    00255
    00258         virtual float getAverageFPS() const;
    00259
    00262         virtual float getBestFPS() const;
    00263
    00266         virtual float getWorstFPS() const;
    00267
    00270         virtual float getBestFrameTime() const;
    00271
    00274         virtual float getWorstFrameTime() const;
    00275
    00278         virtual void resetStatistics(void);
    00279
    00289         virtual void getCustomAttribute(const String& name, void* pData);
    00290
    00299         virtual void addListener(RenderTargetListener* listener);
    00301         virtual void removeListener(RenderTargetListener* listener);
    00303         virtual void removeAllListeners(void);
    00304
    00312         virtual void setPriority( uchar priority ) { mPriority = priority; }
    00314         virtual uchar getPriority() const { return mPriority; }
    00315
    00318         virtual bool isActive() const;
    00319
    00322         virtual void setActive( bool state );
    00323
    00335         virtual void setAutoUpdated(bool autoupdate);
    00339         virtual bool isAutoUpdated(void) const;
    00340
    00346         virtual void copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer = FB_AUTO) = 0;
    00347
    00351         virtual PixelFormat suggestPixelFormat() const { return PF_BYTE_RGBA; }
    00352
    00354         void writeContentsToFile(const String& filename);
    00355
    00358         virtual String writeContentsToTimestampedFile(const String& filenamePrefix, const String& filenameSuffix);
    00359
    00360         virtual bool requiresTextureFlipping() const = 0;
    00361
    00363         virtual size_t getTriangleCount(void) const;
    00365         virtual size_t getBatchCount(void) const;
    00369         virtual void _notifyCameraRemoved(const Camera* cam);
    00370
    00377         virtual bool isPrimary(void) const;
    00378
    00386         virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
    00387
    00390         virtual uint getFSAA() const { return mFSAA; }
    00391
    00394         virtual const String& getFSAAHint() const { return mFSAAHint; }
    00395
    00399         class Impl
    00400         {
    00401         protected:
    00402             ~Impl() { }
    00403         };
    00409         virtual Impl *_getImpl();
    00410
    00434         virtual void _beginUpdate();
    00435
    00445         virtual void _updateViewport(int zorder, bool updateStatistics = true);
    00446
    00455         virtual void _updateViewport(Viewport* viewport, bool updateStatistics = true);
    00456
    00465         virtual void _updateAutoUpdatedViewports(bool updateStatistics = true);
    00466
    00473         virtual void _endUpdate();
    00474
    00475     protected:
    00477         String mName;
    00479         uchar mPriority;
    00480
    00481         unsigned int mWidth;
    00482         unsigned int mHeight;
    00483         unsigned int mColourDepth;
    00484         uint16       mDepthBufferPoolId;
    00485         DepthBuffer *mDepthBuffer;
    00486
    00487         // Stats
    00488         FrameStats mStats;
    00489
    00490         Timer* mTimer ;
    00491         unsigned long mLastSecond;
    00492         unsigned long mLastTime;
    00493         size_t mFrameCount;
    00494
    00495         bool mActive;
    00496         bool mAutoUpdate;
    00497         // Hardware sRGB gamma conversion done on write?
    00498         bool mHwGamma;
    00499         // FSAA performed?
    00500         uint mFSAA;
    00501         String mFSAAHint;
    00502
    00503         void updateStats(void);
    00504
    00505         typedef map<int, Viewport*>::type ViewportList;
    00507         ViewportList mViewportList;
    00508
    00509         typedef vector<RenderTargetListener*>::type RenderTargetListenerList;
    00510         RenderTargetListenerList mListeners;
    00511
    00512
    00514         virtual void firePreUpdate(void);
    00516         virtual void firePostUpdate(void);
    00518         virtual void fireViewportPreUpdate(Viewport* vp);
    00520         virtual void fireViewportPostUpdate(Viewport* vp);
    00522         virtual void fireViewportAdded(Viewport* vp);
    00524         virtual void fireViewportRemoved(Viewport* vp);
    00525
    00527         virtual void updateImpl();
    00528     };
    00532 } // Namespace
    00533
    00534 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:23