2
0

BsRenderAPI.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. * Version of the render API interface usable from the sim thread. All the commands get queued on the accessor provided
  25. * to each method and will 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. /**
  35. * @copydoc RenderAPICore::disableTextureUnit()
  36. *
  37. * @param[in] accessor Accessor on which will this command be queued for execution.
  38. */
  39. static void disableTextureUnit(CoreAccessor& accessor, GpuProgramType gptype, UINT16 texUnit);
  40. /**
  41. * @copydoc RenderAPICore::setTexture()
  42. *
  43. * @param[in] accessor Accessor on which will this command be queued for execution.
  44. */
  45. static void setTexture(CoreAccessor& accessor, GpuProgramType gptype, UINT16 texUnit, bool enabled,
  46. const SPtr<Texture> &texPtr);
  47. /**
  48. * @copydoc RenderAPICore::setLoadStoreTexture()
  49. *
  50. * @param[in] accessor Accessor on which will this command be queued for execution.
  51. */
  52. static void setLoadStoreTexture(CoreAccessor& accessor, GpuProgramType gptype, UINT16 texUnit, bool enabled,
  53. const SPtr<Texture>& texPtr, const TextureSurface& surface);
  54. /**
  55. * @copydoc RenderAPICore::setSamplerState()
  56. *
  57. * @param[in] accessor Accessor on which will this command be queued for execution.
  58. */
  59. static void setSamplerState(CoreAccessor& accessor, GpuProgramType gptype, UINT16 texUnit,
  60. const SPtr<SamplerState>& samplerState);
  61. /**
  62. * @copydoc RenderAPICore::setBlendState()
  63. *
  64. * @param[in] accessor Accessor on which will this command be queued for execution.
  65. */
  66. static void setBlendState(CoreAccessor& accessor, const SPtr<BlendState>& blendState);
  67. /**
  68. * @copydoc RenderAPICore::setRasterizerState()
  69. *
  70. * @param[in] accessor Accessor on which will this command be queued for execution.
  71. */
  72. static void setRasterizerState(CoreAccessor& accessor, const SPtr<RasterizerState>& rasterizerState);
  73. /**
  74. * @copydoc RenderAPICore::setDepthStencilState()
  75. *
  76. * @param[in] accessor Accessor on which will this command be queued for execution.
  77. */
  78. static void setDepthStencilState(CoreAccessor& accessor, const SPtr<DepthStencilState>& depthStencilState,
  79. UINT32 stencilRefValue);
  80. /**
  81. * Sets the provided vertex buffers starting at the specified source index. Set buffer to nullptr to clear the
  82. * buffer at the specified index.
  83. *
  84. * @param[in] accessor Accessor on which will this command be queued for execution.
  85. * @param[in] index Index at which to start binding the vertex buffers.
  86. * @param[in] buffers A list of buffers to bind to the pipeline.
  87. */
  88. static void setVertexBuffers(CoreAccessor& accessor, UINT32 index, const Vector<SPtr<VertexBuffer>>& buffers);
  89. /**
  90. * @copydoc RenderAPICore::setIndexBuffer()
  91. *
  92. * @param[in] accessor Accessor on which will this command be queued for execution.
  93. */
  94. static void setIndexBuffer(CoreAccessor& accessor, const SPtr<IndexBuffer>& buffer);
  95. /**
  96. * @copydoc RenderAPICore::setVertexDeclaration()
  97. *
  98. * @param[in] accessor Accessor on which will this command be queued for execution.
  99. */
  100. static void setVertexDeclaration(CoreAccessor& accessor, const SPtr<VertexDeclaration>& vertexDeclaration);
  101. /**
  102. * @copydoc RenderAPICore::setViewport()
  103. *
  104. * @param[in] accessor Accessor on which will this command be queued for execution.
  105. */
  106. static void setViewport(CoreAccessor& accessor, const Rect2& area);
  107. /**
  108. * @copydoc RenderAPICore::setDrawOperation()
  109. *
  110. * @param[in] accessor Accessor on which will this command be queued for execution.
  111. */
  112. static void setDrawOperation(CoreAccessor& accessor, DrawOperationType op);
  113. /**
  114. * @copydoc RenderAPICore::setClipPlanes()
  115. *
  116. * @param[in] accessor Accessor on which will this command be queued for execution.
  117. */
  118. static void setClipPlanes(CoreAccessor& accessor, const PlaneList& clipPlanes);
  119. /**
  120. * @copydoc RenderAPICore::addClipPlane(const Plane&)
  121. *
  122. * @param[in] accessor Accessor on which will this command be queued for execution.
  123. */
  124. static void addClipPlane(CoreAccessor& accessor, const Plane& p);
  125. /**
  126. * @copydoc RenderAPICore::resetClipPlanes()
  127. *
  128. * @param[in] accessor Accessor on which will this command be queued for execution.
  129. */
  130. static void resetClipPlanes(CoreAccessor& accessor);
  131. /**
  132. * @copydoc RenderAPICore::setScissorRect()
  133. *
  134. * @param[in] accessor Accessor on which will this command be queued for execution.
  135. */
  136. static void setScissorRect(CoreAccessor& accessor, UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600);
  137. /**
  138. * @copydoc RenderAPICore::setRenderTarget()
  139. *
  140. * @param[in] accessor Accessor on which will this command be queued for execution.
  141. */
  142. static void setRenderTarget(CoreAccessor& accessor, const SPtr<RenderTarget>& target, bool readOnlyDepthStencil = false);
  143. /**
  144. * @copydoc RenderAPICore::bindGpuProgram()
  145. *
  146. * @param[in] accessor Accessor on which will this command be queued for execution.
  147. */
  148. static void bindGpuProgram(CoreAccessor& accessor, const SPtr<GpuProgram>& prg);
  149. /**
  150. * @copydoc RenderAPICore::unbindGpuProgram()
  151. *
  152. * @param[in] accessor Accessor on which will this command be queued for execution.
  153. */
  154. static void unbindGpuProgram(CoreAccessor& accessor, GpuProgramType gptype);
  155. /**
  156. * @copydoc RenderAPICore::setConstantBuffers()
  157. *
  158. * @param[in] accessor Accessor on which will this command be queued for execution.
  159. */
  160. static void setConstantBuffers(CoreAccessor& accessor, GpuProgramType gptype, const SPtr<GpuParams>& params);
  161. /**
  162. * @copydoc RenderAPICore::setGpuParams()
  163. *
  164. * @param[in] accessor Accessor on which will this command be queued for execution.
  165. */
  166. static void setGpuParams(CoreAccessor& accessor, GpuProgramType gptype, const SPtr<GpuParams>& params);
  167. /**
  168. * @copydoc RenderAPICore::beginFrame()
  169. *
  170. * @param[in] accessor Accessor on which will this command be queued for execution.
  171. */
  172. static void beginRender(CoreAccessor& accessor);
  173. /**
  174. * @copydoc RenderAPICore::endFrame()
  175. *
  176. * @param[in] accessor Accessor on which will this command be queued for execution.
  177. */
  178. static void endRender(CoreAccessor& accessor);
  179. /**
  180. * @copydoc RenderAPICore::clearRenderTarget()
  181. *
  182. * @param[in] accessor Accessor on which will this command be queued for execution.
  183. */
  184. static void clearRenderTarget(CoreAccessor& accessor, UINT32 buffers,
  185. const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0, UINT8 targetMask = 0xFF);
  186. /**
  187. * @copydoc RenderAPICore::clearViewport()
  188. *
  189. * @param[in] accessor Accessor on which will this command be queued for execution.
  190. */
  191. static void clearViewport(CoreAccessor& accessor, UINT32 buffers, const Color& color = Color::Black,
  192. float depth = 1.0f, UINT16 stencil = 0, UINT8 targetMask = 0xFF);
  193. /**
  194. * @copydoc RenderAPICore::swapBuffers()
  195. *
  196. * @param[in] accessor Accessor on which will this command be queued for execution.
  197. */
  198. static void swapBuffers(CoreAccessor& accessor, const SPtr<RenderTarget>& target);
  199. /**
  200. * @copydoc RenderAPICore::draw()
  201. *
  202. * @param[in] accessor Accessor on which will this command be queued for execution.
  203. */
  204. static void draw(CoreAccessor& accessor, UINT32 vertexOffset, UINT32 vertexCount, UINT32 instanceCount = 0);
  205. /**
  206. * @copydoc RenderAPICore::drawIndexed()
  207. *
  208. * @param[in] accessor Accessor on which will this command be queued for execution.
  209. */
  210. static void drawIndexed(CoreAccessor& accessor, UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset,
  211. UINT32 vertexCount, UINT32 instanceCount = 0);
  212. /**
  213. * @copydoc RenderAPICore::dispatchCompute()
  214. *
  215. * @param[in] accessor Accessor on which will this command be queued for execution.
  216. */
  217. static void dispatchCompute(CoreAccessor& accessor, UINT32 numGroupsX, UINT32 numGroupsY = 1, UINT32 numGroupsZ = 1);
  218. /** @copydoc RenderAPICore::getVideoModeInfo */
  219. static const VideoModeInfo& getVideoModeInfo();
  220. /** @copydoc RenderAPICore::convertProjectionMatrix */
  221. static void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest);
  222. /** @copydoc RenderAPICore::getAPIInfo */
  223. static const RenderAPIInfo& getAPIInfo();
  224. };
  225. /** Contains properties specific to a render API implementation. */
  226. class RenderAPIInfo
  227. {
  228. public:
  229. RenderAPIInfo(float horzTexelOffset, float vertTexelOffset, float minDepth, float maxDepth,
  230. VertexElementType vertexColorType, bool vertexColorFlip, bool ndcVerticalTopToBottom, bool columnMajorMatrices)
  231. : mHorizontalTexelOffset(horzTexelOffset), mVerticalTexelOffset(vertTexelOffset), mMinDepth(minDepth)
  232. , mMaxDepth(maxDepth), mVertexColorType(vertexColorType), mVertexColorFlip(vertexColorFlip)
  233. , mNDCYAxisDown(ndcVerticalTopToBottom), mColumnMajorMatrices(columnMajorMatrices)
  234. {
  235. }
  236. /** Gets the native type used for vertex colors. */
  237. VertexElementType getColorVertexElementType() const { return mVertexColorType; }
  238. /** Gets horizontal texel offset used for mapping texels to pixels in this render system. */
  239. float getHorizontalTexelOffset() const { return mHorizontalTexelOffset; }
  240. /** Gets vertical texel offset used for mapping texels to pixels in this render system. */
  241. float getVerticalTexelOffset() const { return mVerticalTexelOffset; }
  242. /** Gets the minimum (closest) depth value used by this render system. */
  243. float getMinimumDepthInputValue() const { return mMinDepth; }
  244. /** Gets the maximum (farthest) depth value used by this render system. */
  245. float getMaximumDepthInputValue() const { return mMaxDepth; }
  246. /** Checks if vertex color needs to be flipped before sent to the shader. */
  247. bool getVertexColorFlipRequired() const { return mVertexColorFlip; }
  248. /** Checks whether GPU programs expect matrices in column major format. */
  249. bool getGpuProgramHasColumnMajorMatrices() const { return mColumnMajorMatrices; }
  250. /**
  251. * Returns true if Y axis in normalized device coordinates points down, false if up. If axis is pointing down the
  252. * NDC at the top is -1, and at the bottom is 1, otherwise reverse.
  253. */
  254. bool getNDCYAxisDown() const { return mNDCYAxisDown; }
  255. private:
  256. float mHorizontalTexelOffset = 0.0f;
  257. float mVerticalTexelOffset = 0.0f;
  258. float mMinDepth = 0.0f;
  259. float mMaxDepth = 1.0f;
  260. VertexElementType mVertexColorType = VET_COLOR_ABGR;
  261. bool mVertexColorFlip = false;
  262. bool mNDCYAxisDown = true;
  263. bool mColumnMajorMatrices = false;
  264. };
  265. /** @} */
  266. /** @addtogroup RenderAPI-Internal
  267. * @{
  268. */
  269. /**
  270. * Render system provides base functionality for a rendering API like DirectX or OpenGL. Most of the class is abstract
  271. * and specific subclass for each rendering API needs to be implemented.
  272. *
  273. * @note Core thread only unless specifically noted otherwise on per-method basis.
  274. */
  275. class BS_CORE_EXPORT RenderAPICore : public Module<RenderAPICore>
  276. {
  277. public:
  278. RenderAPICore();
  279. virtual ~RenderAPICore();
  280. /**
  281. * Returns the name of the rendering system.
  282. *
  283. * @note Thread safe.
  284. */
  285. virtual const StringID& getName() const = 0;
  286. /**
  287. * Gets the name of the primary shading language used by the rendering system.
  288. *
  289. * @note Thread safe.
  290. */
  291. virtual const String& getShadingLanguageName() const = 0;
  292. /**
  293. * Sets a sampler state for the specified texture unit.
  294. *
  295. * @param[in] gptype Determines to which GPU program slot to bind the sampler state.
  296. * @param[in] texUnit Texture unit index to bind the state to.
  297. * @param[in] samplerState Sampler state to bind, or null to unbind.
  298. *
  299. * @see SamplerState
  300. */
  301. virtual void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SPtr<SamplerStateCore>& samplerState) = 0;
  302. /**
  303. * Sets a blend state used for all active render targets.
  304. *
  305. * @param[in] blendState Blend state to bind, or null to unbind.
  306. *
  307. * @see BlendState
  308. */
  309. virtual void setBlendState(const SPtr<BlendStateCore>& blendState) = 0;
  310. /**
  311. * Sets a state that controls various rasterizer options.
  312. *
  313. * @param[in] rasterizerState Rasterizer state to bind, or null to unbind.
  314. *
  315. * @see RasterizerState
  316. */
  317. virtual void setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState) = 0;
  318. /**
  319. * Sets a state that controls depth & stencil buffer options.
  320. *
  321. * @param[in] depthStencilState Depth-stencil state to bind, or null to unbind.
  322. * @param[in] stencilRefValue Stencil reference value to be used for stencil comparisons, if enabled.
  323. *
  324. * @see DepthStencilState
  325. */
  326. virtual void setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue) = 0;
  327. /**
  328. * Binds a texture to the pipeline for the specified GPU program type at the specified slot. If the slot matches
  329. * the one configured in the GPU program the program will be able to access this texture on the GPU.
  330. *
  331. * @param[in] gptype Determines to which GPU program slot to bind the texture.
  332. * @param[in] texUnit Texture unit index to bind the texture to.
  333. * @param[in] enabled True to bind the texture at the specified unit, false to unbind.
  334. * @param[in] texPtr Texture to bind.
  335. */
  336. virtual void setTexture(GpuProgramType gptype, UINT16 texUnit, bool enabled, const SPtr<TextureCore>& texPtr) = 0;
  337. /**
  338. * Removes a texture at the specified texture unit.
  339. *
  340. * @param[in] gptype Determines at which GPU program slot to unbind the texture.
  341. * @param[in] texUnit Texture unit index to unbind the texture from.
  342. */
  343. virtual void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit);
  344. /**
  345. * Binds a texture that can be used for random load/store operations from a GPU program.
  346. *
  347. * @param[in] gptype Determines to which GPU program slot to bind the texture.
  348. * @param[in] texUnit Texture unit index to bind the texture to.
  349. * @param[in] enabled True to bind the texture at the specified unit, false to unbind.
  350. * @param[in] texPtr Texture to bind.
  351. * @param[in] surface Determines which surface of the texture to bind.
  352. */
  353. virtual void setLoadStoreTexture(GpuProgramType gptype, UINT16 texUnit, bool enabled,
  354. const SPtr<TextureCore>& texPtr, const TextureSurface& surface) = 0;
  355. /**
  356. * Signals that rendering for a specific viewport has started. Any draw calls need to be called between beginFrame()
  357. * and endFrame().
  358. */
  359. virtual void beginFrame() = 0;
  360. /** Ends that rendering to a specific viewport has ended. */
  361. virtual void endFrame() = 0;
  362. /**
  363. * Sets the active viewport that will be used for all render operations.
  364. *
  365. * @param[in] area Area of the viewport, in normalized ([0,1] range) coordinates.
  366. */
  367. virtual void setViewport(const Rect2& area) = 0;
  368. /**
  369. * Sets the provided vertex buffers starting at the specified source index. Set buffer to nullptr to clear the
  370. * buffer at the specified index.
  371. *
  372. * @param[in] index Index at which to start binding the vertex buffers.
  373. * @param[in] buffers A list of buffers to bind to the pipeline.
  374. * @param[in] numBuffers Number of buffers in the @p buffers list.
  375. */
  376. virtual void setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers) = 0;
  377. /**
  378. * Sets an index buffer to use when drawing. Indices in an index buffer reference vertices in the vertex buffer,
  379. * which increases cache coherency and reduces the size of vertex buffers by eliminating duplicate data.
  380. *
  381. * @param[in] buffer Index buffer to bind, null to unbine.
  382. */
  383. virtual void setIndexBuffer(const SPtr<IndexBufferCore>& buffer) = 0;
  384. /**
  385. * Sets the vertex declaration to use when drawing. Vertex declaration is used to decode contents of a single
  386. * vertex in a vertex buffer.
  387. *
  388. * @param[in] vertexDeclaration Vertex declaration to bind.
  389. */
  390. virtual void setVertexDeclaration(const SPtr<VertexDeclarationCore>& vertexDeclaration) = 0;
  391. /**
  392. * Sets the draw operation that determines how to interpret the elements of the index or vertex buffers.
  393. *
  394. * @param[in] op Draw operation to enable.
  395. */
  396. virtual void setDrawOperation(DrawOperationType op) = 0;
  397. /**
  398. * Draw an object based on currently bound GPU programs, vertex declaration and vertex buffers. Draws directly from
  399. * the vertex buffer without using indices.
  400. *
  401. * @param[in] vertexOffset Offset into the currently bound vertex buffer to start drawing from.
  402. * @param[in] vertexCount Number of vertices to draw.
  403. * @param[in] instanceCount Number of times to draw the provided geometry, each time with an (optionally)
  404. * separate per-instance data.
  405. */
  406. virtual void draw(UINT32 vertexOffset, UINT32 vertexCount, UINT32 instanceCount = 0) = 0;
  407. /**
  408. * Draw an object based on currently bound GPU programs, vertex declaration, vertex and index buffers.
  409. *
  410. * @param[in] startIndex Offset into the currently bound index buffer to start drawing from.
  411. * @param[in] indexCount Number of indices to draw.
  412. * @param[in] vertexOffset Offset to apply to each vertex index.
  413. * @param[in] vertexCount Number of vertices to draw.
  414. * @param[in] instanceCount Number of times to draw the provided geometry, each time with an (optionally)
  415. * separate per-instance data.
  416. */
  417. virtual void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount,
  418. UINT32 instanceCount = 0) = 0;
  419. /**
  420. * Executes the currently bound compute shader.
  421. *
  422. * @param[in] numGroupsX Number of groups to start in the X direction. Must be in range [1, 65535].
  423. * @param[in] numGroupsY Number of groups to start in the Y direction. Must be in range [1, 65535].
  424. * @param[in] numGroupsZ Number of groups to start in the Z direction. Must be in range [1, 64].
  425. */
  426. virtual void dispatchCompute(UINT32 numGroupsX, UINT32 numGroupsY = 1, UINT32 numGroupsZ = 1) = 0;
  427. /**
  428. * Swap the front and back buffer of the specified render target.
  429. *
  430. * @param[in] target Render target to perform the buffer swap on.
  431. */
  432. virtual void swapBuffers(const SPtr<RenderTargetCore>& target);
  433. /**
  434. * Gets the capabilities of the render system.
  435. *
  436. * @note Thread safe.
  437. */
  438. const RenderAPICapabilities* getCapabilities() const;
  439. /** Returns information about the driver version. */
  440. virtual const DriverVersion& getDriverVersion() const;
  441. /**
  442. * Binds the provided GPU program to the pipeline. Any following draw operations will use this program.
  443. *
  444. * @param[in] prg GPU program to bind. Slot it is bound to is determined by the program type.
  445. *
  446. * @note You need to bind at least a vertex and a fragment program in order to draw something.
  447. */
  448. virtual void bindGpuProgram(const SPtr<GpuProgramCore>& prg);
  449. /**
  450. * Binds constant(uniform) GPU program parameters. Caller must ensure these match the previously bound GPU program.
  451. *
  452. * @param[in] gptype GPU program slot to bind the buffer to.
  453. * @param[in] params Object containing the required constant buffers.
  454. */
  455. virtual void setConstantBuffers(GpuProgramType gptype, const SPtr<GpuParamsCore>& params) = 0;
  456. /**
  457. * Binds all specified GPU program parameters (textures, buffers, samplers and constant buffers). Caller must
  458. * ensure these match the previously bound GPU program.
  459. *
  460. * @param[in] gptype GPU program slot to bind the buffer to.
  461. * @param[in] params Object containing the required parameters.
  462. */
  463. virtual void setGpuParams(GpuProgramType gptype, const SPtr<GpuParamsCore>& params);
  464. /**
  465. * Unbinds a program of a given type.
  466. *
  467. * @param[in] gptype GPU program slot to unbind the program from.
  468. */
  469. virtual void unbindGpuProgram(GpuProgramType gptype);
  470. /** Query if a GPU program of a given type is currently bound. */
  471. virtual bool isGpuProgramBound(GpuProgramType gptype);
  472. /**
  473. * Sets up clip planes that will clip drawn geometry on the negative side of the planes.
  474. *
  475. * @param[in] clipPlanes A list of planes to set, replacing the old ones.
  476. */
  477. virtual void setClipPlanes(const PlaneList& clipPlanes);
  478. /**
  479. * Adds a new clip plane. All drawn geometry will be clipped to this plane.
  480. *
  481. * @param[in] p Clip plane to add.
  482. */
  483. virtual void addClipPlane(const Plane& p);
  484. /** Clears all clip planes. */
  485. virtual void resetClipPlanes();
  486. /**
  487. * Allows you to set up a region in which rendering can take place. Coordinates are in pixels. No rendering will be
  488. * done to render target pixels outside of the provided region.
  489. *
  490. * @param[in] left Left border of the scissor rectangle, in pixels.
  491. * @param[in] top Top border of the scissor rectangle, in pixels.
  492. * @param[in] right Right border of the scissor rectangle, in pixels.
  493. * @param[in] bottom Bottom border of the scissor rectangle, in pixels.
  494. */
  495. virtual void setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom) = 0;
  496. /**
  497. * Clears the currently active render target.
  498. *
  499. * @param[in] buffers Combination of one or more elements of FrameBufferType denoting which buffers are
  500. * to be cleared.
  501. * @param[in] color (optional) The color to clear the color buffer with, if enabled.
  502. * @param[in] depth (optional) The value to initialize the depth buffer with, if enabled.
  503. * @param[in] stencil (optional) The value to initialize the stencil buffer with, if enabled.
  504. * @param[in] targetMask (optional) In case multiple render targets are bound, this allows you to control
  505. * which ones to clear (0x01 first, 0x02 second, 0x04 third, etc., and combinations).
  506. */
  507. virtual void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f,
  508. UINT16 stencil = 0, UINT8 targetMask = 0xFF) = 0;
  509. /**
  510. * Clears the currently active viewport (meaning it clears just a sub-area of a render-target that is covered by the
  511. * viewport, as opposed to clearRenderTarget() which always clears the entire render target).
  512. *
  513. * @param[in] buffers Combination of one or more elements of FrameBufferType denoting which buffers are to be
  514. * cleared.
  515. * @param[in] color (optional) The color to clear the color buffer with, if enabled.
  516. * @param[in] depth (optional) The value to initialize the depth buffer with, if enabled.
  517. * @param[in] stencil (optional) The value to initialize the stencil buffer with, if enabled.
  518. * @param[in] targetMask (optional) In case multiple render targets are bound, this allows you to control
  519. * which ones to clear (0x01 first, 0x02 second, 0x04 third, etc., and combinations).
  520. */
  521. virtual void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f,
  522. UINT16 stencil = 0, UINT8 targetMask = 0xFF) = 0;
  523. /**
  524. * Change the render target into which we want to draw.
  525. *
  526. * @param[in] target Render target to draw to.
  527. * @param[in] readOnlyDepthStencil If true the caller guarantees he won't write to the depth/stencil buffer
  528. * (if any was provided). This allows the depth buffer to be bound for depth
  529. * testing, as well as reading in a shader, at the same time.
  530. */
  531. virtual void setRenderTarget(const SPtr<RenderTargetCore>& target, bool readOnlyDepthStencil = false) = 0;
  532. /**
  533. * Returns information about available output devices and their video modes.
  534. *
  535. * @note Thread safe.
  536. */
  537. const VideoModeInfo& getVideoModeInfo() const { return *mVideoModeInfo; }
  538. /************************************************************************/
  539. /* UTILITY METHODS */
  540. /************************************************************************/
  541. /**
  542. * Contains a default matrix into a matrix suitable for use by this specific render system.
  543. *
  544. * @note Thread safe.
  545. */
  546. virtual void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest) = 0;
  547. /**
  548. * Returns information about the specific API implementation.
  549. *
  550. * @note Thread safe.
  551. */
  552. virtual const RenderAPIInfo& getAPIInfo() const = 0;
  553. /**
  554. * Generates a parameter block description and calculates per-parameter offsets for the provided gpu data
  555. * parameters. The offsets are render API specific and correspond to std140 layout for OpenGL, and the default
  556. * layout in DirectX.
  557. *
  558. * @param[in] name Name to assign the parameter block.
  559. * @param[in] params List of parameters in the parameter block. Only name, type and array size fields need to be
  560. * populated, the rest will be populated when the method returns.
  561. * @return Descriptor for the parameter block holding the provided parameters as laid out by the
  562. * default render API layout.
  563. */
  564. virtual GpuParamBlockDesc generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params) = 0;
  565. /************************************************************************/
  566. /* INTERNAL METHODS */
  567. /************************************************************************/
  568. protected:
  569. /**
  570. * Initializes the render API system and creates a primary render window.
  571. *
  572. * @note
  573. * Although I'd like otherwise, due to the nature of some render API implementations, you cannot initialize the
  574. * render system without a window.
  575. * @note
  576. * Sim thread.
  577. */
  578. SPtr<RenderWindow> initialize(const RENDER_WINDOW_DESC& primaryWindowDesc);
  579. /**
  580. * Prepares the initialization of the render API system on the core thread. After the system is prepared a render
  581. * window can be created and initialization finalized.
  582. */
  583. virtual void initializePrepare();
  584. /**
  585. * Finalizes the initialization of the render API system on the core thread. Should be called after the primary
  586. * render window is created.
  587. */
  588. virtual void initializeFinalize(const SPtr<RenderWindowCore>& primaryWindow);
  589. /**
  590. * Shuts down the render API system and cleans up all resources.
  591. *
  592. * @note Sim thread.
  593. */
  594. void destroy();
  595. /** Performs render API system shutdown on the core thread. */
  596. virtual void destroyCore();
  597. /** @copydoc setClipPlanes */
  598. virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0;
  599. /************************************************************************/
  600. /* INTERNAL DATA */
  601. /************************************************************************/
  602. protected:
  603. friend class RenderAPIManager;
  604. SPtr<RenderTargetCore> mActiveRenderTarget;
  605. DriverVersion mDriverVersion;
  606. CullingMode mCullingMode;
  607. UINT16 mDisabledTexUnitsFrom;
  608. bool mVertexProgramBound;
  609. bool mGeometryProgramBound;
  610. bool mFragmentProgramBound;
  611. bool mDomainProgramBound;
  612. bool mHullProgramBound;
  613. bool mComputeProgramBound;
  614. PlaneList mClipPlanes;
  615. bool mClipPlanesDirty;
  616. RenderAPICapabilities* mCurrentCapabilities;
  617. SPtr<VideoModeInfo> mVideoModeInfo;
  618. };
  619. /** @} */
  620. }