CmRenderTarget.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. #include "CmCoreObject.h"
  31. #include "boost/signal.hpp"
  32. /* Define the number of priority groups for the render system's render targets. */
  33. #ifndef CM_NUM_RENDERTARGET_GROUPS
  34. #define CM_NUM_RENDERTARGET_GROUPS 10
  35. #define CM_DEFAULT_RT_GROUP 4
  36. #define CM_REND_TO_TEX_RT_GROUP 2
  37. #endif
  38. namespace CamelotFramework
  39. {
  40. struct CM_EXPORT RENDER_SURFACE_DESC
  41. {
  42. TexturePtr texture;
  43. UINT32 face;
  44. UINT32 numFaces;
  45. UINT32 mipLevel;
  46. };
  47. /** \addtogroup Core
  48. * @{
  49. */
  50. /** \addtogroup RenderSystem
  51. * @{
  52. */
  53. /** A 'canvas' which can receive the results of a rendering
  54. operation.
  55. @remarks
  56. This abstract class defines a common root to all targets of rendering operations. A
  57. render target could be a window on a screen, or another
  58. offscreen surface like a texture or bump map etc.
  59. @author
  60. Steven Streeting
  61. @version
  62. 1.0
  63. */
  64. class CM_EXPORT RenderTarget : public CoreObject
  65. {
  66. public:
  67. enum FrameBuffer
  68. {
  69. FB_FRONT,
  70. FB_BACK,
  71. FB_AUTO
  72. };
  73. virtual ~RenderTarget();
  74. /// Retrieve target's name.
  75. virtual const String& getName(void) const;
  76. /// Retrieve information about the render target.
  77. virtual void getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth);
  78. virtual unsigned int getWidth(void) const;
  79. virtual unsigned int getHeight(void) const;
  80. virtual unsigned int getColourDepth(void) const;
  81. /**
  82. * @brief Swaps the frame buffers to display the next frame.
  83. *
  84. * @note Core thread only.
  85. */
  86. virtual void swapBuffers() {};
  87. /**
  88. * @brief Returns true if the render target is a render window.
  89. */
  90. virtual bool isWindow() const = 0;
  91. /** Gets a custom (maybe platform-specific) attribute.
  92. @remarks
  93. This is a nasty way of satisfying any API's need to see platform-specific details.
  94. It horrid, but D3D needs this kind of info. At least it's abstracted.
  95. @param
  96. name The name of the attribute.
  97. @param
  98. pData Pointer to memory of the right kind of structure to receive the info.
  99. */
  100. virtual void getCustomAttribute(const String& name, void* pData) const;
  101. /** Sets the priority of this render target in relation to the others.
  102. @remarks
  103. This can be used in order to schedule render target updates. Lower
  104. priorities will be rendered first. Note that the priority must be set
  105. at the time the render target is attached to the render system, changes
  106. afterwards will not affect the ordering.
  107. */
  108. virtual void setPriority( UINT8 priority ) { mPriority = priority; }
  109. /** Gets the priority of a render target. */
  110. virtual UINT8 getPriority() const { return mPriority; }
  111. /** Used to retrieve or set the active state of the render target.
  112. */
  113. virtual bool isActive() const;
  114. /** Used to set the active state of the render target.
  115. */
  116. virtual void setActive( bool state );
  117. /** Copies the current contents of the render target to a pixelbox.
  118. @remarks See suggestPixelFormat for a tip as to the best pixel format to
  119. extract into, although you can use whatever format you like and the
  120. results will be converted.
  121. */
  122. virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer = FB_AUTO) = 0;
  123. /** Suggests a pixel format to use for extracting the data in this target,
  124. when calling copyContentsToMemory.
  125. */
  126. virtual PixelFormat suggestPixelFormat() const { return PF_BYTE_RGBA; }
  127. virtual bool requiresTextureFlipping() const = 0;
  128. /** Indicates whether on rendering, linear colour space is converted to
  129. sRGB gamma colour space. This is the exact opposite conversion of
  130. what is indicated by Texture::isHardwareGammaEnabled, and can only
  131. be enabled on creation of the render target. For render windows, it's
  132. enabled through the 'gamma' creation misc parameter. For textures,
  133. it is enabled through the hwGamma parameter to the create call.
  134. */
  135. virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
  136. /** Indicates whether multisampling is performed on rendering and at what level.
  137. */
  138. virtual UINT32 getFSAA() const { return mFSAA; }
  139. /** Gets the FSAA hint (@see Root::createRenderWindow)
  140. */
  141. virtual const String& getFSAAHint() const { return mFSAAHint; }
  142. /**
  143. * @brief Returns true if the render target will wait for vertical sync before swapping buffers.
  144. */
  145. bool getVSync() const { return mVSync; }
  146. /**
  147. * @brief Set whether the render target will wait for vertical sync before swapping buffers.
  148. */
  149. void setVSync(bool vsync) { mVSync = vsync; }
  150. mutable boost::signal<void(RenderTarget*)> onMovedOrResized;
  151. protected:
  152. RenderTarget();
  153. /// The name of this target.
  154. String mName;
  155. /// The priority of the render target.
  156. UINT8 mPriority;
  157. unsigned int mWidth;
  158. unsigned int mHeight;
  159. unsigned int mColorDepth;
  160. bool mActive;
  161. // Hardware sRGB gamma conversion done on write?
  162. bool mHwGamma;
  163. // Wait for vsync?
  164. bool mVSync;
  165. // FSAA performed?
  166. UINT32 mFSAA;
  167. String mFSAAHint;
  168. };
  169. /** @} */
  170. /** @} */
  171. } // Namespace
  172. #endif