BsD3D11RenderAPI.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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) override;
  64. /**
  65. * @copydoc RenderAPICore::clearViewport
  66. */
  67. void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0) override;
  68. /**
  69. * @copydoc RenderAPICore::setRenderTarget
  70. */
  71. void setRenderTarget(const SPtr<RenderTargetCore>& target) override;
  72. /**
  73. * @copydoc RenderAPICore::setViewport
  74. */
  75. void setViewport(const Rect2& vp) override;
  76. /**
  77. * @copydoc RenderAPICore::setScissorRect
  78. */
  79. void setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom) override;
  80. /**
  81. * @copydoc RenderAPICore::setVertexBuffers
  82. */
  83. void setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers) override;
  84. /**
  85. * @copydoc RenderAPICore::setIndexBuffer
  86. */
  87. void setIndexBuffer(const SPtr<IndexBufferCore>& buffer) override;
  88. /**
  89. * @copydoc RenderAPICore::setVertexDeclaration
  90. */
  91. void setVertexDeclaration(const SPtr<VertexDeclarationCore>& vertexDeclaration) override;
  92. /**
  93. * @copydoc RenderAPICore::setDrawOperation
  94. */
  95. void setDrawOperation(DrawOperationType op) override;
  96. /**
  97. * @copydoc RenderAPICore::draw
  98. */
  99. void draw(UINT32 vertexOffset, UINT32 vertexCount) override;
  100. /**
  101. * @copydoc RenderAPICore::drawIndexed
  102. */
  103. void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount) override;
  104. /**
  105. * @copydoc RenderAPICore::bindGpuProgram
  106. */
  107. void bindGpuProgram(const SPtr<GpuProgramCore>& prg) override;
  108. /**
  109. * @copydoc RenderAPICore::unbindGpuProgram
  110. */
  111. void unbindGpuProgram(GpuProgramType gptype) override;
  112. /**
  113. * @copydoc RenderAPICore::setConstantBuffers
  114. */
  115. void setConstantBuffers(GpuProgramType gptype, const SPtr<GpuParamsCore>& params) override;
  116. /**
  117. * @copydoc RenderAPICore::setClipPlanesImpl
  118. */
  119. void setClipPlanesImpl(const PlaneList& clipPlanes) override;
  120. /**
  121. * @copydoc RenderAPICore::convertProjectionMatrix
  122. */
  123. void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest) override;
  124. /**
  125. * @copydoc RenderAPICore::getColorVertexElementType
  126. */
  127. VertexElementType getColorVertexElementType() const override;
  128. /**
  129. * @copydoc RenderAPICore::getHorizontalTexelOffset
  130. */
  131. float getHorizontalTexelOffset() override;
  132. /**
  133. * @copydoc RenderAPICore::getVerticalTexelOffset
  134. */
  135. float getVerticalTexelOffset() override;
  136. /**
  137. * @copydoc RenderAPICore::getMinimumDepthInputValue
  138. */
  139. float getMinimumDepthInputValue() override;
  140. /**
  141. * @copydoc RenderAPICore::getMaximumDepthInputValue
  142. */
  143. float getMaximumDepthInputValue() override;
  144. /************************************************************************/
  145. /* Internal use by DX11 RenderSystem only */
  146. /************************************************************************/
  147. /**
  148. * @brief Determines DXGI multisample settings from the provided parameters.
  149. *
  150. * @param multisampleCount Number of requested samples.
  151. * @param format Pixel format used by the render target.
  152. * @param outputSampleDesc Output structure that will contain the requested multisample settings.
  153. */
  154. void determineMultisampleSettings(UINT32 multisampleCount, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outputSampleDesc);
  155. /**
  156. * @brief Returns the main DXGI factory object.
  157. */
  158. IDXGIFactory* getDXGIFactory() const { return mDXGIFactory; }
  159. /**
  160. * @brief Returns the primary DX11 device object.
  161. */
  162. D3D11Device& getPrimaryDevice() const { return *mDevice; }
  163. /**
  164. * @brief Returns information describing all available drivers.
  165. */
  166. D3D11DriverList* getDriverList() const { return mDriverList; }
  167. protected:
  168. friend class D3D11RenderAPIFactory;
  169. /**
  170. * @copydoc RenderAPICore::initializePrepare
  171. */
  172. void initializePrepare() override;
  173. /**
  174. * @copydoc RenderAPICore::initializeFinalize
  175. */
  176. void initializeFinalize(const SPtr<RenderWindowCore>& primaryWindow) override;
  177. /**
  178. * @copydoc RenderAPICore::destroy_internal
  179. */
  180. void destroyCore() override;
  181. /**
  182. * @brief Creates or retrieves a proper input layout depending on the currently set vertex shader
  183. * and vertex buffer.
  184. *
  185. * Applies the input layout to the pipeline.
  186. */
  187. void applyInputLayout();
  188. /**
  189. * @brief Recalculates actual viewport dimensions based on currently
  190. * set viewport normalized dimensions and render target and applies
  191. * them for further rendering.
  192. */
  193. void applyViewport();
  194. /**
  195. * @brief Creates and populates a set of render system capabilities describing which functionality
  196. * is available.
  197. */
  198. RenderAPICapabilities* createRenderSystemCapabilities() const;
  199. private:
  200. IDXGIFactory* mDXGIFactory;
  201. D3D11Device* mDevice;
  202. D3D11DriverList* mDriverList;
  203. D3D11Driver* mActiveD3DDriver;
  204. D3D_FEATURE_LEVEL mFeatureLevel;
  205. D3D11HLSLProgramFactory* mHLSLFactory;
  206. D3D11InputLayoutManager* mIAManager;
  207. std::pair<SPtr<TextureCore>, TextureViewPtr> mBoundUAVs[D3D11_PS_CS_UAV_REGISTER_COUNT];
  208. UINT32 mStencilRef;
  209. Rect2 mViewportNorm;
  210. D3D11_VIEWPORT mViewport;
  211. D3D11_RECT mScissorRect;
  212. SPtr<VertexDeclarationCore> mActiveVertexDeclaration;
  213. SPtr<D3D11GpuProgramCore> mActiveVertexShader;
  214. DrawOperationType mActiveDrawOp;
  215. };
  216. }