[PROPSYS]
[reactos.git] / reactos / dll / opengl / 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 <precomp.h>
32
33 #if FEATURE_rastpos
34
35
36 /**
37 * Helper function for all the RasterPos functions.
38 */
39 static void
40 rasterpos(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
41 {
42 GET_CURRENT_CONTEXT(ctx);
43 GLfloat p[4];
44
45 p[0] = x;
46 p[1] = y;
47 p[2] = z;
48 p[3] = w;
49
50 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
51 FLUSH_CURRENT(ctx, 0);
52
53 if (ctx->NewState)
54 _mesa_update_state( ctx );
55
56 ctx->Driver.RasterPos(ctx, p);
57 }
58
59
60 static void GLAPIENTRY
61 _mesa_RasterPos2d(GLdouble x, GLdouble y)
62 {
63 rasterpos((GLfloat)x, (GLfloat)y, (GLfloat)0.0, (GLfloat)1.0);
64 }
65
66 static void GLAPIENTRY
67 _mesa_RasterPos2f(GLfloat x, GLfloat y)
68 {
69 rasterpos(x, y, 0.0F, 1.0F);
70 }
71
72 static void GLAPIENTRY
73 _mesa_RasterPos2i(GLint x, GLint y)
74 {
75 rasterpos((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
76 }
77
78 static void GLAPIENTRY
79 _mesa_RasterPos2s(GLshort x, GLshort y)
80 {
81 rasterpos(x, y, 0.0F, 1.0F);
82 }
83
84 static void GLAPIENTRY
85 _mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
86 {
87 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
88 }
89
90 static void GLAPIENTRY
91 _mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
92 {
93 rasterpos(x, y, z, 1.0F);
94 }
95
96 static void GLAPIENTRY
97 _mesa_RasterPos3i(GLint x, GLint y, GLint z)
98 {
99 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
100 }
101
102 static void GLAPIENTRY
103 _mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
104 {
105 rasterpos(x, y, z, 1.0F);
106 }
107
108 static void GLAPIENTRY
109 _mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
110 {
111 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
112 }
113
114 static void GLAPIENTRY
115 _mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
116 {
117 rasterpos(x, y, z, w);
118 }
119
120 static void GLAPIENTRY
121 _mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
122 {
123 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
124 }
125
126 static void GLAPIENTRY
127 _mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
128 {
129 rasterpos(x, y, z, w);
130 }
131
132 static void GLAPIENTRY
133 _mesa_RasterPos2dv(const GLdouble *v)
134 {
135 rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
136 }
137
138 static void GLAPIENTRY
139 _mesa_RasterPos2fv(const GLfloat *v)
140 {
141 rasterpos(v[0], v[1], 0.0F, 1.0F);
142 }
143
144 static void GLAPIENTRY
145 _mesa_RasterPos2iv(const GLint *v)
146 {
147 rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
148 }
149
150 static void GLAPIENTRY
151 _mesa_RasterPos2sv(const GLshort *v)
152 {
153 rasterpos(v[0], v[1], 0.0F, 1.0F);
154 }
155
156 static void GLAPIENTRY
157 _mesa_RasterPos3dv(const GLdouble *v)
158 {
159 rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
160 }
161
162 static void GLAPIENTRY
163 _mesa_RasterPos3fv(const GLfloat *v)
164 {
165 rasterpos(v[0], v[1], v[2], 1.0F);
166 }
167
168 static void GLAPIENTRY
169 _mesa_RasterPos3iv(const GLint *v)
170 {
171 rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
172 }
173
174 static void GLAPIENTRY
175 _mesa_RasterPos3sv(const GLshort *v)
176 {
177 rasterpos(v[0], v[1], v[2], 1.0F);
178 }
179
180 static void GLAPIENTRY
181 _mesa_RasterPos4dv(const GLdouble *v)
182 {
183 rasterpos((GLfloat) v[0], (GLfloat) v[1],
184 (GLfloat) v[2], (GLfloat) v[3]);
185 }
186
187 static void GLAPIENTRY
188 _mesa_RasterPos4fv(const GLfloat *v)
189 {
190 rasterpos(v[0], v[1], v[2], v[3]);
191 }
192
193 static void GLAPIENTRY
194 _mesa_RasterPos4iv(const GLint *v)
195 {
196 rasterpos((GLfloat) v[0], (GLfloat) v[1],
197 (GLfloat) v[2], (GLfloat) v[3]);
198 }
199
200 static void GLAPIENTRY
201 _mesa_RasterPos4sv(const GLshort *v)
202 {
203 rasterpos(v[0], v[1], v[2], v[3]);
204 }
205
206
207 /**********************************************************************/
208 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
209 /**********************************************************************/
210
211
212 /**
213 * All glWindowPosMESA and glWindowPosARB commands call this function to
214 * update the current raster position.
215 */
216 static void
217 window_pos3f(GLfloat x, GLfloat y, GLfloat z)
218 {
219 GET_CURRENT_CONTEXT(ctx);
220 GLfloat z2;
221
222 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
223 FLUSH_CURRENT(ctx, 0);
224
225 z2 = CLAMP(z, 0.0F, 1.0F) * (ctx->Viewport.Far - ctx->Viewport.Near)
226 + ctx->Viewport.Near;
227
228 /* set raster position */
229 ctx->Current.RasterPos[0] = x;
230 ctx->Current.RasterPos[1] = y;
231 ctx->Current.RasterPos[2] = z2;
232 ctx->Current.RasterPos[3] = 1.0F;
233
234 ctx->Current.RasterPosValid = GL_TRUE;
235
236 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
237 ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
238 else
239 ctx->Current.RasterDistance = 0.0;
240
241 /* raster color = current color or index */
242 ctx->Current.RasterColor[0]
243 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0], 0.0F, 1.0F);
244 ctx->Current.RasterColor[1]
245 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][1], 0.0F, 1.0F);
246 ctx->Current.RasterColor[2]
247 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][2], 0.0F, 1.0F);
248 ctx->Current.RasterColor[3]
249 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3], 0.0F, 1.0F);
250 ctx->Current.RasterSecondaryColor[0]
251 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0], 0.0F, 1.0F);
252 ctx->Current.RasterSecondaryColor[1]
253 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1], 0.0F, 1.0F);
254 ctx->Current.RasterSecondaryColor[2]
255 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][2], 0.0F, 1.0F);
256 ctx->Current.RasterSecondaryColor[3]
257 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][3], 0.0F, 1.0F);
258
259 /* raster texcoord = current texcoord */
260 COPY_4FV( ctx->Current.RasterTexCoords, ctx->Current.Attrib[VERT_ATTRIB_TEX] );
261
262 if (ctx->RenderMode==GL_SELECT) {
263 _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
264 }
265 }
266
267
268 /* This is just to support the GL_MESA_window_pos version */
269 static void
270 window_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
271 {
272 GET_CURRENT_CONTEXT(ctx);
273 window_pos3f(x, y, z);
274 ctx->Current.RasterPos[3] = w;
275 }
276
277
278 static void GLAPIENTRY
279 _mesa_WindowPos2dMESA(GLdouble x, GLdouble y)
280 {
281 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
282 }
283
284 static void GLAPIENTRY
285 _mesa_WindowPos2fMESA(GLfloat x, GLfloat y)
286 {
287 window_pos4f(x, y, 0.0F, 1.0F);
288 }
289
290 static void GLAPIENTRY
291 _mesa_WindowPos2iMESA(GLint x, GLint y)
292 {
293 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
294 }
295
296 static void GLAPIENTRY
297 _mesa_WindowPos2sMESA(GLshort x, GLshort y)
298 {
299 window_pos4f(x, y, 0.0F, 1.0F);
300 }
301
302 static void GLAPIENTRY
303 _mesa_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
304 {
305 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
306 }
307
308 static void GLAPIENTRY
309 _mesa_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
310 {
311 window_pos4f(x, y, z, 1.0F);
312 }
313
314 static void GLAPIENTRY
315 _mesa_WindowPos3iMESA(GLint x, GLint y, GLint z)
316 {
317 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
318 }
319
320 static void GLAPIENTRY
321 _mesa_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
322 {
323 window_pos4f(x, y, z, 1.0F);
324 }
325
326 static void GLAPIENTRY
327 _mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
328 {
329 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
330 }
331
332 static void GLAPIENTRY
333 _mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
334 {
335 window_pos4f(x, y, z, w);
336 }
337
338 static void GLAPIENTRY
339 _mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
340 {
341 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
342 }
343
344 static void GLAPIENTRY
345 _mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
346 {
347 window_pos4f(x, y, z, w);
348 }
349
350 static void GLAPIENTRY
351 _mesa_WindowPos2dvMESA(const GLdouble *v)
352 {
353 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
354 }
355
356 static void GLAPIENTRY
357 _mesa_WindowPos2fvMESA(const GLfloat *v)
358 {
359 window_pos4f(v[0], v[1], 0.0F, 1.0F);
360 }
361
362 static void GLAPIENTRY
363 _mesa_WindowPos2ivMESA(const GLint *v)
364 {
365 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
366 }
367
368 static void GLAPIENTRY
369 _mesa_WindowPos2svMESA(const GLshort *v)
370 {
371 window_pos4f(v[0], v[1], 0.0F, 1.0F);
372 }
373
374 static void GLAPIENTRY
375 _mesa_WindowPos3dvMESA(const GLdouble *v)
376 {
377 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
378 }
379
380 static void GLAPIENTRY
381 _mesa_WindowPos3fvMESA(const GLfloat *v)
382 {
383 window_pos4f(v[0], v[1], v[2], 1.0);
384 }
385
386 static void GLAPIENTRY
387 _mesa_WindowPos3ivMESA(const GLint *v)
388 {
389 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
390 }
391
392 static void GLAPIENTRY
393 _mesa_WindowPos3svMESA(const GLshort *v)
394 {
395 window_pos4f(v[0], v[1], v[2], 1.0F);
396 }
397
398 static void GLAPIENTRY
399 _mesa_WindowPos4dvMESA(const GLdouble *v)
400 {
401 window_pos4f((GLfloat) v[0], (GLfloat) v[1],
402 (GLfloat) v[2], (GLfloat) v[3]);
403 }
404
405 static void GLAPIENTRY
406 _mesa_WindowPos4fvMESA(const GLfloat *v)
407 {
408 window_pos4f(v[0], v[1], v[2], v[3]);
409 }
410
411 static void GLAPIENTRY
412 _mesa_WindowPos4ivMESA(const GLint *v)
413 {
414 window_pos4f((GLfloat) v[0], (GLfloat) v[1],
415 (GLfloat) v[2], (GLfloat) v[3]);
416 }
417
418 static void GLAPIENTRY
419 _mesa_WindowPos4svMESA(const GLshort *v)
420 {
421 window_pos4f(v[0], v[1], v[2], v[3]);
422 }
423
424
425 #if 0
426
427 /*
428 * OpenGL implementation of glWindowPos*MESA()
429 */
430 void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
431 {
432 GLfloat fx, fy;
433
434 /* Push current matrix mode and viewport attributes */
435 glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
436
437 /* Setup projection parameters */
438 glMatrixMode( GL_PROJECTION );
439 glPushMatrix();
440 glLoadIdentity();
441 glMatrixMode( GL_MODELVIEW );
442 glPushMatrix();
443 glLoadIdentity();
444
445 glDepthRange( z, z );
446 glViewport( (int) x - 1, (int) y - 1, 2, 2 );
447
448 /* set the raster (window) position */
449 fx = x - (int) x;
450 fy = y - (int) y;
451 glRasterPos4f( fx, fy, 0.0, w );
452
453 /* restore matrices, viewport and matrix mode */
454 glPopMatrix();
455 glMatrixMode( GL_PROJECTION );
456 glPopMatrix();
457
458 glPopAttrib();
459 }
460
461 #endif
462
463
464 void
465 _mesa_init_rastpos_dispatch(struct _glapi_table *disp)
466 {
467 SET_RasterPos2f(disp, _mesa_RasterPos2f);
468 SET_RasterPos2fv(disp, _mesa_RasterPos2fv);
469 SET_RasterPos2i(disp, _mesa_RasterPos2i);
470 SET_RasterPos2iv(disp, _mesa_RasterPos2iv);
471 SET_RasterPos2d(disp, _mesa_RasterPos2d);
472 SET_RasterPos2dv(disp, _mesa_RasterPos2dv);
473 SET_RasterPos2s(disp, _mesa_RasterPos2s);
474 SET_RasterPos2sv(disp, _mesa_RasterPos2sv);
475 SET_RasterPos3d(disp, _mesa_RasterPos3d);
476 SET_RasterPos3dv(disp, _mesa_RasterPos3dv);
477 SET_RasterPos3f(disp, _mesa_RasterPos3f);
478 SET_RasterPos3fv(disp, _mesa_RasterPos3fv);
479 SET_RasterPos3i(disp, _mesa_RasterPos3i);
480 SET_RasterPos3iv(disp, _mesa_RasterPos3iv);
481 SET_RasterPos3s(disp, _mesa_RasterPos3s);
482 SET_RasterPos3sv(disp, _mesa_RasterPos3sv);
483 SET_RasterPos4d(disp, _mesa_RasterPos4d);
484 SET_RasterPos4dv(disp, _mesa_RasterPos4dv);
485 SET_RasterPos4f(disp, _mesa_RasterPos4f);
486 SET_RasterPos4fv(disp, _mesa_RasterPos4fv);
487 SET_RasterPos4i(disp, _mesa_RasterPos4i);
488 SET_RasterPos4iv(disp, _mesa_RasterPos4iv);
489 SET_RasterPos4s(disp, _mesa_RasterPos4s);
490 SET_RasterPos4sv(disp, _mesa_RasterPos4sv);
491
492 /* 197. GL_MESA_window_pos */
493 SET_WindowPos2dMESA(disp, _mesa_WindowPos2dMESA);
494 SET_WindowPos2dvMESA(disp, _mesa_WindowPos2dvMESA);
495 SET_WindowPos2fMESA(disp, _mesa_WindowPos2fMESA);
496 SET_WindowPos2fvMESA(disp, _mesa_WindowPos2fvMESA);
497 SET_WindowPos2iMESA(disp, _mesa_WindowPos2iMESA);
498 SET_WindowPos2ivMESA(disp, _mesa_WindowPos2ivMESA);
499 SET_WindowPos2sMESA(disp, _mesa_WindowPos2sMESA);
500 SET_WindowPos2svMESA(disp, _mesa_WindowPos2svMESA);
501 SET_WindowPos3dMESA(disp, _mesa_WindowPos3dMESA);
502 SET_WindowPos3dvMESA(disp, _mesa_WindowPos3dvMESA);
503 SET_WindowPos3fMESA(disp, _mesa_WindowPos3fMESA);
504 SET_WindowPos3fvMESA(disp, _mesa_WindowPos3fvMESA);
505 SET_WindowPos3iMESA(disp, _mesa_WindowPos3iMESA);
506 SET_WindowPos3ivMESA(disp, _mesa_WindowPos3ivMESA);
507 SET_WindowPos3sMESA(disp, _mesa_WindowPos3sMESA);
508 SET_WindowPos3svMESA(disp, _mesa_WindowPos3svMESA);
509 SET_WindowPos4dMESA(disp, _mesa_WindowPos4dMESA);
510 SET_WindowPos4dvMESA(disp, _mesa_WindowPos4dvMESA);
511 SET_WindowPos4fMESA(disp, _mesa_WindowPos4fMESA);
512 SET_WindowPos4fvMESA(disp, _mesa_WindowPos4fvMESA);
513 SET_WindowPos4iMESA(disp, _mesa_WindowPos4iMESA);
514 SET_WindowPos4ivMESA(disp, _mesa_WindowPos4ivMESA);
515 SET_WindowPos4sMESA(disp, _mesa_WindowPos4sMESA);
516 SET_WindowPos4svMESA(disp, _mesa_WindowPos4svMESA);
517 }
518
519
520 #endif /* FEATURE_rastpos */
521
522
523 /**********************************************************************/
524 /** \name Initialization */
525 /**********************************************************************/
526 /*@{*/
527
528 /**
529 * Initialize the context current raster position information.
530 *
531 * \param ctx GL context.
532 *
533 * Initialize the current raster position information in
534 * __struct gl_contextRec::Current, and adds the extension entry points to the
535 * dispatcher.
536 */
537 void _mesa_init_rastpos( struct gl_context * ctx )
538 {
539 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
540 ctx->Current.RasterDistance = 0.0;
541 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
542 ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 );
543 ASSIGN_4V( ctx->Current.RasterTexCoords, 0.0, 0.0, 0.0, 1.0 );
544 ctx->Current.RasterPosValid = GL_TRUE;
545 }
546
547 /*@}*/