OgreRenderSystem.h 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  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 "OgrePrerequisites.h"
  28. #include "OgreString.h"
  29. #include "OgreTextureUnitState.h"
  30. #include "OgreCommon.h"
  31. #include "OgreRenderOperation.h"
  32. #include "OgreRenderSystemCapabilities.h"
  33. #include "OgreRenderTarget.h"
  34. #include "OgreRenderTexture.h"
  35. #include "OgreGpuProgram.h"
  36. #include "OgrePlane.h"
  37. namespace Ogre
  38. {
  39. /** \addtogroup Core
  40. * @{
  41. */
  42. /** \addtogroup RenderSystem
  43. * @{
  44. */
  45. typedef map< String, RenderTarget * >::type RenderTargetMap;
  46. typedef multimap<uchar, RenderTarget * >::type RenderTargetPriorityMap;
  47. class TextureManager;
  48. /// Enum describing the ways to generate texture coordinates
  49. enum TexCoordCalcMethod
  50. {
  51. /// No calculated texture coordinates
  52. TEXCALC_NONE,
  53. /// Environment map based on vertex normals
  54. TEXCALC_ENVIRONMENT_MAP,
  55. /// Environment map based on vertex positions
  56. TEXCALC_ENVIRONMENT_MAP_PLANAR,
  57. TEXCALC_ENVIRONMENT_MAP_REFLECTION,
  58. TEXCALC_ENVIRONMENT_MAP_NORMAL,
  59. /// Projective texture
  60. TEXCALC_PROJECTIVE_TEXTURE
  61. };
  62. /// Enum describing the various actions which can be taken onthe stencil buffer
  63. enum StencilOperation
  64. {
  65. /// Leave the stencil buffer unchanged
  66. SOP_KEEP,
  67. /// Set the stencil value to zero
  68. SOP_ZERO,
  69. /// Set the stencil value to the reference value
  70. SOP_REPLACE,
  71. /// Increase the stencil value by 1, clamping at the maximum value
  72. SOP_INCREMENT,
  73. /// Decrease the stencil value by 1, clamping at 0
  74. SOP_DECREMENT,
  75. /// Increase the stencil value by 1, wrapping back to 0 when incrementing the maximum value
  76. SOP_INCREMENT_WRAP,
  77. /// Decrease the stencil value by 1, wrapping when decrementing 0
  78. SOP_DECREMENT_WRAP,
  79. /// Invert the bits of the stencil buffer
  80. SOP_INVERT
  81. };
  82. /** Defines the functionality of a 3D API
  83. @remarks
  84. The RenderSystem class provides a base interface
  85. which abstracts the general functionality of the 3D API
  86. e.g. Direct3D or OpenGL. Whilst a few of the general
  87. methods have implementations, most of this class is
  88. abstract, requiring a subclass based on a specific API
  89. to be constructed to provide the full functionality.
  90. Note there are 2 levels to the interface - one which
  91. will be used often by the caller of the Ogre library,
  92. and one which is at a lower level and will be used by the
  93. other classes provided by Ogre. These lower level
  94. methods are prefixed with '_' to differentiate them.
  95. The advanced user of the library may use these lower
  96. level methods to access the 3D API at a more fundamental
  97. level (dealing direct with render states and rendering
  98. primitives), but still benefiting from Ogre's abstraction
  99. of exactly which 3D API is in use.
  100. @author
  101. Steven Streeting
  102. @version
  103. 1.0
  104. */
  105. class _OgreExport RenderSystem
  106. {
  107. public:
  108. /** Default Constructor.
  109. */
  110. RenderSystem();
  111. /** Destructor.
  112. */
  113. virtual ~RenderSystem();
  114. /** Returns the name of the rendering system.
  115. */
  116. virtual const String& getName(void) const = 0;
  117. /** Sets an option for this API
  118. @remarks
  119. Used to confirm the settings (normally chosen by the user) in
  120. order to make the renderer able to initialise with the settings as required.
  121. This may be video mode, D3D driver, full screen / windowed etc.
  122. Called automatically by the default configuration
  123. dialog, and by the restoration of saved settings.
  124. These settings are stored and only activated when
  125. RenderSystem::initialise or RenderSystem::reinitialise
  126. are called.
  127. @par
  128. If using a custom configuration dialog, it is advised that the
  129. caller calls RenderSystem::getConfigOptions
  130. again, since some options can alter resulting from a selection.
  131. @param
  132. name The name of the option to alter.
  133. @param
  134. value The value to set the option to.
  135. */
  136. virtual void setConfigOption(const String &name, const String &value) = 0;
  137. /** Create an object for performing hardware occlusion queries.
  138. */
  139. virtual HardwareOcclusionQuery* createHardwareOcclusionQuery(void) = 0;
  140. /** Destroy a hardware occlusion query object.
  141. */
  142. virtual void destroyHardwareOcclusionQuery(HardwareOcclusionQuery *hq);
  143. /** Validates the options set for the rendering system, returning a message if there are problems.
  144. @note
  145. If the returned string is empty, there are no problems.
  146. */
  147. virtual String validateConfigOptions(void) = 0;
  148. /** Start up the renderer using the settings selected (Or the defaults if none have been selected).
  149. @remarks
  150. Called by Root::setRenderSystem. Shouldn't really be called
  151. directly, although this can be done if the app wants to.
  152. @param
  153. autoCreateWindow If true, creates a render window
  154. automatically, based on settings chosen so far. This saves
  155. an extra call to _createRenderWindow
  156. for the main render window.
  157. @par
  158. If an application has more specific window requirements,
  159. however (e.g. a level design app), it should specify false
  160. for this parameter and do it manually.
  161. @returns
  162. A pointer to the automatically created window, if requested, otherwise null.
  163. */
  164. virtual RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
  165. /** Query the real capabilities of the GPU and driver in the RenderSystem*/
  166. virtual RenderSystemCapabilities* createRenderSystemCapabilities() const = 0;
  167. /** Force the render system to use the special capabilities. Can only be called
  168. * before the render system has been fully initializer (before createWindow is called)
  169. * @param
  170. * capabilities has to be a subset of the real capabilities and the caller is
  171. * responsible for deallocating capabilities.
  172. */
  173. virtual void useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities);
  174. /** Restart the renderer (normally following a change in settings).
  175. */
  176. virtual void reinitialise(void) = 0;
  177. /** Shutdown the renderer and cleanup resources.
  178. */
  179. virtual void shutdown(void);
  180. /** Sets the colour & strength of the ambient (global directionless) light in the world.
  181. */
  182. virtual void setAmbientLight(float r, float g, float b) = 0;
  183. /** Sets the type of light shading required (default = Gouraud).
  184. */
  185. virtual void setShadingType(ShadeOptions so) = 0;
  186. /** Sets whether or not dynamic lighting is enabled.
  187. @param
  188. enabled If true, dynamic lighting is performed on geometry with normals supplied, geometry without
  189. normals will not be displayed. If false, no lighting is applied and all geometry will be full brightness.
  190. */
  191. virtual void setLightingEnabled(bool enabled) = 0;
  192. /** Sets whether or not W-buffers are enabled if they are available for this renderer.
  193. @param
  194. enabled If true and the renderer supports them W-buffers will be used. If false
  195. W-buffers will not be used even if available. W-buffers are enabled by default
  196. for 16bit depth buffers and disabled for all other depths.
  197. */
  198. void setWBufferEnabled(bool enabled);
  199. /** Returns true if the renderer will try to use W-buffers when avalible.
  200. */
  201. bool getWBufferEnabled(void) const;
  202. /** Creates a new rendering window.
  203. @remarks
  204. This method creates a new rendering window as specified
  205. by the paramteters. The rendering system could be
  206. responible for only a single window (e.g. in the case
  207. of a game), or could be in charge of multiple ones (in the
  208. case of a level editor). The option to create the window
  209. as a child of another is therefore given.
  210. This method will create an appropriate subclass of
  211. RenderWindow depending on the API and platform implementation.
  212. @par
  213. After creation, this window can be retrieved using getRenderTarget().
  214. @param
  215. name The name of the window. Used in other methods
  216. later like setRenderTarget and getRenderTarget.
  217. @param
  218. width The width of the new window.
  219. @param
  220. height The height of the new window.
  221. @param
  222. fullScreen Specify true to make the window full screen
  223. without borders, title bar or menu bar.
  224. @param
  225. miscParams A NameValuePairList describing the other parameters for the new rendering window.
  226. Options are case sensitive. Unrecognised parameters will be ignored silently.
  227. These values might be platform dependent, but these are present for all platforms unless
  228. indicated otherwise:
  229. <table>
  230. <tr>
  231. <td><b>Key</b></td>
  232. <td><b>Type/Values</b></td>
  233. <td><b>Default</b></td>
  234. <td><b>Description</b></td>
  235. <td><b>Notes</b></td>
  236. </tr>
  237. <tr>
  238. <td>title</td>
  239. <td>Any string</td>
  240. <td>RenderTarget name</td>
  241. <td>The title of the window that will appear in the title bar</td>
  242. <td>&nbsp;</td>
  243. </tr>
  244. <tr>
  245. <td>colourDepth</td>
  246. <td>16, 32</td>
  247. <td>Desktop depth</td>
  248. <td>Colour depth of the resulting rendering window; only applies if fullScreen</td>
  249. <td>Win32 Specific</td>
  250. </tr>
  251. <tr>
  252. <td>left</td>
  253. <td>Positive integers</td>
  254. <td>Centred</td>
  255. <td>Screen x coordinate from left</td>
  256. <td>&nbsp;</td>
  257. </tr>
  258. <tr>
  259. <td>top</td>
  260. <td>Positive integers</td>
  261. <td>Centred</td>
  262. <td>Screen y coordinate from left</td>
  263. <td>&nbsp;</td>
  264. </tr>
  265. <tr>
  266. <td>depthBuffer</td>
  267. <td>true, false</td>
  268. <td>true</td>
  269. <td>Use depth buffer</td>
  270. <td>DirectX9 specific</td>
  271. </tr>
  272. <tr>
  273. <td>externalWindowHandle</td>
  274. <td>Win32: HWND as integer<br/>
  275. GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)</td>
  276. <td>0 (none)</td>
  277. <td>External window handle, for embedding the OGRE render in an existing window</td>
  278. <td>&nbsp;</td>
  279. </tr>
  280. <tr>
  281. <td>externalGLControl</td>
  282. <td>true, false</td>
  283. <td>false</td>
  284. <td>Let the external window control OpenGL i.e. don't select a pixel format for the window,
  285. do not change v-sync and do not swap buffer. When set to true, the calling application
  286. is responsible of OpenGL initialization and buffer swapping. It should also create an
  287. OpenGL context for its own rendering, Ogre will create one for its use. Then the calling
  288. application must also enable Ogre OpenGL context before calling any Ogre function and
  289. restore its OpenGL context after these calls.</td>
  290. <td>OpenGL specific</td>
  291. </tr>
  292. <tr>
  293. <td>externalGLContext</td>
  294. <td>Context as Unsigned Long</td>
  295. <td>0 (create own context)</td>
  296. <td>Use an externally created GL context</td>
  297. <td>OpenGL Specific</td>
  298. </tr>
  299. <tr>
  300. <td>parentWindowHandle</td>
  301. <td>Win32: HWND as integer<br/>
  302. GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)</td>
  303. <td>0 (none)</td>
  304. <td>Parent window handle, for embedding the OGRE in a child of an external window</td>
  305. <td>&nbsp;</td>
  306. </tr>
  307. <tr>
  308. <td>macAPI</td>
  309. <td>String: "cocoa" or "carbon"</td>
  310. <td>"carbon"</td>
  311. <td>Specifies the type of rendering window on the Mac Platform.</td>
  312. <td>&nbsp;</td>
  313. </tr>
  314. <tr>
  315. <td>macAPICocoaUseNSView</td>
  316. <td>bool "true" or "false"</td>
  317. <td>"false"</td>
  318. <td>On the Mac platform the most diffused method to embed OGRE in a custom application is to use Interface Builder
  319. and add to the interface an instance of OgreView.
  320. The pointer to this instance is then used as "externalWindowHandle".
  321. However, there are cases where you are NOT using Interface Builder and you get the Cocoa NSView* of an existing interface.
  322. For example, this is happens when you want to render into a Java/AWT interface.
  323. In short, by setting this flag to "true" the Ogre::Root::createRenderWindow interprets the "externalWindowHandle" as a NSView*
  324. instead of an OgreView*. See OgreOSXCocoaView.h/mm.
  325. </td>
  326. <td>&nbsp;</td>
  327. </tr>
  328. <tr>
  329. <td>contentScalingFactor</td>
  330. <td>Positive Float greater than 1.0</td>
  331. <td>The default content scaling factor of the screen</td>
  332. <td>Specifies the CAEAGLLayer content scaling factor. Only supported on iOS 4 or greater.
  333. This can be useful to limit the resolution of the OpenGL ES backing store. For example, the iPhone 4's
  334. native resolution is 960 x 640. Windows are always 320 x 480, if you would like to limit the display
  335. to 720 x 480, specify 1.5 as the scaling factor.
  336. </td>
  337. <td>&nbsp;</td>
  338. </tr>
  339. <tr>
  340. <td>FSAA</td>
  341. <td>Positive integer (usually 0, 2, 4, 8, 16)</td>
  342. <td>0</td>
  343. <td>Full screen antialiasing factor</td>
  344. <td>&nbsp;</td>
  345. </tr>
  346. <tr>
  347. <td>FSAAHint</td>
  348. <td>Depends on RenderSystem and hardware. Currently supports:<br/>
  349. "Quality": on systems that have an option to prefer higher AA quality over speed, use it</td>
  350. <td>Blank</td>
  351. <td>Full screen antialiasing hint</td>
  352. <td>&nbsp;</td>
  353. </tr>
  354. <tr>
  355. <td>displayFrequency</td>
  356. <td>Refresh rate in Hertz (e.g. 60, 75, 100)</td>
  357. <td>Desktop vsync rate</td>
  358. <td>Display frequency rate, for fullscreen mode</td>
  359. <td>&nbsp;</td>
  360. </tr>
  361. <tr>
  362. <td>vsync</td>
  363. <td>true, false</td>
  364. <td>false</td>
  365. <td>Synchronize buffer swaps to monitor vsync, eliminating tearing at the expense of a fixed frame rate</td>
  366. <td>&nbsp;</td>
  367. </tr>
  368. <tr>
  369. <td>vsyncInterval</td>
  370. <td>1, 2, 3, 4</td>
  371. <td>1</td>
  372. <td>If vsync is enabled, the minimum number of vertical blanks that should occur between renders.
  373. For example if vsync is enabled, the refresh rate is 60 and this is set to 2, then the
  374. frame rate will be locked at 30.</td>
  375. <td>&nbsp;</td>
  376. </tr>
  377. <tr>
  378. <td>border</td>
  379. <td>none, fixed, resize</td>
  380. <td>resize</td>
  381. <td>The type of window border (in windowed mode)</td>
  382. <td>&nbsp;</td>
  383. </tr>
  384. <tr>
  385. <td>outerDimensions</td>
  386. <td>true, false</td>
  387. <td>false</td>
  388. <td>Whether the width/height is expressed as the size of the
  389. outer window, rather than the content area</td>
  390. <td>&nbsp;</td>
  391. </tr>
  392. <tr>
  393. <td>useNVPerfHUD</td>
  394. <td>true, false</td>
  395. <td>false</td>
  396. <td>Enable the use of nVidia NVPerfHUD</td>
  397. <td>&nbsp;</td>
  398. </tr>
  399. <tr>
  400. <td>gamma</td>
  401. <td>true, false</td>
  402. <td>false</td>
  403. <td>Enable hardware conversion from linear colour space to gamma
  404. colour space on rendering to the window.</td>
  405. <td>&nbsp;</td>
  406. </tr>
  407. */
  408. virtual RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
  409. bool fullScreen, const NameValuePairList *miscParams = 0) = 0;
  410. /** Creates multiple rendering windows.
  411. @param
  412. renderWindowDescriptions Array of structures containing the descriptions of each render window.
  413. The structure's members are the same as the parameters of _createRenderWindow:
  414. * name
  415. * width
  416. * height
  417. * fullScreen
  418. * miscParams
  419. See _createRenderWindow for details about each member.
  420. @param
  421. createdWindows This array will hold the created render windows.
  422. @returns
  423. true on success.
  424. */
  425. virtual bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
  426. RenderWindowList& createdWindows);
  427. /** Create a MultiRenderTarget, which is a render target that renders to multiple RenderTextures
  428. at once. Surfaces can be bound and unbound at will.
  429. This fails if mCapabilities->getNumMultiRenderTargets() is smaller than 2.
  430. */
  431. virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0;
  432. /** Destroys a render window */
  433. virtual void destroyRenderWindow(const String& name);
  434. /** Destroys a render texture */
  435. virtual void destroyRenderTexture(const String& name);
  436. /** Destroys a render target of any sort */
  437. virtual void destroyRenderTarget(const String& name);
  438. /** Attaches the passed render target to the render system.
  439. */
  440. virtual void attachRenderTarget( RenderTarget &target );
  441. /** Returns a pointer to the render target with the passed name, or NULL if that
  442. render target cannot be found.
  443. */
  444. virtual RenderTarget * getRenderTarget( const String &name );
  445. /** Detaches the render target with the passed name from the render system and
  446. returns a pointer to it.
  447. @note
  448. If the render target cannot be found, NULL is returned.
  449. */
  450. virtual RenderTarget * detachRenderTarget( const String &name );
  451. /// Iterator over RenderTargets
  452. typedef Ogre::RenderTargetMap::iterator RenderTargetIterator;
  453. /** Returns a specialised MapIterator over all render targets attached to the RenderSystem. */
  454. virtual RenderTargetIterator getRenderTargetIterator(void) {
  455. return mRenderTargets.begin();
  456. }
  457. /** Returns a description of an error code.
  458. */
  459. virtual String getErrorDescription(long errorNumber) const = 0;
  460. /** Defines whether or now fullscreen render windows wait for the vertical blank before flipping buffers.
  461. @remarks
  462. By default, all rendering windows wait for a vertical blank (when the CRT beam turns off briefly to move
  463. from the bottom right of the screen back to the top left) before flipping the screen buffers. This ensures
  464. that the image you see on the screen is steady. However it restricts the frame rate to the refresh rate of
  465. the monitor, and can slow the frame rate down. You can speed this up by not waiting for the blank, but
  466. this has the downside of introducing 'tearing' artefacts where part of the previous frame is still displayed
  467. as the buffers are switched. Speed vs quality, you choose.
  468. @note
  469. Has NO effect on windowed mode render targets. Only affects fullscreen mode.
  470. @param
  471. enabled If true, the system waits for vertical blanks - quality over speed. If false it doesn't - speed over quality.
  472. */
  473. void setWaitForVerticalBlank(bool enabled);
  474. /** Returns true if the system is synchronising frames with the monitor vertical blank.
  475. */
  476. bool getWaitForVerticalBlank(void) const;
  477. // ------------------------------------------------------------------------
  478. // Internal Rendering Access
  479. // All methods below here are normally only called by other OGRE classes
  480. // They can be called by library user if required
  481. // ------------------------------------------------------------------------
  482. /** Tells the rendersystem to use the attached set of lights (and no others)
  483. up to the number specified (this allows the same list to be used with different
  484. count limits) */
  485. virtual void _useLights(const LightList& lights, unsigned short limit) = 0;
  486. /** Are fixed-function lights provided in view space? Affects optimisation.
  487. */
  488. virtual bool areFixedFunctionLightsInViewSpace() const { return false; }
  489. /** Sets the world transform matrix. */
  490. virtual void _setWorldMatrix(const Matrix4 &m) = 0;
  491. /** Sets multiple world matrices (vertex blending). */
  492. virtual void _setWorldMatrices(const Matrix4* m, unsigned short count);
  493. /** Sets the view transform matrix */
  494. virtual void _setViewMatrix(const Matrix4 &m) = 0;
  495. /** Sets the projection transform matrix */
  496. virtual void _setProjectionMatrix(const Matrix4 &m) = 0;
  497. /** Utility function for setting all the properties of a texture unit at once.
  498. This method is also worth using over the individual texture unit settings because it
  499. only sets those settings which are different from the current settings for this
  500. unit, thus minimising render state changes.
  501. */
  502. virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl);
  503. /** Turns off a texture unit. */
  504. virtual void _disableTextureUnit(size_t texUnit);
  505. /** Disables all texture units from the given unit upwards */
  506. virtual void _disableTextureUnitsFrom(size_t texUnit);
  507. /** Sets the surface properties to be used for future rendering.
  508. This method sets the the properties of the surfaces of objects
  509. to be rendered after it. In this context these surface properties
  510. are the amount of each type of light the object reflects (determining
  511. it's colour under different types of light), whether it emits light
  512. itself, and how shiny it is. Textures are not dealt with here,
  513. see the _setTetxure method for details.
  514. This method is used by _setMaterial so does not need to be called
  515. direct if that method is being used.
  516. @param ambient The amount of ambient (sourceless and directionless)
  517. light an object reflects. Affected by the colour/amount of ambient light in the scene.
  518. @param diffuse The amount of light from directed sources that is
  519. reflected (affected by colour/amount of point, directed and spot light sources)
  520. @param specular The amount of specular light reflected. This is also
  521. affected by directed light sources but represents the colour at the
  522. highlights of the object.
  523. @param emissive The colour of light emitted from the object. Note that
  524. this will make an object seem brighter and not dependent on lights in
  525. the scene, but it will not act as a light, so will not illuminate other
  526. objects. Use a light attached to the same SceneNode as the object for this purpose.
  527. @param shininess A value which only has an effect on specular highlights (so
  528. specular must be non-black). The higher this value, the smaller and crisper the
  529. specular highlights will be, imitating a more highly polished surface.
  530. This value is not constrained to 0.0-1.0, in fact it is likely to
  531. be more (10.0 gives a modest sheen to an object).
  532. @param tracking A bit field that describes which of the ambient, diffuse, specular
  533. and emissive colours follow the vertex colour of the primitive. When a bit in this field is set
  534. its ColourValue is ignored. This is a combination of TVC_AMBIENT, TVC_DIFFUSE, TVC_SPECULAR(note that the shininess value is still
  535. taken from shininess) and TVC_EMISSIVE. TVC_NONE means that there will be no material property
  536. tracking the vertex colours.
  537. */
  538. virtual void _setSurfaceParams(const ColourValue &ambient,
  539. const ColourValue &diffuse, const ColourValue &specular,
  540. const ColourValue &emissive, Real shininess,
  541. TrackVertexColourType tracking = TVC_NONE) = 0;
  542. /** Sets whether or not rendering points using OT_POINT_LIST will
  543. render point sprites (textured quads) or plain points.
  544. @param enabled True enables point sprites, false returns to normal
  545. point rendering.
  546. */
  547. virtual void _setPointSpritesEnabled(bool enabled) = 0;
  548. /** Sets the size of points and how they are attenuated with distance.
  549. @remarks
  550. When performing point rendering or point sprite rendering,
  551. point size can be attenuated with distance. The equation for
  552. doing this is attenuation = 1 / (constant + linear * dist + quadratic * d^2) .
  553. @par
  554. For example, to disable distance attenuation (constant screensize)
  555. you would set constant to 1, and linear and quadratic to 0. A
  556. standard perspective attenuation would be 0, 1, 0 respectively.
  557. */
  558. virtual void _setPointParameters(Real size, bool attenuationEnabled,
  559. Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) = 0;
  560. /**
  561. Sets the texture to bind to a given texture unit.
  562. User processes would not normally call this direct unless rendering
  563. primitives themselves.
  564. @param unit The index of the texture unit to modify. Multitexturing
  565. hardware can support multiple units (see
  566. RenderSystemCapabilites::getNumTextureUnits)
  567. @param enabled Boolean to turn the unit on/off
  568. @param texPtr Pointer to the texture to use.
  569. */
  570. virtual void _setTexture(size_t unit, bool enabled,
  571. const TexturePtr &texPtr) = 0;
  572. /** Binds a texture to a vertex sampler.
  573. @remarks
  574. Not all rendersystems support separate vertex samplers. For those that
  575. do, you can set a texture for them, separate to the regular texture
  576. samplers, using this method. For those that don't, you should use the
  577. regular texture samplers which are shared between the vertex and
  578. fragment units; calling this method will throw an exception.
  579. @see RenderSystemCapabilites::getVertexTextureUnitsShared
  580. */
  581. virtual void _setVertexTexture(size_t unit, const TexturePtr& tex);
  582. /**
  583. Sets the texture coordinate set to use for a texture unit.
  584. Meant for use internally - not generally used directly by apps - the Material and TextureUnitState
  585. classes let you manage textures far more easily.
  586. @param unit Texture unit as above
  587. @param index The index of the texture coordinate set to use.
  588. */
  589. virtual void _setTextureCoordSet(size_t unit, size_t index) = 0;
  590. /**
  591. Sets a method for automatically calculating texture coordinates for a stage.
  592. Should not be used by apps - for use by Ogre only.
  593. @param unit Texture unit as above
  594. @param m Calculation method to use
  595. @param frustum Optional Frustum param, only used for projective effects
  596. */
  597. virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
  598. const Frustum* frustum = 0) = 0;
  599. /** Sets the texture blend modes from a TextureUnitState record.
  600. Meant for use internally only - apps should use the Material
  601. and TextureUnitState classes.
  602. @param unit Texture unit as above
  603. @param bm Details of the blending mode
  604. */
  605. virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) = 0;
  606. /** Sets the filtering options for a given texture unit.
  607. @param unit The texture unit to set the filtering options for
  608. @param minFilter The filter used when a texture is reduced in size
  609. @param magFilter The filter used when a texture is magnified
  610. @param mipFilter The filter used between mipmap levels, FO_NONE disables mipmapping
  611. */
  612. virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
  613. FilterOptions magFilter, FilterOptions mipFilter);
  614. /** Sets a single filter for a given texture unit.
  615. @param unit The texture unit to set the filtering options for
  616. @param ftype The filter type
  617. @param filter The filter to be used
  618. */
  619. virtual void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0;
  620. /** Sets the maximal anisotropy for the specified texture unit.*/
  621. virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
  622. /** Sets the texture addressing mode for a texture unit.*/
  623. virtual void _setTextureAddressingMode(size_t unit, const TextureUnitState::UVWAddressingMode& uvw) = 0;
  624. /** Sets the texture border colour for a texture unit.*/
  625. virtual void _setTextureBorderColour(size_t unit, const ColourValue& colour) = 0;
  626. /** Sets the mipmap bias value for a given texture unit.
  627. @remarks
  628. This allows you to adjust the mipmap calculation up or down for a
  629. given texture unit. Negative values force a larger mipmap to be used,
  630. positive values force a smaller mipmap to be used. Units are in numbers
  631. of levels, so +1 forces the mipmaps to one smaller level.
  632. @note Only does something if render system has capability RSC_MIPMAP_LOD_BIAS.
  633. */
  634. virtual void _setTextureMipmapBias(size_t unit, float bias) = 0;
  635. /** Sets the texture coordinate transformation matrix for a texture unit.
  636. @param unit Texture unit to affect
  637. @param xform The 4x4 matrix
  638. */
  639. virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) = 0;
  640. /** Sets the global blending factors for combining subsequent renders with the existing frame contents.
  641. The result of the blending operation is:</p>
  642. <p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
  643. Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
  644. enumerated type.
  645. By changing the operation you can change addition between the source and destination pixels to a different operator.
  646. @param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
  647. @param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
  648. @param op The blend operation mode for combining pixels
  649. */
  650. virtual void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD) = 0;
  651. /** Sets the global blending factors for combining subsequent renders with the existing frame contents.
  652. The result of the blending operation is:</p>
  653. <p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
  654. Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
  655. enumerated type.
  656. @param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
  657. @param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
  658. @param sourceFactorAlpha The source factor in the above calculation for the alpha channel, i.e. multiplied by the texture alpha components.
  659. @param destFactorAlpha The destination factor in the above calculation for the alpha channel, i.e. multiplied by the pixel alpha components.
  660. @param op The blend operation mode for combining pixels
  661. @param alphaOp The blend operation mode for combining pixel alpha values
  662. */
  663. virtual void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha,
  664. SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD) = 0;
  665. /** Sets the global alpha rejection approach for future renders.
  666. By default images are rendered regardless of texture alpha. This method lets you change that.
  667. @param func The comparison function which must pass for a pixel to be written.
  668. @param val The value to compare each pixels alpha value to (0-255)
  669. @param alphaToCoverage Whether to enable alpha to coverage, if supported
  670. */
  671. virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
  672. /** Notify the rendersystem that it should adjust texture projection to be
  673. relative to a different origin.
  674. */
  675. virtual void _setTextureProjectionRelativeTo(bool enabled, const Vector3& pos);
  676. /**
  677. * Signifies the beginning of a frame, i.e. the start of rendering on a single viewport. Will occur
  678. * several times per complete frame if multiple viewports exist.
  679. */
  680. virtual void _beginFrame(void) = 0;
  681. //Dummy structure for render system contexts - implementing RenderSystems can extend
  682. //as needed
  683. struct RenderSystemContext { };
  684. /**
  685. * Pause rendering for a frame. This has to be called after _beginFrame and before _endFrame.
  686. * Will usually be called by the SceneManager, don't use this manually unless you know what
  687. * you are doing.
  688. */
  689. virtual RenderSystemContext* _pauseFrame(void);
  690. /**
  691. * Resume rendering for a frame. This has to be called after a _pauseFrame call
  692. * Will usually be called by the SceneManager, don't use this manually unless you know what
  693. * you are doing.
  694. * @param context the render system context, as returned by _pauseFrame
  695. */
  696. virtual void _resumeFrame(RenderSystemContext* context);
  697. /**
  698. * Ends rendering of a frame to the current viewport.
  699. */
  700. virtual void _endFrame(void) = 0;
  701. /**
  702. Sets the provided viewport as the active one for future
  703. rendering operations. This viewport is aware of it's own
  704. camera and render target. Must be implemented by subclass.
  705. @param target Pointer to the appropriate viewport.
  706. */
  707. virtual void _setViewport(Viewport *vp) = 0;
  708. /** Get the current active viewport for rendering. */
  709. virtual Viewport* _getViewport(void);
  710. /** Sets the culling mode for the render system based on the 'vertex winding'.
  711. A typical way for the rendering engine to cull triangles is based on the
  712. 'vertex winding' of triangles. Vertex winding refers to the direction in
  713. which the vertices are passed or indexed to in the rendering operation as viewed
  714. from the camera, and will wither be clockwise or anticlockwise (that's 'counterclockwise' for
  715. you Americans out there ;) The default is CULL_CLOCKWISE i.e. that only triangles whose vertices
  716. are passed/indexed in anticlockwise order are rendered - this is a common approach and is used in 3D studio models
  717. for example. You can alter this culling mode if you wish but it is not advised unless you know what you are doing.
  718. You may wish to use the CULL_NONE option for mesh data that you cull yourself where the vertex
  719. winding is uncertain.
  720. */
  721. virtual void _setCullingMode(CullingMode mode) = 0;
  722. virtual CullingMode _getCullingMode(void) const;
  723. /** Sets the mode of operation for depth buffer tests from this point onwards.
  724. Sometimes you may wish to alter the behaviour of the depth buffer to achieve
  725. special effects. Because it's unlikely that you'll set these options for an entire frame,
  726. but rather use them to tweak settings between rendering objects, this is an internal
  727. method (indicated by the '_' prefix) which will be used by a SceneManager implementation
  728. rather than directly from the client application.
  729. If this method is never called the settings are automatically the same as the default parameters.
  730. @param depthTest If true, the depth buffer is tested for each pixel and the frame buffer is only updated
  731. if the depth function test succeeds. If false, no test is performed and pixels are always written.
  732. @param depthWrite If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
  733. If false, the depth buffer is left unchanged even if a new pixel is written.
  734. @param depthFunction Sets the function required for the depth test.
  735. */
  736. virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
  737. /** Sets whether or not the depth buffer check is performed before a pixel write.
  738. @param enabled If true, the depth buffer is tested for each pixel and the frame buffer is only updated
  739. if the depth function test succeeds. If false, no test is performed and pixels are always written.
  740. */
  741. virtual void _setDepthBufferCheckEnabled(bool enabled = true) = 0;
  742. /** Sets whether or not the depth buffer is updated after a pixel write.
  743. @param enabled If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
  744. If false, the depth buffer is left unchanged even if a new pixel is written.
  745. */
  746. virtual void _setDepthBufferWriteEnabled(bool enabled = true) = 0;
  747. /** Sets the comparison function for the depth buffer check.
  748. Advanced use only - allows you to choose the function applied to compare the depth values of
  749. new and existing pixels in the depth buffer. Only an issue if the deoth buffer check is enabled
  750. (see _setDepthBufferCheckEnabled)
  751. @param func The comparison between the new depth and the existing depth which must return true
  752. for the new pixel to be written.
  753. */
  754. virtual void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
  755. /** Sets whether or not colour buffer writing is enabled, and for which channels.
  756. @remarks
  757. For some advanced effects, you may wish to turn off the writing of certain colour
  758. channels, or even all of the colour channels so that only the depth buffer is updated
  759. in a rendering pass. However, the chances are that you really want to use this option
  760. through the Material class.
  761. @param red, green, blue, alpha Whether writing is enabled for each of the 4 colour channels. */
  762. virtual void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
  763. /** Sets the depth bias, NB you should use the Material version of this.
  764. @remarks
  765. When polygons are coplanar, you can get problems with 'depth fighting' where
  766. the pixels from the two polys compete for the same screen pixel. This is particularly
  767. a problem for decals (polys attached to another surface to represent details such as
  768. bulletholes etc.).
  769. @par
  770. A way to combat this problem is to use a depth bias to adjust the depth buffer value
  771. used for the decal such that it is slightly higher than the true value, ensuring that
  772. the decal appears on top.
  773. @note
  774. The final bias value is a combination of a constant bias and a bias proportional
  775. to the maximum depth slope of the polygon being rendered. The final bias
  776. is constantBias + slopeScaleBias * maxslope. Slope scale biasing is
  777. generally preferable but is not available on older hardware.
  778. @param constantBias The constant bias value, expressed as a value in
  779. homogeneous depth coordinates.
  780. @param slopeScaleBias The bias value which is factored by the maximum slope
  781. of the polygon, see the description above. This is not supported by all
  782. cards.
  783. */
  784. virtual void _setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0;
  785. /** Sets the fogging mode for future geometry.
  786. @param mode Set up the mode of fog as described in the FogMode enum, or set to FOG_NONE to turn off.
  787. @param colour The colour of the fog. Either set this to the same as your viewport background colour,
  788. or to blend in with a skydome or skybox.
  789. @param expDensity The density of the fog in FOG_EXP or FOG_EXP2 mode, as a value between 0 and 1. The default is 1. i.e. completely opaque, lower values can mean
  790. that fog never completely obscures the scene.
  791. @param linearStart Distance at which linear fog starts to encroach. The distance must be passed
  792. as a parametric value between 0 and 1, with 0 being the near clipping plane, and 1 being the far clipping plane. Only applicable if mode is FOG_LINEAR.
  793. @param linearEnd Distance at which linear fog becomes completely opaque.The distance must be passed
  794. as a parametric value between 0 and 1, with 0 being the near clipping plane, and 1 being the far clipping plane. Only applicable if mode is FOG_LINEAR.
  795. */
  796. virtual void _setFog(FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0) = 0;
  797. /** The RenderSystem will keep a count of tris rendered, this resets the count. */
  798. virtual void _beginGeometryCount(void);
  799. /** Reports the number of tris rendered since the last _beginGeometryCount call. */
  800. virtual unsigned int _getFaceCount(void) const;
  801. /** Reports the number of batches rendered since the last _beginGeometryCount call. */
  802. virtual unsigned int _getBatchCount(void) const;
  803. /** Reports the number of vertices passed to the renderer since the last _beginGeometryCount call. */
  804. virtual unsigned int _getVertexCount(void) const;
  805. /** Generates a packed data version of the passed in ColourValue suitable for
  806. use as with this RenderSystem.
  807. @remarks
  808. Since different render systems have different colour data formats (eg
  809. RGBA for GL, ARGB for D3D) this method allows you to use 1 method for all.
  810. @param colour The colour to convert
  811. @param pDest Pointer to location to put the result.
  812. */
  813. virtual void convertColourValue(const ColourValue& colour, uint32* pDest);
  814. /** Get the native VertexElementType for a compact 32-bit colour value
  815. for this rendersystem.
  816. */
  817. virtual VertexElementType getColourVertexElementType(void) const = 0;
  818. /** Converts a uniform projection matrix to suitable for this render system.
  819. @remarks
  820. Because different APIs have different requirements (some incompatible) for the
  821. projection matrix, this method allows each to implement their own correctly and pass
  822. back a generic OGRE matrix for storage in the engine.
  823. */
  824. virtual void _convertProjectionMatrix(const Matrix4& matrix,
  825. Matrix4& dest, bool forGpuProgram = false) = 0;
  826. /** Builds a perspective projection matrix suitable for this render system.
  827. @remarks
  828. Because different APIs have different requirements (some incompatible) for the
  829. projection matrix, this method allows each to implement their own correctly and pass
  830. back a generic OGRE matrix for storage in the engine.
  831. */
  832. virtual void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
  833. Matrix4& dest, bool forGpuProgram = false) = 0;
  834. /** Builds a perspective projection matrix for the case when frustum is
  835. not centered around camera.
  836. @remarks
  837. Viewport coordinates are in camera coordinate frame, i.e. camera is
  838. at the origin.
  839. */
  840. virtual void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
  841. Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false) = 0;
  842. /** Builds an orthographic projection matrix suitable for this render system.
  843. @remarks
  844. Because different APIs have different requirements (some incompatible) for the
  845. projection matrix, this method allows each to implement their own correctly and pass
  846. back a generic OGRE matrix for storage in the engine.
  847. */
  848. virtual void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
  849. Matrix4& dest, bool forGpuProgram = false) = 0;
  850. /** Update a perspective projection matrix to use 'oblique depth projection'.
  851. @remarks
  852. This method can be used to change the nature of a perspective
  853. transform in order to make the near plane not perpendicular to the
  854. camera view direction, but to be at some different orientation.
  855. This can be useful for performing arbitrary clipping (e.g. to a
  856. reflection plane) which could otherwise only be done using user
  857. clip planes, which are more expensive, and not necessarily supported
  858. on all cards.
  859. @param matrix The existing projection matrix. Note that this must be a
  860. perspective transform (not orthographic), and must not have already
  861. been altered by this method. The matrix will be altered in-place.
  862. @param plane The plane which is to be used as the clipping plane. This
  863. plane must be in CAMERA (view) space.
  864. @param forGpuProgram Is this for use with a Gpu program or fixed-function
  865. */
  866. virtual void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
  867. bool forGpuProgram) = 0;
  868. /** Sets how to rasterise triangles, as points, wireframe or solid polys. */
  869. virtual void _setPolygonMode(PolygonMode level) = 0;
  870. /** Turns stencil buffer checking on or off.
  871. @remarks
  872. Stencilling (masking off areas of the rendering target based on the stencil
  873. buffer) can be turned on or off using this method. By default, stencilling is
  874. disabled.
  875. */
  876. virtual void setStencilCheckEnabled(bool enabled) = 0;
  877. /** Determines if this system supports hardware accelerated stencil buffer.
  878. @remarks
  879. Note that the lack of this function doesn't mean you can't do stencilling, but
  880. the stencilling operations will be provided in software, which will NOT be
  881. fast.
  882. @par
  883. Generally hardware stencils are only supported in 32-bit colour modes, because
  884. the stencil buffer shares the memory of the z-buffer, and in most cards the
  885. z-buffer has to be the same depth as the colour buffer. This means that in 32-bit
  886. mode, 24 bits of the z-buffer are depth and 8 bits are stencil. In 16-bit mode there
  887. is no room for a stencil (although some cards support a 15:1 depth:stencil option,
  888. this isn't useful for very much) so 8 bits of stencil are provided in software.
  889. This can mean that if you use stencilling, your applications may be faster in
  890. 32-but colour than in 16-bit, which may seem odd to some people.
  891. */
  892. /*virtual bool hasHardwareStencil(void) = 0;*/
  893. /** This method allows you to set all the stencil buffer parameters in one call.
  894. @remarks
  895. The stencil buffer is used to mask out pixels in the render target, allowing
  896. you to do effects like mirrors, cut-outs, stencil shadows and more. Each of
  897. your batches of rendering is likely to ignore the stencil buffer,
  898. update it with new values, or apply it to mask the output of the render.
  899. The stencil test is:<PRE>
  900. (Reference Value & Mask) CompareFunction (Stencil Buffer Value & Mask)</PRE>
  901. The result of this will cause one of 3 actions depending on whether the test fails,
  902. succeeds but with the depth buffer check still failing, or succeeds with the
  903. depth buffer check passing too.
  904. @par
  905. Unlike other render states, stencilling is left for the application to turn
  906. on and off when it requires. This is because you are likely to want to change
  907. parameters between batches of arbitrary objects and control the ordering yourself.
  908. In order to batch things this way, you'll want to use OGRE's separate render queue
  909. groups (see RenderQueue) and register a RenderQueueListener to get notifications
  910. between batches.
  911. @par
  912. There are individual state change methods for each of the parameters set using
  913. this method.
  914. Note that the default values in this method represent the defaults at system
  915. start up too.
  916. @param func The comparison function applied.
  917. @param refValue The reference value used in the comparison
  918. @param mask The bitmask applied to both the stencil value and the reference value
  919. before comparison
  920. @param stencilFailOp The action to perform when the stencil check fails
  921. @param depthFailOp The action to perform when the stencil check passes, but the
  922. depth buffer check still fails
  923. @param passOp The action to take when both the stencil and depth check pass.
  924. @param twoSidedOperation If set to true, then if you render both back and front faces
  925. (you'll have to turn off culling) then these parameters will apply for front faces,
  926. and the inverse of them will happen for back faces (keep remains the same).
  927. */
  928. virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
  929. uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
  930. StencilOperation stencilFailOp = SOP_KEEP,
  931. StencilOperation depthFailOp = SOP_KEEP,
  932. StencilOperation passOp = SOP_KEEP,
  933. bool twoSidedOperation = false) = 0;
  934. /** Sets the current vertex declaration, ie the source of vertex data. */
  935. virtual void setVertexDeclaration(VertexDeclaration* decl) = 0;
  936. /** Sets the current vertex buffer binding state. */
  937. virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
  938. /** Sets whether or not normals are to be automatically normalised.
  939. @remarks
  940. This is useful when, for example, you are scaling SceneNodes such that
  941. normals may not be unit-length anymore. Note though that this has an
  942. overhead so should not be turn on unless you really need it.
  943. @par
  944. You should not normally call this direct unless you are rendering
  945. world geometry; set it on the Renderable because otherwise it will be
  946. overridden by material settings.
  947. */
  948. virtual void setNormaliseNormals(bool normalise) = 0;
  949. /**
  950. Render something to the active viewport.
  951. Low-level rendering interface to perform rendering
  952. operations. Unlikely to be used directly by client
  953. applications, since the SceneManager and various support
  954. classes will be responsible for calling this method.
  955. Can only be called between _beginScene and _endScene
  956. @param op A rendering operation instance, which contains
  957. details of the operation to be performed.
  958. */
  959. virtual void _render(const RenderOperation& op);
  960. /** Gets the capabilities of the render system. */
  961. const RenderSystemCapabilities* getCapabilities(void) const { return mCurrentCapabilities; }
  962. /** Returns the driver version.
  963. */
  964. virtual const DriverVersion& getDriverVersion(void) const { return mDriverVersion; }
  965. /** Binds a given GpuProgram (but not the parameters).
  966. @remarks Only one GpuProgram of each type can be bound at once, binding another
  967. one will simply replace the existing one.
  968. */
  969. virtual void bindGpuProgram(GpuProgram* prg);
  970. /** Bind Gpu program parameters.
  971. @param gptype The type of program to bind the parameters to
  972. @param params The parameters to bind
  973. @param variabilityMask A mask of GpuParamVariability identifying which params need binding
  974. */
  975. virtual void bindGpuProgramParameters(GpuProgramType gptype,
  976. GpuProgramParametersSharedPtr params, uint16 variabilityMask) = 0;
  977. /** Only binds Gpu program parameters used for passes that have more than one iteration rendering
  978. */
  979. virtual void bindGpuProgramPassIterationParameters(GpuProgramType gptype) = 0;
  980. /** Unbinds GpuPrograms of a given GpuProgramType.
  981. @remarks
  982. This returns the pipeline to fixed-function processing for this type.
  983. */
  984. virtual void unbindGpuProgram(GpuProgramType gptype);
  985. /** Returns whether or not a Gpu program of the given type is currently bound. */
  986. virtual bool isGpuProgramBound(GpuProgramType gptype);
  987. /** Sets the user clipping region.
  988. */
  989. virtual void setClipPlanes(const PlaneList& clipPlanes);
  990. /** Add a user clipping plane. */
  991. virtual void addClipPlane (const Plane &p);
  992. /** Add a user clipping plane. */
  993. virtual void addClipPlane (Real A, Real B, Real C, Real D);
  994. /** Clears the user clipping region.
  995. */
  996. virtual void resetClipPlanes();
  997. /** Utility method for initialising all render targets attached to this rendering system. */
  998. virtual void _initRenderTargets(void);
  999. /** Utility method to notify all render targets that a camera has been removed,
  1000. in case they were referring to it as their viewer.
  1001. */
  1002. virtual void _notifyCameraRemoved(const Camera* cam);
  1003. /** Internal method for updating all render targets attached to this rendering system. */
  1004. virtual void _updateAllRenderTargets(bool swapBuffers = true);
  1005. /** Internal method for swapping all the buffers on all render targets,
  1006. if _updateAllRenderTargets was called with a 'false' parameter. */
  1007. virtual void _swapAllRenderTargetBuffers(bool waitForVsync = true);
  1008. /** Sets whether or not vertex windings set should be inverted; this can be important
  1009. for rendering reflections. */
  1010. virtual void setInvertVertexWinding(bool invert);
  1011. /** Indicates whether or not the vertex windings set will be inverted for the current render (e.g. reflections)
  1012. @see RenderSystem::setInvertVertexWinding
  1013. */
  1014. virtual bool getInvertVertexWinding(void) const;
  1015. /** Sets the 'scissor region' ie the region of the target in which rendering can take place.
  1016. @remarks
  1017. This method allows you to 'mask off' rendering in all but a given rectangular area
  1018. as identified by the parameters to this method.
  1019. @note
  1020. Not all systems support this method. Check the RenderSystemCapabilities for the
  1021. RSC_SCISSOR_TEST capability to see if it is supported.
  1022. @param enabled True to enable the scissor test, false to disable it.
  1023. @param left, top, right, bottom The location of the corners of the rectangle, expressed in
  1024. <i>pixels</i>.
  1025. */
  1026. virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0,
  1027. size_t right = 800, size_t bottom = 600) = 0;
  1028. /** Clears one or more frame buffers on the active render target.
  1029. @param buffers Combination of one or more elements of FrameBufferType
  1030. denoting which buffers are to be cleared
  1031. @param colour The colour to clear the colour buffer with, if enabled
  1032. @param depth The value to initialise the depth buffer with, if enabled
  1033. @param stencil The value to initialise the stencil buffer with, if enabled.
  1034. */
  1035. virtual void clearFrameBuffer(unsigned int buffers,
  1036. const ColourValue& colour = ColourValue::Black,
  1037. Real depth = 1.0f, unsigned short stencil = 0) = 0;
  1038. /** Returns the horizontal texel offset value required for mapping
  1039. texel origins to pixel origins in this rendersystem.
  1040. @remarks
  1041. Since rendersystems sometimes disagree on the origin of a texel,
  1042. mapping from texels to pixels can sometimes be problematic to
  1043. implement generically. This method allows you to retrieve the offset
  1044. required to map the origin of a texel to the origin of a pixel in
  1045. the horizontal direction.
  1046. */
  1047. virtual Real getHorizontalTexelOffset(void) = 0;
  1048. /** Returns the vertical texel offset value required for mapping
  1049. texel origins to pixel origins in this rendersystem.
  1050. @remarks
  1051. Since rendersystems sometimes disagree on the origin of a texel,
  1052. mapping from texels to pixels can sometimes be problematic to
  1053. implement generically. This method allows you to retrieve the offset
  1054. required to map the origin of a texel to the origin of a pixel in
  1055. the vertical direction.
  1056. */
  1057. virtual Real getVerticalTexelOffset(void) = 0;
  1058. /** Gets the minimum (closest) depth value to be used when rendering
  1059. using identity transforms.
  1060. @remarks
  1061. When using identity transforms you can manually set the depth
  1062. of a vertex; however the input values required differ per
  1063. rendersystem. This method lets you retrieve the correct value.
  1064. @see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
  1065. */
  1066. virtual Real getMinimumDepthInputValue(void) = 0;
  1067. /** Gets the maximum (farthest) depth value to be used when rendering
  1068. using identity transforms.
  1069. @remarks
  1070. When using identity transforms you can manually set the depth
  1071. of a vertex; however the input values required differ per
  1072. rendersystem. This method lets you retrieve the correct value.
  1073. @see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
  1074. */
  1075. virtual Real getMaximumDepthInputValue(void) = 0;
  1076. /** set the current multi pass count value. This must be set prior to
  1077. calling _render() if multiple renderings of the same pass state are
  1078. required.
  1079. @param count Number of times to render the current state.
  1080. */
  1081. virtual void setCurrentPassIterationCount(const size_t count) { mCurrentPassIterationCount = count; }
  1082. /** Tell the render system whether to derive a depth bias on its own based on
  1083. the values passed to it in setCurrentPassIterationCount.
  1084. The depth bias set will be baseValue + iteration * multiplier
  1085. @param derive True to tell the RS to derive this automatically
  1086. @param baseValue The base value to which the multiplier should be
  1087. added
  1088. @param multiplier The amount of depth bias to apply per iteration
  1089. @param slopeScale The constant slope scale bias for completeness
  1090. */
  1091. virtual void setDeriveDepthBias(bool derive, float baseValue = 0.0f,
  1092. float multiplier = 0.0f, float slopeScale = 0.0f)
  1093. {
  1094. mDerivedDepthBias = derive;
  1095. mDerivedDepthBiasBase = baseValue;
  1096. mDerivedDepthBiasMultiplier = multiplier;
  1097. mDerivedDepthBiasSlopeScale = slopeScale;
  1098. }
  1099. /**
  1100. * Set current render target to target, enabling its device context if needed
  1101. */
  1102. virtual void _setRenderTarget(RenderTarget *target) = 0;
  1103. /** Defines a listener on the custom events that this render system
  1104. can raise.
  1105. @see RenderSystem::addListener
  1106. */
  1107. class _OgreExport Listener
  1108. {
  1109. public:
  1110. Listener() {}
  1111. virtual ~Listener() {}
  1112. /** A rendersystem-specific event occurred.
  1113. @param eventName The name of the event which has occurred
  1114. @param parameters A list of parameters that may belong to this event,
  1115. may be null if there are no parameters
  1116. */
  1117. virtual void eventOccurred(const String& eventName,
  1118. const NameValuePairList* parameters = 0) = 0;
  1119. };
  1120. /** Adds a listener to the custom events that this render system can raise.
  1121. @remarks
  1122. Some render systems have quite specific, internally generated events
  1123. that the application may wish to be notified of. Many applications
  1124. don't have to worry about these events, and can just trust OGRE to
  1125. handle them, but if you want to know, you can add a listener here.
  1126. @par
  1127. Events are raised very generically by string name. Perhaps the most
  1128. common example of a render system specific event is the loss and
  1129. restoration of a device in DirectX; which OGRE deals with, but you
  1130. may wish to know when it happens.
  1131. @see RenderSystem::getRenderSystemEvents
  1132. */
  1133. virtual void addListener(Listener* l);
  1134. /** Remove a listener to the custom events that this render system can raise.
  1135. */
  1136. virtual void removeListener(Listener* l);
  1137. /** Gets a list of the rendersystem specific events that this rendersystem
  1138. can raise.
  1139. @see RenderSystem::addListener
  1140. */
  1141. virtual const StringVector& getRenderSystemEvents(void) const { return mEventNames; }
  1142. /** Tell the rendersystem to perform any prep tasks it needs to directly
  1143. before other threads which might access the rendering API are registered.
  1144. @remarks
  1145. Call this from your main thread before starting your other threads
  1146. (which themselves should call registerThread()). Note that if you
  1147. start your own threads, there is a specific startup sequence which
  1148. must be respected and requires synchronisation between the threads:
  1149. <ol>
  1150. <li>[Main thread]Call preExtraThreadsStarted</li>
  1151. <li>[Main thread]Start other thread, wait</li>
  1152. <li>[Other thread]Call registerThread, notify main thread & continue</li>
  1153. <li>[Main thread]Wake up & call postExtraThreadsStarted</li>
  1154. </ol>
  1155. Once this init sequence is completed the threads are independent but
  1156. this startup sequence must be respected.
  1157. */
  1158. virtual void preExtraThreadsStarted() = 0;
  1159. /* Tell the rendersystem to perform any tasks it needs to directly
  1160. after other threads which might access the rendering API are registered.
  1161. @see RenderSystem::preExtraThreadsStarted
  1162. */
  1163. virtual void postExtraThreadsStarted() = 0;
  1164. /** Register the an additional thread which may make calls to rendersystem-related
  1165. objects.
  1166. @remarks
  1167. This method should only be called by additional threads during their
  1168. initialisation. If they intend to use hardware rendering system resources
  1169. they should call this method before doing anything related to the render system.
  1170. Some rendering APIs require a per-thread setup and this method will sort that
  1171. out. It is also necessary to call unregisterThread before the thread shuts down.
  1172. @note
  1173. This method takes no parameters - it must be called from the thread being
  1174. registered and that context is enough.
  1175. */
  1176. virtual void registerThread() = 0;
  1177. /** Unregister an additional thread which may make calls to rendersystem-related objects.
  1178. @see RenderSystem::registerThread
  1179. */
  1180. virtual void unregisterThread() = 0;
  1181. /**
  1182. * Gets the number of display monitors.
  1183. @see Root::getDisplayMonitorCount
  1184. */
  1185. virtual unsigned int getDisplayMonitorCount() const = 0;
  1186. protected:
  1187. /** The render targets. */
  1188. RenderTargetMap mRenderTargets;
  1189. /** The render targets, ordered by priority. */
  1190. RenderTargetPriorityMap mPrioritisedRenderTargets;
  1191. /** The Active render target. */
  1192. RenderTarget * mActiveRenderTarget;
  1193. /** The Active GPU programs and gpu program parameters*/
  1194. GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters;
  1195. GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters;
  1196. GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters;
  1197. // Texture manager
  1198. // A concrete class of this will be created and
  1199. // made available under the TextureManager singleton,
  1200. // managed by the RenderSystem
  1201. TextureManager* mTextureManager;
  1202. // Active viewport (dest for future rendering operations)
  1203. Viewport* mActiveViewport;
  1204. CullingMode mCullingMode;
  1205. bool mVSync;
  1206. unsigned int mVSyncInterval;
  1207. bool mWBuffer;
  1208. size_t mBatchCount;
  1209. size_t mFaceCount;
  1210. size_t mVertexCount;
  1211. /// Saved manual colour blends
  1212. ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2];
  1213. bool mInvertVertexWinding;
  1214. /// Texture units from this upwards are disabled
  1215. size_t mDisabledTexUnitsFrom;
  1216. /// number of times to render the current state
  1217. size_t mCurrentPassIterationCount;
  1218. size_t mCurrentPassIterationNum;
  1219. /// Whether to update the depth bias per render call
  1220. bool mDerivedDepthBias;
  1221. float mDerivedDepthBiasBase;
  1222. float mDerivedDepthBiasMultiplier;
  1223. float mDerivedDepthBiasSlopeScale;
  1224. /** updates pass iteration rendering state including bound gpu program parameter
  1225. pass iteration auto constant entry
  1226. @returns True if more iterations are required
  1227. */
  1228. bool updatePassIterationRenderState(void);
  1229. /// List of names of events this rendersystem may raise
  1230. StringVector mEventNames;
  1231. /// Internal method for firing a rendersystem event
  1232. virtual void fireEvent(const String& name, const NameValuePairList* params = 0);
  1233. typedef list<Listener*>::type ListenerList;
  1234. ListenerList mEventListeners;
  1235. typedef list<HardwareOcclusionQuery*>::type HardwareOcclusionQueryList;
  1236. HardwareOcclusionQueryList mHwOcclusionQueries;
  1237. bool mVertexProgramBound;
  1238. bool mGeometryProgramBound;
  1239. bool mFragmentProgramBound;
  1240. // Recording user clip planes
  1241. PlaneList mClipPlanes;
  1242. // Indicator that we need to re-set the clip planes on next render call
  1243. bool mClipPlanesDirty;
  1244. /// Used to store the capabilities of the graphics card
  1245. RenderSystemCapabilities* mRealCapabilities;
  1246. RenderSystemCapabilities* mCurrentCapabilities;
  1247. bool mUseCustomCapabilities;
  1248. /// Internal method used to set the underlying clip planes when needed
  1249. virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0;
  1250. /** Initialize the render system from the capabilities*/
  1251. virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0;
  1252. DriverVersion mDriverVersion;
  1253. bool mTexProjRelative;
  1254. Vector3 mTexProjRelativeOrigin;
  1255. };
  1256. /** @} */
  1257. /** @} */
  1258. }
  1259. #endif