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