Leaked source code of windows server 2003
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.

197 lines
6.5 KiB

  1. #ifndef __MIPMAP_HPP__
  2. #define __MIPMAP_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: mipmap.hpp
  8. * Content: Class header the mip-map class. This class acts a
  9. * container for the (planar) Surfaces that are used as textures.
  10. *
  11. *
  12. ***************************************************************************/
  13. // Includes
  14. #include "texture.hpp"
  15. #include "pixel.hpp"
  16. // Forward decls
  17. class CMipSurface;
  18. //
  19. // The mip-map class holds a collection of CMipSurfaces. The MipTexture class
  20. // implements the IDirect3DTexture8 interface; each MipSurface implements the
  21. // IDirect3DSurface8 interface. To reduce overhead per level, we have
  22. // put most of the "real" guts of each surface into the MipMap container
  23. // class; i.e. most of the methods of the MipSurface really just end up
  24. // calling something in the MipMap object.
  25. //
  26. // The base class implementation assumes a sys-mem allocation.
  27. //
  28. class CMipMap : public CBaseTexture, public IDirect3DTexture8
  29. {
  30. public:
  31. // Creation method to allow creation of MipMaps no matter
  32. // their actual underlying type.
  33. static HRESULT Create(CBaseDevice *pDevice,
  34. DWORD cpWidth,
  35. DWORD cpHeight,
  36. DWORD cLevels,
  37. DWORD dwUsage,
  38. D3DFORMAT Format,
  39. D3DPOOL Pool,
  40. IDirect3DTexture8 **ppMipMap);
  41. // Destructor
  42. virtual ~CMipMap();
  43. // IUnknown methods
  44. STDMETHOD(QueryInterface) (REFIID riid,
  45. LPVOID FAR * ppvObj);
  46. STDMETHOD_(ULONG,AddRef) ();
  47. STDMETHOD_(ULONG,Release) ();
  48. // IDirect3DResource methods
  49. STDMETHOD(GetDevice) (IDirect3DDevice8 ** ppvObj);
  50. STDMETHOD(SetPrivateData)(REFGUID riid,
  51. CONST VOID* pvData,
  52. DWORD cbData,
  53. DWORD dwFlags);
  54. STDMETHOD(GetPrivateData)(REFGUID riid,
  55. LPVOID pvData,
  56. LPDWORD pcbData);
  57. STDMETHOD(FreePrivateData)(REFGUID riid);
  58. STDMETHOD_(DWORD, GetPriority)();
  59. STDMETHOD_(DWORD, SetPriority)(DWORD dwPriority);
  60. STDMETHOD_(void, PreLoad)();
  61. STDMETHOD_(D3DRESOURCETYPE, GetType)();
  62. // IDirect3DMipTexture methods
  63. STDMETHOD_(DWORD, GetLOD)();
  64. STDMETHOD_(DWORD, SetLOD)(DWORD dwLOD);
  65. STDMETHOD_(DWORD, GetLevelCount)();
  66. // IDirect3DMipMap methods
  67. STDMETHOD(GetLevelDesc)(UINT iLevel, D3DSURFACE_DESC *pDesc);
  68. STDMETHOD(GetSurfaceLevel)(UINT iLevel,
  69. IDirect3DSurface8 **ppSurfaceLevel);
  70. STDMETHOD(LockRect)(UINT iLevel,
  71. D3DLOCKED_RECT *pLockedRectData,
  72. CONST RECT *pRect,
  73. DWORD dwFlags);
  74. STDMETHOD(UnlockRect)(UINT iLevel);
  75. STDMETHOD(AddDirtyRect)(CONST RECT *pRect);
  76. // Direct accessor for surface descriptor
  77. const D3DSURFACE_DESC *Desc() const
  78. {
  79. return &m_desc;
  80. } // Desc;
  81. // Helper for Lock
  82. void ComputeMipMapOffset(UINT iLevel,
  83. CONST RECT *pRect,
  84. D3DLOCKED_RECT *pLockedRectData) const
  85. {
  86. CPixel::ComputeMipMapOffset(Desc(),
  87. iLevel,
  88. m_rgbPixels,
  89. pRect,
  90. pLockedRectData);
  91. } // ComputeMipMapOffset
  92. // Notification when a mip-level is locked for writing
  93. void OnSurfaceLock(DWORD iLevel, CONST RECT *pRect, DWORD Flags);
  94. // Methods for CResource
  95. // Specifies a creation of a resource that
  96. // looks just like the current one; in a new POOL
  97. // with a new LOD.
  98. virtual HRESULT Clone(D3DPOOL Pool,
  99. CResource **ppResource) const;
  100. // Provides a method to access basic structure of the
  101. // pieces of the resource.
  102. virtual const D3DBUFFER_DESC* GetBufferDesc() const;
  103. // Updates destination with source dirty rects
  104. virtual HRESULT UpdateDirtyPortion(CResource *pResourceTarget);
  105. // Allows the Resource Manager to mark the texture
  106. // as needing to be completely updated on next
  107. // call to UpdateDirtyPortion
  108. virtual void MarkAllDirty();
  109. // Methods for CBaseTexture
  110. // Method for UpdateTexture to call; does type-specific
  111. // parameter checking before calling UpdateDirtyPortion
  112. virtual HRESULT UpdateTexture(CBaseTexture *pTextureTarget);
  113. // Parameter validation method to make sure that no part of
  114. // the texture is locked.
  115. #ifdef DEBUG
  116. virtual BOOL IsTextureLocked();
  117. #endif // DEBUG
  118. private:
  119. // Constructor returns an error code
  120. // if the object could not be fully
  121. // constructed
  122. CMipMap(CBaseDevice *pDevice,
  123. DWORD cpWidth,
  124. DWORD cpHeight,
  125. DWORD cLevels,
  126. DWORD dwUsage,
  127. D3DFORMAT UserFormat,
  128. D3DFORMAT RealFormat,
  129. D3DPOOL Pool,
  130. REF_TYPE refType,
  131. HRESULT *phr
  132. );
  133. // Internally keep track of current
  134. // set of dirty rects
  135. void InternalAddDirtyRect(CONST RECT *pRect);
  136. // Each mipmap has an array of CMipSurfaces
  137. CMipSurface **m_prgMipSurfaces;
  138. // Each mipmap 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. D3DSURFACE_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. enum
  148. {
  149. MIPMAP_MAXDIRTYRECT = 6,
  150. MIPMAP_ALLDIRTY = 7
  151. };
  152. RECT m_DirtyRectArray[MIPMAP_MAXDIRTYRECT];
  153. // If m_cRectUsed is greater than MIPMAP_MAXDIRTYRECT
  154. // then it means that everything is dirty
  155. UINT m_cRectUsed;
  156. }; // class CMipMap
  157. #endif // __MIPMAP_HPP__