BsGLRenderTexture.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __GLRENDERTEXTURE_H__
  25. #define __GLRENDERTEXTURE_H__
  26. #include "BsGLPrerequisites.h"
  27. #include "BsGLTexture.h"
  28. #include "BsGLFrameBufferObject.h"
  29. #include "BsModule.h"
  30. /// Extra GL constants
  31. #define GL_DEPTH24_STENCIL8_EXT 0x88F0
  32. namespace BansheeEngine
  33. {
  34. /** Base class for GL Render Textures
  35. */
  36. class BS_RSGL_EXPORT GLRenderTexture: public RenderTexture
  37. {
  38. public:
  39. virtual ~GLRenderTexture();
  40. bool requiresTextureFlipping() const { return true; }
  41. virtual void getCustomAttribute(const String& name, void* pData) const;
  42. protected:
  43. friend class GLTextureManager;
  44. GLRenderTexture();
  45. /**
  46. * @copydoc RenderTexture::initialize_internal().
  47. */
  48. void initialize_internal();
  49. /**
  50. * @copydoc RenderTexture::destroy_internal().
  51. */
  52. void destroy_internal();
  53. GLFrameBufferObject* mFB;
  54. };
  55. /**
  56. * @brief Manager/factory for RenderTextures.
  57. *
  58. * @note Must be initialized when RenderSystem is first started.
  59. */
  60. class BS_RSGL_EXPORT GLRTTManager : public Module<GLRTTManager>
  61. {
  62. public:
  63. GLRTTManager();
  64. ~GLRTTManager();
  65. /**
  66. * @brief Check if a certain format is usable as FBO rendertarget format.
  67. *
  68. * @note Thread safe.
  69. */
  70. bool checkFormat(PixelFormat format) { return mProps[format].valid; }
  71. /** Get a FBO without depth/stencil for temporary use, like blitting between textures.
  72. */
  73. GLuint getTemporaryFBO() { return mTempFBO; }
  74. /**
  75. * @brief Get the closest supported alternative format. If format is supported, returns format.
  76. *
  77. * @note Thread safe
  78. */
  79. virtual PixelFormat getSupportedAlternative(PixelFormat format);
  80. private:
  81. /** Frame Buffer Object properties for a certain texture format.
  82. */
  83. struct FormatProperties
  84. {
  85. bool valid; // This format can be used as RTT (FBO)
  86. /** Allowed modes/properties for this pixel format
  87. */
  88. struct Mode
  89. {
  90. UINT32 depth; // Depth format (0=no depth)
  91. UINT32 stencil; // Stencil format (0=no stencil)
  92. };
  93. Vector<Mode> modes;
  94. };
  95. /** Properties for all internal formats defined by the engine
  96. */
  97. FormatProperties mProps[PF_COUNT];
  98. /** Temporary FBO identifier
  99. */
  100. GLuint mTempFBO;
  101. /** Detect allowed FBO formats */
  102. void detectFBOFormats();
  103. GLuint _tryFormat(GLenum depthFormat, GLenum stencilFormat);
  104. bool _tryPackedFormat(GLenum packedFormat);
  105. };
  106. }
  107. #endif // __GLTEXTURE_H__