BsGLRenderTexture.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. GLFrameBufferObject* mFB;
  28. };
  29. /**
  30. * @brief OpenGL implementation of a render texture.
  31. *
  32. * @note Sim thread only.
  33. */
  34. class BS_RSGL_EXPORT GLRenderTexture : public RenderTexture
  35. {
  36. public:
  37. virtual ~GLRenderTexture() { }
  38. protected:
  39. friend class GLTextureManager;
  40. GLRenderTexture() { }
  41. /**
  42. * @copydoc RenderTexture::requiresTextureFlipping
  43. */
  44. bool requiresTextureFlipping() const { return true; }
  45. /**
  46. * @copydoc RenderTexture::createProperties
  47. */
  48. virtual RenderTargetProperties* createProperties() const;
  49. /**
  50. * @copydoc RenderTexture::createCore
  51. */
  52. virtual RenderTextureCore* createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
  53. const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
  54. };
  55. /**
  56. * @brief Manager that handles valid render texture formats.
  57. *
  58. * @note Must be initialized when RenderSystem is first started.
  59. */
  60. class BS_RSGL_EXPORT GLRTTManager : public Module<GLRTTManager>
  61. {
  62. public:
  63. GLRTTManager();
  64. ~GLRTTManager();
  65. /**
  66. * @brief Check if a certain format is usable as a render target format.
  67. *
  68. * @note Thread safe.
  69. */
  70. bool checkFormat(PixelFormat format) { return mProps[format].valid; }
  71. /**
  72. * @brief Get the closest supported alternative format. If format is supported, returns format.
  73. *
  74. * @note Thread safe.
  75. */
  76. virtual PixelFormat getSupportedAlternative(PixelFormat format);
  77. /**
  78. * @brief Returns a persistent FBO that is used as a
  79. * source buffer for blit operations.
  80. */
  81. GLuint getBlitReadFBO() const { return mBlitReadFBO; }
  82. /**
  83. * @brief Returns a persistent FBO that is used as a
  84. * destination buffer for blit operations.
  85. */
  86. GLuint getBlitDrawFBO() const { return mBlitWriteFBO; }
  87. private:
  88. /**
  89. * Frame buffer object properties for a certain texture format.
  90. */
  91. struct FormatProperties
  92. {
  93. /**
  94. * Allowed modes/properties for this pixel format
  95. */
  96. struct Mode
  97. {
  98. UINT32 depth; /**< Depth format (0 = no depth). */
  99. UINT32 stencil; /**< Stencil format (0 = no stencil). */
  100. };
  101. Vector<Mode> modes;
  102. bool valid;
  103. };
  104. /**
  105. * @brief Detect which internal formats are allowed to be used on render target
  106. * color or depth/stencil surfaces.
  107. */
  108. void detectFBOFormats();
  109. /**
  110. * @brief Checks are the specified depth & stencil formats compatible.
  111. */
  112. bool _tryFormat(GLenum depthFormat, GLenum stencilFormat);
  113. /**
  114. * @brief Checks is the specified packed format valid for using
  115. * in the render target.
  116. */
  117. bool _tryPackedFormat(GLenum packedFormat);
  118. FormatProperties mProps[PF_COUNT];
  119. GLuint mBlitReadFBO;
  120. GLuint mBlitWriteFBO;
  121. };
  122. }