D3D9GraphicsImpl.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright (c) 2008-2022 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../../GraphicsAPI/Direct3D9/D3D9ShaderProgram.h"
  5. #include "../../GraphicsAPI/Direct3D9/D3D9VertexDeclaration.h"
  6. #include "../../Math/Color.h"
  7. #include <d3d9.h>
  8. namespace Urho3D
  9. {
  10. #define URHO3D_SAFE_RELEASE(p) if (p) { ((IUnknown*)p)->Release(); p = 0; }
  11. #define URHO3D_LOGD3DERROR(msg, hr) URHO3D_LOGERRORF("%s (HRESULT %x)", msg, (unsigned)hr)
  12. using ShaderProgramMap_D3D9 = HashMap<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgram_D3D9>>;
  13. using VertexDeclarationMap_D3D9 = HashMap<unsigned long long, SharedPtr<VertexDeclaration_D3D9>>;
  14. /// %Graphics implementation. Holds API-specific objects.
  15. class URHO3D_API GraphicsImpl_D3D9
  16. {
  17. friend class Graphics;
  18. public:
  19. /// Construct.
  20. GraphicsImpl_D3D9();
  21. /// Return Direct3D device.
  22. IDirect3DDevice9* GetDevice() const { return device_; }
  23. /// Return device capabilities.
  24. const D3DCAPS9& GetDeviceCaps() const { return deviceCaps_; }
  25. /// Return adapter identifier.
  26. const D3DADAPTER_IDENTIFIER9& GetAdapterIdentifier() const { return adapterIdentifier_; }
  27. /// Return whether a texture format and usage is supported.
  28. bool CheckFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCETYPE type);
  29. /// Return whether a multisample level is supported.
  30. bool CheckMultiSampleSupport(D3DFORMAT format, int level);
  31. private:
  32. /// Direct3D interface.
  33. IDirect3D9* interface_;
  34. /// Direct3D device.
  35. IDirect3DDevice9* device_;
  36. /// Default color surface.
  37. IDirect3DSurface9* defaultColorSurface_;
  38. /// Default depth-stencil surface.
  39. IDirect3DSurface9* defaultDepthStencilSurface_;
  40. /// Frame query for flushing the GPU command queue.
  41. IDirect3DQuery9* frameQuery_;
  42. /// Adapter number.
  43. DWORD adapter_;
  44. /// Device type.
  45. D3DDEVTYPE deviceType_;
  46. /// Device capabilities.
  47. D3DCAPS9 deviceCaps_;
  48. /// Adapter identifier.
  49. D3DADAPTER_IDENTIFIER9 adapterIdentifier_;
  50. /// Direct3D presentation parameters.
  51. D3DPRESENT_PARAMETERS presentParams_;
  52. /// Texture min filter modes in use.
  53. D3DTEXTUREFILTERTYPE minFilters_[MAX_TEXTURE_UNITS];
  54. /// Texture mag filter modes in use.
  55. D3DTEXTUREFILTERTYPE magFilters_[MAX_TEXTURE_UNITS];
  56. /// Texture mip filter modes in use.
  57. D3DTEXTUREFILTERTYPE mipFilters_[MAX_TEXTURE_UNITS];
  58. /// Texture U coordinate addressing modes in use.
  59. D3DTEXTUREADDRESS uAddressModes_[MAX_TEXTURE_UNITS];
  60. /// Texture V coordinate addressing modes in use.
  61. D3DTEXTUREADDRESS vAddressModes_[MAX_TEXTURE_UNITS];
  62. /// Texture W coordinate addressing modes in use.
  63. D3DTEXTUREADDRESS wAddressModes_[MAX_TEXTURE_UNITS];
  64. /// Texture anisotropy setting in use.
  65. unsigned maxAnisotropy_[MAX_TEXTURE_UNITS];
  66. /// Texture border colors in use.
  67. Color borderColors_[MAX_TEXTURE_UNITS];
  68. /// Device lost flag.
  69. bool deviceLost_;
  70. /// Frame query issued flag.
  71. bool queryIssued_;
  72. /// sRGB mode in use.
  73. bool sRGBModes_[MAX_TEXTURE_UNITS];
  74. /// sRGB write flag.
  75. bool sRGBWrite_;
  76. /// Color surfaces in use.
  77. IDirect3DSurface9* colorSurfaces_[MAX_RENDERTARGETS];
  78. /// Depth-stencil surface in use.
  79. IDirect3DSurface9* depthStencilSurface_;
  80. /// Blending enabled flag.
  81. DWORD blendEnable_;
  82. /// Source blend mode.
  83. D3DBLEND srcBlend_;
  84. /// Destination blend mode.
  85. D3DBLEND destBlend_;
  86. /// Blend operation.
  87. D3DBLENDOP blendOp_;
  88. /// Vertex declarations.
  89. VertexDeclarationMap_D3D9 vertexDeclarations_;
  90. /// Stream frequencies by vertex buffer.
  91. unsigned streamFrequencies_[MAX_VERTEX_STREAMS];
  92. /// Stream offsets by vertex buffer.
  93. unsigned streamOffsets_[MAX_VERTEX_STREAMS];
  94. /// Vertex declaration in use.
  95. VertexDeclaration_D3D9* vertexDeclaration_;
  96. /// Shader programs.
  97. ShaderProgramMap_D3D9 shaderPrograms_;
  98. /// Shader program in use.
  99. ShaderProgram_D3D9* shaderProgram_;
  100. };
  101. }