BsRenderTexture.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsTexture.h"
  7. #include "BsRenderTarget.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Structure that describes a render texture color and depth/stencil surfaces.
  12. */
  13. struct BS_CORE_EXPORT RENDER_TEXTURE_DESC
  14. {
  15. RENDER_SURFACE_DESC colorSurface;
  16. RENDER_SURFACE_DESC depthStencilSurface;
  17. };
  18. /**
  19. * @brief Render target specialization that allows you to render into a texture you may
  20. * later bind in further render operations.
  21. *
  22. * @note Thread safe, except where noted otherwise.
  23. */
  24. class BS_CORE_EXPORT RenderTexture : public RenderTarget
  25. {
  26. public:
  27. virtual ~RenderTexture();
  28. /**
  29. * @brief Creates a new render texture with color and optionally depth/stencil surfaces.
  30. *
  31. * @param textureType Type of texture to render to.
  32. * @param width Width of the render texture, in pixels.
  33. * @param height Height of the render texture, in pixels.
  34. * @param format Pixel format used by the texture color surface.
  35. * @param hwGamma Should the written pixels be gamma corrected.
  36. * @param multisampleCount If higher than 1, texture containing multiple samples per pixel is created.
  37. * @param multisampleHint Hint about what kind of multisampling to use. Render system specific.
  38. * @param createDepth Should a depth/stencil surface be created along with the color surface.
  39. * @param depthStencilFormat Format used by the depth stencil surface, if one is created.
  40. */
  41. static RenderTexturePtr create(TextureType textureType, UINT32 width, UINT32 height,
  42. PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 multisampleCount = 0,
  43. const String& multisampleHint = "", bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
  44. /**
  45. * @copydoc RenderTarget::isWindow.
  46. */
  47. bool isWindow() const { return false; }
  48. /**
  49. * @copydoc RenderTarget::requiresTextureFlipping.
  50. */
  51. bool requiresTextureFlipping() const { return false; }
  52. /**
  53. * @brief Returns a color surface texture you may bind as an input to an GPU program.
  54. *
  55. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  56. */
  57. const HTexture& getBindableColorTexture() const { return mBindableColorTex; }
  58. /**
  59. * @brief Returns a depth/stencil surface texture you may bind as an input to an GPU program.
  60. *
  61. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  62. */
  63. const HTexture& getBindableDepthStencilTexture() const { return mBindableDepthStencilTex; }
  64. protected:
  65. friend class TextureManager;
  66. RenderTexture();
  67. /**
  68. * @copydoc RenderTarget::initialize
  69. */
  70. void initialize(const RENDER_TEXTURE_DESC& desc);
  71. /**
  72. * @copydoc RenderTarget::destroy_internal()
  73. */
  74. virtual void destroy_internal();
  75. private:
  76. /**
  77. * @brief Throws an exception of the color and depth/stencil buffers aren't compatible.
  78. */
  79. void throwIfBuffersDontMatch() const;
  80. /**
  81. * @copydoc RenderTarget::copyToMemory
  82. */
  83. virtual void copyToMemory(PixelData &dst, FrameBuffer buffer = FB_AUTO);
  84. protected:
  85. TextureViewPtr mColorSurface;
  86. TextureViewPtr mDepthStencilSurface;
  87. HTexture mBindableColorTex;
  88. HTexture mBindableDepthStencilTex;
  89. };
  90. }