BsRenderAPI.h 27 KB

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