aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lldynamictexture.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/lldynamictexture.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/lldynamictexture.cpp')
-rw-r--r--linden/indra/newview/lldynamictexture.cpp234
1 files changed, 234 insertions, 0 deletions
diff --git a/linden/indra/newview/lldynamictexture.cpp b/linden/indra/newview/lldynamictexture.cpp
new file mode 100644
index 0000000..6111e36
--- /dev/null
+++ b/linden/indra/newview/lldynamictexture.cpp
@@ -0,0 +1,234 @@
1/**
2 * @file lldynamictexture.cpp
3 * @brief Implementation of LLDynamicTexture class
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "lldynamictexture.h"
31#include "linked_lists.h"
32#include "llimagegl.h"
33#include "llglheaders.h"
34#include "llviewerwindow.h"
35#include "llviewercamera.h"
36#include "llviewercontrol.h"
37#include "llviewerimage.h"
38
39// static
40LLLinkedList<LLDynamicTexture> LLDynamicTexture::sInstances[ LLDynamicTexture::ORDER_COUNT ];
41S32 LLDynamicTexture::sNumRenders = 0;
42
43//-----------------------------------------------------------------------------
44// LLDynamicTexture()
45//-----------------------------------------------------------------------------
46LLDynamicTexture::LLDynamicTexture(S32 width, S32 height, S32 components, EOrder order, BOOL clamp) :
47 mWidth(width),
48 mHeight(height),
49 mComponents(components),
50 mTexture(NULL),
51 mLastBindTime(0),
52 mClamp(clamp)
53{
54 llassert((1 <= components) && (components <= 4));
55
56 generateGLTexture();
57
58 llassert( 0 <= order && order < ORDER_COUNT );
59 LLDynamicTexture::sInstances[ order ].addData(this);
60}
61
62//-----------------------------------------------------------------------------
63// LLDynamicTexture()
64//-----------------------------------------------------------------------------
65LLDynamicTexture::~LLDynamicTexture()
66{
67 for( S32 order = 0; order < ORDER_COUNT; order++ )
68 {
69 LLDynamicTexture::sInstances[order].removeData(this); // will fail in all but one case.
70 }
71}
72
73//-----------------------------------------------------------------------------
74// generateGLTexture()
75//-----------------------------------------------------------------------------
76void LLDynamicTexture::generateGLTexture()
77{
78 if (mComponents < 1 || mComponents > 4)
79 {
80 llerrs << "Bad number of components in dynamic texture: " << mComponents << llendl;
81 }
82
83 LLPointer<LLImageRaw> raw_image = new LLImageRaw(mWidth, mHeight, mComponents);
84 mTexture = new LLImageGL(mWidth, mHeight, mComponents, FALSE);
85 mTexture->createGLTexture(0, raw_image);
86 mTexture->setClamp(mClamp, mClamp);
87}
88
89void LLDynamicTexture::generateGLTexture(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format, BOOL swap_bytes)
90{
91 if (mComponents < 1 || mComponents > 4)
92 {
93 llerrs << "Bad number of components in dynamic texture: " << mComponents << llendl;
94 }
95
96 LLPointer<LLImageRaw> raw_image = new LLImageRaw(mWidth, mHeight, mComponents);
97 mTexture = new LLImageGL(mWidth, mHeight, mComponents, FALSE);
98 mTexture->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes);
99 mTexture->createGLTexture(0, raw_image);
100 mTexture->setClamp(mClamp, mClamp);
101}
102
103//-----------------------------------------------------------------------------
104// render()
105//-----------------------------------------------------------------------------
106BOOL LLDynamicTexture::render()
107{
108 return FALSE;
109}
110
111//-----------------------------------------------------------------------------
112// preRender()
113//-----------------------------------------------------------------------------
114void LLDynamicTexture::preRender(BOOL clear_depth)
115{
116 {
117 // force rendering to on-screen portion of frame buffer
118 LLCoordScreen window_pos;
119 gViewerWindow->getWindow()->getPosition( &window_pos );
120 mOrigin.set(0, gViewerWindow->getWindowDisplayHeight() - mHeight); // top left corner
121
122 if (window_pos.mX < 0)
123 {
124 mOrigin.mX = -window_pos.mX;
125 }
126 if (window_pos.mY < 0)
127 {
128 mOrigin.mY += window_pos.mY;
129 }
130
131 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
132 }
133 // Set up camera
134 mCamera.setOrigin(*gCamera);
135 mCamera.setAxes(*gCamera);
136 mCamera.setAspect(gCamera->getAspect());
137 mCamera.setView(gCamera->getView());
138 mCamera.setNear(gCamera->getNear());
139
140 glViewport(mOrigin.mX, mOrigin.mY, mWidth, mHeight);
141 if (clear_depth)
142 {
143 glClear(GL_DEPTH_BUFFER_BIT);
144 }
145}
146
147//-----------------------------------------------------------------------------
148// postRender()
149//-----------------------------------------------------------------------------
150void LLDynamicTexture::postRender(BOOL success)
151{
152 {
153 if (success)
154 {
155 success = mTexture->setSubImageFromFrameBuffer(0, 0, mOrigin.mX, mOrigin.mY, mWidth, mHeight);
156 }
157 }
158
159 // restore viewport
160 gViewerWindow->setupViewport();
161
162 // restore camera
163 gCamera->setOrigin(mCamera);
164 gCamera->setAxes(mCamera);
165 gCamera->setAspect(mCamera.getAspect());
166 gCamera->setView(mCamera.getView());
167 gCamera->setNear(mCamera.getNear());
168}
169
170//-----------------------------------------------------------------------------
171// bindTexture()
172//-----------------------------------------------------------------------------
173void LLDynamicTexture::bindTexture()
174{
175 LLViewerImage::bindTexture(mTexture,0);
176}
177
178void LLDynamicTexture::unbindTexture()
179{
180 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
181}
182
183//-----------------------------------------------------------------------------
184// static
185// updateDynamicTextures()
186// Calls update on each dynamic texture. Calls each group in order: "first," then "middle," then "last."
187//-----------------------------------------------------------------------------
188BOOL LLDynamicTexture::updateAllInstances()
189{
190 sNumRenders = 0;
191 if (gGLManager.mIsDisabled)
192 {
193 return TRUE;
194 }
195
196 BOOL result = FALSE;
197 for( S32 order = 0; order < ORDER_COUNT; order++ )
198 {
199 for (LLDynamicTexture *dynamicTexture = LLDynamicTexture::sInstances[order].getFirstData();
200 dynamicTexture;
201 dynamicTexture = LLDynamicTexture::sInstances[order].getNextData())
202 {
203 if (dynamicTexture->needsRender())
204 {
205 dynamicTexture->preRender();
206 if (dynamicTexture->render())
207 {
208 result = TRUE;
209 gViewerWindow->finishFastFrame();
210 sNumRenders++;
211 }
212 dynamicTexture->postRender(result);
213 }
214 }
215 }
216
217 return result;
218}
219
220//-----------------------------------------------------------------------------
221// static
222// destroyGL()
223//-----------------------------------------------------------------------------
224void LLDynamicTexture::destroyGL()
225{
226}
227
228//-----------------------------------------------------------------------------
229// static
230// restoreGL()
231//-----------------------------------------------------------------------------
232void LLDynamicTexture::restoreGL()
233{
234}