FrameBuffer.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. /**
  9. * Defines a video output off all graphics buffer containing a complete frame of data.
  10. * This consists of a RenderTarget and DepthStencilTarget holding the color, depth and
  11. * stencil data in the rendering frame.
  12. *
  13. * to change the default Game framebuffer call Game::setFrameBuffer(myFrameBuffer);
  14. * To restore back to the default call Game::setFrameBuffer(NULL).
  15. * This is useful for rendering shadows and other post-processing effects.
  16. */
  17. class FrameBuffer : public Ref
  18. {
  19. public:
  20. /**
  21. * Creates an empty FrameBuffer and adds it to the list of available FrameBuffers.
  22. *
  23. * @param id The ID of the new FrameBuffer. Uniqueness is recommended but not enforced.
  24. *
  25. * @return A newly created FrameBuffer.
  26. */
  27. static FrameBuffer* create(const char* id);
  28. /**
  29. * Creates a new FrameBuffer with a RenderTarget of the specified width and height,
  30. * and adds the FrameBuffer to the list of available FrameBuffers.
  31. *
  32. * @param id The ID of the new FrameBuffer. Uniqueness is recommended but not enforced.
  33. * @param width The width of the RenderTarget to be created and attached.
  34. * @param height The height of the RenderTarget to be created and attached.
  35. *
  36. * @return A newly created FrameBuffer.
  37. */
  38. static FrameBuffer* create(const char* id, unsigned int width, unsigned int height);
  39. /**
  40. * Get a named FrameBuffer from its ID.
  41. *
  42. * @param id The ID of the FrameBuffer to search for.
  43. *
  44. * @return The FrameBuffer with the specified ID, or NULL if one was not found.
  45. */
  46. static FrameBuffer* getFrameBuffer(const char* id);
  47. /**
  48. * Get the ID of this FrameBuffer.
  49. *
  50. * @return The ID of this FrameBuffer.
  51. */
  52. const char* getID() const;
  53. /**
  54. * Get the number of color attachments available on the current hardware.
  55. *
  56. * @return The number of color attachments available on the current hardware.
  57. */
  58. static unsigned int getMaxRenderTargets();
  59. /**
  60. * Set a RenderTarget on this FrameBuffer's color attachment at the specified index.
  61. *
  62. * @param target The RenderTarget to set.
  63. * @param index The index of the color attachment to set.
  64. */
  65. void setRenderTarget(RenderTarget* target, unsigned int index = 0);
  66. /**
  67. * Get the RenderTarget attached to the FrameBuffer's color attachment at the specified index.
  68. *
  69. * @param index The index of the color attachment to retrieve a RenderTarget from.
  70. *
  71. * @return The RenderTarget attached at the specified index.
  72. */
  73. RenderTarget* getRenderTarget(unsigned int index = 0) const;
  74. /**
  75. * Set this FrameBuffer's DepthStencilTarget.
  76. *
  77. * @param target The DepthStencilTarget to set on this FrameBuffer.
  78. */
  79. void setDepthStencilTarget(DepthStencilTarget* target);
  80. /**
  81. * Get this FrameBuffer's DepthStencilTarget.
  82. *
  83. * @return This FrameBuffer's DepthStencilTarget.
  84. */
  85. DepthStencilTarget* getDepthStencilTarget() const;
  86. /**
  87. * Binds this FrameBuffer for off-screen rendering.
  88. */
  89. void bind();
  90. /**
  91. * Binds the default FrameBuffer for rendering to the display.
  92. */
  93. static void bindDefault();
  94. private:
  95. /**
  96. * Constructor.
  97. */
  98. FrameBuffer(const char* id);
  99. /**
  100. * Destructor.
  101. */
  102. ~FrameBuffer();
  103. std::string _id;
  104. FrameBufferHandle _handle;
  105. RenderTarget** _renderTargets;
  106. DepthStencilTarget* _depthStencilTarget;
  107. };
  108. }
  109. #endif