gfxGLTextureTarget.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GFXGLTEXTURETARGET_H_
  23. #define _GFXGLTEXTURETARGET_H_
  24. #include "gfx/gfxTarget.h"
  25. #include "core/util/autoPtr.h"
  26. class GFXGLTextureObject;
  27. class _GFXGLTargetDesc;
  28. class _GFXGLTextureTargetImpl;
  29. /// Render to texture support for OpenGL.
  30. /// This class needs to make a number of assumptions due to the requirements
  31. /// and complexity of render to texture in OpenGL.
  32. /// 1) This class is only guaranteed to work with 2D textures or cubemaps. 3D textures
  33. /// may or may not work.
  34. /// 2) This class does not currently support multiple texture targets. Regardless
  35. /// of how many targets you bind, only Color0 will be used.
  36. /// 3) This class requires that the DepthStencil and Color0 targets have identical
  37. /// dimensions.
  38. /// 4) If the DepthStencil target is GFXTextureTarget::sDefaultStencil, then the
  39. /// Color0 target should be the same size as the current backbuffer and should also
  40. /// be the same format (typically R8G8B8A8)
  41. class GFXGLTextureTarget : public GFXTextureTarget
  42. {
  43. public:
  44. GFXGLTextureTarget(bool genMips);
  45. virtual ~GFXGLTextureTarget();
  46. virtual const Point2I getSize();
  47. virtual GFXFormat getFormat();
  48. virtual void attachTexture(RenderSlot slot, GFXTextureObject *tex, U32 mipLevel=0, U32 zOffset = 0);
  49. virtual void attachTexture(RenderSlot slot, GFXCubemap *tex, U32 face, U32 mipLevel=0);
  50. virtual void clearAttachments();
  51. /// Functions to query internal state
  52. /// @{
  53. /// Returns the internal structure for the given slot. This should only be called by our internal implementations.
  54. _GFXGLTargetDesc* getTargetDesc(RenderSlot slot) const;
  55. /// @}
  56. void deactivate();
  57. void zombify();
  58. void resurrect();
  59. virtual const String describeSelf() const;
  60. virtual void resolve();
  61. virtual void resolveTo(GFXTextureObject* obj);
  62. protected:
  63. friend class GFXGLDevice;
  64. /// The callback used to get texture events.
  65. /// @see GFXTextureManager::addEventDelegate
  66. void _onTextureEvent( GFXTexCallbackCode code );
  67. /// Pointer to our internal implementation
  68. AutoPtr<_GFXGLTextureTargetImpl> _impl;
  69. /// Array of _GFXGLTargetDesc's, an internal struct used to keep track of texture data.
  70. AutoPtr<_GFXGLTargetDesc> mTargets[MaxRenderSlotId];
  71. /// These redirect to our internal implementation
  72. /// @{
  73. void applyState();
  74. void makeActive();
  75. /// @}
  76. //copy FBO
  77. GLuint mCopyFboSrc, mCopyFboDst;
  78. };
  79. #endif