# 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-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
    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
    00093         VertexDeclarationList mVertexDeclarations;
    00094         VertexBufferBindingList mVertexBufferBindings;
    00095
    00096
    00097         virtual void destroyAllDeclarations(void);
    00098         virtual void destroyAllBindings(void);
    00099
    00100     public:
    00101
    00102         enum BufferLicenseType
    00103         {
    00105             BLT_MANUAL_RELEASE,
    00107             BLT_AUTOMATIC_RELEASE
    00108         };
    00109
    00110     protected:
    00112         class _OgrePrivate VertexBufferLicense
    00113         {
    00114         public:
    00115             HardwareVertexBuffer* originalBufferPtr;
    00116             BufferLicenseType licenseType;
    00117             HardwareVertexBufferSharedPtr buffer;
    00118             HardwareBufferLicensee* licensee;
    00119             VertexBufferLicense(
    00120                 HardwareVertexBuffer* orig,
    00121                 BufferLicenseType ltype,
    00122                 HardwareVertexBufferSharedPtr buf,
    00123                 HardwareBufferLicensee* lic)
    00124                 : originalBufferPtr(orig), licenseType(ltype), buffer(buf), licensee(lic) {}
    00125
    00126         };
    00127
    00129         typedef std::vector<HardwareVertexBufferSharedPtr> FreeTemporaryVertexBufferList;
    00131         typedef std::map<HardwareVertexBuffer*, FreeTemporaryVertexBufferList*> FreeTemporaryVertexBufferMap;
    00133         FreeTemporaryVertexBufferMap mFreeTempVertexBufferMap;
    00135         typedef std::vector<VertexBufferLicense> TemporaryVertexBufferLicenseList;
    00137         TemporaryVertexBufferLicenseList mTempVertexBufferLicenses;
    00138
    00139         typedef std::set<HardwareVertexBuffer*> VertexBufferList;
    00140         typedef std::set<HardwareIndexBuffer*> IndexBufferList;
    00141         VertexBufferList mVertexBuffers;
    00142         IndexBufferList mIndexBuffers;
    00143
    00144
    00146         HardwareVertexBufferSharedPtr makeBufferCopy(
    00147             const HardwareVertexBufferSharedPtr& source,
    00148             HardwareBuffer::Usage usage, bool useShadowBuffer);
    00149
    00150     public:
    00151         HardwareBufferManager();
    00152         virtual ~HardwareBufferManager();
    00181         virtual HardwareVertexBufferSharedPtr
    00182             createVertexBuffer(size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage,
    00183             bool useShadowBuffer = false) = 0;
    00200         virtual HardwareIndexBufferSharedPtr
    00201             createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes,
    00202             HardwareBuffer::Usage usage, bool useShadowBuffer = false) = 0;
    00204         virtual VertexDeclaration* createVertexDeclaration(void);
    00206         virtual void destroyVertexDeclaration(VertexDeclaration* decl);
    00207
    00209         virtual VertexBufferBinding* createVertexBufferBinding(void);
    00211         virtual void destroyVertexBufferBinding(VertexBufferBinding* binding);
    00212
    00218         virtual void registerVertexBufferSourceAndCopy(
    00219             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00220             const HardwareVertexBufferSharedPtr& copy);
    00221
    00238         virtual HardwareVertexBufferSharedPtr allocateVertexBufferCopy(
    00239             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00240             BufferLicenseType licenseType,
    00241             HardwareBufferLicensee* licensee,
    00242             bool copyData = false);
    00251         virtual void releaseVertexBufferCopy(
    00252             const HardwareVertexBufferSharedPtr& bufferCopy);
    00253
    00256         virtual void _releaseBufferCopies(void);
    00257
    00265         virtual void _forceReleaseBufferCopies(
    00266             const HardwareVertexBufferSharedPtr& sourceBuffer);
    00267
    00269         void _notifyVertexBufferDestroyed(HardwareVertexBuffer* buf);
    00271         void _notifyIndexBufferDestroyed(HardwareIndexBuffer* buf);
    00272
    00288         static HardwareBufferManager& getSingleton(void);
    00304         static HardwareBufferManager* getSingletonPtr(void);
    00305
    00306     };
    00307
    00308 }
    00309
    00310 #endif
    00311

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Sep 25 17:35:55 2005