gfxD3D9VertexBuffer.h 4.2 KB

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