gfxD3D9VertexBuffer.h
Engine/source/gfx/D3D9/gfxD3D9VertexBuffer.h
Classes:
class
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _GFXD3D_VERTEXBUFFER_H_ 25#define _GFXD3D_VERTEXBUFFER_H_ 26 27#ifndef _GFXD3D9DEVICE_H_ 28#include "gfx/D3D9/gfxD3D9Device.h" 29#endif 30#ifndef _SAFEDELETE_H_ 31#include "core/util/safeDelete.h" 32#endif 33 34//***************************************************************************** 35// GFXD3D9VertexBuffer 36//***************************************************************************** 37class GFXD3D9VertexBuffer : public GFXVertexBuffer 38{ 39public: 40 IDirect3DVertexBuffer9 *vb; 41 StrongRefPtr<GFXD3D9VertexBuffer> mVolatileBuffer; 42 43#ifdef TORQUE_DEBUG 44 #define _VBGuardString "GFX_VERTEX_BUFFER_GUARD_STRING" 45 U8 *mDebugGuardBuffer; 46 void *mLockedBuffer; 47#endif TORQUE_DEBUG 48 49 bool mIsFirstLock; 50 bool mClearAtFrameEnd; 51 52 GFXD3D9VertexBuffer(); 53 GFXD3D9VertexBuffer( GFXDevice *device, 54 U32 numVerts, 55 const GFXVertexFormat *vertexFormat, 56 U32 vertexSize, 57 GFXBufferType bufferType ); 58 virtual ~GFXD3D9VertexBuffer(); 59 60 void lock(U32 vertexStart, U32 vertexEnd, void **vertexPtr); 61 void unlock(); 62 void prepare() {} 63 64#ifdef TORQUE_DEBUG 65 char *name; 66 67 /// In debug compile, the verts will be chained together and the device 68 /// will examine the chain when it's destructor is called, this will 69 /// allow developers to see which vertex buffers are not destroyed 70 GFXD3D9VertexBuffer *next; 71#endif 72 void setName( const char *n ); 73 74 // GFXResource interface 75 virtual void zombify(); 76 virtual void resurrect(); 77}; 78 79//----------------------------------------------------------------------------- 80// This is for debugging vertex buffers and trying to track down which vbs 81// aren't getting free'd 82 83inline GFXD3D9VertexBuffer::GFXD3D9VertexBuffer() 84: GFXVertexBuffer(0,0,0,0,(GFXBufferType)0) 85{ 86#ifdef TORQUE_DEBUG 87 name = NULL; 88#endif 89 vb = NULL; 90 mIsFirstLock = true; 91 lockedVertexEnd = lockedVertexStart = 0; 92 mClearAtFrameEnd = false; 93 94#ifdef TORQUE_DEBUG 95 mDebugGuardBuffer = NULL; 96 mLockedBuffer = NULL; 97#endif 98} 99 100inline GFXD3D9VertexBuffer::GFXD3D9VertexBuffer( GFXDevice *device, 101 U32 numVerts, 102 const GFXVertexFormat *vertexFormat, 103 U32 vertexSize, 104 GFXBufferType bufferType ) 105 : GFXVertexBuffer( device, numVerts, vertexFormat, vertexSize, bufferType ) 106{ 107#ifdef TORQUE_DEBUG 108 name = NULL; 109#endif 110 vb = NULL; 111 mIsFirstLock = true; 112 mClearAtFrameEnd = false; 113 lockedVertexEnd = lockedVertexStart = 0; 114 115#ifdef TORQUE_DEBUG 116 mDebugGuardBuffer = NULL; 117 mLockedBuffer = NULL; 118#endif 119} 120 121#ifdef TORQUE_DEBUG 122 123inline void GFXD3D9VertexBuffer::setName( const char *n ) 124{ 125 SAFE_DELETE( name ); 126 name = new char[dStrlen( n )]; 127 dStrcpy( name, n ); 128} 129 130#else 131 132inline void GFXD3D9VertexBuffer::setName( const char *n ) { } 133 134#endif // !TORQUE_DEBUG 135 136#endif // _GFXD3D_VERTEXBUFFER_H_ 137 138
