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