home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / directx2 / docs / ddraw.txt < prev    next >
Encoding:
Text File  |  1996-05-28  |  37.4 KB  |  775 lines

  1. ************************
  2. ***                  ***
  3. ***                  ***
  4. *** DirectDraw Notes ***
  5. ***                  ***
  6. ***                  ***
  7. ************************
  8.  
  9. Last updated  May 22, 1996
  10.  
  11. Notes for DirectDraw 2.0  RC 1
  12. ========================================
  13.  
  14. In some hardware configurations, stretched transparent blits do not work
  15. correctly. If at all possible, when writing DirectDraw applications, you 
  16. should avoid using stretched transparent blits. To work around this 
  17. limitation, you can do a stretched blit to an intermediate surface, followed
  18. by a transparent blit to your original destination surface.
  19.  
  20. On some, relatively rare, older video boards, source color key blitting 
  21. to the primary surface may not work. You can work around this by composing 
  22. your image with transparency to a back buffer, then blitting the result to
  23. the primary surface.
  24.  
  25. DirectDraw::Initialize() is now called if the DirectDraw object
  26. is created with standard COM methods.
  27.  
  28.  
  29. Notes for DirectDraw 2.0  Beta 3
  30. ========================================
  31.  
  32.  
  33. SetDisplayMode now supports setting the monitor refresh rate
  34. ------------------------------------------------------------
  35. The IDirectDraw2::SetDisplayMode function now takes two additional 
  36. parameters.  The dwRefreshRate parameter can be used to specify a 
  37. monitor refresh rate in Hz.  Valid refresh rates can now be enumerated
  38. with the IDirectDraw2::EnumDisplayModes function. The refresh rate is 
  39. returned in the dwRefreshRate field of the DDSURFACEDESC structure.
  40.  
  41. If a refresh rate of 0 is specified in SetDisplayMode, this means to 
  42. revert back to the IDirectDraw behaviour and set the default refresh
  43. rate for the specified mode.  The display driver may or may not enumerate
  44. specific refresh rates for each mode.  If no refresh rate is specified
  45. by the driver for a particular mode, the dwRefreshRate field in the 
  46. DDSURFACEDESC structure set by EnumDisplayModes will be 0.
  47.  
  48.  
  49. Direct Draw modes now respect monitor settings
  50. ----------------------------------------------
  51. Windows 95 allows a user to specify the type of monitor that is being 
  52. used.  DirectDraw now checks the display modes that it knows about against
  53. the display restrictions of the installed monitor.  If it is determined 
  54. that the requested mode is not compatible with the monitor, then SetDisplayMode
  55. will fail.  Only modes which are supported on the installed monitor will be 
  56. enumerated in EnumDisplayModes.
  57.  
  58.  
  59. IDirectDrawSurface2::DDGetInterface now supported
  60. -------------------------------------------------
  61. A new method has been added to the IDirectDrawSurface2 interface which is 
  62. call DDGetInterface.  This function returns a pointer to the DirectDraw 
  63. object that was used to create the specified surface.
  64.  
  65. Direct Draw clipper objects now have a COM class factory
  66. --------------------------------------------------------
  67. Direct Draw clipper objects now have full class factory support for COM
  68. compliance. Clippers can now be created using either CoGetClassObject
  69. to obtain a class factory and then calling CreateInstance or by calling
  70. CoCreateInstance directly. The class identifier for the clipper class is
  71. CLSID_DirectDrawClipper. Please note that it is still possible to create
  72. clipper objects using either of the two existing API functions;
  73. DirectDrawCreateClipper or IDirectDraw::CreateClipper. Class factory 
  74. support is provided in addition to these functions rather than in
  75. replacement of them.
  76.  
  77. Clippers created by the class factory mechanism must be initialized
  78. with the IDirectDrawClipper::Initialize member before use. Initialize
  79. takes two parameters; a DirectDraw driver object interface pointer and
  80. a flags field. Currently the flags field must be 0. If a NULL driver object
  81. is specified then the clipper is not owned by a Direct Draw driver object
  82. and behaves identically to clippers created with DirectDrawCreateClipper.
  83. If a driver object is specified the clipper will be owned by that driver
  84. object and behaves identically to IDirectDraw::CreateClipper.
  85.  
  86. Flip now flips all levels of a mip-map
  87. --------------------------------------
  88. Previously, Flip only flipped the the mip-map level supplied as an
  89. argument. Now, however, Flip will flip all the levels of a mip-map
  90. from the level supplied to the lowest level in the map. A destination
  91. surface can also be provided in which case all levels in the mip-map will
  92. flip to the back buffer in thier flippable chain which matches the supplied
  93. override. For example, if the third back buffer in the top level
  94. flippable chain is supplied all levels in the mip-map will flip to thier
  95. third back buffer.
  96.  
  97. The number of levels in a mip-map is now stored explicitly
  98. ----------------------------------------------------------
  99. The number of levels in a mip-map chain is now stored explicitly.
  100. When the surface description of a mip-map is obtained (via
  101. IDirectDrawSurface::Lock or IDirectDrawSurface::GetSurfaceDesc) the
  102. dwMipMapCount field will contain the number of levels in a mip-map
  103. including the top-level. Note, for levels other than the top-level
  104. in the map, dwMipMapCount will specify the number of levels from
  105. that map to the smallest map in the chain.
  106.  
  107. New surface capability bit for Direct3D texture loading
  108. -------------------------------------------------------
  109. A new surface capability bit, DDSCAPS_ALLOCONLOAD, has been added
  110. to support device dependent and compressed texture surfaces. This
  111. capability bit specifies that a given texture surface does not
  112. have memory allocated for it when it is created. Instead, sufficient
  113. memory will be allocated when the texture is loaded using the Direct3D
  114. texture Load member. Currently the semantics of this bit are not fully
  115. implemented and the width, height and pixel format of the texture
  116. surface should be specified when DDSCAPS_ALLOCONLOAD is specified.
  117. However, for the final release, width, height and pixel format will
  118. not be specified at create time but will be initialized when the
  119. texture is loaded. If DDSCAPS_ALLOCONLOAD is specified so must
  120. DDSCAPS_TEXTURE. For further information see the Direct3D documentation
  121. on the IDirect3DTexture::Load member function.
  122.  
  123.  
  124. Notes for DirectDraw 2.0  Beta 2
  125. ========================================
  126.  
  127.  
  128. Support for high resolutions and TrueColor bit depths
  129. -----------------------------------------------------
  130. Direct Draw supports all of the screen resolutions and depths supported 
  131. by the Display Driver.  Version 1.0 of Direct Draw limited the available 
  132. video modes to 640x480 with pixel depths of 8 bits per pixel and 16 bits 
  133. per pixel.  This restriction has been relaxed and Direct Draw now allows 
  134. an application to change the mode into any mode supported by the Display 
  135. Driver.  This includes all supported 24 and 32 bits-per-pixel modes.
  136.  
  137. Note that this release of Direct Draw does not check the monitor capabilities 
  138. stored by the system to determine if a particular display resolution is 
  139. compatible with the monitor.  This means that an application may use 
  140. EnumerateDisplayModes to determine the available video modes and then switch 
  141. into a mode that is not supported by the monitor.  This is a defect which 
  142. will be corrected in the next release.
  143.  
  144.  
  145. HEL Blitting Support for 24 and 32 bit Surfaces 
  146. -----------------------------------------------
  147. Direct Draw now supports HEL blitting of 24 and 32 bits-per-pixel surfaces.  
  148. If the Display Driver supports blitting at these resolutions then the 
  149. hardware blitter will be used for vram to vram blits.  Otherwise, the 
  150. Hardware Emulation Layer (HEL) will be used to do the blits.
  151.  
  152.  
  153. Multiple Direct Draw Objects per Process
  154. ----------------------------------------
  155. Direct Draw 1.0 only allowed the creation of one Direct Draw object per 
  156. process.  If your process happened to use another system component (such 
  157. as Direct Play) that created a Direct Draw object, the process would be 
  158. unable to create another Direct Draw object for its own use.
  159.  
  160. This restriction has been eliminated in this release.  It is now possible 
  161. for a process to call DirectDrawCreate as many times as necessary.  A 
  162. unique and independent interface will be returned from each call.  Each 
  163. DirectDraw object may be used as desired.  There are no dependencies 
  164. between the objects.  They behave exactly as they would if they had been 
  165. created by two different processes.
  166.  
  167. Since the Direct Draw objects are independent, surface, palette, and 
  168. clipper objects which are created with a particular Direct Draw object 
  169. should not be used with other Direct Draw objects.  This is because these 
  170. objects are automatically released when the Direct Draw object is 
  171. destroyed.  If they are used with another Direct Draw object, they 
  172. may go away if the original object is destroyed.
  173.  
  174. Clipper objects which are created with DirectDrawClipperCreate are 
  175. independent of any particular Direct Draw object and may be used with 
  176. one or more Direct Draw objects.
  177.  
  178.  
  179. SetCooperativeLevel Doesn't Require an HWND for non-Exclusive Mode
  180. ------------------------------------------------------------------
  181. Direct Draw 1.0 required an HWND to be specified in the SetCooperativeLevel 
  182. call regardless of whether or not Full-screen Exclusive mode was being 
  183. requested.  This function no longer requires an HWND to be specified 
  184. if the application is requesting DDSCL_NORMAL mode.  It is now possible 
  185. for an application to use Direct Draw with multiple windows.  All of these 
  186. windows may be used simultaneously in normal windowed mode.
  187.  
  188.  
  189. New IDirectDraw2 and IDirectDrawSurface2 interfaces
  190. ---------------------------------------------------
  191. The COM model that Direct Draw uses specifies that additional functionality 
  192. is provided by providing new interfaces.  This release of Direct Draw 
  193. implements a new Direct Draw interface and a new Direct Draw Surface 
  194. interface.  These new interfaces may be obtained by using QueryInterface 
  195. as shown in the following code fragment:
  196.  
  197.     /*
  198.      * create an IDirectDraw2 interface
  199.      */
  200.     LPDIRECTDRAW        lpDD;
  201.     LPDIRECTDRAW2       lpDD2;
  202.  
  203.     ddrval = DirectDrawCreate( NULL, &lpDD, NULL );
  204.     if( ddrval != DD_OK )
  205.         return;
  206.  
  207.     ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL );
  208.     if( ddrval != DD_OK )
  209.         return;
  210.  
  211.  
  212.     ddrval = lpDD->QueryInterface( IID_IDirectDraw2, (LPVOID *)&lpDD2);
  213.     if( ddrval != DD_OK )
  214.         return;
  215.  
  216.  
  217.     ddscaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  218.     ddrval = lpDD2->GetAvailableVidMem(&ddscaps, &total, &free);
  219.     if( ddrval != DD_OK )
  220.         return;
  221.  
  222. This code fragment shows C++ syntax for creating an IDirectDraw interface 
  223. and then using QueryInterface to create an IDirectDraw2 interface.  It is 
  224. this interface which contains the GetAvailableVidMem function.  An attempt 
  225. to use the GetAvailableVidMem function from an IDirectDraw interface will 
  226. result in a compile-time error.
  227.  
  228. The IDirectDraw2 interface contains all of the same member functions as the 
  229. IDirectDraw interface along with one additional member functions called  
  230. GetAvailableVidMem.  The SetDisplayMode function in this interface will 
  231. allow refresh rates to be specified.  This is not enabled for this beta and 
  232. this function will return DDERR_UNSUPPORTED.  The SetDisplayMode function 
  233. in the IDirectDraw interface can be used instead.
  234.  
  235. The IDirectDrawSurface2 interface contains all of the same member functions 
  236. as the IDirectDrawSurface interface with two additional member functions 
  237. called PageLock and PageUnlock.  The following code fragment shows how to 
  238. create an IDirectDrawSurface2 interface:
  239.  
  240.     LPDIRECTDRAWSURFACE     lpSurf;
  241.     LPDIRECTDRAWSURFACE2    lpSurf2;
  242.  
  243.     // Create surfaces
  244.     memset( &ddsd, 0, sizeof( ddsd ) );
  245.     ddsd.dwSize = sizeof( ddsd );
  246.     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
  247.     ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
  248.                           DDSCAPS_SYSTEMMEMORY;
  249.     ddsd.dwWidth = 10;
  250.     ddsd.dwHeight = 10;
  251.  
  252.     ddrval = lpDD2->CreateSurface( &ddsd, &lpSurf, NULL );
  253.     if( ddrval != DD_OK )
  254.         return;
  255.  
  256.     ddrval = lpSurf->QueryInterface( IID_IDirectDrawSurface2, (LPVOID *)&lpSurf2);
  257.     if( ddrval != DD_OK )
  258.         return;
  259.  
  260.     ddrval = lpSurf2->PageLock( 0 );
  261.     if( ddrval != DD_OK )
  262.         return;
  263.  
  264.     ddrval = lpSurf2->PageUnlock( 0 );
  265.     if( ddrval != DD_OK )
  266.         return;
  267.     
  268.  
  269. New PageLock and PageUnlock functions
  270. -------------------------------------
  271. A new feature that is supported with this release is the capability for 
  272. DirectDraw to allow a driver to control the blitting to or from a system 
  273. memory surface.  A driver may choose to do this blitting by copying the 
  274. bytes one by one or by using DMA transfers.  If the driver uses a DMA 
  275. transfer, it is important that the system memory which contains the bits 
  276. for the surface is locked so that it cannot be paged out while the DMA is 
  277. in progress.  This can be done using the PageLock and PageUnlock functions 
  278. available in the IDirectDrawSurface2 interface.
  279.  
  280. HRESULT PageLock( LPDIRECTDRAWSURFACE lpddSurf, DWORD dwFlags );
  281. HRESULT PageUnlock( LPDIRECTDRAWSURFACE lpddSurf, DWORD dwFlags );
  282.  
  283. There are no flags currently defined for these functions so the only valid 
  284. value for dwFlags is 0.  This function may be called on a vram surface but 
  285. it will simply return DD_OK without doing anything.  If called on a Sytem 
  286. Memory surface (ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY is nonzero) then all 
  287. of the memory pages used by this surface will be locked so that they canÆt 
  288. be paged out.  A Lock count is maintained for each surface and incremented 
  289. each time PageLock is called for that surface.  The count is decremented 
  290. when PageUnlock is called.  When the count reaches 0, the memory is unlocked 
  291. and may then be paged by the operating system.  Note that the performance 
  292. of the operating system may be negatively affected if too much memory is 
  293. locked.
  294.  
  295. The following codes may be returned from these two functions:
  296. DD_OK
  297. DDERR_INVALIDOBJECT
  298. DDERR_INVALIDPARAMS
  299. DDERR_SURFACE_LOCK
  300. DDERR_CANTPAGELOCK
  301.  
  302.  
  303. Driver can now Blit to and from System Memory surfaces
  304. ------------------------------------------------------
  305. In DirectDraw 1.0, if a surface was in system memory, the HEL automatically 
  306. performed the blit.  Some display cards have DMA hardware which allows them 
  307. to efficiently blit to and from system memory surfaces.  The DDCAPS 
  308. structure has been expanded to allow drivers to report this capability.  
  309. The following fields have been added.
  310.  
  311. DWORD   dwSVBCaps
  312. DWORD   dwSVBCKeyCaps
  313. DWORD   dwSVBFXCaps
  314. DWORD   dwSVBRops[DD_ROP_SPACE]
  315.  
  316. DWORD   dwVSBCaps
  317. DWORD   dwVSBCKeyCaps
  318. DWORD   dwVSBFXCaps
  319. DWORD   dwVSBRops[DD_ROP_SPACE]
  320.  
  321. DWORD   dwSSBCaps
  322. DWORD   dwSSBCKeyCaps
  323. DWORD   dwSSBFXCaps
  324. DWORD   dwSSBRops[DD_ROP_SPACE]
  325.  
  326. The SVB prefix indicates capabilities bits that relate to System memory to 
  327. Video memory Blits.  The VSB prefix indicates capabilities bits that relate 
  328. to Video memory to System memory Blits.  The SSB prefix indicates 
  329. capabilities bits that relate to System memory to System memory Blits.
  330.  
  331. The dwSVBCaps field corresponds to the dwCaps field except that it describes 
  332. the blitting capabilities of the display driver for System Memory to Video 
  333. Memory blits.  Likewise, the dwSVBCKeyCaps corresponds to the dwCKeyCaps 
  334. field and dwSVBFXCaps corresponds to dwFXCaps.  The dwSVBRops array describes 
  335. the raster ops that the driver supports for this type of blit.
  336.  
  337. These fields are only valid if the DDCAPS_CANBLTSYSMEM bit is set in dwCaps 
  338. indicating that the driver is able to blit to or from system memory.
  339.  
  340. If the system memory surface being used by the hardware blitter is not 
  341. locked, Direct Draw will automatically call PageLock on the surface to insure 
  342. that the memory has been locked.  
  343.  
  344.  
  345. DirectDraw Palette Objects
  346. ==========================
  347.  
  348. Setting Palettes on Non-Primary surfaces
  349. ----------------------------------------
  350. In DirectDraw 1.0 palettes could only be attached to the primary surface.
  351. Palettes can now be attached to any palletized surface (primary, back
  352. buffer, offscreen plain or texture map). Only those palettes attached 
  353. to primary surfaces will have any effect on the system palette. In it
  354. important to note that DirectDraw blits never perform color conversion -
  355. any palettes attached to the source or destination surface of a blit are 
  356. ignored. Furthermore, the DirectDraw surface function GetDC() also ignores
  357. any DirectDraw palette selected into the surface.
  358.  
  359. Non-primary surface palettes are intended for use by applications or
  360. Direct3D (or other 3D renderer).
  361.  
  362. Sharing Palettes
  363. ----------------
  364. Palettes can now be shared between multiple surfaces. The same palette
  365. can be set on the front and back buffer of a flipping chain or shared
  366. between multiple texture surfaces. When a palette is attached to a
  367. surface with SetPalette(), the surface increments the reference count 
  368. of that palette. When the reference count of the surface reaches zero
  369. it will decrement the reference count of the attached palette. In
  370. addition, if a palette is detached from a surface by calling SetPalette()
  371. with a NULL palette interface pointer, the reference count of the
  372. surface's palette will be decremented. Please note that if SetPalette()
  373. is called several times consecutively for the same surface with the 
  374. same palette the reference count for the palette will be incremented
  375. once only. Subsequent calls will not effect the paletteÆs reference count.
  376.  
  377. New Palette Types
  378. -----------------
  379. In additional to the 8-bit (256 entry) palettes supported previously,
  380. DirectDraw 2.0 supports 1-bit (2 entry), 2-bit (4 entry) and 4-bit
  381. (16 entry) palettes. Such palettes can by created by specifying one of
  382. the new palette capability flags; DDPCAPS_1BIT, DDPCAPS_2BIT and
  383. DDPCAPS_4BIT. Matching capability flags have been added for surface
  384. pixel formats (DDPF_PALETTEINDEXED1, DDPF_PALETTEINDEXED2 and
  385. DDPF_PALETTEINDEXED4). A palette can only be attached to a surface with
  386. a matching pixel format. For example, a 2 entry palette created with the
  387. DDPCAPS_1BIT flag can only be attached to a 1-bit surface created with
  388. the pixel format flag DDPF_PALETTEINDEXED1 etc. Furthermore, it is now
  389. possible to create indexed palettes. An indexed palette is one whose
  390. entries do not hold RGB colors but integer indices into the array of
  391. PALETTEENTRYs of some target palette. An indexed palette's color table
  392. is an array of 2, 4, 16 or 256 bytes where each byte is an index into
  393. some unspecified, destination palette.
  394.  
  395. To create an indexed palette specify the palette capability flag
  396. DDPCAPS_8BITENTRIES when calling CreatePalette(). For example, to
  397. create a 4-bit, indexed palette specify DPCAPS_4BIT | DDPCAPS_8BITENTRIES.
  398. When creating an indexed palette a pointer to an array of BYTEs is passed
  399. rather than a pointer to an array of PALETTEENTRY structures. The pointer
  400. to the array of BYTEs must be cast to an LPPALETTEENTRY when calling
  401. CreatePalette().
  402.  
  403. DirectDraw Clipper Objects
  404. ==========================
  405.  
  406. Sharing Clippers
  407. ----------------
  408. Clippers can now be shared between multiple surfaces. For example, the
  409. same clipper can be set on both the front and back buffers of a flipping
  410. chain. When a clipper is attached to a surface with SetClipper(), the
  411. surface increments the reference count of that clipper. When the reference
  412. count of the surface reaches zero it will decrement the reference count 
  413. of the attached clipper. In addition, if a clipper is detached from a
  414. surface by calling SetClipper() with a NULL clipper interface pointer,
  415. the reference count of the surface's clipper will be decremented.
  416.  
  417. Please note that if SetClipper() is called several times consecutively
  418. for the same surface with the same clipper the reference count for the
  419. clipper will be incremented once only. Subsequent calls will not 
  420. effect the clipper's reference count.
  421.  
  422. Driver Independent Clippers
  423. ---------------------------
  424. It is now possible to create clipper objects which are not owned by a
  425. DirectDraw driver object. Such clippers can be shared across multiple
  426. driver objects. Driver independent clipper objects are created with 
  427. the new DirectDraw API function DirectDrawCreateClipper(). This function
  428. can be called before any DirectDraw driver objects are created. As these
  429. clippers are not owned by any DirectDraw driver object, they are not
  430. automatically released when an application's driver objects are released.
  431. If not released explicitly by the application such clippers will be
  432. released by DirectDraw when the application terminates.
  433.  
  434. It is still possible to create clippers with the DirectDraw interface
  435. member function CreateClipper(). Such clippers behave identically to
  436. the clippers of DirectDraw 1.0. Specifically they will be automatically
  437. released when the driver object from which they were created is released.
  438.  
  439. Enhanced Surface Format Support in the Hardware Emulation Layer (HEL)
  440. =====================================================================
  441.  
  442. In DirectDraw 1.0 the Hardware Emulation Layer (HEL) could only create
  443. surfaces whose pixel format exactly matched that of the current primary
  444. surface. This restriction has been relaxed for DirectDraw 2.0. 
  445.  
  446. The HEL now supports the following pixel formats for offscreen plain
  447. surfaces.
  448.  
  449. Pixel Format Flags                Bit Depth  Red Mask   Green Mask  Blue Mask  Alpha Mask
  450. DDPF_RGB | DDPF_PALETTEINDEXED1    1         0x00000000 0x00000000  0x00000000 0x00000000
  451. DDPF_RGB | DDPF_PALETTEINDEXED2    2         0x00000000 0x00000000  0x00000000 0x00000000
  452. DDPF_RGB | DDPF_PALETTEINDEXED4    4         0x00000000 0x00000000  0x00000000 0x00000000
  453. DDPF_RGB | DDPF_PALETTEINDEXED8    8         0x00000000 0x00000000  0x00000000 0x00000000
  454. DDPF_RGB                          16         0x0000F800 0x000007E0  0x0000001F 0x00000000
  455. DDPF_RGB                          16         0x00007C00 0x000003E0  0x0000001F 0x00000000
  456. DDPF_RGB                          24         0x00FF0000 0x0000FF00  0x000000FF 0x00000000
  457. DDPF_RGB                          24         0x000000FF 0x0000FF00  0x00FF0000 0x00000000
  458. DDPF_RGB                          32         0x00FF0000 0x0000FF00  0x000000FF 0x00000000
  459. DDPF_RGB                          32         0x000000FF 0x0000FF00  0x00FF0000 0x00000000
  460.  
  461. In addition to supporting a wider range of offscreen surface formats the
  462. HEL also supports surfaces intended for use by Direct3D (or other 3D
  463. renders). These surfaces are discussed in the next section.
  464.  
  465. Support for 3D Surfaces
  466. =======================
  467.  
  468. Support for surfaces specific to 3D rendering has been enhanced in
  469. DirectDraw 2.0. The 3D specific surface types; texture maps, mipmaps
  470. and Z-buffers will be discussed below.
  471.  
  472. Texture Maps
  473. ------------
  474. The surface capability flag used to indicate that a surface is a texture
  475. is DDSCAPS_TEXTURE. This flag was previously DDSCAPS_TEXTUREMAP but was
  476. modified for consistency with Direct3D. Texture maps can now be allocated
  477. in system memory using the HEL. To allocate a texture map surface specify
  478. the DDSCAPS_TEXTURE flag in the ddsCaps field of the surface description
  479. passed to CreateSurface(). A wide range of texture pixel formats are
  480. supported by the HEL. These formats are as follows:
  481.  
  482. Pixel Format Flags                 Bit Depth  Red Mask   Green Mask  Blue Mask  Alpha Mask
  483. DDPF_RGB | DDPF_PALETTEINDEXED1,    1         0x00000000 0x00000000  0x00000000 0x00000000 
  484. DDPF_RGB | DDPF_PALETTEINDEXED1 |
  485.            DDPF_PALETTEINDEXEDTO8   1         0x00000000 0x00000000  0x00000000 0x00000000
  486. DDPF_RGB | DDPF_PALETTEINDEXED2     2         0x00000000 0x00000000  0x00000000 0x00000000
  487. DDPF_RGB | DDPF_PALETTEINDEXED2 |
  488.            DDPF_PALETTEINDEXEDTO8   2         0x00000000 0x00000000  0x00000000 0x00000000
  489. DDPF_RGB | DDPF_PALETTEINDEXED4     4         0x00000000 0x00000000  0x00000000 0x00000000
  490. DDPF_RGB | DDPF_PALETTEINDEXED4 |
  491.            DDPF_PALETTEINDEXEDTO8   4         0x00000000 0x00000000  0x00000000 0x00000000
  492. DDPF_RGB | DDPF_PALETTEINDEXED8     8         0x00000000 0x00000000  0x00000000 0x00000000
  493. DDPF_RGB,                           8         0x000000E0 0x0000001C  0x00000003 0x00000000
  494. DDPF_RGB | DDPF_ALPHAPIXELS,       16         0x00000F00 0x000000F0  0x0000000F 0x0000F000
  495. DDPF_RGB,                          16         0x0000F800 0x000007E0  0x0000001F 0x00000000
  496. DDPF_RGB,                          16         0x0000001F 0x000007E0  0x0000F800 0x00000000
  497. DDPF_RGB,                          16         0x00007C00 0x000003E0  0x0000001F 0x00000000
  498. DDPF_RGB | DDPF_ALPHAPIXELS,       16         0x00007C00 0x000003E0  0x0000001F 0x00008000
  499. DDPF_RGB,                          24         0x00FF0000 0x0000FF00  0x000000FF 0x00000000
  500. DDPF_RGB,                          24         0x000000FF 0x0000FF00  0x00FF0000 0x00000000
  501. DDPF_RGB,                          32         0x00FF0000 0x0000FF00  0x000000FF 0x00000000
  502. DDPF_RGB,                          32         0x000000FF 0x0000FF00  0x00FF0000 0x00000000
  503. DDPF_RGB | DDPF_ALPHAPIXELS,       32         0x00FF0000 0x0000FF00  0x000000FF 0xFF000000
  504. DDPF_RGB | DDPF_ALPHAPIXELS,       32         0x000000FF 0x0000FF00  0x00FF0000 0xFF000000
  505.  
  506. The above formats are those which can be created by the HEL in system
  507. memory. The DirectDraw driver for a 3D accelerated video card is free to
  508. create textures of other formats in video memory. Such a driver should
  509. export the DDSCAPS_TEXTURE bit to indicate that it can create textures
  510. and should be prepared to handle the DirectDraw HAL callback,
  511. CanCreateSurface() to verify that the surface description for a texture
  512. map is one the driver is prepared to create.
  513.  
  514. Mipmaps
  515. -------
  516. DirectDraw 2.0 supports mipmapped texture surfaces. A mipmap is a
  517. sequence of textures, each of which is a progressively lower resolution,
  518. pre-filtered representation of the same image. Mipmaps are a
  519. computationally low cost way of improving the quality of rendered textures.
  520. Each pre-filtered image (or level) in the mipmap is a power of two
  521. smaller than the previous level. In DirectDraw 2.0 mipmaps are represented
  522. as a chain of attached surfaces. The highest resolution texture is at the
  523. head of the chain and has, as an attachment, the next level of the mipmap
  524. which has, in turn, an attachment which is the next level in the mipmap
  525. and so on down to the lowest resolution level of the mipmap.
  526.  
  527. To create a surface representing a single level of a mipmap specify the
  528. DDSCAPS_MIPMAP surface capability in the surface description passed to
  529. CreateSurface(). As all mipmaps are also textures the DDSCAPS_TEXTURE
  530. capability must also be specified. It is possible to create each level
  531. manually and build the chain with AddAttachedSurface(). However,
  532. CreateSurface() can be used to build an entire mipmap chain in a single
  533. operation. The following code fragment demonstrates building a chain 
  534. of five mipmap levels of sizes 256x256, 128x128, 64x64, 32x32 and 16x16.
  535.  
  536.         DDSURFACEDESC       ddsd;
  537.         LPDIRECTDRAWSURFACE lpDDMipMap;
  538.         ZeroMemory(&ddsd, sizeof(ddsd));
  539.         ddsd.dwSize = sizeof(ddsd);
  540.         ddsd.dwFlags = DDSD_CAPS | DDSD_MIPMAPCOUNT;
  541.         ddsd.dwMipMapCount = 5;
  542.         ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP | 
  543.                 DDSCAPS_COMPLEX;
  544.         ddsd.dwWidth = 256UL;
  545.         ddsd.dwHeight = 256UL;
  546.  
  547.         ddres = lpDD->CreateSurface(&ddsd, &lpDDMipMap);
  548.         if (FAILED(ddres))
  549.                 ...
  550.                 
  551. It is permissible to omit the number of mipmaps levels, in which case
  552. CreateSurface() will create a chain of surfaces each a power of two
  553. smaller than the previous one down to the smallest possible size. It is 
  554. also possible to omit the width and height in which case CreateSurface()
  555. will create the number of levels you specify with a minimum level size of
  556. 1x1.
  557.  
  558. A chain of mipmap surfaces is traversed using GetAttachedSurface()
  559. specifying the DDSCAPS_MIPMAP and DDSCAPS_TEXTURE capability flags. The
  560. following code fragment traverses a mipmap chain from highest to lowest
  561. resolutions.
  562.  
  563.         LPDIRECTDRAWSURFACE lpDDLevel, lpDDNextLevel;
  564.         DDSCAPS ddsCaps;
  565.  
  566.         lpDDLevel = lpDDMipMap;
  567.         lpDDLevel->AddRef();
  568.         ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
  569.         ddres = DD_OK;
  570.         while (ddres == DD_OK)
  571.         {
  572.                 // Process this level
  573.                 ...     
  574.                 ddres = lpDDLevel->GetAttachedSurface(&ddsCaps,                 
  575.                         &lpDDNextLevel);
  576.                 lpDDLevel->Release();
  577.                 lpDDLevel = lpDDNextLevel;
  578.         }
  579.         if ((ddres != DD_OK) && (ddres != DDERR_NOTFOUND))
  580.                 ...
  581.                 
  582. It is also possible to build flippable chains of mipmaps. In this
  583. scenario each mipmap level has an associated chain of back buffer
  584. texture surfaces. Each back buffer texture is attached to one level
  585. of the mipmap. Only the front buffer in the chain has DDSCAPS_MIPMAP
  586. set, the others are simply texture maps (DDSCAPS_TEXTURE). A mipmap
  587. level can have two attached texture maps, one with the capability flag 
  588. DDSCAPS_MIPMAP set, which is the next level in the mipmap chain, and one
  589. with the capability flag DDSCAPS_BACKBUFFER set, which is back buffer
  590. of the flippable chain. Note that all the surfaces in each flippable
  591. chain must be of the same size.
  592.  
  593. It is not possible to build such a surface arrangement with a single
  594. call to CreateSurface(). To construct a flippable mipmap either build
  595. a complex mipmap chain and manually attach backbuffers with
  596. AddAttachedSurface() or create a sequence of flippable chains and
  597. build the mipmap with AddAttachedSurface().
  598.  
  599. It is important to note that blit operations apply to only a single
  600. level in the mipmap chain. To blit an entire chain of mipmaps each
  601. level must be blit separately. Also note that Flip()will not currently
  602. flip an entire mipmap chain but only a single level of the mipmap. This
  603. is a defect and will be corrected.
  604.  
  605. Z Buffers
  606. ---------
  607. The DirectDraw HEL can now create Z buffers for use by Direct3D (or
  608. other 3D rendering software). The HEL supports both 16 and 32-bit
  609. Z buffers. The DirectDraw driver for a 3D accelerated video card can 
  610. permit the creation of Z buffers in video memory by exporting the surface
  611. capability bit DDSCAPS_ZBUFFER. It should also specify the Z buffer
  612. depths it supports using the dwZBufferBitDepth field of the DDCAPS
  613. structure.
  614.  
  615. Z buffers can be cleared using the DirectDraw surface function Blt().
  616. A new DDBLT_ flag (DDBLT_DEPTHFILL) has been defined to indicate that
  617. the blit is a Z buffer clear. If this flag is specified the DDBLTFX
  618. structure passed to Blt() should have its dwFillDepth field set to
  619. the required Z depth. If the DirectDraw driver for a 3D accelerated
  620. video card wishes to provide support for Z buffer clearing in hardware
  621. it should export the capability flag DDCAPS_BLTDEPTHFILL and should
  622. have code to handle DDBLT_DEPTHFILL blits. The destination surface
  623. of a depth fill blit must be a Z buffer. Please note that the actual
  624. interpretation of depth value is 3D renderer specific.
  625.  
  626. Direct3D Integration
  627. ====================
  628.  
  629. DirectDraw 2.0 is very tightly integrated with Direct3D. The most
  630. important aspects of this integration are discussed below.
  631.  
  632. The Direct3D Driver Interface
  633. -----------------------------
  634. DirectDraw 2.0 presents a single, unified driver object to the
  635. application programmer. This driver object encapsulates both
  636. DirectDraw and Direct3D state. The DirectDraw driver COM interfaces 
  637. (IID_IDirectDraw or IID_IDirectDraw2) and the Direct3D driver COM interface 
  638. (IID_IDirect3D) are both interfaces which allow the application programmer
  639. to communicate with the same underlying driver object. Hence no Direct3D
  640. driver object is created. Rather a Direct3D interface to the DirectDraw
  641. driver object is obtained. This is achieved using the standard COM 
  642. QueryInterface() function.
  643.  
  644. The following code fragment demonstrates creating the DirectDraw driver
  645. object and obtaining a Direct3D interface for communicating with that object.
  646.  
  647.         LPDIRECTDRAW lpDD;
  648.         LPDIRECT3D   lpD3D;
  649.         ddres = DirectDrawCreate(NULL, &lpDD, NULL);
  650.         if (FAILED(ddres))
  651.                 ...
  652.         ddres = lpDD->QueryInterface(IID_IDirect3D, &lpD3D);
  653.         if (FAILED(ddres))
  654.                 ...
  655.                 
  656. The above code creates a single object and obtains two interfaces to
  657. that object. Hence, the reference count of the driver object after the
  658. QueryInterface() is two. The important implication of this is that the
  659. lifetime of the Direct3D driver state is the same as that of the DirectDraw
  660. object. Releasing the Direct3D interface does not destroy the Direct3D
  661. driver state. That state is not destroyed until all references (both
  662. DirectDraw and Direct3D) to that driver object have been released.
  663. Hence, if you release a Direct3D interface, while holding a reference
  664. to a DirectDraw driver interface, and then re-query the Direct3D
  665. interface all the Direct3D state will be preserved.
  666.  
  667. The Direct3D Device Interface
  668. -----------------------------
  669. As with the driver object, there is no distinct Direct3D device object.
  670. A Direct3D device is simply an interface for communicating with a
  671. DirectDraw surface used as a 3D rendering target. For example, the 
  672. following code fragment creates a Direct3D device interface to a
  673. DirectDraw surface object.
  674.  
  675.         LPDIRECTDRAWSURFACE lpDDSurface;
  676.         LPDIRECT3DDEVICE    lpD3DDevice;
  677.  
  678.         ddres = lpDD->CreateSurface(&ddsd, &lpDDSurface, NULL);
  679.         if (FAILED(ddres))
  680.                 ...
  681.         ddres = lpDDSurface->QueryInterface(lpGuid, &lpD3DDevice);
  682.         if (FAILED(ddres))
  683.                 ...
  684.                 
  685. The same rules of reference counting and state lifetime discussed for
  686. driver objects apply to DirectDraw surfaces and Direct3D devices.
  687. Additionally, multiple, distinct Direct3D device interfaces can be
  688. obtained for the same DirectDraw surface. Hence, it is possible that
  689. a single DirectDraw surface be the target for both a ramp based device
  690. and an RGB based device.
  691.  
  692. The Direct3D Texture Interface
  693. ------------------------------
  694. Direct3D textures are, once again, not a distinct object type but
  695. rather another interface of DirectDraw surface objects. The following
  696. code fragment obtains a Direct3D texture interface from a DirectDraw 
  697. surface object.
  698.  
  699.         LPDIRECTDRAWSURFACE lpDDSurface;
  700.         LPDIRECT3DTEXTURE   lpD3DTexture;
  701.  
  702.         ddres = lpDD->CreateSurface(&ddsd, &lpDDSurface, NULL);
  703.         if (FAILED(ddres))
  704.                 ...
  705.         ddres = lpDDSurface->QueryInterface(IID_IDirect3DTexture, 
  706.                 &lpD3DTexture);
  707.         if (FAILED(ddres))
  708.                 ...
  709.                 
  710. The same reference counting and state lifetime rules of driver objects
  711. and devices apply. It is possible to use a single DirectDraw surface as
  712. both a rendering target and a texture.
  713.  
  714. The DirectDraw HEL and Direct3D
  715. -------------------------------
  716. The DirectDraw HEL has been enhanced to support the creation of texture,
  717. mipmap and Z buffer surfaces. Furthermore, due to the tight integration
  718. of DirectDraw and Direct3D, a DirectDraw enabled system will always
  719. provide Direct3D support (in software emulation at least). Hence, the
  720. DirectDraw HEL exports the DDCAPS_3D capability flag to indicate the
  721. availability of Direct3D in software emulation. A DirectDraw driver for
  722. a hardware accelerated 3D video card should export this capability flag
  723. to indicate the presence of hardware accelerated 3D.
  724.  
  725. GetAvailableVidMem
  726. ==================
  727. DirectDraw 2.0 adds a new DirectDraw interface function to query the
  728. amount of video memory available to a specific type of surface as
  729. defined by surface capability flags. To ensure COM compliance this 
  730. function is not a member of the DirectDraw 1.0 interface but is part
  731. of the new DirectDraw 2.0 interface, IID_IDirectDraw2. To invoke this
  732. function you must first query for the new DirectDraw interface. 
  733.  
  734. The following code fragment demonstrates using GetAvailableVidMem()
  735. to determine both the total and free video memory available for
  736. texture map surfaces.
  737.  
  738.         LPDIRECTDRAW2 lpDD2;
  739.         DDSCAPS       ddsCaps;
  740.         DWORD         dwTotal;
  741.         DWORD         dwFree;
  742.  
  743.         ddres = lpDD->QueryInterface(IID_IDirectDraw2, &lpDD2);
  744.         if (FAILED(ddres))
  745.                 ...
  746.         ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  747.         ddres = lpDD2->GetAvailableVidMem(&ddsCaps, &dwTotal, &dwFree);
  748.         if (FAILED(ddres))
  749.                 ...
  750.                 
  751. It should be noted that this function gives a snapshot of the current
  752. video memory state only. The amount of free video memory is subject to
  753. change as surfaces are created and released. Hence, the free memory 
  754. figure should be used as a rough guide only. In addition, a particular
  755. video card may make no distinction between two different memory types.
  756. For example, it may use the same portion of video memory to store Z 
  757. buffers and textures. Hence, allocating one type of surface (a Z buffer
  758. say) may affect the amount of video memory available for another type
  759. of surface (textures say). Therefore, it is best to first allocate an 
  760. application's fixed resources (such as front, back and Z buffer) before
  761. determining how much memory is available for dynamic use (for texture
  762. mapping, for example).
  763.  
  764. Miscellaneous Changes
  765. =====================
  766.  
  767. New Error Return Codes
  768. ----------------------
  769. DDERR_NOMIPMAPHW - an attempt was made to create a mipmap in video
  770. memory but the hardware DirectDraw driver does not support mipmaps.
  771.  
  772. DDERR_INVALIDSURFACETYPE - an attempt was made to perform an operation
  773. on a surface but the capabilities of that surface do not support the
  774. operation.
  775.