FrameBuffer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef FRAMEBUFFER_H_
  2. #define FRAMEBUFFER_H_
  3. #include "Base.h"
  4. #include "RenderTarget.h"
  5. #include "DepthStencilTarget.h"
  6. namespace gameplay
  7. {
  8. class FrameBuffer : public Ref
  9. {
  10. public:
  11. /**
  12. * Creates an empty FrameBuffer and adds it to the list of available FrameBuffers.
  13. *
  14. * @param id The ID of the new FrameBuffer. Uniqueness is recommended but not enforced.
  15. *
  16. * @return A newly created FrameBuffer.
  17. */
  18. static FrameBuffer* create(const char* id);
  19. /**
  20. * Creates a new FrameBuffer with a RenderTarget of the specified width and height,
  21. * and adds the FrameBuffer to the list of available FrameBuffers.
  22. *
  23. * @param id The ID of the new FrameBuffer. Uniqueness is recommended but not enforced.
  24. * @param width The width of the RenderTarget to be created and attached.
  25. * @param height The height of the RenderTarget to be created and attached.
  26. *
  27. * @return A newly created FrameBuffer.
  28. */
  29. static FrameBuffer* create(const char* id, unsigned int width, unsigned int height);
  30. /**
  31. * Get a named FrameBuffer from its ID.
  32. *
  33. * @param id The ID of the FrameBuffer to search for.
  34. *
  35. * @return The FrameBuffer with the specified ID, or NULL if one was not found.
  36. */
  37. static FrameBuffer* getFrameBuffer(const char* id);
  38. /**
  39. * Get the ID of this FrameBuffer.
  40. *
  41. * @return The ID of this FrameBuffer.
  42. */
  43. const char* getID() const;
  44. /**
  45. * Get the number of color attachments available on the current hardware.
  46. *
  47. * @return The number of color attachments available on the current hardware.
  48. */
  49. static unsigned int getMaxRenderTargets();
  50. /**
  51. * Set a RenderTarget on this FrameBuffer's color attachment at the specified index.
  52. *
  53. * @param target The RenderTarget to set.
  54. * @param index The index of the color attachment to set.
  55. */
  56. void setRenderTarget(RenderTarget* target, unsigned int index = 0);
  57. /**
  58. * Get the RenderTarget attached to the FrameBuffer's color attachment at the specified index.
  59. *
  60. * @param index The index of the color attachment to retrieve a RenderTarget from.
  61. *
  62. * @return The RenderTarget attached at the specified index.
  63. */
  64. RenderTarget* getRenderTarget(unsigned int index = 0) const;
  65. /**
  66. * Set this FrameBuffer's DepthStencilTarget.
  67. *
  68. * @param target The DepthStencilTarget to set on this FrameBuffer.
  69. */
  70. void setDepthStencilTarget(DepthStencilTarget* target);
  71. /**
  72. * Get this FrameBuffer's DepthStencilTarget.
  73. *
  74. * @return This FrameBuffer's DepthStencilTarget.
  75. */
  76. DepthStencilTarget* getDepthStencilTarget() const;
  77. /**
  78. * Binds this FrameBuffer for off-screen rendering.
  79. */
  80. void bind();
  81. /**
  82. * Binds the default FrameBuffer for rendering to the display.
  83. */
  84. static void bindDefault();
  85. private:
  86. FrameBuffer(const char* id);
  87. /**
  88. * Destructor. Removes this FrameBuffer from the list of available FrameBuffers.
  89. */
  90. ~FrameBuffer();
  91. std::string _id;
  92. FrameBufferHandle _handle;
  93. RenderTarget** _renderTargets;
  94. DepthStencilTarget* _depthStencilTarget;
  95. };
  96. }
  97. #endif