Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | 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-2005 The OGRE Team
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 */
00025 #ifndef __HardwareBufferManager__
00026 #define __HardwareBufferManager__
00027 
00028 // Precompiler options
00029 #include "OgrePrerequisites.h"
00030 
00031 #include "OgreSingleton.h"
00032 #include "OgreHardwareVertexBuffer.h"
00033 #include "OgreHardwareIndexBuffer.h"
00034 
00035 
00036 namespace Ogre {
00037 
00048     class _OgreExport HardwareBufferLicensee
00049     {
00050     public:
00051         virtual ~HardwareBufferLicensee() { }
00054         virtual void licenseExpired(HardwareBuffer* buffer) = 0;
00055     };
00056 
00058     class _OgreExport TempBlendedBufferInfo : public HardwareBufferLicensee
00059     {
00060     private:
00061         // Pre-blended 
00062         HardwareVertexBufferSharedPtr srcPositionBuffer;
00063         HardwareVertexBufferSharedPtr srcNormalBuffer;
00064         // Post-blended 
00065         HardwareVertexBufferSharedPtr destPositionBuffer;
00066         HardwareVertexBufferSharedPtr destNormalBuffer;
00068         bool posNormalShareBuffer;
00069         unsigned short posBindIndex;
00070         unsigned short normBindIndex;
00071         bool bindPositions;
00072         bool bindNormals;
00073 
00074     public:
00075         ~TempBlendedBufferInfo(void);
00077         void extractFrom(const VertexData* sourceData);
00079         void checkoutTempCopies(bool positions = true, bool normals = true);
00081         void bindTempCopies(VertexData* targetData, bool suppressHardwareUpload);
00083         void licenseExpired(HardwareBuffer* buffer);
00085         bool buffersCheckedOut(bool positions = true, bool normals = true) const;
00086     };
00087 
00088 
00091     class _OgreExport HardwareBufferManager : public Singleton<HardwareBufferManager>
00092     {
00093         friend class HardwareVertexBufferSharedPtr;
00094         friend class HardwareIndexBufferSharedPtr;
00095     protected:
00101         typedef std::set<HardwareVertexBuffer*> VertexBufferList;
00102         typedef std::set<HardwareIndexBuffer*> IndexBufferList;
00103         VertexBufferList mVertexBuffers;
00104         IndexBufferList mIndexBuffers;
00105 
00106 
00107         typedef std::set<VertexDeclaration*> VertexDeclarationList;
00108         typedef std::set<VertexBufferBinding*> VertexBufferBindingList;
00109         VertexDeclarationList mVertexDeclarations;
00110         VertexBufferBindingList mVertexBufferBindings;
00111 
00112 
00114         virtual void destroyAllDeclarations(void);
00116         virtual void destroyAllBindings(void);
00117 
00119         virtual VertexDeclaration* createVertexDeclarationImpl(void);
00121         virtual void destroyVertexDeclarationImpl(VertexDeclaration* decl);
00122 
00124         virtual VertexBufferBinding* createVertexBufferBindingImpl(void);
00126         virtual void destroyVertexBufferBindingImpl(VertexBufferBinding* binding);
00127 
00128     public:
00129 
00130         enum BufferLicenseType
00131         {
00133             BLT_MANUAL_RELEASE,
00135             BLT_AUTOMATIC_RELEASE
00136         };
00137 
00138     protected:
00140         class _OgrePrivate VertexBufferLicense
00141         {
00142         public:
00143             HardwareVertexBuffer* originalBufferPtr;
00144             BufferLicenseType licenseType;
00145             size_t expiredDelay;
00146             HardwareVertexBufferSharedPtr buffer;
00147             HardwareBufferLicensee* licensee;
00148             VertexBufferLicense(
00149                 HardwareVertexBuffer* orig,
00150                 BufferLicenseType ltype, 
00151                 size_t delay,
00152                 HardwareVertexBufferSharedPtr buf, 
00153                 HardwareBufferLicensee* lic) 
00154                 : originalBufferPtr(orig)
00155                 , licenseType(ltype)
00156                 , expiredDelay(delay)
00157                 , buffer(buf)
00158                 , licensee(lic)
00159             {}
00160 
00161         };
00162 
00164         typedef std::multimap<HardwareVertexBuffer*, HardwareVertexBufferSharedPtr> FreeTemporaryVertexBufferMap;
00166         FreeTemporaryVertexBufferMap mFreeTempVertexBufferMap;
00168         typedef std::map<HardwareVertexBuffer*, VertexBufferLicense> TemporaryVertexBufferLicenseMap;
00170         TemporaryVertexBufferLicenseMap mTempVertexBufferLicenses;
00172         size_t mUnderUsedFrameCount;
00174         static const size_t UNDER_USED_FRAME_THRESHOLD;
00176         static const size_t EXPIRED_DELAY_FRAME_THRESHOLD;
00177 
00178 
00180         HardwareVertexBufferSharedPtr makeBufferCopy(
00181             const HardwareVertexBufferSharedPtr& source, 
00182             HardwareBuffer::Usage usage, bool useShadowBuffer);
00183 
00184     public:
00185         HardwareBufferManager();
00186         virtual ~HardwareBufferManager();
00215         virtual HardwareVertexBufferSharedPtr 
00216             createVertexBuffer(size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage, 
00217             bool useShadowBuffer = false) = 0;
00234         virtual HardwareIndexBufferSharedPtr 
00235             createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes, 
00236             HardwareBuffer::Usage usage, bool useShadowBuffer = false) = 0;
00237 
00239         virtual VertexDeclaration* createVertexDeclaration(void);
00241         virtual void destroyVertexDeclaration(VertexDeclaration* decl);
00242 
00244         virtual VertexBufferBinding* createVertexBufferBinding(void);
00246         virtual void destroyVertexBufferBinding(VertexBufferBinding* binding);
00247 
00253         virtual void registerVertexBufferSourceAndCopy(
00254             const HardwareVertexBufferSharedPtr& sourceBuffer,
00255             const HardwareVertexBufferSharedPtr& copy);
00256 
00273         virtual HardwareVertexBufferSharedPtr allocateVertexBufferCopy(
00274             const HardwareVertexBufferSharedPtr& sourceBuffer, 
00275             BufferLicenseType licenseType,
00276             HardwareBufferLicensee* licensee,
00277             bool copyData = false);
00278 
00287         virtual void releaseVertexBufferCopy(
00288             const HardwareVertexBufferSharedPtr& bufferCopy); 
00289 
00300         virtual void touchVertexBufferCopy(
00301             const HardwareVertexBufferSharedPtr& bufferCopy);
00302 
00312         virtual void _freeUnusedBufferCopies(void);
00313 
00320         virtual void _releaseBufferCopies(bool forceFreeUnused = false);
00321 
00331         virtual void _forceReleaseBufferCopies(
00332             const HardwareVertexBufferSharedPtr& sourceBuffer);
00333 
00343         virtual void _forceReleaseBufferCopies(HardwareVertexBuffer* sourceBuffer);
00344 
00346         void _notifyVertexBufferDestroyed(HardwareVertexBuffer* buf);
00348         void _notifyIndexBufferDestroyed(HardwareIndexBuffer* buf);
00349 
00365         static HardwareBufferManager& getSingleton(void);
00381         static HardwareBufferManager* getSingletonPtr(void);
00382             
00383     };
00384 
00385 }
00386 
00387 #endif
00388 

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:42 2006