IRenderTarget.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright (C) 2015 Patryk Nadrowski
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "IReferenceCounted.h"
  6. #include "EDriverTypes.h"
  7. #include "irrArray.h"
  8. namespace irr
  9. {
  10. namespace video
  11. {
  12. class ITexture;
  13. //! Enumeration of cube texture surfaces
  14. enum E_CUBE_SURFACE
  15. {
  16. ECS_POSX = 0,
  17. ECS_NEGX,
  18. ECS_POSY,
  19. ECS_NEGY,
  20. ECS_POSZ,
  21. ECS_NEGZ
  22. };
  23. //! Interface of a Render Target.
  24. /** This is a framebuffer object (FBO) in OpenGL. */
  25. class IRenderTarget : public virtual IReferenceCounted
  26. {
  27. public:
  28. //! constructor
  29. IRenderTarget() :
  30. DepthStencil(0), DriverType(EDT_NULL)
  31. {
  32. }
  33. //! Returns an array of previously set textures.
  34. const core::array<ITexture *> &getTexture() const
  35. {
  36. return Textures;
  37. }
  38. //! Returns a of previously set depth / depth-stencil texture.
  39. ITexture *getDepthStencil() const
  40. {
  41. return DepthStencil;
  42. }
  43. //! Returns an array of active surface for cube textures
  44. const core::array<E_CUBE_SURFACE> &getCubeSurfaces() const
  45. {
  46. return CubeSurfaces;
  47. }
  48. //! Set multiple textures.
  49. /** Set multiple textures for the render target.
  50. \param texture Array of texture objects. These textures are used for a color outputs.
  51. \param depthStencil Depth or packed depth-stencil texture. This texture is used as depth
  52. or depth-stencil buffer. You can pass getDepthStencil() if you don't want to change it.
  53. \param cubeSurfaces When rendering to cube textures, set the surface to be used for each texture. Can be empty otherwise.
  54. */
  55. void setTexture(const core::array<ITexture *> &texture, ITexture *depthStencil, const core::array<E_CUBE_SURFACE> &cubeSurfaces = core::array<E_CUBE_SURFACE>())
  56. {
  57. setTextures(texture.const_pointer(), texture.size(), depthStencil, cubeSurfaces.const_pointer(), cubeSurfaces.size());
  58. }
  59. //! Sets one texture + depthStencil
  60. //! You can pass getDepthStencil() for depthStencil if you don't want to change that one
  61. void setTexture(ITexture *texture, ITexture *depthStencil)
  62. {
  63. if (texture) {
  64. setTextures(&texture, 1, depthStencil);
  65. } else {
  66. setTextures(0, 0, depthStencil);
  67. }
  68. }
  69. //! Set one cube surface texture.
  70. void setTexture(ITexture *texture, ITexture *depthStencil, E_CUBE_SURFACE cubeSurface)
  71. {
  72. if (texture) {
  73. setTextures(&texture, 1, depthStencil, &cubeSurface, 1);
  74. } else {
  75. setTextures(0, 0, depthStencil, &cubeSurface, 1);
  76. }
  77. }
  78. //! Get driver type of render target.
  79. E_DRIVER_TYPE getDriverType() const
  80. {
  81. return DriverType;
  82. }
  83. protected:
  84. //! Set multiple textures.
  85. // NOTE: working with pointers instead of arrays to avoid unnecessary memory allocations for the single textures case
  86. virtual void setTextures(ITexture *const *textures, u32 numTextures, ITexture *depthStencil, const E_CUBE_SURFACE *cubeSurfaces = 0, u32 numCubeSurfaces = 0) = 0;
  87. //! Textures assigned to render target.
  88. core::array<ITexture *> Textures;
  89. //! Depth or packed depth-stencil texture assigned to render target.
  90. ITexture *DepthStencil;
  91. //! Active surface of cube textures
  92. core::array<E_CUBE_SURFACE> CubeSurfaces;
  93. //! Driver type of render target.
  94. E_DRIVER_TYPE DriverType;
  95. private:
  96. // no copying (IReferenceCounted still allows that for reasons which take some time to work around)
  97. IRenderTarget(const IRenderTarget &);
  98. IRenderTarget &operator=(const IRenderTarget &);
  99. };
  100. }
  101. }