mesa/es: Remove redundant light pname and light validation
[mesa.git] / src / mesa / main / rastpos.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file rastpos.c
28 * Raster position operations.
29 */
30
31 #include "glheader.h"
32 #include "context.h"
33 #include "feedback.h"
34 #include "macros.h"
35 #include "mfeatures.h"
36 #include "mtypes.h"
37 #include "rastpos.h"
38 #include "state.h"
39 #include "main/dispatch.h"
40
41
42 #if FEATURE_rastpos
43
44
45 /**
46 * Helper function for all the RasterPos functions.
47 */
48 static void
49 rasterpos(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
50 {
51 GET_CURRENT_CONTEXT(ctx);
52 GLfloat p[4];
53
54 p[0] = x;
55 p[1] = y;
56 p[2] = z;
57 p[3] = w;
58
59 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
60 FLUSH_CURRENT(ctx, 0);
61
62 if (ctx->NewState)
63 _mesa_update_state( ctx );
64
65 ctx->Driver.RasterPos(ctx, p);
66 }
67
68
69 static void GLAPIENTRY
70 _mesa_RasterPos2d(GLdouble x, GLdouble y)
71 {
72 rasterpos((GLfloat)x, (GLfloat)y, (GLfloat)0.0, (GLfloat)1.0);
73 }
74
75 static void GLAPIENTRY
76 _mesa_RasterPos2f(GLfloat x, GLfloat y)
77 {
78 rasterpos(x, y, 0.0F, 1.0F);
79 }
80
81 static void GLAPIENTRY
82 _mesa_RasterPos2i(GLint x, GLint y)
83 {
84 rasterpos((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
85 }
86
87 static void GLAPIENTRY
88 _mesa_RasterPos2s(GLshort x, GLshort y)
89 {
90 rasterpos(x, y, 0.0F, 1.0F);
91 }
92
93 static void GLAPIENTRY
94 _mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
95 {
96 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
97 }
98
99 static void GLAPIENTRY
100 _mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
101 {
102 rasterpos(x, y, z, 1.0F);
103 }
104
105 static void GLAPIENTRY
106 _mesa_RasterPos3i(GLint x, GLint y, GLint z)
107 {
108 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
109 }
110
111 static void GLAPIENTRY
112 _mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
113 {
114 rasterpos(x, y, z, 1.0F);
115 }
116
117 static void GLAPIENTRY
118 _mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
119 {
120 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
121 }
122
123 static void GLAPIENTRY
124 _mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
125 {
126 rasterpos(x, y, z, w);
127 }
128
129 static void GLAPIENTRY
130 _mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
131 {
132 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
133 }
134
135 static void GLAPIENTRY
136 _mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
137 {
138 rasterpos(x, y, z, w);
139 }
140
141 static void GLAPIENTRY
142 _mesa_RasterPos2dv(const GLdouble *v)
143 {
144 rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
145 }
146
147 static void GLAPIENTRY
148 _mesa_RasterPos2fv(const GLfloat *v)
149 {
150 rasterpos(v[0], v[1], 0.0F, 1.0F);
151 }
152
153 static void GLAPIENTRY
154 _mesa_RasterPos2iv(const GLint *v)
155 {
156 rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
157 }
158
159 static void GLAPIENTRY
160 _mesa_RasterPos2sv(const GLshort *v)
161 {
162 rasterpos(v[0], v[1], 0.0F, 1.0F);
163 }
164
165 static void GLAPIENTRY
166 _mesa_RasterPos3dv(const GLdouble *v)
167 {
168 rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
169 }
170
171 static void GLAPIENTRY
172 _mesa_RasterPos3fv(const GLfloat *v)
173 {
174 rasterpos(v[0], v[1], v[2], 1.0F);
175 }
176
177 static void GLAPIENTRY
178 _mesa_RasterPos3iv(const GLint *v)
179 {
180 rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
181 }
182
183 static void GLAPIENTRY
184 _mesa_RasterPos3sv(const GLshort *v)
185 {
186 rasterpos(v[0], v[1], v[2], 1.0F);
187 }
188
189 static void GLAPIENTRY
190 _mesa_RasterPos4dv(const GLdouble *v)
191 {
192 rasterpos((GLfloat) v[0], (GLfloat) v[1],
193 (GLfloat) v[2], (GLfloat) v[3]);
194 }
195
196 static void GLAPIENTRY
197 _mesa_RasterPos4fv(const GLfloat *v)
198 {
199 rasterpos(v[0], v[1], v[2], v[3]);
200 }
201
202 static void GLAPIENTRY
203 _mesa_RasterPos4iv(const GLint *v)
204 {
205 rasterpos((GLfloat) v[0], (GLfloat) v[1],
206 (GLfloat) v[2], (GLfloat) v[3]);
207 }
208
209 static void GLAPIENTRY
210 _mesa_RasterPos4sv(const GLshort *v)
211 {
212 rasterpos(v[0], v[1], v[2], v[3]);
213 }
214
215
216 /**********************************************************************/
217 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
218 /**********************************************************************/
219
220
221 /**
222 * All glWindowPosMESA and glWindowPosARB commands call this function to
223 * update the current raster position.
224 */
225 static void
226 window_pos3f(GLfloat x, GLfloat y, GLfloat z)
227 {
228 GET_CURRENT_CONTEXT(ctx);
229 GLfloat z2;
230
231 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
232 FLUSH_CURRENT(ctx, 0);
233
234 z2 = CLAMP(z, 0.0F, 1.0F) * (ctx->Viewport.Far - ctx->Viewport.Near)
235 + ctx->Viewport.Near;
236
237 /* set raster position */
238 ctx->Current.RasterPos[0] = x;
239 ctx->Current.RasterPos[1] = y;
240 ctx->Current.RasterPos[2] = z2;
241 ctx->Current.RasterPos[3] = 1.0F;
242
243 ctx->Current.RasterPosValid = GL_TRUE;
244
245 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
246 ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
247 else
248 ctx->Current.RasterDistance = 0.0;
249
250 /* raster color = current color or index */
251 ctx->Current.RasterColor[0]
252 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0], 0.0F, 1.0F);
253 ctx->Current.RasterColor[1]
254 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][1], 0.0F, 1.0F);
255 ctx->Current.RasterColor[2]
256 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][2], 0.0F, 1.0F);
257 ctx->Current.RasterColor[3]
258 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3], 0.0F, 1.0F);
259 ctx->Current.RasterSecondaryColor[0]
260 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0], 0.0F, 1.0F);
261 ctx->Current.RasterSecondaryColor[1]
262 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1], 0.0F, 1.0F);
263 ctx->Current.RasterSecondaryColor[2]
264 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][2], 0.0F, 1.0F);
265 ctx->Current.RasterSecondaryColor[3]
266 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][3], 0.0F, 1.0F);
267
268 /* raster texcoord = current texcoord */
269 {
270 GLuint texSet;
271 for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) {
272 assert(texSet < Elements(ctx->Current.RasterTexCoords));
273 COPY_4FV( ctx->Current.RasterTexCoords[texSet],
274 ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] );
275 }
276 }
277
278 if (ctx->RenderMode==GL_SELECT) {
279 _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
280 }
281 }
282
283
284 /* This is just to support the GL_MESA_window_pos version */
285 static void
286 window_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
287 {
288 GET_CURRENT_CONTEXT(ctx);
289 window_pos3f(x, y, z);
290 ctx->Current.RasterPos[3] = w;
291 }
292
293
294 static void GLAPIENTRY
295 _mesa_WindowPos2dMESA(GLdouble x, GLdouble y)
296 {
297 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
298 }
299
300 static void GLAPIENTRY
301 _mesa_WindowPos2fMESA(GLfloat x, GLfloat y)
302 {
303 window_pos4f(x, y, 0.0F, 1.0F);
304 }
305
306 static void GLAPIENTRY
307 _mesa_WindowPos2iMESA(GLint x, GLint y)
308 {
309 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
310 }
311
312 static void GLAPIENTRY
313 _mesa_WindowPos2sMESA(GLshort x, GLshort y)
314 {
315 window_pos4f(x, y, 0.0F, 1.0F);
316 }
317
318 static void GLAPIENTRY
319 _mesa_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
320 {
321 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
322 }
323
324 static void GLAPIENTRY
325 _mesa_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
326 {
327 window_pos4f(x, y, z, 1.0F);
328 }
329
330 static void GLAPIENTRY
331 _mesa_WindowPos3iMESA(GLint x, GLint y, GLint z)
332 {
333 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
334 }
335
336 static void GLAPIENTRY
337 _mesa_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
338 {
339 window_pos4f(x, y, z, 1.0F);
340 }
341
342 static void GLAPIENTRY
343 _mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
344 {
345 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
346 }
347
348 static void GLAPIENTRY
349 _mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
350 {
351 window_pos4f(x, y, z, w);
352 }
353
354 static void GLAPIENTRY
355 _mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
356 {
357 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
358 }
359
360 static void GLAPIENTRY
361 _mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
362 {
363 window_pos4f(x, y, z, w);
364 }
365
366 static void GLAPIENTRY
367 _mesa_WindowPos2dvMESA(const GLdouble *v)
368 {
369 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
370 }
371
372 static void GLAPIENTRY
373 _mesa_WindowPos2fvMESA(const GLfloat *v)
374 {
375 window_pos4f(v[0], v[1], 0.0F, 1.0F);
376 }
377
378 static void GLAPIENTRY
379 _mesa_WindowPos2ivMESA(const GLint *v)
380 {
381 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
382 }
383
384 static void GLAPIENTRY
385 _mesa_WindowPos2svMESA(const GLshort *v)
386 {
387 window_pos4f(v[0], v[1], 0.0F, 1.0F);
388 }
389
390 static void GLAPIENTRY
391 _mesa_WindowPos3dvMESA(const GLdouble *v)
392 {
393 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
394 }
395
396 static void GLAPIENTRY
397 _mesa_WindowPos3fvMESA(const GLfloat *v)
398 {
399 window_pos4f(v[0], v[1], v[2], 1.0);
400 }
401
402 static void GLAPIENTRY
403 _mesa_WindowPos3ivMESA(const GLint *v)
404 {
405 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
406 }
407
408 static void GLAPIENTRY
409 _mesa_WindowPos3svMESA(const GLshort *v)
410 {
411 window_pos4f(v[0], v[1], v[2], 1.0F);
412 }
413
414 static void GLAPIENTRY
415 _mesa_WindowPos4dvMESA(const GLdouble *v)
416 {
417 window_pos4f((GLfloat) v[0], (GLfloat) v[1],
418 (GLfloat) v[2], (GLfloat) v[3]);
419 }
420
421 static void GLAPIENTRY
422 _mesa_WindowPos4fvMESA(const GLfloat *v)
423 {
424 window_pos4f(v[0], v[1], v[2], v[3]);
425 }
426
427 static void GLAPIENTRY
428 _mesa_WindowPos4ivMESA(const GLint *v)
429 {
430 window_pos4f((GLfloat) v[0], (GLfloat) v[1],
431 (GLfloat) v[2], (GLfloat) v[3]);
432 }
433
434 static void GLAPIENTRY
435 _mesa_WindowPos4svMESA(const GLshort *v)
436 {
437 window_pos4f(v[0], v[1], v[2], v[3]);
438 }
439
440
441 #if 0
442
443 /*
444 * OpenGL implementation of glWindowPos*MESA()
445 */
446 void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
447 {
448 GLfloat fx, fy;
449
450 /* Push current matrix mode and viewport attributes */
451 glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
452
453 /* Setup projection parameters */
454 glMatrixMode( GL_PROJECTION );
455 glPushMatrix();
456 glLoadIdentity();
457 glMatrixMode( GL_MODELVIEW );
458 glPushMatrix();
459 glLoadIdentity();
460
461 glDepthRange( z, z );
462 glViewport( (int) x - 1, (int) y - 1, 2, 2 );
463
464 /* set the raster (window) position */
465 fx = x - (int) x;
466 fy = y - (int) y;
467 glRasterPos4f( fx, fy, 0.0, w );
468
469 /* restore matrices, viewport and matrix mode */
470 glPopMatrix();
471 glMatrixMode( GL_PROJECTION );
472 glPopMatrix();
473
474 glPopAttrib();
475 }
476
477 #endif
478
479
480 void
481 _mesa_init_rastpos_dispatch(struct _glapi_table *disp)
482 {
483 SET_RasterPos2f(disp, _mesa_RasterPos2f);
484 SET_RasterPos2fv(disp, _mesa_RasterPos2fv);
485 SET_RasterPos2i(disp, _mesa_RasterPos2i);
486 SET_RasterPos2iv(disp, _mesa_RasterPos2iv);
487 SET_RasterPos2d(disp, _mesa_RasterPos2d);
488 SET_RasterPos2dv(disp, _mesa_RasterPos2dv);
489 SET_RasterPos2s(disp, _mesa_RasterPos2s);
490 SET_RasterPos2sv(disp, _mesa_RasterPos2sv);
491 SET_RasterPos3d(disp, _mesa_RasterPos3d);
492 SET_RasterPos3dv(disp, _mesa_RasterPos3dv);
493 SET_RasterPos3f(disp, _mesa_RasterPos3f);
494 SET_RasterPos3fv(disp, _mesa_RasterPos3fv);
495 SET_RasterPos3i(disp, _mesa_RasterPos3i);
496 SET_RasterPos3iv(disp, _mesa_RasterPos3iv);
497 SET_RasterPos3s(disp, _mesa_RasterPos3s);
498 SET_RasterPos3sv(disp, _mesa_RasterPos3sv);
499 SET_RasterPos4d(disp, _mesa_RasterPos4d);
500 SET_RasterPos4dv(disp, _mesa_RasterPos4dv);
501 SET_RasterPos4f(disp, _mesa_RasterPos4f);
502 SET_RasterPos4fv(disp, _mesa_RasterPos4fv);
503 SET_RasterPos4i(disp, _mesa_RasterPos4i);
504 SET_RasterPos4iv(disp, _mesa_RasterPos4iv);
505 SET_RasterPos4s(disp, _mesa_RasterPos4s);
506 SET_RasterPos4sv(disp, _mesa_RasterPos4sv);
507
508 /* 197. GL_MESA_window_pos */
509 SET_WindowPos2dMESA(disp, _mesa_WindowPos2dMESA);
510 SET_WindowPos2dvMESA(disp, _mesa_WindowPos2dvMESA);
511 SET_WindowPos2fMESA(disp, _mesa_WindowPos2fMESA);
512 SET_WindowPos2fvMESA(disp, _mesa_WindowPos2fvMESA);
513 SET_WindowPos2iMESA(disp, _mesa_WindowPos2iMESA);
514 SET_WindowPos2ivMESA(disp, _mesa_WindowPos2ivMESA);
515 SET_WindowPos2sMESA(disp, _mesa_WindowPos2sMESA);
516 SET_WindowPos2svMESA(disp, _mesa_WindowPos2svMESA);
517 SET_WindowPos3dMESA(disp, _mesa_WindowPos3dMESA);
518 SET_WindowPos3dvMESA(disp, _mesa_WindowPos3dvMESA);
519 SET_WindowPos3fMESA(disp, _mesa_WindowPos3fMESA);
520 SET_WindowPos3fvMESA(disp, _mesa_WindowPos3fvMESA);
521 SET_WindowPos3iMESA(disp, _mesa_WindowPos3iMESA);
522 SET_WindowPos3ivMESA(disp, _mesa_WindowPos3ivMESA);
523 SET_WindowPos3sMESA(disp, _mesa_WindowPos3sMESA);
524 SET_WindowPos3svMESA(disp, _mesa_WindowPos3svMESA);
525 SET_WindowPos4dMESA(disp, _mesa_WindowPos4dMESA);
526 SET_WindowPos4dvMESA(disp, _mesa_WindowPos4dvMESA);
527 SET_WindowPos4fMESA(disp, _mesa_WindowPos4fMESA);
528 SET_WindowPos4fvMESA(disp, _mesa_WindowPos4fvMESA);
529 SET_WindowPos4iMESA(disp, _mesa_WindowPos4iMESA);
530 SET_WindowPos4ivMESA(disp, _mesa_WindowPos4ivMESA);
531 SET_WindowPos4sMESA(disp, _mesa_WindowPos4sMESA);
532 SET_WindowPos4svMESA(disp, _mesa_WindowPos4svMESA);
533 }
534
535
536 #endif /* FEATURE_rastpos */
537
538
539 /**********************************************************************/
540 /** \name Initialization */
541 /**********************************************************************/
542 /*@{*/
543
544 /**
545 * Initialize the context current raster position information.
546 *
547 * \param ctx GL context.
548 *
549 * Initialize the current raster position information in
550 * __struct gl_contextRec::Current, and adds the extension entry points to the
551 * dispatcher.
552 */
553 void _mesa_init_rastpos( struct gl_context * ctx )
554 {
555 int i;
556
557 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
558 ctx->Current.RasterDistance = 0.0;
559 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
560 ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 );
561 for (i = 0; i < Elements(ctx->Current.RasterTexCoords); i++)
562 ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
563 ctx->Current.RasterPosValid = GL_TRUE;
564 }
565
566 /*@}*/