rastpos.c revision c1f859d4
1/*
2 * Mesa 3-D graphics library
3 * Version:  6.5.3
4 *
5 * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25
26/**
27 * \file rastpos.c
28 * Raster position operations.
29 */
30
31#include "glheader.h"
32#include "context.h"
33#include "feedback.h"
34#include "macros.h"
35#include "rastpos.h"
36#include "state.h"
37
38
39/**
40 * Helper function for all the RasterPos functions.
41 */
42static void
43rasterpos(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
44{
45   GET_CURRENT_CONTEXT(ctx);
46   GLfloat p[4];
47
48   p[0] = x;
49   p[1] = y;
50   p[2] = z;
51   p[3] = w;
52
53   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
54   FLUSH_CURRENT(ctx, 0);
55
56   if (ctx->NewState)
57      _mesa_update_state( ctx );
58
59   ctx->Driver.RasterPos(ctx, p);
60}
61
62
63void GLAPIENTRY
64_mesa_RasterPos2d(GLdouble x, GLdouble y)
65{
66   rasterpos((GLfloat)x, (GLfloat)y, (GLfloat)0.0, (GLfloat)1.0);
67}
68
69void GLAPIENTRY
70_mesa_RasterPos2f(GLfloat x, GLfloat y)
71{
72   rasterpos(x, y, 0.0F, 1.0F);
73}
74
75void GLAPIENTRY
76_mesa_RasterPos2i(GLint x, GLint y)
77{
78   rasterpos((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
79}
80
81void GLAPIENTRY
82_mesa_RasterPos2s(GLshort x, GLshort y)
83{
84   rasterpos(x, y, 0.0F, 1.0F);
85}
86
87void GLAPIENTRY
88_mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
89{
90   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
91}
92
93void GLAPIENTRY
94_mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
95{
96   rasterpos(x, y, z, 1.0F);
97}
98
99void GLAPIENTRY
100_mesa_RasterPos3i(GLint x, GLint y, GLint z)
101{
102   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
103}
104
105void GLAPIENTRY
106_mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
107{
108   rasterpos(x, y, z, 1.0F);
109}
110
111void GLAPIENTRY
112_mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
113{
114   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
115}
116
117void GLAPIENTRY
118_mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
119{
120   rasterpos(x, y, z, w);
121}
122
123void GLAPIENTRY
124_mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
125{
126   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
127}
128
129void GLAPIENTRY
130_mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
131{
132   rasterpos(x, y, z, w);
133}
134
135void GLAPIENTRY
136_mesa_RasterPos2dv(const GLdouble *v)
137{
138   rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
139}
140
141void GLAPIENTRY
142_mesa_RasterPos2fv(const GLfloat *v)
143{
144   rasterpos(v[0], v[1], 0.0F, 1.0F);
145}
146
147void GLAPIENTRY
148_mesa_RasterPos2iv(const GLint *v)
149{
150   rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
151}
152
153void GLAPIENTRY
154_mesa_RasterPos2sv(const GLshort *v)
155{
156   rasterpos(v[0], v[1], 0.0F, 1.0F);
157}
158
159void GLAPIENTRY
160_mesa_RasterPos3dv(const GLdouble *v)
161{
162   rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
163}
164
165void GLAPIENTRY
166_mesa_RasterPos3fv(const GLfloat *v)
167{
168   rasterpos(v[0], v[1], v[2], 1.0F);
169}
170
171void GLAPIENTRY
172_mesa_RasterPos3iv(const GLint *v)
173{
174   rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
175}
176
177void GLAPIENTRY
178_mesa_RasterPos3sv(const GLshort *v)
179{
180   rasterpos(v[0], v[1], v[2], 1.0F);
181}
182
183void GLAPIENTRY
184_mesa_RasterPos4dv(const GLdouble *v)
185{
186   rasterpos((GLfloat) v[0], (GLfloat) v[1],
187		     (GLfloat) v[2], (GLfloat) v[3]);
188}
189
190void GLAPIENTRY
191_mesa_RasterPos4fv(const GLfloat *v)
192{
193   rasterpos(v[0], v[1], v[2], v[3]);
194}
195
196void GLAPIENTRY
197_mesa_RasterPos4iv(const GLint *v)
198{
199   rasterpos((GLfloat) v[0], (GLfloat) v[1],
200		     (GLfloat) v[2], (GLfloat) v[3]);
201}
202
203void GLAPIENTRY
204_mesa_RasterPos4sv(const GLshort *v)
205{
206   rasterpos(v[0], v[1], v[2], v[3]);
207}
208
209
210/**********************************************************************/
211/***           GL_ARB_window_pos / GL_MESA_window_pos               ***/
212/**********************************************************************/
213
214#if FEATURE_drawpix
215/**
216 * All glWindowPosMESA and glWindowPosARB commands call this function to
217 * update the current raster position.
218 */
219static void
220window_pos3f(GLfloat x, GLfloat y, GLfloat z)
221{
222   GET_CURRENT_CONTEXT(ctx);
223   GLfloat z2;
224
225   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
226   FLUSH_CURRENT(ctx, 0);
227
228   z2 = CLAMP(z, 0.0F, 1.0F) * (ctx->Viewport.Far - ctx->Viewport.Near)
229      + ctx->Viewport.Near;
230
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;
236
237   ctx->Current.RasterPosValid = GL_TRUE;
238
239   if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
240      ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
241   else
242      ctx->Current.RasterDistance = 0.0;
243
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);
262   }
263   else {
264      ctx->Current.RasterIndex
265         = ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0];
266   }
267
268   /* raster texcoord = current texcoord */
269   {
270      GLuint texSet;
271      for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) {
272         COPY_4FV( ctx->Current.RasterTexCoords[texSet],
273                  ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] );
274      }
275   }
276
277   if (ctx->RenderMode==GL_SELECT) {
278      _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
279   }
280}
281
282
283/* This is just to support the GL_MESA_window_pos version */
284static void
285window_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
286{
287   GET_CURRENT_CONTEXT(ctx);
288   window_pos3f(x, y, z);
289   ctx->Current.RasterPos[3] = w;
290}
291
292
293void GLAPIENTRY
294_mesa_WindowPos2dMESA(GLdouble x, GLdouble y)
295{
296   window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
297}
298
299void GLAPIENTRY
300_mesa_WindowPos2fMESA(GLfloat x, GLfloat y)
301{
302   window_pos4f(x, y, 0.0F, 1.0F);
303}
304
305void GLAPIENTRY
306_mesa_WindowPos2iMESA(GLint x, GLint y)
307{
308   window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
309}
310
311void GLAPIENTRY
312_mesa_WindowPos2sMESA(GLshort x, GLshort y)
313{
314   window_pos4f(x, y, 0.0F, 1.0F);
315}
316
317void GLAPIENTRY
318_mesa_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
319{
320   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
321}
322
323void GLAPIENTRY
324_mesa_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
325{
326   window_pos4f(x, y, z, 1.0F);
327}
328
329void GLAPIENTRY
330_mesa_WindowPos3iMESA(GLint x, GLint y, GLint z)
331{
332   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
333}
334
335void GLAPIENTRY
336_mesa_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
337{
338   window_pos4f(x, y, z, 1.0F);
339}
340
341void GLAPIENTRY
342_mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
343{
344   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
345}
346
347void GLAPIENTRY
348_mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
349{
350   window_pos4f(x, y, z, w);
351}
352
353void GLAPIENTRY
354_mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
355{
356   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
357}
358
359void GLAPIENTRY
360_mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
361{
362   window_pos4f(x, y, z, w);
363}
364
365void GLAPIENTRY
366_mesa_WindowPos2dvMESA(const GLdouble *v)
367{
368   window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
369}
370
371void GLAPIENTRY
372_mesa_WindowPos2fvMESA(const GLfloat *v)
373{
374   window_pos4f(v[0], v[1], 0.0F, 1.0F);
375}
376
377void GLAPIENTRY
378_mesa_WindowPos2ivMESA(const GLint *v)
379{
380   window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
381}
382
383void GLAPIENTRY
384_mesa_WindowPos2svMESA(const GLshort *v)
385{
386   window_pos4f(v[0], v[1], 0.0F, 1.0F);
387}
388
389void GLAPIENTRY
390_mesa_WindowPos3dvMESA(const GLdouble *v)
391{
392   window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
393}
394
395void GLAPIENTRY
396_mesa_WindowPos3fvMESA(const GLfloat *v)
397{
398   window_pos4f(v[0], v[1], v[2], 1.0);
399}
400
401void GLAPIENTRY
402_mesa_WindowPos3ivMESA(const GLint *v)
403{
404   window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
405}
406
407void GLAPIENTRY
408_mesa_WindowPos3svMESA(const GLshort *v)
409{
410   window_pos4f(v[0], v[1], v[2], 1.0F);
411}
412
413void GLAPIENTRY
414_mesa_WindowPos4dvMESA(const GLdouble *v)
415{
416   window_pos4f((GLfloat) v[0], (GLfloat) v[1],
417			 (GLfloat) v[2], (GLfloat) v[3]);
418}
419
420void GLAPIENTRY
421_mesa_WindowPos4fvMESA(const GLfloat *v)
422{
423   window_pos4f(v[0], v[1], v[2], v[3]);
424}
425
426void GLAPIENTRY
427_mesa_WindowPos4ivMESA(const GLint *v)
428{
429   window_pos4f((GLfloat) v[0], (GLfloat) v[1],
430			 (GLfloat) v[2], (GLfloat) v[3]);
431}
432
433void GLAPIENTRY
434_mesa_WindowPos4svMESA(const GLshort *v)
435{
436   window_pos4f(v[0], v[1], v[2], v[3]);
437}
438
439#endif
440
441#if 0
442
443/*
444 * OpenGL implementation of glWindowPos*MESA()
445 */
446void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
447{
448   GLfloat fx, fy;
449
450   /* Push current matrix mode and viewport attributes */
451   glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
452
453   /* Setup projection parameters */
454   glMatrixMode( GL_PROJECTION );
455   glPushMatrix();
456   glLoadIdentity();
457   glMatrixMode( GL_MODELVIEW );
458   glPushMatrix();
459   glLoadIdentity();
460
461   glDepthRange( z, z );
462   glViewport( (int) x - 1, (int) y - 1, 2, 2 );
463
464   /* set the raster (window) position */
465   fx = x - (int) x;
466   fy = y - (int) y;
467   glRasterPos4f( fx, fy, 0.0, w );
468
469   /* restore matrices, viewport and matrix mode */
470   glPopMatrix();
471   glMatrixMode( GL_PROJECTION );
472   glPopMatrix();
473
474   glPopAttrib();
475}
476
477#endif
478
479
480/**********************************************************************/
481/** \name Initialization                                              */
482/**********************************************************************/
483/*@{*/
484
485/**
486 * Initialize the context current raster position information.
487 *
488 * \param ctx GL context.
489 *
490 * Initialize the current raster position information in
491 * __GLcontextRec::Current, and adds the extension entry points to the
492 * dispatcher.
493 */
494void _mesa_init_rastpos( GLcontext * ctx )
495{
496   int i;
497
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_COORD_UNITS; i++)
504      ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
505   ctx->Current.RasterPosValid = GL_TRUE;
506}
507
508/*@}*/
509