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.

231 lines
8.0 KiB

  1. #ifndef __CUBEMAP_HPP__
  2. #define __CUBEMAP_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: cubesurface.h
  8. * Content: Class header for the cube-map class. This class acts a
  9. * container for the (planar) Surfaces that are used as textures.
  10. * The textures are organized into a set of 6 possible faces
  11. * each of which is mip-mapped
  12. *
  13. *
  14. ***************************************************************************/
  15. // Includes
  16. #include "texture.hpp"
  17. #include "pixel.hpp"
  18. // Forward decls
  19. class CCubeSurface;
  20. //
  21. // The cube-map class holds a collection of CCubeSurfaces. The CubeMap class
  22. // implements the IDirect3DCubeTexture8 interface; each CubeSurface implements the
  23. // IDirect3DSurface8 interface. To reduce overhead per level, we have
  24. // put most of the "real" guts of each surface into the CubeMap container class;
  25. // i.e. most of the methods of the CubeSurface really just end up calling
  26. // something in the CubeMap object.
  27. //
  28. // The base class implementation assumes a sys-mem allocation.
  29. //
  30. class CCubeMap : public CBaseTexture, public IDirect3DCubeTexture8
  31. {
  32. public:
  33. static HRESULT Create(CBaseDevice *pDevice,
  34. DWORD cpEdge,
  35. DWORD cLevels,
  36. DWORD dwUsage,
  37. D3DFORMAT Format,
  38. D3DPOOL Pool,
  39. IDirect3DCubeTexture8 **ppCubeMap);
  40. // Destructor
  41. virtual ~CCubeMap();
  42. // IUnknown methods
  43. STDMETHOD(QueryInterface) (REFIID riid,
  44. VOID FAR **ppvObj);
  45. STDMETHOD_(ULONG,AddRef) ();
  46. STDMETHOD_(ULONG,Release) ();
  47. // IDirect3DResource methods
  48. STDMETHOD(GetDevice)(IDirect3DDevice8 ** ppvObj);
  49. STDMETHOD(SetPrivateData)(REFGUID riid,
  50. CONST VOID *pvData,
  51. DWORD cbData,
  52. DWORD dwFlags);
  53. STDMETHOD(GetPrivateData)(REFGUID riid,
  54. VOID *pvData,
  55. DWORD *pcbData);
  56. STDMETHOD(FreePrivateData)(REFGUID riid);
  57. STDMETHOD_(DWORD, GetPriority)();
  58. STDMETHOD_(DWORD, SetPriority)(DWORD dwPriority);
  59. STDMETHOD_(void, PreLoad)();
  60. STDMETHOD_(D3DRESOURCETYPE, GetType)();
  61. // IDirect3DMipTexture methods
  62. STDMETHOD_(DWORD, GetLOD)();
  63. STDMETHOD_(DWORD, SetLOD)(DWORD dwLOD);
  64. STDMETHOD_(DWORD, GetLevelCount)();
  65. // IDirect3DCubeMap methods
  66. STDMETHOD(GetLevelDesc)(UINT iLevel, D3DSURFACE_DESC *pDesc);
  67. STDMETHOD(GetCubeMapSurface)(D3DCUBEMAP_FACES FaceType,
  68. UINT iLevel,
  69. IDirect3DSurface8 **ppCubeMapSurface);
  70. STDMETHOD(LockRect)(D3DCUBEMAP_FACES FaceType,
  71. UINT iLevel,
  72. D3DLOCKED_RECT *pLockedRectData,
  73. CONST RECT *pRect,
  74. DWORD dwFlags);
  75. STDMETHOD(UnlockRect)(D3DCUBEMAP_FACES FaceType,
  76. UINT iLevel);
  77. STDMETHOD(AddDirtyRect)(D3DCUBEMAP_FACES FaceType,
  78. CONST RECT *pRect);
  79. // Public helper stuff
  80. // Direct accessor for surface descriptor
  81. const D3DSURFACE_DESC *Desc() const
  82. {
  83. return &m_desc;
  84. } // AccessDesc;
  85. // Helper for Lock
  86. void ComputeCubeMapOffset(UINT iFace,
  87. UINT iLevel,
  88. CONST RECT *pRect,
  89. D3DLOCKED_RECT *pLockedRectData)
  90. {
  91. BYTE *pbFace = m_rgbPixels + iFace * m_cbSingleFace;
  92. CPixel::ComputeMipMapOffset(Desc(),
  93. iLevel,
  94. pbFace,
  95. pRect,
  96. pLockedRectData);
  97. } // ComputeCubeMapOffset
  98. // Notification when a cube-surface is locked for writing
  99. void OnSurfaceLock(DWORD iFace,
  100. DWORD iLevel,
  101. CONST RECT *pRect,
  102. DWORD dwFlags);
  103. // Methods for CResource
  104. // Specifies a creation of a resource that
  105. // looks just like the current one; in a new POOL
  106. // with a new LOD.
  107. virtual HRESULT Clone(D3DPOOL Pool,
  108. CResource **ppResource) const;
  109. // Provides a method to access basic structure of the
  110. // pieces of the resource. A resource may be composed
  111. // of one or more buffers.
  112. virtual const D3DBUFFER_DESC* GetBufferDesc() const;
  113. // Updates destination with source dirty rects
  114. virtual HRESULT UpdateDirtyPortion(CResource *pResourceTarget);
  115. // Allows the Resource Manager to mark the texture
  116. // as needing to be completely updated on next
  117. // call to UpdateDirtyPortion
  118. virtual void MarkAllDirty();
  119. // Methods for CBaseTexture
  120. // Method for UpdateTexture to call; does type-specific
  121. // parameter checking before calling UpdateDirtyPortion
  122. virtual HRESULT UpdateTexture(CBaseTexture *pTextureTarget);
  123. // Parameter validation method to make sure that no part of
  124. // the texture is locked.
  125. #ifdef DEBUG
  126. virtual BOOL IsTextureLocked();
  127. #endif // DEBUG
  128. private:
  129. // Constructor returns an error code
  130. // if the object could not be fully
  131. // constructed
  132. CCubeMap(CBaseDevice *pDevice,
  133. DWORD cpEdge,
  134. DWORD cLevels,
  135. DWORD dwUsage,
  136. D3DFORMAT UserFormat,
  137. D3DFORMAT RealFormat,
  138. D3DPOOL Pool,
  139. REF_TYPE refType,
  140. HRESULT *phr
  141. );
  142. // Internally keep track of current
  143. // set of dirty rects
  144. void InternalAddDirtyRect(DWORD iFace, CONST RECT *pRect);
  145. // Helpful accessor for getting to a particular
  146. // level of the cube-map
  147. #undef DPF_MODNAME
  148. #define DPF_MODNAME "CCubeMap::GetSurface"
  149. CCubeSurface *GetSurface(D3DCUBEMAP_FACES FaceType, DWORD iLevel)
  150. {
  151. DXGASSERT(FaceType <= CUBEMAP_MAXFACES);
  152. DXGASSERT(iLevel < m_cLevels);
  153. DXGASSERT(m_prgCubeSurfaces);
  154. return m_prgCubeSurfaces[FaceType * m_cLevels + iLevel];
  155. } // GetSurface
  156. // Each cubemap has an array of CCubeSurfaces
  157. CCubeSurface **m_prgCubeSurfaces;
  158. // Each cubemap has a memory block that holds
  159. // all the pixel data in a contiguous chunk
  160. BYTE *m_rgbPixels;
  161. // Keep track of how much memory we needed
  162. // for an entire face (including alignment padding)
  163. DWORD m_cbSingleFace;
  164. // Keep track of description
  165. D3DSURFACE_DESC m_desc;
  166. // In DX7 we kept track of upto 6 RECTs per mip-chain.
  167. // These rects indicate which portion of the top-most level of
  168. // a mip-chain were modified. (We continue to ignore modifications
  169. // to lower levels of the mip-chain. This is by-design.)
  170. //
  171. // NOTE: However, for cube-maps, it isn't clear what the right
  172. // dirty rect system ought to be. So we keep track of one
  173. // rect per-face (which is a union of all the locks taken
  174. // on that face). If we have a real-world app using managed
  175. // cube-maps, we really should profile it and examine usage
  176. // patterns.
  177. enum
  178. {
  179. CUBEMAP_MAXFACES = 6,
  180. };
  181. RECT m_DirtyRectArray[CUBEMAP_MAXFACES];
  182. // To ease processing, we also keep the following data
  183. BOOL m_IsFaceCleanArray[CUBEMAP_MAXFACES];
  184. BOOL m_IsFaceAllDirtyArray[CUBEMAP_MAXFACES];
  185. BOOL m_IsAnyFaceDirty;
  186. }; // class CCubeMap
  187. #endif // __CUBEMAP_HPP__