PageRenderTime 155ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llrender/llrendertarget.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 158 lines | 50 code | 32 blank | 76 comment | 0 complexity | 8010487b3d1bf8666850acf2c5473edd MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llrendertarget.h
  3. * @brief Off screen render target abstraction. Loose wrapper for GL_EXT_framebuffer_objects.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLRENDERTARGET_H
  27. #define LL_LLRENDERTARGET_H
  28. // LLRenderTarget is unavailible on the mapserver since it uses FBOs.
  29. #if !LL_MESA_HEADLESS
  30. #include "llgl.h"
  31. #include "llrender.h"
  32. /*
  33. SAMPLE USAGE:
  34. LLRenderTarget target;
  35. ...
  36. //allocate a 256x256 RGBA render target with depth buffer
  37. target.allocate(256,256,GL_RGBA,TRUE);
  38. //render to contents of offscreen buffer
  39. target.bindTarget();
  40. target.clear();
  41. ... <issue drawing commands> ...
  42. target.flush();
  43. ...
  44. //use target as a texture
  45. gGL.getTexUnit(INDEX)->bind(&target);
  46. ... <issue drawing commands> ...
  47. */
  48. class LLMultisampleBuffer;
  49. class LLRenderTarget
  50. {
  51. public:
  52. //whether or not to use FBO implementation
  53. static bool sUseFBO;
  54. static U32 sBytesAllocated;
  55. LLRenderTarget();
  56. ~LLRenderTarget();
  57. //allocate resources for rendering
  58. //must be called before use
  59. //multiple calls will release previously allocated resources
  60. bool allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, bool stencil, LLTexUnit::eTextureType usage = LLTexUnit::TT_TEXTURE, bool use_fbo = false, S32 samples = 0);
  61. //add color buffer attachment
  62. //limit of 4 color attachments per render target
  63. bool addColorAttachment(U32 color_fmt);
  64. //allocate a depth texture
  65. bool allocateDepth();
  66. //share depth buffer with provided render target
  67. void shareDepthBuffer(LLRenderTarget& target);
  68. //free any allocated resources
  69. //safe to call redundantly
  70. void release();
  71. //bind target for rendering
  72. //applies appropriate viewport
  73. void bindTarget();
  74. //unbind target for rendering
  75. static void unbindTarget();
  76. //clear render targer, clears depth buffer if present,
  77. //uses scissor rect if in copy-to-texture mode
  78. void clear(U32 mask = 0xFFFFFFFF);
  79. //get applied viewport
  80. void getViewport(S32* viewport);
  81. //get X resolution
  82. U32 getWidth() const { return mResX; }
  83. //get Y resolution
  84. U32 getHeight() const { return mResY; }
  85. LLTexUnit::eTextureType getUsage(void) const { return mUsage; }
  86. U32 getTexture(U32 attachment = 0) const;
  87. U32 getDepth(void) const { return mDepth; }
  88. bool hasStencil() const { return mStencil; }
  89. void bindTexture(U32 index, S32 channel);
  90. //flush rendering operations
  91. //must be called when rendering is complete
  92. //should be used 1:1 with bindTarget
  93. // call bindTarget once, do all your rendering, call flush once
  94. // if fetch_depth is TRUE, every effort will be made to copy the depth buffer into
  95. // the current depth texture. A depth texture will be allocated if needed.
  96. void flush(bool fetch_depth = FALSE);
  97. void copyContents(LLRenderTarget& source, S32 srcX0, S32 srcY0, S32 srcX1, S32 srcY1,
  98. S32 dstX0, S32 dstY0, S32 dstX1, S32 dstY1, U32 mask, U32 filter);
  99. static void copyContentsToFramebuffer(LLRenderTarget& source, S32 srcX0, S32 srcY0, S32 srcX1, S32 srcY1,
  100. S32 dstX0, S32 dstY0, S32 dstX1, S32 dstY1, U32 mask, U32 filter);
  101. //Returns TRUE if target is ready to be rendered into.
  102. //That is, if the target has been allocated with at least
  103. //one renderable attachment (i.e. color buffer, depth buffer).
  104. bool isComplete() const;
  105. static LLRenderTarget* getCurrentBoundTarget() { return sBoundTarget; }
  106. protected:
  107. U32 mResX;
  108. U32 mResY;
  109. std::vector<U32> mTex;
  110. U32 mFBO;
  111. U32 mDepth;
  112. bool mStencil;
  113. bool mUseDepth;
  114. bool mRenderDepth;
  115. LLTexUnit::eTextureType mUsage;
  116. static LLRenderTarget* sBoundTarget;
  117. };
  118. #endif //!LL_MESA_HEADLESS
  119. #endif