CmRenderSystem.h 49 KB

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