BsCoreThreadAccessor.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsRenderSystem.h"
  4. #include "BsCommandQueue.h"
  5. #include "BsAsyncOp.h"
  6. #include "BsViewport.h"
  7. #include "BsColor.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Contains some base functionality used for CoreThreadAccessor.
  12. *
  13. * @see CoreThreadAccesor
  14. */
  15. class BS_CORE_EXPORT CoreThreadAccessorBase
  16. {
  17. public:
  18. CoreThreadAccessorBase(CommandQueueBase* commandQueue);
  19. virtual ~CoreThreadAccessorBase();
  20. /** @copydoc RenderSystem::disableTextureUnit() */
  21. void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit);
  22. /** @copydoc RenderSystem::setTexture() */
  23. void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr);
  24. /** @copydoc RenderSystem::setLoadStoreTexture() */
  25. void setLoadStoreTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr& texPtr,
  26. const TextureSurface& surface);
  27. /** @copydoc RenderSystem::setSamplerState() */
  28. void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState);
  29. /** @copydoc RenderSystem::setBlendState() */
  30. void setBlendState(const BlendStatePtr& blendState);
  31. /** @copydoc RenderSystem::setRasterizerState() */
  32. void setRasterizerState(const RasterizerStatePtr& rasterizerState);
  33. /** @copydoc RenderSystem::setRasterizerState() */
  34. void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
  35. /** @copydoc RenderSystem::setVertexBuffers() */
  36. void setVertexBuffers(UINT32 index, const Vector<VertexBufferPtr>& buffers);
  37. /** @copydoc RenderSystem::setIndexBuffer() */
  38. void setIndexBuffer(const IndexBufferPtr& buffer);
  39. /** @copydoc RenderSystem::setVertexDeclaration() */
  40. void setVertexDeclaration(const VertexDeclarationPtr& vertexDeclaration);
  41. /** @copydoc RenderSystem::setViewport() */
  42. void setViewport(const Rect2& vp);
  43. /** @copydoc RenderSystem::setDrawOperation() */
  44. void setDrawOperation(DrawOperationType op);
  45. /** @copydoc RenderSystem::setClipPlanes() */
  46. void setClipPlanes(const PlaneList& clipPlanes);
  47. /** @copydoc RenderSystem::addClipPlane(const Plane&) */
  48. void addClipPlane(const Plane& p);
  49. /** @copydoc RenderSystem::resetClipPlanes() */
  50. void resetClipPlanes();
  51. /** @copydoc RenderSystem::setScissorTest() */
  52. void setScissorTest(UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600);
  53. /** @copydoc RenderSystem::setRenderTarget() */
  54. void setRenderTarget(RenderTargetPtr target);
  55. /** @copydoc RenderSystem::bindGpuProgram() */
  56. void bindGpuProgram(HGpuProgram prg);
  57. /** @copydoc RenderSystem::unbindGpuProgram() */
  58. void unbindGpuProgram(GpuProgramType gptype);
  59. /** @copydoc RenderSystem::bindGpuParams() */
  60. void bindGpuParams(GpuProgramType gptype, const GpuParamsPtr& params);
  61. /** @copydoc RenderSystem::beginFrame() */
  62. void beginRender();
  63. /** @copydoc RenderSystem::endFrame() */
  64. void endRender();
  65. /** @copydoc RenderSystem::clearRenderTarget() */
  66. void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
  67. /** @copydoc RenderSystem::clearViewport() */
  68. void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
  69. /** @copydoc RenderSystem::swapBuffers() */
  70. void swapBuffers(RenderTargetPtr target);
  71. /** @copydoc RenderSystem::draw() */
  72. void draw(UINT32 vertexOffset, UINT32 vertexCount);
  73. /** @copydoc RenderSystem::drawIndexed() */
  74. void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount);
  75. /**
  76. * @brief Queues a new generic command that will be added to the command queue.
  77. */
  78. AsyncOp queueReturnCommand(std::function<void(AsyncOp&)> commandCallback);
  79. /**
  80. * @brief Queues a new generic command that will be added to the command queue.
  81. */
  82. void queueCommand(std::function<void()> commandCallback);
  83. /**
  84. * @brief Makes all the currently queued commands available to the core thread. They will be executed
  85. * as soon as the core thread is ready. All queued commands are removed from the accessor.
  86. */
  87. void submitToCoreThread(bool blockUntilComplete = false);
  88. /**
  89. * @brief Cancels all commands in the queue.
  90. */
  91. void cancelAll();
  92. private:
  93. CommandQueueBase* mCommandQueue;
  94. };
  95. /**
  96. * @brief Core thread accessor allows you to schedule core commands outside of the core thread. Provides a set of common
  97. * methods you may want to execute on the core thread, as well as a general command queuing methods.
  98. *
  99. * @note Queued commands are only executed after the call to submitToCoreThread, in the order they were submitted.
  100. */
  101. template <class CommandQueueSyncPolicy = CommandQueueNoSync>
  102. class BS_CORE_EXPORT CoreThreadAccessor : public CoreThreadAccessorBase
  103. {
  104. public:
  105. /**
  106. * @brief Constructor.
  107. *
  108. * @param threadId Identifier for the thread that created the accessor.
  109. */
  110. CoreThreadAccessor(BS_THREAD_ID_TYPE threadId)
  111. :CoreThreadAccessorBase(bs_new<CommandQueue<CommandQueueSyncPolicy>>(threadId))
  112. {
  113. }
  114. };
  115. }