BsGLRenderTexture.h 3.6 KB

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