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 | #ifndef __RenderTarget_H__ |
---|
30 | #define __RenderTarget_H__ |
---|
31 | |
---|
32 | #include "OgrePrerequisites.h" |
---|
33 | |
---|
34 | #include "OgreString.h" |
---|
35 | #include "OgreTextureManager.h" |
---|
36 | #include "OgreViewport.h" |
---|
37 | #include "OgreTimer.h" |
---|
38 | |
---|
39 | /* Define the number of priority groups for the render system's render targets. */ |
---|
40 | #ifndef OGRE_NUM_RENDERTARGET_GROUPS |
---|
41 | #define OGRE_NUM_RENDERTARGET_GROUPS 10 |
---|
42 | #define OGRE_DEFAULT_RT_GROUP 4 |
---|
43 | #define OGRE_REND_TO_TEX_RT_GROUP 2 |
---|
44 | #endif |
---|
45 | |
---|
46 | namespace Ogre { |
---|
47 | |
---|
48 | /** A 'canvas' which can receive the results of a rendering |
---|
49 | operation. |
---|
50 | @remarks |
---|
51 | This abstract class defines a common root to all targets of rendering operations. A |
---|
52 | render target could be a window on a screen, or another |
---|
53 | offscreen surface like a texture or bump map etc. |
---|
54 | @author |
---|
55 | Steven Streeting |
---|
56 | @version |
---|
57 | 1.0 |
---|
58 | */ |
---|
59 | class _OgreExport RenderTarget |
---|
60 | { |
---|
61 | public: |
---|
62 | enum StatFlags |
---|
63 | { |
---|
64 | SF_NONE = 0, |
---|
65 | SF_FPS = 1, |
---|
66 | SF_AVG_FPS = 2, |
---|
67 | SF_BEST_FPS = 4, |
---|
68 | SF_WORST_FPS = 8, |
---|
69 | SF_TRIANGLE_COUNT = 16, |
---|
70 | SF_ALL = 0xFFFF |
---|
71 | }; |
---|
72 | |
---|
73 | struct FrameStats |
---|
74 | { |
---|
75 | float lastFPS; |
---|
76 | float avgFPS; |
---|
77 | float bestFPS; |
---|
78 | float worstFPS; |
---|
79 | unsigned long bestFrameTime; |
---|
80 | unsigned long worstFrameTime; |
---|
81 | size_t triangleCount; |
---|
82 | size_t batchCount; |
---|
83 | }; |
---|
84 | |
---|
85 | RenderTarget(); |
---|
86 | virtual ~RenderTarget(); |
---|
87 | |
---|
88 | /// Retrieve target's name. |
---|
89 | virtual const String& getName(void) const; |
---|
90 | |
---|
91 | /// Retrieve information about the render target. |
---|
92 | virtual void getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth); |
---|
93 | |
---|
94 | virtual unsigned int getWidth(void) const; |
---|
95 | virtual unsigned int getHeight(void) const; |
---|
96 | virtual unsigned int getColourDepth(void) const; |
---|
97 | |
---|
98 | /** Tells the target to update it's contents. |
---|
99 | @remarks |
---|
100 | If OGRE is not running in an automatic rendering loop |
---|
101 | (started using Root::startRendering), |
---|
102 | the user of the library is responsible for asking each render |
---|
103 | target to refresh. This is the method used to do this. It automatically |
---|
104 | re-renders the contents of the target using whatever cameras have been |
---|
105 | pointed at it (using Camera::setRenderTarget). |
---|
106 | @par |
---|
107 | This allows OGRE to be used in multi-windowed utilities |
---|
108 | and for contents to be refreshed only when required, rather than |
---|
109 | constantly as with the automatic rendering loop. |
---|
110 | */ |
---|
111 | virtual void update(void); |
---|
112 | |
---|
113 | /** Adds a viewport to the rendering target. |
---|
114 | @remarks |
---|
115 | A viewport is the rectangle into which redering output is sent. This method adds |
---|
116 | a viewport to the render target, rendering from the supplied camera. The |
---|
117 | rest of the parameters are only required if you wish to add more than one viewport |
---|
118 | to a single rendering target. Note that size information passed to this method is |
---|
119 | passed as a parametric, i.e. it is relative rather than absolute. This is to allow |
---|
120 | viewports to automatically resize along with the target. |
---|
121 | @param |
---|
122 | cam The camera from which the viewport contents will be rendered (mandatory) |
---|
123 | @param |
---|
124 | ZOrder The relative order of the viewport with others on the target (allows overlapping |
---|
125 | viewports i.e. picture-in-picture). Higher ZOrders are on top of lower ones. The actual number |
---|
126 | is irrelevant, only the relative ZOrder matters (you can leave gaps in the numbering) |
---|
127 | @param |
---|
128 | left The relative position of the left of the viewport on the target, as a value between 0 and 1. |
---|
129 | @param |
---|
130 | top The relative position of the top of the viewport on the target, as a value between 0 and 1. |
---|
131 | @param |
---|
132 | width The relative width of the viewport on the target, as a value between 0 and 1. |
---|
133 | @param |
---|
134 | height The relative height of the viewport on the target, as a value between 0 and 1. |
---|
135 | */ |
---|
136 | virtual Viewport* addViewport(Camera* cam, int ZOrder = 0, float left = 0.0f, float top = 0.0f , |
---|
137 | float width = 1.0f, float height = 1.0f); |
---|
138 | |
---|
139 | /** Returns the number of viewports attached to this target.*/ |
---|
140 | virtual unsigned short getNumViewports(void) const; |
---|
141 | |
---|
142 | /** Retrieves a pointer to the viewport with the given index. */ |
---|
143 | virtual Viewport* getViewport(unsigned short index); |
---|
144 | |
---|
145 | /** Removes a viewport at a given ZOrder. |
---|
146 | */ |
---|
147 | virtual void removeViewport(int ZOrder); |
---|
148 | |
---|
149 | /** Removes all viewports on this target. |
---|
150 | */ |
---|
151 | virtual void removeAllViewports(void); |
---|
152 | |
---|
153 | /** Retieves details of current rendering performance. |
---|
154 | @remarks |
---|
155 | If the user application wishes to do it's own performance |
---|
156 | display, or use performance for some other means, this |
---|
157 | method allows it to retrieve the statistics. |
---|
158 | @param |
---|
159 | lastFPS Pointer to a float to receive the number of frames per second (FPS) |
---|
160 | based on the last frame rendered. |
---|
161 | @param |
---|
162 | avgFPS Pointer to a float to receive the FPS rating based on an average of all |
---|
163 | the frames rendered since rendering began (the call to |
---|
164 | Root::startRendering). |
---|
165 | @param |
---|
166 | bestFPS Pointer to a float to receive the best FPS rating that has been achieved |
---|
167 | since rendering began. |
---|
168 | @param |
---|
169 | worstFPS Pointer to a float to receive the worst FPS rating seen so far. |
---|
170 | */ |
---|
171 | virtual void getStatistics(float& lastFPS, float& avgFPS, |
---|
172 | float& bestFPS, float& worstFPS) const; // Access to stats |
---|
173 | |
---|
174 | virtual const FrameStats& getStatistics(void) const; |
---|
175 | |
---|
176 | /** Individual stats access - gets the number of frames per second (FPS) based on the last frame rendered. |
---|
177 | */ |
---|
178 | virtual float getLastFPS() const; |
---|
179 | |
---|
180 | /** Individual stats access - gets the average frames per second (FPS) since call to Root::startRendering. |
---|
181 | */ |
---|
182 | virtual float getAverageFPS() const; |
---|
183 | |
---|
184 | /** Individual stats access - gets the best frames per second (FPS) since call to Root::startRendering. |
---|
185 | */ |
---|
186 | virtual float getBestFPS() const; |
---|
187 | |
---|
188 | /** Individual stats access - gets the worst frames per second (FPS) since call to Root::startRendering. |
---|
189 | */ |
---|
190 | virtual float getWorstFPS() const; |
---|
191 | |
---|
192 | /** Individual stats access - gets the best frame time |
---|
193 | */ |
---|
194 | virtual float getBestFrameTime() const; |
---|
195 | |
---|
196 | /** Individual stats access - gets the worst frame time |
---|
197 | */ |
---|
198 | virtual float getWorstFrameTime() const; |
---|
199 | |
---|
200 | /** Resets saved frame-rate statistices. |
---|
201 | */ |
---|
202 | virtual void resetStatistics(void); |
---|
203 | |
---|
204 | /** Gets a custom (maybe platform-specific) attribute. |
---|
205 | @remarks |
---|
206 | This is a nasty way of satisfying any API's need to see platform-specific details. |
---|
207 | It horrid, but D3D needs this kind of info. At least it's abstracted. |
---|
208 | @param |
---|
209 | name The name of the attribute. |
---|
210 | @param |
---|
211 | pData Pointer to memory of the right kind of structure to receive the info. |
---|
212 | */ |
---|
213 | virtual void getCustomAttribute(const String& name, void* pData); |
---|
214 | |
---|
215 | /** Add a listener to this RenderTarget which will be called back before & after rendering. |
---|
216 | @remarks |
---|
217 | If you want notifications before and after a target is updated by the system, use |
---|
218 | this method to register your own custom RenderTargetListener class. This is useful |
---|
219 | for potentially adding your own manual rendering commands before and after the |
---|
220 | 'normal' system rendering. |
---|
221 | @par NB this should not be used for frame-based scene updates, use Root::addFrameListener for that. |
---|
222 | */ |
---|
223 | virtual void addListener(RenderTargetListener* listener); |
---|
224 | /** Removes a RenderTargetListener previously registered using addListener. */ |
---|
225 | virtual void removeListener(RenderTargetListener* listener); |
---|
226 | /** Removes all listeners from this instance. */ |
---|
227 | virtual void removeAllListeners(void); |
---|
228 | |
---|
229 | /** Sets the priority of this render target in relation to the others. |
---|
230 | @remarks |
---|
231 | This can be used in order to schedule render target updates. Lower |
---|
232 | priorities will be rendered first. Note that the priority must be set |
---|
233 | at the time the render target is attached to the render system, changes |
---|
234 | afterwards will not affect the ordering. |
---|
235 | */ |
---|
236 | virtual void setPriority( uchar priority ) { mPriority = priority; } |
---|
237 | /** Gets the priority of a render target. */ |
---|
238 | virtual uchar getPriority() const { return mPriority; } |
---|
239 | |
---|
240 | /** Used to retrieve or set the active state of the render target. |
---|
241 | */ |
---|
242 | virtual bool isActive() const; |
---|
243 | |
---|
244 | /** Used to set the active state of the render target. |
---|
245 | */ |
---|
246 | virtual void setActive( bool state ); |
---|
247 | |
---|
248 | /** Sets whether this target should be automatically updated if Ogre's rendering |
---|
249 | loop or Root::_updateAllRenderTargets is being used. |
---|
250 | @remarks |
---|
251 | By default, if you use Ogre's own rendering loop (Root::startRendering) |
---|
252 | or call Root::_updateAllRenderTargets, all render targets are updated |
---|
253 | automatically. This method allows you to control that behaviour, if |
---|
254 | for example you have a render target which you only want to update periodically. |
---|
255 | @param autoupdate If true, the render target is updated during the automatic render |
---|
256 | loop or when Root::_updateAllRenderTargets is called. If false, the |
---|
257 | target is only updated when its update() method is called explicitly. |
---|
258 | */ |
---|
259 | virtual void setAutoUpdated(bool autoupdate); |
---|
260 | /** Gets whether this target is automatically updated if Ogre's rendering |
---|
261 | loop or Root::_updateAllRenderTargets is being used. |
---|
262 | */ |
---|
263 | virtual bool isAutoUpdated(void) const; |
---|
264 | |
---|
265 | /** Writes the current contents of the render target to the named file. */ |
---|
266 | virtual void writeContentsToFile(const String& filename) = 0; |
---|
267 | |
---|
268 | /** Writes the current contents of the render target to the (PREFIX)(time-stamp)(SUFFIX) file. |
---|
269 | @returns the name of the file used.*/ |
---|
270 | virtual String writeContentsToTimestampedFile(const String& filenamePrefix, const String& filenameSuffix); |
---|
271 | |
---|
272 | virtual bool requiresTextureFlipping() const = 0; |
---|
273 | |
---|
274 | /** Gets the number of triangles rendered in the last update() call. */ |
---|
275 | virtual size_t getTriangleCount(void) const; |
---|
276 | /** Gets the number of batches rendered in the last update() call. */ |
---|
277 | virtual size_t getBatchCount(void) const; |
---|
278 | /** Utility method to notify a render target that a camera has been removed, |
---|
279 | incase it was referring to it as a viewer. |
---|
280 | */ |
---|
281 | virtual void _notifyCameraRemoved(const Camera* cam); |
---|
282 | |
---|
283 | /** Indicates whether this target is the primary window. The |
---|
284 | primary window is special in that it is destroyed when |
---|
285 | ogre is shut down, and cannot be destroyed directly. |
---|
286 | This is the case because it holds the context for vertex, |
---|
287 | index buffers and textures. |
---|
288 | */ |
---|
289 | virtual bool isPrimary(void) const; |
---|
290 | |
---|
291 | |
---|
292 | /** RenderSystem specific interface for a RenderTarget; |
---|
293 | this should be subclassed by RenderSystems. |
---|
294 | */ |
---|
295 | class Impl |
---|
296 | { |
---|
297 | protected: |
---|
298 | /** Declared protected as interface is never used for destruction. |
---|
299 | gcc will issue a warning here: `class Impl' has virtual functions |
---|
300 | but non-virtual destructor. This is no problem because this interface |
---|
301 | is never used to delete an object. |
---|
302 | */ |
---|
303 | ~Impl() { }; |
---|
304 | }; |
---|
305 | /** Get rendersystem specific interface for this RenderTarget. |
---|
306 | This is used by the RenderSystem to (un)bind this target, |
---|
307 | and to get specific information like surfaces |
---|
308 | and framebuffer objects. |
---|
309 | */ |
---|
310 | virtual Impl *_getImpl(); |
---|
311 | protected: |
---|
312 | /// The name of this target. |
---|
313 | String mName; |
---|
314 | /// The priority of the render target. |
---|
315 | uchar mPriority; |
---|
316 | |
---|
317 | unsigned int mWidth; |
---|
318 | unsigned int mHeight; |
---|
319 | unsigned int mColourDepth; |
---|
320 | bool mIsDepthBuffered; |
---|
321 | |
---|
322 | // Stats |
---|
323 | FrameStats mStats; |
---|
324 | |
---|
325 | Timer* mTimer ; |
---|
326 | unsigned long mLastSecond; |
---|
327 | unsigned long mLastTime; |
---|
328 | size_t mFrameCount; |
---|
329 | |
---|
330 | bool mActive; |
---|
331 | bool mAutoUpdate; |
---|
332 | |
---|
333 | void updateStats(void); |
---|
334 | |
---|
335 | typedef std::map<int, Viewport*, std::less<int> > ViewportList; |
---|
336 | /// List of viewports, map on Z-order |
---|
337 | ViewportList mViewportList; |
---|
338 | |
---|
339 | typedef std::vector<RenderTargetListener*> RenderTargetListenerList; |
---|
340 | RenderTargetListenerList mListeners; |
---|
341 | |
---|
342 | |
---|
343 | /// internal method for firing events |
---|
344 | virtual void firePreUpdate(void); |
---|
345 | /// internal method for firing events |
---|
346 | virtual void firePostUpdate(void); |
---|
347 | /// internal method for firing events |
---|
348 | virtual void fireViewportPreUpdate(Viewport* vp); |
---|
349 | /// internal method for firing events |
---|
350 | virtual void fireViewportPostUpdate(Viewport* vp); |
---|
351 | /// internal method for firing events |
---|
352 | virtual void fireViewportAdded(Viewport* vp); |
---|
353 | /// internal method for firing events |
---|
354 | virtual void fireViewportRemoved(Viewport* vp); |
---|
355 | }; |
---|
356 | |
---|
357 | } // Namespace |
---|
358 | |
---|
359 | #endif |
---|