CmDeferredRenderContext.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCommonEnums.h"
  4. #include "CmSamplerState.h"
  5. #include "CmGpuProgram.h"
  6. #include "CmColor.h"
  7. namespace CamelotEngine
  8. {
  9. /**
  10. * @brief Deferred render context allows you to execute RenderSystem commands outside of the render thread.
  11. * DeferredRenderContext cannot be shared between threads. It must be created and used on the threat that created it.
  12. *
  13. * @note All commands are queued and only executed after the call to submitToGpu, in the order they were called.
  14. */
  15. class CM_EXPORT DeferredRenderContext
  16. {
  17. public:
  18. DeferredRenderContext(RenderSystem* rs, CM_THREAD_ID_TYPE threadId);
  19. ~DeferredRenderContext();
  20. /** @copydoc RenderSystem::setWaitForVerticalBlank() */
  21. void setWaitForVerticalBlank(bool enabled);
  22. /** @copydoc RenderSystem::getWaitForVerticalBlank() */
  23. bool getWaitForVerticalBlank(void) const;
  24. /** @copydoc RenderSystem::disableTextureUnit() */
  25. void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit);
  26. /** @copydoc RenderSystem::setPointParameters() */
  27. void setPointParameters(float size, bool attenuationEnabled, float constant, float linear, float quadratic, float minSize, float maxSize);
  28. /** @copydoc RenderSystem::setTexture() */
  29. void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr);
  30. /** @copydoc RenderSystem::setSamplerState() */
  31. void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState);
  32. /** @copydoc RenderSystem::setBlendState() */
  33. void setBlendState(const BlendStatePtr& blendState);
  34. /** @copydoc RenderSystem::setRasterizerState() */
  35. void setRasterizerState(const RasterizerStatePtr& rasterizerState);
  36. /** @copydoc RenderSystem::setRasterizerState() */
  37. void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
  38. /** @copydoc RenderSystem::setViewport() */
  39. void setViewport(const Viewport& vp);
  40. /** @copydoc RenderSystem::setVertexBuffer() */
  41. void setVertexBuffer(UINT32 index, const VertexBufferPtr& buffer);
  42. /** @copydoc RenderSystem::setIndexBuffer() */
  43. void setIndexBuffer(const IndexBufferPtr& buffer);
  44. /** @copydoc RenderSystem::setVertexDeclaration() */
  45. void setVertexDeclaration(VertexDeclarationPtr vertexDeclaration);
  46. /** @copydoc RenderSystem::setDrawOperation() */
  47. void setDrawOperation(DrawOperationType op);
  48. /** @copydoc RenderSystem::setClipPlanes() */
  49. void setClipPlanes(const PlaneList& clipPlanes);
  50. /** @copydoc RenderSystem::addClipPlane(const Plane&) */
  51. void addClipPlane(const Plane& p);
  52. /** @copydoc RenderSystem::addClipPlane(float, float, float, float) */
  53. void addClipPlane(float A, float B, float C, float D);
  54. /** @copydoc RenderSystem::resetClipPlanes() */
  55. void resetClipPlanes();
  56. /** @copydoc RenderSystem::setScissorTest() */
  57. void setScissorTest(UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600);
  58. /** @copydoc RenderSystem::setRenderTarget() */
  59. void setRenderTarget(RenderTarget *target);
  60. /** @copydoc RenderSystem::bindGpuProgram() */
  61. void bindGpuProgram(GpuProgramHandle prg);
  62. /** @copydoc RenderSystem::unbindGpuProgram() */
  63. void unbindGpuProgram(GpuProgramType gptype);
  64. /** @copydoc RenderSystem::bindGpuParams() */
  65. void bindGpuParams(GpuProgramType gptype, GpuParamsPtr params);
  66. /** @copydoc RenderSystem::beginFrame() */
  67. void beginFrame(void);
  68. /** @copydoc RenderSystem::endFrame() */
  69. void endFrame(void);
  70. /** @copydoc RenderSystem::render() */
  71. void render(const RenderOperation& op);
  72. /** @copydoc RenderSystem::draw() */
  73. void draw(UINT32 vertexCount);
  74. /** @copydoc RenderSystem::drawIndexed() */
  75. void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexCount);
  76. /** @copydoc RenderSystem::swapAllRenderTargetBuffers() */
  77. void swapAllRenderTargetBuffers(bool waitForVsync = true);
  78. /** @copydoc RenderSystem::clear() */
  79. void clear(RenderTargetPtr target, unsigned int buffers, const Color& color = Color::Black, float depth = 1.0f, unsigned short stencil = 0);
  80. /**
  81. * @brief Makes all the currently queued commands available to the GPU. They will be executed
  82. * as soon as the render thread is ready.
  83. */
  84. void submitToGpu();
  85. /**
  86. * @brief Cancels all commands in the queue.
  87. */
  88. void cancelAll();
  89. private:
  90. CommandQueue* mCommandQueue;
  91. RenderSystem* mRenderSystem;
  92. bool mWaitForVerticalBlank;
  93. };
  94. }