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 "OgreD3D9HardwareIndexBuffer.h" 00026 #include "OgreD3D9Mappings.h" 00027 #include "OgreException.h" 00028 00029 namespace Ogre { 00030 00031 //--------------------------------------------------------------------- 00032 D3D9HardwareIndexBuffer::D3D9HardwareIndexBuffer(HardwareIndexBuffer::IndexType idxType, 00033 size_t numIndexes, HardwareBuffer::Usage usage, LPDIRECT3DDEVICE9 pDev, 00034 bool useSystemMemory, bool useShadowBuffer) 00035 : HardwareIndexBuffer(idxType, numIndexes, usage, useSystemMemory, useShadowBuffer) 00036 { 00037 // Create the Index buffer 00038 HRESULT hr = pDev->CreateIndexBuffer( 00039 static_cast<UINT>(mSizeInBytes), 00040 D3D9Mappings::get(usage), 00041 D3D9Mappings::get(idxType), 00042 mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT, 00043 &mlpD3DBuffer, 00044 NULL 00045 ); 00046 00047 if (FAILED(hr)) 00048 { 00049 String msg = DXGetErrorDescription9(hr); 00050 Except(hr, "Cannot create D3D9 Index buffer: " + msg, 00051 "D3D9HardwareIndexBuffer::D3D9HardwareIndexBuffer"); 00052 } 00053 00054 } 00055 //--------------------------------------------------------------------- 00056 D3D9HardwareIndexBuffer::~D3D9HardwareIndexBuffer() 00057 { 00058 SAFE_RELEASE(mlpD3DBuffer); 00059 } 00060 //--------------------------------------------------------------------- 00061 void* D3D9HardwareIndexBuffer::lockImpl(size_t offset, 00062 size_t length, LockOptions options) 00063 { 00064 void* pBuf; 00065 DWORD lockOpts; 00066 if (!(mUsage & HBU_DYNAMIC) && options == HBL_DISCARD) 00067 { 00068 // D3D doesn't like discard on non-dynamic buffers 00069 lockOpts = 0; 00070 } 00071 else 00072 { 00073 lockOpts= D3D9Mappings::get(options); 00074 } 00075 HRESULT hr = mlpD3DBuffer->Lock( 00076 static_cast<UINT>(offset), 00077 static_cast<UINT>(length), 00078 &pBuf, 00079 lockOpts); 00080 00081 if (FAILED(hr)) 00082 { 00083 Except(hr, "Cannot lock D3D9 Index buffer", 00084 "D3D9HardwareIndexBuffer::lock"); 00085 } 00086 00087 00088 return pBuf; 00089 00090 00091 } 00092 //--------------------------------------------------------------------- 00093 void D3D9HardwareIndexBuffer::unlockImpl(void) 00094 { 00095 HRESULT hr = mlpD3DBuffer->Unlock(); 00096 } 00097 //--------------------------------------------------------------------- 00098 void D3D9HardwareIndexBuffer::readData(size_t offset, size_t length, 00099 void* pDest) 00100 { 00101 // There is no functional interface in D3D, just do via manual 00102 // lock, copy & unlock 00103 void* pSrc = this->lock(offset, length, HardwareBuffer::HBL_READ_ONLY); 00104 memcpy(pDest, pSrc, length); 00105 this->unlock(); 00106 00107 } 00108 //--------------------------------------------------------------------- 00109 void D3D9HardwareIndexBuffer::writeData(size_t offset, size_t length, 00110 const void* pSource, 00111 bool discardWholeBuffer) 00112 { 00113 // There is no functional interface in D3D, just do via manual 00114 // lock, copy & unlock 00115 void* pDst = this->lock(offset, length, 00116 discardWholeBuffer ? HardwareBuffer::HBL_DISCARD : HardwareBuffer::HBL_NORMAL); 00117 memcpy(pDst, pSource, length); 00118 this->unlock(); } 00119 //--------------------------------------------------------------------- 00120 00121 }
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:02 2004