BsD3D11RenderSystem.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 BlendStatePtr& blendState);
  27. /**
  28. * @copydoc RenderSystem::setRasterizerState
  29. */
  30. void setRasterizerState(const RasterizerStatePtr& rasterizerState);
  31. /**
  32. * @copydoc RenderSystem::setDepthStencilState
  33. */
  34. void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
  35. /**
  36. * @copydoc RenderSystem::setSamplerState
  37. */
  38. void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState);
  39. /**
  40. * @copydoc RenderSystem::setTexture
  41. */
  42. void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr);
  43. /**
  44. * @copydoc RenderSystem::disableTextureUnit
  45. */
  46. void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit);
  47. /**
  48. * @copydoc RenderSystem::beginFrame
  49. */
  50. void beginFrame();
  51. /**
  52. * @copydoc RenderSystem::endFrame
  53. */
  54. void endFrame();
  55. /**
  56. * @copydoc RenderSystem::clearRenderTarget
  57. */
  58. void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
  59. /**
  60. * @copydoc RenderSystem::clearViewport
  61. */
  62. void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
  63. /**
  64. * @copydoc RenderSystem::setRenderTarget
  65. */
  66. void setRenderTarget(RenderTargetPtr target);
  67. /**
  68. * @copydoc RenderSystem::setViewport
  69. */
  70. void setViewport(Viewport vp);
  71. /**
  72. * @copydoc RenderSystem::setScissorRect
  73. */
  74. void setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom);
  75. /**
  76. * @copydoc RenderSystem::setVertexBuffers
  77. */
  78. void setVertexBuffers(UINT32 index, VertexBufferPtr* buffers, UINT32 numBuffers);
  79. /**
  80. * @copydoc RenderSystem::setIndexBuffer
  81. */
  82. void setIndexBuffer(const IndexBufferPtr& buffer);
  83. /**
  84. * @copydoc RenderSystem::setVertexDeclaration
  85. */
  86. void setVertexDeclaration(VertexDeclarationPtr vertexDeclaration);
  87. /**
  88. * @copydoc RenderSystem::setDrawOperation
  89. */
  90. void setDrawOperation(DrawOperationType op);
  91. /**
  92. * @copydoc RenderSystem::draw
  93. */
  94. void draw(UINT32 vertexOffset, UINT32 vertexCount);
  95. /**
  96. * @copydoc RenderSystem::drawIndexed
  97. */
  98. void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount);
  99. /**
  100. * @copydoc RenderSystem::bindGpuProgram
  101. */
  102. void bindGpuProgram(HGpuProgram prg);
  103. /**
  104. * @copydoc RenderSystem::unbindGpuProgram
  105. */
  106. void unbindGpuProgram(GpuProgramType gptype);
  107. /**
  108. * @copydoc RenderSystem::bindGpuParams
  109. */
  110. void bindGpuParams(GpuProgramType gptype, GpuParamsPtr params);
  111. /**
  112. * @copydoc RenderSystem::setClipPlanesImpl
  113. */
  114. void setClipPlanesImpl(const PlaneList& clipPlanes);
  115. /**
  116. * @copydoc RenderSystem::convertProjectionMatrix
  117. */
  118. void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest, bool forGpuProgram = false);
  119. /**
  120. * @copydoc RenderSystem::getColorVertexElementType
  121. */
  122. VertexElementType getColorVertexElementType() const;
  123. /**
  124. * @copydoc RenderSystem::getHorizontalTexelOffset
  125. */
  126. float getHorizontalTexelOffset();
  127. /**
  128. * @copydoc RenderSystem::getVerticalTexelOffset
  129. */
  130. float getVerticalTexelOffset();
  131. /**
  132. * @copydoc RenderSystem::getMinimumDepthInputValue
  133. */
  134. float getMinimumDepthInputValue();
  135. /**
  136. * @copydoc RenderSystem::getMaximumDepthInputValue
  137. */
  138. float getMaximumDepthInputValue();
  139. /************************************************************************/
  140. /* Internal use by DX11 RenderSystem only */
  141. /************************************************************************/
  142. /**
  143. * @brief Determines DXGI multisample settings from the provided parameters.
  144. *
  145. * @param multisampleCount Number of requested samples.
  146. * @param multisampleHint String describing an optional hint to which multisample method to use.
  147. * @param format Pixel format used by the render target.
  148. * @param outputSampleDesc Output structure that will contain the requested multisample settings.
  149. */
  150. void determineMultisampleSettings(UINT32 multisampleCount, const String& multisampleHint, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outputSampleDesc);
  151. /**
  152. * @brief Returns the main DXGI factory object.
  153. */
  154. IDXGIFactory* getDXGIFactory() const { return mDXGIFactory; }
  155. /**
  156. * @brief Returns the primary DX11 device object.
  157. */
  158. D3D11Device& getPrimaryDevice() const { return *mDevice; }
  159. /**
  160. * @brief Returns information describing all available drivers.
  161. */
  162. D3D11DriverList* getDriverList() const { return mDriverList; }
  163. protected:
  164. friend class D3D11RenderSystemFactory;
  165. /**
  166. * @copydoc RenderSystem::initialize_internal
  167. */
  168. void initialize_internal(AsyncOp& asyncOp);
  169. /**
  170. * @copydoc RenderSystem::destroy_internal
  171. */
  172. void destroy_internal();
  173. /**
  174. * @brief Creates or retrieves a proper input layout depending on the currently set vertex shader
  175. * and vertex buffer.
  176. *
  177. * Applies the input layout to the pipeline.
  178. */
  179. void applyInputLayout();
  180. /**
  181. * @brief Creates and populates a set of render system capabilities describing which functionality
  182. * is available.
  183. */
  184. RenderSystemCapabilities* createRenderSystemCapabilities() const;
  185. private:
  186. IDXGIFactory* mDXGIFactory;
  187. D3D11Device* mDevice;
  188. D3D11DriverList* mDriverList;
  189. D3D11Driver* mActiveD3DDriver;
  190. D3D_FEATURE_LEVEL mFeatureLevel;
  191. D3D11HLSLProgramFactory* mHLSLFactory;
  192. D3D11InputLayoutManager* mIAManager;
  193. UINT32 mStencilRef;
  194. D3D11_VIEWPORT mViewport;
  195. D3D11_RECT mScissorRect;
  196. VertexDeclarationPtr mActiveVertexDeclaration;
  197. D3D11GpuProgramPtr mActiveVertexShader;
  198. DrawOperationType mActiveDrawOp;
  199. };
  200. }