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.
35 #include "mfeatures.h"
39 #include "main/dispatch.h"
46 * Helper function for all the RasterPos functions.
49 rasterpos(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
51 GET_CURRENT_CONTEXT(ctx
);
59 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
60 FLUSH_CURRENT(ctx
, 0);
63 _mesa_update_state( ctx
);
65 ctx
->Driver
.RasterPos(ctx
, p
);
69 static void GLAPIENTRY
70 _mesa_RasterPos2d(GLdouble x
, GLdouble y
)
72 rasterpos((GLfloat
)x
, (GLfloat
)y
, (GLfloat
)0.0, (GLfloat
)1.0);
75 static void GLAPIENTRY
76 _mesa_RasterPos2f(GLfloat x
, GLfloat y
)
78 rasterpos(x
, y
, 0.0F
, 1.0F
);
81 static void GLAPIENTRY
82 _mesa_RasterPos2i(GLint x
, GLint y
)
84 rasterpos((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
87 static void GLAPIENTRY
88 _mesa_RasterPos2s(GLshort x
, GLshort y
)
90 rasterpos(x
, y
, 0.0F
, 1.0F
);
93 static void GLAPIENTRY
94 _mesa_RasterPos3d(GLdouble x
, GLdouble y
, GLdouble z
)
96 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
99 static void GLAPIENTRY
100 _mesa_RasterPos3f(GLfloat x
, GLfloat y
, GLfloat z
)
102 rasterpos(x
, y
, z
, 1.0F
);
105 static void GLAPIENTRY
106 _mesa_RasterPos3i(GLint x
, GLint y
, GLint z
)
108 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
111 static void GLAPIENTRY
112 _mesa_RasterPos3s(GLshort x
, GLshort y
, GLshort z
)
114 rasterpos(x
, y
, z
, 1.0F
);
117 static void GLAPIENTRY
118 _mesa_RasterPos4d(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
120 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
123 static void GLAPIENTRY
124 _mesa_RasterPos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
126 rasterpos(x
, y
, z
, w
);
129 static void GLAPIENTRY
130 _mesa_RasterPos4i(GLint x
, GLint y
, GLint z
, GLint w
)
132 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
135 static void GLAPIENTRY
136 _mesa_RasterPos4s(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
138 rasterpos(x
, y
, z
, w
);
141 static void GLAPIENTRY
142 _mesa_RasterPos2dv(const GLdouble
*v
)
144 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
147 static void GLAPIENTRY
148 _mesa_RasterPos2fv(const GLfloat
*v
)
150 rasterpos(v
[0], v
[1], 0.0F
, 1.0F
);
153 static void GLAPIENTRY
154 _mesa_RasterPos2iv(const GLint
*v
)
156 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
159 static void GLAPIENTRY
160 _mesa_RasterPos2sv(const GLshort
*v
)
162 rasterpos(v
[0], v
[1], 0.0F
, 1.0F
);
165 static void GLAPIENTRY
166 _mesa_RasterPos3dv(const GLdouble
*v
)
168 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
171 static void GLAPIENTRY
172 _mesa_RasterPos3fv(const GLfloat
*v
)
174 rasterpos(v
[0], v
[1], v
[2], 1.0F
);
177 static void GLAPIENTRY
178 _mesa_RasterPos3iv(const GLint
*v
)
180 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
183 static void GLAPIENTRY
184 _mesa_RasterPos3sv(const GLshort
*v
)
186 rasterpos(v
[0], v
[1], v
[2], 1.0F
);
189 static void GLAPIENTRY
190 _mesa_RasterPos4dv(const GLdouble
*v
)
192 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1],
193 (GLfloat
) v
[2], (GLfloat
) v
[3]);
196 static void GLAPIENTRY
197 _mesa_RasterPos4fv(const GLfloat
*v
)
199 rasterpos(v
[0], v
[1], v
[2], v
[3]);
202 static void GLAPIENTRY
203 _mesa_RasterPos4iv(const GLint
*v
)
205 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1],
206 (GLfloat
) v
[2], (GLfloat
) v
[3]);
209 static void GLAPIENTRY
210 _mesa_RasterPos4sv(const GLshort
*v
)
212 rasterpos(v
[0], v
[1], v
[2], v
[3]);
216 /**********************************************************************/
217 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
218 /**********************************************************************/
222 * All glWindowPosMESA and glWindowPosARB commands call this function to
223 * update the current raster position.
226 window_pos3f(GLfloat x
, GLfloat y
, GLfloat z
)
228 GET_CURRENT_CONTEXT(ctx
);
231 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
232 FLUSH_CURRENT(ctx
, 0);
234 z2
= CLAMP(z
, 0.0F
, 1.0F
) * (ctx
->Viewport
.Far
- ctx
->Viewport
.Near
)
235 + ctx
->Viewport
.Near
;
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
;
243 ctx
->Current
.RasterPosValid
= GL_TRUE
;
245 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
)
246 ctx
->Current
.RasterDistance
= ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0];
248 ctx
->Current
.RasterDistance
= 0.0;
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
);
268 /* raster texcoord = current texcoord */
269 COPY_4FV( ctx
->Current
.RasterTexCoords
, ctx
->Current
.Attrib
[VERT_ATTRIB_TEX
] );
271 if (ctx
->RenderMode
==GL_SELECT
) {
272 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
277 /* This is just to support the GL_MESA_window_pos version */
279 window_pos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
281 GET_CURRENT_CONTEXT(ctx
);
282 window_pos3f(x
, y
, z
);
283 ctx
->Current
.RasterPos
[3] = w
;
287 static void GLAPIENTRY
288 _mesa_WindowPos2dMESA(GLdouble x
, GLdouble y
)
290 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
293 static void GLAPIENTRY
294 _mesa_WindowPos2fMESA(GLfloat x
, GLfloat y
)
296 window_pos4f(x
, y
, 0.0F
, 1.0F
);
299 static void GLAPIENTRY
300 _mesa_WindowPos2iMESA(GLint x
, GLint y
)
302 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
305 static void GLAPIENTRY
306 _mesa_WindowPos2sMESA(GLshort x
, GLshort y
)
308 window_pos4f(x
, y
, 0.0F
, 1.0F
);
311 static void GLAPIENTRY
312 _mesa_WindowPos3dMESA(GLdouble x
, GLdouble y
, GLdouble z
)
314 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
317 static void GLAPIENTRY
318 _mesa_WindowPos3fMESA(GLfloat x
, GLfloat y
, GLfloat z
)
320 window_pos4f(x
, y
, z
, 1.0F
);
323 static void GLAPIENTRY
324 _mesa_WindowPos3iMESA(GLint x
, GLint y
, GLint z
)
326 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
329 static void GLAPIENTRY
330 _mesa_WindowPos3sMESA(GLshort x
, GLshort y
, GLshort z
)
332 window_pos4f(x
, y
, z
, 1.0F
);
335 static void GLAPIENTRY
336 _mesa_WindowPos4dMESA(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
338 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
341 static void GLAPIENTRY
342 _mesa_WindowPos4fMESA(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
344 window_pos4f(x
, y
, z
, w
);
347 static void GLAPIENTRY
348 _mesa_WindowPos4iMESA(GLint x
, GLint y
, GLint z
, GLint w
)
350 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
353 static void GLAPIENTRY
354 _mesa_WindowPos4sMESA(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
356 window_pos4f(x
, y
, z
, w
);
359 static void GLAPIENTRY
360 _mesa_WindowPos2dvMESA(const GLdouble
*v
)
362 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
365 static void GLAPIENTRY
366 _mesa_WindowPos2fvMESA(const GLfloat
*v
)
368 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
371 static void GLAPIENTRY
372 _mesa_WindowPos2ivMESA(const GLint
*v
)
374 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
377 static void GLAPIENTRY
378 _mesa_WindowPos2svMESA(const GLshort
*v
)
380 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
383 static void GLAPIENTRY
384 _mesa_WindowPos3dvMESA(const GLdouble
*v
)
386 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
389 static void GLAPIENTRY
390 _mesa_WindowPos3fvMESA(const GLfloat
*v
)
392 window_pos4f(v
[0], v
[1], v
[2], 1.0);
395 static void GLAPIENTRY
396 _mesa_WindowPos3ivMESA(const GLint
*v
)
398 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
401 static void GLAPIENTRY
402 _mesa_WindowPos3svMESA(const GLshort
*v
)
404 window_pos4f(v
[0], v
[1], v
[2], 1.0F
);
407 static void GLAPIENTRY
408 _mesa_WindowPos4dvMESA(const GLdouble
*v
)
410 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
411 (GLfloat
) v
[2], (GLfloat
) v
[3]);
414 static void GLAPIENTRY
415 _mesa_WindowPos4fvMESA(const GLfloat
*v
)
417 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
420 static void GLAPIENTRY
421 _mesa_WindowPos4ivMESA(const GLint
*v
)
423 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
424 (GLfloat
) v
[2], (GLfloat
) v
[3]);
427 static void GLAPIENTRY
428 _mesa_WindowPos4svMESA(const GLshort
*v
)
430 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
437 * OpenGL implementation of glWindowPos*MESA()
439 void glWindowPos4fMESA( GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
443 /* Push current matrix mode and viewport attributes */
444 glPushAttrib( GL_TRANSFORM_BIT
| GL_VIEWPORT_BIT
);
446 /* Setup projection parameters */
447 glMatrixMode( GL_PROJECTION
);
450 glMatrixMode( GL_MODELVIEW
);
454 glDepthRange( z
, z
);
455 glViewport( (int) x
- 1, (int) y
- 1, 2, 2 );
457 /* set the raster (window) position */
460 glRasterPos4f( fx
, fy
, 0.0, w
);
462 /* restore matrices, viewport and matrix mode */
464 glMatrixMode( GL_PROJECTION
);
474 _mesa_init_rastpos_dispatch(struct _glapi_table
*disp
)
476 SET_RasterPos2f(disp
, _mesa_RasterPos2f
);
477 SET_RasterPos2fv(disp
, _mesa_RasterPos2fv
);
478 SET_RasterPos2i(disp
, _mesa_RasterPos2i
);
479 SET_RasterPos2iv(disp
, _mesa_RasterPos2iv
);
480 SET_RasterPos2d(disp
, _mesa_RasterPos2d
);
481 SET_RasterPos2dv(disp
, _mesa_RasterPos2dv
);
482 SET_RasterPos2s(disp
, _mesa_RasterPos2s
);
483 SET_RasterPos2sv(disp
, _mesa_RasterPos2sv
);
484 SET_RasterPos3d(disp
, _mesa_RasterPos3d
);
485 SET_RasterPos3dv(disp
, _mesa_RasterPos3dv
);
486 SET_RasterPos3f(disp
, _mesa_RasterPos3f
);
487 SET_RasterPos3fv(disp
, _mesa_RasterPos3fv
);
488 SET_RasterPos3i(disp
, _mesa_RasterPos3i
);
489 SET_RasterPos3iv(disp
, _mesa_RasterPos3iv
);
490 SET_RasterPos3s(disp
, _mesa_RasterPos3s
);
491 SET_RasterPos3sv(disp
, _mesa_RasterPos3sv
);
492 SET_RasterPos4d(disp
, _mesa_RasterPos4d
);
493 SET_RasterPos4dv(disp
, _mesa_RasterPos4dv
);
494 SET_RasterPos4f(disp
, _mesa_RasterPos4f
);
495 SET_RasterPos4fv(disp
, _mesa_RasterPos4fv
);
496 SET_RasterPos4i(disp
, _mesa_RasterPos4i
);
497 SET_RasterPos4iv(disp
, _mesa_RasterPos4iv
);
498 SET_RasterPos4s(disp
, _mesa_RasterPos4s
);
499 SET_RasterPos4sv(disp
, _mesa_RasterPos4sv
);
501 /* 197. GL_MESA_window_pos */
502 SET_WindowPos2dMESA(disp
, _mesa_WindowPos2dMESA
);
503 SET_WindowPos2dvMESA(disp
, _mesa_WindowPos2dvMESA
);
504 SET_WindowPos2fMESA(disp
, _mesa_WindowPos2fMESA
);
505 SET_WindowPos2fvMESA(disp
, _mesa_WindowPos2fvMESA
);
506 SET_WindowPos2iMESA(disp
, _mesa_WindowPos2iMESA
);
507 SET_WindowPos2ivMESA(disp
, _mesa_WindowPos2ivMESA
);
508 SET_WindowPos2sMESA(disp
, _mesa_WindowPos2sMESA
);
509 SET_WindowPos2svMESA(disp
, _mesa_WindowPos2svMESA
);
510 SET_WindowPos3dMESA(disp
, _mesa_WindowPos3dMESA
);
511 SET_WindowPos3dvMESA(disp
, _mesa_WindowPos3dvMESA
);
512 SET_WindowPos3fMESA(disp
, _mesa_WindowPos3fMESA
);
513 SET_WindowPos3fvMESA(disp
, _mesa_WindowPos3fvMESA
);
514 SET_WindowPos3iMESA(disp
, _mesa_WindowPos3iMESA
);
515 SET_WindowPos3ivMESA(disp
, _mesa_WindowPos3ivMESA
);
516 SET_WindowPos3sMESA(disp
, _mesa_WindowPos3sMESA
);
517 SET_WindowPos3svMESA(disp
, _mesa_WindowPos3svMESA
);
518 SET_WindowPos4dMESA(disp
, _mesa_WindowPos4dMESA
);
519 SET_WindowPos4dvMESA(disp
, _mesa_WindowPos4dvMESA
);
520 SET_WindowPos4fMESA(disp
, _mesa_WindowPos4fMESA
);
521 SET_WindowPos4fvMESA(disp
, _mesa_WindowPos4fvMESA
);
522 SET_WindowPos4iMESA(disp
, _mesa_WindowPos4iMESA
);
523 SET_WindowPos4ivMESA(disp
, _mesa_WindowPos4ivMESA
);
524 SET_WindowPos4sMESA(disp
, _mesa_WindowPos4sMESA
);
525 SET_WindowPos4svMESA(disp
, _mesa_WindowPos4svMESA
);
529 #endif /* FEATURE_rastpos */
532 /**********************************************************************/
533 /** \name Initialization */
534 /**********************************************************************/
538 * Initialize the context current raster position information.
540 * \param ctx GL context.
542 * Initialize the current raster position information in
543 * __struct gl_contextRec::Current, and adds the extension entry points to the
546 void _mesa_init_rastpos( struct gl_context
* ctx
)
548 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
549 ctx
->Current
.RasterDistance
= 0.0;
550 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
551 ASSIGN_4V( ctx
->Current
.RasterSecondaryColor
, 0.0, 0.0, 0.0, 1.0 );
552 ASSIGN_4V( ctx
->Current
.RasterTexCoords
, 0.0, 0.0, 0.0, 1.0 );
553 ctx
->Current
.RasterPosValid
= GL_TRUE
;