OGRE: 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-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __HardwareBufferManager__
    00029 #define __HardwareBufferManager__
    00030
    00031 // Precompiler options
    00032 #include "OgrePrerequisites.h"
    00033
    00034 #include "OgreSingleton.h"
    00035 #include "OgreHardwareVertexBuffer.h"
    00036 #include "OgreHardwareIndexBuffer.h"
    00037 #include "OgreRenderToVertexBuffer.h"
    00038
    00039 namespace Ogre {
    00057     class _OgreExport HardwareBufferLicensee
    00058     {
    00059     public:
    00060         virtual ~HardwareBufferLicensee() { }
    00063         virtual void licenseExpired(HardwareBuffer* buffer) = 0;
    00064     };
    00065
    00067     class _OgreExport TempBlendedBufferInfo : public HardwareBufferLicensee, public BufferAlloc
    00068     {
    00069     private:
    00070         // Pre-blended
    00071         HardwareVertexBufferSharedPtr srcPositionBuffer;
    00072         HardwareVertexBufferSharedPtr srcNormalBuffer;
    00073         // Post-blended
    00074         HardwareVertexBufferSharedPtr destPositionBuffer;
    00075         HardwareVertexBufferSharedPtr destNormalBuffer;
    00077         bool posNormalShareBuffer;
    00078         unsigned short posBindIndex;
    00079         unsigned short normBindIndex;
    00080         bool bindPositions;
    00081         bool bindNormals;
    00082
    00083     public:
    00084         ~TempBlendedBufferInfo(void);
    00086         void extractFrom(const VertexData* sourceData);
    00088         void checkoutTempCopies(bool positions = true, bool normals = true);
    00090         void bindTempCopies(VertexData* targetData, bool suppressHardwareUpload);
    00092         void licenseExpired(HardwareBuffer* buffer);
    00094         bool buffersCheckedOut(bool positions = true, bool normals = true) const;
    00095     };
    00096
    00097
    00109     class _OgreExport HardwareBufferManagerBase : public BufferAlloc
    00110     {
    00111         friend class HardwareVertexBufferSharedPtr;
    00112         friend class HardwareIndexBufferSharedPtr;
    00113     protected:
    00119         typedef set<HardwareVertexBuffer*>::type VertexBufferList;
    00120         typedef set<HardwareIndexBuffer*>::type IndexBufferList;
    00121         VertexBufferList mVertexBuffers;
    00122         IndexBufferList mIndexBuffers;
    00123
    00124
    00125         typedef set<VertexDeclaration*>::type VertexDeclarationList;
    00126         typedef set<VertexBufferBinding*>::type VertexBufferBindingList;
    00127         VertexDeclarationList mVertexDeclarations;
    00128         VertexBufferBindingList mVertexBufferBindings;
    00129
    00130         // Mutexes
    00131         OGRE_MUTEX(mVertexBuffersMutex)
    00132         OGRE_MUTEX(mIndexBuffersMutex)
    00133         OGRE_MUTEX(mVertexDeclarationsMutex)
    00134         OGRE_MUTEX(mVertexBufferBindingsMutex)
    00135
    00137         virtual void destroyAllDeclarations(void);
    00139         virtual void destroyAllBindings(void);
    00140
    00142         virtual VertexDeclaration* createVertexDeclarationImpl(void);
    00144         virtual void destroyVertexDeclarationImpl(VertexDeclaration* decl);
    00145
    00147         virtual VertexBufferBinding* createVertexBufferBindingImpl(void);
    00149         virtual void destroyVertexBufferBindingImpl(VertexBufferBinding* binding);
    00150
    00151     public:
    00152
    00153         enum BufferLicenseType
    00154         {
    00156             BLT_MANUAL_RELEASE,
    00158             BLT_AUTOMATIC_RELEASE
    00159         };
    00160
    00161     protected:
    00163         class _OgrePrivate VertexBufferLicense
    00164         {
    00165         public:
    00166             HardwareVertexBuffer* originalBufferPtr;
    00167             BufferLicenseType licenseType;
    00168             size_t expiredDelay;
    00169             HardwareVertexBufferSharedPtr buffer;
    00170             HardwareBufferLicensee* licensee;
    00171             VertexBufferLicense(
    00172                 HardwareVertexBuffer* orig,
    00173                 BufferLicenseType ltype,
    00174                 size_t delay,
    00175                 HardwareVertexBufferSharedPtr buf,
    00176                 HardwareBufferLicensee* lic)
    00177                 : originalBufferPtr(orig)
    00178                 , licenseType(ltype)
    00179                 , expiredDelay(delay)
    00180                 , buffer(buf)
    00181                 , licensee(lic)
    00182             {}
    00183
    00184         };
    00185
    00187         typedef multimap<HardwareVertexBuffer*, HardwareVertexBufferSharedPtr>::type FreeTemporaryVertexBufferMap;
    00189         FreeTemporaryVertexBufferMap mFreeTempVertexBufferMap;
    00191         typedef map<HardwareVertexBuffer*, VertexBufferLicense>::type TemporaryVertexBufferLicenseMap;
    00193         TemporaryVertexBufferLicenseMap mTempVertexBufferLicenses;
    00195         size_t mUnderUsedFrameCount;
    00197         static const size_t UNDER_USED_FRAME_THRESHOLD;
    00199         static const size_t EXPIRED_DELAY_FRAME_THRESHOLD;
    00200         // Mutexes
    00201         OGRE_MUTEX(mTempBuffersMutex)
    00202
    00203
    00204
    00205         virtual HardwareVertexBufferSharedPtr makeBufferCopy(
    00206             const HardwareVertexBufferSharedPtr& source,
    00207             HardwareBuffer::Usage usage, bool useShadowBuffer);
    00208
    00209     public:
    00210         HardwareBufferManagerBase();
    00211         virtual ~HardwareBufferManagerBase();
    00240         virtual HardwareVertexBufferSharedPtr
    00241             createVertexBuffer(size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage,
    00242             bool useShadowBuffer = false) = 0;
    00259         virtual HardwareIndexBufferSharedPtr
    00260             createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes,
    00261             HardwareBuffer::Usage usage, bool useShadowBuffer = false) = 0;
    00262
    00267         virtual RenderToVertexBufferSharedPtr createRenderToVertexBuffer() = 0;
    00268
    00270         virtual VertexDeclaration* createVertexDeclaration(void);
    00272         virtual void destroyVertexDeclaration(VertexDeclaration* decl);
    00273
    00275         virtual VertexBufferBinding* createVertexBufferBinding(void);
    00277         virtual void destroyVertexBufferBinding(VertexBufferBinding* binding);
    00278
    00284         virtual void registerVertexBufferSourceAndCopy(
    00285             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00286             const HardwareVertexBufferSharedPtr& copy);
    00287
    00304         virtual HardwareVertexBufferSharedPtr allocateVertexBufferCopy(
    00305             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00306             BufferLicenseType licenseType,
    00307             HardwareBufferLicensee* licensee,
    00308             bool copyData = false);
    00309
    00318         virtual void releaseVertexBufferCopy(
    00319             const HardwareVertexBufferSharedPtr& bufferCopy);
    00320
    00331         virtual void touchVertexBufferCopy(
    00332             const HardwareVertexBufferSharedPtr& bufferCopy);
    00333
    00343         virtual void _freeUnusedBufferCopies(void);
    00344
    00351         virtual void _releaseBufferCopies(bool forceFreeUnused = false);
    00352
    00362         virtual void _forceReleaseBufferCopies(
    00363             const HardwareVertexBufferSharedPtr& sourceBuffer);
    00364
    00374         virtual void _forceReleaseBufferCopies(HardwareVertexBuffer* sourceBuffer);
    00375
    00377         void _notifyVertexBufferDestroyed(HardwareVertexBuffer* buf);
    00379         void _notifyIndexBufferDestroyed(HardwareIndexBuffer* buf);
    00380
    00381     };
    00382
    00384     class _OgreExport HardwareBufferManager : public HardwareBufferManagerBase, public Singleton<HardwareBufferManager>
    00385     {
    00386         friend class HardwareVertexBufferSharedPtr;
    00387         friend class HardwareIndexBufferSharedPtr;
    00388     protected:
    00389         HardwareBufferManagerBase* mImpl;
    00390     public:
    00391         HardwareBufferManager(HardwareBufferManagerBase* imp);
    00392         ~HardwareBufferManager();
    00393
    00395         HardwareVertexBufferSharedPtr
    00396             createVertexBuffer(size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage,
    00397             bool useShadowBuffer = false)
    00398         {
    00399             return mImpl->createVertexBuffer(vertexSize, numVerts, usage, useShadowBuffer);
    00400         }
    00402         HardwareIndexBufferSharedPtr
    00403             createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes,
    00404             HardwareBuffer::Usage usage, bool useShadowBuffer = false)
    00405         {
    00406             return mImpl->createIndexBuffer(itype, numIndexes, usage, useShadowBuffer);
    00407         }
    00408
    00410         RenderToVertexBufferSharedPtr createRenderToVertexBuffer()
    00411         {
    00412             return mImpl->createRenderToVertexBuffer();
    00413         }
    00414
    00416         virtual VertexDeclaration* createVertexDeclaration(void)
    00417         {
    00418             return mImpl->createVertexDeclaration();
    00419         }
    00421         virtual void destroyVertexDeclaration(VertexDeclaration* decl)
    00422         {
    00423             mImpl->destroyVertexDeclaration(decl);
    00424         }
    00425
    00427         virtual VertexBufferBinding* createVertexBufferBinding(void)
    00428         {
    00429             return mImpl->createVertexBufferBinding();
    00430         }
    00432         virtual void destroyVertexBufferBinding(VertexBufferBinding* binding)
    00433         {
    00434             mImpl->destroyVertexBufferBinding(binding);
    00435         }
    00437         virtual void registerVertexBufferSourceAndCopy(
    00438             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00439             const HardwareVertexBufferSharedPtr& copy)
    00440         {
    00441             mImpl->registerVertexBufferSourceAndCopy(sourceBuffer, copy);
    00442         }
    00444         virtual HardwareVertexBufferSharedPtr allocateVertexBufferCopy(
    00445             const HardwareVertexBufferSharedPtr& sourceBuffer,
    00446             BufferLicenseType licenseType,
    00447             HardwareBufferLicensee* licensee,
    00448             bool copyData = false)
    00449         {
    00450             return mImpl->allocateVertexBufferCopy(sourceBuffer, licenseType, licensee, copyData);
    00451         }
    00453         virtual void releaseVertexBufferCopy(
    00454             const HardwareVertexBufferSharedPtr& bufferCopy)
    00455         {
    00456             mImpl->releaseVertexBufferCopy(bufferCopy);
    00457         }
    00458
    00460         virtual void touchVertexBufferCopy(
    00461             const HardwareVertexBufferSharedPtr& bufferCopy)
    00462         {
    00463             mImpl->touchVertexBufferCopy(bufferCopy);
    00464         }
    00465
    00467         virtual void _freeUnusedBufferCopies(void)
    00468         {
    00469             mImpl->_freeUnusedBufferCopies();
    00470         }
    00472         virtual void _releaseBufferCopies(bool forceFreeUnused = false)
    00473         {
    00474             mImpl->_releaseBufferCopies(forceFreeUnused);
    00475         }
    00477         virtual void _forceReleaseBufferCopies(
    00478             const HardwareVertexBufferSharedPtr& sourceBuffer)
    00479         {
    00480             mImpl->_forceReleaseBufferCopies(sourceBuffer);
    00481         }
    00483         virtual void _forceReleaseBufferCopies(HardwareVertexBuffer* sourceBuffer)
    00484         {
    00485             mImpl->_forceReleaseBufferCopies(sourceBuffer);
    00486         }
    00488         void _notifyVertexBufferDestroyed(HardwareVertexBuffer* buf)
    00489         {
    00490             mImpl->_notifyVertexBufferDestroyed(buf);
    00491         }
    00493         void _notifyIndexBufferDestroyed(HardwareIndexBuffer* buf)
    00494         {
    00495             mImpl->_notifyIndexBufferDestroyed(buf);
    00496         }
    00497
    00498
    00514         static HardwareBufferManager& getSingleton(void);
    00530         static HardwareBufferManager* getSingletonPtr(void);
    00531
    00532     };
    00533
    00536 }
    00537
    00538 #endif
    00539

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:51