CmD3D11RenderSystem.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #pragma once
  2. #include "CmD3D11Prerequisites.h"
  3. #include "CmRenderSystem.h"
  4. namespace CamelotFramework
  5. {
  6. class CM_D3D11_EXPORT D3D11RenderSystem : public RenderSystem
  7. {
  8. public:
  9. ~D3D11RenderSystem();
  10. /**
  11. * @copydoc RenderSystem::getName()
  12. */
  13. const String& getName() const;
  14. /**
  15. * @copydoc RenderSystem::getShadingLanguageName()
  16. */
  17. const String& getShadingLanguageName() const;
  18. void setBlendState(const BlendStatePtr& blendState);
  19. void setRasterizerState(const RasterizerStatePtr& rasterizerState);
  20. void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
  21. void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState);
  22. void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr);
  23. void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit);
  24. void beginFrame();
  25. void endFrame();
  26. /**
  27. * @copydoc RenderSystem::clearRenderTarget()
  28. */
  29. void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
  30. /**
  31. * @copydoc RenderSystem::clearViewport()
  32. */
  33. void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
  34. void setRenderTarget(RenderTargetPtr target);
  35. void setViewport(const ViewportPtr& vp);
  36. void setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom);
  37. void setVertexBuffers(UINT32 index, VertexBufferPtr* buffers, UINT32 numBuffers);
  38. void setIndexBuffer(const IndexBufferPtr& buffer);
  39. void setVertexDeclaration(VertexDeclarationPtr vertexDeclaration);
  40. void setDrawOperation(DrawOperationType op);
  41. /** @copydoc RenderSystem::draw() */
  42. void draw(UINT32 vertexOffset, UINT32 vertexCount);
  43. /** @copydoc RenderSystem::drawIndexed() */
  44. void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount);
  45. /** @copydoc RenderSystem::bindGpuProgram() */
  46. void bindGpuProgram(HGpuProgram prg);
  47. /** @copydoc RenderSystem::unbindGpuProgram() */
  48. void unbindGpuProgram(GpuProgramType gptype);
  49. /** @copydoc RenderSystem::bindGpuParams() */
  50. void bindGpuParams(GpuProgramType gptype, BindableGpuParams& params);
  51. void setClipPlanesImpl(const PlaneList& clipPlanes);
  52. RenderSystemCapabilities* createRenderSystemCapabilities() const;
  53. void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps);
  54. String getErrorDescription(long errorNumber) const;
  55. void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest, bool forGpuProgram = false);
  56. VertexElementType getColorVertexElementType() const;
  57. float getHorizontalTexelOffset();
  58. float getVerticalTexelOffset();
  59. float getMinimumDepthInputValue();
  60. float getMaximumDepthInputValue();
  61. /************************************************************************/
  62. /* Internal use by DX11 RenderSystem only */
  63. /************************************************************************/
  64. void determineFSAASettings(UINT32 fsaa, const String& fsaaHint, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outFSAASettings);
  65. bool checkTextureFilteringSupported(TextureType ttype, PixelFormat format, int usage);
  66. IDXGIFactory* getDXGIFactory() const { return mDXGIFactory; }
  67. D3D11Device& getPrimaryDevice() const { return *mDevice; }
  68. /**
  69. * @brief Returns a total number of outputs (e.g. monitors), across all adapters.
  70. */
  71. D3D11DriverList* getDriverList() const { return mDriverList; }
  72. protected:
  73. friend class D3D11RenderSystemFactory;
  74. D3D11RenderSystem();
  75. /**
  76. * @copydoc RenderSystem::initialize_internal().
  77. */
  78. void initialize_internal(AsyncOp& asyncOp);
  79. /**
  80. * @copydoc RenderSystem::destroy_internal().
  81. */
  82. void destroy_internal();
  83. private:
  84. IDXGIFactory* mDXGIFactory;
  85. D3D11Device* mDevice;
  86. D3D11DriverList* mDriverList;
  87. D3D11Driver* mActiveD3DDriver;
  88. D3D_FEATURE_LEVEL mFeatureLevel;
  89. D3D11HLSLProgramFactory* mHLSLFactory;
  90. D3D11InputLayoutManager* mIAManager;
  91. // State variables
  92. UINT32 mStencilRef;
  93. D3D11_VIEWPORT mViewport;
  94. D3D11_RECT mScissorRect;
  95. VertexDeclarationPtr mActiveVertexDeclaration;
  96. D3D11HLSLProgramPtr mActiveVertexShader;
  97. /**
  98. * @brief Creates or retrieves a proper input layout depending on the currently set vertex shader
  99. * and vertex buffer.
  100. *
  101. * Applies the input layout to the pipeline.
  102. */
  103. void applyInputLayout();
  104. };
  105. }