CmRenderTexture.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 __RenderTexture_H__
  25. #define __RenderTexture_H__
  26. #include "CmPrerequisites.h"
  27. #include "CmRenderTarget.h"
  28. namespace CamelotEngine
  29. {
  30. /** \addtogroup Core
  31. * @{
  32. */
  33. /** \addtogroup RenderSystem
  34. * @{
  35. */
  36. /** This class represents a RenderTarget that renders to a Texture. There is no 1 on 1
  37. relation between Textures and RenderTextures, as there can be multiple
  38. RenderTargets rendering to different mipmaps, faces (for cubemaps) or slices (for 3D textures)
  39. of the same Texture.
  40. */
  41. class CM_EXPORT RenderTexture: public RenderTarget
  42. {
  43. public:
  44. RenderTexture(HardwarePixelBuffer *buffer, UINT32 zoffset);
  45. virtual ~RenderTexture();
  46. virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
  47. PixelFormat suggestPixelFormat() const;
  48. /**
  49. * @brief Sets the depth stencil buffer attached to this render target.
  50. */
  51. //virtual void setDepthStencilBuffer(DepthStencilBufferPtr depthStencil) = 0;
  52. protected:
  53. HardwarePixelBuffer *mBuffer;
  54. UINT32 mZOffset;
  55. };
  56. /** This class represents a render target that renders to multiple RenderTextures
  57. at once. Surfaces can be bound and unbound at will, as long as the following constraints
  58. are met:
  59. - All bound surfaces have the same size
  60. - All bound surfaces have the same bit depth
  61. - Target 0 is bound
  62. */
  63. class CM_EXPORT MultiRenderTarget: public RenderTarget
  64. {
  65. public:
  66. MultiRenderTarget(const String &name);
  67. /** Bind a surface to a certain attachment point.
  68. @param attachment 0 .. mCapabilities->getNumMultiRenderTargets()-1
  69. @param target RenderTexture to bind.
  70. It does not bind the surface and fails with an exception (ERR_INVALIDPARAMS) if:
  71. - Not all bound surfaces have the same size
  72. - Not all bound surfaces have the same internal format
  73. */
  74. virtual void bindSurface(UINT32 attachment, RenderTexture *target)
  75. {
  76. for (UINT32 i = (UINT32)mBoundSurfaces.size(); i <= attachment; ++i)
  77. {
  78. mBoundSurfaces.push_back(0);
  79. }
  80. mBoundSurfaces[attachment] = target;
  81. bindSurfaceImpl(attachment, target);
  82. }
  83. /** Unbind attachment.
  84. */
  85. virtual void unbindSurface(UINT32 attachment)
  86. {
  87. if (attachment < (UINT32)mBoundSurfaces.size())
  88. mBoundSurfaces[attachment] = 0;
  89. unbindSurfaceImpl(attachment);
  90. }
  91. /** Error throwing implementation, it's not possible to write a MultiRenderTarget
  92. to disk.
  93. */
  94. virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
  95. /// Irrelevant implementation since cannot copy
  96. PixelFormat suggestPixelFormat() const { return PF_UNKNOWN; }
  97. typedef vector<RenderTexture*>::type BoundSufaceList;
  98. /// Get a list of the surfaces which have been bound
  99. const BoundSufaceList& getBoundSurfaceList() const { return mBoundSurfaces; }
  100. /** Get a pointer to a bound surface */
  101. RenderTexture* getBoundSurface(UINT32 index)
  102. {
  103. assert (index < mBoundSurfaces.size());
  104. return mBoundSurfaces[index];
  105. }
  106. protected:
  107. BoundSufaceList mBoundSurfaces;
  108. /// implementation of bindSurface, must be provided
  109. virtual void bindSurfaceImpl(UINT32 attachment, RenderTexture *target) = 0;
  110. /// implementation of unbindSurface, must be provided
  111. virtual void unbindSurfaceImpl(UINT32 attachment) = 0;
  112. };
  113. /** @} */
  114. /** @} */
  115. }
  116. #endif