BsGLRenderTexture.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsGLPrerequisites.h"
  6. #include "BsGLTexture.h"
  7. #include "BsGLFrameBufferObject.h"
  8. #include "BsModule.h"
  9. #define GL_DEPTH24_STENCIL8_EXT 0x88F0
  10. namespace BansheeEngine
  11. {
  12. /**
  13. * @brief OpenGL implementation of a render texture.
  14. */
  15. class BS_RSGL_EXPORT GLRenderTexture: public RenderTexture
  16. {
  17. public:
  18. virtual ~GLRenderTexture();
  19. /**
  20. * @copydoc RenderTexture::requiresTextureFlipping
  21. */
  22. bool requiresTextureFlipping() const { return true; }
  23. /**
  24. * @copydoc RenderTexture::getCustomAttribute
  25. */
  26. virtual void getCustomAttribute(const String& name, void* pData) const;
  27. protected:
  28. friend class GLTextureManager;
  29. GLRenderTexture();
  30. /**
  31. * @copydoc RenderTexture::initialize_internal
  32. */
  33. void initialize_internal();
  34. /**
  35. * @copydoc RenderTexture::destroy_internal
  36. */
  37. void destroy_internal();
  38. GLFrameBufferObject* mFB;
  39. };
  40. /**
  41. * @brief Manager that handles valid render texture formats.
  42. *
  43. * @note Must be initialized when RenderSystem is first started.
  44. */
  45. class BS_RSGL_EXPORT GLRTTManager : public Module<GLRTTManager>
  46. {
  47. public:
  48. GLRTTManager();
  49. ~GLRTTManager();
  50. /**
  51. * @brief Check if a certain format is usable as a render target format.
  52. *
  53. * @note Thread safe.
  54. */
  55. bool checkFormat(PixelFormat format) { return mProps[format].valid; }
  56. /**
  57. * @brief Get the closest supported alternative format. If format is supported, returns format.
  58. *
  59. * @note Thread safe.
  60. */
  61. virtual PixelFormat getSupportedAlternative(PixelFormat format);
  62. private:
  63. /**
  64. * Frame buffer object properties for a certain texture format.
  65. */
  66. struct FormatProperties
  67. {
  68. /**
  69. * Allowed modes/properties for this pixel format
  70. */
  71. struct Mode
  72. {
  73. UINT32 depth; /**< Depth format (0 = no depth). */
  74. UINT32 stencil; /**< Stencil format (0 = no stencil). */
  75. };
  76. Vector<Mode> modes;
  77. bool valid;
  78. };
  79. FormatProperties mProps[PF_COUNT];
  80. GLuint mTempFBO;
  81. /**
  82. * @brief Detect which internal formats are allowed to be used on render target
  83. * color or depth/stencil surfaces.
  84. */
  85. void detectFBOFormats();
  86. /**
  87. * @brief Checks are the specified depth & stencil formats compatible.
  88. */
  89. bool _tryFormat(GLenum depthFormat, GLenum stencilFormat);
  90. /**
  91. * @brief Checks is the specified packed format valid for using
  92. * in the render target.
  93. */
  94. bool _tryPackedFormat(GLenum packedFormat);
  95. };
  96. }