CmRenderSystem.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __RenderSystem_H_
  25. #define __RenderSystem_H_
  26. // Precompiler options
  27. #include "CmPrerequisites.h"
  28. #include <memory>
  29. #include "CmString.h"
  30. #include "CmSamplerState.h"
  31. #include "CmCommon.h"
  32. #include "CmRenderOperation.h"
  33. #include "CmRenderSystemCapabilities.h"
  34. #include "CmRenderTarget.h"
  35. #include "CmRenderTexture.h"
  36. #include "CmGpuProgram.h"
  37. #include "CmPlane.h"
  38. #include "boost/function.hpp"
  39. #include "boost/signal.hpp"
  40. namespace CamelotEngine
  41. {
  42. /** \addtogroup Core
  43. * @{
  44. */
  45. /** \addtogroup RenderSystem
  46. * @{
  47. */
  48. typedef map< String, RenderTarget * >::type RenderTargetMap;
  49. typedef multimap<UINT8, RenderTarget * >::type RenderTargetPriorityMap;
  50. class TextureManager;
  51. /// Enum describing the ways to generate texture coordinates
  52. enum TexCoordCalcMethod
  53. {
  54. /// No calculated texture coordinates
  55. TEXCALC_NONE,
  56. /// Environment map based on vertex normals
  57. TEXCALC_ENVIRONMENT_MAP,
  58. /// Environment map based on vertex positions
  59. TEXCALC_ENVIRONMENT_MAP_PLANAR,
  60. TEXCALC_ENVIRONMENT_MAP_REFLECTION,
  61. TEXCALC_ENVIRONMENT_MAP_NORMAL,
  62. /// Projective texture
  63. TEXCALC_PROJECTIVE_TEXTURE
  64. };
  65. /// Enum describing the various actions which can be taken onthe stencil buffer
  66. enum StencilOperation
  67. {
  68. /// Leave the stencil buffer unchanged
  69. SOP_KEEP,
  70. /// Set the stencil value to zero
  71. SOP_ZERO,
  72. /// Set the stencil value to the reference value
  73. SOP_REPLACE,
  74. /// Increase the stencil value by 1, clamping at the maximum value
  75. SOP_INCREMENT,
  76. /// Decrease the stencil value by 1, clamping at 0
  77. SOP_DECREMENT,
  78. /// Increase the stencil value by 1, wrapping back to 0 when incrementing the maximum value
  79. SOP_INCREMENT_WRAP,
  80. /// Decrease the stencil value by 1, wrapping when decrementing 0
  81. SOP_DECREMENT_WRAP,
  82. /// Invert the bits of the stencil buffer
  83. SOP_INVERT
  84. };
  85. /** Defines the functionality of a 3D API
  86. @remarks
  87. The RenderSystem class provides a base interface
  88. which abstracts the general functionality of the 3D API
  89. e.g. Direct3D or OpenGL. Whilst a few of the general
  90. methods have implementations, most of this class is
  91. abstract, requiring a subclass based on a specific API
  92. to be constructed to provide the full functionality.
  93. Note there are 2 levels to the interface - one which
  94. will be used often by the caller of the Ogre library,
  95. and one which is at a lower level and will be used by the
  96. other classes provided by Ogre. These lower level
  97. methods are prefixed with '_' to differentiate them.
  98. The advanced user of the library may use these lower
  99. level methods to access the 3D API at a more fundamental
  100. level (dealing direct with render states and rendering
  101. primitives), but still benefiting from Ogre's abstraction
  102. of exactly which 3D API is in use.
  103. @author
  104. Steven Streeting
  105. @version
  106. 1.0
  107. */
  108. class CM_EXPORT RenderSystem
  109. {
  110. public:
  111. /** Default Constructor.
  112. */
  113. RenderSystem();
  114. /** Destructor.
  115. */
  116. virtual ~RenderSystem();
  117. /** Returns the name of the rendering system.
  118. */
  119. virtual const String& getName(void) const = 0;
  120. /** Sets an option for this API
  121. @remarks
  122. Used to confirm the settings (normally chosen by the user) in
  123. order to make the renderer able to initialise with the settings as required.
  124. This may be video mode, D3D driver, full screen / windowed etc.
  125. Called automatically by the default configuration
  126. dialog, and by the restoration of saved settings.
  127. These settings are stored and only activated when
  128. RenderSystem::initialise or RenderSystem::reinitialise
  129. are called.
  130. @par
  131. If using a custom configuration dialog, it is advised that the
  132. caller calls RenderSystem::getConfigOptions
  133. again, since some options can alter resulting from a selection.
  134. @param
  135. name The name of the option to alter.
  136. @param
  137. value The value to set the option to.
  138. */
  139. virtual void setConfigOption(const String &name, const String &value) = 0;
  140. /** Validates the options set for the rendering system, returning a message if there are problems.
  141. @note
  142. If the returned string is empty, there are no problems.
  143. */
  144. virtual String validateConfigOptions(void) = 0;
  145. /* @brief Start up the RenderSystem. Call before doing any operations on the render system.
  146. * Make sure all subsequent calls to the RenderSystem are done from the same thread it was started on.
  147. *
  148. * @remark If you want to access the render system from other threads, call RenderSystem::createRenderContext,
  149. * set the active context using RenderSystem::setActiveRenderContext and call the render system normally.
  150. * By default an automatically created primary render context is used.
  151. */
  152. void startUp();
  153. /** Query the real capabilities of the GPU and driver in the RenderSystem*/
  154. virtual RenderSystemCapabilities* createRenderSystemCapabilities() const = 0;
  155. /** Force the render system to use the special capabilities. Can only be called
  156. * before the render system has been fully initializer (before createWindow is called)
  157. * @param
  158. * capabilities has to be a subset of the real capabilities and the caller is
  159. * responsible for deallocating capabilities.
  160. */
  161. virtual void useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities);
  162. /** Shutdown the renderer and cleanup resources.
  163. */
  164. virtual void shutdown(void);
  165. /** Creates a new rendering window.
  166. @remarks
  167. This method creates a new rendering window as specified
  168. by the paramteters. The rendering system could be
  169. responible for only a single window (e.g. in the case
  170. of a game), or could be in charge of multiple ones (in the
  171. case of a level editor). The option to create the window
  172. as a child of another is therefore given.
  173. This method will create an appropriate subclass of
  174. RenderWindow depending on the API and platform implementation.
  175. @par
  176. After creation, this window can be retrieved using getRenderTarget().
  177. @param
  178. name The name of the window. Used in other methods
  179. later like setRenderTarget and getRenderTarget.
  180. @param
  181. width The width of the new window.
  182. @param
  183. height The height of the new window.
  184. @param
  185. fullScreen Specify true to make the window full screen
  186. without borders, title bar or menu bar.
  187. @param
  188. miscParams A NameValuePairList describing the other parameters for the new rendering window.
  189. Options are case sensitive. Unrecognised parameters will be ignored silently.
  190. These values might be platform dependent, but these are present for all platforms unless
  191. indicated otherwise:
  192. <table>
  193. <tr>
  194. <td><b>Key</b></td>
  195. <td><b>Type/Values</b></td>
  196. <td><b>Default</b></td>
  197. <td><b>Description</b></td>
  198. <td><b>Notes</b></td>
  199. </tr>
  200. <tr>
  201. <td>title</td>
  202. <td>Any string</td>
  203. <td>RenderTarget name</td>
  204. <td>The title of the window that will appear in the title bar</td>
  205. <td>&nbsp;</td>
  206. </tr>
  207. <tr>
  208. <td>colourDepth</td>
  209. <td>16, 32</td>
  210. <td>Desktop depth</td>
  211. <td>Colour depth of the resulting rendering window; only applies if fullScreen</td>
  212. <td>Win32 Specific</td>
  213. </tr>
  214. <tr>
  215. <td>left</td>
  216. <td>Positive integers</td>
  217. <td>Centred</td>
  218. <td>Screen x coordinate from left</td>
  219. <td>&nbsp;</td>
  220. </tr>
  221. <tr>
  222. <td>top</td>
  223. <td>Positive integers</td>
  224. <td>Centred</td>
  225. <td>Screen y coordinate from left</td>
  226. <td>&nbsp;</td>
  227. </tr>
  228. <tr>
  229. <td>depthBuffer</td>
  230. <td>true, false</td>
  231. <td>true</td>
  232. <td>Use depth buffer</td>
  233. <td>DirectX9 specific</td>
  234. </tr>
  235. <tr>
  236. <td>externalWindowHandle</td>
  237. <td>Win32: HWND as integer<br/>
  238. GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)</td>
  239. <td>0 (none)</td>
  240. <td>External window handle, for embedding the OGRE render in an existing window</td>
  241. <td>&nbsp;</td>
  242. </tr>
  243. <tr>
  244. <td>externalGLControl</td>
  245. <td>true, false</td>
  246. <td>false</td>
  247. <td>Let the external window control OpenGL i.e. don't select a pixel format for the window,
  248. do not change v-sync and do not swap buffer. When set to true, the calling application
  249. is responsible of OpenGL initialization and buffer swapping. It should also create an
  250. OpenGL context for its own rendering, Ogre will create one for its use. Then the calling
  251. application must also enable Ogre OpenGL context before calling any Ogre function and
  252. restore its OpenGL context after these calls.</td>
  253. <td>OpenGL specific</td>
  254. </tr>
  255. <tr>
  256. <td>externalGLContext</td>
  257. <td>Context as Unsigned Long</td>
  258. <td>0 (create own context)</td>
  259. <td>Use an externally created GL context</td>
  260. <td>OpenGL Specific</td>
  261. </tr>
  262. <tr>
  263. <td>parentWindowHandle</td>
  264. <td>Win32: HWND as integer<br/>
  265. GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)</td>
  266. <td>0 (none)</td>
  267. <td>Parent window handle, for embedding the engine in a child of an external window</td>
  268. <td>&nbsp;</td>
  269. </tr>
  270. <tr>
  271. <td>macAPI</td>
  272. <td>String: "cocoa" or "carbon"</td>
  273. <td>"carbon"</td>
  274. <td>Specifies the type of rendering window on the Mac Platform.</td>
  275. <td>&nbsp;</td>
  276. </tr>
  277. <tr>
  278. <td>macAPICocoaUseNSView</td>
  279. <td>bool "true" or "false"</td>
  280. <td>"false"</td>
  281. <td>On the Mac platform the most diffused method to embed engine in a custom application is to use Interface Builder
  282. and add to the interface an instance of OgreView.
  283. The pointer to this instance is then used as "externalWindowHandle".
  284. However, there are cases where you are NOT using Interface Builder and you get the Cocoa NSView* of an existing interface.
  285. For example, this is happens when you want to render into a Java/AWT interface.
  286. In short, by setting this flag to "true" the Ogre::Root::createRenderWindow interprets the "externalWindowHandle" as a NSView*
  287. instead of an OgreView*. See OgreOSXCocoaView.h/mm.
  288. </td>
  289. <td>&nbsp;</td>
  290. </tr>
  291. <tr>
  292. <td>FSAA</td>
  293. <td>Positive integer (usually 0, 2, 4, 8, 16)</td>
  294. <td>0</td>
  295. <td>Full screen antialiasing factor</td>
  296. <td>&nbsp;</td>
  297. </tr>
  298. <tr>
  299. <td>FSAAHint</td>
  300. <td>Depends on RenderSystem and hardware. Currently supports:<br/>
  301. "Quality": on systems that have an option to prefer higher AA quality over speed, use it</td>
  302. <td>Blank</td>
  303. <td>Full screen antialiasing hint</td>
  304. <td>&nbsp;</td>
  305. </tr>
  306. <tr>
  307. <td>displayFrequency</td>
  308. <td>Refresh rate in Hertz (e.g. 60, 75, 100)</td>
  309. <td>Desktop vsync rate</td>
  310. <td>Display frequency rate, for fullscreen mode</td>
  311. <td>&nbsp;</td>
  312. </tr>
  313. <tr>
  314. <td>vsync</td>
  315. <td>true, false</td>
  316. <td>false</td>
  317. <td>Synchronize buffer swaps to monitor vsync, eliminating tearing at the expense of a fixed frame rate</td>
  318. <td>&nbsp;</td>
  319. </tr>
  320. <tr>
  321. <td>vsyncInterval</td>
  322. <td>1, 2, 3, 4</td>
  323. <td>1</td>
  324. <td>If vsync is enabled, the minimum number of vertical blanks that should occur between renders.
  325. For example if vsync is enabled, the refresh rate is 60 and this is set to 2, then the
  326. frame rate will be locked at 30.</td>
  327. <td>&nbsp;</td>
  328. </tr>
  329. <tr>
  330. <td>border</td>
  331. <td>none, fixed, resize</td>
  332. <td>resize</td>
  333. <td>The type of window border (in windowed mode)</td>
  334. <td>&nbsp;</td>
  335. </tr>
  336. <tr>
  337. <td>outerDimensions</td>
  338. <td>true, false</td>
  339. <td>false</td>
  340. <td>Whether the width/height is expressed as the size of the
  341. outer window, rather than the content area</td>
  342. <td>&nbsp;</td>
  343. </tr>
  344. <tr>
  345. <td>useNVPerfHUD</td>
  346. <td>true, false</td>
  347. <td>false</td>
  348. <td>Enable the use of nVidia NVPerfHUD</td>
  349. <td>&nbsp;</td>
  350. </tr>
  351. <tr>
  352. <td>gamma</td>
  353. <td>true, false</td>
  354. <td>false</td>
  355. <td>Enable hardware conversion from linear colour space to gamma
  356. colour space on rendering to the window.</td>
  357. <td>&nbsp;</td>
  358. </tr>
  359. */
  360. RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height,
  361. bool fullScreen, const NameValuePairList *miscParams = 0);
  362. /** Create a MultiRenderTarget, which is a render target that renders to multiple RenderTextures
  363. at once. Surfaces can be bound and unbound at will.
  364. This fails if mCapabilities->getNumMultiRenderTargets() is smaller than 2.
  365. */
  366. virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0;
  367. /** Destroys a render window */
  368. virtual void destroyRenderWindow(const String& name);
  369. /** Destroys a render texture */
  370. virtual void destroyRenderTexture(const String& name);
  371. /** Destroys a render target of any sort */
  372. virtual void destroyRenderTarget(const String& name);
  373. /** Attaches the passed render target to the render system.
  374. */
  375. virtual void attachRenderTarget( RenderTarget &target );
  376. /** Returns a pointer to the render target with the passed name, or NULL if that
  377. render target cannot be found.
  378. */
  379. virtual RenderTarget * getRenderTarget( const String &name );
  380. /** Detaches the render target with the passed name from the render system and
  381. returns a pointer to it.
  382. @note
  383. If the render target cannot be found, NULL is returned.
  384. */
  385. virtual RenderTarget * detachRenderTarget( const String &name );
  386. /// Iterator over RenderTargets
  387. typedef CamelotEngine::RenderTargetMap::iterator RenderTargetIterator;
  388. /** Returns a specialised MapIterator over all render targets attached to the RenderSystem. */
  389. virtual RenderTargetIterator getRenderTargetIterator(void) {
  390. return mRenderTargets.begin();
  391. }
  392. /** Returns a description of an error code.
  393. */
  394. virtual String getErrorDescription(long errorNumber) const = 0;
  395. /** Defines whether or now fullscreen render windows wait for the vertical blank before flipping buffers.
  396. @remarks
  397. By default, all rendering windows wait for a vertical blank (when the CRT beam turns off briefly to move
  398. from the bottom right of the screen back to the top left) before flipping the screen buffers. This ensures
  399. that the image you see on the screen is steady. However it restricts the frame rate to the refresh rate of
  400. the monitor, and can slow the frame rate down. You can speed this up by not waiting for the blank, but
  401. this has the downside of introducing 'tearing' artefacts where part of the previous frame is still displayed
  402. as the buffers are switched. Speed vs quality, you choose.
  403. @note
  404. Has NO effect on windowed mode render targets. Only affects fullscreen mode.
  405. @param
  406. enabled If true, the system waits for vertical blanks - quality over speed. If false it doesn't - speed over quality.
  407. */
  408. void setWaitForVerticalBlank(bool enabled);
  409. /** Returns true if the system is synchronising frames with the monitor vertical blank.
  410. */
  411. bool getWaitForVerticalBlank(void) const;
  412. // ------------------------------------------------------------------------
  413. // Internal Rendering Access
  414. // All methods below here are normally only called by other Camelot classes
  415. // They can be called by library user if required
  416. // ------------------------------------------------------------------------
  417. /** Utility function for setting all the properties of a texture unit at once.
  418. This method is also worth using over the individual texture unit settings because it
  419. only sets those settings which are different from the current settings for this
  420. unit, thus minimising render state changes.
  421. */
  422. virtual void setTextureUnitSettings(size_t texUnit, const TexturePtr& texture, const SamplerState& tl);
  423. /** Turns off a texture unit. */
  424. virtual void disableTextureUnit(size_t texUnit);
  425. /** Disables all texture units from the given unit upwards */
  426. virtual void disableTextureUnitsFrom(size_t texUnit);
  427. /** Sets the size of points and how they are attenuated with distance.
  428. @remarks
  429. When performing point rendering or point sprite rendering,
  430. point size can be attenuated with distance. The equation for
  431. doing this is attenuation = 1 / (constant + linear * dist + quadratic * d^2) .
  432. @par
  433. For example, to disable distance attenuation (constant screensize)
  434. you would set constant to 1, and linear and quadratic to 0. A
  435. standard perspective attenuation would be 0, 1, 0 respectively.
  436. */
  437. virtual void setPointParameters(float size, bool attenuationEnabled,
  438. float constant, float linear, float quadratic, float minSize, float maxSize) = 0;
  439. /**
  440. Sets the texture to bind to a given texture unit.
  441. User processes would not normally call this direct unless rendering
  442. primitives themselves.
  443. @param unit The index of the texture unit to modify. Multitexturing
  444. hardware can support multiple units (see
  445. RenderSystemCapabilites::getNumTextureUnits)
  446. @param enabled Boolean to turn the unit on/off
  447. @param texPtr Pointer to the texture to use.
  448. */
  449. virtual void setTexture(size_t unit, bool enabled,
  450. const TexturePtr &texPtr) = 0;
  451. /** Binds a texture to a vertex sampler.
  452. @remarks
  453. Not all rendersystems support separate vertex samplers. For those that
  454. do, you can set a texture for them, separate to the regular texture
  455. samplers, using this method. For those that don't, you should use the
  456. regular texture samplers which are shared between the vertex and
  457. fragment units; calling this method will throw an exception.
  458. @see RenderSystemCapabilites::getVertexTextureUnitsShared
  459. */
  460. virtual void setVertexTexture(size_t unit, const TexturePtr& tex);
  461. /** Sets the filtering options for a given texture unit.
  462. @param unit The texture unit to set the filtering options for
  463. @param minFilter The filter used when a texture is reduced in size
  464. @param magFilter The filter used when a texture is magnified
  465. @param mipFilter The filter used between mipmap levels, FO_NONE disables mipmapping
  466. */
  467. virtual void setTextureFiltering(size_t unit, FilterOptions minFilter,
  468. FilterOptions magFilter, FilterOptions mipFilter);
  469. /** Sets a single filter for a given texture unit.
  470. @param unit The texture unit to set the filtering options for
  471. @param ftype The filter type
  472. @param filter The filter to be used
  473. */
  474. virtual void setTextureFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0;
  475. /** Sets the maximal anisotropy for the specified texture unit.*/
  476. virtual void setTextureAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
  477. /** Sets the texture addressing mode for a texture unit.*/
  478. virtual void setTextureAddressingMode(size_t unit, const SamplerState::UVWAddressingMode& uvw) = 0;
  479. /** Sets the texture border color for a texture unit.*/
  480. virtual void setTextureBorderColor(size_t unit, const Color& colour) = 0;
  481. /** Sets the mipmap bias value for a given texture unit.
  482. @remarks
  483. This allows you to adjust the mipmap calculation up or down for a
  484. given texture unit. Negative values force a larger mipmap to be used,
  485. positive values force a smaller mipmap to be used. Units are in numbers
  486. of levels, so +1 forces the mipmaps to one smaller level.
  487. @note Only does something if render system has capability RSC_MIPMAP_LOD_BIAS.
  488. */
  489. virtual void setTextureMipmapBias(size_t unit, float bias) = 0;
  490. /** Sets the global blending factors for combining subsequent renders with the existing frame contents.
  491. The result of the blending operation is:</p>
  492. <p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
  493. Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
  494. enumerated type.
  495. By changing the operation you can change addition between the source and destination pixels to a different operator.
  496. @param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
  497. @param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
  498. @param op The blend operation mode for combining pixels
  499. */
  500. virtual void setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD) = 0;
  501. /** Sets the global blending factors for combining subsequent renders with the existing frame contents.
  502. The result of the blending operation is:</p>
  503. <p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
  504. Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
  505. enumerated type.
  506. @param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
  507. @param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
  508. @param sourceFactorAlpha The source factor in the above calculation for the alpha channel, i.e. multiplied by the texture alpha components.
  509. @param destFactorAlpha The destination factor in the above calculation for the alpha channel, i.e. multiplied by the pixel alpha components.
  510. @param op The blend operation mode for combining pixels
  511. @param alphaOp The blend operation mode for combining pixel alpha values
  512. */
  513. virtual void setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha,
  514. SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD) = 0;
  515. /** Sets the global alpha rejection approach for future renders.
  516. By default images are rendered regardless of texture alpha. This method lets you change that.
  517. @param func The comparison function which must pass for a pixel to be written.
  518. @param val The value to compare each pixels alpha value to (0-255)
  519. @param alphaToCoverage Whether to enable alpha to coverage, if supported
  520. */
  521. virtual void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
  522. /**
  523. * Signifies the beginning of a frame, i.e. the start of rendering on a single viewport. Will occur
  524. * several times per complete frame if multiple viewports exist.
  525. */
  526. virtual void beginFrame(void) = 0;
  527. /**
  528. * Ends rendering of a frame to the current viewport.
  529. */
  530. virtual void endFrame(void) = 0;
  531. /**
  532. Sets the provided viewport as the active one for future
  533. rendering operations. This viewport is aware of it's own
  534. camera and render target. Must be implemented by subclass.
  535. @param target Viewport to render to.
  536. */
  537. virtual void setViewport(const Viewport& vp) = 0;
  538. /** Get the current active viewport for rendering. */
  539. virtual Viewport getViewport(void);
  540. /** Sets the culling mode for the render system based on the 'vertex winding'.
  541. A typical way for the rendering engine to cull triangles is based on the
  542. 'vertex winding' of triangles. Vertex winding refers to the direction in
  543. which the vertices are passed or indexed to in the rendering operation as viewed
  544. from the camera, and will wither be clockwise or anticlockwise (that's 'counterclockwise' for
  545. you Americans out there ;) The default is CULL_CLOCKWISE i.e. that only triangles whose vertices
  546. are passed/indexed in anticlockwise order are rendered - this is a common approach and is used in 3D studio models
  547. for example. You can alter this culling mode if you wish but it is not advised unless you know what you are doing.
  548. You may wish to use the CULL_NONE option for mesh data that you cull yourself where the vertex
  549. winding is uncertain.
  550. */
  551. virtual void setCullingMode(CullingMode mode) = 0;
  552. virtual CullingMode getCullingMode(void) const;
  553. /** Sets the mode of operation for depth buffer tests from this point onwards.
  554. Sometimes you may wish to alter the behaviour of the depth buffer to achieve
  555. special effects. Because it's unlikely that you'll set these options for an entire frame,
  556. but rather use them to tweak settings between rendering objects, this is an internal
  557. method (indicated by the '_' prefix) which will be used by a SceneManager implementation
  558. rather than directly from the client application.
  559. If this method is never called the settings are automatically the same as the default parameters.
  560. @param depthTest If true, the depth buffer is tested for each pixel and the frame buffer is only updated
  561. if the depth function test succeeds. If false, no test is performed and pixels are always written.
  562. @param depthWrite If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
  563. If false, the depth buffer is left unchanged even if a new pixel is written.
  564. @param depthFunction Sets the function required for the depth test.
  565. */
  566. virtual void setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
  567. /** Sets whether or not the depth buffer check is performed before a pixel write.
  568. @param enabled If true, the depth buffer is tested for each pixel and the frame buffer is only updated
  569. if the depth function test succeeds. If false, no test is performed and pixels are always written.
  570. */
  571. virtual void setDepthBufferCheckEnabled(bool enabled = true) = 0;
  572. /** Sets whether or not the depth buffer is updated after a pixel write.
  573. @param enabled If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
  574. If false, the depth buffer is left unchanged even if a new pixel is written.
  575. */
  576. virtual void setDepthBufferWriteEnabled(bool enabled = true) = 0;
  577. /** Sets the comparison function for the depth buffer check.
  578. Advanced use only - allows you to choose the function applied to compare the depth values of
  579. new and existing pixels in the depth buffer. Only an issue if the deoth buffer check is enabled
  580. (see _setDepthBufferCheckEnabled)
  581. @param func The comparison between the new depth and the existing depth which must return true
  582. for the new pixel to be written.
  583. */
  584. virtual void setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
  585. /** Sets whether or not colour buffer writing is enabled, and for which channels.
  586. @remarks
  587. For some advanced effects, you may wish to turn off the writing of certain colour
  588. channels, or even all of the colour channels so that only the depth buffer is updated
  589. in a rendering pass. However, the chances are that you really want to use this option
  590. through the Material class.
  591. @param red, green, blue, alpha Whether writing is enabled for each of the 4 colour channels. */
  592. virtual void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
  593. /** Sets the depth bias, NB you should use the Material version of this.
  594. @remarks
  595. When polygons are coplanar, you can get problems with 'depth fighting' where
  596. the pixels from the two polys compete for the same screen pixel. This is particularly
  597. a problem for decals (polys attached to another surface to represent details such as
  598. bulletholes etc.).
  599. @par
  600. A way to combat this problem is to use a depth bias to adjust the depth buffer value
  601. used for the decal such that it is slightly higher than the true value, ensuring that
  602. the decal appears on top.
  603. @note
  604. The final bias value is a combination of a constant bias and a bias proportional
  605. to the maximum depth slope of the polygon being rendered. The final bias
  606. is constantBias + slopeScaleBias * maxslope. Slope scale biasing is
  607. generally preferable but is not available on older hardware.
  608. @param constantBias The constant bias value, expressed as a value in
  609. homogeneous depth coordinates.
  610. @param slopeScaleBias The bias value which is factored by the maximum slope
  611. of the polygon, see the description above. This is not supported by all
  612. cards.
  613. */
  614. virtual void setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0;
  615. /** The RenderSystem will keep a count of tris rendered, this resets the count. */
  616. virtual void beginGeometryCount(void);
  617. /** Reports the number of tris rendered since the last _beginGeometryCount call. */
  618. virtual unsigned int getFaceCount(void) const;
  619. /** Reports the number of batches rendered since the last _beginGeometryCount call. */
  620. virtual unsigned int getBatchCount(void) const;
  621. /** Reports the number of vertices passed to the renderer since the last _beginGeometryCount call. */
  622. virtual unsigned int getVertexCount(void) const;
  623. /** Generates a packed data version of the passed in ColourValue suitable for
  624. use as with this RenderSystem.
  625. @remarks
  626. Since different render systems have different colour data formats (eg
  627. RGBA for GL, ARGB for D3D) this method allows you to use 1 method for all.
  628. @param colour The colour to convert
  629. @param pDest Pointer to location to put the result.
  630. */
  631. virtual void convertColorValue(const Color& colour, UINT32* pDest);
  632. /** Get the native VertexElementType for a compact 32-bit colour value
  633. for this rendersystem.
  634. */
  635. virtual VertexElementType getColorVertexElementType(void) const = 0;
  636. /** Converts a uniform projection matrix to suitable for this render system.
  637. @remarks
  638. Because different APIs have different requirements (some incompatible) for the
  639. projection matrix, this method allows each to implement their own correctly and pass
  640. back a generic Camelot matrix for storage in the engine.
  641. */
  642. virtual void _convertProjectionMatrix(const Matrix4& matrix,
  643. Matrix4& dest, bool forGpuProgram = false) = 0;
  644. /** Sets how to rasterise triangles, as points, wireframe or solid polys. */
  645. virtual void setPolygonMode(PolygonMode level) = 0;
  646. /** Turns stencil buffer checking on or off.
  647. @remarks
  648. Stencilling (masking off areas of the rendering target based on the stencil
  649. buffer) can be turned on or off using this method. By default, stencilling is
  650. disabled.
  651. */
  652. virtual void setStencilCheckEnabled(bool enabled) = 0;
  653. /** Determines if this system supports hardware accelerated stencil buffer.
  654. @remarks
  655. Note that the lack of this function doesn't mean you can't do stencilling, but
  656. the stencilling operations will be provided in software, which will NOT be
  657. fast.
  658. @par
  659. Generally hardware stencils are only supported in 32-bit colour modes, because
  660. the stencil buffer shares the memory of the z-buffer, and in most cards the
  661. z-buffer has to be the same depth as the colour buffer. This means that in 32-bit
  662. mode, 24 bits of the z-buffer are depth and 8 bits are stencil. In 16-bit mode there
  663. is no room for a stencil (although some cards support a 15:1 depth:stencil option,
  664. this isn't useful for very much) so 8 bits of stencil are provided in software.
  665. This can mean that if you use stencilling, your applications may be faster in
  666. 32-but colour than in 16-bit, which may seem odd to some people.
  667. */
  668. /*virtual bool hasHardwareStencil(void) = 0;*/
  669. /** This method allows you to set all the stencil buffer parameters in one call.
  670. @remarks
  671. The stencil buffer is used to mask out pixels in the render target, allowing
  672. you to do effects like mirrors, cut-outs, stencil shadows and more. Each of
  673. your batches of rendering is likely to ignore the stencil buffer,
  674. update it with new values, or apply it to mask the output of the render.
  675. The stencil test is:<PRE>
  676. (Reference Value & Mask) CompareFunction (Stencil Buffer Value & Mask)</PRE>
  677. The result of this will cause one of 3 actions depending on whether the test fails,
  678. succeeds but with the depth buffer check still failing, or succeeds with the
  679. depth buffer check passing too.
  680. @par
  681. Unlike other render states, stencilling is left for the application to turn
  682. on and off when it requires. This is because you are likely to want to change
  683. parameters between batches of arbitrary objects and control the ordering yourself.
  684. In order to batch things this way, you'll want to use OGRE's separate render queue
  685. groups (see RenderQueue) and register a RenderQueueListener to get notifications
  686. between batches.
  687. @par
  688. There are individual state change methods for each of the parameters set using
  689. this method.
  690. Note that the default values in this method represent the defaults at system
  691. start up too.
  692. @param func The comparison function applied.
  693. @param refValue The reference value used in the comparison
  694. @param mask The bitmask applied to both the stencil value and the reference value
  695. before comparison
  696. @param stencilFailOp The action to perform when the stencil check fails
  697. @param depthFailOp The action to perform when the stencil check passes, but the
  698. depth buffer check still fails
  699. @param passOp The action to take when both the stencil and depth check pass.
  700. @param twoSidedOperation If set to true, then if you render both back and front faces
  701. (you'll have to turn off culling) then these parameters will apply for front faces,
  702. and the inverse of them will happen for back faces (keep remains the same).
  703. */
  704. virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
  705. UINT32 refValue = 0, UINT32 mask = 0xFFFFFFFF,
  706. StencilOperation stencilFailOp = SOP_KEEP,
  707. StencilOperation depthFailOp = SOP_KEEP,
  708. StencilOperation passOp = SOP_KEEP,
  709. bool twoSidedOperation = false) = 0;
  710. /** Sets the current vertex declaration, ie the source of vertex data. */
  711. virtual void setVertexDeclaration(VertexDeclarationPtr decl) = 0;
  712. /** Sets the current vertex buffer binding state. */
  713. virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
  714. /**
  715. Render something to the active viewport.
  716. Low-level rendering interface to perform rendering
  717. operations. Unlikely to be used directly by client
  718. applications, since the SceneManager and various support
  719. classes will be responsible for calling this method.
  720. Can only be called between _beginScene and _endScene
  721. @param op A rendering operation instance, which contains
  722. details of the operation to be performed.
  723. */
  724. virtual void render(const RenderOperation& op);
  725. /** Gets the capabilities of the render system. */
  726. const RenderSystemCapabilities* getCapabilities(void) const { return mCurrentCapabilities; }
  727. /** Returns the driver version.
  728. */
  729. virtual const DriverVersion& getDriverVersion(void) const { return mDriverVersion; }
  730. /** Binds a given GpuProgram (but not the parameters).
  731. @remarks Only one GpuProgram of each type can be bound at once, binding another
  732. one will simply replace the existing one.
  733. */
  734. virtual void bindGpuProgram(GpuProgramRef prg);
  735. /** Bind Gpu program parameters.
  736. @param gptype The type of program to bind the parameters to
  737. @param params The parameters to bind
  738. @param variabilityMask A mask of GpuParamVariability identifying which params need binding
  739. */
  740. virtual void bindGpuProgramParameters(GpuProgramType gptype,
  741. GpuProgramParametersSharedPtr params, UINT16 variabilityMask) = 0;
  742. /** Unbinds GpuPrograms of a given GpuProgramType.
  743. @remarks
  744. This returns the pipeline to fixed-function processing for this type.
  745. */
  746. virtual void unbindGpuProgram(GpuProgramType gptype);
  747. /** Returns whether or not a Gpu program of the given type is currently bound. */
  748. virtual bool isGpuProgramBound(GpuProgramType gptype);
  749. /** Sets the user clipping region.
  750. */
  751. virtual void setClipPlanes(const PlaneList& clipPlanes);
  752. /** Add a user clipping plane. */
  753. virtual void addClipPlane (const Plane &p);
  754. /** Add a user clipping plane. */
  755. virtual void addClipPlane (float A, float B, float C, float D);
  756. /** Clears the user clipping region.
  757. */
  758. virtual void resetClipPlanes();
  759. /** Internal method for swapping all the buffers on all render targets,
  760. if _updateAllRenderTargets was called with a 'false' parameter. */
  761. virtual void swapAllRenderTargetBuffers(bool waitForVsync = true);
  762. /** Sets whether or not vertex windings set should be inverted; this can be important
  763. for rendering reflections. */
  764. virtual void setInvertVertexWinding(bool invert);
  765. /** Indicates whether or not the vertex windings set will be inverted for the current render (e.g. reflections)
  766. @see RenderSystem::setInvertVertexWinding
  767. */
  768. virtual bool getInvertVertexWinding(void) const;
  769. /** Sets the 'scissor region' ie the region of the target in which rendering can take place.
  770. @remarks
  771. This method allows you to 'mask off' rendering in all but a given rectangular area
  772. as identified by the parameters to this method.
  773. @note
  774. Not all systems support this method. Check the RenderSystemCapabilities for the
  775. RSC_SCISSOR_TEST capability to see if it is supported.
  776. @param enabled True to enable the scissor test, false to disable it.
  777. @param left, top, right, bottom The location of the corners of the rectangle, expressed in
  778. <i>pixels</i>.
  779. */
  780. virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0,
  781. size_t right = 800, size_t bottom = 600) = 0;
  782. /** Clears one or more frame buffers on the active render target.
  783. @param buffers Combination of one or more elements of FrameBufferType
  784. denoting which buffers are to be cleared
  785. @param colour The colour to clear the colour buffer with, if enabled
  786. @param depth The value to initialise the depth buffer with, if enabled
  787. @param stencil The value to initialise the stencil buffer with, if enabled.
  788. */
  789. virtual void clearFrameBuffer(unsigned int buffers,
  790. const Color& colour = Color::Black,
  791. float depth = 1.0f, unsigned short stencil = 0) = 0;
  792. /** Returns the horizontal texel offset value required for mapping
  793. texel origins to pixel origins in this rendersystem.
  794. @remarks
  795. Since rendersystems sometimes disagree on the origin of a texel,
  796. mapping from texels to pixels can sometimes be problematic to
  797. implement generically. This method allows you to retrieve the offset
  798. required to map the origin of a texel to the origin of a pixel in
  799. the horizontal direction.
  800. */
  801. virtual float getHorizontalTexelOffset(void) = 0;
  802. /** Returns the vertical texel offset value required for mapping
  803. texel origins to pixel origins in this rendersystem.
  804. @remarks
  805. Since rendersystems sometimes disagree on the origin of a texel,
  806. mapping from texels to pixels can sometimes be problematic to
  807. implement generically. This method allows you to retrieve the offset
  808. required to map the origin of a texel to the origin of a pixel in
  809. the vertical direction.
  810. */
  811. virtual float getVerticalTexelOffset(void) = 0;
  812. /** Gets the minimum (closest) depth value to be used when rendering
  813. using identity transforms.
  814. @remarks
  815. When using identity transforms you can manually set the depth
  816. of a vertex; however the input values required differ per
  817. rendersystem. This method lets you retrieve the correct value.
  818. @see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
  819. */
  820. virtual float getMinimumDepthInputValue(void) = 0;
  821. /** Gets the maximum (farthest) depth value to be used when rendering
  822. using identity transforms.
  823. @remarks
  824. When using identity transforms you can manually set the depth
  825. of a vertex; however the input values required differ per
  826. rendersystem. This method lets you retrieve the correct value.
  827. @see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
  828. */
  829. virtual float getMaximumDepthInputValue(void) = 0;
  830. /**
  831. * Set current render target to target, enabling its device context if needed
  832. */
  833. virtual void setRenderTarget(RenderTarget *target) = 0;
  834. /** Register the an additional thread which may make calls to rendersystem-related
  835. objects.
  836. @remarks
  837. This method should only be called by additional threads during their
  838. initialisation. If they intend to use hardware rendering system resources
  839. they should call this method before doing anything related to the render system.
  840. Some rendering APIs require a per-thread setup and this method will sort that
  841. out. It is also necessary to call unregisterThread before the thread shuts down.
  842. @note
  843. This method takes no parameters - it must be called from the thread being
  844. registered and that context is enough.
  845. */
  846. virtual void registerThread() = 0;
  847. /** Unregister an additional thread which may make calls to rendersystem-related objects.
  848. @see RenderSystem::registerThread
  849. */
  850. virtual void unregisterThread() = 0;
  851. /**
  852. * Gets the number of display monitors.
  853. @see Root::getDisplayMonitorCount
  854. */
  855. virtual unsigned int getDisplayMonitorCount() const = 0;
  856. /************************************************************************/
  857. /* INTERNAL CALLBACKS */
  858. /************************************************************************/
  859. protected:
  860. virtual void startUp_internal(AsyncOp& asyncOp);
  861. virtual void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height,
  862. bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp) = 0;
  863. protected:
  864. /** The render targets. */
  865. RenderTargetMap mRenderTargets;
  866. /** The render targets, ordered by priority. */
  867. RenderTargetPriorityMap mPrioritisedRenderTargets;
  868. /** The Active render target. */
  869. RenderTarget * mActiveRenderTarget;
  870. /** The Active GPU programs and gpu program parameters*/
  871. GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters;
  872. GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters;
  873. GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters;
  874. // Active viewport (dest for future rendering operations)
  875. Viewport mActiveViewport;
  876. CullingMode mCullingMode;
  877. bool mVSync;
  878. unsigned int mVSyncInterval;
  879. size_t mBatchCount;
  880. size_t mFaceCount;
  881. size_t mVertexCount;
  882. bool mInvertVertexWinding;
  883. /// Texture units from this upwards are disabled
  884. size_t mDisabledTexUnitsFrom;
  885. bool mVertexProgramBound;
  886. bool mGeometryProgramBound;
  887. bool mFragmentProgramBound;
  888. // Recording user clip planes
  889. PlaneList mClipPlanes;
  890. // Indicator that we need to re-set the clip planes on next render call
  891. bool mClipPlanesDirty;
  892. /// Used to store the capabilities of the graphics card
  893. RenderSystemCapabilities* mRealCapabilities;
  894. RenderSystemCapabilities* mCurrentCapabilities;
  895. bool mUseCustomCapabilities;
  896. /// Internal method used to set the underlying clip planes when needed
  897. virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0;
  898. /** Initialize the render system from the capabilities*/
  899. virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0;
  900. DriverVersion mDriverVersion;
  901. /************************************************************************/
  902. /* THREADING */
  903. /************************************************************************/
  904. class RenderWorkerFunc CM_THREAD_WORKER_INHERIT
  905. {
  906. public:
  907. RenderWorkerFunc(RenderSystem* rs);
  908. void operator()();
  909. private:
  910. RenderSystem* mRS;
  911. };
  912. RenderWorkerFunc* mRenderThreadFunc;
  913. bool mRenderThreadShutdown;
  914. CM_THREAD_ID_TYPE mRenderThreadId;
  915. CM_THREAD_SYNCHRONISER(mRSContextInitCondition)
  916. CM_MUTEX(mRSContextInitMutex)
  917. CM_THREAD_SYNCHRONISER(mRSContextReadyCondition)
  918. CM_MUTEX(mRSContextMutex)
  919. CM_MUTEX(mRSRenderCallbackMutex)
  920. CM_MUTEX(mResourceContextMutex)
  921. #if CM_THREAD_SUPPORT
  922. CM_THREAD_TYPE* mRenderThread;
  923. #endif
  924. RenderSystemContextPtr mResourceContext;
  925. vector<RenderSystemContextPtr>::type mRenderSystemContexts;
  926. boost::signal<void()> PreRenderThreadUpdateCallback;
  927. boost::signal<void()> PostRenderThreadUpdateCallback;
  928. /**
  929. * @brief Initializes a separate render thread. Should only be called once.
  930. */
  931. void initRenderThread();
  932. /**
  933. * @brief Main function of the render thread. Called once thread is started.
  934. */
  935. void runRenderThread();
  936. /**
  937. * @brief Shutdowns the render thread. It will complete all ready commands
  938. * before shutdown.
  939. */
  940. void shutdownRenderThread();
  941. /**
  942. * @brief Throws an exception if current thread isn't the render thread;
  943. */
  944. void throwIfInvalidThread();
  945. /**
  946. * @brief Submits the specified context to the GPU. Normally this happens automatically
  947. * at the end of each frame for all contexts, but in some cases you might want to do it
  948. * manually via this method.
  949. *
  950. * @param context The context to submit.
  951. * @param blockUntilComplete If true, the calling thread will block until all commands are submitted.
  952. */
  953. void submitToGpu(RenderSystemContextPtr context, bool blockUntilComplete);
  954. public:
  955. /**
  956. * @brief Returns the id of the render thread. If a separate render thread
  957. * is not used, then it returns the id of the thread RenderSystem
  958. * was initialized on.
  959. */
  960. CM_THREAD_ID_TYPE getRenderThreadId() const { return mRenderThreadId; }
  961. /**
  962. * @brief Creates a new render system context that you can use for rendering on
  963. * a non-render thread. You can have as many of these as you wish, the only limitation
  964. * is that you do not use a single instance on more than one thread. Each thread
  965. * requires its own context.
  966. */
  967. RenderSystemContextPtr createRenderSystemContext();
  968. /**
  969. * @brief Callback that is called from the render thread before it starts processing
  970. * deferred render commands.
  971. */
  972. void addPreRenderThreadUpdateCallback(boost::function<void()> callback);
  973. /**
  974. * @brief Callback that is called from the render thread after it ends processing
  975. * deferred render commands.
  976. */
  977. void addPostRenderThreadUpdateCallback(boost::function<void()> callback);
  978. /**
  979. * @brief Called every frame
  980. */
  981. void update();
  982. };
  983. /** @} */
  984. /** @} */
  985. }
  986. #endif