CmRenderTexture.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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, size_t zoffset);
  45. virtual ~RenderTexture();
  46. virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
  47. PixelFormat suggestPixelFormat() const;
  48. protected:
  49. HardwarePixelBuffer *mBuffer;
  50. size_t mZOffset;
  51. };
  52. /** This class represents a render target that renders to multiple RenderTextures
  53. at once. Surfaces can be bound and unbound at will, as long as the following constraints
  54. are met:
  55. - All bound surfaces have the same size
  56. - All bound surfaces have the same bit depth
  57. - Target 0 is bound
  58. */
  59. class CM_EXPORT MultiRenderTarget: public RenderTarget
  60. {
  61. public:
  62. MultiRenderTarget(const String &name);
  63. /** Bind a surface to a certain attachment point.
  64. @param attachment 0 .. mCapabilities->getNumMultiRenderTargets()-1
  65. @param target RenderTexture to bind.
  66. It does not bind the surface and fails with an exception (ERR_INVALIDPARAMS) if:
  67. - Not all bound surfaces have the same size
  68. - Not all bound surfaces have the same internal format
  69. */
  70. virtual void bindSurface(size_t attachment, RenderTexture *target)
  71. {
  72. for (size_t i = mBoundSurfaces.size(); i <= attachment; ++i)
  73. {
  74. mBoundSurfaces.push_back(0);
  75. }
  76. mBoundSurfaces[attachment] = target;
  77. bindSurfaceImpl(attachment, target);
  78. }
  79. /** Unbind attachment.
  80. */
  81. virtual void unbindSurface(size_t attachment)
  82. {
  83. if (attachment < mBoundSurfaces.size())
  84. mBoundSurfaces[attachment] = 0;
  85. unbindSurfaceImpl(attachment);
  86. }
  87. /** Error throwing implementation, it's not possible to write a MultiRenderTarget
  88. to disk.
  89. */
  90. virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
  91. /// Irrelevant implementation since cannot copy
  92. PixelFormat suggestPixelFormat() const { return PF_UNKNOWN; }
  93. typedef vector<RenderTexture*>::type BoundSufaceList;
  94. /// Get a list of the surfaces which have been bound
  95. const BoundSufaceList& getBoundSurfaceList() const { return mBoundSurfaces; }
  96. /** Get a pointer to a bound surface */
  97. RenderTexture* getBoundSurface(size_t index)
  98. {
  99. assert (index < mBoundSurfaces.size());
  100. return mBoundSurfaces[index];
  101. }
  102. protected:
  103. BoundSufaceList mBoundSurfaces;
  104. /// implementation of bindSurface, must be provided
  105. virtual void bindSurfaceImpl(size_t attachment, RenderTexture *target) = 0;
  106. /// implementation of unbindSurface, must be provided
  107. virtual void unbindSurfaceImpl(size_t attachment) = 0;
  108. };
  109. /** @} */
  110. /** @} */
  111. }
  112. #endif