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 * Helper function for all the RasterPos functions.
40 rasterpos(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
42 GET_CURRENT_CONTEXT(ctx
);
50 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
51 FLUSH_CURRENT(ctx
, 0);
54 _mesa_update_state( ctx
);
56 ctx
->Driver
.RasterPos(ctx
, p
);
60 static void GLAPIENTRY
61 _mesa_RasterPos2d(GLdouble x
, GLdouble y
)
63 rasterpos((GLfloat
)x
, (GLfloat
)y
, (GLfloat
)0.0, (GLfloat
)1.0);
66 static void GLAPIENTRY
67 _mesa_RasterPos2f(GLfloat x
, GLfloat y
)
69 rasterpos(x
, y
, 0.0F
, 1.0F
);
72 static void GLAPIENTRY
73 _mesa_RasterPos2i(GLint x
, GLint y
)
75 rasterpos((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
78 static void GLAPIENTRY
79 _mesa_RasterPos2s(GLshort x
, GLshort y
)
81 rasterpos(x
, y
, 0.0F
, 1.0F
);
84 static void GLAPIENTRY
85 _mesa_RasterPos3d(GLdouble x
, GLdouble y
, GLdouble z
)
87 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
90 static void GLAPIENTRY
91 _mesa_RasterPos3f(GLfloat x
, GLfloat y
, GLfloat z
)
93 rasterpos(x
, y
, z
, 1.0F
);
96 static void GLAPIENTRY
97 _mesa_RasterPos3i(GLint x
, GLint y
, GLint z
)
99 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
102 static void GLAPIENTRY
103 _mesa_RasterPos3s(GLshort x
, GLshort y
, GLshort z
)
105 rasterpos(x
, y
, z
, 1.0F
);
108 static void GLAPIENTRY
109 _mesa_RasterPos4d(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
111 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
114 static void GLAPIENTRY
115 _mesa_RasterPos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
117 rasterpos(x
, y
, z
, w
);
120 static void GLAPIENTRY
121 _mesa_RasterPos4i(GLint x
, GLint y
, GLint z
, GLint w
)
123 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
126 static void GLAPIENTRY
127 _mesa_RasterPos4s(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
129 rasterpos(x
, y
, z
, w
);
132 static void GLAPIENTRY
133 _mesa_RasterPos2dv(const GLdouble
*v
)
135 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
138 static void GLAPIENTRY
139 _mesa_RasterPos2fv(const GLfloat
*v
)
141 rasterpos(v
[0], v
[1], 0.0F
, 1.0F
);
144 static void GLAPIENTRY
145 _mesa_RasterPos2iv(const GLint
*v
)
147 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
150 static void GLAPIENTRY
151 _mesa_RasterPos2sv(const GLshort
*v
)
153 rasterpos(v
[0], v
[1], 0.0F
, 1.0F
);
156 static void GLAPIENTRY
157 _mesa_RasterPos3dv(const GLdouble
*v
)
159 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
162 static void GLAPIENTRY
163 _mesa_RasterPos3fv(const GLfloat
*v
)
165 rasterpos(v
[0], v
[1], v
[2], 1.0F
);
168 static void GLAPIENTRY
169 _mesa_RasterPos3iv(const GLint
*v
)
171 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
174 static void GLAPIENTRY
175 _mesa_RasterPos3sv(const GLshort
*v
)
177 rasterpos(v
[0], v
[1], v
[2], 1.0F
);
180 static void GLAPIENTRY
181 _mesa_RasterPos4dv(const GLdouble
*v
)
183 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1],
184 (GLfloat
) v
[2], (GLfloat
) v
[3]);
187 static void GLAPIENTRY
188 _mesa_RasterPos4fv(const GLfloat
*v
)
190 rasterpos(v
[0], v
[1], v
[2], v
[3]);
193 static void GLAPIENTRY
194 _mesa_RasterPos4iv(const GLint
*v
)
196 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1],
197 (GLfloat
) v
[2], (GLfloat
) v
[3]);
200 static void GLAPIENTRY
201 _mesa_RasterPos4sv(const GLshort
*v
)
203 rasterpos(v
[0], v
[1], v
[2], v
[3]);
207 /**********************************************************************/
208 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
209 /**********************************************************************/
213 * All glWindowPosMESA and glWindowPosARB commands call this function to
214 * update the current raster position.
217 window_pos3f(GLfloat x
, GLfloat y
, GLfloat z
)
219 GET_CURRENT_CONTEXT(ctx
);
222 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
223 FLUSH_CURRENT(ctx
, 0);
225 z2
= CLAMP(z
, 0.0F
, 1.0F
) * (ctx
->Viewport
.Far
- ctx
->Viewport
.Near
)
226 + ctx
->Viewport
.Near
;
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
;
234 ctx
->Current
.RasterPosValid
= GL_TRUE
;
236 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
)
237 ctx
->Current
.RasterDistance
= ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0];
239 ctx
->Current
.RasterDistance
= 0.0;
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
);
259 /* raster texcoord = current texcoord */
260 COPY_4FV( ctx
->Current
.RasterTexCoords
, ctx
->Current
.Attrib
[VERT_ATTRIB_TEX
] );
262 if (ctx
->RenderMode
==GL_SELECT
) {
263 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
268 /* This is just to support the GL_MESA_window_pos version */
270 window_pos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
272 GET_CURRENT_CONTEXT(ctx
);
273 window_pos3f(x
, y
, z
);
274 ctx
->Current
.RasterPos
[3] = w
;
278 static void GLAPIENTRY
279 _mesa_WindowPos2dMESA(GLdouble x
, GLdouble y
)
281 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
284 static void GLAPIENTRY
285 _mesa_WindowPos2fMESA(GLfloat x
, GLfloat y
)
287 window_pos4f(x
, y
, 0.0F
, 1.0F
);
290 static void GLAPIENTRY
291 _mesa_WindowPos2iMESA(GLint x
, GLint y
)
293 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
296 static void GLAPIENTRY
297 _mesa_WindowPos2sMESA(GLshort x
, GLshort y
)
299 window_pos4f(x
, y
, 0.0F
, 1.0F
);
302 static void GLAPIENTRY
303 _mesa_WindowPos3dMESA(GLdouble x
, GLdouble y
, GLdouble z
)
305 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
308 static void GLAPIENTRY
309 _mesa_WindowPos3fMESA(GLfloat x
, GLfloat y
, GLfloat z
)
311 window_pos4f(x
, y
, z
, 1.0F
);
314 static void GLAPIENTRY
315 _mesa_WindowPos3iMESA(GLint x
, GLint y
, GLint z
)
317 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
320 static void GLAPIENTRY
321 _mesa_WindowPos3sMESA(GLshort x
, GLshort y
, GLshort z
)
323 window_pos4f(x
, y
, z
, 1.0F
);
326 static void GLAPIENTRY
327 _mesa_WindowPos4dMESA(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
329 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
332 static void GLAPIENTRY
333 _mesa_WindowPos4fMESA(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
335 window_pos4f(x
, y
, z
, w
);
338 static void GLAPIENTRY
339 _mesa_WindowPos4iMESA(GLint x
, GLint y
, GLint z
, GLint w
)
341 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
344 static void GLAPIENTRY
345 _mesa_WindowPos4sMESA(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
347 window_pos4f(x
, y
, z
, w
);
350 static void GLAPIENTRY
351 _mesa_WindowPos2dvMESA(const GLdouble
*v
)
353 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
356 static void GLAPIENTRY
357 _mesa_WindowPos2fvMESA(const GLfloat
*v
)
359 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
362 static void GLAPIENTRY
363 _mesa_WindowPos2ivMESA(const GLint
*v
)
365 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
368 static void GLAPIENTRY
369 _mesa_WindowPos2svMESA(const GLshort
*v
)
371 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
374 static void GLAPIENTRY
375 _mesa_WindowPos3dvMESA(const GLdouble
*v
)
377 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
380 static void GLAPIENTRY
381 _mesa_WindowPos3fvMESA(const GLfloat
*v
)
383 window_pos4f(v
[0], v
[1], v
[2], 1.0);
386 static void GLAPIENTRY
387 _mesa_WindowPos3ivMESA(const GLint
*v
)
389 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
392 static void GLAPIENTRY
393 _mesa_WindowPos3svMESA(const GLshort
*v
)
395 window_pos4f(v
[0], v
[1], v
[2], 1.0F
);
398 static void GLAPIENTRY
399 _mesa_WindowPos4dvMESA(const GLdouble
*v
)
401 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
402 (GLfloat
) v
[2], (GLfloat
) v
[3]);
405 static void GLAPIENTRY
406 _mesa_WindowPos4fvMESA(const GLfloat
*v
)
408 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
411 static void GLAPIENTRY
412 _mesa_WindowPos4ivMESA(const GLint
*v
)
414 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
415 (GLfloat
) v
[2], (GLfloat
) v
[3]);
418 static void GLAPIENTRY
419 _mesa_WindowPos4svMESA(const GLshort
*v
)
421 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
428 * OpenGL implementation of glWindowPos*MESA()
430 void glWindowPos4fMESA( GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
434 /* Push current matrix mode and viewport attributes */
435 glPushAttrib( GL_TRANSFORM_BIT
| GL_VIEWPORT_BIT
);
437 /* Setup projection parameters */
438 glMatrixMode( GL_PROJECTION
);
441 glMatrixMode( GL_MODELVIEW
);
445 glDepthRange( z
, z
);
446 glViewport( (int) x
- 1, (int) y
- 1, 2, 2 );
448 /* set the raster (window) position */
451 glRasterPos4f( fx
, fy
, 0.0, w
);
453 /* restore matrices, viewport and matrix mode */
455 glMatrixMode( GL_PROJECTION
);
465 _mesa_init_rastpos_dispatch(struct _glapi_table
*disp
)
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
);
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
);
520 #endif /* FEATURE_rastpos */
523 /**********************************************************************/
524 /** \name Initialization */
525 /**********************************************************************/
529 * Initialize the context current raster position information.
531 * \param ctx GL context.
533 * Initialize the current raster position information in
534 * __struct gl_contextRec::Current, and adds the extension entry points to the
537 void _mesa_init_rastpos( struct gl_context
* ctx
)
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
;