CmRenderSystem.h 48 KB

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