BsD3D11RenderAPI.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsD3D11Prerequisites.h"
  5. #include "BsRenderAPI.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup D3D11
  9. * @{
  10. */
  11. /** Implementation of a render system using DirectX 11. Provides abstracted access to various low level DX11 methods. */
  12. class BS_D3D11_EXPORT D3D11RenderAPI : public RenderAPICore
  13. {
  14. public:
  15. D3D11RenderAPI();
  16. ~D3D11RenderAPI();
  17. /** @copydoc RenderAPICore::getName */
  18. const StringID& getName() const override;
  19. /** @copydoc RenderAPICore::getShadingLanguageName */
  20. const String& getShadingLanguageName() const override;
  21. /** @copydoc RenderAPICore::setBlendState */
  22. void setBlendState(const SPtr<BlendStateCore>& blendState) override;
  23. /** @copydoc RenderAPICore::setRasterizerState */
  24. void setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState) override;
  25. /** @copydoc RenderAPICore::setDepthStencilState */
  26. void setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue) override;
  27. /** @copydoc RenderAPICore::setSamplerState */
  28. void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SPtr<SamplerStateCore>& samplerState) override;
  29. /** @copydoc RenderAPICore::setTexture */
  30. void setTexture(GpuProgramType gptype, UINT16 texUnit, const SPtr<TextureCore>& texture) override;
  31. /** @copydoc RenderAPICore::setLoadStoreTexture */
  32. void setLoadStoreTexture(GpuProgramType gptype, UINT16 texUnit, bool enabled, const SPtr<TextureCore>& texture,
  33. const TextureSurface& surface) override;
  34. /** @copydoc RenderAPICore::setBuffer */
  35. void setBuffer(GpuProgramType gptype, UINT16 unit, const SPtr<GpuBufferCore>& buffer, bool loadStore = false) override;
  36. /** @copydoc RenderAPICore::beginFrame */
  37. void beginFrame() override;
  38. /** @copydoc RenderAPICore::endFrame */
  39. void endFrame() override;
  40. /** @copydoc RenderAPICore::clearRenderTarget */
  41. void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0,
  42. UINT8 targetMask = 0xFF) override;
  43. /** @copydoc RenderAPICore::clearViewport */
  44. void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0,
  45. UINT8 targetMask = 0xFF) override;
  46. /** @copydoc RenderAPICore::setRenderTarget */
  47. void setRenderTarget(const SPtr<RenderTargetCore>& target, bool readOnlyDepthStencil = false) override;
  48. /** @copydoc RenderAPICore::setViewport */
  49. void setViewport(const Rect2& area) override;
  50. /** @copydoc RenderAPICore::setScissorRect */
  51. void setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom) override;
  52. /** @copydoc RenderAPICore::setVertexBuffers */
  53. void setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers) override;
  54. /** @copydoc RenderAPICore::setIndexBuffer */
  55. void setIndexBuffer(const SPtr<IndexBufferCore>& buffer) override;
  56. /** @copydoc RenderAPICore::setVertexDeclaration */
  57. void setVertexDeclaration(const SPtr<VertexDeclarationCore>& vertexDeclaration) override;
  58. /** @copydoc RenderAPICore::setDrawOperation */
  59. void setDrawOperation(DrawOperationType op) override;
  60. /** @copydoc RenderAPICore::draw */
  61. void draw(UINT32 vertexOffset, UINT32 vertexCount, UINT32 instanceCount = 0) override;
  62. /** @copydoc RenderAPICore::drawIndexed */
  63. void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount,
  64. UINT32 instanceCount = 0) override;
  65. /** @copydoc RenderAPICore::dispatchCompute */
  66. void dispatchCompute(UINT32 numGroupsX, UINT32 numGroupsY = 1, UINT32 numGroupsZ = 1) override;
  67. /** @copydoc RenderAPICore::bindGpuProgram */
  68. void bindGpuProgram(const SPtr<GpuProgramCore>& prg) override;
  69. /** @copydoc RenderAPICore::unbindGpuProgram */
  70. void unbindGpuProgram(GpuProgramType gptype) override;
  71. /** @copydoc RenderAPICore::setParamBuffer */
  72. void setParamBuffer(GpuProgramType gptype, UINT32 slot, const SPtr<GpuParamBlockBufferCore>& buffer,
  73. const GpuParamDesc& paramDesc) override;
  74. /** @copydoc RenderAPICore::setClipPlanesImpl */
  75. void setClipPlanesImpl(const PlaneList& clipPlanes) override;
  76. /** @copydoc RenderAPICore::convertProjectionMatrix */
  77. void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest) override;
  78. /** @copydoc RenderAPICore::getAPIInfo */
  79. const RenderAPIInfo& getAPIInfo() const override;
  80. /** @copydoc RenderAPICore::generateParamBlockDesc() */
  81. GpuParamBlockDesc generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params) override;
  82. /************************************************************************/
  83. /* Internal use by DX11 RenderSystem only */
  84. /************************************************************************/
  85. /**
  86. * Determines DXGI multisample settings from the provided parameters.
  87. *
  88. * @param[in] multisampleCount Number of requested samples.
  89. * @param[in] format Pixel format used by the render target.
  90. * @param[out] outputSampleDesc Output structure that will contain the requested multisample settings.
  91. */
  92. void determineMultisampleSettings(UINT32 multisampleCount, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outputSampleDesc);
  93. /** Returns the main DXGI factory object. */
  94. IDXGIFactory* getDXGIFactory() const { return mDXGIFactory; }
  95. /** Returns the primary DX11 device object. */
  96. D3D11Device& getPrimaryDevice() const { return *mDevice; }
  97. /** Returns information describing all available drivers. */
  98. D3D11DriverList* getDriverList() const { return mDriverList; }
  99. protected:
  100. friend class D3D11RenderAPIFactory;
  101. /** @copydoc RenderAPICore::initializePrepare */
  102. void initializePrepare() override;
  103. /** @copydoc RenderAPICore::initializeFinalize */
  104. void initializeFinalize(const SPtr<RenderWindowCore>& primaryWindow) override;
  105. /** @copydoc RenderAPICore::destroyCore */
  106. void destroyCore() override;
  107. /**
  108. * Creates or retrieves a proper input layout depending on the currently set vertex shader and vertex buffer.
  109. *
  110. * Applies the input layout to the pipeline.
  111. */
  112. void applyInputLayout();
  113. /**
  114. * Recalculates actual viewport dimensions based on currently set viewport normalized dimensions and render target
  115. * and applies them for further rendering.
  116. */
  117. void applyViewport();
  118. /** Creates and populates a set of render system capabilities describing which functionality is available. */
  119. RenderAPICapabilities* createRenderSystemCapabilities() const;
  120. private:
  121. IDXGIFactory* mDXGIFactory;
  122. D3D11Device* mDevice;
  123. D3D11DriverList* mDriverList;
  124. D3D11Driver* mActiveD3DDriver;
  125. D3D_FEATURE_LEVEL mFeatureLevel;
  126. D3D11HLSLProgramFactory* mHLSLFactory;
  127. D3D11InputLayoutManager* mIAManager;
  128. std::pair<SPtr<TextureCore>, SPtr<TextureView>> mBoundUAVs[D3D11_PS_CS_UAV_REGISTER_COUNT];
  129. UINT32 mStencilRef;
  130. Rect2 mViewportNorm;
  131. D3D11_VIEWPORT mViewport;
  132. D3D11_RECT mScissorRect;
  133. SPtr<VertexDeclarationCore> mActiveVertexDeclaration;
  134. SPtr<D3D11GpuProgramCore> mActiveVertexShader;
  135. DrawOperationType mActiveDrawOp;
  136. };
  137. /** @} */
  138. }