BsGLRenderTexture.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #pragma once
  2. #include "BsGLPrerequisites.h"
  3. #include "BsGLTexture.h"
  4. #include "BsGLFrameBufferObject.h"
  5. #include "BsModule.h"
  6. #define GL_DEPTH24_STENCIL8_EXT 0x88F0
  7. namespace BansheeEngine
  8. {
  9. class GLRenderTexture;
  10. /**
  11. * @brief OpenGL implementation of a render texture.
  12. *
  13. * @note Core thread only.
  14. */
  15. class BS_RSGL_EXPORT GLRenderTextureCore : public RenderTextureCore
  16. {
  17. public:
  18. GLRenderTextureCore(GLRenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
  19. const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
  20. virtual ~GLRenderTextureCore();
  21. /**
  22. * @copydoc RenderTextureCore::getCustomAttribute
  23. */
  24. virtual void getCustomAttribute(const String& name, void* pData) const;
  25. protected:
  26. friend class GLRenderTexture;
  27. /**
  28. * @copydoc CoreObjectCore::initialize
  29. */
  30. virtual void initialize();
  31. /**
  32. * @copydoc CoreObjectCore::destroy
  33. */
  34. virtual void destroy();
  35. GLFrameBufferObject* mFB;
  36. };
  37. /**
  38. * @brief OpenGL implementation of a render texture.
  39. *
  40. * @note Sim thread only.
  41. */
  42. class BS_RSGL_EXPORT GLRenderTexture : public RenderTexture
  43. {
  44. public:
  45. virtual ~GLRenderTexture() { }
  46. protected:
  47. friend class GLTextureManager;
  48. GLRenderTexture() { }
  49. /**
  50. * @copydoc RenderTexture::requiresTextureFlipping
  51. */
  52. bool requiresTextureFlipping() const { return true; }
  53. /**
  54. * @copydoc RenderTexture::createProperties
  55. */
  56. virtual RenderTargetProperties* createProperties() const;
  57. /**
  58. * @copydoc RenderTexture::createCore
  59. */
  60. virtual CoreObjectCore* createCore() const;
  61. };
  62. /**
  63. * @brief Manager that handles valid render texture formats.
  64. *
  65. * @note Must be initialized when RenderSystem is first started.
  66. */
  67. class BS_RSGL_EXPORT GLRTTManager : public Module<GLRTTManager>
  68. {
  69. public:
  70. GLRTTManager();
  71. ~GLRTTManager();
  72. /**
  73. * @brief Check if a certain format is usable as a render target format.
  74. *
  75. * @note Thread safe.
  76. */
  77. bool checkFormat(PixelFormat format) { return mProps[format].valid; }
  78. /**
  79. * @brief Get the closest supported alternative format. If format is supported, returns format.
  80. *
  81. * @note Thread safe.
  82. */
  83. virtual PixelFormat getSupportedAlternative(PixelFormat format);
  84. /**
  85. * @brief Returns a persistent FBO that is used as a
  86. * source buffer for blit operations.
  87. */
  88. GLuint getBlitReadFBO() const { return mBlitReadFBO; }
  89. /**
  90. * @brief Returns a persistent FBO that is used as a
  91. * destination buffer for blit operations.
  92. */
  93. GLuint getBlitDrawFBO() const { return mBlitWriteFBO; }
  94. private:
  95. /**
  96. * Frame buffer object properties for a certain texture format.
  97. */
  98. struct FormatProperties
  99. {
  100. /**
  101. * Allowed modes/properties for this pixel format
  102. */
  103. struct Mode
  104. {
  105. UINT32 depth; /**< Depth format (0 = no depth). */
  106. UINT32 stencil; /**< Stencil format (0 = no stencil). */
  107. };
  108. Vector<Mode> modes;
  109. bool valid;
  110. };
  111. /**
  112. * @brief Detect which internal formats are allowed to be used on render target
  113. * color or depth/stencil surfaces.
  114. */
  115. void detectFBOFormats();
  116. /**
  117. * @brief Checks are the specified depth & stencil formats compatible.
  118. */
  119. bool _tryFormat(GLenum depthFormat, GLenum stencilFormat);
  120. /**
  121. * @brief Checks is the specified packed format valid for using
  122. * in the render target.
  123. */
  124. bool _tryPackedFormat(GLenum packedFormat);
  125. FormatProperties mProps[PF_COUNT];
  126. GLuint mBlitReadFBO;
  127. GLuint mBlitWriteFBO;
  128. };
  129. }