BsRenderAPI.h 26 KB

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