diff options
author | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
commit | cd17687f01420952712a500107e0f93e7ab8d5f8 (patch) | |
tree | ce48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llrender/llglimmediate.cpp | |
parent | Second Life viewer sources 1.19.0.5 (diff) | |
download | meta-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/llglimmediate.cpp')
-rw-r--r-- | linden/indra/llrender/llglimmediate.cpp | 354 |
1 files changed, 354 insertions, 0 deletions
diff --git a/linden/indra/llrender/llglimmediate.cpp b/linden/indra/llrender/llglimmediate.cpp new file mode 100644 index 0000000..db62f3d --- /dev/null +++ b/linden/indra/llrender/llglimmediate.cpp | |||
@@ -0,0 +1,354 @@ | |||
1 | /** | ||
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 | #ifdef LL_RELEASE_FOR_DOWNLOAD | ||
40 | #define IMM_ERRS llwarns | ||
41 | #else | ||
42 | #define IMM_ERRS llerrs | ||
43 | #endif | ||
44 | |||
45 | bool LLGLImmediate::sClever = false; | ||
46 | |||
47 | static BOOL sStarted = FALSE; | ||
48 | |||
49 | LLGLImmediate::LLGLImmediate() | ||
50 | { | ||
51 | mCount = 0; | ||
52 | mMode = GL_TRIANGLES; | ||
53 | memset(mBuffer, 0, sizeof(Vertex)*4096); | ||
54 | } | ||
55 | |||
56 | void LLGLImmediate::start() | ||
57 | { | ||
58 | if(sClever) | ||
59 | { | ||
60 | if (sStarted) | ||
61 | { | ||
62 | llerrs << "Redundant start." << llendl; | ||
63 | } | ||
64 | |||
65 | sStarted = TRUE; | ||
66 | LLVertexBuffer::unbind(); | ||
67 | |||
68 | glEnableClientState(GL_VERTEX_ARRAY); | ||
69 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); | ||
70 | glEnableClientState(GL_COLOR_ARRAY); | ||
71 | |||
72 | const U32 stride = sizeof(Vertex); | ||
73 | |||
74 | glVertexPointer(3, GL_FLOAT, stride, &(mBuffer[0].v)); | ||
75 | glTexCoordPointer(2, GL_FLOAT, stride, &(mBuffer[0].uv)); | ||
76 | glColorPointer(4, GL_UNSIGNED_BYTE, stride, &(mBuffer[0].c)); | ||
77 | |||
78 | color4f(1,1,1,1); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | void LLGLImmediate::stop() | ||
83 | { | ||
84 | if (sClever) | ||
85 | { | ||
86 | if (!sStarted) | ||
87 | { | ||
88 | llerrs << "Redundant stop." << llendl; | ||
89 | } | ||
90 | |||
91 | flush(); | ||
92 | |||
93 | sStarted = FALSE; | ||
94 | |||
95 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | ||
96 | glDisableClientState(GL_COLOR_ARRAY); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | void LLGLImmediate::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z) | ||
101 | { | ||
102 | flush(); | ||
103 | glTranslatef(x,y,z); | ||
104 | } | ||
105 | |||
106 | void LLGLImmediate::pushMatrix() | ||
107 | { | ||
108 | flush(); | ||
109 | glPushMatrix(); | ||
110 | } | ||
111 | |||
112 | void LLGLImmediate::popMatrix() | ||
113 | { | ||
114 | flush(); | ||
115 | glPopMatrix(); | ||
116 | } | ||
117 | |||
118 | void LLGLImmediate::blendFunc(GLenum sfactor, GLenum dfactor) | ||
119 | { | ||
120 | if (sStarted) | ||
121 | { | ||
122 | flush(); | ||
123 | } | ||
124 | glBlendFunc(sfactor, dfactor); | ||
125 | } | ||
126 | |||
127 | void LLGLImmediate::begin(const GLuint& mode) | ||
128 | { | ||
129 | if (sClever) | ||
130 | { | ||
131 | if (mode != mMode) | ||
132 | { | ||
133 | if (mMode == GL_QUADS || | ||
134 | mMode == GL_LINES || | ||
135 | mMode == GL_TRIANGLES || | ||
136 | mMode == GL_POINTS) | ||
137 | { | ||
138 | flush(); | ||
139 | } | ||
140 | else if (mCount != 0) | ||
141 | { | ||
142 | llerrs << "gGL.begin() called redundantly." << llendl; | ||
143 | } | ||
144 | |||
145 | mMode = mode; | ||
146 | } | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | glBegin(mode); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | void LLGLImmediate::end() | ||
155 | { | ||
156 | if (sClever) | ||
157 | { | ||
158 | if (mCount == 0) | ||
159 | { | ||
160 | IMM_ERRS << "GL begin and end called with no vertices specified." << llendl; | ||
161 | } | ||
162 | |||
163 | if ((mMode != GL_QUADS && | ||
164 | mMode != GL_LINES && | ||
165 | mMode != GL_TRIANGLES && | ||
166 | mMode != GL_POINTS) || | ||
167 | mCount > 2048) | ||
168 | { | ||
169 | flush(); | ||
170 | } | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | glEnd(); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | void LLGLImmediate::flush() | ||
179 | { | ||
180 | if (sClever) | ||
181 | { | ||
182 | if (mCount > 0) | ||
183 | { | ||
184 | #if 0 | ||
185 | if (!glIsEnabled(GL_VERTEX_ARRAY)) | ||
186 | { | ||
187 | llerrs << "foo 1" << llendl; | ||
188 | } | ||
189 | |||
190 | if (!glIsEnabled(GL_COLOR_ARRAY)) | ||
191 | { | ||
192 | llerrs << "foo 2" << llendl; | ||
193 | } | ||
194 | |||
195 | if (!glIsEnabled(GL_TEXTURE_COORD_ARRAY)) | ||
196 | { | ||
197 | llerrs << "foo 3" << llendl; | ||
198 | } | ||
199 | |||
200 | if (glIsEnabled(GL_NORMAL_ARRAY)) | ||
201 | { | ||
202 | llerrs << "foo 7" << llendl; | ||
203 | } | ||
204 | |||
205 | GLvoid* pointer; | ||
206 | |||
207 | glGetPointerv(GL_VERTEX_ARRAY_POINTER, &pointer); | ||
208 | if (pointer != &(mBuffer[0].v)) | ||
209 | { | ||
210 | llerrs << "foo 4" << llendl; | ||
211 | } | ||
212 | |||
213 | glGetPointerv(GL_COLOR_ARRAY_POINTER, &pointer); | ||
214 | if (pointer != &(mBuffer[0].c)) | ||
215 | { | ||
216 | llerrs << "foo 5" << llendl; | ||
217 | } | ||
218 | |||
219 | glGetPointerv(GL_TEXTURE_COORD_ARRAY_POINTER, &pointer); | ||
220 | if (pointer != &(mBuffer[0].uv)) | ||
221 | { | ||
222 | llerrs << "foo 6" << llendl; | ||
223 | } | ||
224 | #endif | ||
225 | if (!sStarted) | ||
226 | { | ||
227 | llerrs << "Drawing call issued outside start/stop." << llendl; | ||
228 | } | ||
229 | glDrawArrays(mMode, 0, mCount); | ||
230 | mBuffer[0] = mBuffer[mCount]; | ||
231 | mCount = 0; | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | |||
236 | void LLGLImmediate::vertex3f(const GLfloat& x, const GLfloat& y, const GLfloat& z) | ||
237 | { | ||
238 | if (sClever) | ||
239 | { | ||
240 | if (mCount >= 4096) | ||
241 | { | ||
242 | // llwarns << "GL immediate mode overflow. Some geometry not drawn." << llendl; | ||
243 | return; | ||
244 | } | ||
245 | |||
246 | mBuffer[mCount].v[0] = x; | ||
247 | mBuffer[mCount].v[1] = y; | ||
248 | mBuffer[mCount].v[2] = z; | ||
249 | mCount++; | ||
250 | if (mCount < 4096) | ||
251 | { | ||
252 | mBuffer[mCount] = mBuffer[mCount-1]; | ||
253 | } | ||
254 | } | ||
255 | else | ||
256 | { | ||
257 | glVertex3f(x,y,z); | ||
258 | } | ||
259 | } | ||
260 | |||
261 | void LLGLImmediate::vertex2i(const GLint& x, const GLint& y) | ||
262 | { | ||
263 | vertex3f((GLfloat) x, (GLfloat) y, 0); | ||
264 | } | ||
265 | |||
266 | void LLGLImmediate::vertex2f(const GLfloat& x, const GLfloat& y) | ||
267 | { | ||
268 | vertex3f(x,y,0); | ||
269 | } | ||
270 | |||
271 | void LLGLImmediate::vertex2fv(const GLfloat* v) | ||
272 | { | ||
273 | vertex3f(v[0], v[1], 0); | ||
274 | } | ||
275 | |||
276 | void LLGLImmediate::vertex3fv(const GLfloat* v) | ||
277 | { | ||
278 | vertex3f(v[0], v[1], v[2]); | ||
279 | } | ||
280 | |||
281 | void LLGLImmediate::texCoord2f(const GLfloat& x, const GLfloat& y) | ||
282 | { | ||
283 | if (sClever) | ||
284 | { | ||
285 | mBuffer[mCount].uv[0] = x; | ||
286 | mBuffer[mCount].uv[1] = y; | ||
287 | } | ||
288 | else | ||
289 | { | ||
290 | glTexCoord2f(x,y); | ||
291 | } | ||
292 | } | ||
293 | |||
294 | void LLGLImmediate::texCoord2i(const GLint& x, const GLint& y) | ||
295 | { | ||
296 | texCoord2f((GLfloat) x, (GLfloat) y); | ||
297 | } | ||
298 | |||
299 | void LLGLImmediate::texCoord2fv(const GLfloat* tc) | ||
300 | { | ||
301 | texCoord2f(tc[0], tc[1]); | ||
302 | } | ||
303 | |||
304 | void LLGLImmediate::color4ub(const GLubyte& r, const GLubyte& g, const GLubyte& b, const GLubyte& a) | ||
305 | { | ||
306 | if (sClever) | ||
307 | { | ||
308 | mBuffer[mCount].c[0] = r; | ||
309 | mBuffer[mCount].c[1] = g; | ||
310 | mBuffer[mCount].c[2] = b; | ||
311 | mBuffer[mCount].c[3] = a; | ||
312 | } | ||
313 | else | ||
314 | { | ||
315 | glColor4ub(r,g,b,a); | ||
316 | } | ||
317 | } | ||
318 | |||
319 | void LLGLImmediate::color4ubv(const GLubyte* c) | ||
320 | { | ||
321 | color4ub(c[0], c[1], c[2], c[3]); | ||
322 | } | ||
323 | |||
324 | void LLGLImmediate::color4f(const GLfloat& r, const GLfloat& g, const GLfloat& b, const GLfloat& a) | ||
325 | { | ||
326 | color4ub((GLubyte) (llclamp(r, 0.f, 1.f)*255), | ||
327 | (GLubyte) (llclamp(g, 0.f, 1.f)*255), | ||
328 | (GLubyte) (llclamp(b, 0.f, 1.f)*255), | ||
329 | (GLubyte) (llclamp(a, 0.f, 1.f)*255)); | ||
330 | } | ||
331 | |||
332 | void LLGLImmediate::color4fv(const GLfloat* c) | ||
333 | { | ||
334 | color4f(c[0],c[1],c[2],c[3]); | ||
335 | } | ||
336 | |||
337 | void LLGLImmediate::color3f(const GLfloat& r, const GLfloat& g, const GLfloat& b) | ||
338 | { | ||
339 | color4f(r,g,b,1); | ||
340 | } | ||
341 | |||
342 | void LLGLImmediate::color3fv(const GLfloat* c) | ||
343 | { | ||
344 | color4f(c[0],c[1],c[2],1); | ||
345 | } | ||
346 | |||
347 | void LLGLImmediate::setClever(bool do_clever) | ||
348 | { | ||
349 | llassert(!sStarted); | ||
350 | llassert(mCount == 0); | ||
351 | |||
352 | sClever = do_clever; | ||
353 | } | ||
354 | |||