BsD3D11RenderSystem.h 6.6 KB

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