CmRenderSystem.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __RenderSystem_H_
  25. #define __RenderSystem_H_
  26. // Precompiler options
  27. #include "CmPrerequisites.h"
  28. #include <memory>
  29. #include "CmString.h"
  30. #include "CmSamplerState.h"
  31. #include "CmCommon.h"
  32. #include "CmRenderOperation.h"
  33. #include "CmRenderSystemCapabilities.h"
  34. #include "CmRenderTarget.h"
  35. #include "CmRenderTexture.h"
  36. #include "CmGpuProgram.h"
  37. #include "CmPlane.h"
  38. #include "boost/function.hpp"
  39. #include "boost/signal.hpp"
  40. namespace CamelotEngine
  41. {
  42. /** \addtogroup Core
  43. * @{
  44. */
  45. /** \addtogroup RenderSystem
  46. * @{
  47. */
  48. typedef multimap<UINT8, RenderTarget * >::type RenderTargetPriorityMap;
  49. class TextureManager;
  50. /** Defines the functionality of a 3D API
  51. @remarks
  52. The RenderSystem class provides a base interface
  53. which abstracts the general functionality of the 3D API
  54. e.g. Direct3D or OpenGL. Whilst a few of the general
  55. methods have implementations, most of this class is
  56. abstract, requiring a subclass based on a specific API
  57. to be constructed to provide the full functionality.
  58. Note there are 2 levels to the interface - one which
  59. will be used often by the caller of the Ogre library,
  60. and one which is at a lower level and will be used by the
  61. other classes provided by Ogre. These lower level
  62. methods are prefixed with '_' to differentiate them.
  63. The advanced user of the library may use these lower
  64. level methods to access the 3D API at a more fundamental
  65. level (dealing direct with render states and rendering
  66. primitives), but still benefiting from Ogre's abstraction
  67. of exactly which 3D API is in use.
  68. @author
  69. Steven Streeting
  70. @version
  71. 1.0
  72. */
  73. class CM_EXPORT RenderSystem
  74. {
  75. public:
  76. /** Default Constructor.
  77. */
  78. RenderSystem();
  79. /** Destructor.
  80. */
  81. virtual ~RenderSystem();
  82. /** Returns the name of the rendering system.
  83. */
  84. virtual const String& getName(void) const = 0;
  85. /* @brief Start up the RenderSystem. Call before doing any operations on the render system.
  86. * Make sure all subsequent calls to the RenderSystem are done from the same thread it was started on.
  87. *
  88. * @remark If you want to access the render system from other threads, call RenderSystem::createRenderContext,
  89. * set the active context using RenderSystem::setActiveRenderContext and call the render system normally.
  90. * By default an automatically created primary render context is used.
  91. */
  92. void startUp();
  93. // TODO - Classes below (shutdown to getErrorDescription) are not yet thread safe
  94. /** Shutdown the renderer and cleanup resources.
  95. */
  96. void shutdown(void);
  97. /** Creates a new rendering window.
  98. @remarks
  99. This method creates a new rendering window as specified
  100. by the paramteters. The rendering system could be
  101. responible for only a single window (e.g. in the case
  102. of a game), or could be in charge of multiple ones (in the
  103. case of a level editor). The option to create the window
  104. as a child of another is therefore given.
  105. This method will create an appropriate subclass of
  106. RenderWindow depending on the API and platform implementation.
  107. @par
  108. After creation, this window can be retrieved using getRenderTarget().
  109. @param
  110. name The name of the window. Used in other methods
  111. later like setRenderTarget and getRenderTarget.
  112. @param
  113. width The width of the new window.
  114. @param
  115. height The height of the new window.
  116. @param
  117. fullScreen Specify true to make the window full screen
  118. without borders, title bar or menu bar.
  119. @param
  120. miscParams A NameValuePairList describing the other parameters for the new rendering window.
  121. Options are case sensitive. Unrecognised parameters will be ignored silently.
  122. These values might be platform dependent, but these are present for all platforms unless
  123. indicated otherwise:
  124. <table>
  125. <tr>
  126. <td><b>Key</b></td>
  127. <td><b>Type/Values</b></td>
  128. <td><b>Default</b></td>
  129. <td><b>Description</b></td>
  130. <td><b>Notes</b></td>
  131. </tr>
  132. <tr>
  133. <td>title</td>
  134. <td>Any string</td>
  135. <td>RenderTarget name</td>
  136. <td>The title of the window that will appear in the title bar</td>
  137. <td>&nbsp;</td>
  138. </tr>
  139. <tr>
  140. <td>colourDepth</td>
  141. <td>16, 32</td>
  142. <td>Desktop depth</td>
  143. <td>Colour depth of the resulting rendering window; only applies if fullScreen</td>
  144. <td>Win32 Specific</td>
  145. </tr>
  146. <tr>
  147. <td>left</td>
  148. <td>Positive integers</td>
  149. <td>Centred</td>
  150. <td>Screen x coordinate from left</td>
  151. <td>&nbsp;</td>
  152. </tr>
  153. <tr>
  154. <td>top</td>
  155. <td>Positive integers</td>
  156. <td>Centred</td>
  157. <td>Screen y coordinate from left</td>
  158. <td>&nbsp;</td>
  159. </tr>
  160. <tr>
  161. <td>depthBuffer</td>
  162. <td>true, false</td>
  163. <td>true</td>
  164. <td>Use depth buffer</td>
  165. <td>DirectX9 specific</td>
  166. </tr>
  167. <tr>
  168. <td>externalWindowHandle</td>
  169. <td>Win32: HWND as integer<br/>
  170. GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)</td>
  171. <td>0 (none)</td>
  172. <td>External window handle, for embedding the OGRE render in an existing window</td>
  173. <td>&nbsp;</td>
  174. </tr>
  175. <tr>
  176. <td>externalGLControl</td>
  177. <td>true, false</td>
  178. <td>false</td>
  179. <td>Let the external window control OpenGL i.e. don't select a pixel format for the window,
  180. do not change v-sync and do not swap buffer. When set to true, the calling application
  181. is responsible of OpenGL initialization and buffer swapping. It should also create an
  182. OpenGL context for its own rendering, Ogre will create one for its use. Then the calling
  183. application must also enable Ogre OpenGL context before calling any Ogre function and
  184. restore its OpenGL context after these calls.</td>
  185. <td>OpenGL specific</td>
  186. </tr>
  187. <tr>
  188. <td>externalGLContext</td>
  189. <td>Context as Unsigned Long</td>
  190. <td>0 (create own context)</td>
  191. <td>Use an externally created GL context</td>
  192. <td>OpenGL Specific</td>
  193. </tr>
  194. <tr>
  195. <td>parentWindowHandle</td>
  196. <td>Win32: HWND as integer<br/>
  197. GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)</td>
  198. <td>0 (none)</td>
  199. <td>Parent window handle, for embedding the engine in a child of an external window</td>
  200. <td>&nbsp;</td>
  201. </tr>
  202. <tr>
  203. <td>macAPI</td>
  204. <td>String: "cocoa" or "carbon"</td>
  205. <td>"carbon"</td>
  206. <td>Specifies the type of rendering window on the Mac Platform.</td>
  207. <td>&nbsp;</td>
  208. </tr>
  209. <tr>
  210. <td>macAPICocoaUseNSView</td>
  211. <td>bool "true" or "false"</td>
  212. <td>"false"</td>
  213. <td>On the Mac platform the most diffused method to embed engine in a custom application is to use Interface Builder
  214. and add to the interface an instance of OgreView.
  215. The pointer to this instance is then used as "externalWindowHandle".
  216. However, there are cases where you are NOT using Interface Builder and you get the Cocoa NSView* of an existing interface.
  217. For example, this is happens when you want to render into a Java/AWT interface.
  218. In short, by setting this flag to "true" the Ogre::Root::createRenderWindow interprets the "externalWindowHandle" as a NSView*
  219. instead of an OgreView*. See OgreOSXCocoaView.h/mm.
  220. </td>
  221. <td>&nbsp;</td>
  222. </tr>
  223. <tr>
  224. <td>FSAA</td>
  225. <td>Positive integer (usually 0, 2, 4, 8, 16)</td>
  226. <td>0</td>
  227. <td>Full screen antialiasing factor</td>
  228. <td>&nbsp;</td>
  229. </tr>
  230. <tr>
  231. <td>FSAAHint</td>
  232. <td>Depends on RenderSystem and hardware. Currently supports:<br/>
  233. "Quality": on systems that have an option to prefer higher AA quality over speed, use it</td>
  234. <td>Blank</td>
  235. <td>Full screen antialiasing hint</td>
  236. <td>&nbsp;</td>
  237. </tr>
  238. <tr>
  239. <td>displayFrequency</td>
  240. <td>Refresh rate in Hertz (e.g. 60, 75, 100)</td>
  241. <td>Desktop vsync rate</td>
  242. <td>Display frequency rate, for fullscreen mode</td>
  243. <td>&nbsp;</td>
  244. </tr>
  245. <tr>
  246. <td>vsync</td>
  247. <td>true, false</td>
  248. <td>false</td>
  249. <td>Synchronize buffer swaps to monitor vsync, eliminating tearing at the expense of a fixed frame rate</td>
  250. <td>&nbsp;</td>
  251. </tr>
  252. <tr>
  253. <td>vsyncInterval</td>
  254. <td>1, 2, 3, 4</td>
  255. <td>1</td>
  256. <td>If vsync is enabled, the minimum number of vertical blanks that should occur between renders.
  257. For example if vsync is enabled, the refresh rate is 60 and this is set to 2, then the
  258. frame rate will be locked at 30.</td>
  259. <td>&nbsp;</td>
  260. </tr>
  261. <tr>
  262. <td>border</td>
  263. <td>none, fixed, resize</td>
  264. <td>resize</td>
  265. <td>The type of window border (in windowed mode)</td>
  266. <td>&nbsp;</td>
  267. </tr>
  268. <tr>
  269. <td>outerDimensions</td>
  270. <td>true, false</td>
  271. <td>false</td>
  272. <td>Whether the width/height is expressed as the size of the
  273. outer window, rather than the content area</td>
  274. <td>&nbsp;</td>
  275. </tr>
  276. <tr>
  277. <td>useNVPerfHUD</td>
  278. <td>true, false</td>
  279. <td>false</td>
  280. <td>Enable the use of nVidia NVPerfHUD</td>
  281. <td>&nbsp;</td>
  282. </tr>
  283. <tr>
  284. <td>gamma</td>
  285. <td>true, false</td>
  286. <td>false</td>
  287. <td>Enable hardware conversion from linear colour space to gamma
  288. colour space on rendering to the window.</td>
  289. <td>&nbsp;</td>
  290. </tr>
  291. */
  292. RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height,
  293. bool fullScreen, const NameValuePairList *miscParams = 0);
  294. virtual void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height,
  295. bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp) = 0;
  296. /** Attaches the passed render target to the render system.
  297. */
  298. virtual void attachRenderTarget(RenderTarget &target);
  299. /** Detaches the render target from the render system.
  300. @note
  301. If the render target cannot be found, NULL is returned.
  302. */
  303. virtual void detachRenderTarget(RenderTarget& renderTarget);
  304. /** Destroys a render window */
  305. virtual void destroyRenderWindow(RenderWindow* renderWindow);
  306. /** Destroys a render texture */
  307. virtual void destroyRenderTexture(RenderTexture* renderTexture);
  308. /** Destroys a render target of any sort */
  309. virtual void destroyRenderTarget(RenderTarget* renderTarget);
  310. /** Defines whether or now fullscreen render windows wait for the vertical blank before flipping buffers.
  311. @remarks
  312. By default, all rendering windows wait for a vertical blank (when the CRT beam turns off briefly to move
  313. from the bottom right of the screen back to the top left) before flipping the screen buffers. This ensures
  314. that the image you see on the screen is steady. However it restricts the frame rate to the refresh rate of
  315. the monitor, and can slow the frame rate down. You can speed this up by not waiting for the blank, but
  316. this has the downside of introducing 'tearing' artefacts where part of the previous frame is still displayed
  317. as the buffers are switched. Speed vs quality, you choose.
  318. @note
  319. Has NO effect on windowed mode render targets. Only affects fullscreen mode.
  320. @param
  321. enabled If true, the system waits for vertical blanks - quality over speed. If false it doesn't - speed over quality.
  322. */
  323. void setWaitForVerticalBlank(bool enabled);
  324. /** Returns true if the system is synchronising frames with the monitor vertical blank.
  325. */
  326. bool getWaitForVerticalBlank(void) const;
  327. /**
  328. * @brief Sets a sampler state for the specified texture unit.
  329. * @see SamplerState
  330. */
  331. virtual void setSamplerState(UINT16 texUnit, const SamplerState& samplerState) = 0;
  332. /** Turns off a texture unit. */
  333. virtual void disableTextureUnit(UINT16 texUnit);
  334. /** Disables all texture units from the given unit upwards */
  335. virtual void disableTextureUnitsFrom(UINT16 texUnit);
  336. /**
  337. * @brief Sets a blend state used for all active render targets.
  338. * @see BlendState
  339. */
  340. virtual void setBlendState(const BlendState& blendState) = 0;
  341. /**
  342. * @brief Sets a state that controls various rasterizer options.
  343. * @see RasterizerState
  344. */
  345. virtual void setRasterizerState(const RasterizerState& rasterizerState) = 0;
  346. /**
  347. * @brief Sets a state that controls depth & stencil buffer options.
  348. * @see DepthStencilState
  349. */
  350. virtual void setDepthStencilState(const DepthStencilState& depthStencilState) = 0;
  351. /**
  352. * @brief Sets a reference values used for stencil buffer comparisons.
  353. * Actual comparison function and stencil operations are set by setting the StencilState.
  354. *
  355. * @remarks
  356. * The stencil buffer is used to mask out pixels in the render target, allowing
  357. * you to do effects like mirrors, cut-outs, stencil shadows and more. Each of
  358. * your batches of rendering is likely to ignore the stencil buffer,
  359. * update it with new values, or apply it to mask the output of the render.
  360. * The stencil test is:<PRE>
  361. * (Reference Value & Mask) CompareFunction (Stencil Buffer Value & Mask)</PRE>
  362. * The result of this will cause one of 3 actions depending on whether the test fails,
  363. * succeeds but with the depth buffer check still failing, or succeeds with the
  364. * depth buffer check passing too.
  365. */
  366. virtual void setStencilRefValue(UINT32 refValue) = 0;
  367. /**
  368. Sets the texture to bind to a given texture unit.
  369. User processes would not normally call this direct unless rendering
  370. primitives themselves.
  371. @param unit The index of the texture unit to modify. Multitexturing
  372. hardware can support multiple units (see
  373. RenderSystemCapabilites::getNumTextureUnits)
  374. @param enabled Boolean to turn the unit on/off
  375. @param texPtr Pointer to the texture to use.
  376. */
  377. virtual void setTexture(UINT16 unit, bool enabled, const TexturePtr &texPtr) = 0;
  378. /**
  379. * Signifies the beginning of a frame, i.e. the start of rendering on a single viewport. Will occur
  380. * several times per complete frame if multiple viewports exist.
  381. */
  382. virtual void beginFrame(void) = 0;
  383. /**
  384. * Ends rendering of a frame to the current viewport.
  385. */
  386. virtual void endFrame(void) = 0;
  387. /**
  388. Sets the provided viewport as the active one for future
  389. rendering operations. This viewport is aware of it's own
  390. camera and render target. Must be implemented by subclass.
  391. @param target Viewport to render to.
  392. */
  393. virtual void setViewport(const Viewport& vp) = 0;
  394. /** Get the current active viewport for rendering. */
  395. virtual Viewport getViewport(void);
  396. /** Sets the current vertex declaration, ie the source of vertex data. */
  397. virtual void setVertexDeclaration(VertexDeclarationPtr decl) = 0;
  398. /** Sets the current vertex buffer binding state. */
  399. virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
  400. /**
  401. Render something to the active viewport.
  402. Low-level rendering interface to perform rendering
  403. operations. Unlikely to be used directly by client
  404. applications, since the SceneManager and various support
  405. classes will be responsible for calling this method.
  406. Can only be called between _beginScene and _endScene
  407. @param op A rendering operation instance, which contains
  408. details of the operation to be performed.
  409. */
  410. virtual void render(const RenderOperation& op);
  411. /** Gets the capabilities of the render system. */
  412. const RenderSystemCapabilities* getCapabilities(void) const;
  413. /** Returns the driver version.
  414. */
  415. virtual const DriverVersion& getDriverVersion(void) const;
  416. /** Binds a given GpuProgram (but not the parameters).
  417. @remarks Only one GpuProgram of each type can be bound at once, binding another
  418. one will simply replace the existing one.
  419. */
  420. virtual void bindGpuProgram(GpuProgramHandle prg);
  421. /** Bind Gpu program parameters.
  422. @param gptype The type of program to bind the parameters to
  423. @param params The parameters to bind
  424. @param variabilityMask A mask of GpuParamVariability identifying which params need binding
  425. */
  426. virtual void bindGpuProgramParameters(GpuProgramType gptype,
  427. GpuProgramParametersSharedPtr params, UINT16 variabilityMask) = 0;
  428. /** Unbinds GpuPrograms of a given GpuProgramType.
  429. @remarks
  430. This returns the pipeline to fixed-function processing for this type.
  431. */
  432. virtual void unbindGpuProgram(GpuProgramType gptype);
  433. /** Returns whether or not a Gpu program of the given type is currently bound. */
  434. virtual bool isGpuProgramBound(GpuProgramType gptype);
  435. /** Sets the user clipping region.
  436. */
  437. virtual void setClipPlanes(const PlaneList& clipPlanes);
  438. /** Add a user clipping plane. */
  439. virtual void addClipPlane (const Plane& p);
  440. /** Add a user clipping plane. */
  441. virtual void addClipPlane (float A, float B, float C, float D);
  442. /** Clears the user clipping region.
  443. */
  444. virtual void resetClipPlanes();
  445. /** Internal method for swapping all the buffers on all render targets,
  446. if _updateAllRenderTargets was called with a 'false' parameter. */
  447. virtual void swapAllRenderTargetBuffers(bool waitForVsync = true);
  448. /** Sets the 'scissor region' ie the region of the target in which rendering can take place.
  449. @remarks
  450. This method allows you to 'mask off' rendering in all but a given rectangular area
  451. as identified by the parameters to this method.
  452. @note
  453. Not all systems support this method. Check the RenderSystemCapabilities for the
  454. RSC_SCISSOR_TEST capability to see if it is supported.
  455. @param left, top, right, bottom The location of the corners of the rectangle, expressed in
  456. <i>pixels</i>.
  457. */
  458. virtual void setScissorRect(UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600) = 0;
  459. /** Clears one or more frame buffers on the active render target.
  460. @param buffers Combination of one or more elements of FrameBufferType
  461. denoting which buffers are to be cleared
  462. @param colour The colour to clear the colour buffer with, if enabled
  463. @param depth The value to initialise the depth buffer with, if enabled
  464. @param stencil The value to initialise the stencil buffer with, if enabled.
  465. */
  466. virtual void clearFrameBuffer(unsigned int buffers,
  467. const Color& color = Color::Black,
  468. float depth = 1.0f, unsigned short stencil = 0) = 0;
  469. /**
  470. * Set current render target to target, enabling its device context if needed
  471. */
  472. virtual void setRenderTarget(RenderTarget *target) = 0;
  473. /************************************************************************/
  474. /* UTILITY METHODS */
  475. /************************************************************************/
  476. /** Get the native VertexElementType for a compact 32-bit colour value
  477. for this rendersystem.
  478. */
  479. virtual VertexElementType getColorVertexElementType(void) const = 0;
  480. /** Converts a uniform projection matrix to suitable for this render system.
  481. @remarks
  482. Because different APIs have different requirements (some incompatible) for the
  483. projection matrix, this method allows each to implement their own correctly and pass
  484. back a generic Camelot matrix for storage in the engine.
  485. */
  486. virtual void convertProjectionMatrix(const Matrix4& matrix,
  487. Matrix4& dest, bool forGpuProgram = false) = 0;
  488. /** Returns the horizontal texel offset value required for mapping
  489. texel origins to pixel origins in this rendersystem.
  490. @remarks
  491. Since rendersystems sometimes disagree on the origin of a texel,
  492. mapping from texels to pixels can sometimes be problematic to
  493. implement generically. This method allows you to retrieve the offset
  494. required to map the origin of a texel to the origin of a pixel in
  495. the horizontal direction.
  496. */
  497. virtual float getHorizontalTexelOffset(void) = 0;
  498. /** Returns the vertical texel offset value required for mapping
  499. texel origins to pixel origins in this rendersystem.
  500. @remarks
  501. Since rendersystems sometimes disagree on the origin of a texel,
  502. mapping from texels to pixels can sometimes be problematic to
  503. implement generically. This method allows you to retrieve the offset
  504. required to map the origin of a texel to the origin of a pixel in
  505. the vertical direction.
  506. */
  507. virtual float getVerticalTexelOffset(void) = 0;
  508. /** Gets the minimum (closest) depth value to be used when rendering
  509. using identity transforms.
  510. @remarks
  511. When using identity transforms you can manually set the depth
  512. of a vertex; however the input values required differ per
  513. rendersystem. This method lets you retrieve the correct value.
  514. @see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
  515. */
  516. virtual float getMinimumDepthInputValue(void) = 0;
  517. /** Gets the maximum (farthest) depth value to be used when rendering
  518. using identity transforms.
  519. @remarks
  520. When using identity transforms you can manually set the depth
  521. of a vertex; however the input values required differ per
  522. rendersystem. This method lets you retrieve the correct value.
  523. @see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
  524. */
  525. virtual float getMaximumDepthInputValue(void) = 0;
  526. /************************************************************************/
  527. /* INTERNAL DATA & METHODS */
  528. /************************************************************************/
  529. protected:
  530. /** The render targets. */
  531. vector<RenderTarget*>::type mRenderTargets;
  532. /** The render targets, ordered by priority. */
  533. RenderTargetPriorityMap mPrioritisedRenderTargets;
  534. /** The Active render target. */
  535. RenderTarget * mActiveRenderTarget;
  536. /** The Active GPU programs and gpu program parameters*/
  537. GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters;
  538. GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters;
  539. GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters;
  540. // Active viewport (dest for future rendering operations)
  541. Viewport mActiveViewport;
  542. CullingMode mCullingMode;
  543. bool mVsync;
  544. unsigned int mVSyncInterval;
  545. bool mInvertVertexWinding;
  546. /// Texture units from this upwards are disabled
  547. UINT16 mDisabledTexUnitsFrom;
  548. bool mVertexProgramBound;
  549. bool mGeometryProgramBound;
  550. bool mFragmentProgramBound;
  551. // Recording user clip planes
  552. PlaneList mClipPlanes;
  553. // Indicator that we need to re-set the clip planes on next render call
  554. bool mClipPlanesDirty;
  555. /// Used to store the capabilities of the graphics card
  556. RenderSystemCapabilities* mCurrentCapabilities;
  557. virtual void startUp_internal();
  558. virtual void shutdown_internal();
  559. /// Internal method used to set the underlying clip planes when needed
  560. virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0;
  561. /** Query the real capabilities of the GPU and driver in the RenderSystem*/
  562. virtual RenderSystemCapabilities* createRenderSystemCapabilities() const = 0;
  563. /** Initialize the render system from the capabilities*/
  564. virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0;
  565. /** Create a MultiRenderTarget, which is a render target that renders to multiple RenderTextures
  566. at once. Surfaces can be bound and unbound at will.
  567. This fails if mCapabilities->getNumMultiRenderTargets() is smaller than 2.
  568. */
  569. virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0;
  570. /** Returns a description of an error code.
  571. */
  572. virtual String getErrorDescription(long errorNumber) const = 0;
  573. DriverVersion mDriverVersion;
  574. /************************************************************************/
  575. /* THREADING */
  576. /************************************************************************/
  577. class RenderWorkerFunc CM_THREAD_WORKER_INHERIT
  578. {
  579. public:
  580. RenderWorkerFunc(RenderSystem* rs);
  581. void operator()();
  582. private:
  583. RenderSystem* mRS;
  584. };
  585. RenderWorkerFunc* mRenderThreadFunc;
  586. bool mRenderThreadShutdown;
  587. CM_THREAD_ID_TYPE mRenderThreadId;
  588. CM_THREAD_SYNCHRONISER(mRenderThreadStartCondition)
  589. CM_MUTEX(mRenderThreadStartMutex)
  590. CM_MUTEX(mCommandQueueMutex)
  591. CM_THREAD_SYNCHRONISER(mCommandReadyCondition)
  592. CM_MUTEX(mCommandNotifyMutex)
  593. CM_THREAD_SYNCHRONISER(mCommandCompleteCondition)
  594. #if CM_THREAD_SUPPORT
  595. CM_THREAD_TYPE* mRenderThread;
  596. #endif
  597. CommandQueue* mCommandQueue;
  598. UINT32 mMaxCommandNotifyId; // ID that will be assigned to the next command with a notifier callback
  599. vector<UINT32>::type mCommandsCompleted; // Completed commands that have notifier callbacks set up
  600. /**
  601. * @brief Initializes a separate render thread. Should only be called once.
  602. */
  603. void initRenderThread();
  604. /**
  605. * @brief Main function of the render thread. Called once thread is started.
  606. */
  607. void runRenderThread();
  608. /**
  609. * @brief Shutdowns the render thread. It will complete all ready commands
  610. * before shutdown.
  611. */
  612. void shutdownRenderThread();
  613. /**
  614. * @brief Throws an exception if current thread isn't the render thread;
  615. */
  616. void throwIfNotRenderThread() const;
  617. /**
  618. * @brief Blocks the calling thread until the command with the specified ID completes.
  619. * Make sure that the specified ID actually exists, otherwise this will block forever.
  620. */
  621. void blockUntilCommandCompleted(UINT32 commandId);
  622. /**
  623. * @brief Callback called by the command list when a specific command finishes executing.
  624. * This is only called on commands that have a special notify on complete flag set.
  625. *
  626. * @param commandId Identifier for the command.
  627. */
  628. void commandCompletedNotify(UINT32 commandId);
  629. public:
  630. /**
  631. * @brief Returns the id of the render thread. If a separate render thread
  632. * is not used, then it returns the id of the thread RenderSystem
  633. * was initialized on.
  634. */
  635. CM_THREAD_ID_TYPE getRenderThreadId() const { return mRenderThreadId; }
  636. /**
  637. * @brief Creates a new render system context that you can use for rendering on
  638. * a non-render thread. You can have as many of these as you wish, the only limitation
  639. * is that you do not use a single instance on more than one thread. Each thread
  640. * requires its own context. The context will be bound to the thread you call this method on.
  641. */
  642. DeferredRenderContextPtr createDeferredContext();
  643. /**
  644. * @brief Queues a new command that will be added to the global command queue. You are allowed to call this from any thread,
  645. * however be aware that it involves possibly slow synchronization primitives, so limit your usage.
  646. *
  647. * @param blockUntilComplete If true the thread will be blocked until the command executes. Be aware that there be many commands queued before it
  648. * and they all need to be executed in order before the current command is reached, which might take a long time.
  649. *
  650. * @see CommandQueue::queueReturn
  651. */
  652. AsyncOp queueReturnCommand(boost::function<void(AsyncOp&)> commandCallback, bool blockUntilComplete = false);
  653. /**
  654. * @brief Queues a new command that will be added to the global command queue.You are allowed to call this from any thread,
  655. * however be aware that it involves possibly slow synchronization primitives, so limit your usage.
  656. *
  657. * @param blockUntilComplete If true the thread will be blocked until the command executes. Be aware that there be many commands queued before it
  658. * and they all need to be executed in order before the current command is reached, which might take a long time.
  659. * @see CommandQueue::queue
  660. */
  661. void queueCommand(boost::function<void()> commandCallback, bool blockUntilComplete = false);
  662. };
  663. /** @} */
  664. /** @} */
  665. }
  666. #endif