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 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #include "OgreStableHeaders.h"
|
---|
26 | #include "OgreViewport.h"
|
---|
27 |
|
---|
28 | #include "OgreLogManager.h"
|
---|
29 | #include "OgreRenderTarget.h"
|
---|
30 | #include "OgreCamera.h"
|
---|
31 | #include "OgreMath.h"
|
---|
32 | #include "OgreRoot.h"
|
---|
33 | #include "OgreMaterialManager.h"
|
---|
34 |
|
---|
35 |
|
---|
36 | namespace Ogre {
|
---|
37 | //---------------------------------------------------------------------
|
---|
38 | Viewport::Viewport(Camera* cam, RenderTarget* target, Real left, Real top, Real width, Real height, int ZOrder)
|
---|
39 | : mCamera(cam)
|
---|
40 | , mTarget(target)
|
---|
41 | , mRelLeft(left)
|
---|
42 | , mRelTop(top)
|
---|
43 | , mRelWidth(width)
|
---|
44 | , mRelHeight(height)
|
---|
45 | // Actual dimensions will update later
|
---|
46 | , mZOrder(ZOrder)
|
---|
47 | , mBackColour(ColourValue::Black)
|
---|
48 | , mClearEveryFrame(true)
|
---|
49 | , mClearBuffers(0xFF)
|
---|
50 | , mUpdated(false)
|
---|
51 | , mShowOverlays(true)
|
---|
52 | , mShowSkies(true)
|
---|
53 | , mShowShadows(true)
|
---|
54 | , mRQSequence(0)
|
---|
55 | , mMaterialSchemeName(MaterialManager::DEFAULT_SCHEME_NAME)
|
---|
56 | {
|
---|
57 |
|
---|
58 | StringUtil::StrStreamType msg;
|
---|
59 |
|
---|
60 | msg << "Creating viewport on target '" << target->getName() << "'"
|
---|
61 | << ", rendering from camera '" << cam->getName() << "'"
|
---|
62 | << ", relative dimensions " << std::fixed << std::setprecision(2)
|
---|
63 | << "L: " << left << " T: " << top << " W: " << width << " H: " << height
|
---|
64 | << " ZOrder: " << ZOrder;
|
---|
65 | LogManager::getSingleton().logMessage(msg.str());
|
---|
66 |
|
---|
67 | // Calculate actual dimensions
|
---|
68 | _updateDimensions();
|
---|
69 |
|
---|
70 | // notify camera
|
---|
71 | cam->_notifyViewport(this);
|
---|
72 | }
|
---|
73 | //---------------------------------------------------------------------
|
---|
74 | Viewport::~Viewport()
|
---|
75 | {
|
---|
76 |
|
---|
77 | }
|
---|
78 | //---------------------------------------------------------------------
|
---|
79 | bool Viewport::_isUpdated(void) const
|
---|
80 | {
|
---|
81 | return mUpdated;
|
---|
82 | }
|
---|
83 | //---------------------------------------------------------------------
|
---|
84 | void Viewport::_clearUpdatedFlag(void)
|
---|
85 | {
|
---|
86 | mUpdated = false;
|
---|
87 | }
|
---|
88 | //---------------------------------------------------------------------
|
---|
89 | void Viewport::_updateDimensions(void)
|
---|
90 | {
|
---|
91 | Real height = (Real) mTarget->getHeight();
|
---|
92 | Real width = (Real) mTarget->getWidth();
|
---|
93 |
|
---|
94 | mActLeft = (int) (mRelLeft * width);
|
---|
95 | mActTop = (int) (mRelTop * height);
|
---|
96 | mActWidth = (int) (mRelWidth * width);
|
---|
97 | mActHeight = (int) (mRelHeight * height);
|
---|
98 |
|
---|
99 | // This will check if the cameras getAutoAspectRation() property is set.
|
---|
100 | // If it's true its aspect ratio is fit to the current viewport
|
---|
101 | // If it's false the camera remains unchanged.
|
---|
102 | // This allows cameras to be used to render to many viewports,
|
---|
103 | // which can have their own dimensions and aspect ratios.
|
---|
104 |
|
---|
105 | if (mCamera->getAutoAspectRatio())
|
---|
106 | {
|
---|
107 | mCamera->setAspectRatio((Real) mActWidth / (Real) mActHeight);
|
---|
108 | }
|
---|
109 |
|
---|
110 | StringUtil::StrStreamType msg;
|
---|
111 |
|
---|
112 | msg << "Viewport for camera '" << mCamera->getName() << "'"
|
---|
113 | << ", actual dimensions " << std::fixed << std::setprecision(2)
|
---|
114 | << "L: " << mActLeft << " T: " << mActTop << " W: " << mActWidth << " H: " << mActHeight;
|
---|
115 |
|
---|
116 | LogManager::getSingleton().logMessage(msg.str());
|
---|
117 |
|
---|
118 | mUpdated = true;
|
---|
119 | }
|
---|
120 | //---------------------------------------------------------------------
|
---|
121 | int Viewport::getZOrder(void) const
|
---|
122 | {
|
---|
123 | return mZOrder;
|
---|
124 | }
|
---|
125 | //---------------------------------------------------------------------
|
---|
126 | RenderTarget* Viewport::getTarget(void) const
|
---|
127 | {
|
---|
128 | return mTarget;
|
---|
129 | }
|
---|
130 | //---------------------------------------------------------------------
|
---|
131 | Camera* Viewport::getCamera(void) const
|
---|
132 | {
|
---|
133 | return mCamera;
|
---|
134 | }
|
---|
135 | //---------------------------------------------------------------------
|
---|
136 | Real Viewport::getLeft(void) const
|
---|
137 | {
|
---|
138 | return mRelLeft;
|
---|
139 | }
|
---|
140 | //---------------------------------------------------------------------
|
---|
141 | Real Viewport::getTop(void) const
|
---|
142 | {
|
---|
143 | return mRelTop;
|
---|
144 | }
|
---|
145 | //---------------------------------------------------------------------
|
---|
146 | Real Viewport::getWidth(void) const
|
---|
147 | {
|
---|
148 | return mRelWidth;
|
---|
149 | }
|
---|
150 | //---------------------------------------------------------------------
|
---|
151 | Real Viewport::getHeight(void) const
|
---|
152 | {
|
---|
153 | return mRelHeight;
|
---|
154 | }
|
---|
155 | //---------------------------------------------------------------------
|
---|
156 | int Viewport::getActualLeft(void) const
|
---|
157 | {
|
---|
158 | return mActLeft;
|
---|
159 | }
|
---|
160 | //---------------------------------------------------------------------
|
---|
161 | int Viewport::getActualTop(void) const
|
---|
162 | {
|
---|
163 | return mActTop;
|
---|
164 | }
|
---|
165 | //---------------------------------------------------------------------
|
---|
166 | int Viewport::getActualWidth(void) const
|
---|
167 | {
|
---|
168 | return mActWidth;
|
---|
169 | }
|
---|
170 | //---------------------------------------------------------------------
|
---|
171 | int Viewport::getActualHeight(void) const
|
---|
172 | {
|
---|
173 | return mActHeight;
|
---|
174 | }
|
---|
175 | //---------------------------------------------------------------------
|
---|
176 | void Viewport::setDimensions(Real left, Real top, Real width, Real height)
|
---|
177 | {
|
---|
178 | mRelLeft = left;
|
---|
179 | mRelTop = top;
|
---|
180 | mRelWidth = width;
|
---|
181 | mRelHeight = height;
|
---|
182 | _updateDimensions();
|
---|
183 | }
|
---|
184 | //---------------------------------------------------------------------
|
---|
185 | void Viewport::update(void)
|
---|
186 | {
|
---|
187 | if (mCamera)
|
---|
188 | {
|
---|
189 | // Tell Camera to render into me
|
---|
190 | mCamera->_renderScene(this, mShowOverlays);
|
---|
191 | }
|
---|
192 | }
|
---|
193 | //---------------------------------------------------------------------
|
---|
194 | void Viewport::setBackgroundColour(const ColourValue& colour)
|
---|
195 | {
|
---|
196 | mBackColour = colour;
|
---|
197 | }
|
---|
198 | //---------------------------------------------------------------------
|
---|
199 | const ColourValue& Viewport::getBackgroundColour(void) const
|
---|
200 | {
|
---|
201 | return mBackColour;
|
---|
202 | }
|
---|
203 | //---------------------------------------------------------------------
|
---|
204 | void Viewport::setClearEveryFrame(bool clear, unsigned int buffers)
|
---|
205 | {
|
---|
206 | mClearEveryFrame = clear;
|
---|
207 | mClearBuffers = buffers;
|
---|
208 | }
|
---|
209 | //---------------------------------------------------------------------
|
---|
210 | bool Viewport::getClearEveryFrame(void) const
|
---|
211 | {
|
---|
212 | return mClearEveryFrame;
|
---|
213 | }
|
---|
214 | //---------------------------------------------------------------------
|
---|
215 | unsigned int Viewport::getClearBuffers(void) const
|
---|
216 | {
|
---|
217 | return mClearBuffers;
|
---|
218 | }
|
---|
219 | //---------------------------------------------------------------------
|
---|
220 | void Viewport::getActualDimensions(int &left, int&top, int &width, int &height) const
|
---|
221 | {
|
---|
222 | left = mActLeft;
|
---|
223 | top = mActTop;
|
---|
224 | width = mActWidth;
|
---|
225 | height = mActHeight;
|
---|
226 |
|
---|
227 | }
|
---|
228 | //---------------------------------------------------------------------
|
---|
229 | unsigned int Viewport::_getNumRenderedFaces(void) const
|
---|
230 | {
|
---|
231 | return mCamera->_getNumRenderedFaces();
|
---|
232 | }
|
---|
233 | //---------------------------------------------------------------------
|
---|
234 | void Viewport::setCamera(Camera* cam)
|
---|
235 | {
|
---|
236 | mCamera = cam;
|
---|
237 |
|
---|
238 | }
|
---|
239 | //---------------------------------------------------------------------
|
---|
240 | void Viewport::setOverlaysEnabled(bool enabled)
|
---|
241 | {
|
---|
242 | mShowOverlays = enabled;
|
---|
243 | }
|
---|
244 | //---------------------------------------------------------------------
|
---|
245 | bool Viewport::getOverlaysEnabled(void) const
|
---|
246 | {
|
---|
247 | return mShowOverlays;
|
---|
248 | }
|
---|
249 | //---------------------------------------------------------------------
|
---|
250 | void Viewport::setSkiesEnabled(bool enabled)
|
---|
251 | {
|
---|
252 | mShowSkies = enabled;
|
---|
253 | }
|
---|
254 | //---------------------------------------------------------------------
|
---|
255 | bool Viewport::getSkiesEnabled(void) const
|
---|
256 | {
|
---|
257 | return mShowSkies;
|
---|
258 | }
|
---|
259 | //---------------------------------------------------------------------
|
---|
260 | void Viewport::setShadowsEnabled(bool enabled)
|
---|
261 | {
|
---|
262 | mShowShadows = enabled;
|
---|
263 | }
|
---|
264 | //---------------------------------------------------------------------
|
---|
265 | bool Viewport::getShadowsEnabled(void) const
|
---|
266 | {
|
---|
267 | return mShowShadows;
|
---|
268 | }
|
---|
269 | //-----------------------------------------------------------------------
|
---|
270 | void Viewport::setRenderQueueInvocationSequenceName(const String& sequenceName)
|
---|
271 | {
|
---|
272 | mRQSequenceName = sequenceName;
|
---|
273 | if (mRQSequenceName.empty())
|
---|
274 | {
|
---|
275 | mRQSequence = 0;
|
---|
276 | }
|
---|
277 | else
|
---|
278 | {
|
---|
279 | mRQSequence =
|
---|
280 | Root::getSingleton().getRenderQueueInvocationSequence(mRQSequenceName);
|
---|
281 | }
|
---|
282 | }
|
---|
283 | //-----------------------------------------------------------------------
|
---|
284 | const String& Viewport::getRenderQueueInvocationSequenceName(void) const
|
---|
285 | {
|
---|
286 | return mRQSequenceName;
|
---|
287 | }
|
---|
288 | //-----------------------------------------------------------------------
|
---|
289 | RenderQueueInvocationSequence* Viewport::_getRenderQueueInvocationSequence(void)
|
---|
290 | {
|
---|
291 | return mRQSequence;
|
---|
292 | }
|
---|
293 | //-----------------------------------------------------------------------
|
---|
294 |
|
---|
295 | }
|
---|