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