aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llrender/llrendertarget.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llrender/llrendertarget.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/llrender/llrendertarget.cpp')
-rw-r--r--linden/indra/llrender/llrendertarget.cpp185
1 files changed, 185 insertions, 0 deletions
diff --git a/linden/indra/llrender/llrendertarget.cpp b/linden/indra/llrender/llrendertarget.cpp
new file mode 100644
index 0000000..974e0a2
--- /dev/null
+++ b/linden/indra/llrender/llrendertarget.cpp
@@ -0,0 +1,185 @@
1/**
2 * @file llrendertarget.cpp
3 * @brief LLRenderTarget implementation
4 *
5 * $LicenseInfo:firstyear=2001&license=viewergpl$
6 *
7 * Copyright (c) 2001-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "linden_common.h"
33
34#include "llrendertarget.h"
35#include "llglimmediate.h"
36
37
38BOOL LLRenderTarget::sUseFBO = FALSE;
39
40LLRenderTarget::LLRenderTarget()
41{
42 mResX = mResY = mTex = mFBO = mDepth = 0;
43 mUseDepth = FALSE;
44 mUsage = GL_TEXTURE_2D;
45}
46
47LLRenderTarget::~LLRenderTarget()
48{
49 release();
50}
51
52void LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, BOOL depth, U32 usage, BOOL force_fbo)
53{
54 mResX = resx;
55 mResY = resy;
56
57 mUsage = usage;
58 mUseDepth = depth;
59 release();
60
61 glGenTextures(1, (GLuint *) &mTex);
62 glBindTexture(mUsage, mTex);
63 glTexImage2D(mUsage, 0, color_fmt, mResX, mResY, 0, color_fmt, GL_UNSIGNED_BYTE, NULL);
64
65 glTexParameteri(mUsage, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
66 glTexParameteri(mUsage, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
67
68 if (mUsage != GL_TEXTURE_RECTANGLE_ARB)
69 {
70 glTexParameteri(mUsage, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
71 glTexParameteri(mUsage, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
72 }
73 else
74 {
75 // ATI doesn't support mirrored repeat for rectangular textures.
76 glTexParameteri(mUsage, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
77 glTexParameteri(mUsage, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
78 }
79
80 stop_glerror();
81
82 if (sUseFBO || force_fbo)
83 {
84 if (depth)
85 {
86 glGenRenderbuffersEXT(1, (GLuint *) &mDepth);
87 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mDepth);
88 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT,mResX,mResY);
89 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
90 }
91
92 glGenFramebuffersEXT(1, (GLuint *) &mFBO);
93 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBO);
94
95 if (mDepth)
96 {
97 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
98 GL_RENDERBUFFER_EXT, mDepth);
99 }
100 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
101 mUsage, mTex, 0);
102
103
104 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
105 }
106}
107
108void LLRenderTarget::release()
109{
110 if (mFBO)
111 {
112 glDeleteFramebuffersEXT(1, (GLuint *) &mFBO);
113 mFBO = 0;
114 }
115
116 if (mTex)
117 {
118 glDeleteTextures(1, (GLuint *) &mTex);
119 mTex = 0;
120 }
121
122 if (mDepth)
123 {
124 glDeleteRenderbuffersEXT(1, (GLuint *) &mDepth);
125 mDepth = 0;
126 }
127}
128
129void LLRenderTarget::bindTarget()
130{
131 if (mFBO)
132 {
133 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBO);
134 }
135
136 glViewport(0, 0, mResX, mResY);
137}
138
139void LLRenderTarget::clear()
140{
141 U32 mask = GL_COLOR_BUFFER_BIT;
142 if (mUseDepth)
143 {
144 mask |= GL_DEPTH_BUFFER_BIT;
145 }
146 if (mFBO)
147 {
148 glClear(mask);
149 }
150 else
151 {
152 LLGLEnable scissor(GL_SCISSOR_TEST);
153 glScissor(0, 0, mResX, mResY);
154 glClear(mask);
155 }
156}
157
158void LLRenderTarget::bindTexture()
159{
160 glBindTexture(mUsage, mTex);
161}
162
163void LLRenderTarget::flush()
164{
165 gGL.flush();
166 if (!mFBO)
167 {
168 bindTexture();
169 glCopyTexSubImage2D(mUsage, 0, 0, 0, 0, 0, mResX, mResY);
170 }
171}
172
173BOOL LLRenderTarget::isComplete() const
174{
175 return (mTex || mDepth) ? TRUE : FALSE;
176}
177
178void LLRenderTarget::getViewport(S32* viewport)
179{
180 viewport[0] = 0;
181 viewport[1] = 0;
182 viewport[2] = mResX;
183 viewport[3] = mResY;
184}
185