BsGLRenderTexture.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "BsGLPrerequisites.h"
  3. #include "BsGLTexture.h"
  4. #include "BsGLFrameBufferObject.h"
  5. #include "BsModule.h"
  6. // Extra GL constants
  7. #define GL_DEPTH24_STENCIL8_EXT 0x88F0
  8. namespace BansheeEngine
  9. {
  10. /** Base class for GL Render Textures
  11. */
  12. class BS_RSGL_EXPORT GLRenderTexture: public RenderTexture
  13. {
  14. public:
  15. virtual ~GLRenderTexture();
  16. bool requiresTextureFlipping() const { return true; }
  17. virtual void getCustomAttribute(const String& name, void* pData) const;
  18. protected:
  19. friend class GLTextureManager;
  20. GLRenderTexture();
  21. /**
  22. * @copydoc RenderTexture::initialize_internal().
  23. */
  24. void initialize_internal();
  25. /**
  26. * @copydoc RenderTexture::destroy_internal().
  27. */
  28. void destroy_internal();
  29. GLFrameBufferObject* mFB;
  30. };
  31. /**
  32. * @brief Manager/factory for RenderTextures.
  33. *
  34. * @note Must be initialized when RenderSystem is first started.
  35. */
  36. class BS_RSGL_EXPORT GLRTTManager : public Module<GLRTTManager>
  37. {
  38. public:
  39. GLRTTManager();
  40. ~GLRTTManager();
  41. /**
  42. * @brief Check if a certain format is usable as FBO rendertarget format.
  43. *
  44. * @note Thread safe.
  45. */
  46. bool checkFormat(PixelFormat format) { return mProps[format].valid; }
  47. /** Get a FBO without depth/stencil for temporary use, like blitting between textures.
  48. */
  49. GLuint getTemporaryFBO() { return mTempFBO; }
  50. /**
  51. * @brief Get the closest supported alternative format. If format is supported, returns format.
  52. *
  53. * @note Thread safe
  54. */
  55. virtual PixelFormat getSupportedAlternative(PixelFormat format);
  56. private:
  57. /** Frame Buffer Object properties for a certain texture format.
  58. */
  59. struct FormatProperties
  60. {
  61. bool valid; // This format can be used as RTT (FBO)
  62. /** Allowed modes/properties for this pixel format
  63. */
  64. struct Mode
  65. {
  66. UINT32 depth; // Depth format (0=no depth)
  67. UINT32 stencil; // Stencil format (0=no stencil)
  68. };
  69. Vector<Mode> modes;
  70. };
  71. /** Properties for all internal formats defined by the engine
  72. */
  73. FormatProperties mProps[PF_COUNT];
  74. /** Temporary FBO identifier
  75. */
  76. GLuint mTempFBO;
  77. /** Detect allowed FBO formats */
  78. void detectFBOFormats();
  79. GLuint _tryFormat(GLenum depthFormat, GLenum stencilFormat);
  80. bool _tryPackedFormat(GLenum packedFormat);
  81. };
  82. }