OgreViewport.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 "OgreViewport.h"
  25. #include "OgreException.h"
  26. #include "OgreRenderTarget.h"
  27. #include "OgreMath.h"
  28. #include "OgreRenderSystem.h"
  29. #include "CmRenderSystemManager.h"
  30. namespace Ogre {
  31. //---------------------------------------------------------------------
  32. Viewport::Viewport(RenderTarget* target, Real left, Real top, Real width, Real height, int ZOrder)
  33. :mTarget(target)
  34. , mRelLeft(left)
  35. , mRelTop(top)
  36. , mRelWidth(width)
  37. , mRelHeight(height)
  38. // Actual dimensions will update later
  39. , mZOrder(ZOrder)
  40. , mBackColour(ColourValue::Black)
  41. , mClearEveryFrame(true)
  42. , mClearBuffers(FBT_COLOUR | FBT_DEPTH)
  43. {
  44. // Calculate actual dimensions
  45. _updateDimensions();
  46. }
  47. //---------------------------------------------------------------------
  48. Viewport::~Viewport()
  49. {
  50. }
  51. //---------------------------------------------------------------------
  52. void Viewport::_updateDimensions(void)
  53. {
  54. Real height = (Real) mTarget->getHeight();
  55. Real width = (Real) mTarget->getWidth();
  56. mActLeft = (int) (mRelLeft * width);
  57. mActTop = (int) (mRelTop * height);
  58. mActWidth = (int) (mRelWidth * width);
  59. mActHeight = (int) (mRelHeight * height);
  60. }
  61. //---------------------------------------------------------------------
  62. int Viewport::getZOrder(void) const
  63. {
  64. return mZOrder;
  65. }
  66. //---------------------------------------------------------------------
  67. RenderTarget* Viewport::getTarget(void) const
  68. {
  69. return mTarget;
  70. }
  71. //---------------------------------------------------------------------
  72. Real Viewport::getLeft(void) const
  73. {
  74. return mRelLeft;
  75. }
  76. //---------------------------------------------------------------------
  77. Real Viewport::getTop(void) const
  78. {
  79. return mRelTop;
  80. }
  81. //---------------------------------------------------------------------
  82. Real Viewport::getWidth(void) const
  83. {
  84. return mRelWidth;
  85. }
  86. //---------------------------------------------------------------------
  87. Real Viewport::getHeight(void) const
  88. {
  89. return mRelHeight;
  90. }
  91. //---------------------------------------------------------------------
  92. int Viewport::getActualLeft(void) const
  93. {
  94. return mActLeft;
  95. }
  96. //---------------------------------------------------------------------
  97. int Viewport::getActualTop(void) const
  98. {
  99. return mActTop;
  100. }
  101. //---------------------------------------------------------------------
  102. int Viewport::getActualWidth(void) const
  103. {
  104. return mActWidth;
  105. }
  106. //---------------------------------------------------------------------
  107. int Viewport::getActualHeight(void) const
  108. {
  109. return mActHeight;
  110. }
  111. //---------------------------------------------------------------------
  112. void Viewport::setDimensions(Real left, Real top, Real width, Real height)
  113. {
  114. mRelLeft = left;
  115. mRelTop = top;
  116. mRelWidth = width;
  117. mRelHeight = height;
  118. _updateDimensions();
  119. }
  120. //---------------------------------------------------------------------
  121. void Viewport::update(void)
  122. {
  123. }
  124. //---------------------------------------------------------------------
  125. void Viewport::setBackgroundColour(const ColourValue& colour)
  126. {
  127. mBackColour = colour;
  128. }
  129. //---------------------------------------------------------------------
  130. const ColourValue& Viewport::getBackgroundColour(void) const
  131. {
  132. return mBackColour;
  133. }
  134. //---------------------------------------------------------------------
  135. void Viewport::setClearEveryFrame(bool inClear, unsigned int inBuffers)
  136. {
  137. mClearEveryFrame = inClear;
  138. mClearBuffers = inBuffers;
  139. }
  140. //---------------------------------------------------------------------
  141. bool Viewport::getClearEveryFrame(void) const
  142. {
  143. return mClearEveryFrame;
  144. }
  145. //---------------------------------------------------------------------
  146. unsigned int Viewport::getClearBuffers(void) const
  147. {
  148. return mClearBuffers;
  149. }
  150. //---------------------------------------------------------------------
  151. void Viewport::clear(unsigned int buffers, const ColourValue& col,
  152. Real depth, unsigned short stencil)
  153. {
  154. RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
  155. if (rs)
  156. {
  157. Viewport* currentvp = rs->_getViewport();
  158. if (currentvp && currentvp == this)
  159. rs->clearFrameBuffer(buffers, col, depth, stencil);
  160. else if (currentvp)
  161. {
  162. rs->_setViewport(this);
  163. rs->clearFrameBuffer(buffers, col, depth, stencil);
  164. rs->_setViewport(currentvp);
  165. }
  166. }
  167. }
  168. //---------------------------------------------------------------------
  169. void Viewport::getActualDimensions(int &left, int&top, int &width, int &height) const
  170. {
  171. left = mActLeft;
  172. top = mActTop;
  173. width = mActWidth;
  174. height = mActHeight;
  175. }
  176. //-----------------------------------------------------------------------
  177. }