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.
40 * Helper function for all the RasterPos functions.
43 rasterpos(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
45 GET_CURRENT_CONTEXT(ctx
);
54 _mesa_update_state( ctx
);
56 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
57 FLUSH_CURRENT(ctx
, 0);
59 ctx
->Driver
.RasterPos(ctx
, p
);
64 _mesa_RasterPos2d(GLdouble x
, GLdouble y
)
66 rasterpos((GLfloat
)x
, (GLfloat
)y
, (GLfloat
)0.0, (GLfloat
)1.0);
70 _mesa_RasterPos2f(GLfloat x
, GLfloat y
)
72 rasterpos(x
, y
, 0.0F
, 1.0F
);
76 _mesa_RasterPos2i(GLint x
, GLint y
)
78 rasterpos((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
82 _mesa_RasterPos2s(GLshort x
, GLshort y
)
84 rasterpos(x
, y
, 0.0F
, 1.0F
);
88 _mesa_RasterPos3d(GLdouble x
, GLdouble y
, GLdouble z
)
90 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
94 _mesa_RasterPos3f(GLfloat x
, GLfloat y
, GLfloat z
)
96 rasterpos(x
, y
, z
, 1.0F
);
100 _mesa_RasterPos3i(GLint x
, GLint y
, GLint z
)
102 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
106 _mesa_RasterPos3s(GLshort x
, GLshort y
, GLshort z
)
108 rasterpos(x
, y
, z
, 1.0F
);
112 _mesa_RasterPos4d(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
114 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
118 _mesa_RasterPos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
120 rasterpos(x
, y
, z
, w
);
124 _mesa_RasterPos4i(GLint x
, GLint y
, GLint z
, GLint w
)
126 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
130 _mesa_RasterPos4s(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
132 rasterpos(x
, y
, z
, w
);
136 _mesa_RasterPos2dv(const GLdouble
*v
)
138 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
142 _mesa_RasterPos2fv(const GLfloat
*v
)
144 rasterpos(v
[0], v
[1], 0.0F
, 1.0F
);
148 _mesa_RasterPos2iv(const GLint
*v
)
150 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
154 _mesa_RasterPos2sv(const GLshort
*v
)
156 rasterpos(v
[0], v
[1], 0.0F
, 1.0F
);
160 _mesa_RasterPos3dv(const GLdouble
*v
)
162 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
166 _mesa_RasterPos3fv(const GLfloat
*v
)
168 rasterpos(v
[0], v
[1], v
[2], 1.0F
);
172 _mesa_RasterPos3iv(const GLint
*v
)
174 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
178 _mesa_RasterPos3sv(const GLshort
*v
)
180 rasterpos(v
[0], v
[1], v
[2], 1.0F
);
184 _mesa_RasterPos4dv(const GLdouble
*v
)
186 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1],
187 (GLfloat
) v
[2], (GLfloat
) v
[3]);
191 _mesa_RasterPos4fv(const GLfloat
*v
)
193 rasterpos(v
[0], v
[1], v
[2], v
[3]);
197 _mesa_RasterPos4iv(const GLint
*v
)
199 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1],
200 (GLfloat
) v
[2], (GLfloat
) v
[3]);
204 _mesa_RasterPos4sv(const GLshort
*v
)
206 rasterpos(v
[0], v
[1], v
[2], v
[3]);
210 /**********************************************************************/
211 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
212 /**********************************************************************/
216 * All glWindowPosMESA and glWindowPosARB commands call this function to
217 * update the current raster position.
220 window_pos3f(GLfloat x
, GLfloat y
, GLfloat z
)
222 GET_CURRENT_CONTEXT(ctx
);
225 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
226 FLUSH_CURRENT(ctx
, 0);
228 z2
= CLAMP(z
, 0.0F
, 1.0F
) * (ctx
->Viewport
.Far
- ctx
->Viewport
.Near
)
229 + ctx
->Viewport
.Near
;
231 /* set raster position */
232 ctx
->Current
.RasterPos
[0] = x
;
233 ctx
->Current
.RasterPos
[1] = y
;
234 ctx
->Current
.RasterPos
[2] = z2
;
235 ctx
->Current
.RasterPos
[3] = 1.0F
;
237 ctx
->Current
.RasterPosValid
= GL_TRUE
;
239 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
)
240 ctx
->Current
.RasterDistance
= ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0];
242 ctx
->Current
.RasterDistance
= 0.0;
244 /* raster color = current color or index */
245 if (ctx
->Visual
.rgbMode
) {
246 ctx
->Current
.RasterColor
[0]
247 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][0], 0.0F
, 1.0F
);
248 ctx
->Current
.RasterColor
[1]
249 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][1], 0.0F
, 1.0F
);
250 ctx
->Current
.RasterColor
[2]
251 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][2], 0.0F
, 1.0F
);
252 ctx
->Current
.RasterColor
[3]
253 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][3], 0.0F
, 1.0F
);
254 ctx
->Current
.RasterSecondaryColor
[0]
255 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][0], 0.0F
, 1.0F
);
256 ctx
->Current
.RasterSecondaryColor
[1]
257 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][1], 0.0F
, 1.0F
);
258 ctx
->Current
.RasterSecondaryColor
[2]
259 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][2], 0.0F
, 1.0F
);
260 ctx
->Current
.RasterSecondaryColor
[3]
261 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][3], 0.0F
, 1.0F
);
264 ctx
->Current
.RasterIndex
265 = ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR_INDEX
][0];
268 /* raster texcoord = current texcoord */
271 for (texSet
= 0; texSet
< ctx
->Const
.MaxTextureCoordUnits
; texSet
++) {
272 COPY_4FV( ctx
->Current
.RasterTexCoords
[texSet
],
273 ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ texSet
] );
277 if (ctx
->RenderMode
==GL_SELECT
) {
278 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
283 /* This is just to support the GL_MESA_window_pos version */
285 window_pos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
287 GET_CURRENT_CONTEXT(ctx
);
288 window_pos3f(x
, y
, z
);
289 ctx
->Current
.RasterPos
[3] = w
;
294 _mesa_WindowPos2dMESA(GLdouble x
, GLdouble y
)
296 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
300 _mesa_WindowPos2fMESA(GLfloat x
, GLfloat y
)
302 window_pos4f(x
, y
, 0.0F
, 1.0F
);
306 _mesa_WindowPos2iMESA(GLint x
, GLint y
)
308 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
312 _mesa_WindowPos2sMESA(GLshort x
, GLshort y
)
314 window_pos4f(x
, y
, 0.0F
, 1.0F
);
318 _mesa_WindowPos3dMESA(GLdouble x
, GLdouble y
, GLdouble z
)
320 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
324 _mesa_WindowPos3fMESA(GLfloat x
, GLfloat y
, GLfloat z
)
326 window_pos4f(x
, y
, z
, 1.0F
);
330 _mesa_WindowPos3iMESA(GLint x
, GLint y
, GLint z
)
332 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
336 _mesa_WindowPos3sMESA(GLshort x
, GLshort y
, GLshort z
)
338 window_pos4f(x
, y
, z
, 1.0F
);
342 _mesa_WindowPos4dMESA(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
344 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
348 _mesa_WindowPos4fMESA(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
350 window_pos4f(x
, y
, z
, w
);
354 _mesa_WindowPos4iMESA(GLint x
, GLint y
, GLint z
, GLint w
)
356 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
360 _mesa_WindowPos4sMESA(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
362 window_pos4f(x
, y
, z
, w
);
366 _mesa_WindowPos2dvMESA(const GLdouble
*v
)
368 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
372 _mesa_WindowPos2fvMESA(const GLfloat
*v
)
374 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
378 _mesa_WindowPos2ivMESA(const GLint
*v
)
380 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
384 _mesa_WindowPos2svMESA(const GLshort
*v
)
386 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
390 _mesa_WindowPos3dvMESA(const GLdouble
*v
)
392 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
396 _mesa_WindowPos3fvMESA(const GLfloat
*v
)
398 window_pos4f(v
[0], v
[1], v
[2], 1.0);
402 _mesa_WindowPos3ivMESA(const GLint
*v
)
404 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
408 _mesa_WindowPos3svMESA(const GLshort
*v
)
410 window_pos4f(v
[0], v
[1], v
[2], 1.0F
);
414 _mesa_WindowPos4dvMESA(const GLdouble
*v
)
416 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
417 (GLfloat
) v
[2], (GLfloat
) v
[3]);
421 _mesa_WindowPos4fvMESA(const GLfloat
*v
)
423 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
427 _mesa_WindowPos4ivMESA(const GLint
*v
)
429 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
430 (GLfloat
) v
[2], (GLfloat
) v
[3]);
434 _mesa_WindowPos4svMESA(const GLshort
*v
)
436 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
444 * OpenGL implementation of glWindowPos*MESA()
446 void glWindowPos4fMESA( GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
450 /* Push current matrix mode and viewport attributes */
451 glPushAttrib( GL_TRANSFORM_BIT
| GL_VIEWPORT_BIT
);
453 /* Setup projection parameters */
454 glMatrixMode( GL_PROJECTION
);
457 glMatrixMode( GL_MODELVIEW
);
461 glDepthRange( z
, z
);
462 glViewport( (int) x
- 1, (int) y
- 1, 2, 2 );
464 /* set the raster (window) position */
467 glRasterPos4f( fx
, fy
, 0.0, w
);
469 /* restore matrices, viewport and matrix mode */
471 glMatrixMode( GL_PROJECTION
);
480 /**********************************************************************/
481 /** \name Initialization */
482 /**********************************************************************/
486 * Initialize the context current raster position information.
488 * \param ctx GL context.
490 * Initialize the current raster position information in
491 * __GLcontextRec::Current, and adds the extension entry points to the
494 void _mesa_init_rastpos( GLcontext
* ctx
)
498 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
499 ctx
->Current
.RasterDistance
= 0.0;
500 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
501 ASSIGN_4V( ctx
->Current
.RasterSecondaryColor
, 0.0, 0.0, 0.0, 1.0 );
502 ctx
->Current
.RasterIndex
= 1.0;
503 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
504 ASSIGN_4V( ctx
->Current
.RasterTexCoords
[i
], 0.0, 0.0, 0.0, 1.0 );
505 ctx
->Current
.RasterPosValid
= GL_TRUE
;