CmRenderTarget.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 "CmRenderTarget.h"
  25. #include "OgreStringConverter.h"
  26. #include "CmViewport.h"
  27. #include "OgreException.h"
  28. #include "CmRenderSystem.h"
  29. #include "CmRenderSystemManager.h"
  30. namespace CamelotEngine {
  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. 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. _endUpdate();
  74. }
  75. void RenderTarget::_beginUpdate()
  76. {
  77. }
  78. void RenderTarget::_endUpdate()
  79. {
  80. }
  81. void RenderTarget::_updateViewport(Viewport* viewport, bool updateStatistics)
  82. {
  83. assert(viewport->getTarget() == this &&
  84. "RenderTarget::_updateViewport the requested viewport is "
  85. "not bound to the rendertarget!");
  86. viewport->update();
  87. }
  88. void RenderTarget::_updateViewport(int zorder, bool updateStatistics)
  89. {
  90. ViewportList::iterator it = mViewportList.find(zorder);
  91. if (it != mViewportList.end())
  92. {
  93. _updateViewport((*it).second,updateStatistics);
  94. }
  95. else
  96. {
  97. OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,"No viewport with given zorder : "
  98. + StringConverter::toString(zorder), "RenderTarget::_updateViewport");
  99. }
  100. }
  101. Viewport* RenderTarget::addViewport(int ZOrder, float left, float top ,
  102. float width , float height)
  103. {
  104. // Check no existing viewport with this Z-order
  105. ViewportList::iterator it = mViewportList.find(ZOrder);
  106. if (it != mViewportList.end())
  107. {
  108. StringUtil::StrStreamType str;
  109. str << "Can't create another viewport for "
  110. << mName << " with Z-Order " << ZOrder
  111. << " because a viewport exists with this Z-Order already.";
  112. OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, str.str(), "RenderTarget::addViewport");
  113. }
  114. // Add viewport to list
  115. // Order based on Z-Order
  116. Viewport* vp = new Viewport(this, left, top, width, height, ZOrder);
  117. mViewportList.insert(ViewportList::value_type(ZOrder, vp));
  118. return vp;
  119. }
  120. //-----------------------------------------------------------------------
  121. void RenderTarget::removeViewport(int ZOrder)
  122. {
  123. ViewportList::iterator it = mViewportList.find(ZOrder);
  124. if (it != mViewportList.end())
  125. {
  126. delete (*it).second;
  127. mViewportList.erase(ZOrder);
  128. }
  129. }
  130. void RenderTarget::removeAllViewports(void)
  131. {
  132. for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
  133. {
  134. delete (*it).second;
  135. }
  136. mViewportList.clear();
  137. }
  138. void RenderTarget::getCustomAttribute(const String& name, void* pData)
  139. {
  140. OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Attribute not found.", "RenderTarget::getCustomAttribute");
  141. }
  142. //-----------------------------------------------------------------------
  143. unsigned short RenderTarget::getNumViewports(void) const
  144. {
  145. return (unsigned short)mViewportList.size();
  146. }
  147. //-----------------------------------------------------------------------
  148. Viewport* RenderTarget::getViewport(unsigned short index)
  149. {
  150. assert (index < mViewportList.size() && "Index out of bounds");
  151. ViewportList::iterator i = mViewportList.begin();
  152. while (index--)
  153. ++i;
  154. return i->second;
  155. }
  156. //-----------------------------------------------------------------------
  157. bool RenderTarget::isActive() const
  158. {
  159. return mActive;
  160. }
  161. //-----------------------------------------------------------------------
  162. void RenderTarget::setActive( bool state )
  163. {
  164. mActive = state;
  165. }
  166. //-----------------------------------------------------------------------
  167. bool RenderTarget::isPrimary(void) const
  168. {
  169. // RenderWindow will override and return true for the primary window
  170. return false;
  171. }
  172. //-----------------------------------------------------------------------
  173. RenderTarget::Impl *RenderTarget::_getImpl()
  174. {
  175. return 0;
  176. }
  177. //-----------------------------------------------------------------------
  178. void RenderTarget::update(bool swap)
  179. {
  180. // call implementation
  181. updateImpl();
  182. if (swap)
  183. {
  184. // Swap buffers
  185. swapBuffers(CamelotEngine::RenderSystemManager::getActive()->getWaitForVerticalBlank());
  186. }
  187. }
  188. }