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