OGRE: OgreHardwareBufferManager.h Source File - OGRE Documentation

# OgreHardwareBufferManager.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-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __HardwareBufferManager__
    00030 #define __HardwareBufferManager__
    00031
    00032 // Precompiler options
    00033 #include "OgrePrerequisites.h"
    00034
    00035 #include "OgreSingleton.h"
    00036 #include "OgreHardwareVertexBuffer.h"
    00037 #include "OgreHardwareIndexBuffer.h"
    00038 #include "OgreRenderToVertexBuffer.h"
    00039
    00040 namespace Ogre {
    00041
    00052     class _OgreExport HardwareBufferLicensee
    00053     {
    00054     public:
    00055         virtual ~HardwareBufferLicensee() { }
    00058         virtual void licenseExpired(HardwareBuffer* buffer) = 0;
    00059     };
    00060
    00062     class _OgreExport TempBlendedBufferInfo : public HardwareBufferLicensee, public BufferAlloc
    00063     {
    00064     private:
    00065         // Pre-blended
    00066         HardwareVertexBufferSharedPtr srcPositionBuffer;
    00067         HardwareVertexBufferSharedPtr srcNormalBuffer;
    00068         // Post-blended
    00069         HardwareVertexBufferSharedPtr destPositionBuffer;
    00070         HardwareVertexBufferSharedPtr destNormalBuffer;
    00072         bool posNormalShareBuffer;
    00073         unsigned short posBindIndex;
    00074         unsigned short normBindIndex;
    00075         bool bindPositions;
    00076         bool bindNormals;
    00077
    00078     public:
    00079         ~TempBlendedBufferInfo(void);
    00081         void extractFrom(const VertexData* sourceData);
    00083         void checkoutTempCopies(bool positions = true, bool normals = true);
    00085         void bindTempCopies(VertexData* targetData, bool suppressHardwareUpload);
    00087         void licenseExpired(HardwareBuffer* buffer);
    00089         bool buffersCheckedOut(bool positions = true, bool normals = true) const;
    00090     };
    00091
    00092
    00095     class _OgreExport HardwareBufferManager : public Singleton<HardwareBufferManager>
    00096     {
    00097         friend class HardwareVertexBufferSharedPtr;
    00098         friend class HardwareIndexBufferSharedPtr;
    00099     protected:
    00105         typedef std::set<HardwareVertexBuffer*> VertexBufferList;
    00106         typedef std::set<HardwareIndexBuffer*> IndexBufferList;
    00107         VertexBufferList mVertexBuffers;
    00108         IndexBufferList mIndexBuffers;
    00109
    00110
    00111         typedef std::set<VertexDeclaration*> VertexDeclarationList;
    00112         typedef std::set<VertexBufferBinding*> VertexBufferBindingList;
    00113         VertexDeclarationList mVertexDeclarations;
    00114         VertexBufferBindingList mVertexBufferBindings;
    00115
    00116         // Mutexes
    00117         OGRE_MUTEX(mVertexBuffersMutex)
    00118         OGRE_MUTEX(mIndexBuffersMutex)
    00119         OGRE_MUTEX(mVertexDeclarationsMutex)
    00120         OGRE_MUTEX(mVertexBufferBindingsMutex)
    00121
    00123         virtual void destroyAllDeclarations(void);
    00125         virtual void destroyAllBindings(void);
    00126
    00128         virtual VertexDeclaration* createVertexDeclarationImpl(void);
    00130         virtual void destroyVertexDeclarationImpl(VertexDeclaration* decl);
    00131
    00133         virtual VertexBufferBinding* createVertexBufferBindingImpl(void);
    00135         virtual void destroyVertexBufferBindingImpl(VertexBufferBinding* binding);
    00136
    00137     public:
    00138
    00139         enum BufferLicenseType
    00140         {
    00142             BLT_MANUAL_RELEASE,
    00144             BLT_AUTOMATIC_RELEASE
    00145         };
    00146
    00147     protected:
    00149         class _OgrePrivate VertexBufferLicense
    00150         {
    00151         public:
    00152             HardwareVertexBuffer* originalBufferPtr;
    00153             BufferLicenseType licenseType;
    00154             size_t expiredDelay;
    00155             HardwareVertexBufferSharedPtr buffer;
    00156             HardwareBufferLicensee* licensee;
    00157             VertexBufferLicense(
    00158                 HardwareVertexBuffer* orig,
    00159                 BufferLicenseType ltype,
    00160                 size_t delay,
    00161                 HardwareVertexBufferSharedPtr buf,
    00162                 HardwareBufferLicensee* lic)
    00163                 : originalBufferPtr(orig)
    00164                 , licenseType(ltype)
    00165                 , expiredDelay(delay)
    00166                 , buffer(buf)
    00167                 , licensee(lic)
    00168             {}
    00169
    00170         };
    00171
    00173         typedef std::multimap<HardwareVertexBuffer*, HardwareVertexBufferSharedPtr> FreeTemporaryVertexBufferMap;
    00175         FreeTemporaryVertexBufferMap mFreeTempVertexBufferMap;
    00177         typedef std::map<HardwareVertexBuffer*, VertexBufferLicense> TemporaryVertexBufferLicenseMap;
    00179         TemporaryVertexBufferLicenseMap mTempVertexBufferLicenses;
    00181         size_t mUnderUsedFrameCount;
    00183         static const size_t UNDER_USED_FRAME_THRESHOLD;
    00185         static const size_t EXPIRED_DELAY_FRAME_THRESHOLD;
    00186         // Mutexes
    00187         OGRE_MUTEX(mTempBuffersMutex)
    00188
    00189
    00190
    00191         HardwareVertexBufferSharedPtr makeBufferCopy(
    00192             const HardwareVertexBufferSharedPtr& source,
    00193             HardwareBuffer::Usage usage, bool useShadowBuffer);
    00194
    00195     public:
    00196         HardwareBufferManager();
    00197         virtual ~HardwareBufferManager();
    00226         virtual HardwareVertexBufferSharedPtr
    00227             createVertexBuffer(size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage,
    00228             bool useShadowBuffer = false) = 0;
    00245         virtual HardwareIndexBufferSharedPtr
    00246             createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes,
    00247             HardwareBuffer::Usage usage, bool useShadowBuffer = false) = 0;
    00248
    00253         virtual RenderToVertexBufferSharedPtr createRenderToVertexBuffer() = 0;
    00254
    00256         virtual VertexDeclaration* createVertexDeclaration(void);
    00258         virtual void destroyVertexDeclaration(VertexDeclaration* decl);
    00259
    00261         virtual VertexBufferBinding* createVertexBufferBinding(void);
    00263         virtual void destroyVertexBufferBinding(VertexBufferBinding* binding);
    00264
    00270         virtual void registerVertexBufferSourceAndCopy(
    00271             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00272             const HardwareVertexBufferSharedPtr& copy);
    00273
    00290         virtual HardwareVertexBufferSharedPtr allocateVertexBufferCopy(
    00291             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00292             BufferLicenseType licenseType,
    00293             HardwareBufferLicensee* licensee,
    00294             bool copyData = false);
    00295
    00304         virtual void releaseVertexBufferCopy(
    00305             const HardwareVertexBufferSharedPtr& bufferCopy);
    00306
    00317         virtual void touchVertexBufferCopy(
    00318             const HardwareVertexBufferSharedPtr& bufferCopy);
    00319
    00329         virtual void _freeUnusedBufferCopies(void);
    00330
    00337         virtual void _releaseBufferCopies(bool forceFreeUnused = false);
    00338
    00348         virtual void _forceReleaseBufferCopies(
    00349             const HardwareVertexBufferSharedPtr& sourceBuffer);
    00350
    00360         virtual void _forceReleaseBufferCopies(HardwareVertexBuffer* sourceBuffer);
    00361
    00363         void _notifyVertexBufferDestroyed(HardwareVertexBuffer* buf);
    00365         void _notifyIndexBufferDestroyed(HardwareIndexBuffer* buf);
    00366
    00382         static HardwareBufferManager& getSingleton(void);
    00398         static HardwareBufferManager* getSingletonPtr(void);
    00399
    00400     };
    00401
    00402 }
    00403
    00404 #endif
    00405

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:17 2009