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