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