D3D11GraphicsImpl.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #include "../../Precompiled.h"
  4. #include "../../Graphics/Graphics.h"
  5. #include "D3D11GraphicsImpl.h"
  6. #include "../../DebugNew.h"
  7. namespace Urho3D
  8. {
  9. GraphicsImpl_D3D11::GraphicsImpl_D3D11() :
  10. device_(nullptr),
  11. deviceContext_(nullptr),
  12. swapChain_(nullptr),
  13. defaultRenderTargetView_(nullptr),
  14. defaultDepthTexture_(nullptr),
  15. defaultDepthStencilView_(nullptr),
  16. depthStencilView_(nullptr),
  17. resolveTexture_(nullptr),
  18. shaderProgram_(nullptr)
  19. {
  20. for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
  21. renderTargetViews_[i] = nullptr;
  22. for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
  23. {
  24. shaderResourceViews_[i] = nullptr;
  25. samplers_[i] = nullptr;
  26. }
  27. for (unsigned i = 0; i < MAX_VERTEX_STREAMS; ++i)
  28. {
  29. vertexBuffers_[i] = nullptr;
  30. vertexSizes_[i] = 0;
  31. vertexOffsets_[i] = 0;
  32. }
  33. for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS; ++i)
  34. {
  35. constantBuffers_[VS][i] = nullptr;
  36. constantBuffers_[PS][i] = nullptr;
  37. }
  38. }
  39. bool GraphicsImpl_D3D11::CheckMultiSampleSupport(DXGI_FORMAT format, unsigned sampleCount) const
  40. {
  41. if (sampleCount < 2)
  42. return true; // Not multisampled
  43. UINT numLevels = 0;
  44. if (FAILED(device_->CheckMultisampleQualityLevels(format, sampleCount, &numLevels)))
  45. return false;
  46. else
  47. return numLevels > 0;
  48. }
  49. unsigned GraphicsImpl_D3D11::GetMultiSampleQuality(DXGI_FORMAT format, unsigned sampleCount) const
  50. {
  51. if (sampleCount < 2)
  52. return 0; // Not multisampled, should use quality 0
  53. if (device_->GetFeatureLevel() >= D3D_FEATURE_LEVEL_10_1)
  54. return 0xffffffff; // D3D10.1+ standard level
  55. UINT numLevels = 0;
  56. if (FAILED(device_->CheckMultisampleQualityLevels(format, sampleCount, &numLevels)) || !numLevels)
  57. return 0; // Errored or sample count not supported
  58. else
  59. return numLevels - 1; // D3D10.0 and below: use the best quality
  60. }
  61. }