CmViewport.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 "CmCommonEnums.h"
  28. #include "CmColor.h"
  29. #include "CmRect.h"
  30. #include <boost/signals/connection.hpp>
  31. namespace CamelotFramework {
  32. /** \addtogroup Core
  33. * @{
  34. */
  35. /** \addtogroup RenderSystem
  36. * @{
  37. */
  38. /** An abstraction of a viewport, i.e. a rendering region on a render
  39. target.
  40. @remarks
  41. A viewport is the meeting of a camera and a rendering surface -
  42. the camera renders the scene from a viewpoint, and places its
  43. results into some subset of a rendering target, which may be the
  44. whole surface or just a part of the surface. Each viewport has a
  45. single camera as source and a single target as destination. A
  46. camera only has 1 viewport, but a render target may have several.
  47. A viewport also has a Z-order, i.e. if there is more than one
  48. viewport on a single render target and they overlap, one must
  49. obscure the other in some predetermined way.
  50. */
  51. class CM_EXPORT Viewport
  52. {
  53. public:
  54. Viewport();
  55. /** The usual constructor.
  56. @param
  57. cam Pointer to a camera to be the source for the image.
  58. @param
  59. target Pointer to the render target to be the destination
  60. for the rendering.
  61. @param
  62. left
  63. @param
  64. top
  65. @param
  66. width
  67. @param
  68. height
  69. Dimensions of the viewport, expressed as a value between
  70. 0 and 1. This allows the dimensions to apply irrespective of
  71. changes in the target's size: e.g. to fill the whole area,
  72. values of 0,0,1,1 are appropriate.
  73. @param
  74. ZOrder Relative Z-order on the target. Lower = further to
  75. the front.
  76. */
  77. Viewport(
  78. RenderTargetPtr target,
  79. float left = 0.0f, float top = 0.0f,
  80. float width = 1.0f, float height = 1.0f,
  81. int ZOrder = 0);
  82. /** Default destructor.
  83. */
  84. virtual ~Viewport();
  85. /** Retrieves a pointer to the render target for this viewport.
  86. */
  87. RenderTargetPtr getTarget(void) const;
  88. /** Gets one of the relative dimensions of the viewport,
  89. a value between 0.0 and 1.0.
  90. */
  91. float getNormalizedLeft(void) const;
  92. /** Gets one of the relative dimensions of the viewport, a value
  93. between 0.0 and 1.0.
  94. */
  95. float getNormalizedTop(void) const;
  96. /** Gets one of the relative dimensions of the viewport, a value
  97. between 0.0 and 1.0.
  98. */
  99. float getNormalizedWidth(void) const;
  100. /** Gets one of the relative dimensions of the viewport, a value
  101. between 0.0 and 1.0.
  102. */
  103. float getNormalizedHeight(void) const;
  104. /** Gets one of the actual dimensions of the viewport, a value in
  105. pixels.
  106. */
  107. int getLeft(void) const;
  108. /** Gets one of the actual dimensions of the viewport, a value in
  109. pixels.
  110. */
  111. int getTop(void) const;
  112. /** Gets one of the actual dimensions of the viewport, a value in
  113. pixels.
  114. */
  115. int getWidth(void) const;
  116. /** Gets one of the actual dimensions of the viewport, a value in
  117. pixels.
  118. */
  119. int getHeight(void) const;
  120. /** Sets the dimensions (after creation).
  121. @param
  122. left
  123. @param
  124. top
  125. @param
  126. width
  127. @param
  128. height Dimensions relative to the size of the target,
  129. represented as real values between 0 and 1. i.e. the full
  130. target area is 0, 0, 1, 1.
  131. */
  132. void setDimensions(float left, float top, float width, float height);
  133. /** Access to actual dimensions (based on target size).
  134. */
  135. const Rect& getDimensions() const { return mDimensions; }
  136. const Color& getClearColor() const { return mClearColor; }
  137. void setClearColor(const Color& clearColor) { mClearColor = clearColor; }
  138. float getClearDepthValue() const { return mDepthClearValue; }
  139. void getClearDepthValue(float value) { mDepthClearValue = value; }
  140. UINT16 getClearStencilValue() const { return mStencilClearValue; }
  141. void setStencilClearValue(UINT16 value) { mStencilClearValue = value; }
  142. bool getRequiresColorClear() const { return mRequiresColorClear; }
  143. void setRequiresColorClear(bool requiresClear) { mRequiresColorClear = requiresClear; }
  144. bool getRequiresDepthClear() const { return mRequiresDepthClear; }
  145. void setRequiresDepthClear(bool requiresClear) { mRequiresDepthClear = requiresClear; }
  146. bool getRequiresStencilClear() const { return mRequiresStencilClear; }
  147. void setRequiresStencilClear(bool requiresClear) { mRequiresStencilClear = requiresClear; }
  148. protected:
  149. RenderTargetPtr mTarget;
  150. // Relative dimensions, irrespective of target dimensions (0..1)
  151. float mRelLeft, mRelTop, mRelWidth, mRelHeight;
  152. // Actual dimensions, based on target dimensions
  153. Rect mDimensions;
  154. bool mRequiresColorClear, mRequiresDepthClear, mRequiresStencilClear;
  155. Color mClearColor;
  156. float mDepthClearValue;
  157. UINT16 mStencilClearValue;
  158. boost::signals::connection mTargetConn;
  159. static const Color DefaultClearColor;
  160. /** Notifies the viewport of a possible change in dimensions.
  161. @remarks
  162. Used by the target to update the viewport's dimensions
  163. (usually the result of a change in target size).
  164. @note
  165. Internal use by engine only.
  166. */
  167. void updateDimensions(void);
  168. void targetResized(RenderTarget* target);
  169. };
  170. /** @} */
  171. /** @} */
  172. }
  173. #endif