2
0

BsD3D11RenderSystem.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #pragma once
  2. #include "BsD3D11Prerequisites.h"
  3. #include "BsRenderSystem.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 D3D11RenderSystem : public RenderSystem
  11. {
  12. public:
  13. D3D11RenderSystem();
  14. ~D3D11RenderSystem();
  15. /**
  16. * @copydoc RenderSystem::getName
  17. */
  18. const String& getName() const;
  19. /**
  20. * @copydoc RenderSystem::getShadingLanguageName
  21. */
  22. const String& getShadingLanguageName() const;
  23. /**
  24. * @copydoc RenderSystem::setBlendState
  25. */
  26. void setBlendState(const SPtr<BlendStateCore>& blendState);
  27. /**
  28. * @copydoc RenderSystem::setRasterizerState
  29. */
  30. void setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState);
  31. /**
  32. * @copydoc RenderSystem::setDepthStencilState
  33. */
  34. void setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue);
  35. /**
  36. * @copydoc RenderSystem::setSamplerState
  37. */
  38. void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SPtr<SamplerStateCore>& samplerState);
  39. /**
  40. * @copydoc RenderSystem::setTexture
  41. */
  42. void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const SPtr<TextureCore>& texPtr);
  43. /**
  44. * @copydoc RenderSystem::setLoadStoreTexture
  45. */
  46. void setLoadStoreTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const SPtr<TextureCore>& texPtr,
  47. const TextureSurface& surface);
  48. /**
  49. * @copydoc RenderSystem::disableTextureUnit
  50. */
  51. void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit);
  52. /**
  53. * @copydoc RenderSystem::beginFrame
  54. */
  55. void beginFrame();
  56. /**
  57. * @copydoc RenderSystem::endFrame
  58. */
  59. void endFrame();
  60. /**
  61. * @copydoc RenderSystem::clearRenderTarget
  62. */
  63. void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
  64. /**
  65. * @copydoc RenderSystem::clearViewport
  66. */
  67. void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
  68. /**
  69. * @copydoc RenderSystem::setRenderTarget
  70. */
  71. void setRenderTarget(const SPtr<RenderTargetCore>& target);
  72. /**
  73. * @copydoc RenderSystem::setViewport
  74. */
  75. void setViewport(const Rect2& vp);
  76. /**
  77. * @copydoc RenderSystem::setScissorRect
  78. */
  79. void setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom);
  80. /**
  81. * @copydoc RenderSystem::setVertexBuffers
  82. */
  83. void setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers);
  84. /**
  85. * @copydoc RenderSystem::setIndexBuffer
  86. */
  87. void setIndexBuffer(const SPtr<IndexBufferCore>& buffer);
  88. /**
  89. * @copydoc RenderSystem::setVertexDeclaration
  90. */
  91. void setVertexDeclaration(const SPtr<VertexDeclarationCore>& vertexDeclaration);
  92. /**
  93. * @copydoc RenderSystem::setDrawOperation
  94. */
  95. void setDrawOperation(DrawOperationType op);
  96. /**
  97. * @copydoc RenderSystem::draw
  98. */
  99. void draw(UINT32 vertexOffset, UINT32 vertexCount);
  100. /**
  101. * @copydoc RenderSystem::drawIndexed
  102. */
  103. void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount);
  104. /**
  105. * @copydoc RenderSystem::bindGpuProgram
  106. */
  107. void bindGpuProgram(const SPtr<GpuProgramCore>& prg);
  108. /**
  109. * @copydoc RenderSystem::unbindGpuProgram
  110. */
  111. void unbindGpuProgram(GpuProgramType gptype);
  112. /**
  113. * @copydoc RenderSystem::bindGpuParams
  114. */
  115. void bindGpuParams(GpuProgramType gptype, const SPtr<GpuParamsCore>& params);
  116. /**
  117. * @copydoc RenderSystem::setClipPlanesImpl
  118. */
  119. void setClipPlanesImpl(const PlaneList& clipPlanes);
  120. /**
  121. * @copydoc RenderSystem::convertProjectionMatrix
  122. */
  123. void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest);
  124. /**
  125. * @copydoc RenderSystem::getColorVertexElementType
  126. */
  127. VertexElementType getColorVertexElementType() const;
  128. /**
  129. * @copydoc RenderSystem::getHorizontalTexelOffset
  130. */
  131. float getHorizontalTexelOffset();
  132. /**
  133. * @copydoc RenderSystem::getVerticalTexelOffset
  134. */
  135. float getVerticalTexelOffset();
  136. /**
  137. * @copydoc RenderSystem::getMinimumDepthInputValue
  138. */
  139. float getMinimumDepthInputValue();
  140. /**
  141. * @copydoc RenderSystem::getMaximumDepthInputValue
  142. */
  143. float getMaximumDepthInputValue();
  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 D3D11RenderSystemFactory;
  169. /**
  170. * @copydoc RenderSystem::initializePrepare
  171. */
  172. void initializePrepare();
  173. /**
  174. * @copydoc RenderSystem::initializeFinalize
  175. */
  176. void initializeFinalize(const SPtr<RenderWindowCore>& primaryWindow);
  177. /**
  178. * @copydoc RenderSystem::destroy_internal
  179. */
  180. void destroy_internal();
  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. RenderSystemCapabilities* 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. }