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"
43 * Helper function for all the RasterPos functions.
46 rasterpos(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
48 GET_CURRENT_CONTEXT(ctx);
56 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
57 FLUSH_CURRENT(ctx, 0);
60 _mesa_update_state( ctx );
62 ctx->Driver.RasterPos(ctx, p);
67 _mesa_RasterPos2d(GLdouble x, GLdouble y)
69 rasterpos((GLfloat)x, (GLfloat)y, (GLfloat)0.0, (GLfloat)1.0);
73 _mesa_RasterPos2f(GLfloat x, GLfloat y)
75 rasterpos(x, y, 0.0F, 1.0F);
79 _mesa_RasterPos2i(GLint x, GLint y)
81 rasterpos((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
85 _mesa_RasterPos2s(GLshort x, GLshort y)
87 rasterpos(x, y, 0.0F, 1.0F);
91 _mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
93 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
97 _mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
99 rasterpos(x, y, z, 1.0F);
103 _mesa_RasterPos3i(GLint x, GLint y, GLint z)
105 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
109 _mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
111 rasterpos(x, y, z, 1.0F);
115 _mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
117 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
121 _mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
123 rasterpos(x, y, z, w);
127 _mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
129 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
133 _mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
135 rasterpos(x, y, z, w);
139 _mesa_RasterPos2dv(const GLdouble *v)
141 rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
145 _mesa_RasterPos2fv(const GLfloat *v)
147 rasterpos(v[0], v[1], 0.0F, 1.0F);
151 _mesa_RasterPos2iv(const GLint *v)
153 rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
157 _mesa_RasterPos2sv(const GLshort *v)
159 rasterpos(v[0], v[1], 0.0F, 1.0F);
163 _mesa_RasterPos3dv(const GLdouble *v)
165 rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
169 _mesa_RasterPos3fv(const GLfloat *v)
171 rasterpos(v[0], v[1], v[2], 1.0F);
175 _mesa_RasterPos3iv(const GLint *v)
177 rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
181 _mesa_RasterPos3sv(const GLshort *v)
183 rasterpos(v[0], v[1], v[2], 1.0F);
187 _mesa_RasterPos4dv(const GLdouble *v)
189 rasterpos((GLfloat) v[0], (GLfloat) v[1],
190 (GLfloat) v[2], (GLfloat) v[3]);
194 _mesa_RasterPos4fv(const GLfloat *v)
196 rasterpos(v[0], v[1], v[2], v[3]);
200 _mesa_RasterPos4iv(const GLint *v)
202 rasterpos((GLfloat) v[0], (GLfloat) v[1],
203 (GLfloat) v[2], (GLfloat) v[3]);
207 _mesa_RasterPos4sv(const GLshort *v)
209 rasterpos(v[0], v[1], v[2], v[3]);
213 /**********************************************************************/
214 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
215 /**********************************************************************/
219 * All glWindowPosMESA and glWindowPosARB commands call this function to
220 * update the current raster position.
223 window_pos3f(GLfloat x, GLfloat y, GLfloat z)
225 GET_CURRENT_CONTEXT(ctx);
228 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
229 FLUSH_CURRENT(ctx, 0);
231 z2 = CLAMP(z, 0.0F, 1.0F) * (ctx->Viewport.Far - ctx->Viewport.Near)
232 + ctx->Viewport.Near;
234 /* set raster position */
235 ctx->Current.RasterPos[0] = x;
236 ctx->Current.RasterPos[1] = y;
237 ctx->Current.RasterPos[2] = z2;
238 ctx->Current.RasterPos[3] = 1.0F;
240 ctx->Current.RasterPosValid = GL_TRUE;
242 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
243 ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
245 ctx->Current.RasterDistance = 0.0;
247 /* raster color = current color or index */
248 ctx->Current.RasterColor[0]
249 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0], 0.0F, 1.0F);
250 ctx->Current.RasterColor[1]
251 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][1], 0.0F, 1.0F);
252 ctx->Current.RasterColor[2]
253 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][2], 0.0F, 1.0F);
254 ctx->Current.RasterColor[3]
255 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3], 0.0F, 1.0F);
256 ctx->Current.RasterSecondaryColor[0]
257 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0], 0.0F, 1.0F);
258 ctx->Current.RasterSecondaryColor[1]
259 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1], 0.0F, 1.0F);
260 ctx->Current.RasterSecondaryColor[2]
261 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][2], 0.0F, 1.0F);
262 ctx->Current.RasterSecondaryColor[3]
263 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][3], 0.0F, 1.0F);
265 /* raster texcoord = current texcoord */
268 for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) {
269 assert(texSet < Elements(ctx->Current.RasterTexCoords));
270 COPY_4FV( ctx->Current.RasterTexCoords[texSet],
271 ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] );
275 if (ctx->RenderMode==GL_SELECT) {
276 _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
281 /* This is just to support the GL_MESA_window_pos version */
283 window_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
285 GET_CURRENT_CONTEXT(ctx);
286 window_pos3f(x, y, z);
287 ctx->Current.RasterPos[3] = w;
292 _mesa_WindowPos2d(GLdouble x, GLdouble y)
294 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
298 _mesa_WindowPos2f(GLfloat x, GLfloat y)
300 window_pos4f(x, y, 0.0F, 1.0F);
304 _mesa_WindowPos2i(GLint x, GLint y)
306 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
310 _mesa_WindowPos2s(GLshort x, GLshort y)
312 window_pos4f(x, y, 0.0F, 1.0F);
316 _mesa_WindowPos3d(GLdouble x, GLdouble y, GLdouble z)
318 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
322 _mesa_WindowPos3f(GLfloat x, GLfloat y, GLfloat z)
324 window_pos4f(x, y, z, 1.0F);
328 _mesa_WindowPos3i(GLint x, GLint y, GLint z)
330 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
334 _mesa_WindowPos3s(GLshort x, GLshort y, GLshort z)
336 window_pos4f(x, y, z, 1.0F);
340 _mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
342 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
346 _mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
348 window_pos4f(x, y, z, w);
352 _mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
354 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
358 _mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
360 window_pos4f(x, y, z, w);
364 _mesa_WindowPos2dv(const GLdouble *v)
366 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
370 _mesa_WindowPos2fv(const GLfloat *v)
372 window_pos4f(v[0], v[1], 0.0F, 1.0F);
376 _mesa_WindowPos2iv(const GLint *v)
378 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
382 _mesa_WindowPos2sv(const GLshort *v)
384 window_pos4f(v[0], v[1], 0.0F, 1.0F);
388 _mesa_WindowPos3dv(const GLdouble *v)
390 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
394 _mesa_WindowPos3fv(const GLfloat *v)
396 window_pos4f(v[0], v[1], v[2], 1.0);
400 _mesa_WindowPos3iv(const GLint *v)
402 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
406 _mesa_WindowPos3sv(const GLshort *v)
408 window_pos4f(v[0], v[1], v[2], 1.0F);
412 _mesa_WindowPos4dvMESA(const GLdouble *v)
414 window_pos4f((GLfloat) v[0], (GLfloat) v[1],
415 (GLfloat) v[2], (GLfloat) v[3]);
419 _mesa_WindowPos4fvMESA(const GLfloat *v)
421 window_pos4f(v[0], v[1], v[2], v[3]);
425 _mesa_WindowPos4ivMESA(const GLint *v)
427 window_pos4f((GLfloat) v[0], (GLfloat) v[1],
428 (GLfloat) v[2], (GLfloat) v[3]);
432 _mesa_WindowPos4svMESA(const GLshort *v)
434 window_pos4f(v[0], v[1], v[2], v[3]);
441 * OpenGL implementation of glWindowPos*MESA()
443 void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
447 /* Push current matrix mode and viewport attributes */
448 glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
450 /* Setup projection parameters */
451 glMatrixMode( GL_PROJECTION );
454 glMatrixMode( GL_MODELVIEW );
458 glDepthRange( z, z );
459 glViewport( (int) x - 1, (int) y - 1, 2, 2 );
461 /* set the raster (window) position */
464 glRasterPos4f( fx, fy, 0.0, w );
466 /* restore matrices, viewport and matrix mode */
468 glMatrixMode( GL_PROJECTION );
477 /**********************************************************************/
478 /** \name Initialization */
479 /**********************************************************************/
483 * Initialize the context current raster position information.
485 * \param ctx GL context.
487 * Initialize the current raster position information in
488 * __struct gl_contextRec::Current, and adds the extension entry points to the
491 void _mesa_init_rastpos( struct gl_context * ctx )
495 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
496 ctx->Current.RasterDistance = 0.0;
497 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
498 ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 );
499 for (i = 0; i < Elements(ctx->Current.RasterTexCoords); i++)
500 ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
501 ctx->Current.RasterPosValid = GL_TRUE;