Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
5.0 KiB

  1. #ifndef __BUFFER_HPP__
  2. #define __BUFFER_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: buffer.hpp
  8. * Content: Class header the buffer base class; this class
  9. * contains all the logic that is shared between
  10. * the Index/Vertex/Command buffer types.
  11. *
  12. ***************************************************************************/
  13. // Includes
  14. #include "resource.hpp"
  15. //
  16. // The CBuffer is a base class for the index and vertex buffers
  17. //
  18. class CBuffer : public CResource
  19. {
  20. public:
  21. // Methods for Resource management
  22. virtual HRESULT UpdateDirtyPortion(CResource *pResourceTarget) { return S_OK; }
  23. virtual void MarkAllDirty();
  24. virtual BYTE* Data() const = 0;
  25. BOOL IsLocked() const
  26. {
  27. return m_LockCount > 0;
  28. } // IsLocked
  29. protected:
  30. // Constructor returns an error code
  31. // if the object could not be fully
  32. // constructed
  33. CBuffer(CBaseDevice *pDevice,
  34. DWORD cbLength,
  35. DWORD dwFVF,
  36. D3DFORMAT Format,
  37. D3DRESOURCETYPE Type,
  38. DWORD Usage,
  39. DWORD ActualUsage,
  40. D3DPOOL Pool,
  41. D3DPOOL ActualPool,
  42. REF_TYPE refType,
  43. HRESULT *phr
  44. );
  45. void LockImpl(UINT cbOffsetToLock,
  46. UINT cbSizeToLock,
  47. BYTE **ppbData,
  48. DWORD dwFlags,
  49. DWORD cbLength)
  50. {
  51. *ppbData = m_pbBuffer + cbOffsetToLock;
  52. // Do dirty rect stuff
  53. if (IsD3DManaged() && (dwFlags & D3DLOCK_READONLY) == 0)
  54. {
  55. OnBufferChangeImpl(cbOffsetToLock, cbSizeToLock);
  56. }
  57. }
  58. void OnBufferChangeImpl(UINT cbOffsetToLock, UINT cbSizeToLock);
  59. BYTE* GetPrivateDataPointer() const
  60. {
  61. return m_pbBuffer;
  62. }
  63. #if DBG
  64. BOOL m_isLockable;
  65. DWORD m_SceneStamp;
  66. DWORD m_TimesLocked;
  67. #endif // DBG
  68. DWORD m_LockCount;
  69. DWORD m_cbDirtyMin;
  70. DWORD m_cbDirtyMax;
  71. // Destructor
  72. virtual ~CBuffer();
  73. private:
  74. BYTE *m_pbBuffer;
  75. }; // class CBuffer
  76. // HACK: Ok; here's a minimal command buffer... This is probably not
  77. // the final implementation; but hey there you go.
  78. class CCommandBuffer : public CBuffer
  79. {
  80. public:
  81. // Static creation method
  82. static HRESULT Create(CBaseDevice *pDevice,
  83. DWORD cbLength,
  84. D3DPOOL Pool,
  85. CCommandBuffer **ppIndexBuffer);
  86. HRESULT Clone(D3DPOOL Pool,
  87. CResource **ppResource) const;
  88. const D3DBUFFER_DESC * GetBufferDesc() const
  89. {
  90. return &m_desc;
  91. } // GetDesc
  92. // You must call Release to free this guy. No support for
  93. // addref
  94. UINT Release()
  95. {
  96. return ReleaseImpl();
  97. };
  98. // Lock and Unlock support
  99. STDMETHOD(Lock)(THIS_
  100. UINT cbOffsetToLock,
  101. UINT cbSizeToLock,
  102. BYTE **ppbData,
  103. DWORD dwFlags)
  104. {
  105. #if DBG
  106. if (m_LockCount != 0)
  107. {
  108. DPF_ERR("Lock failed for command buffer; buffer was already locked.");
  109. return D3DERR_INVALIDCALL;
  110. }
  111. #endif // DBG
  112. m_LockCount = 1;
  113. LockImpl(cbOffsetToLock,
  114. cbSizeToLock,
  115. ppbData,
  116. dwFlags,
  117. m_cbLength);
  118. return S_OK;
  119. } // Lock
  120. STDMETHOD(Unlock)(THIS)
  121. {
  122. #if DBG
  123. // If we aren't locked; then something is wrong
  124. if (m_LockCount != 1)
  125. {
  126. DPF_ERR("Unlock failed on a command buffer; buffer wasn't locked.");
  127. return D3DERR_INVALIDCALL;
  128. }
  129. #endif // DBG
  130. // Clear our locked state
  131. m_LockCount = 0;
  132. return S_OK;
  133. } // Unlock
  134. BYTE* Data() const
  135. {
  136. DXGASSERT(FALSE); // Direct access not supported
  137. return 0;
  138. }
  139. private:
  140. CCommandBuffer(CBaseDevice *pDevice,
  141. DWORD cbLength,
  142. D3DPOOL Pool,
  143. HRESULT *phr)
  144. :
  145. CBuffer(pDevice,
  146. cbLength,
  147. 0, // dwFVF
  148. D3DFMT_UNKNOWN,
  149. D3DRTYPE_COMMANDBUFFER,
  150. D3DUSAGE_LOCK, // Usage
  151. D3DUSAGE_LOCK, // ActualUsage
  152. Pool, // Pool
  153. Pool, // ActualPool
  154. REF_INTERNAL,
  155. phr),
  156. m_cbLength(cbLength)
  157. {
  158. m_desc.Pool = Pool;
  159. m_desc.Usage = 0;
  160. m_desc.Format = D3DFMT_UNKNOWN;
  161. m_desc.Type = D3DRTYPE_COMMANDBUFFER;
  162. }; // CCommandBuffer::CCommandBuffer
  163. DWORD m_cbLength;
  164. D3DBUFFER_DESC m_desc;
  165. }; // class CCommandBuffer
  166. #endif // __BUFFER_HPP__