PageRenderTime 22ms CodeModel.GetById 8ms app.highlight 10ms RepoModel.GetById 1ms 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
  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
 27#ifndef LL_LLRENDERTARGET_H
 28#define LL_LLRENDERTARGET_H
 29
 30// LLRenderTarget is unavailible on the mapserver since it uses FBOs.
 31#if !LL_MESA_HEADLESS
 32
 33#include "llgl.h"
 34#include "llrender.h"
 35
 36/*
 37 SAMPLE USAGE:
 38
 39	LLRenderTarget target;
 40
 41	...
 42
 43	//allocate a 256x256 RGBA render target with depth buffer
 44	target.allocate(256,256,GL_RGBA,TRUE);
 45
 46	//render to contents of offscreen buffer
 47	target.bindTarget();
 48	target.clear();
 49	... <issue drawing commands> ...
 50	target.flush();
 51
 52	...
 53
 54	//use target as a texture
 55	gGL.getTexUnit(INDEX)->bind(&target);
 56	... <issue drawing commands> ...
 57
 58*/
 59
 60class LLMultisampleBuffer;
 61
 62class LLRenderTarget
 63{
 64public:
 65	//whether or not to use FBO implementation
 66	static bool sUseFBO; 
 67	static U32 sBytesAllocated;
 68
 69	LLRenderTarget();
 70	~LLRenderTarget();
 71
 72	//allocate resources for rendering
 73	//must be called before use
 74	//multiple calls will release previously allocated resources
 75	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);
 76
 77	//add color buffer attachment
 78	//limit of 4 color attachments per render target
 79	bool addColorAttachment(U32 color_fmt);
 80
 81	//allocate a depth texture
 82	bool allocateDepth();
 83
 84	//share depth buffer with provided render target
 85	void shareDepthBuffer(LLRenderTarget& target);
 86
 87	//free any allocated resources
 88	//safe to call redundantly
 89	void release();
 90
 91	//bind target for rendering
 92	//applies appropriate viewport
 93	void bindTarget();
 94
 95	//unbind target for rendering
 96	static void unbindTarget();
 97	
 98	//clear render targer, clears depth buffer if present,
 99	//uses scissor rect if in copy-to-texture mode
100	void clear(U32 mask = 0xFFFFFFFF);
101	
102	//get applied viewport
103	void getViewport(S32* viewport);
104
105	//get X resolution
106	U32 getWidth() const { return mResX; }
107
108	//get Y resolution
109	U32 getHeight() const { return mResY; }
110
111	LLTexUnit::eTextureType getUsage(void) const { return mUsage; }
112
113	U32 getTexture(U32 attachment = 0) const;
114
115	U32 getDepth(void) const { return mDepth; }
116	bool hasStencil() const { return mStencil; }
117
118	void bindTexture(U32 index, S32 channel);
119
120	//flush rendering operations
121	//must be called when rendering is complete
122	//should be used 1:1 with bindTarget 
123	// call bindTarget once, do all your rendering, call flush once
124	// if fetch_depth is TRUE, every effort will be made to copy the depth buffer into 
125	// the current depth texture.  A depth texture will be allocated if needed.
126	void flush(bool fetch_depth = FALSE);
127
128	void copyContents(LLRenderTarget& source, S32 srcX0, S32 srcY0, S32 srcX1, S32 srcY1,
129						S32 dstX0, S32 dstY0, S32 dstX1, S32 dstY1, U32 mask, U32 filter);
130
131	static void copyContentsToFramebuffer(LLRenderTarget& source, S32 srcX0, S32 srcY0, S32 srcX1, S32 srcY1,
132						S32 dstX0, S32 dstY0, S32 dstX1, S32 dstY1, U32 mask, U32 filter);
133
134	//Returns TRUE if target is ready to be rendered into.
135	//That is, if the target has been allocated with at least
136	//one renderable attachment (i.e. color buffer, depth buffer).
137	bool isComplete() const;
138
139	static LLRenderTarget* getCurrentBoundTarget() { return sBoundTarget; }
140
141protected:
142	U32 mResX;
143	U32 mResY;
144	std::vector<U32> mTex;
145	U32 mFBO;
146	U32 mDepth;
147	bool mStencil;
148	bool mUseDepth;
149	bool mRenderDepth;
150	LLTexUnit::eTextureType mUsage;
151	
152	static LLRenderTarget* sBoundTarget;
153};
154
155#endif //!LL_MESA_HEADLESS
156
157#endif
158