BsD3D11RenderAPI.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #pragma once
  2. #include "BsD3D11Prerequisites.h"
  3. #include "BsRenderAPI.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Implementation of a render system using DirectX 11. Provides abstracted
  8. * access to various low level DX11 methods.
  9. */
  10. class BS_D3D11_EXPORT D3D11RenderAPI : public RenderAPICore
  11. {
  12. public:
  13. D3D11RenderAPI();
  14. ~D3D11RenderAPI();
  15. /**
  16. * @copydoc RenderAPICore::getName
  17. */
  18. const StringID& getName() const override;
  19. /**
  20. * @copydoc RenderAPICore::getShadingLanguageName
  21. */
  22. const String& getShadingLanguageName() const override;
  23. /**
  24. * @copydoc RenderAPICore::setBlendState
  25. */
  26. void setBlendState(const SPtr<BlendStateCore>& blendState) override;
  27. /**
  28. * @copydoc RenderAPICore::setRasterizerState
  29. */
  30. void setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState) override;
  31. /**
  32. * @copydoc RenderAPICore::setDepthStencilState
  33. */
  34. void setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue) override;
  35. /**
  36. * @copydoc RenderAPICore::setSamplerState
  37. */
  38. void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SPtr<SamplerStateCore>& samplerState) override;
  39. /**
  40. * @copydoc RenderAPICore::setTexture
  41. */
  42. void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const SPtr<TextureCore>& texPtr) override;
  43. /**
  44. * @copydoc RenderAPICore::setLoadStoreTexture
  45. */
  46. void setLoadStoreTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const SPtr<TextureCore>& texPtr,
  47. const TextureSurface& surface) override;
  48. /**
  49. * @copydoc RenderAPICore::disableTextureUnit
  50. */
  51. void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit) override;
  52. /**
  53. * @copydoc RenderAPICore::beginFrame
  54. */
  55. void beginFrame() override;
  56. /**
  57. * @copydoc RenderAPICore::endFrame
  58. */
  59. void endFrame() override;
  60. /**
  61. * @copydoc RenderAPICore::clearRenderTarget
  62. */
  63. void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0,
  64. UINT8 targetMask = 0xFF) override;
  65. /**
  66. * @copydoc RenderAPICore::clearViewport
  67. */
  68. void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0,
  69. UINT8 targetMask = 0xFF) override;
  70. /**
  71. * @copydoc RenderAPICore::setRenderTarget
  72. */
  73. void setRenderTarget(const SPtr<RenderTargetCore>& target, bool readOnlyDepthStencil = false) override;
  74. /**
  75. * @copydoc RenderAPICore::setViewport
  76. */
  77. void setViewport(const Rect2& vp) override;
  78. /**
  79. * @copydoc RenderAPICore::setScissorRect
  80. */
  81. void setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom) override;
  82. /**
  83. * @copydoc RenderAPICore::setVertexBuffers
  84. */
  85. void setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers) override;
  86. /**
  87. * @copydoc RenderAPICore::setIndexBuffer
  88. */
  89. void setIndexBuffer(const SPtr<IndexBufferCore>& buffer) override;
  90. /**
  91. * @copydoc RenderAPICore::setVertexDeclaration
  92. */
  93. void setVertexDeclaration(const SPtr<VertexDeclarationCore>& vertexDeclaration) override;
  94. /**
  95. * @copydoc RenderAPICore::setDrawOperation
  96. */
  97. void setDrawOperation(DrawOperationType op) override;
  98. /**
  99. * @copydoc RenderAPICore::draw
  100. */
  101. void draw(UINT32 vertexOffset, UINT32 vertexCount) override;
  102. /**
  103. * @copydoc RenderAPICore::drawIndexed
  104. */
  105. void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount) override;
  106. /**
  107. * @copydoc RenderAPICore::bindGpuProgram
  108. */
  109. void bindGpuProgram(const SPtr<GpuProgramCore>& prg) override;
  110. /**
  111. * @copydoc RenderAPICore::unbindGpuProgram
  112. */
  113. void unbindGpuProgram(GpuProgramType gptype) override;
  114. /**
  115. * @copydoc RenderAPICore::setConstantBuffers
  116. */
  117. void setConstantBuffers(GpuProgramType gptype, const SPtr<GpuParamsCore>& params) override;
  118. /**
  119. * @copydoc RenderAPICore::setClipPlanesImpl
  120. */
  121. void setClipPlanesImpl(const PlaneList& clipPlanes) override;
  122. /**
  123. * @copydoc RenderAPICore::convertProjectionMatrix
  124. */
  125. void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest) override;
  126. /**
  127. * @copydoc RenderAPICore::getColorVertexElementType
  128. */
  129. VertexElementType getColorVertexElementType() const override;
  130. /**
  131. * @copydoc RenderAPICore::getHorizontalTexelOffset
  132. */
  133. float getHorizontalTexelOffset() override;
  134. /**
  135. * @copydoc RenderAPICore::getVerticalTexelOffset
  136. */
  137. float getVerticalTexelOffset() override;
  138. /**
  139. * @copydoc RenderAPICore::getMinimumDepthInputValue
  140. */
  141. float getMinimumDepthInputValue() override;
  142. /**
  143. * @copydoc RenderAPICore::getMaximumDepthInputValue
  144. */
  145. float getMaximumDepthInputValue() override;
  146. /**
  147. * @copydoc RenderAPICore::generateParamBlockDesc()
  148. */
  149. GpuParamBlockDesc generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params) override;
  150. /************************************************************************/
  151. /* Internal use by DX11 RenderSystem only */
  152. /************************************************************************/
  153. /**
  154. * @brief Determines DXGI multisample settings from the provided parameters.
  155. *
  156. * @param multisampleCount Number of requested samples.
  157. * @param format Pixel format used by the render target.
  158. * @param outputSampleDesc Output structure that will contain the requested multisample settings.
  159. */
  160. void determineMultisampleSettings(UINT32 multisampleCount, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outputSampleDesc);
  161. /**
  162. * @brief Returns the main DXGI factory object.
  163. */
  164. IDXGIFactory* getDXGIFactory() const { return mDXGIFactory; }
  165. /**
  166. * @brief Returns the primary DX11 device object.
  167. */
  168. D3D11Device& getPrimaryDevice() const { return *mDevice; }
  169. /**
  170. * @brief Returns information describing all available drivers.
  171. */
  172. D3D11DriverList* getDriverList() const { return mDriverList; }
  173. protected:
  174. friend class D3D11RenderAPIFactory;
  175. /**
  176. * @copydoc RenderAPICore::initializePrepare
  177. */
  178. void initializePrepare() override;
  179. /**
  180. * @copydoc RenderAPICore::initializeFinalize
  181. */
  182. void initializeFinalize(const SPtr<RenderWindowCore>& primaryWindow) override;
  183. /**
  184. * @copydoc RenderAPICore::destroy_internal
  185. */
  186. void destroyCore() override;
  187. /**
  188. * @brief Creates or retrieves a proper input layout depending on the currently set vertex shader
  189. * and vertex buffer.
  190. *
  191. * Applies the input layout to the pipeline.
  192. */
  193. void applyInputLayout();
  194. /**
  195. * @brief Recalculates actual viewport dimensions based on currently
  196. * set viewport normalized dimensions and render target and applies
  197. * them for further rendering.
  198. */
  199. void applyViewport();
  200. /**
  201. * @brief Creates and populates a set of render system capabilities describing which functionality
  202. * is available.
  203. */
  204. RenderAPICapabilities* createRenderSystemCapabilities() const;
  205. private:
  206. IDXGIFactory* mDXGIFactory;
  207. D3D11Device* mDevice;
  208. D3D11DriverList* mDriverList;
  209. D3D11Driver* mActiveD3DDriver;
  210. D3D_FEATURE_LEVEL mFeatureLevel;
  211. D3D11HLSLProgramFactory* mHLSLFactory;
  212. D3D11InputLayoutManager* mIAManager;
  213. std::pair<SPtr<TextureCore>, TextureViewPtr> mBoundUAVs[D3D11_PS_CS_UAV_REGISTER_COUNT];
  214. UINT32 mStencilRef;
  215. Rect2 mViewportNorm;
  216. D3D11_VIEWPORT mViewport;
  217. D3D11_RECT mScissorRect;
  218. SPtr<VertexDeclarationCore> mActiveVertexDeclaration;
  219. SPtr<D3D11GpuProgramCore> mActiveVertexShader;
  220. DrawOperationType mActiveDrawOp;
  221. };
  222. }