1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <stdio.h>
|
---|
8 | #include "state.h"
|
---|
9 | #include "cr_mem.h"
|
---|
10 | #include "state/cr_statetypes.h"
|
---|
11 | #include "state_internals.h"
|
---|
12 |
|
---|
13 | void crStateLightingInitBits (CRLightingBits *l)
|
---|
14 | {
|
---|
15 | l->light = (CRLightBits *) crCalloc (sizeof(*(l->light)) * CR_MAX_LIGHTS );
|
---|
16 | }
|
---|
17 |
|
---|
18 | void crStateLightingDestroy (CRContext *ctx)
|
---|
19 | {
|
---|
20 | crFree( ctx->lighting.light );
|
---|
21 | }
|
---|
22 |
|
---|
23 | void crStateLightingInit (CRContext *ctx)
|
---|
24 | {
|
---|
25 | CRLightingState *l = &ctx->lighting;
|
---|
26 | CRStateBits *sb = GetCurrentBits();
|
---|
27 | CRLightingBits *lb = &(sb->lighting);
|
---|
28 | int i;
|
---|
29 | GLvectorf zero_vector = {0.0f, 0.0f, 0.0f, 1.0f};
|
---|
30 | GLcolorf zero_color = {0.0f, 0.0f, 0.0f, 1.0f};
|
---|
31 | GLcolorf ambient_color = {0.2f, 0.2f, 0.2f, 1.0f};
|
---|
32 | GLcolorf diffuse_color = {0.8f, 0.8f, 0.8f, 1.0f};
|
---|
33 | GLvectorf spot_vector = {0.0f, 0.0f, -1.0f, 0.0f};
|
---|
34 | GLcolorf one_color = {1.0f, 1.0f, 1.0f, 1.0f};
|
---|
35 |
|
---|
36 | l->lighting = GL_FALSE;
|
---|
37 | RESET(lb->enable, ctx->bitid);
|
---|
38 | l->colorMaterial = GL_FALSE;
|
---|
39 | RESET(lb->colorMaterial, ctx->bitid);
|
---|
40 | l->shadeModel = GL_SMOOTH;
|
---|
41 | RESET(lb->shadeModel, ctx->bitid);
|
---|
42 | l->colorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
|
---|
43 | l->colorMaterialFace = GL_FRONT_AND_BACK;
|
---|
44 | l->ambient[0] = ambient_color;
|
---|
45 | l->diffuse[0] = diffuse_color;
|
---|
46 | l->specular[0] = zero_color;
|
---|
47 | l->emission[0] = zero_color;
|
---|
48 | l->shininess[0] = 0.0f;
|
---|
49 | l->indexes[0][0] = 0;
|
---|
50 | l->indexes[0][1] = 1;
|
---|
51 | l->indexes[0][2] = 1;
|
---|
52 | l->ambient[1] = ambient_color;
|
---|
53 | l->diffuse[1] = diffuse_color;
|
---|
54 | l->specular[1] = zero_color;
|
---|
55 | l->emission[1] = zero_color;
|
---|
56 | l->shininess[1] = 0.0f;
|
---|
57 | l->indexes[1][0] = 0;
|
---|
58 | l->indexes[1][1] = 1;
|
---|
59 | l->indexes[1][2] = 1;
|
---|
60 | RESET(lb->material, ctx->bitid);
|
---|
61 | l->lightModelAmbient = ambient_color;
|
---|
62 | l->lightModelLocalViewer = GL_FALSE;
|
---|
63 | l->lightModelTwoSide = GL_FALSE;
|
---|
64 | #if defined(CR_EXT_separate_specular_color)
|
---|
65 | l->lightModelColorControlEXT = GL_SINGLE_COLOR_EXT;
|
---|
66 | #elif defined(CR_OPENGL_VERSION_1_2)
|
---|
67 | l->lightModelColorControlEXT = GL_SINGLE_COLOR;
|
---|
68 | #endif
|
---|
69 | RESET(lb->lightModel, ctx->bitid);
|
---|
70 | #if defined(CR_EXT_secondary_color)
|
---|
71 | l->colorSumEXT = GL_FALSE;
|
---|
72 | #endif
|
---|
73 | l->light = (CRLight *) crCalloc (sizeof (*(l->light)) * CR_MAX_LIGHTS);
|
---|
74 |
|
---|
75 | for (i=0; i<CR_MAX_LIGHTS; i++)
|
---|
76 | {
|
---|
77 | CRLightBits *ltb = lb->light + i;
|
---|
78 | l->light[i].enable = GL_FALSE;
|
---|
79 | RESET(ltb->enable, ctx->bitid);
|
---|
80 | l->light[i].ambient = zero_color;
|
---|
81 | RESET(ltb->ambient, ctx->bitid);
|
---|
82 | l->light[i].diffuse = zero_color;
|
---|
83 | RESET(ltb->diffuse, ctx->bitid);
|
---|
84 | l->light[i].specular = zero_color;
|
---|
85 | RESET(ltb->specular, ctx->bitid);
|
---|
86 | l->light[i].position = zero_vector;
|
---|
87 | l->light[i].position.z = 1.0f;
|
---|
88 | l->light[i].position.w = 0.0f;
|
---|
89 | l->light[i].objPosition = l->light[i].position;
|
---|
90 | RESET(ltb->position, ctx->bitid);
|
---|
91 | l->light[i].spotDirection = spot_vector;
|
---|
92 | l->light[i].spotExponent = 0.0f;
|
---|
93 | l->light[i].spotCutoff = 180.0f;
|
---|
94 | RESET(ltb->spot, ctx->bitid);
|
---|
95 | l->light[i].constantAttenuation= 1.0f;
|
---|
96 | l->light[i].linearAttenuation= 0.0f;
|
---|
97 | l->light[i].quadraticAttenuation = 0.0f;
|
---|
98 | RESET(ltb->attenuation, ctx->bitid);
|
---|
99 | RESET(ltb->dirty, ctx->bitid);
|
---|
100 | }
|
---|
101 | l->light[0].diffuse = one_color;
|
---|
102 | l->light[0].specular = one_color;
|
---|
103 |
|
---|
104 | RESET(lb->dirty, ctx->bitid);
|
---|
105 | }
|
---|
106 |
|
---|
107 | void STATE_APIENTRY crStateShadeModel (GLenum mode)
|
---|
108 | {
|
---|
109 | CRContext *g = GetCurrentContext();
|
---|
110 | CRLightingState *l = &(g->lighting);
|
---|
111 | CRStateBits *sb = GetCurrentBits();
|
---|
112 | CRLightingBits *lb = &(sb->lighting);
|
---|
113 |
|
---|
114 | if (g->current.inBeginEnd)
|
---|
115 | {
|
---|
116 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "ShadeModel called in begin/end");
|
---|
117 | return;
|
---|
118 | }
|
---|
119 |
|
---|
120 | FLUSH();
|
---|
121 |
|
---|
122 | if (mode != GL_SMOOTH &&
|
---|
123 | mode != GL_FLAT)
|
---|
124 | {
|
---|
125 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "ShadeModel: Bogus mode 0x%x", mode);
|
---|
126 | return;
|
---|
127 | }
|
---|
128 |
|
---|
129 | l->shadeModel = mode;
|
---|
130 | DIRTY(lb->shadeModel, g->neg_bitid);
|
---|
131 | DIRTY(lb->dirty, g->neg_bitid);
|
---|
132 | }
|
---|
133 |
|
---|
134 | void STATE_APIENTRY crStateColorMaterial (GLenum face, GLenum mode)
|
---|
135 | {
|
---|
136 | CRContext *g = GetCurrentContext();
|
---|
137 | CRLightingState *l = &(g->lighting);
|
---|
138 | CRStateBits *sb = GetCurrentBits();
|
---|
139 | CRLightingBits *lb = &(sb->lighting);
|
---|
140 |
|
---|
141 | if (g->current.inBeginEnd)
|
---|
142 | {
|
---|
143 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "ColorMaterial called in begin/end");
|
---|
144 | return;
|
---|
145 | }
|
---|
146 |
|
---|
147 | FLUSH();
|
---|
148 |
|
---|
149 | if (face != GL_FRONT &&
|
---|
150 | face != GL_BACK &&
|
---|
151 | face != GL_FRONT_AND_BACK)
|
---|
152 | {
|
---|
153 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "ColorMaterial: Bogus face &d", face);
|
---|
154 | return;
|
---|
155 | }
|
---|
156 |
|
---|
157 | if (mode != GL_EMISSION &&
|
---|
158 | mode != GL_AMBIENT &&
|
---|
159 | mode != GL_DIFFUSE &&
|
---|
160 | mode != GL_SPECULAR &&
|
---|
161 | mode != GL_AMBIENT_AND_DIFFUSE)
|
---|
162 | {
|
---|
163 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "ColorMaterial: Bogus mode &d", mode);
|
---|
164 | return;
|
---|
165 | }
|
---|
166 |
|
---|
167 | l->colorMaterialFace = face;
|
---|
168 | l->colorMaterialMode = mode;
|
---|
169 | /* XXX this could conceivably be needed here (BP) */
|
---|
170 | /*
|
---|
171 | crStateColorMaterialRecover();
|
---|
172 | */
|
---|
173 | DIRTY(lb->colorMaterial, g->neg_bitid);
|
---|
174 | DIRTY(lb->dirty, g->neg_bitid);
|
---|
175 | }
|
---|
176 |
|
---|
177 | void STATE_APIENTRY crStateLightModelfv (GLenum pname, const GLfloat *param)
|
---|
178 | {
|
---|
179 | CRContext *g = GetCurrentContext();
|
---|
180 | CRLightingState *l = &(g->lighting);
|
---|
181 | CRStateBits *sb = GetCurrentBits();
|
---|
182 | CRLightingBits *lb = &(sb->lighting);
|
---|
183 |
|
---|
184 | if (g->current.inBeginEnd)
|
---|
185 | {
|
---|
186 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "LightModelfv called in begin/end");
|
---|
187 | return;
|
---|
188 | }
|
---|
189 |
|
---|
190 | FLUSH();
|
---|
191 |
|
---|
192 | switch (pname)
|
---|
193 | {
|
---|
194 | case GL_LIGHT_MODEL_LOCAL_VIEWER:
|
---|
195 | l->lightModelLocalViewer = (GLboolean) (*param==0.0f?GL_FALSE:GL_TRUE);
|
---|
196 | break;
|
---|
197 | case GL_LIGHT_MODEL_TWO_SIDE:
|
---|
198 | l->lightModelTwoSide = (GLboolean) (*param==0.0f?GL_FALSE:GL_TRUE);
|
---|
199 | break;
|
---|
200 | case GL_LIGHT_MODEL_AMBIENT:
|
---|
201 | l->lightModelAmbient.r = param[0];
|
---|
202 | l->lightModelAmbient.g = param[1];
|
---|
203 | l->lightModelAmbient.b = param[2];
|
---|
204 | l->lightModelAmbient.a = param[3];
|
---|
205 | break;
|
---|
206 | #if defined(CR_OPENGL_VERSION_1_2)
|
---|
207 | case GL_LIGHT_MODEL_COLOR_CONTROL:
|
---|
208 | if (param[0] == GL_SEPARATE_SPECULAR_COLOR || param[0] == GL_SINGLE_COLOR)
|
---|
209 | {
|
---|
210 | l->lightModelColorControlEXT = (GLenum) param[0];
|
---|
211 | }
|
---|
212 | else
|
---|
213 | {
|
---|
214 | crStateError( __LINE__, __FILE__, GL_INVALID_ENUM, "LightModel: Invalid param for LIGHT_MODEL_COLOR_CONTROL: 0x%x", param[0] );
|
---|
215 | return;
|
---|
216 | }
|
---|
217 | break;
|
---|
218 | #else
|
---|
219 | #if defined(CR_EXT_separate_specular_color)
|
---|
220 | case GL_LIGHT_MODEL_COLOR_CONTROL_EXT:
|
---|
221 | if( g->extensions.EXT_separate_specular_color )
|
---|
222 | {
|
---|
223 | if( param[0] == GL_SEPARATE_SPECULAR_COLOR_EXT || param[0] == GL_SINGLE_COLOR_EXT )
|
---|
224 | {
|
---|
225 | l->lightModelColorControlEXT = (GLenum) param[0];
|
---|
226 | }
|
---|
227 | else
|
---|
228 | {
|
---|
229 | crStateError( __LINE__, __FILE__, GL_INVALID_ENUM, "LightModel: Invalid param for LIGHT_MODEL_COLOR_CONTROL: 0x%x", param[0] );
|
---|
230 | return;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | else
|
---|
234 | {
|
---|
235 | crStateError( __LINE__, __FILE__, GL_INVALID_ENUM, "LightModel( LIGHT_MODEL_COLOR_CONTROL, ...) - EXT_separate_specular_color is unavailable." );
|
---|
236 | return;
|
---|
237 | }
|
---|
238 | break;
|
---|
239 | #endif
|
---|
240 | #endif
|
---|
241 | default:
|
---|
242 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "LightModelfv: Invalid pname: 0x%x", pname);
|
---|
243 | return;
|
---|
244 | }
|
---|
245 | DIRTY(lb->lightModel, g->neg_bitid);
|
---|
246 | DIRTY(lb->dirty, g->neg_bitid);
|
---|
247 | }
|
---|
248 |
|
---|
249 | void STATE_APIENTRY crStateLightModeliv (GLenum pname, const GLint *param)
|
---|
250 | {
|
---|
251 | GLfloat f_param;
|
---|
252 | GLcolor f_color;
|
---|
253 | #ifndef CR_OPENGL_VERSION_1_2
|
---|
254 | CRContext *g = GetCurrentContext();
|
---|
255 | #endif
|
---|
256 |
|
---|
257 | switch (pname)
|
---|
258 | {
|
---|
259 | case GL_LIGHT_MODEL_LOCAL_VIEWER:
|
---|
260 | case GL_LIGHT_MODEL_TWO_SIDE:
|
---|
261 | f_param = (GLfloat) (*param);
|
---|
262 | crStateLightModelfv( pname, &f_param );
|
---|
263 | break;
|
---|
264 | case GL_LIGHT_MODEL_AMBIENT:
|
---|
265 | f_color.r = ((GLfloat)param[0])/CR_MAXINT;
|
---|
266 | f_color.g = ((GLfloat)param[1])/CR_MAXINT;
|
---|
267 | f_color.b = ((GLfloat)param[2])/CR_MAXINT;
|
---|
268 | f_color.a = ((GLfloat)param[3])/CR_MAXINT;
|
---|
269 | crStateLightModelfv( pname, (GLfloat *) &f_color );
|
---|
270 | break;
|
---|
271 | #if defined(CR_OPENGL_VERSION_1_2)
|
---|
272 | case GL_LIGHT_MODEL_COLOR_CONTROL:
|
---|
273 | f_param = (GLfloat) (*param);
|
---|
274 | crStateLightModelfv( pname, &f_param );
|
---|
275 | break;
|
---|
276 | #else
|
---|
277 | #ifdef CR_EXT_separate_specular_color
|
---|
278 | case GL_LIGHT_MODEL_COLOR_CONTROL_EXT:
|
---|
279 | if( g->extensions.EXT_separate_specular_color ) {
|
---|
280 | f_param = (GLfloat) (*param);
|
---|
281 | crStateLightModelfv( pname, &f_param );
|
---|
282 | } else {
|
---|
283 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "LightModeliv(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, ...) - EXT_separate_specular_color not enabled!" );
|
---|
284 | return;
|
---|
285 | }
|
---|
286 | break;
|
---|
287 | #endif
|
---|
288 | #endif
|
---|
289 | default:
|
---|
290 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "LightModeliv: Invalid pname: 0x%x", pname);
|
---|
291 | return;
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 | void STATE_APIENTRY crStateLightModelf (GLenum pname, GLfloat param)
|
---|
296 | {
|
---|
297 | crStateLightModelfv( pname, ¶m );
|
---|
298 | }
|
---|
299 |
|
---|
300 | void STATE_APIENTRY crStateLightModeli (GLenum pname, GLint param)
|
---|
301 | {
|
---|
302 | GLfloat f_param = (GLfloat) param;
|
---|
303 | crStateLightModelfv( pname, &f_param );
|
---|
304 | }
|
---|
305 |
|
---|
306 | void STATE_APIENTRY crStateLightfv (GLenum light, GLenum pname, const GLfloat *param)
|
---|
307 | {
|
---|
308 | CRContext *g = GetCurrentContext();
|
---|
309 | CRLightingState *l = &(g->lighting);
|
---|
310 | CRTransformState *t = &(g->transform);
|
---|
311 | CRLight *lt;
|
---|
312 | unsigned int i;
|
---|
313 | GLfloat x, y, z, w;
|
---|
314 | CRmatrix inv;
|
---|
315 | CRmatrix *mat;
|
---|
316 | CRStateBits *sb = GetCurrentBits();
|
---|
317 | CRLightingBits *lb = &(sb->lighting);
|
---|
318 | CRLightBits *ltb;
|
---|
319 |
|
---|
320 | if (g->current.inBeginEnd)
|
---|
321 | {
|
---|
322 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glLightfv called in begin/end");
|
---|
323 | return;
|
---|
324 | }
|
---|
325 |
|
---|
326 | FLUSH();
|
---|
327 |
|
---|
328 | i = light - GL_LIGHT0;
|
---|
329 | if (i>=g->limits.maxLights)
|
---|
330 | {
|
---|
331 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glLight: invalid light specified: 0x%x", light);
|
---|
332 | return;
|
---|
333 | }
|
---|
334 |
|
---|
335 | lt = l->light + i;
|
---|
336 | ltb = lb->light + i;
|
---|
337 |
|
---|
338 | switch (pname)
|
---|
339 | {
|
---|
340 | case GL_AMBIENT:
|
---|
341 | lt->ambient.r = param[0];
|
---|
342 | lt->ambient.g = param[1];
|
---|
343 | lt->ambient.b = param[2];
|
---|
344 | lt->ambient.a = param[3];
|
---|
345 | DIRTY(ltb->ambient, g->neg_bitid);
|
---|
346 | break;
|
---|
347 | case GL_DIFFUSE:
|
---|
348 | lt->diffuse.r = param[0];
|
---|
349 | lt->diffuse.g = param[1];
|
---|
350 | lt->diffuse.b = param[2];
|
---|
351 | lt->diffuse.a = param[3];
|
---|
352 | DIRTY(ltb->diffuse, g->neg_bitid);
|
---|
353 | break;
|
---|
354 | case GL_SPECULAR:
|
---|
355 | lt->specular.r = param[0];
|
---|
356 | lt->specular.g = param[1];
|
---|
357 | lt->specular.b = param[2];
|
---|
358 | lt->specular.a = param[3];
|
---|
359 | DIRTY(ltb->specular, g->neg_bitid);
|
---|
360 | break;
|
---|
361 | case GL_POSITION:
|
---|
362 | x = param[0];
|
---|
363 | y = param[1];
|
---|
364 | z = param[2];
|
---|
365 | w = param[3];
|
---|
366 | mat = t->modelViewStack.top;
|
---|
367 | lt->objPosition.x = x;
|
---|
368 | lt->objPosition.y = y;
|
---|
369 | lt->objPosition.z = z;
|
---|
370 | lt->objPosition.w = w;
|
---|
371 |
|
---|
372 | lt->position.x = mat->m00*x + mat->m10*y + mat->m20*z + mat->m30*w;
|
---|
373 | lt->position.y = mat->m01*x + mat->m11*y + mat->m21*z + mat->m31*w;
|
---|
374 | lt->position.z = mat->m02*x + mat->m12*y + mat->m22*z + mat->m32*w;
|
---|
375 | lt->position.w = mat->m03*x + mat->m13*y + mat->m23*z + mat->m33*w;
|
---|
376 |
|
---|
377 | DIRTY(ltb->position, g->neg_bitid);
|
---|
378 | break;
|
---|
379 | case GL_SPOT_DIRECTION:
|
---|
380 | lt->spotDirection.x = param[0];
|
---|
381 | lt->spotDirection.y = param[1];
|
---|
382 | lt->spotDirection.z = param[2];
|
---|
383 | lt->spotDirection.w = 0.0f;
|
---|
384 | mat = t->modelViewStack.top;
|
---|
385 |
|
---|
386 | if (lt->objPosition.w != 0.0f)
|
---|
387 | {
|
---|
388 | lt->spotDirection.w = - ( ( lt->objPosition.x * lt->spotDirection.x +
|
---|
389 | lt->objPosition.y * lt->spotDirection.y +
|
---|
390 | lt->objPosition.z * lt->spotDirection.z ) /
|
---|
391 | lt->objPosition.w );
|
---|
392 | }
|
---|
393 |
|
---|
394 | crMatrixInvertTranspose(&inv, mat);
|
---|
395 | crStateTransformXformPointMatrixf (&inv, &(lt->spotDirection));
|
---|
396 |
|
---|
397 | DIRTY(ltb->spot, g->neg_bitid);
|
---|
398 | break;
|
---|
399 | case GL_SPOT_EXPONENT:
|
---|
400 | if (*param < 0.0f || *param > 180.0f)
|
---|
401 | {
|
---|
402 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLight: spot exponent out of range: %f", *param);
|
---|
403 | return;
|
---|
404 | }
|
---|
405 | lt->spotExponent = *param;
|
---|
406 | DIRTY(ltb->spot, g->neg_bitid);
|
---|
407 | break;
|
---|
408 | case GL_SPOT_CUTOFF:
|
---|
409 | if ((*param < 0.0f || *param > 90.0f) && *param != 180.0f)
|
---|
410 | {
|
---|
411 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLight: spot cutoff out of range: %f", *param);
|
---|
412 | return;
|
---|
413 | }
|
---|
414 | lt->spotCutoff = *param;
|
---|
415 | DIRTY(ltb->spot, g->neg_bitid);
|
---|
416 | break;
|
---|
417 | case GL_CONSTANT_ATTENUATION:
|
---|
418 | if (*param < 0.0f)
|
---|
419 | {
|
---|
420 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLight: constant Attenuation negative: %f", *param);
|
---|
421 | return;
|
---|
422 | }
|
---|
423 | lt->constantAttenuation = *param;
|
---|
424 | DIRTY(ltb->attenuation, g->neg_bitid);
|
---|
425 | break;
|
---|
426 | case GL_LINEAR_ATTENUATION:
|
---|
427 | if (*param < 0.0f)
|
---|
428 | {
|
---|
429 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLight: linear Attenuation negative: %f", *param);
|
---|
430 | return;
|
---|
431 | }
|
---|
432 | lt->linearAttenuation = *param;
|
---|
433 | DIRTY(ltb->attenuation, g->neg_bitid);
|
---|
434 | break;
|
---|
435 | case GL_QUADRATIC_ATTENUATION:
|
---|
436 | if (*param < 0.0f)
|
---|
437 | {
|
---|
438 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glLight: quadratic Attenuation negative: %f", *param);
|
---|
439 | return;
|
---|
440 | }
|
---|
441 | lt->quadraticAttenuation = *param;
|
---|
442 | DIRTY(ltb->attenuation, g->neg_bitid);
|
---|
443 | break;
|
---|
444 | default:
|
---|
445 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glLight: invalid pname: 0x%x", pname);
|
---|
446 | return;
|
---|
447 | }
|
---|
448 | DIRTY(ltb->dirty, g->neg_bitid);
|
---|
449 | DIRTY(lb->dirty, g->neg_bitid);
|
---|
450 | }
|
---|
451 |
|
---|
452 | void STATE_APIENTRY crStateLightiv (GLenum light, GLenum pname, const GLint *param)
|
---|
453 | {
|
---|
454 | GLfloat f_param;
|
---|
455 | GLcolor f_color;
|
---|
456 | GLvector f_vector;
|
---|
457 |
|
---|
458 | switch (pname)
|
---|
459 | {
|
---|
460 | case GL_AMBIENT:
|
---|
461 | case GL_DIFFUSE:
|
---|
462 | case GL_SPECULAR:
|
---|
463 | f_color.r = ((GLfloat)param[0])/CR_MAXINT;
|
---|
464 | f_color.g = ((GLfloat)param[1])/CR_MAXINT;
|
---|
465 | f_color.b = ((GLfloat)param[2])/CR_MAXINT;
|
---|
466 | f_color.a = ((GLfloat)param[3])/CR_MAXINT;
|
---|
467 | crStateLightfv( light, pname, (GLfloat *) &f_color );
|
---|
468 | break;
|
---|
469 | case GL_POSITION:
|
---|
470 | case GL_SPOT_DIRECTION:
|
---|
471 | f_vector.x = (GLfloat) param[0];
|
---|
472 | f_vector.y = (GLfloat) param[1];
|
---|
473 | f_vector.z = (GLfloat) param[2];
|
---|
474 | f_vector.w = (GLfloat) param[3];
|
---|
475 | crStateLightfv( light, pname, (GLfloat *) &f_vector );
|
---|
476 | break;
|
---|
477 | case GL_SPOT_EXPONENT:
|
---|
478 | case GL_SPOT_CUTOFF:
|
---|
479 | case GL_CONSTANT_ATTENUATION:
|
---|
480 | case GL_LINEAR_ATTENUATION:
|
---|
481 | case GL_QUADRATIC_ATTENUATION:
|
---|
482 | f_param = (GLfloat) (*param);
|
---|
483 | crStateLightfv( light, pname, &f_param );
|
---|
484 | break;
|
---|
485 | default:
|
---|
486 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glLight: invalid pname: 0x%x", pname);
|
---|
487 | return;
|
---|
488 | }
|
---|
489 | }
|
---|
490 |
|
---|
491 | void STATE_APIENTRY crStateLightf (GLenum light, GLenum pname, GLfloat param)
|
---|
492 | {
|
---|
493 | crStateLightfv( light, pname, ¶m );
|
---|
494 | }
|
---|
495 |
|
---|
496 | void STATE_APIENTRY crStateLighti (GLenum light, GLenum pname, GLint param)
|
---|
497 | {
|
---|
498 | GLfloat f_param = (GLfloat) param;
|
---|
499 | crStateLightfv( light, pname, &f_param );
|
---|
500 | }
|
---|
501 |
|
---|
502 | void STATE_APIENTRY crStateMaterialfv (GLenum face, GLenum pname, const GLfloat *param)
|
---|
503 | {
|
---|
504 | CRContext *g = GetCurrentContext();
|
---|
505 | CRLightingState *l = &(g->lighting);
|
---|
506 | CRStateBits *sb = GetCurrentBits();
|
---|
507 | CRLightingBits *lb = &(sb->lighting);
|
---|
508 |
|
---|
509 | if (!g->current.inBeginEnd)
|
---|
510 | {
|
---|
511 | FLUSH();
|
---|
512 | }
|
---|
513 |
|
---|
514 | switch (pname)
|
---|
515 | {
|
---|
516 | case GL_AMBIENT :
|
---|
517 | switch (face)
|
---|
518 | {
|
---|
519 | case GL_FRONT:
|
---|
520 | l->ambient[0].r = param[0];
|
---|
521 | l->ambient[0].g = param[1];
|
---|
522 | l->ambient[0].b = param[2];
|
---|
523 | l->ambient[0].a = param[3];
|
---|
524 | break;
|
---|
525 | case GL_FRONT_AND_BACK:
|
---|
526 | l->ambient[0].r = param[0];
|
---|
527 | l->ambient[0].g = param[1];
|
---|
528 | l->ambient[0].b = param[2];
|
---|
529 | l->ambient[0].a = param[3];
|
---|
530 | /* FALLTHROUGH! */
|
---|
531 | case GL_BACK:
|
---|
532 | l->ambient[1].r = param[0];
|
---|
533 | l->ambient[1].g = param[1];
|
---|
534 | l->ambient[1].b = param[2];
|
---|
535 | l->ambient[1].a = param[3];
|
---|
536 | break;
|
---|
537 | default:
|
---|
538 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
|
---|
539 | return;
|
---|
540 | }
|
---|
541 | break;
|
---|
542 | case GL_AMBIENT_AND_DIFFUSE :
|
---|
543 | switch (face)
|
---|
544 | {
|
---|
545 | case GL_FRONT:
|
---|
546 | l->ambient[0].r = param[0];
|
---|
547 | l->ambient[0].g = param[1];
|
---|
548 | l->ambient[0].b = param[2];
|
---|
549 | l->ambient[0].a = param[3];
|
---|
550 | break;
|
---|
551 | case GL_FRONT_AND_BACK:
|
---|
552 | l->ambient[0].r = param[0];
|
---|
553 | l->ambient[0].g = param[1];
|
---|
554 | l->ambient[0].b = param[2];
|
---|
555 | l->ambient[0].a = param[3];
|
---|
556 | /* FALLTHROUGH! */
|
---|
557 | case GL_BACK:
|
---|
558 | l->ambient[1].r = param[0];
|
---|
559 | l->ambient[1].g = param[1];
|
---|
560 | l->ambient[1].b = param[2];
|
---|
561 | l->ambient[1].a = param[3];
|
---|
562 | break;
|
---|
563 | default:
|
---|
564 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
|
---|
565 | return;
|
---|
566 | }
|
---|
567 | /* FALLTHROUGH! */
|
---|
568 | case GL_DIFFUSE :
|
---|
569 | switch (face)
|
---|
570 | {
|
---|
571 | case GL_FRONT:
|
---|
572 | l->diffuse[0].r = param[0];
|
---|
573 | l->diffuse[0].g = param[1];
|
---|
574 | l->diffuse[0].b = param[2];
|
---|
575 | l->diffuse[0].a = param[3];
|
---|
576 | break;
|
---|
577 | case GL_FRONT_AND_BACK:
|
---|
578 | l->diffuse[0].r = param[0];
|
---|
579 | l->diffuse[0].g = param[1];
|
---|
580 | l->diffuse[0].b = param[2];
|
---|
581 | l->diffuse[0].a = param[3];
|
---|
582 | /* FALLTHROUGH! */
|
---|
583 | case GL_BACK:
|
---|
584 | l->diffuse[1].r = param[0];
|
---|
585 | l->diffuse[1].g = param[1];
|
---|
586 | l->diffuse[1].b = param[2];
|
---|
587 | l->diffuse[1].a = param[3];
|
---|
588 | break;
|
---|
589 | default:
|
---|
590 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
|
---|
591 | return;
|
---|
592 | }
|
---|
593 | break;
|
---|
594 | case GL_SPECULAR :
|
---|
595 | switch (face)
|
---|
596 | {
|
---|
597 | case GL_FRONT:
|
---|
598 | l->specular[0].r = param[0];
|
---|
599 | l->specular[0].g = param[1];
|
---|
600 | l->specular[0].b = param[2];
|
---|
601 | l->specular[0].a = param[3];
|
---|
602 | break;
|
---|
603 | case GL_FRONT_AND_BACK:
|
---|
604 | l->specular[0].r = param[0];
|
---|
605 | l->specular[0].g = param[1];
|
---|
606 | l->specular[0].b = param[2];
|
---|
607 | l->specular[0].a = param[3];
|
---|
608 | /* FALLTHROUGH! */
|
---|
609 | case GL_BACK:
|
---|
610 | l->specular[1].r = param[0];
|
---|
611 | l->specular[1].g = param[1];
|
---|
612 | l->specular[1].b = param[2];
|
---|
613 | l->specular[1].a = param[3];
|
---|
614 | break;
|
---|
615 | default:
|
---|
616 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
|
---|
617 | return;
|
---|
618 | }
|
---|
619 | break;
|
---|
620 | case GL_EMISSION :
|
---|
621 | switch (face)
|
---|
622 | {
|
---|
623 | case GL_FRONT:
|
---|
624 | l->emission[0].r = param[0];
|
---|
625 | l->emission[0].g = param[1];
|
---|
626 | l->emission[0].b = param[2];
|
---|
627 | l->emission[0].a = param[3];
|
---|
628 | break;
|
---|
629 | case GL_FRONT_AND_BACK:
|
---|
630 | l->emission[0].r = param[0];
|
---|
631 | l->emission[0].g = param[1];
|
---|
632 | l->emission[0].b = param[2];
|
---|
633 | l->emission[0].a = param[3];
|
---|
634 | /* FALLTHROUGH! */
|
---|
635 | case GL_BACK:
|
---|
636 | l->emission[1].r = param[0];
|
---|
637 | l->emission[1].g = param[1];
|
---|
638 | l->emission[1].b = param[2];
|
---|
639 | l->emission[1].a = param[3];
|
---|
640 | break;
|
---|
641 | default:
|
---|
642 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
|
---|
643 | return;
|
---|
644 | }
|
---|
645 | break;
|
---|
646 | case GL_SHININESS:
|
---|
647 | if (*param > 180.0f || *param < 0.0f)
|
---|
648 | {
|
---|
649 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMaterialfv: param out of range: %f", param);
|
---|
650 | return;
|
---|
651 | }
|
---|
652 |
|
---|
653 | switch (face)
|
---|
654 | {
|
---|
655 | case GL_FRONT:
|
---|
656 | l->shininess[0] = *param;
|
---|
657 | break;
|
---|
658 | case GL_FRONT_AND_BACK:
|
---|
659 | l->shininess[0] = *param;
|
---|
660 | /* FALLTHROUGH! */
|
---|
661 | case GL_BACK:
|
---|
662 | l->shininess[1] = *param;
|
---|
663 | break;
|
---|
664 | default:
|
---|
665 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
|
---|
666 | return;
|
---|
667 | }
|
---|
668 | break;
|
---|
669 | case GL_COLOR_INDEXES :
|
---|
670 | switch (face)
|
---|
671 | {
|
---|
672 | case GL_FRONT:
|
---|
673 | l->indexes[0][0] = (GLint) param[0];
|
---|
674 | l->indexes[0][1] = (GLint) param[1];
|
---|
675 | l->indexes[0][2] = (GLint) param[2];
|
---|
676 | break;
|
---|
677 | case GL_FRONT_AND_BACK:
|
---|
678 | l->indexes[0][0] = (GLint) param[0];
|
---|
679 | l->indexes[0][1] = (GLint) param[1];
|
---|
680 | l->indexes[0][2] = (GLint) param[2];
|
---|
681 | /* FALLTHROUGH! */
|
---|
682 | case GL_BACK:
|
---|
683 | l->indexes[1][0] = (GLint) param[0];
|
---|
684 | l->indexes[1][1] = (GLint) param[1];
|
---|
685 | l->indexes[1][2] = (GLint) param[2];
|
---|
686 | break;
|
---|
687 | default:
|
---|
688 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad face: 0x%x", face);
|
---|
689 | return;
|
---|
690 | }
|
---|
691 | break;
|
---|
692 | default:
|
---|
693 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialfv: bad pname: 0x%x", pname);
|
---|
694 | return;
|
---|
695 | }
|
---|
696 | DIRTY(lb->material, g->neg_bitid);
|
---|
697 | DIRTY(lb->dirty, g->neg_bitid);
|
---|
698 | }
|
---|
699 |
|
---|
700 | void STATE_APIENTRY crStateMaterialiv (GLenum face, GLenum pname, const GLint *param)
|
---|
701 | {
|
---|
702 | GLfloat f_param;
|
---|
703 | GLcolor f_color;
|
---|
704 |
|
---|
705 | switch (pname)
|
---|
706 | {
|
---|
707 | case GL_AMBIENT :
|
---|
708 | case GL_AMBIENT_AND_DIFFUSE :
|
---|
709 | case GL_DIFFUSE :
|
---|
710 | case GL_SPECULAR :
|
---|
711 | case GL_EMISSION :
|
---|
712 | f_color.r = ((GLfloat) param[0]) / ((GLfloat) CR_MAXINT);
|
---|
713 | f_color.g = ((GLfloat) param[1]) / ((GLfloat) CR_MAXINT);
|
---|
714 | f_color.b = ((GLfloat) param[2]) / ((GLfloat) CR_MAXINT);
|
---|
715 | f_color.a = ((GLfloat) param[3]) / ((GLfloat) CR_MAXINT);
|
---|
716 | crStateMaterialfv( face, pname, (GLfloat *) &f_color );
|
---|
717 | break;
|
---|
718 | case GL_SHININESS:
|
---|
719 | f_param = (GLfloat) (*param);
|
---|
720 | crStateMaterialfv( face, pname, (GLfloat *) &f_param );
|
---|
721 | break;
|
---|
722 | case GL_COLOR_INDEXES :
|
---|
723 | f_param = (GLfloat) (*param);
|
---|
724 | crStateMaterialfv( face, pname, (GLfloat *) &f_param );
|
---|
725 | break;
|
---|
726 | default:
|
---|
727 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterialiv: bad pname: 0x%x", pname);
|
---|
728 | return;
|
---|
729 | }
|
---|
730 | }
|
---|
731 |
|
---|
732 | void STATE_APIENTRY crStateMaterialf (GLenum face, GLenum pname, GLfloat param)
|
---|
733 | {
|
---|
734 | crStateMaterialfv( face, pname, ¶m );
|
---|
735 | }
|
---|
736 |
|
---|
737 | void STATE_APIENTRY crStateMateriali (GLenum face, GLenum pname, GLint param)
|
---|
738 | {
|
---|
739 | GLfloat f_param = (GLfloat) param;
|
---|
740 | crStateMaterialfv( face, pname, &f_param );
|
---|
741 | }
|
---|
742 |
|
---|
743 | void STATE_APIENTRY crStateGetLightfv (GLenum light, GLenum pname, GLfloat *param)
|
---|
744 | {
|
---|
745 | CRContext *g = GetCurrentContext();
|
---|
746 | CRLightingState *l = &(g->lighting);
|
---|
747 | CRLight *lt;
|
---|
748 | unsigned int i;
|
---|
749 |
|
---|
750 | if (g->current.inBeginEnd)
|
---|
751 | {
|
---|
752 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
753 | "glGetLightfv called in begin/end");
|
---|
754 | return;
|
---|
755 | }
|
---|
756 |
|
---|
757 | i = light - GL_LIGHT0;
|
---|
758 | if (i>=g->limits.maxLights)
|
---|
759 | {
|
---|
760 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
761 | "glGetLight: invalid light specified: 0x%x", light);
|
---|
762 | return;
|
---|
763 | }
|
---|
764 |
|
---|
765 | lt = l->light + i;
|
---|
766 |
|
---|
767 | switch (pname)
|
---|
768 | {
|
---|
769 | case GL_AMBIENT:
|
---|
770 | param[0] = lt->ambient.r;
|
---|
771 | param[1] = lt->ambient.g;
|
---|
772 | param[2] = lt->ambient.b;
|
---|
773 | param[3] = lt->ambient.a;
|
---|
774 | break;
|
---|
775 | case GL_DIFFUSE:
|
---|
776 | param[0] = lt->diffuse.r;
|
---|
777 | param[1] = lt->diffuse.g;
|
---|
778 | param[2] = lt->diffuse.b;
|
---|
779 | param[3] = lt->diffuse.a;
|
---|
780 | break;
|
---|
781 | case GL_SPECULAR:
|
---|
782 | param[0] = lt->specular.r;
|
---|
783 | param[1] = lt->specular.g;
|
---|
784 | param[2] = lt->specular.b;
|
---|
785 | param[3] = lt->specular.a;
|
---|
786 | break;
|
---|
787 | case GL_POSITION:
|
---|
788 | param[0] = lt->position.x;
|
---|
789 | param[1] = lt->position.y;
|
---|
790 | param[2] = lt->position.z;
|
---|
791 | param[3] = lt->position.w;
|
---|
792 | break;
|
---|
793 | case GL_SPOT_DIRECTION:
|
---|
794 | param[0] = lt->spotDirection.x;
|
---|
795 | param[1] = lt->spotDirection.y;
|
---|
796 | param[2] = lt->spotDirection.z;
|
---|
797 | #if 0
|
---|
798 | /* the w-component of the direction, although possibly (?)
|
---|
799 | useful to keep around internally, is not returned as part
|
---|
800 | of the get. */
|
---|
801 | param[3] = lt->spotDirection.w;
|
---|
802 | #endif
|
---|
803 | break;
|
---|
804 | case GL_SPOT_EXPONENT:
|
---|
805 | *param = lt->spotExponent;
|
---|
806 | break;
|
---|
807 | case GL_SPOT_CUTOFF:
|
---|
808 | *param = lt->spotCutoff;
|
---|
809 | break;
|
---|
810 | case GL_CONSTANT_ATTENUATION:
|
---|
811 | *param = lt->constantAttenuation;
|
---|
812 | break;
|
---|
813 | case GL_LINEAR_ATTENUATION:
|
---|
814 | *param = lt->linearAttenuation;
|
---|
815 | break;
|
---|
816 | case GL_QUADRATIC_ATTENUATION:
|
---|
817 | *param = lt->quadraticAttenuation;
|
---|
818 | break;
|
---|
819 | default:
|
---|
820 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
821 | "glGetLight: invalid pname: 0x%x", pname);
|
---|
822 | return;
|
---|
823 | }
|
---|
824 | }
|
---|
825 |
|
---|
826 | void STATE_APIENTRY crStateGetLightiv (GLenum light, GLenum pname, GLint *param)
|
---|
827 | {
|
---|
828 | CRContext *g = GetCurrentContext();
|
---|
829 | CRLightingState *l = &(g->lighting);
|
---|
830 | CRLight *lt;
|
---|
831 | unsigned int i;
|
---|
832 |
|
---|
833 | if (g->current.inBeginEnd)
|
---|
834 | {
|
---|
835 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
836 | "glGetLightiv called in begin/end");
|
---|
837 | return;
|
---|
838 | }
|
---|
839 |
|
---|
840 | i = light - GL_LIGHT0;
|
---|
841 | if (i>=g->limits.maxLights)
|
---|
842 | {
|
---|
843 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
844 | "glGetLight: invalid light specified: 0x%x", light);
|
---|
845 | return;
|
---|
846 | }
|
---|
847 |
|
---|
848 | lt = l->light + i;
|
---|
849 |
|
---|
850 | switch (pname)
|
---|
851 | {
|
---|
852 | case GL_AMBIENT:
|
---|
853 | param[0] = (GLint) (lt->ambient.r * CR_MAXINT);
|
---|
854 | param[1] = (GLint) (lt->ambient.g * CR_MAXINT);
|
---|
855 | param[2] = (GLint) (lt->ambient.b * CR_MAXINT);
|
---|
856 | param[3] = (GLint) (lt->ambient.a * CR_MAXINT);
|
---|
857 | break;
|
---|
858 | case GL_DIFFUSE:
|
---|
859 | param[0] = (GLint) (lt->diffuse.r * CR_MAXINT);
|
---|
860 | param[1] = (GLint) (lt->diffuse.g * CR_MAXINT);
|
---|
861 | param[2] = (GLint) (lt->diffuse.b * CR_MAXINT);
|
---|
862 | param[3] = (GLint) (lt->diffuse.a * CR_MAXINT);
|
---|
863 | break;
|
---|
864 | case GL_SPECULAR:
|
---|
865 | param[0] = (GLint) (lt->specular.r * CR_MAXINT);
|
---|
866 | param[1] = (GLint) (lt->specular.g * CR_MAXINT);
|
---|
867 | param[2] = (GLint) (lt->specular.b * CR_MAXINT);
|
---|
868 | param[3] = (GLint) (lt->specular.a * CR_MAXINT);
|
---|
869 | break;
|
---|
870 | case GL_POSITION:
|
---|
871 | param[0] = (GLint) (lt->position.x);
|
---|
872 | param[1] = (GLint) (lt->position.y);
|
---|
873 | param[2] = (GLint) (lt->position.z);
|
---|
874 | param[3] = (GLint) (lt->position.w);
|
---|
875 | break;
|
---|
876 | case GL_SPOT_DIRECTION:
|
---|
877 | param[0] = (GLint) (lt->spotDirection.x);
|
---|
878 | param[1] = (GLint) (lt->spotDirection.y);
|
---|
879 | param[2] = (GLint) (lt->spotDirection.z);
|
---|
880 | #if 0
|
---|
881 | /* the w-component of the direction, although possibly (?)
|
---|
882 | useful to keep around internally, is not returned as part
|
---|
883 | of the get. */
|
---|
884 | param[3] = (GLint) (lt->spotDirection.w);
|
---|
885 | #endif
|
---|
886 | break;
|
---|
887 | case GL_SPOT_EXPONENT:
|
---|
888 | *param = (GLint) (lt->spotExponent);
|
---|
889 | break;
|
---|
890 | case GL_SPOT_CUTOFF:
|
---|
891 | *param = (GLint) (lt->spotCutoff);
|
---|
892 | break;
|
---|
893 | case GL_CONSTANT_ATTENUATION:
|
---|
894 | *param = (GLint) (lt->constantAttenuation);
|
---|
895 | break;
|
---|
896 | case GL_LINEAR_ATTENUATION:
|
---|
897 | *param = (GLint) (lt->linearAttenuation);
|
---|
898 | break;
|
---|
899 | case GL_QUADRATIC_ATTENUATION:
|
---|
900 | *param = (GLint) (lt->quadraticAttenuation);
|
---|
901 | break;
|
---|
902 | default:
|
---|
903 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
904 | "glGetLight: invalid pname: 0x%x", pname);
|
---|
905 | return;
|
---|
906 | }
|
---|
907 | }
|
---|
908 |
|
---|
909 | void STATE_APIENTRY crStateGetMaterialfv (GLenum face, GLenum pname, GLfloat *param)
|
---|
910 | {
|
---|
911 | CRContext *g = GetCurrentContext();
|
---|
912 | CRLightingState *l = &(g->lighting);
|
---|
913 |
|
---|
914 | if (g->current.inBeginEnd)
|
---|
915 | {
|
---|
916 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
917 | "glGetMaterialfv called in begin/end");
|
---|
918 | return;
|
---|
919 | }
|
---|
920 |
|
---|
921 | switch (pname)
|
---|
922 | {
|
---|
923 | case GL_AMBIENT:
|
---|
924 | switch (face)
|
---|
925 | {
|
---|
926 | case GL_FRONT:
|
---|
927 | param[0] = l->ambient[0].r;
|
---|
928 | param[1] = l->ambient[0].g;
|
---|
929 | param[2] = l->ambient[0].b;
|
---|
930 | param[3] = l->ambient[0].a;
|
---|
931 | break;
|
---|
932 | case GL_BACK:
|
---|
933 | param[0] = l->ambient[1].r;
|
---|
934 | param[1] = l->ambient[1].g;
|
---|
935 | param[2] = l->ambient[1].b;
|
---|
936 | param[3] = l->ambient[1].a;
|
---|
937 | break;
|
---|
938 | default:
|
---|
939 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
940 | "glGetMaterialfv: bad face: 0x%x", face);
|
---|
941 | return;
|
---|
942 | }
|
---|
943 | break;
|
---|
944 | case GL_DIFFUSE:
|
---|
945 | switch (face)
|
---|
946 | {
|
---|
947 | case GL_FRONT:
|
---|
948 | param[0] = l->diffuse[0].r;
|
---|
949 | param[1] = l->diffuse[0].g;
|
---|
950 | param[2] = l->diffuse[0].b;
|
---|
951 | param[3] = l->diffuse[0].a;
|
---|
952 | break;
|
---|
953 | case GL_BACK:
|
---|
954 | param[0] = l->diffuse[1].r;
|
---|
955 | param[1] = l->diffuse[1].g;
|
---|
956 | param[2] = l->diffuse[1].b;
|
---|
957 | param[3] = l->diffuse[1].a;
|
---|
958 | break;
|
---|
959 | default:
|
---|
960 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
961 | "glGetMaterialfv: bad face: 0x%x", face);
|
---|
962 | return;
|
---|
963 | }
|
---|
964 | break;
|
---|
965 | case GL_SPECULAR :
|
---|
966 | switch (face)
|
---|
967 | {
|
---|
968 | case GL_FRONT:
|
---|
969 | param[0] = l->specular[0].r;
|
---|
970 | param[1] = l->specular[0].g;
|
---|
971 | param[2] = l->specular[0].b;
|
---|
972 | param[3] = l->specular[0].a;
|
---|
973 | break;
|
---|
974 | case GL_BACK:
|
---|
975 | param[0] = l->specular[1].r;
|
---|
976 | param[1] = l->specular[1].g;
|
---|
977 | param[2] = l->specular[1].b;
|
---|
978 | param[3] = l->specular[1].a;
|
---|
979 | break;
|
---|
980 | default:
|
---|
981 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
982 | "glGetMaterialfv: bad face: 0x%x", face);
|
---|
983 | return;
|
---|
984 | }
|
---|
985 | break;
|
---|
986 | case GL_EMISSION:
|
---|
987 | switch (face)
|
---|
988 | {
|
---|
989 | case GL_FRONT:
|
---|
990 | param[0] = l->emission[0].r;
|
---|
991 | param[1] = l->emission[0].g;
|
---|
992 | param[2] = l->emission[0].b;
|
---|
993 | param[3] = l->emission[0].a;
|
---|
994 | break;
|
---|
995 | case GL_BACK:
|
---|
996 | param[0] = l->emission[1].r;
|
---|
997 | param[1] = l->emission[1].g;
|
---|
998 | param[2] = l->emission[1].b;
|
---|
999 | param[3] = l->emission[1].a;
|
---|
1000 | break;
|
---|
1001 | default:
|
---|
1002 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1003 | "glGetMaterialfv: bad face: 0x%x", face);
|
---|
1004 | return;
|
---|
1005 | }
|
---|
1006 | break;
|
---|
1007 | case GL_SHININESS:
|
---|
1008 | switch (face)
|
---|
1009 | {
|
---|
1010 | case GL_FRONT:
|
---|
1011 | *param = l->shininess[0];
|
---|
1012 | break;
|
---|
1013 | case GL_BACK:
|
---|
1014 | *param = l->shininess[1];
|
---|
1015 | break;
|
---|
1016 | default:
|
---|
1017 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1018 | "glGetMaterialfv: bad face: 0x%x", face);
|
---|
1019 | return;
|
---|
1020 | }
|
---|
1021 | break;
|
---|
1022 | case GL_COLOR_INDEXES :
|
---|
1023 | switch (face)
|
---|
1024 | {
|
---|
1025 | case GL_FRONT:
|
---|
1026 | param[0] = (GLfloat) l->indexes[0][0];
|
---|
1027 | param[1] = (GLfloat) l->indexes[0][1];
|
---|
1028 | param[2] = (GLfloat) l->indexes[0][2];
|
---|
1029 | break;
|
---|
1030 | case GL_BACK:
|
---|
1031 | param[0] = (GLfloat) l->indexes[1][0];
|
---|
1032 | param[1] = (GLfloat) l->indexes[1][1];
|
---|
1033 | param[2] = (GLfloat) l->indexes[1][2];
|
---|
1034 | break;
|
---|
1035 | default:
|
---|
1036 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1037 | "glGetMaterialfv: bad face: 0x%x", face);
|
---|
1038 | return;
|
---|
1039 | }
|
---|
1040 | return;
|
---|
1041 | default:
|
---|
1042 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1043 | "glGetMaterialfv: bad pname: 0x%x", pname);
|
---|
1044 | return;
|
---|
1045 | }
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 |
|
---|
1049 | void STATE_APIENTRY crStateGetMaterialiv (GLenum face, GLenum pname, GLint *param)
|
---|
1050 | {
|
---|
1051 | CRContext *g = GetCurrentContext();
|
---|
1052 | CRLightingState *l = &(g->lighting);
|
---|
1053 |
|
---|
1054 | if (g->current.inBeginEnd)
|
---|
1055 | {
|
---|
1056 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
1057 | "glGetMaterialiv called in begin/end");
|
---|
1058 | return;
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | switch (pname)
|
---|
1062 | {
|
---|
1063 | case GL_AMBIENT:
|
---|
1064 | switch (face)
|
---|
1065 | {
|
---|
1066 | case GL_FRONT:
|
---|
1067 | param[0] = (GLint) (l->ambient[0].r * CR_MAXINT);
|
---|
1068 | param[1] = (GLint) (l->ambient[0].g * CR_MAXINT);
|
---|
1069 | param[2] = (GLint) (l->ambient[0].b * CR_MAXINT);
|
---|
1070 | param[3] = (GLint) (l->ambient[0].a * CR_MAXINT);
|
---|
1071 | break;
|
---|
1072 | case GL_BACK:
|
---|
1073 | param[0] = (GLint) (l->ambient[1].r * CR_MAXINT);
|
---|
1074 | param[1] = (GLint) (l->ambient[1].g * CR_MAXINT);
|
---|
1075 | param[2] = (GLint) (l->ambient[1].b * CR_MAXINT);
|
---|
1076 | param[3] = (GLint) (l->ambient[1].a * CR_MAXINT);
|
---|
1077 | break;
|
---|
1078 | default:
|
---|
1079 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1080 | "glGetMaterialiv: bad face: 0x%x", face);
|
---|
1081 | return;
|
---|
1082 | }
|
---|
1083 | break;
|
---|
1084 | case GL_DIFFUSE:
|
---|
1085 | switch (face)
|
---|
1086 | {
|
---|
1087 | case GL_FRONT:
|
---|
1088 | param[0] = (GLint) (l->diffuse[0].r * CR_MAXINT);
|
---|
1089 | param[1] = (GLint) (l->diffuse[0].g * CR_MAXINT);
|
---|
1090 | param[2] = (GLint) (l->diffuse[0].b * CR_MAXINT);
|
---|
1091 | param[3] = (GLint) (l->diffuse[0].a * CR_MAXINT);
|
---|
1092 | break;
|
---|
1093 | case GL_BACK:
|
---|
1094 | param[0] = (GLint) (l->diffuse[1].r * CR_MAXINT);
|
---|
1095 | param[1] = (GLint) (l->diffuse[1].g * CR_MAXINT);
|
---|
1096 | param[2] = (GLint) (l->diffuse[1].b * CR_MAXINT);
|
---|
1097 | param[3] = (GLint) (l->diffuse[1].a * CR_MAXINT);
|
---|
1098 | break;
|
---|
1099 | default:
|
---|
1100 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1101 | "glGetMaterialiv: bad face: 0x%x", face);
|
---|
1102 | return;
|
---|
1103 | }
|
---|
1104 | break;
|
---|
1105 | case GL_SPECULAR:
|
---|
1106 | switch (face)
|
---|
1107 | {
|
---|
1108 | case GL_FRONT:
|
---|
1109 | param[0] = (GLint) (l->specular[0].r * CR_MAXINT);
|
---|
1110 | param[1] = (GLint) (l->specular[0].g * CR_MAXINT);
|
---|
1111 | param[2] = (GLint) (l->specular[0].b * CR_MAXINT);
|
---|
1112 | param[3] = (GLint) (l->specular[0].a * CR_MAXINT);
|
---|
1113 | break;
|
---|
1114 | case GL_BACK:
|
---|
1115 | param[0] = (GLint) (l->specular[1].r * CR_MAXINT);
|
---|
1116 | param[1] = (GLint) (l->specular[1].g * CR_MAXINT);
|
---|
1117 | param[2] = (GLint) (l->specular[1].b * CR_MAXINT);
|
---|
1118 | param[3] = (GLint) (l->specular[1].a * CR_MAXINT);
|
---|
1119 | break;
|
---|
1120 | default:
|
---|
1121 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1122 | "glGetMaterialiv: bad face: 0x%x", face);
|
---|
1123 | return;
|
---|
1124 | }
|
---|
1125 | break;
|
---|
1126 | case GL_EMISSION:
|
---|
1127 | switch (face)
|
---|
1128 | {
|
---|
1129 | case GL_FRONT:
|
---|
1130 | param[0] = (GLint) (l->emission[0].r * CR_MAXINT);
|
---|
1131 | param[1] = (GLint) (l->emission[0].g * CR_MAXINT);
|
---|
1132 | param[2] = (GLint) (l->emission[0].b * CR_MAXINT);
|
---|
1133 | param[3] = (GLint) (l->emission[0].a * CR_MAXINT);
|
---|
1134 | break;
|
---|
1135 | case GL_BACK:
|
---|
1136 | param[0] = (GLint) (l->emission[1].r * CR_MAXINT);
|
---|
1137 | param[1] = (GLint) (l->emission[1].g * CR_MAXINT);
|
---|
1138 | param[2] = (GLint) (l->emission[1].b * CR_MAXINT);
|
---|
1139 | param[3] = (GLint) (l->emission[1].a * CR_MAXINT);
|
---|
1140 | break;
|
---|
1141 | default:
|
---|
1142 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1143 | "glGetMaterialiv: bad face: 0x%x", face);
|
---|
1144 | return;
|
---|
1145 | }
|
---|
1146 | break;
|
---|
1147 | case GL_SHININESS:
|
---|
1148 | switch (face) {
|
---|
1149 | case GL_FRONT:
|
---|
1150 | *param = (GLint) l->shininess[0];
|
---|
1151 | break;
|
---|
1152 | case GL_BACK:
|
---|
1153 | *param = (GLint) l->shininess[1];
|
---|
1154 | break;
|
---|
1155 | default:
|
---|
1156 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1157 | "glGetMaterialiv: bad face: 0x%x", face);
|
---|
1158 | return;
|
---|
1159 | }
|
---|
1160 | break;
|
---|
1161 | case GL_COLOR_INDEXES :
|
---|
1162 | switch (face)
|
---|
1163 | {
|
---|
1164 | case GL_FRONT:
|
---|
1165 | param[0] = (GLint) l->indexes[0][0];
|
---|
1166 | param[1] = (GLint) l->indexes[0][1];
|
---|
1167 | param[2] = (GLint) l->indexes[0][2];
|
---|
1168 | break;
|
---|
1169 | case GL_BACK:
|
---|
1170 | param[0] = (GLint) l->indexes[1][0];
|
---|
1171 | param[1] = (GLint) l->indexes[1][1];
|
---|
1172 | param[2] = (GLint) l->indexes[1][2];
|
---|
1173 | break;
|
---|
1174 | default:
|
---|
1175 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1176 | "glGetMaterialiv: bad face: 0x%x", face);
|
---|
1177 | return;
|
---|
1178 | }
|
---|
1179 | return;
|
---|
1180 | default:
|
---|
1181 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1182 | "glGetMaterialiv: bad pname: 0x%x", pname);
|
---|
1183 | return;
|
---|
1184 | }
|
---|
1185 | }
|
---|
1186 |
|
---|
1187 | void crStateColorMaterialRecover(void)
|
---|
1188 | {
|
---|
1189 | CRContext *g = GetCurrentContext();
|
---|
1190 | CRLightingState *l = &(g->lighting);
|
---|
1191 | CRCurrentState *c = &(g->current);
|
---|
1192 |
|
---|
1193 | /* Assuming that the "current" values are up to date,
|
---|
1194 | * this function will extract them into the material
|
---|
1195 | * values if COLOR_MATERIAL has been enabled on the
|
---|
1196 | * client. */
|
---|
1197 |
|
---|
1198 | if (l->colorMaterial)
|
---|
1199 | {
|
---|
1200 | /* prevent recursion here (was in tilesortspu_flush.c's doFlush() for a
|
---|
1201 | * short time. Without this, kirchner_colormaterial fails.
|
---|
1202 | */
|
---|
1203 | crStateFlushFunc(NULL);
|
---|
1204 |
|
---|
1205 | crStateMaterialfv( l->colorMaterialFace, l->colorMaterialMode, &(c->vertexAttrib[VERT_ATTRIB_COLOR0][0]) );
|
---|
1206 | }
|
---|
1207 | }
|
---|