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-2006 Torus Knot Software Ltd |
---|
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 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreStableHeaders.h" |
---|
30 | #include "OgreViewport.h" |
---|
31 | |
---|
32 | #include "OgreLogManager.h" |
---|
33 | #include "OgreRenderTarget.h" |
---|
34 | #include "OgreCamera.h" |
---|
35 | #include "OgreMath.h" |
---|
36 | #include "OgreRoot.h" |
---|
37 | #include "OgreMaterialManager.h" |
---|
38 | |
---|
39 | |
---|
40 | namespace Ogre { |
---|
41 | //--------------------------------------------------------------------- |
---|
42 | Viewport::Viewport(Camera* cam, RenderTarget* target, Real left, Real top, Real width, Real height, int ZOrder) |
---|
43 | : mCamera(cam) |
---|
44 | , mTarget(target) |
---|
45 | , mRelLeft(left) |
---|
46 | , mRelTop(top) |
---|
47 | , mRelWidth(width) |
---|
48 | , mRelHeight(height) |
---|
49 | // Actual dimensions will update later |
---|
50 | , mZOrder(ZOrder) |
---|
51 | , mBackColour(ColourValue::Black) |
---|
52 | , mClearEveryFrame(true) |
---|
53 | , mClearBuffers(FBT_COLOUR | FBT_DEPTH) |
---|
54 | , mUpdated(false) |
---|
55 | , mShowOverlays(true) |
---|
56 | , mShowSkies(true) |
---|
57 | , mShowShadows(true) |
---|
58 | , mVisibilityMask(0xFFFFFFFF) |
---|
59 | , mRQSequence(0) |
---|
60 | , mMaterialSchemeName(MaterialManager::DEFAULT_SCHEME_NAME) |
---|
61 | { |
---|
62 | |
---|
63 | StringUtil::StrStreamType msg; |
---|
64 | |
---|
65 | msg << "Creating viewport on target '" << target->getName() << "'" |
---|
66 | << ", rendering from camera '" << (cam != 0 ? cam->getName() : "NULL") << "'" |
---|
67 | << ", relative dimensions " << std::fixed << std::setprecision(2) |
---|
68 | << "L: " << left << " T: " << top << " W: " << width << " H: " << height |
---|
69 | << " ZOrder: " << ZOrder; |
---|
70 | LogManager::getSingleton().logMessage(msg.str()); |
---|
71 | |
---|
72 | // Calculate actual dimensions |
---|
73 | _updateDimensions(); |
---|
74 | |
---|
75 | // notify camera |
---|
76 | if(cam) cam->_notifyViewport(this); |
---|
77 | } |
---|
78 | //--------------------------------------------------------------------- |
---|
79 | Viewport::~Viewport() |
---|
80 | { |
---|
81 | |
---|
82 | } |
---|
83 | //--------------------------------------------------------------------- |
---|
84 | bool Viewport::_isUpdated(void) const |
---|
85 | { |
---|
86 | return mUpdated; |
---|
87 | } |
---|
88 | //--------------------------------------------------------------------- |
---|
89 | void Viewport::_clearUpdatedFlag(void) |
---|
90 | { |
---|
91 | mUpdated = false; |
---|
92 | } |
---|
93 | //--------------------------------------------------------------------- |
---|
94 | void Viewport::_updateDimensions(void) |
---|
95 | { |
---|
96 | Real height = (Real) mTarget->getHeight(); |
---|
97 | Real width = (Real) mTarget->getWidth(); |
---|
98 | |
---|
99 | mActLeft = (int) (mRelLeft * width); |
---|
100 | mActTop = (int) (mRelTop * height); |
---|
101 | mActWidth = (int) (mRelWidth * width); |
---|
102 | mActHeight = (int) (mRelHeight * height); |
---|
103 | |
---|
104 | // This will check if the cameras getAutoAspectRation() property is set. |
---|
105 | // If it's true its aspect ratio is fit to the current viewport |
---|
106 | // If it's false the camera remains unchanged. |
---|
107 | // This allows cameras to be used to render to many viewports, |
---|
108 | // which can have their own dimensions and aspect ratios. |
---|
109 | |
---|
110 | if (mCamera && mCamera->getAutoAspectRatio()) |
---|
111 | { |
---|
112 | mCamera->setAspectRatio((Real) mActWidth / (Real) mActHeight); |
---|
113 | } |
---|
114 | |
---|
115 | StringUtil::StrStreamType msg; |
---|
116 | |
---|
117 | msg << "Viewport for camera '" << (mCamera != 0 ? mCamera->getName() : "NULL") << "'" |
---|
118 | << ", actual dimensions " << std::fixed << std::setprecision(2) |
---|
119 | << "L: " << mActLeft << " T: " << mActTop << " W: " << mActWidth << " H: " << mActHeight; |
---|
120 | |
---|
121 | LogManager::getSingleton().logMessage(msg.str(), LML_TRIVIAL); |
---|
122 | |
---|
123 | mUpdated = true; |
---|
124 | } |
---|
125 | //--------------------------------------------------------------------- |
---|
126 | int Viewport::getZOrder(void) const |
---|
127 | { |
---|
128 | return mZOrder; |
---|
129 | } |
---|
130 | //--------------------------------------------------------------------- |
---|
131 | RenderTarget* Viewport::getTarget(void) const |
---|
132 | { |
---|
133 | return mTarget; |
---|
134 | } |
---|
135 | //--------------------------------------------------------------------- |
---|
136 | Camera* Viewport::getCamera(void) const |
---|
137 | { |
---|
138 | return mCamera; |
---|
139 | } |
---|
140 | //--------------------------------------------------------------------- |
---|
141 | Real Viewport::getLeft(void) const |
---|
142 | { |
---|
143 | return mRelLeft; |
---|
144 | } |
---|
145 | //--------------------------------------------------------------------- |
---|
146 | Real Viewport::getTop(void) const |
---|
147 | { |
---|
148 | return mRelTop; |
---|
149 | } |
---|
150 | //--------------------------------------------------------------------- |
---|
151 | Real Viewport::getWidth(void) const |
---|
152 | { |
---|
153 | return mRelWidth; |
---|
154 | } |
---|
155 | //--------------------------------------------------------------------- |
---|
156 | Real Viewport::getHeight(void) const |
---|
157 | { |
---|
158 | return mRelHeight; |
---|
159 | } |
---|
160 | //--------------------------------------------------------------------- |
---|
161 | int Viewport::getActualLeft(void) const |
---|
162 | { |
---|
163 | return mActLeft; |
---|
164 | } |
---|
165 | //--------------------------------------------------------------------- |
---|
166 | int Viewport::getActualTop(void) const |
---|
167 | { |
---|
168 | return mActTop; |
---|
169 | } |
---|
170 | //--------------------------------------------------------------------- |
---|
171 | int Viewport::getActualWidth(void) const |
---|
172 | { |
---|
173 | return mActWidth; |
---|
174 | } |
---|
175 | //--------------------------------------------------------------------- |
---|
176 | int Viewport::getActualHeight(void) const |
---|
177 | { |
---|
178 | return mActHeight; |
---|
179 | } |
---|
180 | //--------------------------------------------------------------------- |
---|
181 | void Viewport::setDimensions(Real left, Real top, Real width, Real height) |
---|
182 | { |
---|
183 | mRelLeft = left; |
---|
184 | mRelTop = top; |
---|
185 | mRelWidth = width; |
---|
186 | mRelHeight = height; |
---|
187 | _updateDimensions(); |
---|
188 | } |
---|
189 | //--------------------------------------------------------------------- |
---|
190 | void Viewport::update(void) |
---|
191 | { |
---|
192 | if (mCamera) |
---|
193 | { |
---|
194 | // Tell Camera to render into me |
---|
195 | mCamera->_renderScene(this, mShowOverlays); |
---|
196 | } |
---|
197 | } |
---|
198 | //--------------------------------------------------------------------- |
---|
199 | void Viewport::setBackgroundColour(const ColourValue& colour) |
---|
200 | { |
---|
201 | mBackColour = colour; |
---|
202 | } |
---|
203 | //--------------------------------------------------------------------- |
---|
204 | const ColourValue& Viewport::getBackgroundColour(void) const |
---|
205 | { |
---|
206 | return mBackColour; |
---|
207 | } |
---|
208 | //--------------------------------------------------------------------- |
---|
209 | void Viewport::setClearEveryFrame(bool clear, unsigned int buffers) |
---|
210 | { |
---|
211 | mClearEveryFrame = clear; |
---|
212 | mClearBuffers = buffers; |
---|
213 | } |
---|
214 | //--------------------------------------------------------------------- |
---|
215 | bool Viewport::getClearEveryFrame(void) const |
---|
216 | { |
---|
217 | return mClearEveryFrame; |
---|
218 | } |
---|
219 | //--------------------------------------------------------------------- |
---|
220 | unsigned int Viewport::getClearBuffers(void) const |
---|
221 | { |
---|
222 | return mClearBuffers; |
---|
223 | } |
---|
224 | //--------------------------------------------------------------------- |
---|
225 | void Viewport::getActualDimensions(int &left, int&top, int &width, int &height) const |
---|
226 | { |
---|
227 | left = mActLeft; |
---|
228 | top = mActTop; |
---|
229 | width = mActWidth; |
---|
230 | height = mActHeight; |
---|
231 | |
---|
232 | } |
---|
233 | //--------------------------------------------------------------------- |
---|
234 | unsigned int Viewport::_getNumRenderedFaces(void) const |
---|
235 | { |
---|
236 | return mCamera ? mCamera->_getNumRenderedFaces() : 0; |
---|
237 | } |
---|
238 | //--------------------------------------------------------------------- |
---|
239 | unsigned int Viewport::_getNumRenderedBatches(void) const |
---|
240 | { |
---|
241 | return mCamera ? mCamera->_getNumRenderedBatches() : 0; |
---|
242 | } |
---|
243 | //--------------------------------------------------------------------- |
---|
244 | void Viewport::setCamera(Camera* cam) |
---|
245 | { |
---|
246 | mCamera = cam; |
---|
247 | if(cam) mCamera->_notifyViewport(this); |
---|
248 | } |
---|
249 | //--------------------------------------------------------------------- |
---|
250 | void Viewport::setOverlaysEnabled(bool enabled) |
---|
251 | { |
---|
252 | mShowOverlays = enabled; |
---|
253 | } |
---|
254 | //--------------------------------------------------------------------- |
---|
255 | bool Viewport::getOverlaysEnabled(void) const |
---|
256 | { |
---|
257 | return mShowOverlays; |
---|
258 | } |
---|
259 | //--------------------------------------------------------------------- |
---|
260 | void Viewport::setSkiesEnabled(bool enabled) |
---|
261 | { |
---|
262 | mShowSkies = enabled; |
---|
263 | } |
---|
264 | //--------------------------------------------------------------------- |
---|
265 | bool Viewport::getSkiesEnabled(void) const |
---|
266 | { |
---|
267 | return mShowSkies; |
---|
268 | } |
---|
269 | //--------------------------------------------------------------------- |
---|
270 | void Viewport::setShadowsEnabled(bool enabled) |
---|
271 | { |
---|
272 | mShowShadows = enabled; |
---|
273 | } |
---|
274 | //--------------------------------------------------------------------- |
---|
275 | bool Viewport::getShadowsEnabled(void) const |
---|
276 | { |
---|
277 | return mShowShadows; |
---|
278 | } |
---|
279 | //----------------------------------------------------------------------- |
---|
280 | void Viewport::setRenderQueueInvocationSequenceName(const String& sequenceName) |
---|
281 | { |
---|
282 | mRQSequenceName = sequenceName; |
---|
283 | if (mRQSequenceName.empty()) |
---|
284 | { |
---|
285 | mRQSequence = 0; |
---|
286 | } |
---|
287 | else |
---|
288 | { |
---|
289 | mRQSequence = |
---|
290 | Root::getSingleton().getRenderQueueInvocationSequence(mRQSequenceName); |
---|
291 | } |
---|
292 | } |
---|
293 | //----------------------------------------------------------------------- |
---|
294 | const String& Viewport::getRenderQueueInvocationSequenceName(void) const |
---|
295 | { |
---|
296 | return mRQSequenceName; |
---|
297 | } |
---|
298 | //----------------------------------------------------------------------- |
---|
299 | RenderQueueInvocationSequence* Viewport::_getRenderQueueInvocationSequence(void) |
---|
300 | { |
---|
301 | return mRQSequence; |
---|
302 | } |
---|
303 | //----------------------------------------------------------------------- |
---|
304 | |
---|
305 | } |
---|