OgreRenderSystem.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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. // RenderSystem implementation
  25. // Note that most of this class is abstract since
  26. // we cannot know how to implement the behaviour without
  27. // being aware of the 3D API. However there are a few
  28. // simple functions which can have a base implementation
  29. #include "OgreRenderSystem.h"
  30. #include "OgreViewport.h"
  31. #include "OgreException.h"
  32. #include "OgreRenderTarget.h"
  33. #include "OgreRenderWindow.h"
  34. #include "OgreHardwarePixelBuffer.h"
  35. #include "OgreHardwareOcclusionQuery.h"
  36. namespace Ogre {
  37. static const TexturePtr sNullTexPtr;
  38. //-----------------------------------------------------------------------
  39. RenderSystem::RenderSystem()
  40. : mActiveRenderTarget(0)
  41. , mTextureManager(0)
  42. , mActiveViewport(0)
  43. // This means CULL clockwise vertices, i.e. front of poly is counter-clockwise
  44. // This makes it the same as OpenGL and other right-handed systems
  45. , mCullingMode(CULL_CLOCKWISE)
  46. , mVSync(true)
  47. , mVSyncInterval(1)
  48. , mWBuffer(false)
  49. , mInvertVertexWinding(false)
  50. , mDisabledTexUnitsFrom(0)
  51. , mCurrentPassIterationCount(0)
  52. , mDerivedDepthBias(false)
  53. , mVertexProgramBound(false)
  54. , mGeometryProgramBound(false)
  55. , mFragmentProgramBound(false)
  56. , mClipPlanesDirty(true)
  57. , mRealCapabilities(0)
  58. , mCurrentCapabilities(0)
  59. , mUseCustomCapabilities(false)
  60. , mTexProjRelative(false)
  61. , mTexProjRelativeOrigin(Vector3::ZERO)
  62. {
  63. }
  64. //-----------------------------------------------------------------------
  65. RenderSystem::~RenderSystem()
  66. {
  67. shutdown();
  68. OGRE_DELETE mRealCapabilities;
  69. mRealCapabilities = 0;
  70. // Current capabilities managed externally
  71. mCurrentCapabilities = 0;
  72. }
  73. //-----------------------------------------------------------------------
  74. void RenderSystem::_initRenderTargets(void)
  75. {
  76. }
  77. //-----------------------------------------------------------------------
  78. void RenderSystem::_updateAllRenderTargets(bool swapBuffers)
  79. {
  80. // Update all in order of priority
  81. // This ensures render-to-texture targets get updated before render windows
  82. RenderTargetPriorityMap::iterator itarg, itargend;
  83. itargend = mPrioritisedRenderTargets.end();
  84. for( itarg = mPrioritisedRenderTargets.begin(); itarg != itargend; ++itarg )
  85. {
  86. if( itarg->second->isActive() && itarg->second->isAutoUpdated())
  87. itarg->second->update(swapBuffers);
  88. }
  89. }
  90. //-----------------------------------------------------------------------
  91. void RenderSystem::_swapAllRenderTargetBuffers(bool waitForVSync)
  92. {
  93. // Update all in order of priority
  94. // This ensures render-to-texture targets get updated before render windows
  95. RenderTargetPriorityMap::iterator itarg, itargend;
  96. itargend = mPrioritisedRenderTargets.end();
  97. for( itarg = mPrioritisedRenderTargets.begin(); itarg != itargend; ++itarg )
  98. {
  99. if( itarg->second->isActive() && itarg->second->isAutoUpdated())
  100. itarg->second->swapBuffers(waitForVSync);
  101. }
  102. }
  103. //-----------------------------------------------------------------------
  104. RenderWindow* RenderSystem::_initialise(bool autoCreateWindow, const String& windowTitle)
  105. {
  106. // Have I been registered by call to Root::setRenderSystem?
  107. /** Don't do this anymore, just allow via Root
  108. RenderSystem* regPtr = Root::getSingleton().getRenderSystem();
  109. if (!regPtr || regPtr != this)
  110. // Register self - library user has come to me direct
  111. Root::getSingleton().setRenderSystem(this);
  112. */
  113. // Subclasses should take it from here
  114. // They should ALL call this superclass method from
  115. // their own initialise() implementations.
  116. mVertexProgramBound = false;
  117. mGeometryProgramBound = false;
  118. mFragmentProgramBound = false;
  119. return 0;
  120. }
  121. //---------------------------------------------------------------------------------------------
  122. void RenderSystem::useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities)
  123. {
  124. if (mRealCapabilities != 0)
  125. {
  126. OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
  127. "Custom render capabilities must be set before the RenderSystem is initialised.",
  128. "RenderSystem::useCustomRenderSystemCapabilities");
  129. }
  130. mCurrentCapabilities = capabilities;
  131. mUseCustomCapabilities = true;
  132. }
  133. //---------------------------------------------------------------------------------------------
  134. bool RenderSystem::_createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
  135. RenderWindowList& createdWindows)
  136. {
  137. unsigned int fullscreenWindowsCount = 0;
  138. // Grab some information and avoid duplicate render windows.
  139. for (unsigned int nWindow=0; nWindow < renderWindowDescriptions.size(); ++nWindow)
  140. {
  141. const RenderWindowDescription* curDesc = &renderWindowDescriptions[nWindow];
  142. // Count full screen windows.
  143. if (curDesc->useFullScreen)
  144. fullscreenWindowsCount++;
  145. bool renderWindowFound = false;
  146. if (mRenderTargets.find(curDesc->name) != mRenderTargets.end())
  147. renderWindowFound = true;
  148. else
  149. {
  150. for (unsigned int nSecWindow = nWindow + 1 ; nSecWindow < renderWindowDescriptions.size(); ++nSecWindow)
  151. {
  152. if (curDesc->name == renderWindowDescriptions[nSecWindow].name)
  153. {
  154. renderWindowFound = true;
  155. break;
  156. }
  157. }
  158. }
  159. // Make sure we don't already have a render target of the
  160. // same name as the one supplied
  161. if(renderWindowFound)
  162. {
  163. String msg;
  164. msg = "A render target of the same name '" + String(curDesc->name) + "' already "
  165. "exists. You cannot create a new window with this name.";
  166. OGRE_EXCEPT( Exception::ERR_INTERNAL_ERROR, msg, "RenderSystem::createRenderWindow" );
  167. }
  168. }
  169. // Case we have to create some full screen rendering windows.
  170. if (fullscreenWindowsCount > 0)
  171. {
  172. // Can not mix full screen and windowed rendering windows.
  173. if (fullscreenWindowsCount != renderWindowDescriptions.size())
  174. {
  175. OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
  176. "Can not create mix of full screen and windowed rendering windows",
  177. "RenderSystem::createRenderWindows");
  178. }
  179. }
  180. return true;
  181. }
  182. //---------------------------------------------------------------------------------------------
  183. void RenderSystem::destroyRenderWindow(const String& name)
  184. {
  185. destroyRenderTarget(name);
  186. }
  187. //---------------------------------------------------------------------------------------------
  188. void RenderSystem::destroyRenderTexture(const String& name)
  189. {
  190. destroyRenderTarget(name);
  191. }
  192. //---------------------------------------------------------------------------------------------
  193. void RenderSystem::destroyRenderTarget(const String& name)
  194. {
  195. RenderTarget* rt = detachRenderTarget(name);
  196. OGRE_DELETE rt;
  197. }
  198. //---------------------------------------------------------------------------------------------
  199. void RenderSystem::attachRenderTarget( RenderTarget &target )
  200. {
  201. assert( target.getPriority() < OGRE_NUM_RENDERTARGET_GROUPS );
  202. mRenderTargets.insert( RenderTargetMap::value_type( target.getName(), &target ) );
  203. mPrioritisedRenderTargets.insert(
  204. RenderTargetPriorityMap::value_type(target.getPriority(), &target ));
  205. }
  206. //---------------------------------------------------------------------------------------------
  207. RenderTarget * RenderSystem::getRenderTarget( const String &name )
  208. {
  209. RenderTargetMap::iterator it = mRenderTargets.find( name );
  210. RenderTarget *ret = NULL;
  211. if( it != mRenderTargets.end() )
  212. {
  213. ret = it->second;
  214. }
  215. return ret;
  216. }
  217. //---------------------------------------------------------------------------------------------
  218. RenderTarget * RenderSystem::detachRenderTarget( const String &name )
  219. {
  220. RenderTargetMap::iterator it = mRenderTargets.find( name );
  221. RenderTarget *ret = NULL;
  222. if( it != mRenderTargets.end() )
  223. {
  224. ret = it->second;
  225. /* Remove the render target from the priority groups. */
  226. RenderTargetPriorityMap::iterator itarg, itargend;
  227. itargend = mPrioritisedRenderTargets.end();
  228. for( itarg = mPrioritisedRenderTargets.begin(); itarg != itargend; ++itarg )
  229. {
  230. if( itarg->second == ret ) {
  231. mPrioritisedRenderTargets.erase( itarg );
  232. break;
  233. }
  234. }
  235. mRenderTargets.erase( it );
  236. }
  237. /// If detached render target is the active render target, reset active render target
  238. if(ret == mActiveRenderTarget)
  239. mActiveRenderTarget = 0;
  240. return ret;
  241. }
  242. //-----------------------------------------------------------------------
  243. Viewport* RenderSystem::_getViewport(void)
  244. {
  245. return mActiveViewport;
  246. }
  247. //-----------------------------------------------------------------------
  248. void RenderSystem::_setTextureUnitSettings(size_t texUnit, TextureUnitState& tl)
  249. {
  250. // This method is only ever called to set a texture unit to valid details
  251. // The method _disableTextureUnit is called to turn a unit off
  252. const TexturePtr& tex = tl._getTexturePtr();
  253. // Vertex texture binding?
  254. if (mCurrentCapabilities->hasCapability(RSC_VERTEX_TEXTURE_FETCH) &&
  255. !mCurrentCapabilities->getVertexTextureUnitsShared())
  256. {
  257. if (tl.getBindingType() == TextureUnitState::BT_VERTEX)
  258. {
  259. // Bind vertex texture
  260. _setVertexTexture(texUnit, tex);
  261. // bind nothing to fragment unit (hardware isn't shared but fragment
  262. // unit can't be using the same index
  263. _setTexture(texUnit, true, sNullTexPtr);
  264. }
  265. else
  266. {
  267. // vice versa
  268. _setVertexTexture(texUnit, sNullTexPtr);
  269. _setTexture(texUnit, true, tex);
  270. }
  271. }
  272. else
  273. {
  274. // Shared vertex / fragment textures or no vertex texture support
  275. // Bind texture (may be blank)
  276. _setTexture(texUnit, true, tex);
  277. }
  278. // Set texture coordinate set
  279. _setTextureCoordSet(texUnit, tl.getTextureCoordSet());
  280. // Set texture layer filtering
  281. _setTextureUnitFiltering(texUnit,
  282. tl.getTextureFiltering(FT_MIN),
  283. tl.getTextureFiltering(FT_MAG),
  284. tl.getTextureFiltering(FT_MIP));
  285. // Set texture layer filtering
  286. _setTextureLayerAnisotropy(texUnit, tl.getTextureAnisotropy());
  287. // Set mipmap biasing
  288. _setTextureMipmapBias(texUnit, tl.getTextureMipmapBias());
  289. // Set blend modes
  290. // Note, colour before alpha is important
  291. _setTextureBlendMode(texUnit, tl.getColourBlendMode());
  292. _setTextureBlendMode(texUnit, tl.getAlphaBlendMode());
  293. // Texture addressing mode
  294. const TextureUnitState::UVWAddressingMode& uvw = tl.getTextureAddressingMode();
  295. _setTextureAddressingMode(texUnit, uvw);
  296. // Set texture border colour only if required
  297. if (uvw.u == TextureUnitState::TAM_BORDER ||
  298. uvw.v == TextureUnitState::TAM_BORDER ||
  299. uvw.w == TextureUnitState::TAM_BORDER)
  300. {
  301. _setTextureBorderColour(texUnit, tl.getTextureBorderColour());
  302. }
  303. // Set texture effects
  304. TextureUnitState::EffectMap::iterator effi;
  305. // Iterate over new effects
  306. bool anyCalcs = false;
  307. for (effi = tl.mEffects.begin(); effi != tl.mEffects.end(); ++effi)
  308. {
  309. switch (effi->second.type)
  310. {
  311. case TextureUnitState::ET_ENVIRONMENT_MAP:
  312. if (effi->second.subtype == TextureUnitState::ENV_CURVED)
  313. {
  314. _setTextureCoordCalculation(texUnit, TEXCALC_ENVIRONMENT_MAP);
  315. anyCalcs = true;
  316. }
  317. else if (effi->second.subtype == TextureUnitState::ENV_PLANAR)
  318. {
  319. _setTextureCoordCalculation(texUnit, TEXCALC_ENVIRONMENT_MAP_PLANAR);
  320. anyCalcs = true;
  321. }
  322. else if (effi->second.subtype == TextureUnitState::ENV_REFLECTION)
  323. {
  324. _setTextureCoordCalculation(texUnit, TEXCALC_ENVIRONMENT_MAP_REFLECTION);
  325. anyCalcs = true;
  326. }
  327. else if (effi->second.subtype == TextureUnitState::ENV_NORMAL)
  328. {
  329. _setTextureCoordCalculation(texUnit, TEXCALC_ENVIRONMENT_MAP_NORMAL);
  330. anyCalcs = true;
  331. }
  332. break;
  333. case TextureUnitState::ET_UVSCROLL:
  334. case TextureUnitState::ET_USCROLL:
  335. case TextureUnitState::ET_VSCROLL:
  336. case TextureUnitState::ET_ROTATE:
  337. case TextureUnitState::ET_TRANSFORM:
  338. break;
  339. case TextureUnitState::ET_PROJECTIVE_TEXTURE:
  340. _setTextureCoordCalculation(texUnit, TEXCALC_PROJECTIVE_TEXTURE,
  341. effi->second.frustum);
  342. anyCalcs = true;
  343. break;
  344. }
  345. }
  346. // Ensure any previous texcoord calc settings are reset if there are now none
  347. if (!anyCalcs)
  348. {
  349. _setTextureCoordCalculation(texUnit, TEXCALC_NONE);
  350. }
  351. // Change tetxure matrix
  352. _setTextureMatrix(texUnit, tl.getTextureTransform());
  353. }
  354. //-----------------------------------------------------------------------
  355. void RenderSystem::_setVertexTexture(size_t unit, const TexturePtr& tex)
  356. {
  357. OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
  358. "This rendersystem does not support separate vertex texture samplers, "
  359. "you should use the regular texture samplers which are shared between "
  360. "the vertex and fragment units.",
  361. "RenderSystem::_setVertexTexture");
  362. }
  363. //-----------------------------------------------------------------------
  364. void RenderSystem::_disableTextureUnit(size_t texUnit)
  365. {
  366. _setTexture(texUnit, false, sNullTexPtr);
  367. }
  368. //---------------------------------------------------------------------
  369. void RenderSystem::_disableTextureUnitsFrom(size_t texUnit)
  370. {
  371. size_t disableTo = OGRE_MAX_TEXTURE_LAYERS;
  372. if (disableTo > mDisabledTexUnitsFrom)
  373. disableTo = mDisabledTexUnitsFrom;
  374. mDisabledTexUnitsFrom = texUnit;
  375. for (size_t i = texUnit; i < disableTo; ++i)
  376. {
  377. _disableTextureUnit(i);
  378. }
  379. }
  380. //-----------------------------------------------------------------------
  381. void RenderSystem::_setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
  382. FilterOptions magFilter, FilterOptions mipFilter)
  383. {
  384. _setTextureUnitFiltering(unit, FT_MIN, minFilter);
  385. _setTextureUnitFiltering(unit, FT_MAG, magFilter);
  386. _setTextureUnitFiltering(unit, FT_MIP, mipFilter);
  387. }
  388. //-----------------------------------------------------------------------
  389. CullingMode RenderSystem::_getCullingMode(void) const
  390. {
  391. return mCullingMode;
  392. }
  393. //-----------------------------------------------------------------------
  394. bool RenderSystem::getWaitForVerticalBlank(void) const
  395. {
  396. return mVSync;
  397. }
  398. //-----------------------------------------------------------------------
  399. void RenderSystem::setWaitForVerticalBlank(bool enabled)
  400. {
  401. mVSync = enabled;
  402. }
  403. bool RenderSystem::getWBufferEnabled(void) const
  404. {
  405. return mWBuffer;
  406. }
  407. //-----------------------------------------------------------------------
  408. void RenderSystem::setWBufferEnabled(bool enabled)
  409. {
  410. mWBuffer = enabled;
  411. }
  412. //-----------------------------------------------------------------------
  413. void RenderSystem::shutdown(void)
  414. {
  415. // Remove occlusion queries
  416. for (HardwareOcclusionQueryList::iterator i = mHwOcclusionQueries.begin();
  417. i != mHwOcclusionQueries.end(); ++i)
  418. {
  419. OGRE_DELETE *i;
  420. }
  421. mHwOcclusionQueries.clear();
  422. // Remove all the render targets.
  423. // (destroy primary target last since others may depend on it)
  424. RenderTarget* primary = 0;
  425. for (RenderTargetMap::iterator it = mRenderTargets.begin(); it != mRenderTargets.end(); ++it)
  426. {
  427. if (!primary && it->second->isPrimary())
  428. primary = it->second;
  429. else
  430. OGRE_DELETE it->second;
  431. }
  432. OGRE_DELETE primary;
  433. mRenderTargets.clear();
  434. mPrioritisedRenderTargets.clear();
  435. }
  436. //-----------------------------------------------------------------------
  437. void RenderSystem::_beginGeometryCount(void)
  438. {
  439. mBatchCount = mFaceCount = mVertexCount = 0;
  440. }
  441. //-----------------------------------------------------------------------
  442. unsigned int RenderSystem::_getFaceCount(void) const
  443. {
  444. return static_cast< unsigned int >( mFaceCount );
  445. }
  446. //-----------------------------------------------------------------------
  447. unsigned int RenderSystem::_getBatchCount(void) const
  448. {
  449. return static_cast< unsigned int >( mBatchCount );
  450. }
  451. //-----------------------------------------------------------------------
  452. unsigned int RenderSystem::_getVertexCount(void) const
  453. {
  454. return static_cast< unsigned int >( mVertexCount );
  455. }
  456. //-----------------------------------------------------------------------
  457. void RenderSystem::convertColourValue(const ColourValue& colour, uint32* pDest)
  458. {
  459. *pDest = VertexElement::convertColourValue(colour, getColourVertexElementType());
  460. }
  461. //-----------------------------------------------------------------------
  462. void RenderSystem::_setWorldMatrices(const Matrix4* m, unsigned short count)
  463. {
  464. // Do nothing with these matrices here, it never used for now,
  465. // derived class should take care with them if required.
  466. // Set hardware matrix to nothing
  467. _setWorldMatrix(Matrix4::IDENTITY);
  468. }
  469. //-----------------------------------------------------------------------
  470. void RenderSystem::_render(const RenderOperation& op)
  471. {
  472. // Update stats
  473. size_t val;
  474. if (op.useIndexes)
  475. val = op.indexData->indexCount;
  476. else
  477. val = op.vertexData->vertexCount;
  478. // account for a pass having multiple iterations
  479. if (mCurrentPassIterationCount > 1)
  480. val *= mCurrentPassIterationCount;
  481. mCurrentPassIterationNum = 0;
  482. switch(op.operationType)
  483. {
  484. case RenderOperation::OT_TRIANGLE_LIST:
  485. mFaceCount += val / 3;
  486. break;
  487. case RenderOperation::OT_TRIANGLE_STRIP:
  488. case RenderOperation::OT_TRIANGLE_FAN:
  489. mFaceCount += val - 2;
  490. break;
  491. case RenderOperation::OT_POINT_LIST:
  492. case RenderOperation::OT_LINE_LIST:
  493. case RenderOperation::OT_LINE_STRIP:
  494. break;
  495. }
  496. mVertexCount += op.vertexData->vertexCount;
  497. mBatchCount += mCurrentPassIterationCount;
  498. // sort out clip planes
  499. // have to do it here in case of matrix issues
  500. if (mClipPlanesDirty)
  501. {
  502. setClipPlanesImpl(mClipPlanes);
  503. mClipPlanesDirty = false;
  504. }
  505. }
  506. //-----------------------------------------------------------------------
  507. void RenderSystem::setInvertVertexWinding(bool invert)
  508. {
  509. mInvertVertexWinding = invert;
  510. }
  511. //-----------------------------------------------------------------------
  512. bool RenderSystem::getInvertVertexWinding(void) const
  513. {
  514. return mInvertVertexWinding;
  515. }
  516. //---------------------------------------------------------------------
  517. void RenderSystem::addClipPlane (const Plane &p)
  518. {
  519. mClipPlanes.push_back(p);
  520. mClipPlanesDirty = true;
  521. }
  522. //---------------------------------------------------------------------
  523. void RenderSystem::addClipPlane (Real A, Real B, Real C, Real D)
  524. {
  525. addClipPlane(Plane(A, B, C, D));
  526. }
  527. //---------------------------------------------------------------------
  528. void RenderSystem::setClipPlanes(const PlaneList& clipPlanes)
  529. {
  530. if (clipPlanes != mClipPlanes)
  531. {
  532. mClipPlanes = clipPlanes;
  533. mClipPlanesDirty = true;
  534. }
  535. }
  536. //---------------------------------------------------------------------
  537. void RenderSystem::resetClipPlanes()
  538. {
  539. if (!mClipPlanes.empty())
  540. {
  541. mClipPlanes.clear();
  542. mClipPlanesDirty = true;
  543. }
  544. }
  545. //-----------------------------------------------------------------------
  546. void RenderSystem::_notifyCameraRemoved(const Camera* cam)
  547. {
  548. // TODO PORT - Not used in the port. Should probably be removed
  549. }
  550. //---------------------------------------------------------------------
  551. bool RenderSystem::updatePassIterationRenderState(void)
  552. {
  553. if (mCurrentPassIterationCount <= 1)
  554. return false;
  555. --mCurrentPassIterationCount;
  556. ++mCurrentPassIterationNum;
  557. if (mActiveVertexGpuProgramParameters != nullptr)
  558. {
  559. mActiveVertexGpuProgramParameters->incPassIterationNumber();
  560. bindGpuProgramPassIterationParameters(GPT_VERTEX_PROGRAM);
  561. }
  562. if (mActiveGeometryGpuProgramParameters != nullptr)
  563. {
  564. mActiveGeometryGpuProgramParameters->incPassIterationNumber();
  565. bindGpuProgramPassIterationParameters(GPT_GEOMETRY_PROGRAM);
  566. }
  567. if (mActiveFragmentGpuProgramParameters != nullptr)
  568. {
  569. mActiveFragmentGpuProgramParameters->incPassIterationNumber();
  570. bindGpuProgramPassIterationParameters(GPT_FRAGMENT_PROGRAM);
  571. }
  572. return true;
  573. }
  574. //-----------------------------------------------------------------------
  575. void RenderSystem::addListener(Listener* l)
  576. {
  577. mEventListeners.push_back(l);
  578. }
  579. //-----------------------------------------------------------------------
  580. void RenderSystem::removeListener(Listener* l)
  581. {
  582. mEventListeners.remove(l);
  583. }
  584. //-----------------------------------------------------------------------
  585. void RenderSystem::fireEvent(const String& name, const NameValuePairList* params)
  586. {
  587. for(ListenerList::iterator i = mEventListeners.begin();
  588. i != mEventListeners.end(); ++i)
  589. {
  590. (*i)->eventOccurred(name, params);
  591. }
  592. }
  593. //-----------------------------------------------------------------------
  594. void RenderSystem::destroyHardwareOcclusionQuery( HardwareOcclusionQuery *hq)
  595. {
  596. HardwareOcclusionQueryList::iterator i =
  597. std::find(mHwOcclusionQueries.begin(), mHwOcclusionQueries.end(), hq);
  598. if (i != mHwOcclusionQueries.end())
  599. {
  600. mHwOcclusionQueries.erase(i);
  601. OGRE_DELETE hq;
  602. }
  603. }
  604. //-----------------------------------------------------------------------
  605. void RenderSystem::bindGpuProgram(GpuProgram* prg)
  606. {
  607. switch(prg->getType())
  608. {
  609. case GPT_VERTEX_PROGRAM:
  610. // mark clip planes dirty if changed (programmable can change space)
  611. if (!mVertexProgramBound && !mClipPlanes.empty())
  612. mClipPlanesDirty = true;
  613. mVertexProgramBound = true;
  614. break;
  615. case GPT_GEOMETRY_PROGRAM:
  616. mGeometryProgramBound = true;
  617. break;
  618. case GPT_FRAGMENT_PROGRAM:
  619. mFragmentProgramBound = true;
  620. break;
  621. }
  622. }
  623. //-----------------------------------------------------------------------
  624. void RenderSystem::unbindGpuProgram(GpuProgramType gptype)
  625. {
  626. switch(gptype)
  627. {
  628. case GPT_VERTEX_PROGRAM:
  629. // mark clip planes dirty if changed (programmable can change space)
  630. if (mVertexProgramBound && !mClipPlanes.empty())
  631. mClipPlanesDirty = true;
  632. mVertexProgramBound = false;
  633. break;
  634. case GPT_GEOMETRY_PROGRAM:
  635. mGeometryProgramBound = false;
  636. break;
  637. case GPT_FRAGMENT_PROGRAM:
  638. mFragmentProgramBound = false;
  639. break;
  640. }
  641. }
  642. //-----------------------------------------------------------------------
  643. bool RenderSystem::isGpuProgramBound(GpuProgramType gptype)
  644. {
  645. switch(gptype)
  646. {
  647. case GPT_VERTEX_PROGRAM:
  648. return mVertexProgramBound;
  649. case GPT_GEOMETRY_PROGRAM:
  650. return mGeometryProgramBound;
  651. case GPT_FRAGMENT_PROGRAM:
  652. return mFragmentProgramBound;
  653. }
  654. // Make compiler happy
  655. return false;
  656. }
  657. //---------------------------------------------------------------------
  658. void RenderSystem::_setTextureProjectionRelativeTo(bool enabled, const Vector3& pos)
  659. {
  660. mTexProjRelative = enabled;
  661. mTexProjRelativeOrigin = pos;
  662. }
  663. //---------------------------------------------------------------------
  664. RenderSystem::RenderSystemContext* RenderSystem::_pauseFrame(void)
  665. {
  666. _endFrame();
  667. return new RenderSystem::RenderSystemContext;
  668. }
  669. //---------------------------------------------------------------------
  670. void RenderSystem::_resumeFrame(RenderSystemContext* context)
  671. {
  672. _beginFrame();
  673. delete context;
  674. }
  675. }