| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- /*
- -----------------------------------------------------------------------------
- This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
- For the latest info, see http://www.ogre3d.org/
- Copyright (c) 2000-2011 Torus Knot Software Ltd
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- -----------------------------------------------------------------------------
- */
- #ifndef __Viewport_H__
- #define __Viewport_H__
- #include "CmPrerequisites.h"
- #include "CmCommonEnums.h"
- #include "CmColor.h"
- #include "CmRect.h"
- #include <boost/signals/connection.hpp>
- namespace CamelotFramework {
- /** \addtogroup Core
- * @{
- */
- /** \addtogroup RenderSystem
- * @{
- */
- /** An abstraction of a viewport, i.e. a rendering region on a render
- target.
- @remarks
- A viewport is the meeting of a camera and a rendering surface -
- the camera renders the scene from a viewpoint, and places its
- results into some subset of a rendering target, which may be the
- whole surface or just a part of the surface. Each viewport has a
- single camera as source and a single target as destination. A
- camera only has 1 viewport, but a render target may have several.
- A viewport also has a Z-order, i.e. if there is more than one
- viewport on a single render target and they overlap, one must
- obscure the other in some predetermined way.
- */
- class CM_EXPORT Viewport
- {
- public:
- Viewport();
- /** The usual constructor.
- @param
- cam Pointer to a camera to be the source for the image.
- @param
- target Pointer to the render target to be the destination
- for the rendering.
- @param
- left
- @param
- top
- @param
- width
- @param
- height
- Dimensions of the viewport, expressed as a value between
- 0 and 1. This allows the dimensions to apply irrespective of
- changes in the target's size: e.g. to fill the whole area,
- values of 0,0,1,1 are appropriate.
- @param
- ZOrder Relative Z-order on the target. Lower = further to
- the front.
- */
- Viewport(
- RenderTargetPtr target,
- float left = 0.0f, float top = 0.0f,
- float width = 1.0f, float height = 1.0f,
- int ZOrder = 0);
- /** Default destructor.
- */
- virtual ~Viewport();
- /** Retrieves a pointer to the render target for this viewport.
- */
- RenderTargetPtr getTarget(void) const;
- /** Gets one of the relative dimensions of the viewport,
- a value between 0.0 and 1.0.
- */
- float getNormalizedLeft(void) const;
- /** Gets one of the relative dimensions of the viewport, a value
- between 0.0 and 1.0.
- */
- float getNormalizedTop(void) const;
- /** Gets one of the relative dimensions of the viewport, a value
- between 0.0 and 1.0.
- */
- float getNormalizedWidth(void) const;
- /** Gets one of the relative dimensions of the viewport, a value
- between 0.0 and 1.0.
- */
- float getNormalizedHeight(void) const;
- /** Gets one of the actual dimensions of the viewport, a value in
- pixels.
- */
- int getLeft(void) const;
- /** Gets one of the actual dimensions of the viewport, a value in
- pixels.
- */
- int getTop(void) const;
- /** Gets one of the actual dimensions of the viewport, a value in
- pixels.
- */
- int getWidth(void) const;
- /** Gets one of the actual dimensions of the viewport, a value in
- pixels.
- */
- int getHeight(void) const;
-
- /** Sets the dimensions (after creation).
- @param
- left
- @param
- top
- @param
- width
- @param
- height Dimensions relative to the size of the target,
- represented as real values between 0 and 1. i.e. the full
- target area is 0, 0, 1, 1.
- */
- void setDimensions(float left, float top, float width, float height);
- /** Access to actual dimensions (based on target size).
- */
- const Rect& getDimensions() const { return mDimensions; }
- const Color& getClearColor() const { return mClearColor; }
- void setClearColor(const Color& clearColor) { mClearColor = clearColor; }
- float getClearDepthValue() const { return mDepthClearValue; }
- void getClearDepthValue(float value) { mDepthClearValue = value; }
- UINT16 getClearStencilValue() const { return mStencilClearValue; }
- void setStencilClearValue(UINT16 value) { mStencilClearValue = value; }
- bool getRequiresColorClear() const { return mRequiresColorClear; }
- void setRequiresColorClear(bool requiresClear) { mRequiresColorClear = requiresClear; }
- bool getRequiresDepthClear() const { return mRequiresDepthClear; }
- void setRequiresDepthClear(bool requiresClear) { mRequiresDepthClear = requiresClear; }
- bool getRequiresStencilClear() const { return mRequiresStencilClear; }
- void setRequiresStencilClear(bool requiresClear) { mRequiresStencilClear = requiresClear; }
- protected:
- RenderTargetPtr mTarget;
- // Relative dimensions, irrespective of target dimensions (0..1)
- float mRelLeft, mRelTop, mRelWidth, mRelHeight;
- // Actual dimensions, based on target dimensions
- Rect mDimensions;
- bool mRequiresColorClear, mRequiresDepthClear, mRequiresStencilClear;
- Color mClearColor;
- float mDepthClearValue;
- UINT16 mStencilClearValue;
- boost::signals::connection mTargetConn;
- static const Color DefaultClearColor;
- /** Notifies the viewport of a possible change in dimensions.
- @remarks
- Used by the target to update the viewport's dimensions
- (usually the result of a change in target size).
- @note
- Internal use by engine only.
- */
- void updateDimensions(void);
- void targetResized(RenderTarget* target);
- };
- /** @} */
- /** @} */
- }
- #endif
|