BsGLRenderTexture.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsGLPrerequisites.h"
  5. #include "BsGLTexture.h"
  6. #include "BsGLFrameBufferObject.h"
  7. #include "BsModule.h"
  8. #define GL_DEPTH24_STENCIL8_EXT 0x88F0
  9. namespace BansheeEngine
  10. {
  11. /** @addtogroup GL
  12. * @{
  13. */
  14. class GLRenderTexture;
  15. /**
  16. * OpenGL implementation of a render texture.
  17. *
  18. * @note Core thread only.
  19. */
  20. class BS_RSGL_EXPORT GLRenderTextureCore : public RenderTextureCore
  21. {
  22. public:
  23. GLRenderTextureCore(const RENDER_TEXTURE_DESC_CORE& desc);
  24. virtual ~GLRenderTextureCore();
  25. /** @copydoc RenderTextureCore::getCustomAttribute */
  26. void getCustomAttribute(const String& name, void* data) const override;
  27. protected:
  28. friend class GLRenderTexture;
  29. /** @copydoc RenderTextureCore::initialize */
  30. void initialize() override;
  31. /** @copydoc RenderTextureCore::getProperties */
  32. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  33. RenderTextureProperties mProperties;
  34. GLFrameBufferObject* mFB;
  35. };
  36. /**
  37. * Manager that handles valid render texture formats.
  38. *
  39. * @note Must be initialized when RenderSystem is first started.
  40. */
  41. class BS_RSGL_EXPORT GLRTTManager : public Module<GLRTTManager>
  42. {
  43. public:
  44. GLRTTManager();
  45. ~GLRTTManager();
  46. /**
  47. * Check if a certain format is usable as a render target format.
  48. *
  49. * @note Thread safe.
  50. */
  51. bool checkFormat(PixelFormat format) const { return mProps[format].valid; }
  52. /**
  53. * Get the closest supported alternative format. If format is supported, returns format.
  54. *
  55. * @note Thread safe.
  56. */
  57. virtual PixelFormat getSupportedAlternative(PixelFormat format);
  58. /** Returns a persistent FBO that is used as a source buffer for blit operations. */
  59. GLuint getBlitReadFBO() const { return mBlitReadFBO; }
  60. /** Returns a persistent FBO that is used as a destination buffer for blit operations. */
  61. GLuint getBlitDrawFBO() const { return mBlitWriteFBO; }
  62. private:
  63. /** Frame buffer object properties for a certain texture format. */
  64. struct FormatProperties
  65. {
  66. /** Allowed modes/properties for this pixel format. */
  67. struct Mode
  68. {
  69. UINT32 depth; /**< Depth format (0 = no depth). */
  70. UINT32 stencil; /**< Stencil format (0 = no stencil). */
  71. };
  72. Vector<Mode> modes;
  73. bool valid;
  74. };
  75. /** Detect which internal formats are allowed to be used on render target color or depth/stencil surfaces. */
  76. void detectFBOFormats();
  77. /** Checks are the specified depth & stencil formats compatible. */
  78. bool _tryFormat(GLenum depthFormat, GLenum stencilFormat);
  79. /** Checks is the specified packed format valid for using in the render target. */
  80. bool _tryPackedFormat(GLenum packedFormat);
  81. FormatProperties mProps[PF_COUNT];
  82. GLuint mBlitReadFBO;
  83. GLuint mBlitWriteFBO;
  84. };
  85. /**
  86. * OpenGL implementation of a render texture.
  87. *
  88. * @note Sim thread only.
  89. */
  90. class GLRenderTexture : public RenderTexture
  91. {
  92. public:
  93. virtual ~GLRenderTexture() { }
  94. protected:
  95. friend class GLTextureManager;
  96. GLRenderTexture(const RENDER_TEXTURE_DESC& desc);
  97. /** @copydoc RenderTexture::getProperties */
  98. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  99. RenderTextureProperties mProperties;
  100. };
  101. /** @} */
  102. }