Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreDefaultHardwareBufferManager.cpp

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-2003 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 #include "OgreStableHeaders.h"
    00026 #include "OgreDefaultHardwareBufferManager.h"
    00027
    00028 namespace Ogre {
    00029
    00030     DefaultHardwareVertexBuffer::DefaultHardwareVertexBuffer(size_t vertexSize, size_t numVertices,
    00031         HardwareBuffer::Usage usage)
    00032         : HardwareVertexBuffer(vertexSize, numVertices, usage, true, false) // always software, never shadowed
    00033     {
    00034         mpData = new unsigned char[mSizeInBytes];
    00035     }
    00036     //-----------------------------------------------------------------------
    00037     DefaultHardwareVertexBuffer::~DefaultHardwareVertexBuffer()
    00038     {
    00039         delete [] mpData;
    00040     }
    00041     //-----------------------------------------------------------------------
    00042     void* DefaultHardwareVertexBuffer::lockImpl(size_t offset, size_t length, LockOptions options)
    00043     {
    00044         // Only for use internally, no 'locking' as such
    00045         return mpData + offset;
    00046     }
    00047     //-----------------------------------------------------------------------
    00048     void DefaultHardwareVertexBuffer::unlockImpl(void)
    00049     {
    00050         // Nothing to do
    00051     }
    00052     //-----------------------------------------------------------------------
    00053     void* DefaultHardwareVertexBuffer::lock(size_t offset, size_t length, LockOptions options)
    00054     {
    00055         mIsLocked = true;
    00056         return mpData + offset;
    00057     }
    00058     //-----------------------------------------------------------------------
    00059     void DefaultHardwareVertexBuffer::unlock(void)
    00060     {
    00061         mIsLocked = false;
    00062         // Nothing to do
    00063     }
    00064     //-----------------------------------------------------------------------
    00065     void DefaultHardwareVertexBuffer::readData(size_t offset, size_t length, void* pDest)
    00066     {
    00067         assert((offset + length) <= mSizeInBytes);
    00068         memcpy(pDest, mpData + offset, length);
    00069     }
    00070     //-----------------------------------------------------------------------
    00071     void DefaultHardwareVertexBuffer::writeData(size_t offset, size_t length, const void* pSource,
    00072             bool discardWholeBuffer)
    00073     {
    00074         assert((offset + length) <= mSizeInBytes);
    00075         // ignore discard, memory is not guaranteed to be zeroised
    00076         memcpy(mpData + offset, pSource, length);
    00077
    00078     }
    00079     //-----------------------------------------------------------------------
    00080
    00081     DefaultHardwareIndexBuffer::DefaultHardwareIndexBuffer(IndexType idxType,
    00082         size_t numIndexes, HardwareBuffer::Usage usage)
    00083         : HardwareIndexBuffer(idxType, numIndexes, usage, true, false) // always software, never shadowed
    00084     {
    00085         mpData = new unsigned char[mSizeInBytes];
    00086     }
    00087     //-----------------------------------------------------------------------
    00088     DefaultHardwareIndexBuffer::~DefaultHardwareIndexBuffer()
    00089     {
    00090         delete [] mpData;
    00091     }
    00092     //-----------------------------------------------------------------------
    00093     void* DefaultHardwareIndexBuffer::lockImpl(size_t offset, size_t length, LockOptions options)
    00094     {
    00095         // Only for use internally, no 'locking' as such
    00096         return mpData + offset;
    00097     }
    00098     //-----------------------------------------------------------------------
    00099     void DefaultHardwareIndexBuffer::unlockImpl(void)
    00100     {
    00101         // Nothing to do
    00102     }
    00103     //-----------------------------------------------------------------------
    00104     void* DefaultHardwareIndexBuffer::lock(size_t offset, size_t length, LockOptions options)
    00105     {
    00106         mIsLocked = true;
    00107         return mpData + offset;
    00108     }
    00109     //-----------------------------------------------------------------------
    00110     void DefaultHardwareIndexBuffer::unlock(void)
    00111     {
    00112         mIsLocked = false;
    00113         // Nothing to do
    00114     }
    00115     //-----------------------------------------------------------------------
    00116     void DefaultHardwareIndexBuffer::readData(size_t offset, size_t length, void* pDest)
    00117     {
    00118         assert((offset + length) <= mSizeInBytes);
    00119         memcpy(pDest, mpData + offset, length);
    00120     }
    00121     //-----------------------------------------------------------------------
    00122     void DefaultHardwareIndexBuffer::writeData(size_t offset, size_t length, const void* pSource,
    00123             bool discardWholeBuffer)
    00124     {
    00125         assert((offset + length) <= mSizeInBytes);
    00126         // ignore discard, memory is not guaranteed to be zeroised
    00127         memcpy(mpData + offset, pSource, length);
    00128
    00129     }
    00130     //-----------------------------------------------------------------------
    00131
    00132
    00133     //-----------------------------------------------------------------------
    00134     void DefaultHardwareBufferManager::destroyVertexBuffer(HardwareVertexBuffer* buf)
    00135     {
    00136         VertexBufferList::iterator i = mVertexBuffers.find(buf);
    00137         if (i != mVertexBuffers.end())
    00138         {
    00139             delete *i;
    00140             mVertexBuffers.erase(i);
    00141         }
    00142     }
    00143     //-----------------------------------------------------------------------
    00144     void DefaultHardwareBufferManager::destroyIndexBuffer(HardwareIndexBuffer* buf)
    00145     {
    00146         IndexBufferList::iterator i = mIndexBuffers.find(buf);
    00147         if (i != mIndexBuffers.end())
    00148         {
    00149             delete *i;
    00150             mIndexBuffers.erase(i);
    00151         }
    00152     }
    00153     //-----------------------------------------------------------------------
    00154     DefaultHardwareBufferManager::DefaultHardwareBufferManager()
    00155     {
    00156     }
    00157     //-----------------------------------------------------------------------
    00158     DefaultHardwareBufferManager::~DefaultHardwareBufferManager()
    00159     {
    00160         destroyAllDeclarations();
    00161         destroyAllBindings();
    00162     }
    00163     //-----------------------------------------------------------------------
    00164     HardwareVertexBufferSharedPtr
    00165         DefaultHardwareBufferManager::createVertexBuffer(size_t vertexSize,
    00166         size_t numVerts, HardwareBuffer::Usage usage, bool useShadowBuffer)
    00167     {
    00168         DefaultHardwareVertexBuffer* vb = new DefaultHardwareVertexBuffer(vertexSize, numVerts, usage);
    00169         mVertexBuffers.insert(vb);
    00170         return HardwareVertexBufferSharedPtr(vb);
    00171     }
    00172     //-----------------------------------------------------------------------
    00173     HardwareIndexBufferSharedPtr
    00174         DefaultHardwareBufferManager::createIndexBuffer(HardwareIndexBuffer::IndexType itype,
    00175         size_t numIndexes, HardwareBuffer::Usage usage, bool useShadowBuffer)
    00176     {
    00177         DefaultHardwareIndexBuffer* ib = new DefaultHardwareIndexBuffer(itype, numIndexes, usage);
    00178         mIndexBuffers.insert(ib);
    00179         return HardwareIndexBufferSharedPtr(ib);
    00180     }
    00181 }

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