2
0

BsGLRenderTexture.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. /**
  10. * @brief OpenGL implementation of a render texture.
  11. */
  12. class BS_RSGL_EXPORT GLRenderTexture: public RenderTexture
  13. {
  14. public:
  15. virtual ~GLRenderTexture();
  16. /**
  17. * @copydoc RenderTexture::requiresTextureFlipping
  18. */
  19. bool requiresTextureFlipping() const { return true; }
  20. /**
  21. * @copydoc RenderTexture::getCustomAttribute
  22. */
  23. virtual void getCustomAttribute(const String& name, void* pData) const;
  24. protected:
  25. friend class GLTextureManager;
  26. GLRenderTexture();
  27. /**
  28. * @copydoc RenderTexture::initialize_internal
  29. */
  30. void initialize_internal();
  31. /**
  32. * @copydoc RenderTexture::destroy_internal
  33. */
  34. void destroy_internal();
  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. private:
  60. /**
  61. * Frame buffer object properties for a certain texture format.
  62. */
  63. struct FormatProperties
  64. {
  65. /**
  66. * Allowed modes/properties for this pixel format
  67. */
  68. struct Mode
  69. {
  70. UINT32 depth; /**< Depth format (0 = no depth). */
  71. UINT32 stencil; /**< Stencil format (0 = no stencil). */
  72. };
  73. Vector<Mode> modes;
  74. bool valid;
  75. };
  76. FormatProperties mProps[PF_COUNT];
  77. GLuint mTempFBO;
  78. /**
  79. * @brief Detect which internal formats are allowed to be used on render target
  80. * color or depth/stencil surfaces.
  81. */
  82. void detectFBOFormats();
  83. /**
  84. * @brief Checks are the specified depth & stencil formats compatible.
  85. */
  86. bool _tryFormat(GLenum depthFormat, GLenum stencilFormat);
  87. /**
  88. * @brief Checks is the specified packed format valid for using
  89. * in the render target.
  90. */
  91. bool _tryPackedFormat(GLenum packedFormat);
  92. };
  93. }