BsRenderAPI.h 27 KB

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