be61dc265d16e43c2128c5826be522f7aa7e9a33
2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
28 * Raster position operations.
37 #include "glapi/dispatch.h"
44 * Helper function for all the RasterPos functions.
47 rasterpos(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
49 GET_CURRENT_CONTEXT(ctx
);
57 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
58 FLUSH_CURRENT(ctx
, 0);
61 _mesa_update_state( ctx
);
63 ctx
->Driver
.RasterPos(ctx
, p
);
67 static void GLAPIENTRY
68 _mesa_RasterPos2d(GLdouble x
, GLdouble y
)
70 rasterpos((GLfloat
)x
, (GLfloat
)y
, (GLfloat
)0.0, (GLfloat
)1.0);
73 static void GLAPIENTRY
74 _mesa_RasterPos2f(GLfloat x
, GLfloat y
)
76 rasterpos(x
, y
, 0.0F
, 1.0F
);
79 static void GLAPIENTRY
80 _mesa_RasterPos2i(GLint x
, GLint y
)
82 rasterpos((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
85 static void GLAPIENTRY
86 _mesa_RasterPos2s(GLshort x
, GLshort y
)
88 rasterpos(x
, y
, 0.0F
, 1.0F
);
91 static void GLAPIENTRY
92 _mesa_RasterPos3d(GLdouble x
, GLdouble y
, GLdouble z
)
94 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
97 static void GLAPIENTRY
98 _mesa_RasterPos3f(GLfloat x
, GLfloat y
, GLfloat z
)
100 rasterpos(x
, y
, z
, 1.0F
);
103 static void GLAPIENTRY
104 _mesa_RasterPos3i(GLint x
, GLint y
, GLint z
)
106 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
109 static void GLAPIENTRY
110 _mesa_RasterPos3s(GLshort x
, GLshort y
, GLshort z
)
112 rasterpos(x
, y
, z
, 1.0F
);
115 static void GLAPIENTRY
116 _mesa_RasterPos4d(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
118 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
121 static void GLAPIENTRY
122 _mesa_RasterPos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
124 rasterpos(x
, y
, z
, w
);
127 static void GLAPIENTRY
128 _mesa_RasterPos4i(GLint x
, GLint y
, GLint z
, GLint w
)
130 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
133 static void GLAPIENTRY
134 _mesa_RasterPos4s(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
136 rasterpos(x
, y
, z
, w
);
139 static void GLAPIENTRY
140 _mesa_RasterPos2dv(const GLdouble
*v
)
142 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
145 static void GLAPIENTRY
146 _mesa_RasterPos2fv(const GLfloat
*v
)
148 rasterpos(v
[0], v
[1], 0.0F
, 1.0F
);
151 static void GLAPIENTRY
152 _mesa_RasterPos2iv(const GLint
*v
)
154 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
157 static void GLAPIENTRY
158 _mesa_RasterPos2sv(const GLshort
*v
)
160 rasterpos(v
[0], v
[1], 0.0F
, 1.0F
);
163 static void GLAPIENTRY
164 _mesa_RasterPos3dv(const GLdouble
*v
)
166 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
169 static void GLAPIENTRY
170 _mesa_RasterPos3fv(const GLfloat
*v
)
172 rasterpos(v
[0], v
[1], v
[2], 1.0F
);
175 static void GLAPIENTRY
176 _mesa_RasterPos3iv(const GLint
*v
)
178 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
181 static void GLAPIENTRY
182 _mesa_RasterPos3sv(const GLshort
*v
)
184 rasterpos(v
[0], v
[1], v
[2], 1.0F
);
187 static void GLAPIENTRY
188 _mesa_RasterPos4dv(const GLdouble
*v
)
190 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1],
191 (GLfloat
) v
[2], (GLfloat
) v
[3]);
194 static void GLAPIENTRY
195 _mesa_RasterPos4fv(const GLfloat
*v
)
197 rasterpos(v
[0], v
[1], v
[2], v
[3]);
200 static void GLAPIENTRY
201 _mesa_RasterPos4iv(const GLint
*v
)
203 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1],
204 (GLfloat
) v
[2], (GLfloat
) v
[3]);
207 static void GLAPIENTRY
208 _mesa_RasterPos4sv(const GLshort
*v
)
210 rasterpos(v
[0], v
[1], v
[2], v
[3]);
214 /**********************************************************************/
215 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
216 /**********************************************************************/
220 * All glWindowPosMESA and glWindowPosARB commands call this function to
221 * update the current raster position.
224 window_pos3f(GLfloat x
, GLfloat y
, GLfloat z
)
226 GET_CURRENT_CONTEXT(ctx
);
229 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
230 FLUSH_CURRENT(ctx
, 0);
232 z2
= CLAMP(z
, 0.0F
, 1.0F
) * (ctx
->Viewport
.Far
- ctx
->Viewport
.Near
)
233 + ctx
->Viewport
.Near
;
235 /* set raster position */
236 ctx
->Current
.RasterPos
[0] = x
;
237 ctx
->Current
.RasterPos
[1] = y
;
238 ctx
->Current
.RasterPos
[2] = z2
;
239 ctx
->Current
.RasterPos
[3] = 1.0F
;
241 ctx
->Current
.RasterPosValid
= GL_TRUE
;
243 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
)
244 ctx
->Current
.RasterDistance
= ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0];
246 ctx
->Current
.RasterDistance
= 0.0;
248 /* raster color = current color or index */
249 if (ctx
->Visual
.rgbMode
) {
250 ctx
->Current
.RasterColor
[0]
251 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][0], 0.0F
, 1.0F
);
252 ctx
->Current
.RasterColor
[1]
253 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][1], 0.0F
, 1.0F
);
254 ctx
->Current
.RasterColor
[2]
255 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][2], 0.0F
, 1.0F
);
256 ctx
->Current
.RasterColor
[3]
257 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][3], 0.0F
, 1.0F
);
258 ctx
->Current
.RasterSecondaryColor
[0]
259 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][0], 0.0F
, 1.0F
);
260 ctx
->Current
.RasterSecondaryColor
[1]
261 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][1], 0.0F
, 1.0F
);
262 ctx
->Current
.RasterSecondaryColor
[2]
263 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][2], 0.0F
, 1.0F
);
264 ctx
->Current
.RasterSecondaryColor
[3]
265 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][3], 0.0F
, 1.0F
);
268 ctx
->Current
.RasterIndex
269 = ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR_INDEX
][0];
272 /* raster texcoord = current texcoord */
275 for (texSet
= 0; texSet
< ctx
->Const
.MaxTextureCoordUnits
; texSet
++) {
276 assert(texSet
< Elements(ctx
->Current
.RasterTexCoords
));
277 COPY_4FV( ctx
->Current
.RasterTexCoords
[texSet
],
278 ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ texSet
] );
282 if (ctx
->RenderMode
==GL_SELECT
) {
283 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
288 /* This is just to support the GL_MESA_window_pos version */
290 window_pos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
292 GET_CURRENT_CONTEXT(ctx
);
293 window_pos3f(x
, y
, z
);
294 ctx
->Current
.RasterPos
[3] = w
;
298 static void GLAPIENTRY
299 _mesa_WindowPos2dMESA(GLdouble x
, GLdouble y
)
301 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
304 static void GLAPIENTRY
305 _mesa_WindowPos2fMESA(GLfloat x
, GLfloat y
)
307 window_pos4f(x
, y
, 0.0F
, 1.0F
);
310 static void GLAPIENTRY
311 _mesa_WindowPos2iMESA(GLint x
, GLint y
)
313 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
316 static void GLAPIENTRY
317 _mesa_WindowPos2sMESA(GLshort x
, GLshort y
)
319 window_pos4f(x
, y
, 0.0F
, 1.0F
);
322 static void GLAPIENTRY
323 _mesa_WindowPos3dMESA(GLdouble x
, GLdouble y
, GLdouble z
)
325 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
328 static void GLAPIENTRY
329 _mesa_WindowPos3fMESA(GLfloat x
, GLfloat y
, GLfloat z
)
331 window_pos4f(x
, y
, z
, 1.0F
);
334 static void GLAPIENTRY
335 _mesa_WindowPos3iMESA(GLint x
, GLint y
, GLint z
)
337 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
340 static void GLAPIENTRY
341 _mesa_WindowPos3sMESA(GLshort x
, GLshort y
, GLshort z
)
343 window_pos4f(x
, y
, z
, 1.0F
);
346 static void GLAPIENTRY
347 _mesa_WindowPos4dMESA(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
349 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
352 static void GLAPIENTRY
353 _mesa_WindowPos4fMESA(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
355 window_pos4f(x
, y
, z
, w
);
358 static void GLAPIENTRY
359 _mesa_WindowPos4iMESA(GLint x
, GLint y
, GLint z
, GLint w
)
361 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
364 static void GLAPIENTRY
365 _mesa_WindowPos4sMESA(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
367 window_pos4f(x
, y
, z
, w
);
370 static void GLAPIENTRY
371 _mesa_WindowPos2dvMESA(const GLdouble
*v
)
373 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
376 static void GLAPIENTRY
377 _mesa_WindowPos2fvMESA(const GLfloat
*v
)
379 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
382 static void GLAPIENTRY
383 _mesa_WindowPos2ivMESA(const GLint
*v
)
385 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
388 static void GLAPIENTRY
389 _mesa_WindowPos2svMESA(const GLshort
*v
)
391 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
394 static void GLAPIENTRY
395 _mesa_WindowPos3dvMESA(const GLdouble
*v
)
397 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
400 static void GLAPIENTRY
401 _mesa_WindowPos3fvMESA(const GLfloat
*v
)
403 window_pos4f(v
[0], v
[1], v
[2], 1.0);
406 static void GLAPIENTRY
407 _mesa_WindowPos3ivMESA(const GLint
*v
)
409 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
412 static void GLAPIENTRY
413 _mesa_WindowPos3svMESA(const GLshort
*v
)
415 window_pos4f(v
[0], v
[1], v
[2], 1.0F
);
418 static void GLAPIENTRY
419 _mesa_WindowPos4dvMESA(const GLdouble
*v
)
421 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
422 (GLfloat
) v
[2], (GLfloat
) v
[3]);
425 static void GLAPIENTRY
426 _mesa_WindowPos4fvMESA(const GLfloat
*v
)
428 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
431 static void GLAPIENTRY
432 _mesa_WindowPos4ivMESA(const GLint
*v
)
434 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
435 (GLfloat
) v
[2], (GLfloat
) v
[3]);
438 static void GLAPIENTRY
439 _mesa_WindowPos4svMESA(const GLshort
*v
)
441 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
448 * OpenGL implementation of glWindowPos*MESA()
450 void glWindowPos4fMESA( GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
454 /* Push current matrix mode and viewport attributes */
455 glPushAttrib( GL_TRANSFORM_BIT
| GL_VIEWPORT_BIT
);
457 /* Setup projection parameters */
458 glMatrixMode( GL_PROJECTION
);
461 glMatrixMode( GL_MODELVIEW
);
465 glDepthRange( z
, z
);
466 glViewport( (int) x
- 1, (int) y
- 1, 2, 2 );
468 /* set the raster (window) position */
471 glRasterPos4f( fx
, fy
, 0.0, w
);
473 /* restore matrices, viewport and matrix mode */
475 glMatrixMode( GL_PROJECTION
);
485 _mesa_init_rastpos_dispatch(struct _glapi_table
*disp
)
487 SET_RasterPos2f(disp
, _mesa_RasterPos2f
);
488 SET_RasterPos2fv(disp
, _mesa_RasterPos2fv
);
489 SET_RasterPos2i(disp
, _mesa_RasterPos2i
);
490 SET_RasterPos2iv(disp
, _mesa_RasterPos2iv
);
491 SET_RasterPos2d(disp
, _mesa_RasterPos2d
);
492 SET_RasterPos2dv(disp
, _mesa_RasterPos2dv
);
493 SET_RasterPos2s(disp
, _mesa_RasterPos2s
);
494 SET_RasterPos2sv(disp
, _mesa_RasterPos2sv
);
495 SET_RasterPos3d(disp
, _mesa_RasterPos3d
);
496 SET_RasterPos3dv(disp
, _mesa_RasterPos3dv
);
497 SET_RasterPos3f(disp
, _mesa_RasterPos3f
);
498 SET_RasterPos3fv(disp
, _mesa_RasterPos3fv
);
499 SET_RasterPos3i(disp
, _mesa_RasterPos3i
);
500 SET_RasterPos3iv(disp
, _mesa_RasterPos3iv
);
501 SET_RasterPos3s(disp
, _mesa_RasterPos3s
);
502 SET_RasterPos3sv(disp
, _mesa_RasterPos3sv
);
503 SET_RasterPos4d(disp
, _mesa_RasterPos4d
);
504 SET_RasterPos4dv(disp
, _mesa_RasterPos4dv
);
505 SET_RasterPos4f(disp
, _mesa_RasterPos4f
);
506 SET_RasterPos4fv(disp
, _mesa_RasterPos4fv
);
507 SET_RasterPos4i(disp
, _mesa_RasterPos4i
);
508 SET_RasterPos4iv(disp
, _mesa_RasterPos4iv
);
509 SET_RasterPos4s(disp
, _mesa_RasterPos4s
);
510 SET_RasterPos4sv(disp
, _mesa_RasterPos4sv
);
512 /* 197. GL_MESA_window_pos */
513 SET_WindowPos2dMESA(disp
, _mesa_WindowPos2dMESA
);
514 SET_WindowPos2dvMESA(disp
, _mesa_WindowPos2dvMESA
);
515 SET_WindowPos2fMESA(disp
, _mesa_WindowPos2fMESA
);
516 SET_WindowPos2fvMESA(disp
, _mesa_WindowPos2fvMESA
);
517 SET_WindowPos2iMESA(disp
, _mesa_WindowPos2iMESA
);
518 SET_WindowPos2ivMESA(disp
, _mesa_WindowPos2ivMESA
);
519 SET_WindowPos2sMESA(disp
, _mesa_WindowPos2sMESA
);
520 SET_WindowPos2svMESA(disp
, _mesa_WindowPos2svMESA
);
521 SET_WindowPos3dMESA(disp
, _mesa_WindowPos3dMESA
);
522 SET_WindowPos3dvMESA(disp
, _mesa_WindowPos3dvMESA
);
523 SET_WindowPos3fMESA(disp
, _mesa_WindowPos3fMESA
);
524 SET_WindowPos3fvMESA(disp
, _mesa_WindowPos3fvMESA
);
525 SET_WindowPos3iMESA(disp
, _mesa_WindowPos3iMESA
);
526 SET_WindowPos3ivMESA(disp
, _mesa_WindowPos3ivMESA
);
527 SET_WindowPos3sMESA(disp
, _mesa_WindowPos3sMESA
);
528 SET_WindowPos3svMESA(disp
, _mesa_WindowPos3svMESA
);
529 SET_WindowPos4dMESA(disp
, _mesa_WindowPos4dMESA
);
530 SET_WindowPos4dvMESA(disp
, _mesa_WindowPos4dvMESA
);
531 SET_WindowPos4fMESA(disp
, _mesa_WindowPos4fMESA
);
532 SET_WindowPos4fvMESA(disp
, _mesa_WindowPos4fvMESA
);
533 SET_WindowPos4iMESA(disp
, _mesa_WindowPos4iMESA
);
534 SET_WindowPos4ivMESA(disp
, _mesa_WindowPos4ivMESA
);
535 SET_WindowPos4sMESA(disp
, _mesa_WindowPos4sMESA
);
536 SET_WindowPos4svMESA(disp
, _mesa_WindowPos4svMESA
);
540 #endif /* FEATURE_rastpos */
543 /**********************************************************************/
544 /** \name Initialization */
545 /**********************************************************************/
549 * Initialize the context current raster position information.
551 * \param ctx GL context.
553 * Initialize the current raster position information in
554 * __GLcontextRec::Current, and adds the extension entry points to the
557 void _mesa_init_rastpos( GLcontext
* ctx
)
561 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
562 ctx
->Current
.RasterDistance
= 0.0;
563 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
564 ASSIGN_4V( ctx
->Current
.RasterSecondaryColor
, 0.0, 0.0, 0.0, 1.0 );
565 ctx
->Current
.RasterIndex
= 1.0;
566 for (i
= 0; i
< Elements(ctx
->Current
.RasterTexCoords
); i
++)
567 ASSIGN_4V( ctx
->Current
.RasterTexCoords
[i
], 0.0, 0.0, 0.0, 1.0 );
568 ctx
->Current
.RasterPosValid
= GL_TRUE
;