OgreRenderTarget.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. #include "OgreRenderTarget.h"
  25. #include "OgreStringConverter.h"
  26. #include "OgreViewport.h"
  27. #include "OgreException.h"
  28. #include "OgreRenderSystem.h"
  29. #include "CmRenderSystemManager.h"
  30. namespace Ogre {
  31. RenderTarget::RenderTarget()
  32. :mPriority(OGRE_DEFAULT_RT_GROUP),
  33. mActive(true),
  34. mAutoUpdate(true),
  35. mHwGamma(false),
  36. mFSAA(0)
  37. {
  38. }
  39. RenderTarget::~RenderTarget()
  40. {
  41. // Delete viewports
  42. for (ViewportList::iterator i = mViewportList.begin();
  43. i != mViewportList.end(); ++i)
  44. {
  45. OGRE_DELETE (*i).second;
  46. }
  47. }
  48. const String& RenderTarget::getName(void) const
  49. {
  50. return mName;
  51. }
  52. void RenderTarget::getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth)
  53. {
  54. width = mWidth;
  55. height = mHeight;
  56. colourDepth = mColourDepth;
  57. }
  58. unsigned int RenderTarget::getWidth(void) const
  59. {
  60. return mWidth;
  61. }
  62. unsigned int RenderTarget::getHeight(void) const
  63. {
  64. return mHeight;
  65. }
  66. unsigned int RenderTarget::getColourDepth(void) const
  67. {
  68. return mColourDepth;
  69. }
  70. void RenderTarget::updateImpl(void)
  71. {
  72. _beginUpdate();
  73. _updateAutoUpdatedViewports(true);
  74. _endUpdate();
  75. }
  76. void RenderTarget::_beginUpdate()
  77. {
  78. }
  79. void RenderTarget::_updateAutoUpdatedViewports(bool updateStatistics)
  80. {
  81. // Go through viewports in Z-order
  82. // Tell each to refresh
  83. ViewportList::iterator it = mViewportList.begin();
  84. while (it != mViewportList.end())
  85. {
  86. Viewport* viewport = (*it).second;
  87. if(viewport->isAutoUpdated())
  88. {
  89. _updateViewport(viewport,updateStatistics);
  90. }
  91. ++it;
  92. }
  93. }
  94. void RenderTarget::_endUpdate()
  95. {
  96. }
  97. void RenderTarget::_updateViewport(Viewport* viewport, bool updateStatistics)
  98. {
  99. assert(viewport->getTarget() == this &&
  100. "RenderTarget::_updateViewport the requested viewport is "
  101. "not bound to the rendertarget!");
  102. viewport->update();
  103. }
  104. void RenderTarget::_updateViewport(int zorder, bool updateStatistics)
  105. {
  106. ViewportList::iterator it = mViewportList.find(zorder);
  107. if (it != mViewportList.end())
  108. {
  109. _updateViewport((*it).second,updateStatistics);
  110. }
  111. else
  112. {
  113. OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,"No viewport with given zorder : "
  114. + StringConverter::toString(zorder), "RenderTarget::_updateViewport");
  115. }
  116. }
  117. Viewport* RenderTarget::addViewport(int ZOrder, float left, float top ,
  118. float width , float height)
  119. {
  120. // Check no existing viewport with this Z-order
  121. ViewportList::iterator it = mViewportList.find(ZOrder);
  122. if (it != mViewportList.end())
  123. {
  124. StringUtil::StrStreamType str;
  125. str << "Can't create another viewport for "
  126. << mName << " with Z-Order " << ZOrder
  127. << " because a viewport exists with this Z-Order already.";
  128. OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, str.str(), "RenderTarget::addViewport");
  129. }
  130. // Add viewport to list
  131. // Order based on Z-Order
  132. Viewport* vp = OGRE_NEW Viewport(this, left, top, width, height, ZOrder);
  133. mViewportList.insert(ViewportList::value_type(ZOrder, vp));
  134. return vp;
  135. }
  136. //-----------------------------------------------------------------------
  137. void RenderTarget::removeViewport(int ZOrder)
  138. {
  139. ViewportList::iterator it = mViewportList.find(ZOrder);
  140. if (it != mViewportList.end())
  141. {
  142. OGRE_DELETE (*it).second;
  143. mViewportList.erase(ZOrder);
  144. }
  145. }
  146. void RenderTarget::removeAllViewports(void)
  147. {
  148. for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
  149. {
  150. OGRE_DELETE (*it).second;
  151. }
  152. mViewportList.clear();
  153. }
  154. void RenderTarget::getCustomAttribute(const String& name, void* pData)
  155. {
  156. OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Attribute not found.", "RenderTarget::getCustomAttribute");
  157. }
  158. //-----------------------------------------------------------------------
  159. unsigned short RenderTarget::getNumViewports(void) const
  160. {
  161. return (unsigned short)mViewportList.size();
  162. }
  163. //-----------------------------------------------------------------------
  164. Viewport* RenderTarget::getViewport(unsigned short index)
  165. {
  166. assert (index < mViewportList.size() && "Index out of bounds");
  167. ViewportList::iterator i = mViewportList.begin();
  168. while (index--)
  169. ++i;
  170. return i->second;
  171. }
  172. //-----------------------------------------------------------------------
  173. bool RenderTarget::isActive() const
  174. {
  175. return mActive;
  176. }
  177. //-----------------------------------------------------------------------
  178. void RenderTarget::setActive( bool state )
  179. {
  180. mActive = state;
  181. }
  182. //-----------------------------------------------------------------------
  183. void RenderTarget::setAutoUpdated(bool autoup)
  184. {
  185. mAutoUpdate = autoup;
  186. }
  187. //-----------------------------------------------------------------------
  188. bool RenderTarget::isAutoUpdated(void) const
  189. {
  190. return mAutoUpdate;
  191. }
  192. //-----------------------------------------------------------------------
  193. bool RenderTarget::isPrimary(void) const
  194. {
  195. // RenderWindow will override and return true for the primary window
  196. return false;
  197. }
  198. //-----------------------------------------------------------------------
  199. RenderTarget::Impl *RenderTarget::_getImpl()
  200. {
  201. return 0;
  202. }
  203. //-----------------------------------------------------------------------
  204. void RenderTarget::update(bool swap)
  205. {
  206. // call implementation
  207. updateImpl();
  208. if (swap)
  209. {
  210. // Swap buffers
  211. swapBuffers(CamelotEngine::RenderSystemManager::getActive()->getWaitForVerticalBlank());
  212. }
  213. }
  214. }