CmGLRenderTexture.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "CmGLPrerequisites.h"
  27. #include "CmGLTexture.h"
  28. #include "CmGLFrameBufferObject.h"
  29. #include "CmModule.h"
  30. /// Extra GL constants
  31. #define GL_DEPTH24_STENCIL8_EXT 0x88F0
  32. namespace CamelotFramework
  33. {
  34. /** Base class for GL Render Textures
  35. */
  36. class CM_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. /** Manager/factory for RenderTextures.
  56. */
  57. class CM_RSGL_EXPORT GLRTTManager : public Module<GLRTTManager>
  58. {
  59. public:
  60. GLRTTManager();
  61. ~GLRTTManager();
  62. /** Check if a certain format is usable as FBO rendertarget format
  63. */
  64. bool checkFormat(PixelFormat format) { return mProps[format].valid; }
  65. /** Get a FBO without depth/stencil for temporary use, like blitting between textures.
  66. */
  67. GLuint getTemporaryFBO() { return mTempFBO; }
  68. /** Get the closest supported alternative format. If format is supported, returns format.
  69. */
  70. virtual PixelFormat getSupportedAlternative(PixelFormat format);
  71. private:
  72. /** Frame Buffer Object properties for a certain texture format.
  73. */
  74. struct FormatProperties
  75. {
  76. bool valid; // This format can be used as RTT (FBO)
  77. /** Allowed modes/properties for this pixel format
  78. */
  79. struct Mode
  80. {
  81. UINT32 depth; // Depth format (0=no depth)
  82. UINT32 stencil; // Stencil format (0=no stencil)
  83. };
  84. Vector<Mode>::type modes;
  85. };
  86. /** Properties for all internal formats defined by the engine
  87. */
  88. FormatProperties mProps[PF_COUNT];
  89. /** Temporary FBO identifier
  90. */
  91. GLuint mTempFBO;
  92. /** Detect allowed FBO formats */
  93. void detectFBOFormats();
  94. GLuint _tryFormat(GLenum depthFormat, GLenum stencilFormat);
  95. bool _tryPackedFormat(GLenum packedFormat);
  96. };
  97. }
  98. #endif // __GLTEXTURE_H__