BsRenderAPI.h 27 KB

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