- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

# 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
    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
    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
    00250         virtual VertexDeclaration* createVertexDeclaration(void);
    00252         virtual void destroyVertexDeclaration(VertexDeclaration* decl);
    00253
    00255         virtual VertexBufferBinding* createVertexBufferBinding(void);
    00257         virtual void destroyVertexBufferBinding(VertexBufferBinding* binding);
    00258
    00264         virtual void registerVertexBufferSourceAndCopy(
    00265             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00266             const HardwareVertexBufferSharedPtr& copy);
    00267
    00284         virtual HardwareVertexBufferSharedPtr allocateVertexBufferCopy(
    00285             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00286             BufferLicenseType licenseType,
    00287             HardwareBufferLicensee* licensee,
    00288             bool copyData = false);
    00289
    00298         virtual void releaseVertexBufferCopy(
    00299             const HardwareVertexBufferSharedPtr& bufferCopy);
    00300
    00311         virtual void touchVertexBufferCopy(
    00312             const HardwareVertexBufferSharedPtr& bufferCopy);
    00313
    00323         virtual void _freeUnusedBufferCopies(void);
    00324
    00331         virtual void _releaseBufferCopies(bool forceFreeUnused = false);
    00332
    00342         virtual void _forceReleaseBufferCopies(
    00343             const HardwareVertexBufferSharedPtr& sourceBuffer);
    00344
    00354         virtual void _forceReleaseBufferCopies(HardwareVertexBuffer* sourceBuffer);
    00355
    00357         void _notifyVertexBufferDestroyed(HardwareVertexBuffer* buf);
    00359         void _notifyIndexBufferDestroyed(HardwareIndexBuffer* buf);
    00360
    00376         static HardwareBufferManager& getSingleton(void);
    00392         static HardwareBufferManager* getSingletonPtr(void);
    00393
    00394     };
    00395
    00396 }
    00397
    00398 #endif
    00399

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Mon Jun 16 12:48:51 2008