rastpos.c revision 7117f1b4
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 "colormac.h"
33#include "context.h"
34#include "feedback.h"
35#include "light.h"
36#include "macros.h"
37#include "rastpos.h"
38#include "state.h"
39#include "simple_list.h"
40#include "mtypes.h"
41
42#include "math/m_matrix.h"
43
44
45/**
46 * Clip a point against the view volume.
47 *
48 * \param v vertex vector describing the point to clip.
49 *
50 * \return zero if outside view volume, or one if inside.
51 */
52static GLuint
53viewclip_point( const GLfloat v[] )
54{
55   if (   v[0] > v[3] || v[0] < -v[3]
56       || v[1] > v[3] || v[1] < -v[3]
57       || v[2] > v[3] || v[2] < -v[3] ) {
58      return 0;
59   }
60   else {
61      return 1;
62   }
63}
64
65
66/**
67 * Clip a point against the far/near Z clipping planes.
68 *
69 * \param v vertex vector describing the point to clip.
70 *
71 * \return zero if outside view volume, or one if inside.
72 */
73static GLuint
74viewclip_point_z( const GLfloat v[] )
75{
76   if (v[2] > v[3] || v[2] < -v[3] ) {
77      return 0;
78   }
79   else {
80      return 1;
81   }
82}
83
84
85/**
86 * Clip a point against the user clipping planes.
87 *
88 * \param ctx GL context.
89 * \param v vertex vector describing the point to clip.
90 *
91 * \return zero if the point was clipped, or one otherwise.
92 */
93static GLuint
94userclip_point( GLcontext *ctx, const GLfloat v[] )
95{
96   GLuint p;
97
98   for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
99      if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
100	 GLfloat dot = v[0] * ctx->Transform._ClipUserPlane[p][0]
101		     + v[1] * ctx->Transform._ClipUserPlane[p][1]
102		     + v[2] * ctx->Transform._ClipUserPlane[p][2]
103		     + v[3] * ctx->Transform._ClipUserPlane[p][3];
104         if (dot < 0.0F) {
105            return 0;
106         }
107      }
108   }
109
110   return 1;
111}
112
113
114/**
115 * Compute lighting for the raster position.  Both RGB and CI modes computed.
116 * \param ctx the context
117 * \param vertex vertex location
118 * \param normal normal vector
119 * \param Rcolor returned color
120 * \param Rspec returned specular color (if separate specular enabled)
121 * \param Rindex returned color index
122 */
123static void
124shade_rastpos(GLcontext *ctx,
125              const GLfloat vertex[4],
126              const GLfloat normal[3],
127              GLfloat Rcolor[4],
128              GLfloat Rspec[4],
129              GLfloat *Rindex)
130{
131   /*const*/ GLfloat (*base)[3] = ctx->Light._BaseColor;
132   const struct gl_light *light;
133   GLfloat diffuseColor[4], specularColor[4];  /* for RGB mode only */
134   GLfloat diffuseCI = 0.0, specularCI = 0.0;  /* for CI mode only */
135
136   _mesa_validate_all_lighting_tables( ctx );
137
138   COPY_3V(diffuseColor, base[0]);
139   diffuseColor[3] = CLAMP(
140      ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3], 0.0F, 1.0F );
141   ASSIGN_4V(specularColor, 0.0, 0.0, 0.0, 1.0);
142
143   foreach (light, &ctx->Light.EnabledList) {
144      GLfloat attenuation = 1.0;
145      GLfloat VP[3]; /* vector from vertex to light pos */
146      GLfloat n_dot_VP;
147      GLfloat diffuseContrib[3], specularContrib[3];
148
149      if (!(light->_Flags & LIGHT_POSITIONAL)) {
150         /* light at infinity */
151	 COPY_3V(VP, light->_VP_inf_norm);
152	 attenuation = light->_VP_inf_spot_attenuation;
153      }
154      else {
155         /* local/positional light */
156	 GLfloat d;
157
158         /* VP = vector from vertex pos to light[i].pos */
159	 SUB_3V(VP, light->_Position, vertex);
160         /* d = length(VP) */
161	 d = (GLfloat) LEN_3FV( VP );
162	 if (d > 1.0e-6) {
163            /* normalize VP */
164	    GLfloat invd = 1.0F / d;
165	    SELF_SCALE_SCALAR_3V(VP, invd);
166	 }
167
168         /* atti */
169	 attenuation = 1.0F / (light->ConstantAttenuation + d *
170			       (light->LinearAttenuation + d *
171				light->QuadraticAttenuation));
172
173	 if (light->_Flags & LIGHT_SPOT) {
174	    GLfloat PV_dot_dir = - DOT3(VP, light->_NormDirection);
175
176	    if (PV_dot_dir<light->_CosCutoff) {
177	       continue;
178	    }
179	    else {
180	       double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
181	       int k = (int) x;
182	       GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0]
183			       + (x-k)*light->_SpotExpTable[k][1]);
184	       attenuation *= spot;
185	    }
186	 }
187      }
188
189      if (attenuation < 1e-3)
190	 continue;
191
192      n_dot_VP = DOT3( normal, VP );
193
194      if (n_dot_VP < 0.0F) {
195	 ACC_SCALE_SCALAR_3V(diffuseColor, attenuation, light->_MatAmbient[0]);
196	 continue;
197      }
198
199      /* Ambient + diffuse */
200      COPY_3V(diffuseContrib, light->_MatAmbient[0]);
201      ACC_SCALE_SCALAR_3V(diffuseContrib, n_dot_VP, light->_MatDiffuse[0]);
202      diffuseCI += n_dot_VP * light->_dli * attenuation;
203
204      /* Specular */
205      {
206         const GLfloat *h;
207         GLfloat n_dot_h;
208
209         ASSIGN_3V(specularContrib, 0.0, 0.0, 0.0);
210
211	 if (ctx->Light.Model.LocalViewer) {
212	    GLfloat v[3];
213	    COPY_3V(v, vertex);
214	    NORMALIZE_3FV(v);
215	    SUB_3V(VP, VP, v);
216            NORMALIZE_3FV(VP);
217	    h = VP;
218	 }
219	 else if (light->_Flags & LIGHT_POSITIONAL) {
220	    ACC_3V(VP, ctx->_EyeZDir);
221            NORMALIZE_3FV(VP);
222	    h = VP;
223	 }
224         else {
225	    h = light->_h_inf_norm;
226	 }
227
228	 n_dot_h = DOT3(normal, h);
229
230	 if (n_dot_h > 0.0F) {
231	    GLfloat spec_coef;
232	    GET_SHINE_TAB_ENTRY( ctx->_ShineTable[0], n_dot_h, spec_coef );
233
234	    if (spec_coef > 1.0e-10) {
235               if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) {
236                  ACC_SCALE_SCALAR_3V( specularContrib, spec_coef,
237                                       light->_MatSpecular[0]);
238               }
239               else {
240                  ACC_SCALE_SCALAR_3V( diffuseContrib, spec_coef,
241                                       light->_MatSpecular[0]);
242               }
243               /*assert(light->_sli > 0.0);*/
244               specularCI += spec_coef * light->_sli * attenuation;
245	    }
246	 }
247      }
248
249      ACC_SCALE_SCALAR_3V( diffuseColor, attenuation, diffuseContrib );
250      ACC_SCALE_SCALAR_3V( specularColor, attenuation, specularContrib );
251   }
252
253   if (ctx->Visual.rgbMode) {
254      Rcolor[0] = CLAMP(diffuseColor[0], 0.0F, 1.0F);
255      Rcolor[1] = CLAMP(diffuseColor[1], 0.0F, 1.0F);
256      Rcolor[2] = CLAMP(diffuseColor[2], 0.0F, 1.0F);
257      Rcolor[3] = CLAMP(diffuseColor[3], 0.0F, 1.0F);
258      Rspec[0] = CLAMP(specularColor[0], 0.0F, 1.0F);
259      Rspec[1] = CLAMP(specularColor[1], 0.0F, 1.0F);
260      Rspec[2] = CLAMP(specularColor[2], 0.0F, 1.0F);
261      Rspec[3] = CLAMP(specularColor[3], 0.0F, 1.0F);
262   }
263   else {
264      GLfloat *ind = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_INDEXES];
265      GLfloat d_a = ind[MAT_INDEX_DIFFUSE] - ind[MAT_INDEX_AMBIENT];
266      GLfloat s_a = ind[MAT_INDEX_SPECULAR] - ind[MAT_INDEX_AMBIENT];
267      GLfloat i = (ind[MAT_INDEX_AMBIENT]
268		   + diffuseCI * (1.0F-specularCI) * d_a
269		   + specularCI * s_a);
270      if (i > ind[MAT_INDEX_SPECULAR]) {
271	 i = ind[MAT_INDEX_SPECULAR];
272      }
273      *Rindex = i;
274   }
275}
276
277
278/**
279 * Do texgen needed for glRasterPos.
280 * \param ctx  rendering context
281 * \param vObj  object-space vertex coordinate
282 * \param vEye  eye-space vertex coordinate
283 * \param normal  vertex normal
284 * \param unit  texture unit number
285 * \param texcoord  incoming texcoord and resulting texcoord
286 */
287static void
288compute_texgen(GLcontext *ctx, const GLfloat vObj[4], const GLfloat vEye[4],
289               const GLfloat normal[3], GLuint unit, GLfloat texcoord[4])
290{
291   const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
292
293   /* always compute sphere map terms, just in case */
294   GLfloat u[3], two_nu, rx, ry, rz, m, mInv;
295   COPY_3V(u, vEye);
296   NORMALIZE_3FV(u);
297   two_nu = 2.0F * DOT3(normal, u);
298   rx = u[0] - normal[0] * two_nu;
299   ry = u[1] - normal[1] * two_nu;
300   rz = u[2] - normal[2] * two_nu;
301   m = rx * rx + ry * ry + (rz + 1.0F) * (rz + 1.0F);
302   if (m > 0.0F)
303      mInv = 0.5F * _mesa_inv_sqrtf(m);
304   else
305      mInv = 0.0F;
306
307   if (texUnit->TexGenEnabled & S_BIT) {
308      switch (texUnit->GenModeS) {
309         case GL_OBJECT_LINEAR:
310            texcoord[0] = DOT4(vObj, texUnit->ObjectPlaneS);
311            break;
312         case GL_EYE_LINEAR:
313            texcoord[0] = DOT4(vEye, texUnit->EyePlaneS);
314            break;
315         case GL_SPHERE_MAP:
316            texcoord[0] = rx * mInv + 0.5F;
317            break;
318         case GL_REFLECTION_MAP:
319            texcoord[0] = rx;
320            break;
321         case GL_NORMAL_MAP:
322            texcoord[0] = normal[0];
323            break;
324         default:
325            _mesa_problem(ctx, "Bad S texgen in compute_texgen()");
326            return;
327      }
328   }
329
330   if (texUnit->TexGenEnabled & T_BIT) {
331      switch (texUnit->GenModeT) {
332         case GL_OBJECT_LINEAR:
333            texcoord[1] = DOT4(vObj, texUnit->ObjectPlaneT);
334            break;
335         case GL_EYE_LINEAR:
336            texcoord[1] = DOT4(vEye, texUnit->EyePlaneT);
337            break;
338         case GL_SPHERE_MAP:
339            texcoord[1] = ry * mInv + 0.5F;
340            break;
341         case GL_REFLECTION_MAP:
342            texcoord[1] = ry;
343            break;
344         case GL_NORMAL_MAP:
345            texcoord[1] = normal[1];
346            break;
347         default:
348            _mesa_problem(ctx, "Bad T texgen in compute_texgen()");
349            return;
350      }
351   }
352
353   if (texUnit->TexGenEnabled & R_BIT) {
354      switch (texUnit->GenModeR) {
355         case GL_OBJECT_LINEAR:
356            texcoord[2] = DOT4(vObj, texUnit->ObjectPlaneR);
357            break;
358         case GL_EYE_LINEAR:
359            texcoord[2] = DOT4(vEye, texUnit->EyePlaneR);
360            break;
361         case GL_REFLECTION_MAP:
362            texcoord[2] = rz;
363            break;
364         case GL_NORMAL_MAP:
365            texcoord[2] = normal[2];
366            break;
367         default:
368            _mesa_problem(ctx, "Bad R texgen in compute_texgen()");
369            return;
370      }
371   }
372
373   if (texUnit->TexGenEnabled & Q_BIT) {
374      switch (texUnit->GenModeQ) {
375         case GL_OBJECT_LINEAR:
376            texcoord[3] = DOT4(vObj, texUnit->ObjectPlaneQ);
377            break;
378         case GL_EYE_LINEAR:
379            texcoord[3] = DOT4(vEye, texUnit->EyePlaneQ);
380            break;
381         default:
382            _mesa_problem(ctx, "Bad Q texgen in compute_texgen()");
383            return;
384      }
385   }
386}
387
388
389
390/**
391 * Set the raster position for pixel operations.
392 *
393 * All glRasterPos command call this function to update the current
394 * raster position.
395 *
396 * \param ctx GL context.
397 * \param x x coordinate for the raster position.
398 * \param y y coordinate for the raster position.
399 * \param z z coordinate for the raster position.
400 * \param w w coordinate for the raster position.
401 *
402 * \sa Called by _mesa_RasterPos4f().
403 *
404 * Flushes the vertices, transforms and clips the vertex coordinates, and
405 * finally sets the current raster position and associated data in
406 * __GLcontextRec::Current.  When in selection mode calls
407 * _mesa_update_hitflag() with the current raster position.
408 */
409static void
410raster_pos4f(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
411{
412   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
413   FLUSH_CURRENT(ctx, 0);
414
415   if (ctx->NewState)
416      _mesa_update_state( ctx );
417
418   if (ctx->VertexProgram._Enabled) {
419      /* XXX implement this */
420      _mesa_problem(ctx, "Vertex programs not implemented for glRasterPos");
421      return;
422   }
423   else {
424      GLfloat obj[4], eye[4], clip[4], ndc[3], d;
425      GLfloat *norm, eyenorm[3];
426      GLfloat *objnorm = ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
427
428      ASSIGN_4V( obj, x, y, z, w );
429      /* apply modelview matrix:  eye = MV * obj */
430      TRANSFORM_POINT( eye, ctx->ModelviewMatrixStack.Top->m, obj );
431      /* apply projection matrix:  clip = Proj * eye */
432      TRANSFORM_POINT( clip, ctx->ProjectionMatrixStack.Top->m, eye );
433
434      /* clip to view volume */
435      if (ctx->Transform.RasterPositionUnclipped) {
436         /* GL_IBM_rasterpos_clip: only clip against Z */
437         if (viewclip_point_z(clip) == 0) {
438            ctx->Current.RasterPosValid = GL_FALSE;
439            return;
440         }
441      }
442      else if (viewclip_point(clip) == 0) {
443         /* Normal OpenGL behaviour */
444         ctx->Current.RasterPosValid = GL_FALSE;
445         return;
446      }
447
448      /* clip to user clipping planes */
449      if (ctx->Transform.ClipPlanesEnabled && !userclip_point(ctx, clip)) {
450         ctx->Current.RasterPosValid = GL_FALSE;
451         return;
452      }
453
454      /* ndc = clip / W */
455      d = (clip[3] == 0.0F) ? 1.0F : 1.0F / clip[3];
456      ndc[0] = clip[0] * d;
457      ndc[1] = clip[1] * d;
458      ndc[2] = clip[2] * d;
459      /* wincoord = viewport_mapping(ndc) */
460      ctx->Current.RasterPos[0] = (ndc[0] * ctx->Viewport._WindowMap.m[MAT_SX]
461                                   + ctx->Viewport._WindowMap.m[MAT_TX]);
462      ctx->Current.RasterPos[1] = (ndc[1] * ctx->Viewport._WindowMap.m[MAT_SY]
463                                   + ctx->Viewport._WindowMap.m[MAT_TY]);
464      ctx->Current.RasterPos[2] = (ndc[2] * ctx->Viewport._WindowMap.m[MAT_SZ]
465                                   + ctx->Viewport._WindowMap.m[MAT_TZ])
466                                  / ctx->DrawBuffer->_DepthMaxF;
467      ctx->Current.RasterPos[3] = clip[3];
468
469      /* compute raster distance */
470      if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
471         ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
472      else
473         ctx->Current.RasterDistance =
474                        SQRTF( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
475
476      /* compute transformed normal vector (for lighting or texgen) */
477      if (ctx->_NeedEyeCoords) {
478         const GLfloat *inv = ctx->ModelviewMatrixStack.Top->inv;
479         TRANSFORM_NORMAL( eyenorm, objnorm, inv );
480         norm = eyenorm;
481      }
482      else {
483         norm = objnorm;
484      }
485
486      /* update raster color */
487      if (ctx->Light.Enabled) {
488         /* lighting */
489         shade_rastpos( ctx, obj, norm,
490                        ctx->Current.RasterColor,
491                        ctx->Current.RasterSecondaryColor,
492                        &ctx->Current.RasterIndex );
493      }
494      else {
495         /* use current color or index */
496         if (ctx->Visual.rgbMode) {
497            COPY_4FV(ctx->Current.RasterColor,
498                     ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
499            COPY_4FV(ctx->Current.RasterSecondaryColor,
500                     ctx->Current.Attrib[VERT_ATTRIB_COLOR1]);
501         }
502         else {
503            ctx->Current.RasterIndex
504               = ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0];
505         }
506      }
507
508      /* texture coords */
509      {
510         GLuint u;
511         for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) {
512            GLfloat tc[4];
513            COPY_4V(tc, ctx->Current.Attrib[VERT_ATTRIB_TEX0 + u]);
514            if (ctx->Texture.Unit[u].TexGenEnabled) {
515               compute_texgen(ctx, obj, eye, norm, u, tc);
516            }
517            TRANSFORM_POINT(ctx->Current.RasterTexCoords[u],
518                            ctx->TextureMatrixStack[u].Top->m, tc);
519         }
520      }
521
522      ctx->Current.RasterPosValid = GL_TRUE;
523   }
524
525   if (ctx->RenderMode == GL_SELECT) {
526      _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
527   }
528}
529
530
531/** Calls _mesa_RasterPos4f() */
532void GLAPIENTRY
533_mesa_RasterPos2d(GLdouble x, GLdouble y)
534{
535   _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
536}
537
538/** Calls _mesa_RasterPos4f() */
539void GLAPIENTRY
540_mesa_RasterPos2f(GLfloat x, GLfloat y)
541{
542   _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
543}
544
545/** Calls _mesa_RasterPos4f() */
546void GLAPIENTRY
547_mesa_RasterPos2i(GLint x, GLint y)
548{
549   _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
550}
551
552/** Calls _mesa_RasterPos4f() */
553void GLAPIENTRY
554_mesa_RasterPos2s(GLshort x, GLshort y)
555{
556   _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
557}
558
559/** Calls _mesa_RasterPos4f() */
560void GLAPIENTRY
561_mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
562{
563   _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
564}
565
566/** Calls _mesa_RasterPos4f() */
567void GLAPIENTRY
568_mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
569{
570   _mesa_RasterPos4f(x, y, z, 1.0F);
571}
572
573/** Calls _mesa_RasterPos4f() */
574void GLAPIENTRY
575_mesa_RasterPos3i(GLint x, GLint y, GLint z)
576{
577   _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
578}
579
580/** Calls _mesa_RasterPos4f() */
581void GLAPIENTRY
582_mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
583{
584   _mesa_RasterPos4f(x, y, z, 1.0F);
585}
586
587/** Calls _mesa_RasterPos4f() */
588void GLAPIENTRY
589_mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
590{
591   _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
592}
593
594/** Calls raster_pos4f() */
595void GLAPIENTRY
596_mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
597{
598   GET_CURRENT_CONTEXT(ctx);
599   raster_pos4f(ctx, x, y, z, w);
600}
601
602/** Calls _mesa_RasterPos4f() */
603void GLAPIENTRY
604_mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
605{
606   _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
607}
608
609/** Calls _mesa_RasterPos4f() */
610void GLAPIENTRY
611_mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
612{
613   _mesa_RasterPos4f(x, y, z, w);
614}
615
616/** Calls _mesa_RasterPos4f() */
617void GLAPIENTRY
618_mesa_RasterPos2dv(const GLdouble *v)
619{
620   _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
621}
622
623/** Calls _mesa_RasterPos4f() */
624void GLAPIENTRY
625_mesa_RasterPos2fv(const GLfloat *v)
626{
627   _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
628}
629
630/** Calls _mesa_RasterPos4f() */
631void GLAPIENTRY
632_mesa_RasterPos2iv(const GLint *v)
633{
634   _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
635}
636
637/** Calls _mesa_RasterPos4f() */
638void GLAPIENTRY
639_mesa_RasterPos2sv(const GLshort *v)
640{
641   _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
642}
643
644/** Calls _mesa_RasterPos4f() */
645void GLAPIENTRY
646_mesa_RasterPos3dv(const GLdouble *v)
647{
648   _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
649}
650
651/** Calls _mesa_RasterPos4f() */
652void GLAPIENTRY
653_mesa_RasterPos3fv(const GLfloat *v)
654{
655   _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
656}
657
658/** Calls _mesa_RasterPos4f() */
659void GLAPIENTRY
660_mesa_RasterPos3iv(const GLint *v)
661{
662   _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
663}
664
665/** Calls _mesa_RasterPos4f() */
666void GLAPIENTRY
667_mesa_RasterPos3sv(const GLshort *v)
668{
669   _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
670}
671
672/** Calls _mesa_RasterPos4f() */
673void GLAPIENTRY
674_mesa_RasterPos4dv(const GLdouble *v)
675{
676   _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
677		     (GLfloat) v[2], (GLfloat) v[3]);
678}
679
680/** Calls _mesa_RasterPos4f() */
681void GLAPIENTRY
682_mesa_RasterPos4fv(const GLfloat *v)
683{
684   _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
685}
686
687/** Calls _mesa_RasterPos4f() */
688void GLAPIENTRY
689_mesa_RasterPos4iv(const GLint *v)
690{
691   _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
692		     (GLfloat) v[2], (GLfloat) v[3]);
693}
694
695/** Calls _mesa_RasterPos4f() */
696void GLAPIENTRY
697_mesa_RasterPos4sv(const GLshort *v)
698{
699   _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
700}
701
702
703/**********************************************************************/
704/***           GL_ARB_window_pos / GL_MESA_window_pos               ***/
705/**********************************************************************/
706
707#if FEATURE_windowpos
708/**
709 * All glWindowPosMESA and glWindowPosARB commands call this function to
710 * update the current raster position.
711 */
712static void
713window_pos3f(GLfloat x, GLfloat y, GLfloat z)
714{
715   GET_CURRENT_CONTEXT(ctx);
716   GLfloat z2;
717
718   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
719   FLUSH_CURRENT(ctx, 0);
720
721   z2 = CLAMP(z, 0.0F, 1.0F) * (ctx->Viewport.Far - ctx->Viewport.Near)
722      + ctx->Viewport.Near;
723
724   /* set raster position */
725   ctx->Current.RasterPos[0] = x;
726   ctx->Current.RasterPos[1] = y;
727   ctx->Current.RasterPos[2] = z2;
728   ctx->Current.RasterPos[3] = 1.0F;
729
730   ctx->Current.RasterPosValid = GL_TRUE;
731
732   if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
733      ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
734   else
735      ctx->Current.RasterDistance = 0.0;
736
737   /* raster color = current color or index */
738   if (ctx->Visual.rgbMode) {
739      ctx->Current.RasterColor[0]
740         = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0], 0.0F, 1.0F);
741      ctx->Current.RasterColor[1]
742         = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][1], 0.0F, 1.0F);
743      ctx->Current.RasterColor[2]
744         = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][2], 0.0F, 1.0F);
745      ctx->Current.RasterColor[3]
746         = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3], 0.0F, 1.0F);
747      ctx->Current.RasterSecondaryColor[0]
748         = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0], 0.0F, 1.0F);
749      ctx->Current.RasterSecondaryColor[1]
750         = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1], 0.0F, 1.0F);
751      ctx->Current.RasterSecondaryColor[2]
752         = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][2], 0.0F, 1.0F);
753      ctx->Current.RasterSecondaryColor[3]
754         = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][3], 0.0F, 1.0F);
755   }
756   else {
757      ctx->Current.RasterIndex
758         = ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0];
759   }
760
761   /* raster texcoord = current texcoord */
762   {
763      GLuint texSet;
764      for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) {
765         COPY_4FV( ctx->Current.RasterTexCoords[texSet],
766                  ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] );
767      }
768   }
769
770   if (ctx->RenderMode==GL_SELECT) {
771      _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
772   }
773}
774
775
776/* This is just to support the GL_MESA_window_pos version */
777static void
778window_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
779{
780   GET_CURRENT_CONTEXT(ctx);
781   window_pos3f(x, y, z);
782   ctx->Current.RasterPos[3] = w;
783}
784
785
786void GLAPIENTRY
787_mesa_WindowPos2dMESA(GLdouble x, GLdouble y)
788{
789   window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
790}
791
792void GLAPIENTRY
793_mesa_WindowPos2fMESA(GLfloat x, GLfloat y)
794{
795   window_pos4f(x, y, 0.0F, 1.0F);
796}
797
798void GLAPIENTRY
799_mesa_WindowPos2iMESA(GLint x, GLint y)
800{
801   window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
802}
803
804void GLAPIENTRY
805_mesa_WindowPos2sMESA(GLshort x, GLshort y)
806{
807   window_pos4f(x, y, 0.0F, 1.0F);
808}
809
810void GLAPIENTRY
811_mesa_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
812{
813   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
814}
815
816void GLAPIENTRY
817_mesa_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
818{
819   window_pos4f(x, y, z, 1.0F);
820}
821
822void GLAPIENTRY
823_mesa_WindowPos3iMESA(GLint x, GLint y, GLint z)
824{
825   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
826}
827
828void GLAPIENTRY
829_mesa_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
830{
831   window_pos4f(x, y, z, 1.0F);
832}
833
834void GLAPIENTRY
835_mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
836{
837   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
838}
839
840void GLAPIENTRY
841_mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
842{
843   window_pos4f(x, y, z, w);
844}
845
846void GLAPIENTRY
847_mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
848{
849   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
850}
851
852void GLAPIENTRY
853_mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
854{
855   window_pos4f(x, y, z, w);
856}
857
858void GLAPIENTRY
859_mesa_WindowPos2dvMESA(const GLdouble *v)
860{
861   window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
862}
863
864void GLAPIENTRY
865_mesa_WindowPos2fvMESA(const GLfloat *v)
866{
867   window_pos4f(v[0], v[1], 0.0F, 1.0F);
868}
869
870void GLAPIENTRY
871_mesa_WindowPos2ivMESA(const GLint *v)
872{
873   window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
874}
875
876void GLAPIENTRY
877_mesa_WindowPos2svMESA(const GLshort *v)
878{
879   window_pos4f(v[0], v[1], 0.0F, 1.0F);
880}
881
882void GLAPIENTRY
883_mesa_WindowPos3dvMESA(const GLdouble *v)
884{
885   window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
886}
887
888void GLAPIENTRY
889_mesa_WindowPos3fvMESA(const GLfloat *v)
890{
891   window_pos4f(v[0], v[1], v[2], 1.0);
892}
893
894void GLAPIENTRY
895_mesa_WindowPos3ivMESA(const GLint *v)
896{
897   window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
898}
899
900void GLAPIENTRY
901_mesa_WindowPos3svMESA(const GLshort *v)
902{
903   window_pos4f(v[0], v[1], v[2], 1.0F);
904}
905
906void GLAPIENTRY
907_mesa_WindowPos4dvMESA(const GLdouble *v)
908{
909   window_pos4f((GLfloat) v[0], (GLfloat) v[1],
910			 (GLfloat) v[2], (GLfloat) v[3]);
911}
912
913void GLAPIENTRY
914_mesa_WindowPos4fvMESA(const GLfloat *v)
915{
916   window_pos4f(v[0], v[1], v[2], v[3]);
917}
918
919void GLAPIENTRY
920_mesa_WindowPos4ivMESA(const GLint *v)
921{
922   window_pos4f((GLfloat) v[0], (GLfloat) v[1],
923			 (GLfloat) v[2], (GLfloat) v[3]);
924}
925
926void GLAPIENTRY
927_mesa_WindowPos4svMESA(const GLshort *v)
928{
929   window_pos4f(v[0], v[1], v[2], v[3]);
930}
931
932#endif
933
934#if 0
935
936/*
937 * OpenGL implementation of glWindowPos*MESA()
938 */
939void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
940{
941   GLfloat fx, fy;
942
943   /* Push current matrix mode and viewport attributes */
944   glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
945
946   /* Setup projection parameters */
947   glMatrixMode( GL_PROJECTION );
948   glPushMatrix();
949   glLoadIdentity();
950   glMatrixMode( GL_MODELVIEW );
951   glPushMatrix();
952   glLoadIdentity();
953
954   glDepthRange( z, z );
955   glViewport( (int) x - 1, (int) y - 1, 2, 2 );
956
957   /* set the raster (window) position */
958   fx = x - (int) x;
959   fy = y - (int) y;
960   glRasterPos4f( fx, fy, 0.0, w );
961
962   /* restore matrices, viewport and matrix mode */
963   glPopMatrix();
964   glMatrixMode( GL_PROJECTION );
965   glPopMatrix();
966
967   glPopAttrib();
968}
969
970#endif
971
972
973/**********************************************************************/
974/** \name Initialization                                              */
975/**********************************************************************/
976/*@{*/
977
978/**
979 * Initialize the context current raster position information.
980 *
981 * \param ctx GL context.
982 *
983 * Initialize the current raster position information in
984 * __GLcontextRec::Current, and adds the extension entry points to the
985 * dispatcher.
986 */
987void _mesa_init_rastpos( GLcontext * ctx )
988{
989   int i;
990
991   ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
992   ctx->Current.RasterDistance = 0.0;
993   ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
994   ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 );
995   ctx->Current.RasterIndex = 1.0;
996   for (i=0; i<MAX_TEXTURE_UNITS; i++)
997      ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
998   ctx->Current.RasterPosValid = GL_TRUE;
999}
1000
1001/*@}*/
1002