D3D9GraphicsImpl.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../../Graphics/ShaderProgram.h"
  24. #include "../../Graphics/VertexDeclaration.h"
  25. #include "../../Math/Color.h"
  26. #include <d3d9.h>
  27. namespace Urho3D
  28. {
  29. #define URHO3D_SAFE_RELEASE(p) if (p) { ((IUnknown*)p)->Release(); p = 0; }
  30. #define URHO3D_LOGD3DERROR(msg, hr) URHO3D_LOGERRORF("%s (HRESULT %x)", msg, (unsigned)hr)
  31. using ShaderProgramMap = HashMap<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgram> >;
  32. using VertexDeclarationMap = HashMap<unsigned long long, SharedPtr<VertexDeclaration> >;
  33. /// %Graphics implementation. Holds API-specific objects.
  34. class URHO3D_API GraphicsImpl
  35. {
  36. friend class Graphics;
  37. public:
  38. /// Construct.
  39. GraphicsImpl();
  40. /// Return Direct3D device.
  41. IDirect3DDevice9* GetDevice() const { return device_; }
  42. /// Return device capabilities.
  43. const D3DCAPS9& GetDeviceCaps() const { return deviceCaps_; }
  44. /// Return adapter identifier.
  45. const D3DADAPTER_IDENTIFIER9& GetAdapterIdentifier() const { return adapterIdentifier_; }
  46. /// Return whether a texture format and usage is supported.
  47. bool CheckFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCETYPE type);
  48. /// Return whether a multisample level is supported.
  49. bool CheckMultiSampleSupport(D3DFORMAT format, int level);
  50. private:
  51. /// Direct3D interface.
  52. IDirect3D9* interface_;
  53. /// Direct3D device.
  54. IDirect3DDevice9* device_;
  55. /// Default color surface.
  56. IDirect3DSurface9* defaultColorSurface_;
  57. /// Default depth-stencil surface.
  58. IDirect3DSurface9* defaultDepthStencilSurface_;
  59. /// Frame query for flushing the GPU command queue.
  60. IDirect3DQuery9* frameQuery_;
  61. /// Adapter number.
  62. DWORD adapter_;
  63. /// Device type.
  64. D3DDEVTYPE deviceType_;
  65. /// Device capabilities.
  66. D3DCAPS9 deviceCaps_;
  67. /// Adapter identifier.
  68. D3DADAPTER_IDENTIFIER9 adapterIdentifier_;
  69. /// Direct3D presentation parameters.
  70. D3DPRESENT_PARAMETERS presentParams_;
  71. /// Texture min filter modes in use.
  72. D3DTEXTUREFILTERTYPE minFilters_[MAX_TEXTURE_UNITS];
  73. /// Texture mag filter modes in use.
  74. D3DTEXTUREFILTERTYPE magFilters_[MAX_TEXTURE_UNITS];
  75. /// Texture mip filter modes in use.
  76. D3DTEXTUREFILTERTYPE mipFilters_[MAX_TEXTURE_UNITS];
  77. /// Texture U coordinate addressing modes in use.
  78. D3DTEXTUREADDRESS uAddressModes_[MAX_TEXTURE_UNITS];
  79. /// Texture V coordinate addressing modes in use.
  80. D3DTEXTUREADDRESS vAddressModes_[MAX_TEXTURE_UNITS];
  81. /// Texture W coordinate addressing modes in use.
  82. D3DTEXTUREADDRESS wAddressModes_[MAX_TEXTURE_UNITS];
  83. /// Texture anisotropy setting in use.
  84. unsigned maxAnisotropy_[MAX_TEXTURE_UNITS];
  85. /// Texture border colors in use.
  86. Color borderColors_[MAX_TEXTURE_UNITS];
  87. /// Device lost flag.
  88. bool deviceLost_;
  89. /// Frame query issued flag.
  90. bool queryIssued_;
  91. /// sRGB mode in use.
  92. bool sRGBModes_[MAX_TEXTURE_UNITS];
  93. /// sRGB write flag.
  94. bool sRGBWrite_;
  95. /// Color surfaces in use.
  96. IDirect3DSurface9* colorSurfaces_[MAX_RENDERTARGETS];
  97. /// Depth-stencil surface in use.
  98. IDirect3DSurface9* depthStencilSurface_;
  99. /// Blending enabled flag.
  100. DWORD blendEnable_;
  101. /// Source blend mode.
  102. D3DBLEND srcBlend_;
  103. /// Destination blend mode.
  104. D3DBLEND destBlend_;
  105. /// Blend operation.
  106. D3DBLENDOP blendOp_;
  107. /// Vertex declarations.
  108. VertexDeclarationMap vertexDeclarations_;
  109. /// Stream frequencies by vertex buffer.
  110. unsigned streamFrequencies_[MAX_VERTEX_STREAMS];
  111. /// Stream offsets by vertex buffer.
  112. unsigned streamOffsets_[MAX_VERTEX_STREAMS];
  113. /// Vertex declaration in use.
  114. VertexDeclaration* vertexDeclaration_;
  115. /// Shader programs.
  116. ShaderProgramMap shaderPrograms_;
  117. /// Shader program in use.
  118. ShaderProgram* shaderProgram_;
  119. };
  120. }