ReactOS 0.4.15-dev-7924-g5949c20
format.h File Reference
#include <d3d9.h>
#include "d3d9_private.h"
Include dependency graph for format.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define D3DFORMAT_OP_DMAP   0x00020000L
 
#define D3DFORMAT_OP_NOTEXCOORDWRAPNORMIP   0x01000000L
 

Functions

BOOL IsBackBufferFormat (D3DFORMAT Format)
 
BOOL IsExtendedFormat (D3DFORMAT Format)
 
BOOL IsZBufferFormat (D3DFORMAT Format)
 
BOOL IsMultiElementFormat (D3DFORMAT Format)
 
BOOL IsSupportedFormatOp (LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT DisplayFormat, DWORD FormatOp)
 
HRESULT CheckDeviceType (LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed)
 
HRESULT CheckDeviceFormat (LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat)
 
HRESULT CheckDeviceFormatConversion (LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat)
 
HRESULT CheckDepthStencilMatch (LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
 

Macro Definition Documentation

◆ D3DFORMAT_OP_DMAP

#define D3DFORMAT_OP_DMAP   0x00020000L

Definition at line 15 of file format.h.

◆ D3DFORMAT_OP_NOTEXCOORDWRAPNORMIP

#define D3DFORMAT_OP_NOTEXCOORDWRAPNORMIP   0x01000000L

Definition at line 19 of file format.h.

Function Documentation

◆ CheckDepthStencilMatch()

HRESULT CheckDepthStencilMatch ( LPD3D9_DRIVERCAPS  pDriverCaps,
D3DFORMAT  AdapterFormat,
D3DFORMAT  RenderTargetFormat,
D3DFORMAT  DepthStencilFormat 
)

Definition at line 539 of file format.c.

540{
541 const DWORD NumFormatOps = pDriverCaps->NumSupportedFormatOps;
542 BOOL bRenderTargetAvailable = FALSE;
543 BOOL bDepthStencilAvailable = FALSE;
544 BOOL bForceSameDepthStencilBits = FALSE;
545 DWORD FormatIndex;
546
548 {
549 return D3DERR_NOTAVAILABLE;
550 }
551
552 if (DepthStencilFormat != D3DFMT_D16_LOCKABLE &&
553 DepthStencilFormat != D3DFMT_D32F_LOCKABLE)
554 {
555 if (TRUE == IsStencilFormat(DepthStencilFormat))
556 {
557 bForceSameDepthStencilBits = TRUE;
558 }
559 }
560
561 if (FALSE == bForceSameDepthStencilBits &&
562 (DepthStencilFormat == D3DFMT_D32 || DepthStencilFormat == D3DFMT_D24X8))
563 {
564 bForceSameDepthStencilBits = TRUE;
565 }
566
567 DepthStencilFormat = GetStencilFormat(pDriverCaps, DepthStencilFormat);
568
569 /* Observe the multiple conditions */
570 for (FormatIndex = 0; FormatIndex < NumFormatOps && (bRenderTargetAvailable == FALSE || bDepthStencilAvailable == FALSE); FormatIndex++)
571 {
572 const LPDDSURFACEDESC pSurfaceDesc = &pDriverCaps->pSupportedFormatOps[FormatIndex];
573 const DWORD FourCC = pSurfaceDesc->ddpfPixelFormat.dwFourCC;
574 const DWORD FormatOperations = pSurfaceDesc->ddpfPixelFormat.dwOperations;
575
576 if (FALSE == bRenderTargetAvailable &&
577 FourCC == RenderTargetFormat &&
578 (FormatOperations & D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET) != 0)
579 {
580 bRenderTargetAvailable = TRUE;
581 }
582
583 if (FALSE == bDepthStencilAvailable &&
584 FourCC == DepthStencilFormat &&
585 (FormatOperations & D3DFORMAT_OP_ZSTENCIL) != 0)
586 {
587 bDepthStencilAvailable = TRUE;
588
589 if ((FormatOperations & D3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH) != 0)
590 {
591 bForceSameDepthStencilBits = FALSE;
592 }
593 }
594 }
595
596 if (FALSE == bRenderTargetAvailable || FALSE == bDepthStencilAvailable)
597 {
598 return D3DERR_INVALIDCALL;
599 }
600
601 if (TRUE == bForceSameDepthStencilBits)
602 {
603 if (GetPixelStride(RenderTargetFormat) != GetPixelStride(DepthStencilFormat))
604 return D3DERR_NOTAVAILABLE;
605 }
606
607 return D3D_OK;
608}
@ D3DFMT_D16_LOCKABLE
Definition: d3d8types.h:640
@ D3DFMT_D32
Definition: d3d8types.h:641
@ D3DFMT_D24X8
Definition: d3d8types.h:645
@ D3DFMT_D32F_LOCKABLE
Definition: d3d9types.h:816
#define D3D_OK
Definition: d3d.h:106
#define D3DERR_INVALIDCALL
#define D3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH
Definition: ddrawi.h:1582
#define D3DFORMAT_OP_DISPLAYMODE
Definition: ddrawi.h:1584
#define D3DFORMAT_OP_ZSTENCIL
Definition: ddrawi.h:1581
#define D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET
Definition: ddrawi.h:1580
#define D3DFORMAT_OP_3DACCELERATION
Definition: ddrawi.h:1585
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL IsSupportedFormatOp(LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT DisplayFormat, DWORD FormatOp)
Definition: format.c:206
BOOL IsStencilFormat(D3DFORMAT Format)
Definition: format.c:51
static D3DFORMAT GetStencilFormat(LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT CheckFormat)
Definition: format.c:276
DWORD GetPixelStride(D3DFORMAT Format)
Definition: format.c:194
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define D3DERR_NOTAVAILABLE
Definition: d3d8.h:84
LPDDSURFACEDESC pSupportedFormatOps
Definition: d3d9_private.h:80
DWORD NumSupportedFormatOps
Definition: d3d9_private.h:79

Referenced by DECLARE_INTERFACE_(), and IDirect3D9Impl_CheckDepthStencilMatch().

◆ CheckDeviceFormat()

HRESULT CheckDeviceFormat ( LPD3D9_DRIVERCAPS  pDriverCaps,
D3DFORMAT  AdapterFormat,
DWORD  Usage,
D3DRESOURCETYPE  RType,
D3DFORMAT  CheckFormat 
)

Definition at line 326 of file format.c.

327{
328 const DWORD NumFormatOps = pDriverCaps->NumSupportedFormatOps;
329 DWORD NonCompatibleOperations = 0, MustSupportOperations = 0;
330 BOOL bSupportedWithAutogen = FALSE;
331 DWORD FormatOpIndex;
332
334 {
335 return D3DERR_NOTAVAILABLE;
336 }
337
338 /* Check for driver auto generated mip map support if requested */
339 if ((Usage & (D3DUSAGE_AUTOGENMIPMAP)) != 0)
340 {
341 switch (RType)
342 {
343 case D3DRTYPE_TEXTURE:
344 if ((pDriverCaps->DriverCaps9.TextureCaps & D3DPTEXTURECAPS_MIPMAP) == 0)
345 return D3DERR_NOTAVAILABLE;
346
347 break;
348
349 case D3DRTYPE_VOLUME:
351 if ((pDriverCaps->DriverCaps9.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP) == 0)
352 return D3DERR_NOTAVAILABLE;
353
354 break;
355
357 if ((pDriverCaps->DriverCaps9.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP) == 0)
358 return D3DERR_NOTAVAILABLE;
359
360 break;
361
362 default:
363 /* Do nothing */
364 break;
365 }
366
367 MustSupportOperations |= D3DFORMAT_OP_AUTOGENMIPMAP;
368 }
369
370 /* Translate from RType and Usage parameters to FormatOps */
371 switch (RType)
372 {
373 case D3DRTYPE_TEXTURE:
374 MustSupportOperations |= D3DFORMAT_OP_TEXTURE;
375 break;
376
377 case D3DRTYPE_VOLUME:
379 MustSupportOperations |= D3DFORMAT_OP_VOLUMETEXTURE;
380 break;
381
383 MustSupportOperations |= D3DFORMAT_OP_CUBETEXTURE;
384 break;
385
386 default:
387 /* Do nothing */
388 break;
389 }
390
391 if (Usage == 0 && RType == D3DRTYPE_SURFACE)
392 {
393 MustSupportOperations |= D3DFORMAT_OP_OFFSCREENPLAIN;
394 }
395
396 if ((Usage & D3DUSAGE_DEPTHSTENCIL) != 0)
397 {
398 MustSupportOperations |= D3DFORMAT_OP_ZSTENCIL;
399 }
400
401 if ((Usage & D3DUSAGE_DMAP) != 0)
402 {
403 MustSupportOperations |= D3DFORMAT_OP_DMAP;
404 }
405
407 {
408 MustSupportOperations |= D3DFORMAT_OP_BUMPMAP;
409 }
410
411 if ((Usage & D3DUSAGE_QUERY_SRGBREAD) != 0)
412 {
413 MustSupportOperations |= D3DFORMAT_OP_SRGBREAD;
414 }
415
416 if ((Usage & D3DUSAGE_QUERY_SRGBWRITE) != 0)
417 {
418 MustSupportOperations |= D3DFORMAT_OP_SRGBWRITE;
419 }
420
422 {
423 MustSupportOperations |= D3DFORMAT_OP_VERTEXTEXTURE;
424 }
425
426 CheckFormat = GetStencilFormat(pDriverCaps, CheckFormat);
427
428 if ((Usage & D3DUSAGE_RENDERTARGET) != 0)
429 {
430 if (AdapterFormat == CheckFormat)
431 {
432 MustSupportOperations |= D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET;
433 }
434 else
435 {
436 D3DFORMAT NonAlphaAdapterFormat;
437 D3DFORMAT NonAlphaCheckFormat;
438
439 NonAlphaAdapterFormat = RemoveAlphaChannel(AdapterFormat);
440 NonAlphaCheckFormat = RemoveAlphaChannel(CheckFormat);
441
442 if (NonAlphaAdapterFormat == NonAlphaCheckFormat &&
443 NonAlphaCheckFormat != D3DFMT_UNKNOWN)
444 {
446 }
447 else
448 {
449 MustSupportOperations |= D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
450 }
451 }
452 }
453
454 if ((Usage & D3DUSAGE_QUERY_FILTER) != 0)
455 {
456 NonCompatibleOperations |= D3DFORMAT_OP_OFFSCREENPLAIN;
457 }
458
460 {
461 NonCompatibleOperations |= D3DFORMAT_OP_NOALPHABLEND;
462 }
463
464 if ((Usage & D3DUSAGE_QUERY_WRAPANDMIP) != 0)
465 {
466 NonCompatibleOperations |= D3DFORMAT_OP_NOTEXCOORDWRAPNORMIP;
467 }
468
469 for (FormatOpIndex = 0; FormatOpIndex < NumFormatOps; FormatOpIndex++)
470 {
472 LPDDSURFACEDESC pSurfaceDesc = &pDriverCaps->pSupportedFormatOps[FormatOpIndex];
473
474 if (pSurfaceDesc->ddpfPixelFormat.dwFourCC != CheckFormat)
475 continue;
476
477 dwOperations = pSurfaceDesc->ddpfPixelFormat.dwOperations;
478
479 if ((dwOperations & NonCompatibleOperations) != 0)
480 continue;
481
482 if ((dwOperations & MustSupportOperations) == MustSupportOperations)
483 return D3D_OK;
484
485 if (((dwOperations & MustSupportOperations) | D3DFORMAT_OP_AUTOGENMIPMAP) == MustSupportOperations)
486 bSupportedWithAutogen = TRUE;
487 }
488
489 if (TRUE == bSupportedWithAutogen)
490 return D3DOK_NOAUTOGEN;
491
492 return D3DERR_NOTAVAILABLE;
493}
#define D3DPTEXTURECAPS_MIPCUBEMAP
Definition: d3d8caps.h:125
#define D3DPTEXTURECAPS_MIPMAP
Definition: d3d8caps.h:123
#define D3DPTEXTURECAPS_MIPVOLUMEMAP
Definition: d3d8caps.h:124
@ D3DFMT_UNKNOWN
Definition: d3d8types.h:601
@ D3DRTYPE_TEXTURE
Definition: d3d8types.h:812
@ D3DRTYPE_VOLUMETEXTURE
Definition: d3d8types.h:813
@ D3DRTYPE_CUBETEXTURE
Definition: d3d8types.h:814
@ D3DRTYPE_VOLUME
Definition: d3d8types.h:811
@ D3DRTYPE_SURFACE
Definition: d3d8types.h:810
#define D3DUSAGE_RENDERTARGET
Definition: d3d8types.h:91
enum _D3DFORMAT D3DFORMAT
#define D3DUSAGE_DEPTHSTENCIL
Definition: d3d8types.h:92
#define D3DOK_NOAUTOGEN
Definition: d3d9.h:105
#define D3DUSAGE_QUERY_SRGBREAD
Definition: d3d9types.h:119
#define D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
Definition: d3d9types.h:118
#define D3DUSAGE_QUERY_FILTER
Definition: d3d9types.h:116
#define D3DUSAGE_QUERY_WRAPANDMIP
Definition: d3d9types.h:122
#define D3DUSAGE_QUERY_LEGACYBUMPMAP
Definition: d3d9types.h:117
#define D3DUSAGE_AUTOGENMIPMAP
Definition: d3d9types.h:113
#define D3DUSAGE_QUERY_SRGBWRITE
Definition: d3d9types.h:120
#define D3DUSAGE_DMAP
Definition: d3d9types.h:114
#define D3DUSAGE_QUERY_VERTEXTEXTURE
Definition: d3d9types.h:121
#define D3DFORMAT_OP_NOALPHABLEND
Definition: ddrawi.h:1596
#define D3DFORMAT_OP_OFFSCREEN_RENDERTARGET
Definition: ddrawi.h:1579
#define D3DFORMAT_OP_AUTOGENMIPMAP
Definition: ddrawi.h:1597
#define D3DFORMAT_OP_TEXTURE
Definition: ddrawi.h:1576
#define D3DFORMAT_OP_BUMPMAP
Definition: ddrawi.h:1590
#define D3DFORMAT_OP_VERTEXTEXTURE
Definition: ddrawi.h:1598
#define D3DFORMAT_OP_SRGBWRITE
Definition: ddrawi.h:1595
#define D3DFORMAT_OP_CUBETEXTURE
Definition: ddrawi.h:1578
#define D3DFORMAT_OP_OFFSCREENPLAIN
Definition: ddrawi.h:1588
#define D3DFORMAT_OP_SRGBREAD
Definition: ddrawi.h:1589
#define D3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET
Definition: ddrawi.h:1583
#define D3DFORMAT_OP_VOLUMETEXTURE
Definition: ddrawi.h:1577
static D3DFORMAT RemoveAlphaChannel(D3DFORMAT CheckFormat)
Definition: format.c:302
#define D3DFORMAT_OP_NOTEXCOORDWRAPNORMIP
Definition: format.h:19
#define D3DFORMAT_OP_DMAP
Definition: format.h:15
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
DWORD dwOperations
Definition: ddraw.h:5
D3DCAPS9 DriverCaps9
Definition: d3d9_private.h:68
DWORD TextureCaps
Definition: d3d9caps.h:279

Referenced by DECLARE_INTERFACE_(), and IDirect3D9Impl_CheckDeviceFormat().

◆ CheckDeviceFormatConversion()

HRESULT CheckDeviceFormatConversion ( LPD3D9_DRIVERCAPS  pDriverCaps,
D3DFORMAT  SourceFormat,
D3DFORMAT  TargetFormat 
)

Definition at line 495 of file format.c.

496{
497 D3DFORMAT NonAlphaSourceFormat;
498 D3DFORMAT NonAlphaTargetFormat;
499
500 NonAlphaSourceFormat = RemoveAlphaChannel(SourceFormat);
501 NonAlphaTargetFormat = RemoveAlphaChannel(TargetFormat);
502
503 if (NonAlphaSourceFormat == NonAlphaTargetFormat)
504 {
505 return D3D_OK;
506 }
507
508 if (FALSE == IsFourCCFormat(SourceFormat))
509 {
510 switch (SourceFormat)
511 {
512 case D3DFMT_A8R8G8B8:
513 case D3DFMT_X8R8G8B8:
514 case D3DFMT_R5G6B5:
515 case D3DFMT_X1R5G5B5:
516 case D3DFMT_A1R5G5B5:
518 /* Do nothing, valid SourceFormat */
519 break;
520
521 default:
522 return D3DERR_NOTAVAILABLE;
523 }
524 }
525 else if (pDriverCaps->DriverCaps9.DevCaps2 == 0)
526 {
527 return D3D_OK;
528 }
529
530 if (FALSE == IsSupportedFormatOp(pDriverCaps, SourceFormat, D3DFORMAT_OP_CONVERT_TO_ARGB) ||
531 FALSE == IsSupportedFormatOp(pDriverCaps, TargetFormat, D3DFORMAT_MEMBEROFGROUP_ARGB))
532 {
533 return D3DERR_NOTAVAILABLE;
534 }
535
536 return D3D_OK;
537}
@ D3DFMT_A1R5G5B5
Definition: d3d8types.h:608
@ D3DFMT_X1R5G5B5
Definition: d3d8types.h:607
@ D3DFMT_A8R8G8B8
Definition: d3d8types.h:604
@ D3DFMT_R5G6B5
Definition: d3d8types.h:606
@ D3DFMT_X8R8G8B8
Definition: d3d8types.h:605
@ D3DFMT_A2R10G10B10
Definition: d3d9types.h:779
#define D3DFORMAT_MEMBEROFGROUP_ARGB
Definition: ddrawi.h:1594
#define D3DFORMAT_OP_CONVERT_TO_ARGB
Definition: ddrawi.h:1587
BOOL IsFourCCFormat(D3DFORMAT Format)
Definition: format.c:37
DWORD DevCaps2
Definition: d3d9caps.h:317

Referenced by DECLARE_INTERFACE_(), and IDirect3D9Impl_CheckDeviceFormatConversion().

◆ CheckDeviceType()

HRESULT CheckDeviceType ( LPD3D9_DRIVERCAPS  pDriverCaps,
D3DFORMAT  DisplayFormat,
D3DFORMAT  BackBufferFormat,
BOOL  Windowed 
)

Definition at line 224 of file format.c.

225{
227 {
228 return D3DERR_NOTAVAILABLE;
229 }
230
231 if (DisplayFormat != BackBufferFormat)
232 {
233 D3DFORMAT AdjustedDisplayFormat = DisplayFormat;
234
235 if (DisplayFormat == D3DFMT_X8R8G8B8)
236 {
237 DisplayFormat = D3DFMT_A8R8G8B8;
238 }
239 else if (DisplayFormat == D3DFMT_X1R5G5B5)
240 {
241 DisplayFormat = D3DFMT_A1R5G5B5;
242 }
243
244 if (AdjustedDisplayFormat == BackBufferFormat)
245 {
246 if (FALSE == IsSupportedFormatOp(pDriverCaps, AdjustedDisplayFormat, D3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET))
247 {
248 return D3DERR_NOTAVAILABLE;
249 }
250
251 return D3D_OK;
252 }
253 else if (FALSE == Windowed)
254 {
255 return D3DERR_NOTAVAILABLE;
256 }
257
258 if (FALSE == IsSupportedFormatOp(pDriverCaps, BackBufferFormat, D3DFORMAT_OP_OFFSCREEN_RENDERTARGET) ||
259 FALSE == IsSupportedFormatOp(pDriverCaps, BackBufferFormat, D3DFORMAT_OP_CONVERT_TO_ARGB) ||
260 FALSE == IsSupportedFormatOp(pDriverCaps, BackBufferFormat, D3DFORMAT_MEMBEROFGROUP_ARGB))
261 {
262 return D3DERR_NOTAVAILABLE;
263 }
264 }
265 else
266 {
267 if (FALSE == IsSupportedFormatOp(pDriverCaps, DisplayFormat, D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET))
268 {
269 return D3DERR_NOTAVAILABLE;
270 }
271 }
272
273 return D3D_OK;
274}

Referenced by DECLARE_INTERFACE_(), and IDirect3D9Impl_CheckDeviceType().

◆ IsBackBufferFormat()

BOOL IsBackBufferFormat ( D3DFORMAT  Format)

Definition at line 14 of file format.c.

15{
16 return ((Format >= D3DFMT_A8R8G8B8) && (Format < D3DFMT_A1R5G5B5)) ||
18}
BOOL IsExtendedFormat(D3DFORMAT Format)
Definition: format.c:20

Referenced by IDirect3D9Impl_CheckDeviceType().

◆ IsExtendedFormat()

BOOL IsExtendedFormat ( D3DFORMAT  Format)

Definition at line 20 of file format.c.

21{
22 return (Format == D3DFMT_A2R10G10B10);
23}

Referenced by IDirect3D9Impl_CheckDeviceType(), and IsBackBufferFormat().

◆ IsMultiElementFormat()

BOOL IsMultiElementFormat ( D3DFORMAT  Format)

Definition at line 32 of file format.c.

33{
34 return (Format == D3DFMT_MULTI2_ARGB8);
35}
@ D3DFMT_MULTI2_ARGB8
Definition: d3d9types.h:804

Referenced by IDirect3D9Impl_CheckDeviceFormat().

◆ IsSupportedFormatOp()

BOOL IsSupportedFormatOp ( LPD3D9_DRIVERCAPS  pDriverCaps,
D3DFORMAT  DisplayFormat,
DWORD  FormatOp 
)

Definition at line 206 of file format.c.

207{
208 const DWORD NumFormatOps = pDriverCaps->NumSupportedFormatOps;
209 DWORD FormatOpIndex;
210
211 for (FormatOpIndex = 0; FormatOpIndex < NumFormatOps; FormatOpIndex++)
212 {
213 const LPDDSURFACEDESC pSurfaceDesc = &pDriverCaps->pSupportedFormatOps[FormatOpIndex];
214 if (pSurfaceDesc->ddpfPixelFormat.dwFourCC == DisplayFormat &&
215 (pSurfaceDesc->ddpfPixelFormat.dwOperations & FormatOp) == FormatOp)
216 {
217 return TRUE;
218 }
219 }
220
221 return FALSE;
222}

Referenced by CheckDepthStencilMatch(), CheckDeviceFormat(), CheckDeviceFormatConversion(), CheckDeviceType(), and GetStencilFormat().

◆ IsZBufferFormat()

BOOL IsZBufferFormat ( D3DFORMAT  Format)

Definition at line 25 of file format.c.

26{
28
29 return TRUE;
30}
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by IDirect3D9Impl_CheckDeviceFormat().