Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound 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 © 2000-2002 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
    00075         void checkoutTempCopies(bool positions = true, bool normals = true);
    00077         void bindTempCopies(VertexData* targetData, bool suppressHardwareUpload);
    00079         void licenseExpired(HardwareBuffer* buffer);
    00080     };
    00081
    00082
    00085     class _OgreExport HardwareBufferManager : public Singleton<HardwareBufferManager>
    00086     {
    00087         friend class HardwareVertexBufferSharedPtr;
    00088         friend class HardwareIndexBufferSharedPtr;
    00089     protected:
    00090         typedef std::list<VertexDeclaration*> VertexDeclarationList;
    00091         typedef std::list<VertexBufferBinding*> VertexBufferBindingList;
    00092         typedef std::set<HardwareVertexBuffer*> VertexBufferList;
    00093         typedef std::set<HardwareIndexBuffer*> IndexBufferList;
    00094
    00095         VertexDeclarationList mVertexDeclarations;
    00096         VertexBufferBindingList mVertexBufferBindings;
    00097         VertexBufferList mVertexBuffers;
    00098         IndexBufferList mIndexBuffers;
    00099
    00100
    00102         virtual void destroyVertexBuffer(HardwareVertexBuffer* buf) = 0;
    00104         virtual void destroyIndexBuffer(HardwareIndexBuffer* buf) = 0;
    00105
    00106         virtual void destroyAllDeclarations(void);
    00107         virtual void destroyAllBindings(void);
    00108
    00109     public:
    00110
    00111         enum BufferLicenseType
    00112         {
    00114             BLT_MANUAL_RELEASE,
    00116             BLT_AUTOMATIC_RELEASE
    00117         };
    00118
    00119     protected:
    00121         class VertexBufferLicense
    00122         {
    00123         public:
    00124             HardwareVertexBuffer* originalBufferPtr;
    00125             BufferLicenseType licenseType;
    00126             HardwareVertexBufferSharedPtr buffer;
    00127             HardwareBufferLicensee* licensee;
    00128             VertexBufferLicense(
    00129                 HardwareVertexBuffer* orig,
    00130                 BufferLicenseType ltype,
    00131                 HardwareVertexBufferSharedPtr buf,
    00132                 HardwareBufferLicensee* lic)
    00133                 : originalBufferPtr(orig), licenseType(ltype), buffer(buf), licensee(lic) {}
    00134
    00135         };
    00136
    00138         typedef std::vector<HardwareVertexBufferSharedPtr> FreeTemporaryVertexBufferList;
    00140         typedef std::map<HardwareVertexBuffer*, FreeTemporaryVertexBufferList*> FreeTemporaryVertexBufferMap;
    00142         FreeTemporaryVertexBufferMap mFreeTempVertexBufferMap;
    00144         typedef std::vector<VertexBufferLicense> TemporaryVertexBufferLicenseList;
    00146         TemporaryVertexBufferLicenseList mTempVertexBufferLicenses;
    00147
    00149         HardwareVertexBufferSharedPtr makeBufferCopy(
    00150             const HardwareVertexBufferSharedPtr& source,
    00151             HardwareBuffer::Usage usage, bool useShadowBuffer);
    00152
    00153     public:
    00154         HardwareBufferManager();
    00155         virtual ~HardwareBufferManager();
    00184         virtual HardwareVertexBufferSharedPtr
    00185             createVertexBuffer(size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage,
    00186             bool useShadowBuffer = false) = 0;
    00203         virtual HardwareIndexBufferSharedPtr
    00204             createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes,
    00205             HardwareBuffer::Usage usage, bool useShadowBuffer = false) = 0;
    00207         virtual VertexDeclaration* createVertexDeclaration(void);
    00209         virtual void destroyVertexDeclaration(VertexDeclaration* decl);
    00210
    00212         virtual VertexBufferBinding* createVertexBufferBinding(void);
    00214         virtual void destroyVertexBufferBinding(VertexBufferBinding* binding);
    00215
    00221         virtual void registerVertexBufferSourceAndCopy(
    00222             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00223             const HardwareVertexBufferSharedPtr& copy);
    00224
    00241         virtual HardwareVertexBufferSharedPtr allocateVertexBufferCopy(
    00242             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00243             BufferLicenseType licenseType,
    00244             HardwareBufferLicensee* licensee,
    00245             bool copyData = false);
    00254         virtual void releaseVertexBufferCopy(
    00255             const HardwareVertexBufferSharedPtr& bufferCopy);
    00256
    00259         virtual void _releaseBufferCopies(void);
    00260
    00268         virtual void _forceReleaseBufferCopies(
    00269             const HardwareVertexBufferSharedPtr& sourceBuffer);
    00285         static HardwareBufferManager& getSingleton(void);
    00301         static HardwareBufferManager* getSingletonPtr(void);
    00302
    00303     };
    00304
    00305 }
    00306
    00307 #endif
    00308

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:29 2004