# 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     public:
    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         ~TempBlendedBufferInfo(void);
    00076         void checkoutTempCopies(bool positions = true, bool normals = true);
    00078         void bindTempCopies(VertexData* targetData, bool suppressHardwareUpload);
    00080         void licenseExpired(HardwareBuffer* buffer);
    00081     };
    00082
    00083
    00086     class _OgreExport HardwareBufferManager : public Singleton<HardwareBufferManager>
    00087     {
    00088         friend class HardwareVertexBufferSharedPtr;
    00089         friend class HardwareIndexBufferSharedPtr;
    00090     protected:
    00091         typedef std::list<VertexDeclaration*> VertexDeclarationList;
    00092         typedef std::list<VertexBufferBinding*> VertexBufferBindingList;
    00093
    00094         VertexDeclarationList mVertexDeclarations;
    00095         VertexBufferBindingList mVertexBufferBindings;
    00096
    00097
    00098         virtual void destroyAllDeclarations(void);
    00099         virtual void destroyAllBindings(void);
    00100
    00101     public:
    00102
    00103         enum BufferLicenseType
    00104         {
    00106             BLT_MANUAL_RELEASE,
    00108             BLT_AUTOMATIC_RELEASE
    00109         };
    00110
    00111     protected:
    00113         class _OgrePrivate VertexBufferLicense
    00114         {
    00115         public:
    00116             HardwareVertexBuffer* originalBufferPtr;
    00117             BufferLicenseType licenseType;
    00118             HardwareVertexBufferSharedPtr buffer;
    00119             HardwareBufferLicensee* licensee;
    00120             VertexBufferLicense(
    00121                 HardwareVertexBuffer* orig,
    00122                 BufferLicenseType ltype,
    00123                 HardwareVertexBufferSharedPtr buf,
    00124                 HardwareBufferLicensee* lic)
    00125                 : originalBufferPtr(orig), licenseType(ltype), buffer(buf), licensee(lic) {}
    00126
    00127         };
    00128
    00130         typedef std::vector<HardwareVertexBufferSharedPtr> FreeTemporaryVertexBufferList;
    00132         typedef std::map<HardwareVertexBuffer*, FreeTemporaryVertexBufferList*> FreeTemporaryVertexBufferMap;
    00134         FreeTemporaryVertexBufferMap mFreeTempVertexBufferMap;
    00136         typedef std::vector<VertexBufferLicense> TemporaryVertexBufferLicenseList;
    00138         TemporaryVertexBufferLicenseList mTempVertexBufferLicenses;
    00139
    00140         typedef std::set<HardwareVertexBuffer*> VertexBufferList;
    00141         typedef std::set<HardwareIndexBuffer*> IndexBufferList;
    00142         VertexBufferList mVertexBuffers;
    00143         IndexBufferList mIndexBuffers;
    00144
    00145
    00147         HardwareVertexBufferSharedPtr makeBufferCopy(
    00148             const HardwareVertexBufferSharedPtr& source,
    00149             HardwareBuffer::Usage usage, bool useShadowBuffer);
    00150
    00151     public:
    00152         HardwareBufferManager();
    00153         virtual ~HardwareBufferManager();
    00182         virtual HardwareVertexBufferSharedPtr
    00183             createVertexBuffer(size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage,
    00184             bool useShadowBuffer = false) = 0;
    00201         virtual HardwareIndexBufferSharedPtr
    00202             createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes,
    00203             HardwareBuffer::Usage usage, bool useShadowBuffer = false) = 0;
    00205         virtual VertexDeclaration* createVertexDeclaration(void);
    00207         virtual void destroyVertexDeclaration(VertexDeclaration* decl);
    00208
    00210         virtual VertexBufferBinding* createVertexBufferBinding(void);
    00212         virtual void destroyVertexBufferBinding(VertexBufferBinding* binding);
    00213
    00219         virtual void registerVertexBufferSourceAndCopy(
    00220             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00221             const HardwareVertexBufferSharedPtr& copy);
    00222
    00239         virtual HardwareVertexBufferSharedPtr allocateVertexBufferCopy(
    00240             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00241             BufferLicenseType licenseType,
    00242             HardwareBufferLicensee* licensee,
    00243             bool copyData = false);
    00252         virtual void releaseVertexBufferCopy(
    00253             const HardwareVertexBufferSharedPtr& bufferCopy);
    00254
    00257         virtual void _releaseBufferCopies(void);
    00258
    00268         virtual void _forceReleaseBufferCopies(
    00269             const HardwareVertexBufferSharedPtr& sourceBuffer)
    00270         { _forceReleaseBufferCopies(sourceBuffer.get()); }
    00271
    00281         void _forceReleaseBufferCopies(HardwareVertexBuffer* sourceBuffer);
    00282
    00284         void _notifyVertexBufferDestroyed(HardwareVertexBuffer* buf);
    00286         void _notifyIndexBufferDestroyed(HardwareIndexBuffer* buf);
    00287
    00303         static HardwareBufferManager& getSingleton(void);
    00319         static HardwareBufferManager* getSingletonPtr(void);
    00320
    00321     };
    00322
    00323 }
    00324
    00325 #endif
    00326

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