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.

201 lines
6.6 KiB

  1. #ifndef __MIPVOL_HPP__
  2. #define __MIPVOL_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: mipvol.hpp
  8. * Content: Class header the mip-volume class. This class acts a
  9. * container for Volumes that are used as textures.
  10. *
  11. *
  12. ***************************************************************************/
  13. // Includes
  14. #include "texture.hpp"
  15. #include "pixel.hpp"
  16. // Forward decls
  17. class CVolume;
  18. //
  19. // The mip-map class holds a collection of CVolumes. The MipVolume class
  20. // implements the IDirect3DVolumeTexture8 interface; each Volume implements
  21. // the IDirect3DVolume8 interface. To reduce overhead per level, we have
  22. // put most of the "real" guts of each volume into the container class;
  23. // i.e. most of the methods of the Volume really just end up calling
  24. // something in the MipVolume object.
  25. //
  26. // The base class implementation assumes a sys-mem allocation.
  27. //
  28. class CMipVolume : public CBaseTexture, public IDirect3DVolumeTexture8
  29. {
  30. public:
  31. // Creation method to allow creation of MipVolumes no matter
  32. // their actual underlying type.
  33. static HRESULT Create(CBaseDevice *pDevice,
  34. DWORD cpWidth,
  35. DWORD cpHeight,
  36. DWORD cpDepth,
  37. DWORD cLevels,
  38. DWORD dwUsage,
  39. D3DFORMAT Format,
  40. D3DPOOL Pool,
  41. IDirect3DVolumeTexture8 **ppMipVolume);
  42. // Destructor
  43. virtual ~CMipVolume();
  44. // IUnknown methods
  45. STDMETHOD(QueryInterface) (REFIID riid,
  46. VOID **ppvObj);
  47. STDMETHOD_(ULONG,AddRef) ();
  48. STDMETHOD_(ULONG,Release) ();
  49. // IDirect3DResource methods
  50. STDMETHOD(GetDevice) (IDirect3DDevice8 **ppvObj);
  51. STDMETHOD(SetPrivateData)(REFGUID riid,
  52. CONST VOID *pvData,
  53. DWORD cbData,
  54. DWORD dwFlags);
  55. STDMETHOD(GetPrivateData)(REFGUID riid,
  56. VOID *pvData,
  57. DWORD *pcbData);
  58. STDMETHOD(FreePrivateData)(REFGUID riid);
  59. STDMETHOD_(DWORD, GetPriority)();
  60. STDMETHOD_(DWORD, SetPriority)(DWORD dwPriority);
  61. STDMETHOD_(void, PreLoad)();
  62. STDMETHOD_(D3DRESOURCETYPE, GetType)();
  63. // IDirect3DMipTexture methods
  64. STDMETHOD_(DWORD, GetLOD)();
  65. STDMETHOD_(DWORD, SetLOD)(DWORD dwLOD);
  66. STDMETHOD_(DWORD, GetLevelCount)();
  67. // IDirect3DMipVolume methods
  68. STDMETHOD(GetLevelDesc)(UINT iLevel, D3DVOLUME_DESC *pDesc);
  69. STDMETHOD(GetVolumeLevel)(UINT iLevel,
  70. IDirect3DVolume8 **ppVolumeLevel);
  71. STDMETHOD(LockBox)(UINT iLevel,
  72. D3DLOCKED_BOX *pLockedBox,
  73. CONST D3DBOX *pBox,
  74. DWORD dwFlags);
  75. STDMETHOD(UnlockBox)(UINT iLevel);
  76. STDMETHOD(AddDirtyBox)(CONST D3DBOX *pBox);
  77. // Direct accessor for surface descriptor
  78. const D3DVOLUME_DESC *Desc() const
  79. {
  80. return &m_desc;
  81. } // AccessDesc;
  82. // Helper for Lock
  83. void ComputeMipVolumeOffset(UINT iLevel,
  84. CONST D3DBOX *pBox,
  85. D3DLOCKED_BOX *pLockedBoxData)
  86. {
  87. CPixel::ComputeMipVolumeOffset(Desc(),
  88. iLevel,
  89. m_rgbPixels,
  90. pBox,
  91. pLockedBoxData);
  92. } // ComputeMipVolumeOffset
  93. // Notification when a mip-level is locked for writing
  94. void OnVolumeLock(DWORD iLevel, CONST D3DBOX *pBox, DWORD dwFlags);
  95. // Methods for the CResource
  96. // Specifies a creation of a resource that
  97. // looks just like the current one; in a new POOL
  98. // with a new LOD.
  99. virtual HRESULT Clone(D3DPOOL Pool,
  100. CResource **ppResource) const;
  101. // Provides a method to access basic structure of the
  102. // pieces of the resource.
  103. virtual const D3DBUFFER_DESC* GetBufferDesc() const;
  104. // Updates destination with source dirty rects
  105. virtual HRESULT UpdateDirtyPortion(CResource *pResourceTarget);
  106. // Allows the Resource Manager to mark the texture
  107. // as needing to be completely updated on next
  108. // call to UpdateDirtyPortion
  109. virtual void MarkAllDirty();
  110. // Methods for CBaseTexture
  111. // Method for UpdateTexture to call; does type-specific
  112. // parameter checking before calling UpdateDirtyPortion
  113. virtual HRESULT UpdateTexture(CBaseTexture *pTextureTarget);
  114. // Parameter validation method to make sure that no part of
  115. // the texture is locked.
  116. #ifdef DEBUG
  117. virtual BOOL IsTextureLocked();
  118. #endif // DEBUG
  119. private:
  120. // Constructor returns an error code
  121. // if the object could not be fully
  122. // constructed
  123. CMipVolume(CBaseDevice *pDevice,
  124. DWORD cpWidth,
  125. DWORD cpHeight,
  126. DWORD cpDepth,
  127. DWORD cLevels,
  128. DWORD dwUsage,
  129. D3DFORMAT Format,
  130. D3DPOOL Pool,
  131. REF_TYPE refType,
  132. HRESULT *phr
  133. );
  134. // Internal implementation of AddDirtyBox
  135. void InternalAddDirtyBox(CONST D3DBOX *pBox);
  136. // Each MipVolume has an array of CMipSurfaces
  137. CVolume **m_VolumeArray;
  138. // Each MipVolume has a memory block that holds
  139. // all the pixel data in a contiguous chunk
  140. BYTE *m_rgbPixels;
  141. // Keep track of description
  142. D3DVOLUME_DESC m_desc;
  143. // In DX7 we kept track of upto 6 RECTs per mip-chain.
  144. // These rects indicate which portion of the top-most level of
  145. // a mip-chain were modified. (We continue to ignore modifications
  146. // to lower levels of the mip-chain. This is by-design.)
  147. //
  148. // For MipVolumes, we follow the same guidelines.. but it is less
  149. // clear that this is the right number to choose.
  150. enum
  151. {
  152. MIPVOLUME_MAXDIRTYBOX = 6,
  153. MIPVOLUME_ALLDIRTY = 7
  154. };
  155. D3DBOX m_DirtyBoxArray[MIPVOLUME_MAXDIRTYBOX];
  156. // If m_cBoxUsed is greater than MIPVOLUME_MAXDIRTYBOX
  157. // then it means that everything is dirty
  158. UINT m_cBoxUsed;
  159. }; // class CMipVolume
  160. #endif // __MIPVOL_HPP__