home *** CD-ROM | disk | FTP | other *** search
/ PC Open 18 / pcopen18_giallo.iso / Win95 / SDK / DOCS / README / DDRAW.TXT < prev    next >
Encoding:
Text File  |  1997-07-14  |  41.9 KB  |  901 lines

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