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

OgreD3D9HardwareBufferManager.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 "OgreD3D9HardwareBufferManager.h"
00026 #include "OgreD3D9HardwareVertexBuffer.h"
00027 #include "OgreD3D9HardwareIndexBuffer.h"
00028 #include "OgreD3D9VertexDeclaration.h"
00029 
00030 namespace Ogre {
00031     //-----------------------------------------------------------------------
00032     D3D9HardwareBufferManager::D3D9HardwareBufferManager(LPDIRECT3DDEVICE9 device)
00033         : mlpD3DDevice(device)
00034     {
00035     }
00036     //-----------------------------------------------------------------------
00037     D3D9HardwareBufferManager::~D3D9HardwareBufferManager()
00038     {
00039         destroyAllDeclarations();
00040         destroyAllBindings();
00041     }
00042     //-----------------------------------------------------------------------
00043     HardwareVertexBufferSharedPtr 
00044     D3D9HardwareBufferManager::
00045     createVertexBuffer(size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage,
00046         bool useShadowBuffer)
00047     {
00048 #if OGRE_D3D_MANAGE_BUFFERS
00049         // Override shadow buffer setting; managed buffers are automatically
00050         // backed by system memory
00051         // Don't override shadow buffer if discardable, since then we use
00052         // unmanaged buffers for speed (avoids write-through overhead)
00053         if (useShadowBuffer && !(usage & HardwareBuffer::HBU_DISCARDABLE))
00054         {
00055             useShadowBuffer = false;
00056             // Also drop any WRITE_ONLY so we can read direct
00057             if (usage == HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY)
00058             {
00059                 usage = HardwareBuffer::HBU_DYNAMIC;
00060             }
00061             else if (usage == HardwareBuffer::HBU_STATIC_WRITE_ONLY)
00062             {
00063                 usage = HardwareBuffer::HBU_STATIC;
00064             }
00065         }
00066 #endif
00067         return HardwareVertexBufferSharedPtr(
00068             new D3D9HardwareVertexBuffer(vertexSize, 
00069             numVerts, usage, mlpD3DDevice, false, useShadowBuffer) );
00070     }
00071     //-----------------------------------------------------------------------
00072     void D3D9HardwareBufferManager::destroyVertexBuffer(HardwareVertexBuffer* buf)
00073     {
00074         delete buf;
00075     }
00076     //-----------------------------------------------------------------------
00077     void D3D9HardwareBufferManager::destroyAllDeclarations(void)
00078     {
00079         VertexDeclarationList::iterator decl;
00080         for (decl = mVertexDeclarations.begin(); decl != mVertexDeclarations.end(); ++decl)
00081         {
00082             delete *decl;
00083         }
00084         mVertexDeclarations.clear();
00085     }
00086     //-----------------------------------------------------------------------
00087     HardwareIndexBufferSharedPtr 
00088     D3D9HardwareBufferManager::
00089     createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes, 
00090         HardwareBuffer::Usage usage, bool useShadowBuffer)
00091     {
00092 #if OGRE_D3D_MANAGE_BUFFERS
00093         // Override shadow buffer setting; managed buffers are automatically
00094         // backed by system memory
00095         if (useShadowBuffer)
00096         {
00097             useShadowBuffer = false;
00098             // Also drop any WRITE_ONLY so we can read direct
00099             if (usage == HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY)
00100             {
00101                 usage = HardwareBuffer::HBU_DYNAMIC;
00102             }
00103             else if (usage == HardwareBuffer::HBU_STATIC_WRITE_ONLY)
00104             {
00105                 usage = HardwareBuffer::HBU_STATIC;
00106             }
00107         }
00108 #endif
00109         // NB no longer store the buffer in a local list since reference counted
00110         return HardwareIndexBufferSharedPtr(
00111                 new D3D9HardwareIndexBuffer(itype, numIndexes, 
00112                 usage, mlpD3DDevice, false, useShadowBuffer) );
00113             
00114     }
00115     //-----------------------------------------------------------------------
00116     void D3D9HardwareBufferManager::destroyIndexBuffer(HardwareIndexBuffer* buf)
00117     {
00118         delete buf;
00119     }
00120     //-----------------------------------------------------------------------
00121     VertexDeclaration* D3D9HardwareBufferManager::createVertexDeclaration(void)
00122     {
00123         VertexDeclaration* decl = new D3D9VertexDeclaration(mlpD3DDevice);
00124         mVertexDeclarations.push_back(decl);
00125         return decl;
00126         
00127     }
00128     //-----------------------------------------------------------------------
00129     void D3D9HardwareBufferManager::destroyVertexDeclaration(VertexDeclaration* decl)
00130     {
00131         mVertexDeclarations.remove(decl);
00132         delete decl;
00133     }
00134 
00135 }

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