BsRenderAPI.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "RenderAPI/BsSamplerState.h"
  6. #include "CoreThread/BsCommandQueue.h"
  7. #include "RenderAPI/BsRenderAPICapabilities.h"
  8. #include "RenderAPI/BsRenderTarget.h"
  9. #include "RenderAPI/BsRenderTexture.h"
  10. #include "RenderAPI/BsRenderWindow.h"
  11. #include "RenderAPI/BsGpuProgram.h"
  12. #include "RenderAPI/BsVertexDeclaration.h"
  13. #include "Math/BsPlane.h"
  14. #include "Utility/BsModule.h"
  15. #include "Utility/BsEvent.h"
  16. namespace bs
  17. {
  18. class RenderAPIInfo;
  19. class RenderAPIManager;
  20. /** @addtogroup RenderAPI
  21. * @{
  22. */
  23. /**
  24. * Provides access to ct::RenderAPI from the simulation thread. All the commands get queued on the core thread queue
  25. * for the calling thread.
  26. *
  27. * @see ct::RenderAPI
  28. *
  29. * @note Sim thread only.
  30. */
  31. class BS_CORE_EXPORT RenderAPI
  32. {
  33. public:
  34. /**
  35. * @see ct::RenderAPI::setGpuParams()
  36. *
  37. * @note This is an @ref asyncMethod "asynchronous method".
  38. */
  39. static void setGpuParams(const SPtr<GpuParams>& gpuParams);
  40. /**
  41. * @see ct::RenderAPI::setGraphicsPipeline()
  42. *
  43. * @note This is an @ref asyncMethod "asynchronous method".
  44. */
  45. static void setGraphicsPipeline(const SPtr<GraphicsPipelineState>& pipelineState);
  46. /**
  47. * @see ct::RenderAPI::setComputePipeline()
  48. *
  49. * @note This is an @ref asyncMethod "asynchronous method".
  50. */
  51. static void setComputePipeline(const SPtr<ComputePipelineState>& pipelineState);
  52. /**
  53. * @see ct::RenderAPI::setVertexBuffers()
  54. *
  55. * @note This is an @ref asyncMethod "asynchronous method".
  56. */
  57. static void setVertexBuffers(UINT32 index, const Vector<SPtr<VertexBuffer>>& buffers);
  58. /**
  59. * @see ct::RenderAPI::setIndexBuffer()
  60. *
  61. * @note This is an @ref asyncMethod "asynchronous method".
  62. */
  63. static void setIndexBuffer(const SPtr<IndexBuffer>& buffer);
  64. /**
  65. * @see ct::RenderAPI::setVertexDeclaration()
  66. *
  67. * @note This is an @ref asyncMethod "asynchronous method".
  68. */
  69. static void setVertexDeclaration(const SPtr<VertexDeclaration>& vertexDeclaration);
  70. /**
  71. * @see ct::RenderAPI::setViewport()
  72. *
  73. * @note This is an @ref asyncMethod "asynchronous method".
  74. */
  75. static void setViewport(const Rect2& area);
  76. /**
  77. * @see ct::RenderAPI::setViewport()
  78. *
  79. * @note This is an @ref asyncMethod "asynchronous method".
  80. */
  81. static void setStencilRef(UINT32 value);
  82. /**
  83. * @see ct::RenderAPI::setDrawOperation()
  84. *
  85. * @note This is an @ref asyncMethod "asynchronous method".
  86. */
  87. static void setDrawOperation(DrawOperationType op);
  88. /**
  89. * @see ct::RenderAPI::setScissorRect()
  90. *
  91. * @note This is an @ref asyncMethod "asynchronous method".
  92. */
  93. static void setScissorRect(UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600);
  94. /**
  95. * @see ct::RenderAPI::setRenderTarget()
  96. *
  97. * @note This is an @ref asyncMethod "asynchronous method".
  98. */
  99. static void setRenderTarget(const SPtr<RenderTarget>& target, UINT32 readOnlyFlags = 0,
  100. RenderSurfaceMask loadMask = RT_NONE);
  101. /**
  102. * @see ct::RenderAPI::clearRenderTarget()
  103. *
  104. * @note This is an @ref asyncMethod "asynchronous method".
  105. */
  106. static void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f,
  107. UINT16 stencil = 0, UINT8 targetMask = 0xFF);
  108. /**
  109. * @see ct::RenderAPI::clearViewport()
  110. *
  111. * @note This is an @ref asyncMethod "asynchronous method".
  112. */
  113. static void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0,
  114. UINT8 targetMask = 0xFF);
  115. /**
  116. * @see ct::RenderAPI::swapBuffers()
  117. *
  118. * @note This is an @ref asyncMethod "asynchronous method".
  119. */
  120. static void swapBuffers(const SPtr<RenderTarget>& target);
  121. /**
  122. * @see ct::RenderAPI::draw()
  123. *
  124. * @note This is an @ref asyncMethod "asynchronous method".
  125. */
  126. static void draw(UINT32 vertexOffset, UINT32 vertexCount, UINT32 instanceCount = 0);
  127. /**
  128. * @see ct::RenderAPI::drawIndexed()
  129. *
  130. * @note This is an @ref asyncMethod "asynchronous method".
  131. */
  132. static void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount,
  133. UINT32 instanceCount = 0);
  134. /**
  135. * @see ct::RenderAPI::dispatchCompute()
  136. *
  137. * @note This is an @ref asyncMethod "asynchronous method".
  138. */
  139. static void dispatchCompute(UINT32 numGroupsX, UINT32 numGroupsY = 1, UINT32 numGroupsZ = 1);
  140. /** @copydoc ct::RenderAPI::getVideoModeInfo */
  141. static const VideoModeInfo& getVideoModeInfo();
  142. /** @copydoc ct::RenderAPI::convertProjectionMatrix */
  143. static void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest);
  144. /** @copydoc ct::RenderAPI::getAPIInfo */
  145. static const RenderAPIInfo& getAPIInfo();
  146. };
  147. /** Feature flags that describe which render API specific features are enabled. */
  148. enum class RenderAPIFeatureFlag
  149. {
  150. /** If set, vertex color order will be reversed before being sent to the shader. */
  151. VertexColorFlip = 1 << 0,
  152. /**
  153. * If set, the Y axis in texture (UV) coordinates is assumed to be pointing up, instead of down (which is the
  154. * default).
  155. */
  156. UVYAxisUp = 1 << 1,
  157. /**
  158. * If set, the Y axis in normalized device coordinates (NDC) is assumed to be pointing down, instead of up (which
  159. * is the default).
  160. */
  161. NDCYAxisDown = 1 << 2,
  162. /**
  163. * If set, the matrices used by shaders are in column major order, instead of in row major (which is the default).
  164. */
  165. ColumnMajorMatrices = 1 << 3,
  166. /**
  167. * If set, the render API has native support for multi-threaded command buffer generation. Otherwise it is
  168. * emulated and using command buffers might not be beneficial.
  169. */
  170. MultiThreadedCB = 1 << 4,
  171. /** If set, the render API supports unordered stores to a texture with more than one sample. */
  172. MSAAImageStores = 1 << 5
  173. };
  174. typedef Flags<RenderAPIFeatureFlag> RenderAPIFeatures;
  175. BS_FLAGS_OPERATORS(RenderAPIFeatureFlag)
  176. /** Contains properties specific to a render API implementation. */
  177. class RenderAPIInfo
  178. {
  179. public:
  180. RenderAPIInfo(float horzTexelOffset, float vertTexelOffset, float minDepth, float maxDepth,
  181. VertexElementType vertexColorType, RenderAPIFeatures featureFlags)
  182. : mHorizontalTexelOffset(horzTexelOffset), mVerticalTexelOffset(vertTexelOffset), mMinDepth(minDepth)
  183. , mMaxDepth(maxDepth), mVertexColorType(vertexColorType), mFeatureFlags(featureFlags)
  184. { }
  185. /** Gets the native type used for vertex colors. */
  186. VertexElementType getColorVertexElementType() const { return mVertexColorType; }
  187. /** Gets horizontal texel offset used for mapping texels to pixels in this render system. */
  188. float getHorizontalTexelOffset() const { return mHorizontalTexelOffset; }
  189. /** Gets vertical texel offset used for mapping texels to pixels in this render system. */
  190. float getVerticalTexelOffset() const { return mVerticalTexelOffset; }
  191. /** Gets the minimum (closest) depth value used by this render system. */
  192. float getMinimumDepthInputValue() const { return mMinDepth; }
  193. /** Gets the maximum (farthest) depth value used by this render system. */
  194. float getMaximumDepthInputValue() const { return mMaxDepth; }
  195. /** Checks is a specific feature flag enabled. */
  196. bool isFlagSet(RenderAPIFeatureFlag flag) const { return mFeatureFlags.isSet(flag); }
  197. private:
  198. float mHorizontalTexelOffset = 0.0f;
  199. float mVerticalTexelOffset = 0.0f;
  200. float mMinDepth = 0.0f;
  201. float mMaxDepth = 1.0f;
  202. VertexElementType mVertexColorType = VET_COLOR_ABGR;
  203. RenderAPIFeatures mFeatureFlags;
  204. };
  205. /** @} */
  206. namespace ct
  207. {
  208. /** @addtogroup RenderAPI-Internal
  209. * @{
  210. */
  211. /**
  212. * Provides low-level API access to rendering commands (internally wrapping DirectX/OpenGL/Vulkan or similar).
  213. *
  214. * Methods that accept a CommandBuffer parameter get queued in the provided command buffer, and don't get executed until
  215. * executeCommands() method is called. User is allowed to populate command buffers from non-core threads, but they all
  216. * must get executed from the core thread.
  217. *
  218. * If a command buffer is not provivided to such methods, they execute immediately. Without a command buffer the methods
  219. * are only allowed to be called from the core thread.
  220. *
  221. * @note Accessible on any thread for methods accepting a CommandBuffer. Otherwise core thread unless specifically
  222. * noted otherwise on per-method basis.
  223. */
  224. class BS_CORE_EXPORT RenderAPI : public Module<RenderAPI>
  225. {
  226. public:
  227. RenderAPI();
  228. virtual ~RenderAPI();
  229. /**
  230. * Returns the name of the rendering system.
  231. *
  232. * @note Thread safe.
  233. */
  234. virtual const StringID& getName() const = 0;
  235. /**
  236. * Gets the name of the primary shading language used by the rendering system.
  237. *
  238. * @note Thread safe.
  239. */
  240. virtual const String& getShadingLanguageName() const = 0;
  241. /**
  242. * Applies a set of parameters that control execution of all currently bound GPU programs. These are the uniforms
  243. * like textures, samplers, or uniform buffers. Caller is expected to ensure the provided parameters actually
  244. * match the currently bound programs.
  245. */
  246. virtual void setGpuParams(const SPtr<GpuParams>& gpuParams,
  247. const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  248. /**
  249. * Sets a pipeline state that controls how will subsequent draw commands render primitives.
  250. *
  251. * @param[in] pipelineState Pipeline state to bind, or null to unbind.
  252. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  253. * is executed immediately. Otherwise it is executed when executeCommands() is
  254. * called. Buffer must support graphics operations.
  255. *
  256. * @see GraphicsPipelineState
  257. */
  258. virtual void setGraphicsPipeline(const SPtr<GraphicsPipelineState>& pipelineState,
  259. const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  260. /**
  261. * Sets a pipeline state that controls how will subsequent dispatch commands execute.
  262. *
  263. * @param[in] pipelineState Pipeline state to bind, or null to unbind.
  264. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  265. * is executed immediately. Otherwise it is executed when executeCommands() is
  266. * called. Buffer must support graphics operations.
  267. */
  268. virtual void setComputePipeline(const SPtr<ComputePipelineState>& pipelineState,
  269. const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  270. /**
  271. * Sets the active viewport that will be used for all render operations.
  272. *
  273. * @param[in] area Area of the viewport, in normalized ([0,1] range) coordinates.
  274. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  275. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  276. * Buffer must support graphics operations.
  277. */
  278. virtual void setViewport(const Rect2& area, const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  279. /**
  280. * Allows you to set up a region in which rendering can take place. Coordinates are in pixels. No rendering will be
  281. * done to render target pixels outside of the provided region.
  282. *
  283. * @param[in] left Left border of the scissor rectangle, in pixels.
  284. * @param[in] top Top border of the scissor rectangle, in pixels.
  285. * @param[in] right Right border of the scissor rectangle, in pixels.
  286. * @param[in] bottom Bottom border of the scissor rectangle, in pixels.
  287. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  288. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  289. * Buffer must support graphics operations.
  290. */
  291. virtual void setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom,
  292. const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  293. /**
  294. * Sets a reference value that will be used for stencil compare operations.
  295. *
  296. * @param[in] value Reference value to set.
  297. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  298. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  299. * Buffer must support graphics operations.
  300. */
  301. virtual void setStencilRef(UINT32 value, const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  302. /**
  303. * Sets the provided vertex buffers starting at the specified source index. Set buffer to nullptr to clear the
  304. * buffer at the specified index.
  305. *
  306. * @param[in] index Index at which to start binding the vertex buffers.
  307. * @param[in] buffers A list of buffers to bind to the pipeline.
  308. * @param[in] numBuffers Number of buffers in the @p buffers list.
  309. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  310. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  311. * Buffer must support graphics operations.
  312. */
  313. virtual void setVertexBuffers(UINT32 index, SPtr<VertexBuffer>* buffers, UINT32 numBuffers,
  314. const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  315. /**
  316. * Sets an index buffer to use when drawing. Indices in an index buffer reference vertices in the vertex buffer,
  317. * which increases cache coherency and reduces the size of vertex buffers by eliminating duplicate data.
  318. *
  319. * @param[in] buffer Index buffer to bind, null to unbind.
  320. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  321. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  322. * Buffer must support graphics operations.
  323. */
  324. virtual void setIndexBuffer(const SPtr<IndexBuffer>& buffer,
  325. const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  326. /**
  327. * Sets the vertex declaration to use when drawing. Vertex declaration is used to decode contents of a single
  328. * vertex in a vertex buffer.
  329. *
  330. * @param[in] vertexDeclaration Vertex declaration to bind.
  331. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  332. * is executed immediately. Otherwise it is executed when executeCommands() is
  333. * called. Buffer must support graphics operations.
  334. */
  335. virtual void setVertexDeclaration(const SPtr<VertexDeclaration>& vertexDeclaration,
  336. const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  337. /**
  338. * Sets the draw operation that determines how to interpret the elements of the index or vertex buffers.
  339. *
  340. * @param[in] op Draw operation to enable.
  341. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  342. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  343. * Buffer must support graphics operations.
  344. */
  345. virtual void setDrawOperation(DrawOperationType op,
  346. const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  347. /**
  348. * Draw an object based on currently bound GPU programs, vertex declaration and vertex buffers. Draws directly from
  349. * the vertex buffer without using indices.
  350. *
  351. * @param[in] vertexOffset Offset into the currently bound vertex buffer to start drawing from.
  352. * @param[in] vertexCount Number of vertices to draw.
  353. * @param[in] instanceCount Number of times to draw the provided geometry, each time with an (optionally)
  354. * separate per-instance data.
  355. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  356. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  357. * Buffer must support graphics operations.
  358. */
  359. virtual void draw(UINT32 vertexOffset, UINT32 vertexCount, UINT32 instanceCount = 0,
  360. const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  361. /**
  362. * Draw an object based on currently bound GPU programs, vertex declaration, vertex and index buffers.
  363. *
  364. * @param[in] startIndex Offset into the currently bound index buffer to start drawing from.
  365. * @param[in] indexCount Number of indices to draw.
  366. * @param[in] vertexOffset Offset to apply to each vertex index.
  367. * @param[in] vertexCount Number of vertices to draw.
  368. * @param[in] instanceCount Number of times to draw the provided geometry, each time with an (optionally)
  369. * separate per-instance data.
  370. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  371. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  372. * Buffer must support graphics operations.
  373. */
  374. virtual void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount,
  375. UINT32 instanceCount = 0, const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  376. /**
  377. * Executes the currently bound compute shader.
  378. *
  379. * @param[in] numGroupsX Number of groups to start in the X direction. Must be in range [1, 65535].
  380. * @param[in] numGroupsY Number of groups to start in the Y direction. Must be in range [1, 65535].
  381. * @param[in] numGroupsZ Number of groups to start in the Z direction. Must be in range [1, 64].
  382. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  383. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  384. * Buffer must support compute or graphics operations.
  385. */
  386. virtual void dispatchCompute(UINT32 numGroupsX, UINT32 numGroupsY = 1, UINT32 numGroupsZ = 1,
  387. const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  388. /**
  389. * Swap the front and back buffer of the specified render target.
  390. *
  391. * @param[in] target Render target to perform the buffer swap on.
  392. * @param[in] syncMask Optional synchronization mask that determines for which queues should the system wait
  393. * before performing the swap buffer operation. By default the system waits for all queues.
  394. * However if certain queues are performing non-rendering operations, or operations not
  395. * related to the provided render target, you can exclude them from the sync mask for
  396. * potentially better performance. You can use CommandSyncMask to generate a valid sync mask.
  397. */
  398. virtual void swapBuffers(const SPtr<RenderTarget>& target, UINT32 syncMask = 0xFFFFFFFF) = 0;
  399. /**
  400. * Change the render target into which we want to draw.
  401. *
  402. * @param[in] target Render target to draw to.
  403. * @param[in] readOnlyFlags Combination of one or more elements of FrameBufferType denoting which buffers
  404. * will be bound for read-only operations. This is useful for depth or stencil
  405. * buffers which need to be bound both for depth/stencil tests, as well as
  406. * shader reads.
  407. * @param[in] loadMask Determines which render target surfaces will have their current contents
  408. * preserved. By default when a render target is bound its contents will be
  409. * lost. You might need to preserve contents if you need to perform blending
  410. * or similar operations with the existing contents of the render target.
  411. *
  412. * Use the mask to select exactly which surfaces of the render target need
  413. * their contents preserved.
  414. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  415. * is executed immediately. Otherwise it is executed when executeCommands() is
  416. * called. Buffer must support graphics operations.
  417. */
  418. virtual void setRenderTarget(const SPtr<RenderTarget>& target, UINT32 readOnlyFlags = 0,
  419. RenderSurfaceMask loadMask = RT_NONE, const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  420. /**
  421. * Clears the currently active render target.
  422. *
  423. * @param[in] buffers Combination of one or more elements of FrameBufferType denoting which buffers are
  424. * to be cleared.
  425. * @param[in] color The color to clear the color buffer with, if enabled.
  426. * @param[in] depth The value to initialize the depth buffer with, if enabled.
  427. * @param[in] stencil The value to initialize the stencil buffer with, if enabled.
  428. * @param[in] targetMask In case multiple render targets are bound, this allows you to control which ones to
  429. * clear (0x01 first, 0x02 second, 0x04 third, etc., and combinations).
  430. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  431. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  432. * Buffer must support graphics operations.
  433. */
  434. virtual void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f,
  435. UINT16 stencil = 0, UINT8 targetMask = 0xFF, const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  436. /**
  437. * Clears the currently active viewport (meaning it clears just a sub-area of a render-target that is covered by the
  438. * viewport, as opposed to clearRenderTarget() which always clears the entire render target).
  439. *
  440. * @param[in] buffers Combination of one or more elements of FrameBufferType denoting which buffers are to
  441. * be cleared.
  442. * @param[in] color The color to clear the color buffer with, if enabled.
  443. * @param[in] depth The value to initialize the depth buffer with, if enabled.
  444. * @param[in] stencil The value to initialize the stencil buffer with, if enabled.
  445. * @param[in] targetMask In case multiple render targets are bound, this allows you to control which ones to
  446. * clear (0x01 first, 0x02 second, 0x04 third, etc., and combinations).
  447. * @param[in] commandBuffer Optional command buffer to queue the operation on. If not provided operation
  448. * is executed immediately. Otherwise it is executed when executeCommands() is called.
  449. * Buffer must support graphics operations.
  450. */
  451. virtual void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f,
  452. UINT16 stencil = 0, UINT8 targetMask = 0xFF, const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
  453. /** Appends all commands from the provided secondary command buffer into the primary command buffer. */
  454. virtual void addCommands(const SPtr<CommandBuffer>& commandBuffer, const SPtr<CommandBuffer>& secondary) = 0;
  455. /**
  456. * Executes all commands in the provided command buffer. Command buffer cannot be secondary.
  457. *
  458. * @param[in] commandBuffer Command buffer whose commands to execute. Set to null to submit the main command
  459. * buffer.
  460. * @param[in] syncMask Optional synchronization mask that determines if the submitted command buffer
  461. * depends on any other command buffers. Use the CommandSyncMask class to generate
  462. * a mask using existing command buffers.
  463. *
  464. * This mask is only relevant if your command buffers are executing on different
  465. * hardware queues, and are somehow dependant. If they are executing on the same queue
  466. * (default) then they will execute sequentially in the order they are submitted.
  467. * Otherwise, if there is a dependency, you must make state it explicitly here.
  468. *
  469. * @note Core thread only.
  470. */
  471. virtual void submitCommandBuffer(const SPtr<CommandBuffer>& commandBuffer, UINT32 syncMask = 0xFFFFFFFF) = 0;
  472. /**
  473. * Gets the capabilities of a specific GPU.
  474. *
  475. * @param[in] deviceIdx Index of the device to get the capabilities for.
  476. *
  477. * @note Thread safe.
  478. */
  479. const RenderAPICapabilities& getCapabilities(UINT32 deviceIdx) const;
  480. /** Returns the number of devices supported by this render API. */
  481. UINT32 getNumDevices() const { return mNumDevices; }
  482. /**
  483. * Returns information about available output devices and their video modes.
  484. *
  485. * @note Thread safe.
  486. */
  487. const VideoModeInfo& getVideoModeInfo() const { return *mVideoModeInfo; }
  488. /************************************************************************/
  489. /* UTILITY METHODS */
  490. /************************************************************************/
  491. /**
  492. * Contains a default matrix into a matrix suitable for use by this specific render system.
  493. *
  494. * @note Thread safe.
  495. */
  496. virtual void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest) = 0;
  497. /**
  498. * Returns information about the specific API implementation.
  499. *
  500. * @note Thread safe.
  501. */
  502. virtual const RenderAPIInfo& getAPIInfo() const = 0;
  503. /**
  504. * Generates a parameter block description and calculates per-parameter offsets for the provided gpu data
  505. * parameters. The offsets are render API specific and correspond to std140 layout for OpenGL, and the default
  506. * layout in DirectX.
  507. *
  508. * @param[in] name Name to assign the parameter block.
  509. * @param[in] params List of parameters in the parameter block. Only name, type and array size fields need to be
  510. * populated, the rest will be populated when the method returns.
  511. * @return Descriptor for the parameter block holding the provided parameters as laid out by the
  512. * default render API layout.
  513. */
  514. virtual GpuParamBlockDesc generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params) = 0;
  515. /************************************************************************/
  516. /* INTERNAL METHODS */
  517. /************************************************************************/
  518. protected:
  519. /**
  520. * Initializes the render API system and creates a primary render window.
  521. *
  522. * @note Sim thread only.
  523. */
  524. SPtr<bs::RenderWindow> initialize(const RENDER_WINDOW_DESC& primaryWindowDesc);
  525. /** Initializes the render API system. Called before the primary render window is created. */
  526. virtual void initialize();
  527. /**
  528. * Performs (optional) secondary initialization of the render API system. Called after the render window is
  529. * created.
  530. */
  531. virtual void initializeWithWindow(const SPtr<RenderWindow>& primaryWindow);
  532. /**
  533. * Shuts down the render API system and cleans up all resources.
  534. *
  535. * @note Sim thread.
  536. */
  537. void destroy();
  538. /** Performs render API system shutdown on the core thread. */
  539. virtual void destroyCore();
  540. /** Converts the number of vertices to number of primitives based on the specified draw operation. */
  541. UINT32 vertexCountToPrimCount(DrawOperationType type, UINT32 elementCount);
  542. /************************************************************************/
  543. /* INTERNAL DATA */
  544. /************************************************************************/
  545. protected:
  546. friend class bs::RenderAPIManager;
  547. SPtr<RenderTarget> mActiveRenderTarget;
  548. RenderAPICapabilities* mCurrentCapabilities;
  549. UINT32 mNumDevices;
  550. SPtr<VideoModeInfo> mVideoModeInfo;
  551. };
  552. /** @} */
  553. }
  554. }