diff options
author | Jacek Antonelli | 2008-08-15 23:45:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:50 -0500 |
commit | 2a4dea528f670b9bb1f77ef27a8a1dd16603d114 (patch) | |
tree | 95c68e362703c9099d571ecbdc6142b1cda1e005 /linden/indra/llrender/llglimmediate.cpp | |
parent | Second Life viewer sources 1.20.6 (diff) | |
download | meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.zip meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.gz meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.bz2 meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.xz |
Second Life viewer sources 1.20.7
Diffstat (limited to 'linden/indra/llrender/llglimmediate.cpp')
-rw-r--r-- | linden/indra/llrender/llglimmediate.cpp | 303 |
1 files changed, 1 insertions, 302 deletions
diff --git a/linden/indra/llrender/llglimmediate.cpp b/linden/indra/llrender/llglimmediate.cpp index edc694a..17c2182 100644 --- a/linden/indra/llrender/llglimmediate.cpp +++ b/linden/indra/llrender/llglimmediate.cpp | |||
@@ -1,302 +1 @@ | |||
1 | /** | #error This file has been renamed llrender.cpp | |
2 | * @file llglimmediate.cpp | ||
3 | * @brief LLGLImmediate 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 "llglimmediate.h" | ||
35 | #include "llvertexbuffer.h" | ||
36 | |||
37 | LLGLImmediate gGL; | ||
38 | |||
39 | bool LLGLImmediate::sClever = false; | ||
40 | |||
41 | const U32 immediate_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TEXCOORD; | ||
42 | |||
43 | LLGLImmediate::LLGLImmediate() | ||
44 | { | ||
45 | mCount = 0; | ||
46 | mMode = LLVertexBuffer::TRIANGLES; | ||
47 | mBuffer = new LLVertexBuffer(immediate_mask, 0); | ||
48 | mBuffer->allocateBuffer(4096, 0, TRUE); | ||
49 | mBuffer->getVertexStrider(mVerticesp); | ||
50 | mBuffer->getTexCoordStrider(mTexcoordsp); | ||
51 | mBuffer->getColorStrider(mColorsp); | ||
52 | } | ||
53 | |||
54 | void LLGLImmediate::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z) | ||
55 | { | ||
56 | flush(); | ||
57 | glTranslatef(x,y,z); | ||
58 | } | ||
59 | |||
60 | void LLGLImmediate::pushMatrix() | ||
61 | { | ||
62 | flush(); | ||
63 | glPushMatrix(); | ||
64 | } | ||
65 | |||
66 | void LLGLImmediate::popMatrix() | ||
67 | { | ||
68 | flush(); | ||
69 | glPopMatrix(); | ||
70 | } | ||
71 | |||
72 | void LLGLImmediate::blendFunc(GLenum sfactor, GLenum dfactor) | ||
73 | { | ||
74 | flush(); | ||
75 | glBlendFunc(sfactor, dfactor); | ||
76 | } | ||
77 | |||
78 | void LLGLImmediate::begin(const GLuint& mode) | ||
79 | { | ||
80 | if (sClever) | ||
81 | { | ||
82 | if (mode != mMode) | ||
83 | { | ||
84 | if (mMode == LLVertexBuffer::QUADS || | ||
85 | mMode == LLVertexBuffer::LINES || | ||
86 | mMode == LLVertexBuffer::TRIANGLES || | ||
87 | mMode == LLVertexBuffer::POINTS) | ||
88 | { | ||
89 | flush(); | ||
90 | } | ||
91 | else if (mCount != 0) | ||
92 | { | ||
93 | llerrs << "gGL.begin() called redundantly." << llendl; | ||
94 | } | ||
95 | |||
96 | mMode = mode; | ||
97 | } | ||
98 | } | ||
99 | else | ||
100 | { | ||
101 | glBegin(LLVertexBuffer::sGLMode[mode]); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | void LLGLImmediate::end() | ||
106 | { | ||
107 | if (sClever) | ||
108 | { | ||
109 | if (mCount == 0) | ||
110 | { | ||
111 | return; | ||
112 | //IMM_ERRS << "GL begin and end called with no vertices specified." << llendl; | ||
113 | } | ||
114 | |||
115 | if ((mMode != LLVertexBuffer::QUADS && | ||
116 | mMode != LLVertexBuffer::LINES && | ||
117 | mMode != LLVertexBuffer::TRIANGLES && | ||
118 | mMode != LLVertexBuffer::POINTS) || | ||
119 | mCount > 2048) | ||
120 | { | ||
121 | flush(); | ||
122 | } | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | glEnd(); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | void LLGLImmediate::flush() | ||
131 | { | ||
132 | if (sClever) | ||
133 | { | ||
134 | if (mCount > 0) | ||
135 | { | ||
136 | #if 0 | ||
137 | if (!glIsEnabled(GL_VERTEX_ARRAY)) | ||
138 | { | ||
139 | llerrs << "foo 1" << llendl; | ||
140 | } | ||
141 | |||
142 | if (!glIsEnabled(GL_COLOR_ARRAY)) | ||
143 | { | ||
144 | llerrs << "foo 2" << llendl; | ||
145 | } | ||
146 | |||
147 | if (!glIsEnabled(GL_TEXTURE_COORD_ARRAY)) | ||
148 | { | ||
149 | llerrs << "foo 3" << llendl; | ||
150 | } | ||
151 | |||
152 | if (glIsEnabled(GL_NORMAL_ARRAY)) | ||
153 | { | ||
154 | llerrs << "foo 7" << llendl; | ||
155 | } | ||
156 | |||
157 | GLvoid* pointer; | ||
158 | |||
159 | glGetPointerv(GL_VERTEX_ARRAY_POINTER, &pointer); | ||
160 | if (pointer != &(mBuffer[0].v)) | ||
161 | { | ||
162 | llerrs << "foo 4" << llendl; | ||
163 | } | ||
164 | |||
165 | glGetPointerv(GL_COLOR_ARRAY_POINTER, &pointer); | ||
166 | if (pointer != &(mBuffer[0].c)) | ||
167 | { | ||
168 | llerrs << "foo 5" << llendl; | ||
169 | } | ||
170 | |||
171 | glGetPointerv(GL_TEXTURE_COORD_ARRAY_POINTER, &pointer); | ||
172 | if (pointer != &(mBuffer[0].uv)) | ||
173 | { | ||
174 | llerrs << "foo 6" << llendl; | ||
175 | } | ||
176 | #endif | ||
177 | |||
178 | mBuffer->setBuffer(immediate_mask); | ||
179 | mBuffer->drawArrays(mMode, 0, mCount); | ||
180 | |||
181 | mVerticesp[0] = mVerticesp[mCount]; | ||
182 | mTexcoordsp[0] = mTexcoordsp[mCount]; | ||
183 | mColorsp[0] = mColorsp[mCount]; | ||
184 | mCount = 0; | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | |||
189 | void LLGLImmediate::vertex3f(const GLfloat& x, const GLfloat& y, const GLfloat& z) | ||
190 | { | ||
191 | if (sClever) | ||
192 | { | ||
193 | if (mCount >= 4096) | ||
194 | { | ||
195 | // llwarns << "GL immediate mode overflow. Some geometry not drawn." << llendl; | ||
196 | return; | ||
197 | } | ||
198 | |||
199 | mVerticesp[mCount] = LLVector3(x,y,z); | ||
200 | mCount++; | ||
201 | if (mCount < 4096) | ||
202 | { | ||
203 | mVerticesp[mCount] = mVerticesp[mCount-1]; | ||
204 | mColorsp[mCount] = mColorsp[mCount-1]; | ||
205 | mTexcoordsp[mCount] = mTexcoordsp[mCount-1]; | ||
206 | } | ||
207 | } | ||
208 | else | ||
209 | { | ||
210 | glVertex3f(x,y,z); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | void LLGLImmediate::vertex2i(const GLint& x, const GLint& y) | ||
215 | { | ||
216 | vertex3f((GLfloat) x, (GLfloat) y, 0); | ||
217 | } | ||
218 | |||
219 | void LLGLImmediate::vertex2f(const GLfloat& x, const GLfloat& y) | ||
220 | { | ||
221 | vertex3f(x,y,0); | ||
222 | } | ||
223 | |||
224 | void LLGLImmediate::vertex2fv(const GLfloat* v) | ||
225 | { | ||
226 | vertex3f(v[0], v[1], 0); | ||
227 | } | ||
228 | |||
229 | void LLGLImmediate::vertex3fv(const GLfloat* v) | ||
230 | { | ||
231 | vertex3f(v[0], v[1], v[2]); | ||
232 | } | ||
233 | |||
234 | void LLGLImmediate::texCoord2f(const GLfloat& x, const GLfloat& y) | ||
235 | { | ||
236 | if (sClever) | ||
237 | { | ||
238 | mTexcoordsp[mCount] = LLVector2(x,y); | ||
239 | } | ||
240 | else | ||
241 | { | ||
242 | glTexCoord2f(x,y); | ||
243 | } | ||
244 | } | ||
245 | |||
246 | void LLGLImmediate::texCoord2i(const GLint& x, const GLint& y) | ||
247 | { | ||
248 | texCoord2f((GLfloat) x, (GLfloat) y); | ||
249 | } | ||
250 | |||
251 | void LLGLImmediate::texCoord2fv(const GLfloat* tc) | ||
252 | { | ||
253 | texCoord2f(tc[0], tc[1]); | ||
254 | } | ||
255 | |||
256 | void LLGLImmediate::color4ub(const GLubyte& r, const GLubyte& g, const GLubyte& b, const GLubyte& a) | ||
257 | { | ||
258 | if (sClever) | ||
259 | { | ||
260 | mColorsp[mCount] = LLColor4U(r,g,b,a); | ||
261 | } | ||
262 | else | ||
263 | { | ||
264 | glColor4ub(r,g,b,a); | ||
265 | } | ||
266 | } | ||
267 | |||
268 | void LLGLImmediate::color4ubv(const GLubyte* c) | ||
269 | { | ||
270 | color4ub(c[0], c[1], c[2], c[3]); | ||
271 | } | ||
272 | |||
273 | void LLGLImmediate::color4f(const GLfloat& r, const GLfloat& g, const GLfloat& b, const GLfloat& a) | ||
274 | { | ||
275 | color4ub((GLubyte) (llclamp(r, 0.f, 1.f)*255), | ||
276 | (GLubyte) (llclamp(g, 0.f, 1.f)*255), | ||
277 | (GLubyte) (llclamp(b, 0.f, 1.f)*255), | ||
278 | (GLubyte) (llclamp(a, 0.f, 1.f)*255)); | ||
279 | } | ||
280 | |||
281 | void LLGLImmediate::color4fv(const GLfloat* c) | ||
282 | { | ||
283 | color4f(c[0],c[1],c[2],c[3]); | ||
284 | } | ||
285 | |||
286 | void LLGLImmediate::color3f(const GLfloat& r, const GLfloat& g, const GLfloat& b) | ||
287 | { | ||
288 | color4f(r,g,b,1); | ||
289 | } | ||
290 | |||
291 | void LLGLImmediate::color3fv(const GLfloat* c) | ||
292 | { | ||
293 | color4f(c[0],c[1],c[2],1); | ||
294 | } | ||
295 | |||
296 | void LLGLImmediate::setClever(bool do_clever) | ||
297 | { | ||
298 | llassert(mCount == 0); | ||
299 | |||
300 | sClever = do_clever; | ||
301 | } | ||
302 | |||