CmViewport.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. #ifndef __Viewport_H__
  25. #define __Viewport_H__
  26. #include "CmPrerequisites.h"
  27. #include "CmCommon.h"
  28. #include "CmColor.h"
  29. #include "CmFrustum.h"
  30. namespace CamelotEngine {
  31. /** \addtogroup Core
  32. * @{
  33. */
  34. /** \addtogroup RenderSystem
  35. * @{
  36. */
  37. /** An abstraction of a viewport, i.e. a rendering region on a render
  38. target.
  39. @remarks
  40. A viewport is the meeting of a camera and a rendering surface -
  41. the camera renders the scene from a viewpoint, and places its
  42. results into some subset of a rendering target, which may be the
  43. whole surface or just a part of the surface. Each viewport has a
  44. single camera as source and a single target as destination. A
  45. camera only has 1 viewport, but a render target may have several.
  46. A viewport also has a Z-order, i.e. if there is more than one
  47. viewport on a single render target and they overlap, one must
  48. obscure the other in some predetermined way.
  49. */
  50. class CM_EXPORT Viewport
  51. {
  52. public:
  53. /** The usual constructor.
  54. @param
  55. cam Pointer to a camera to be the source for the image.
  56. @param
  57. target Pointer to the render target to be the destination
  58. for the rendering.
  59. @param
  60. left
  61. @param
  62. top
  63. @param
  64. width
  65. @param
  66. height
  67. Dimensions of the viewport, expressed as a value between
  68. 0 and 1. This allows the dimensions to apply irrespective of
  69. changes in the target's size: e.g. to fill the whole area,
  70. values of 0,0,1,1 are appropriate.
  71. @param
  72. ZOrder Relative Z-order on the target. Lower = further to
  73. the front.
  74. */
  75. Viewport(
  76. RenderTarget* target,
  77. float left, float top,
  78. float width, float height,
  79. int ZOrder);
  80. /** Default destructor.
  81. */
  82. virtual ~Viewport();
  83. /** Notifies the viewport of a possible change in dimensions.
  84. @remarks
  85. Used by the target to update the viewport's dimensions
  86. (usually the result of a change in target size).
  87. @note
  88. Internal use by Ogre only.
  89. */
  90. void _updateDimensions(void);
  91. /** Instructs the viewport to updates its contents.
  92. */
  93. virtual void update(void);
  94. /** Instructs the viewport to clear itself, without performing an update.
  95. @remarks
  96. You would not normally call this method when updating the viewport,
  97. since the viewport usually clears itself when updating anyway (@see
  98. Viewport::setClearEveryFrame). However, if you wish you have the
  99. option of manually clearing the frame buffer (or elements of it)
  100. using this method.
  101. @param buffers Bitmask identifying which buffer elements to clear
  102. @param colour The colour value to clear to, if FBT_COLOUR is included
  103. @param depth The depth value to clear to, if FBT_DEPTH is included
  104. @param stencil The stencil value to clear to, if FBT_STENCIL is included
  105. */
  106. void clear(unsigned int buffers = FBT_COLOUR | FBT_DEPTH,
  107. const Color& colour = Color::Black,
  108. float depth = 1.0f, unsigned short stencil = 0);
  109. /** Retrieves a pointer to the render target for this viewport.
  110. */
  111. RenderTarget* getTarget(void) const;
  112. /** Gets the Z-Order of this viewport. */
  113. int getZOrder(void) const;
  114. /** Gets one of the relative dimensions of the viewport,
  115. a value between 0.0 and 1.0.
  116. */
  117. float getLeft(void) const;
  118. /** Gets one of the relative dimensions of the viewport, a value
  119. between 0.0 and 1.0.
  120. */
  121. float getTop(void) const;
  122. /** Gets one of the relative dimensions of the viewport, a value
  123. between 0.0 and 1.0.
  124. */
  125. float getWidth(void) const;
  126. /** Gets one of the relative dimensions of the viewport, a value
  127. between 0.0 and 1.0.
  128. */
  129. float getHeight(void) const;
  130. /** Gets one of the actual dimensions of the viewport, a value in
  131. pixels.
  132. */
  133. int getActualLeft(void) const;
  134. /** Gets one of the actual dimensions of the viewport, a value in
  135. pixels.
  136. */
  137. int getActualTop(void) const;
  138. /** Gets one of the actual dimensions of the viewport, a value in
  139. pixels.
  140. */
  141. int getActualWidth(void) const;
  142. /** Gets one of the actual dimensions of the viewport, a value in
  143. pixels.
  144. */
  145. int getActualHeight(void) const;
  146. /** Sets the dimensions (after creation).
  147. @param
  148. left
  149. @param
  150. top
  151. @param
  152. width
  153. @param
  154. height Dimensions relative to the size of the target,
  155. represented as real values between 0 and 1. i.e. the full
  156. target area is 0, 0, 1, 1.
  157. */
  158. void setDimensions(float left, float top, float width, float height);
  159. /** Sets the initial background colour of the viewport (before
  160. rendering).
  161. */
  162. void setBackgroundColour(const Color& colour);
  163. /** Gets the background colour.
  164. */
  165. const Color& getBackgroundColour(void) const;
  166. /** Determines whether to clear the viewport before rendering.
  167. @remarks
  168. You can use this method to set which buffers are cleared
  169. (if any) before rendering every frame.
  170. @param clear Whether or not to clear any buffers
  171. @param buffers One or more values from FrameBufferType denoting
  172. which buffers to clear, if clear is set to true. Note you should
  173. not clear the stencil buffer here unless you know what you're doing.
  174. */
  175. void setClearEveryFrame(bool clear, unsigned int buffers = FBT_COLOUR | FBT_DEPTH);
  176. /** Determines if the viewport is cleared before every frame.
  177. */
  178. bool getClearEveryFrame(void) const;
  179. /** Gets which buffers are to be cleared each frame. */
  180. unsigned int getClearBuffers(void) const;
  181. /** Access to actual dimensions (based on target size).
  182. */
  183. void getActualDimensions(
  184. int &left, int &top, int &width, int &height ) const;
  185. protected:
  186. RenderTarget* mTarget;
  187. // Relative dimensions, irrespective of target dimensions (0..1)
  188. float mRelLeft, mRelTop, mRelWidth, mRelHeight;
  189. // Actual dimensions, based on target dimensions
  190. int mActLeft, mActTop, mActWidth, mActHeight;
  191. /// ZOrder
  192. int mZOrder;
  193. /// Background options
  194. Color mBackColour;
  195. bool mClearEveryFrame;
  196. unsigned int mClearBuffers;
  197. };
  198. /** @} */
  199. /** @} */
  200. }
  201. #endif