BsGLRenderTexture.h 3.6 KB

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