CmRenderTarget.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 __RenderTarget_H__
  25. #define __RenderTarget_H__
  26. #include "CmPrerequisites.h"
  27. #include "CmString.h"
  28. #include "CmPixelUtil.h"
  29. #include "CmViewport.h"
  30. /* Define the number of priority groups for the render system's render targets. */
  31. #ifndef CM_NUM_RENDERTARGET_GROUPS
  32. #define CM_NUM_RENDERTARGET_GROUPS 10
  33. #define OGRE_DEFAULT_RT_GROUP 4
  34. #define OGRE_REND_TO_TEX_RT_GROUP 2
  35. #endif
  36. namespace CamelotEngine {
  37. /** \addtogroup Core
  38. * @{
  39. */
  40. /** \addtogroup RenderSystem
  41. * @{
  42. */
  43. /** A 'canvas' which can receive the results of a rendering
  44. operation.
  45. @remarks
  46. This abstract class defines a common root to all targets of rendering operations. A
  47. render target could be a window on a screen, or another
  48. offscreen surface like a texture or bump map etc.
  49. @author
  50. Steven Streeting
  51. @version
  52. 1.0
  53. */
  54. class CM_EXPORT RenderTarget
  55. {
  56. public:
  57. enum FrameBuffer
  58. {
  59. FB_FRONT,
  60. FB_BACK,
  61. FB_AUTO
  62. };
  63. RenderTarget();
  64. virtual ~RenderTarget();
  65. /// Retrieve target's name.
  66. virtual const String& getName(void) const;
  67. /// Retrieve information about the render target.
  68. virtual void getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth);
  69. virtual unsigned int getWidth(void) const;
  70. virtual unsigned int getHeight(void) const;
  71. virtual unsigned int getColourDepth(void) const;
  72. /** Tells the target to update it's contents.
  73. @remarks
  74. If OGRE is not running in an automatic rendering loop
  75. (started using Root::startRendering),
  76. the user of the library is responsible for asking each render
  77. target to refresh. This is the method used to do this. It automatically
  78. re-renders the contents of the target using whatever cameras have been
  79. pointed at it (using Camera::setRenderTarget).
  80. @par
  81. This allows OGRE to be used in multi-windowed utilities
  82. and for contents to be refreshed only when required, rather than
  83. constantly as with the automatic rendering loop.
  84. @param swapBuffers For targets that support double-buffering, if set
  85. to true, the target will immediately
  86. swap it's buffers after update. Otherwise, the buffers are
  87. not swapped, and you have to call swapBuffers yourself sometime
  88. later. You might want to do this on some rendersystems which
  89. pause for queued rendering commands to complete before accepting
  90. swap buffers calls - so you could do other CPU tasks whilst the
  91. queued commands complete. Or, you might do this if you want custom
  92. control over your windows, such as for externally created windows.
  93. */
  94. virtual void update(bool swapBuffers = true);
  95. /** Swaps the frame buffers to display the next frame.
  96. @remarks
  97. For targets that are double-buffered so that no
  98. 'in-progress' versions of the scene are displayed
  99. during rendering. Once rendering has completed (to
  100. an off-screen version of the window) the buffers
  101. are swapped to display the new frame.
  102. @param
  103. waitForVSync If true, the system waits for the
  104. next vertical blank period (when the CRT beam turns off
  105. as it travels from bottom-right to top-left at the
  106. end of the pass) before flipping. If false, flipping
  107. occurs no matter what the beam position. Waiting for
  108. a vertical blank can be slower (and limits the
  109. framerate to the monitor refresh rate) but results
  110. in a steadier image with no 'tearing' (a flicker
  111. resulting from flipping buffers when the beam is
  112. in the progress of drawing the last frame).
  113. */
  114. virtual void swapBuffers(bool waitForVSync = true)
  115. { (void)waitForVSync; }
  116. /** Gets a custom (maybe platform-specific) attribute.
  117. @remarks
  118. This is a nasty way of satisfying any API's need to see platform-specific details.
  119. It horrid, but D3D needs this kind of info. At least it's abstracted.
  120. @param
  121. name The name of the attribute.
  122. @param
  123. pData Pointer to memory of the right kind of structure to receive the info.
  124. */
  125. virtual void getCustomAttribute_internal(const String& name, void* pData);
  126. /** Sets the priority of this render target in relation to the others.
  127. @remarks
  128. This can be used in order to schedule render target updates. Lower
  129. priorities will be rendered first. Note that the priority must be set
  130. at the time the render target is attached to the render system, changes
  131. afterwards will not affect the ordering.
  132. */
  133. virtual void setPriority( UINT8 priority ) { mPriority = priority; }
  134. /** Gets the priority of a render target. */
  135. virtual UINT8 getPriority() const { return mPriority; }
  136. /** Used to retrieve or set the active state of the render target.
  137. */
  138. virtual bool isActive() const;
  139. /** Used to set the active state of the render target.
  140. */
  141. virtual void setActive( bool state );
  142. /** Copies the current contents of the render target to a pixelbox.
  143. @remarks See suggestPixelFormat for a tip as to the best pixel format to
  144. extract into, although you can use whatever format you like and the
  145. results will be converted.
  146. */
  147. virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer = FB_AUTO) = 0;
  148. /** Suggests a pixel format to use for extracting the data in this target,
  149. when calling copyContentsToMemory.
  150. */
  151. virtual PixelFormat suggestPixelFormat() const { return PF_BYTE_RGBA; }
  152. virtual bool requiresTextureFlipping() const = 0;
  153. /** Indicates whether this target is the primary window. The
  154. primary window is special in that it is destroyed when
  155. ogre is shut down, and cannot be destroyed directly.
  156. This is the case because it holds the context for vertex,
  157. index buffers and textures.
  158. */
  159. virtual bool isPrimary(void) const;
  160. /** Indicates whether on rendering, linear colour space is converted to
  161. sRGB gamma colour space. This is the exact opposite conversion of
  162. what is indicated by Texture::isHardwareGammaEnabled, and can only
  163. be enabled on creation of the render target. For render windows, it's
  164. enabled through the 'gamma' creation misc parameter. For textures,
  165. it is enabled through the hwGamma parameter to the create call.
  166. */
  167. virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
  168. /** Indicates whether multisampling is performed on rendering and at what level.
  169. */
  170. virtual UINT32 getFSAA() const { return mFSAA; }
  171. /** Gets the FSAA hint (@see Root::createRenderWindow)
  172. */
  173. virtual const String& getFSAAHint() const { return mFSAAHint; }
  174. /** RenderSystem specific interface for a RenderTarget;
  175. this should be subclassed by RenderSystems.
  176. */
  177. class Impl
  178. {
  179. protected:
  180. ~Impl() { }
  181. };
  182. /** Get rendersystem specific interface for this RenderTarget.
  183. This is used by the RenderSystem to (un)bind this target,
  184. and to get specific information like surfaces
  185. and framebuffer objects.
  186. */
  187. virtual Impl *_getImpl();
  188. /** Method for manual management of rendering : fires 'preRenderTargetUpdate'
  189. and initialises statistics etc.
  190. @remarks
  191. <ul>
  192. <li>_beginUpdate resets statistics and fires 'preRenderTargetUpdate'.</li>
  193. <li>_updateViewport renders the given viewport (even if it is not autoupdated),
  194. fires preViewportUpdate and postViewportUpdate and manages statistics.</li>
  195. <li>_updateAutoUpdatedViewports renders only viewports that are auto updated,
  196. fires preViewportUpdate and postViewportUpdate and manages statistics.</li>
  197. <li>_endUpdate() ends statistics calculation and fires postRenderTargetUpdate.</li>
  198. </ul>
  199. you can use it like this for example :
  200. <pre>
  201. renderTarget->_beginUpdate();
  202. renderTarget->_updateViewport(1); // which is not auto updated
  203. renderTarget->_updateViewport(2); // which is not auto updated
  204. renderTarget->_updateAutoUpdatedViewports();
  205. renderTarget->_endUpdate();
  206. renderTarget->swapBuffers(true);
  207. </pre>
  208. Please note that in that case, the zorder may not work as you expect,
  209. since you are responsible for calling _updateViewport in the correct order.
  210. */
  211. virtual void _beginUpdate();
  212. /** Method for manual management of rendering - finishes statistics calculation
  213. and fires 'postRenderTargetUpdate'.
  214. @remarks
  215. You should call it after a _beginUpdate
  216. @see _beginUpdate for more details.
  217. */
  218. virtual void _endUpdate();
  219. protected:
  220. /// The name of this target.
  221. String mName;
  222. /// The priority of the render target.
  223. UINT8 mPriority;
  224. unsigned int mWidth;
  225. unsigned int mHeight;
  226. unsigned int mColourDepth;
  227. bool mIsDepthBuffered;
  228. bool mActive;
  229. bool mAutoUpdate;
  230. // Hardware sRGB gamma conversion done on write?
  231. bool mHwGamma;
  232. // FSAA performed?
  233. UINT32 mFSAA;
  234. String mFSAAHint;
  235. /// Internal implementation of update()
  236. virtual void updateImpl();
  237. };
  238. /** @} */
  239. /** @} */
  240. } // Namespace
  241. #endif