17117f1b4Smrg/*
27117f1b4Smrg * Mesa 3-D graphics library
37117f1b4Smrg *
47117f1b4Smrg * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
57117f1b4Smrg *
67117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
77117f1b4Smrg * copy of this software and associated documentation files (the "Software"),
87117f1b4Smrg * to deal in the Software without restriction, including without limitation
97117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
107117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the
117117f1b4Smrg * Software is furnished to do so, subject to the following conditions:
127117f1b4Smrg *
137117f1b4Smrg * The above copyright notice and this permission notice shall be included
147117f1b4Smrg * in all copies or substantial portions of the Software.
157117f1b4Smrg *
167117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
177117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
187117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE.
237117f1b4Smrg */
247117f1b4Smrg
257117f1b4Smrg
267117f1b4Smrg/**
277117f1b4Smrg * \file rastpos.c
287117f1b4Smrg * Raster position operations.
297117f1b4Smrg */
307117f1b4Smrg
317117f1b4Smrg#include "glheader.h"
327117f1b4Smrg#include "context.h"
337117f1b4Smrg#include "feedback.h"
347117f1b4Smrg#include "macros.h"
353464ebd5Sriastradh#include "mtypes.h"
367117f1b4Smrg#include "rastpos.h"
377117f1b4Smrg#include "state.h"
387ec681f3Smrg#include "main/light.h"
3901e04c3fSmrg#include "main/viewport.h"
4001e04c3fSmrg#include "util/bitscan.h"
4101e04c3fSmrg
4201e04c3fSmrg
4301e04c3fSmrg
4401e04c3fSmrg/**
4501e04c3fSmrg * Clip a point against the view volume.
4601e04c3fSmrg *
4701e04c3fSmrg * \param v vertex vector describing the point to clip.
4801e04c3fSmrg *
4901e04c3fSmrg * \return zero if outside view volume, or one if inside.
5001e04c3fSmrg */
5101e04c3fSmrgstatic GLuint
5201e04c3fSmrgviewclip_point_xy( const GLfloat v[] )
5301e04c3fSmrg{
5401e04c3fSmrg   if (   v[0] > v[3] || v[0] < -v[3]
5501e04c3fSmrg       || v[1] > v[3] || v[1] < -v[3] ) {
5601e04c3fSmrg      return 0;
5701e04c3fSmrg   }
5801e04c3fSmrg   else {
5901e04c3fSmrg      return 1;
6001e04c3fSmrg   }
6101e04c3fSmrg}
6201e04c3fSmrg
6301e04c3fSmrg
6401e04c3fSmrg/**
6501e04c3fSmrg * Clip a point against the near Z clipping planes.
6601e04c3fSmrg *
6701e04c3fSmrg * \param v vertex vector describing the point to clip.
6801e04c3fSmrg *
6901e04c3fSmrg * \return zero if outside view volume, or one if inside.
7001e04c3fSmrg */
7101e04c3fSmrgstatic GLuint
7201e04c3fSmrgviewclip_point_near_z( const GLfloat v[] )
7301e04c3fSmrg{
7401e04c3fSmrg   if (v[2] < -v[3]) {
7501e04c3fSmrg      return 0;
7601e04c3fSmrg   }
7701e04c3fSmrg   else {
7801e04c3fSmrg      return 1;
7901e04c3fSmrg   }
8001e04c3fSmrg}
8101e04c3fSmrg
8201e04c3fSmrg
8301e04c3fSmrg/**
8401e04c3fSmrg * Clip a point against the far Z clipping planes.
8501e04c3fSmrg *
8601e04c3fSmrg * \param v vertex vector describing the point to clip.
8701e04c3fSmrg *
8801e04c3fSmrg * \return zero if outside view volume, or one if inside.
8901e04c3fSmrg */
9001e04c3fSmrgstatic GLuint
9101e04c3fSmrgviewclip_point_far_z( const GLfloat v[] )
9201e04c3fSmrg{
9301e04c3fSmrg   if (v[2] > v[3]) {
9401e04c3fSmrg      return 0;
9501e04c3fSmrg   }
9601e04c3fSmrg   else {
9701e04c3fSmrg      return 1;
9801e04c3fSmrg   }
9901e04c3fSmrg}
10001e04c3fSmrg
10101e04c3fSmrg
10201e04c3fSmrg/**
10301e04c3fSmrg * Clip a point against the user clipping planes.
10401e04c3fSmrg *
10501e04c3fSmrg * \param ctx GL context.
10601e04c3fSmrg * \param v vertex vector describing the point to clip.
10701e04c3fSmrg *
10801e04c3fSmrg * \return zero if the point was clipped, or one otherwise.
10901e04c3fSmrg */
11001e04c3fSmrgstatic GLuint
11101e04c3fSmrguserclip_point( struct gl_context *ctx, const GLfloat v[] )
11201e04c3fSmrg{
11301e04c3fSmrg   GLbitfield mask = ctx->Transform.ClipPlanesEnabled;
11401e04c3fSmrg   while (mask) {
11501e04c3fSmrg      const int p = u_bit_scan(&mask);
11601e04c3fSmrg      GLfloat dot = v[0] * ctx->Transform._ClipUserPlane[p][0]
11701e04c3fSmrg         + v[1] * ctx->Transform._ClipUserPlane[p][1]
11801e04c3fSmrg         + v[2] * ctx->Transform._ClipUserPlane[p][2]
11901e04c3fSmrg         + v[3] * ctx->Transform._ClipUserPlane[p][3];
12001e04c3fSmrg
12101e04c3fSmrg      if (dot < 0.0F) {
12201e04c3fSmrg         return 0;
12301e04c3fSmrg      }
12401e04c3fSmrg   }
12501e04c3fSmrg
12601e04c3fSmrg   return 1;
12701e04c3fSmrg}
12801e04c3fSmrg
12901e04c3fSmrg
13001e04c3fSmrg/**
13101e04c3fSmrg * Compute lighting for the raster position.  RGB modes computed.
13201e04c3fSmrg * \param ctx the context
13301e04c3fSmrg * \param vertex vertex location
13401e04c3fSmrg * \param normal normal vector
13501e04c3fSmrg * \param Rcolor returned color
13601e04c3fSmrg * \param Rspec returned specular color (if separate specular enabled)
13701e04c3fSmrg */
13801e04c3fSmrgstatic void
13901e04c3fSmrgshade_rastpos(struct gl_context *ctx,
14001e04c3fSmrg              const GLfloat vertex[4],
14101e04c3fSmrg              const GLfloat normal[3],
14201e04c3fSmrg              GLfloat Rcolor[4],
14301e04c3fSmrg              GLfloat Rspec[4])
14401e04c3fSmrg{
14501e04c3fSmrg   /*const*/ GLfloat (*base)[3] = ctx->Light._BaseColor;
14601e04c3fSmrg   GLbitfield mask;
14701e04c3fSmrg   GLfloat diffuseColor[4], specularColor[4];  /* for RGB mode only */
14801e04c3fSmrg
1497ec681f3Smrg   _mesa_update_light_materials(ctx);
1507ec681f3Smrg
15101e04c3fSmrg   COPY_3V(diffuseColor, base[0]);
15201e04c3fSmrg   diffuseColor[3] = CLAMP(
15301e04c3fSmrg      ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3], 0.0F, 1.0F );
15401e04c3fSmrg   ASSIGN_4V(specularColor, 0.0, 0.0, 0.0, 1.0);
15501e04c3fSmrg
15601e04c3fSmrg   mask = ctx->Light._EnabledLights;
15701e04c3fSmrg   while (mask) {
15801e04c3fSmrg      const int i = u_bit_scan(&mask);
15901e04c3fSmrg      struct gl_light *light = &ctx->Light.Light[i];
1607ec681f3Smrg      struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
16101e04c3fSmrg      GLfloat attenuation = 1.0;
16201e04c3fSmrg      GLfloat VP[3]; /* vector from vertex to light pos */
16301e04c3fSmrg      GLfloat n_dot_VP;
16401e04c3fSmrg      GLfloat diffuseContrib[3], specularContrib[3];
16501e04c3fSmrg
16601e04c3fSmrg      if (!(light->_Flags & LIGHT_POSITIONAL)) {
16701e04c3fSmrg         /* light at infinity */
16801e04c3fSmrg	 COPY_3V(VP, light->_VP_inf_norm);
16901e04c3fSmrg	 attenuation = light->_VP_inf_spot_attenuation;
17001e04c3fSmrg      }
17101e04c3fSmrg      else {
17201e04c3fSmrg         /* local/positional light */
17301e04c3fSmrg	 GLfloat d;
17401e04c3fSmrg
17501e04c3fSmrg         /* VP = vector from vertex pos to light[i].pos */
17601e04c3fSmrg	 SUB_3V(VP, light->_Position, vertex);
17701e04c3fSmrg         /* d = length(VP) */
17801e04c3fSmrg	 d = (GLfloat) LEN_3FV( VP );
17901e04c3fSmrg	 if (d > 1.0e-6F) {
18001e04c3fSmrg            /* normalize VP */
18101e04c3fSmrg	    GLfloat invd = 1.0F / d;
18201e04c3fSmrg	    SELF_SCALE_SCALAR_3V(VP, invd);
18301e04c3fSmrg	 }
18401e04c3fSmrg
18501e04c3fSmrg         /* atti */
1867ec681f3Smrg	 attenuation = 1.0F / (lu->ConstantAttenuation + d *
1877ec681f3Smrg			       (lu->LinearAttenuation + d *
1887ec681f3Smrg				lu->QuadraticAttenuation));
18901e04c3fSmrg
19001e04c3fSmrg	 if (light->_Flags & LIGHT_SPOT) {
19101e04c3fSmrg	    GLfloat PV_dot_dir = - DOT3(VP, light->_NormSpotDirection);
19201e04c3fSmrg
1937ec681f3Smrg	    if (PV_dot_dir<lu->_CosCutoff) {
19401e04c3fSmrg	       continue;
19501e04c3fSmrg	    }
19601e04c3fSmrg	    else {
1977ec681f3Smrg               GLfloat spot = powf(PV_dot_dir, lu->SpotExponent);
19801e04c3fSmrg	       attenuation *= spot;
19901e04c3fSmrg	    }
20001e04c3fSmrg	 }
20101e04c3fSmrg      }
20201e04c3fSmrg
20301e04c3fSmrg      if (attenuation < 1e-3F)
20401e04c3fSmrg	 continue;
20501e04c3fSmrg
20601e04c3fSmrg      n_dot_VP = DOT3( normal, VP );
20701e04c3fSmrg
20801e04c3fSmrg      if (n_dot_VP < 0.0F) {
20901e04c3fSmrg	 ACC_SCALE_SCALAR_3V(diffuseColor, attenuation, light->_MatAmbient[0]);
21001e04c3fSmrg	 continue;
21101e04c3fSmrg      }
21201e04c3fSmrg
21301e04c3fSmrg      /* Ambient + diffuse */
21401e04c3fSmrg      COPY_3V(diffuseContrib, light->_MatAmbient[0]);
21501e04c3fSmrg      ACC_SCALE_SCALAR_3V(diffuseContrib, n_dot_VP, light->_MatDiffuse[0]);
21601e04c3fSmrg
21701e04c3fSmrg      /* Specular */
21801e04c3fSmrg      {
21901e04c3fSmrg         const GLfloat *h;
22001e04c3fSmrg         GLfloat n_dot_h;
22101e04c3fSmrg
22201e04c3fSmrg         ASSIGN_3V(specularContrib, 0.0, 0.0, 0.0);
22301e04c3fSmrg
22401e04c3fSmrg	 if (ctx->Light.Model.LocalViewer) {
22501e04c3fSmrg	    GLfloat v[3];
22601e04c3fSmrg	    COPY_3V(v, vertex);
22701e04c3fSmrg	    NORMALIZE_3FV(v);
22801e04c3fSmrg	    SUB_3V(VP, VP, v);
22901e04c3fSmrg            NORMALIZE_3FV(VP);
23001e04c3fSmrg	    h = VP;
23101e04c3fSmrg	 }
23201e04c3fSmrg	 else if (light->_Flags & LIGHT_POSITIONAL) {
23301e04c3fSmrg	    ACC_3V(VP, ctx->_EyeZDir);
23401e04c3fSmrg            NORMALIZE_3FV(VP);
23501e04c3fSmrg	    h = VP;
23601e04c3fSmrg	 }
23701e04c3fSmrg         else {
23801e04c3fSmrg	    h = light->_h_inf_norm;
23901e04c3fSmrg	 }
24001e04c3fSmrg
24101e04c3fSmrg	 n_dot_h = DOT3(normal, h);
24201e04c3fSmrg
24301e04c3fSmrg	 if (n_dot_h > 0.0F) {
24401e04c3fSmrg	    GLfloat shine;
24501e04c3fSmrg	    GLfloat spec_coef;
24601e04c3fSmrg
24701e04c3fSmrg	    shine = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0];
24801e04c3fSmrg	    spec_coef = powf(n_dot_h, shine);
24901e04c3fSmrg
25001e04c3fSmrg	    if (spec_coef > 1.0e-10F) {
25101e04c3fSmrg               if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) {
25201e04c3fSmrg                  ACC_SCALE_SCALAR_3V( specularContrib, spec_coef,
25301e04c3fSmrg                                       light->_MatSpecular[0]);
25401e04c3fSmrg               }
25501e04c3fSmrg               else {
25601e04c3fSmrg                  ACC_SCALE_SCALAR_3V( diffuseContrib, spec_coef,
25701e04c3fSmrg                                       light->_MatSpecular[0]);
25801e04c3fSmrg               }
25901e04c3fSmrg	    }
26001e04c3fSmrg	 }
26101e04c3fSmrg      }
26201e04c3fSmrg
26301e04c3fSmrg      ACC_SCALE_SCALAR_3V( diffuseColor, attenuation, diffuseContrib );
26401e04c3fSmrg      ACC_SCALE_SCALAR_3V( specularColor, attenuation, specularContrib );
26501e04c3fSmrg   }
26601e04c3fSmrg
26701e04c3fSmrg   Rcolor[0] = CLAMP(diffuseColor[0], 0.0F, 1.0F);
26801e04c3fSmrg   Rcolor[1] = CLAMP(diffuseColor[1], 0.0F, 1.0F);
26901e04c3fSmrg   Rcolor[2] = CLAMP(diffuseColor[2], 0.0F, 1.0F);
27001e04c3fSmrg   Rcolor[3] = CLAMP(diffuseColor[3], 0.0F, 1.0F);
27101e04c3fSmrg   Rspec[0] = CLAMP(specularColor[0], 0.0F, 1.0F);
27201e04c3fSmrg   Rspec[1] = CLAMP(specularColor[1], 0.0F, 1.0F);
27301e04c3fSmrg   Rspec[2] = CLAMP(specularColor[2], 0.0F, 1.0F);
27401e04c3fSmrg   Rspec[3] = CLAMP(specularColor[3], 0.0F, 1.0F);
27501e04c3fSmrg}
27601e04c3fSmrg
27701e04c3fSmrg
27801e04c3fSmrg/**
27901e04c3fSmrg * Do texgen needed for glRasterPos.
28001e04c3fSmrg * \param ctx  rendering context
28101e04c3fSmrg * \param vObj  object-space vertex coordinate
28201e04c3fSmrg * \param vEye  eye-space vertex coordinate
28301e04c3fSmrg * \param normal  vertex normal
28401e04c3fSmrg * \param unit  texture unit number
28501e04c3fSmrg * \param texcoord  incoming texcoord and resulting texcoord
28601e04c3fSmrg */
28701e04c3fSmrgstatic void
28801e04c3fSmrgcompute_texgen(struct gl_context *ctx, const GLfloat vObj[4], const GLfloat vEye[4],
28901e04c3fSmrg               const GLfloat normal[3], GLuint unit, GLfloat texcoord[4])
29001e04c3fSmrg{
29101e04c3fSmrg   const struct gl_fixedfunc_texture_unit *texUnit =
29201e04c3fSmrg      &ctx->Texture.FixedFuncUnit[unit];
29301e04c3fSmrg
29401e04c3fSmrg   /* always compute sphere map terms, just in case */
29501e04c3fSmrg   GLfloat u[3], two_nu, rx, ry, rz, m, mInv;
29601e04c3fSmrg   COPY_3V(u, vEye);
29701e04c3fSmrg   NORMALIZE_3FV(u);
29801e04c3fSmrg   two_nu = 2.0F * DOT3(normal, u);
29901e04c3fSmrg   rx = u[0] - normal[0] * two_nu;
30001e04c3fSmrg   ry = u[1] - normal[1] * two_nu;
30101e04c3fSmrg   rz = u[2] - normal[2] * two_nu;
30201e04c3fSmrg   m = rx * rx + ry * ry + (rz + 1.0F) * (rz + 1.0F);
30301e04c3fSmrg   if (m > 0.0F)
30401e04c3fSmrg      mInv = 0.5F * (1.0f / sqrtf(m));
30501e04c3fSmrg   else
30601e04c3fSmrg      mInv = 0.0F;
30701e04c3fSmrg
30801e04c3fSmrg   if (texUnit->TexGenEnabled & S_BIT) {
30901e04c3fSmrg      switch (texUnit->GenS.Mode) {
31001e04c3fSmrg         case GL_OBJECT_LINEAR:
3117ec681f3Smrg            texcoord[0] = DOT4(vObj, texUnit->ObjectPlane[GEN_S]);
31201e04c3fSmrg            break;
31301e04c3fSmrg         case GL_EYE_LINEAR:
3147ec681f3Smrg            texcoord[0] = DOT4(vEye, texUnit->EyePlane[GEN_S]);
31501e04c3fSmrg            break;
31601e04c3fSmrg         case GL_SPHERE_MAP:
31701e04c3fSmrg            texcoord[0] = rx * mInv + 0.5F;
31801e04c3fSmrg            break;
31901e04c3fSmrg         case GL_REFLECTION_MAP:
32001e04c3fSmrg            texcoord[0] = rx;
32101e04c3fSmrg            break;
32201e04c3fSmrg         case GL_NORMAL_MAP:
32301e04c3fSmrg            texcoord[0] = normal[0];
32401e04c3fSmrg            break;
32501e04c3fSmrg         default:
32601e04c3fSmrg            _mesa_problem(ctx, "Bad S texgen in compute_texgen()");
32701e04c3fSmrg            return;
32801e04c3fSmrg      }
32901e04c3fSmrg   }
33001e04c3fSmrg
33101e04c3fSmrg   if (texUnit->TexGenEnabled & T_BIT) {
33201e04c3fSmrg      switch (texUnit->GenT.Mode) {
33301e04c3fSmrg         case GL_OBJECT_LINEAR:
3347ec681f3Smrg            texcoord[1] = DOT4(vObj, texUnit->ObjectPlane[GEN_T]);
33501e04c3fSmrg            break;
33601e04c3fSmrg         case GL_EYE_LINEAR:
3377ec681f3Smrg            texcoord[1] = DOT4(vEye, texUnit->EyePlane[GEN_T]);
33801e04c3fSmrg            break;
33901e04c3fSmrg         case GL_SPHERE_MAP:
34001e04c3fSmrg            texcoord[1] = ry * mInv + 0.5F;
34101e04c3fSmrg            break;
34201e04c3fSmrg         case GL_REFLECTION_MAP:
34301e04c3fSmrg            texcoord[1] = ry;
34401e04c3fSmrg            break;
34501e04c3fSmrg         case GL_NORMAL_MAP:
34601e04c3fSmrg            texcoord[1] = normal[1];
34701e04c3fSmrg            break;
34801e04c3fSmrg         default:
34901e04c3fSmrg            _mesa_problem(ctx, "Bad T texgen in compute_texgen()");
35001e04c3fSmrg            return;
35101e04c3fSmrg      }
35201e04c3fSmrg   }
35301e04c3fSmrg
35401e04c3fSmrg   if (texUnit->TexGenEnabled & R_BIT) {
35501e04c3fSmrg      switch (texUnit->GenR.Mode) {
35601e04c3fSmrg         case GL_OBJECT_LINEAR:
3577ec681f3Smrg            texcoord[2] = DOT4(vObj, texUnit->ObjectPlane[GEN_R]);
35801e04c3fSmrg            break;
35901e04c3fSmrg         case GL_EYE_LINEAR:
3607ec681f3Smrg            texcoord[2] = DOT4(vEye, texUnit->EyePlane[GEN_R]);
36101e04c3fSmrg            break;
36201e04c3fSmrg         case GL_REFLECTION_MAP:
36301e04c3fSmrg            texcoord[2] = rz;
36401e04c3fSmrg            break;
36501e04c3fSmrg         case GL_NORMAL_MAP:
36601e04c3fSmrg            texcoord[2] = normal[2];
36701e04c3fSmrg            break;
36801e04c3fSmrg         default:
36901e04c3fSmrg            _mesa_problem(ctx, "Bad R texgen in compute_texgen()");
37001e04c3fSmrg            return;
37101e04c3fSmrg      }
37201e04c3fSmrg   }
37301e04c3fSmrg
37401e04c3fSmrg   if (texUnit->TexGenEnabled & Q_BIT) {
37501e04c3fSmrg      switch (texUnit->GenQ.Mode) {
37601e04c3fSmrg         case GL_OBJECT_LINEAR:
3777ec681f3Smrg            texcoord[3] = DOT4(vObj, texUnit->ObjectPlane[GEN_Q]);
37801e04c3fSmrg            break;
37901e04c3fSmrg         case GL_EYE_LINEAR:
3807ec681f3Smrg            texcoord[3] = DOT4(vEye, texUnit->EyePlane[GEN_Q]);
38101e04c3fSmrg            break;
38201e04c3fSmrg         default:
38301e04c3fSmrg            _mesa_problem(ctx, "Bad Q texgen in compute_texgen()");
38401e04c3fSmrg            return;
38501e04c3fSmrg      }
38601e04c3fSmrg   }
38701e04c3fSmrg}
38801e04c3fSmrg
38901e04c3fSmrg
39001e04c3fSmrg/**
39101e04c3fSmrg * glRasterPos transformation.  Typically called via ctx->Driver.RasterPos().
39201e04c3fSmrg *
39301e04c3fSmrg * \param vObj  vertex position in object space
39401e04c3fSmrg */
39501e04c3fSmrgvoid
39601e04c3fSmrg_mesa_RasterPos(struct gl_context *ctx, const GLfloat vObj[4])
39701e04c3fSmrg{
3987ec681f3Smrg   ctx->PopAttribState |= GL_CURRENT_BIT;
3997ec681f3Smrg
40001e04c3fSmrg   if (_mesa_arb_vertex_program_enabled(ctx)) {
40101e04c3fSmrg      /* XXX implement this */
40201e04c3fSmrg      _mesa_problem(ctx, "Vertex programs not implemented for glRasterPos");
40301e04c3fSmrg      return;
40401e04c3fSmrg   }
40501e04c3fSmrg   else {
40601e04c3fSmrg      GLfloat eye[4], clip[4], ndc[3], d;
40701e04c3fSmrg      GLfloat *norm, eyenorm[3];
40801e04c3fSmrg      GLfloat *objnorm = ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
40901e04c3fSmrg      float scale[3], translate[3];
41001e04c3fSmrg
41101e04c3fSmrg      /* apply modelview matrix:  eye = MV * obj */
41201e04c3fSmrg      TRANSFORM_POINT( eye, ctx->ModelviewMatrixStack.Top->m, vObj );
41301e04c3fSmrg      /* apply projection matrix:  clip = Proj * eye */
41401e04c3fSmrg      TRANSFORM_POINT( clip, ctx->ProjectionMatrixStack.Top->m, eye );
41501e04c3fSmrg
41601e04c3fSmrg      /* clip to view volume. */
41701e04c3fSmrg      if (!ctx->Transform.DepthClampNear) {
41801e04c3fSmrg         if (viewclip_point_near_z(clip) == 0) {
41901e04c3fSmrg            ctx->Current.RasterPosValid = GL_FALSE;
42001e04c3fSmrg            return;
42101e04c3fSmrg         }
42201e04c3fSmrg      }
42301e04c3fSmrg      if (!ctx->Transform.DepthClampFar) {
42401e04c3fSmrg         if (viewclip_point_far_z(clip) == 0) {
42501e04c3fSmrg            ctx->Current.RasterPosValid = GL_FALSE;
42601e04c3fSmrg            return;
42701e04c3fSmrg         }
42801e04c3fSmrg      }
42901e04c3fSmrg      if (!ctx->Transform.RasterPositionUnclipped) {
43001e04c3fSmrg         if (viewclip_point_xy(clip) == 0) {
43101e04c3fSmrg            ctx->Current.RasterPosValid = GL_FALSE;
43201e04c3fSmrg            return;
43301e04c3fSmrg         }
43401e04c3fSmrg      }
43501e04c3fSmrg
43601e04c3fSmrg      /* clip to user clipping planes */
43701e04c3fSmrg      if (ctx->Transform.ClipPlanesEnabled && !userclip_point(ctx, clip)) {
43801e04c3fSmrg         ctx->Current.RasterPosValid = GL_FALSE;
43901e04c3fSmrg         return;
44001e04c3fSmrg      }
44101e04c3fSmrg
44201e04c3fSmrg      /* ndc = clip / W */
44301e04c3fSmrg      d = (clip[3] == 0.0F) ? 1.0F : 1.0F / clip[3];
44401e04c3fSmrg      ndc[0] = clip[0] * d;
44501e04c3fSmrg      ndc[1] = clip[1] * d;
44601e04c3fSmrg      ndc[2] = clip[2] * d;
44701e04c3fSmrg      /* wincoord = viewport_mapping(ndc) */
44801e04c3fSmrg      _mesa_get_viewport_xform(ctx, 0, scale, translate);
44901e04c3fSmrg      ctx->Current.RasterPos[0] = ndc[0] * scale[0] + translate[0];
45001e04c3fSmrg      ctx->Current.RasterPos[1] = ndc[1] * scale[1] + translate[1];
45101e04c3fSmrg      ctx->Current.RasterPos[2] = ndc[2] * scale[2] + translate[2];
45201e04c3fSmrg      ctx->Current.RasterPos[3] = clip[3];
45301e04c3fSmrg
45401e04c3fSmrg      if (ctx->Transform.DepthClampNear &&
45501e04c3fSmrg          ctx->Transform.DepthClampFar) {
45601e04c3fSmrg         ctx->Current.RasterPos[3] = CLAMP(ctx->Current.RasterPos[3],
45701e04c3fSmrg                                           ctx->ViewportArray[0].Near,
45801e04c3fSmrg                                           ctx->ViewportArray[0].Far);
45901e04c3fSmrg      } else {
46001e04c3fSmrg         /* Clamp against near and far plane separately */
46101e04c3fSmrg         if (ctx->Transform.DepthClampNear) {
46201e04c3fSmrg            ctx->Current.RasterPos[3] = MAX2(ctx->Current.RasterPos[3],
46301e04c3fSmrg                                             ctx->ViewportArray[0].Near);
46401e04c3fSmrg         }
46501e04c3fSmrg
46601e04c3fSmrg         if (ctx->Transform.DepthClampFar) {
46701e04c3fSmrg            ctx->Current.RasterPos[3] = MIN2(ctx->Current.RasterPos[3],
46801e04c3fSmrg                                             ctx->ViewportArray[0].Far);
46901e04c3fSmrg         }
47001e04c3fSmrg      }
47101e04c3fSmrg
47201e04c3fSmrg      /* compute raster distance */
47301e04c3fSmrg      if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
47401e04c3fSmrg         ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
47501e04c3fSmrg      else
47601e04c3fSmrg         ctx->Current.RasterDistance =
47701e04c3fSmrg                        sqrtf( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
47801e04c3fSmrg
47901e04c3fSmrg      /* compute transformed normal vector (for lighting or texgen) */
48001e04c3fSmrg      if (ctx->_NeedEyeCoords) {
48101e04c3fSmrg         const GLfloat *inv = ctx->ModelviewMatrixStack.Top->inv;
48201e04c3fSmrg         TRANSFORM_NORMAL( eyenorm, objnorm, inv );
48301e04c3fSmrg         norm = eyenorm;
48401e04c3fSmrg      }
48501e04c3fSmrg      else {
48601e04c3fSmrg         norm = objnorm;
48701e04c3fSmrg      }
48801e04c3fSmrg
48901e04c3fSmrg      /* update raster color */
49001e04c3fSmrg      if (ctx->Light.Enabled) {
49101e04c3fSmrg         /* lighting */
49201e04c3fSmrg         shade_rastpos( ctx, vObj, norm,
49301e04c3fSmrg                        ctx->Current.RasterColor,
49401e04c3fSmrg                        ctx->Current.RasterSecondaryColor );
49501e04c3fSmrg      }
49601e04c3fSmrg      else {
49701e04c3fSmrg         /* use current color */
49801e04c3fSmrg	 COPY_4FV(ctx->Current.RasterColor,
49901e04c3fSmrg		  ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
50001e04c3fSmrg	 COPY_4FV(ctx->Current.RasterSecondaryColor,
50101e04c3fSmrg		  ctx->Current.Attrib[VERT_ATTRIB_COLOR1]);
50201e04c3fSmrg      }
50301e04c3fSmrg
50401e04c3fSmrg      /* texture coords */
50501e04c3fSmrg      {
50601e04c3fSmrg         GLuint u;
50701e04c3fSmrg         for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) {
50801e04c3fSmrg            GLfloat tc[4];
50901e04c3fSmrg            COPY_4V(tc, ctx->Current.Attrib[VERT_ATTRIB_TEX0 + u]);
51001e04c3fSmrg            if (ctx->Texture.FixedFuncUnit[u].TexGenEnabled) {
51101e04c3fSmrg               compute_texgen(ctx, vObj, eye, norm, u, tc);
51201e04c3fSmrg            }
51301e04c3fSmrg            TRANSFORM_POINT(ctx->Current.RasterTexCoords[u],
51401e04c3fSmrg                            ctx->TextureMatrixStack[u].Top->m, tc);
51501e04c3fSmrg         }
51601e04c3fSmrg      }
51701e04c3fSmrg
51801e04c3fSmrg      ctx->Current.RasterPosValid = GL_TRUE;
51901e04c3fSmrg   }
52001e04c3fSmrg
52101e04c3fSmrg   if (ctx->RenderMode == GL_SELECT) {
52201e04c3fSmrg      _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
52301e04c3fSmrg   }
52401e04c3fSmrg}
5254a49301eSmrg
5264a49301eSmrg
5277117f1b4Smrg/**
528c1f859d4Smrg * Helper function for all the RasterPos functions.
5297117f1b4Smrg */
5307117f1b4Smrgstatic void
531c1f859d4Smrgrasterpos(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
532c1f859d4Smrg{
533c1f859d4Smrg   GET_CURRENT_CONTEXT(ctx);
534c1f859d4Smrg   GLfloat p[4];
5357117f1b4Smrg
536c1f859d4Smrg   p[0] = x;
537c1f859d4Smrg   p[1] = y;
538c1f859d4Smrg   p[2] = z;
539c1f859d4Smrg   p[3] = w;
5407117f1b4Smrg
5417ec681f3Smrg   FLUSH_VERTICES(ctx, 0, 0);
5427117f1b4Smrg   FLUSH_CURRENT(ctx, 0);
5437117f1b4Smrg
5447117f1b4Smrg   if (ctx->NewState)
5457117f1b4Smrg      _mesa_update_state( ctx );
5467117f1b4Smrg
547c1f859d4Smrg   ctx->Driver.RasterPos(ctx, p);
5487117f1b4Smrg}
5497117f1b4Smrg
5507117f1b4Smrg
551af69d88dSmrgvoid GLAPIENTRY
5527117f1b4Smrg_mesa_RasterPos2d(GLdouble x, GLdouble y)
5537117f1b4Smrg{
554c1f859d4Smrg   rasterpos((GLfloat)x, (GLfloat)y, (GLfloat)0.0, (GLfloat)1.0);
5557117f1b4Smrg}
5567117f1b4Smrg
557af69d88dSmrgvoid GLAPIENTRY
5587117f1b4Smrg_mesa_RasterPos2f(GLfloat x, GLfloat y)
5597117f1b4Smrg{
560c1f859d4Smrg   rasterpos(x, y, 0.0F, 1.0F);
5617117f1b4Smrg}
5627117f1b4Smrg
563af69d88dSmrgvoid GLAPIENTRY
5647117f1b4Smrg_mesa_RasterPos2i(GLint x, GLint y)
5657117f1b4Smrg{
566c1f859d4Smrg   rasterpos((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
5677117f1b4Smrg}
5687117f1b4Smrg
569af69d88dSmrgvoid GLAPIENTRY
5707117f1b4Smrg_mesa_RasterPos2s(GLshort x, GLshort y)
5717117f1b4Smrg{
572c1f859d4Smrg   rasterpos(x, y, 0.0F, 1.0F);
5737117f1b4Smrg}
5747117f1b4Smrg
575af69d88dSmrgvoid GLAPIENTRY
5767117f1b4Smrg_mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
5777117f1b4Smrg{
578c1f859d4Smrg   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
5797117f1b4Smrg}
5807117f1b4Smrg
581af69d88dSmrgvoid GLAPIENTRY
5827117f1b4Smrg_mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
5837117f1b4Smrg{
584c1f859d4Smrg   rasterpos(x, y, z, 1.0F);
5857117f1b4Smrg}
5867117f1b4Smrg
587af69d88dSmrgvoid GLAPIENTRY
5887117f1b4Smrg_mesa_RasterPos3i(GLint x, GLint y, GLint z)
5897117f1b4Smrg{
590c1f859d4Smrg   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
5917117f1b4Smrg}
5927117f1b4Smrg
593af69d88dSmrgvoid GLAPIENTRY
5947117f1b4Smrg_mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
5957117f1b4Smrg{
596c1f859d4Smrg   rasterpos(x, y, z, 1.0F);
5977117f1b4Smrg}
5987117f1b4Smrg
599af69d88dSmrgvoid GLAPIENTRY
6007117f1b4Smrg_mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
6017117f1b4Smrg{
602c1f859d4Smrg   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
6037117f1b4Smrg}
6047117f1b4Smrg
605af69d88dSmrgvoid GLAPIENTRY
6067117f1b4Smrg_mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6077117f1b4Smrg{
608c1f859d4Smrg   rasterpos(x, y, z, w);
6097117f1b4Smrg}
6107117f1b4Smrg
611af69d88dSmrgvoid GLAPIENTRY
6127117f1b4Smrg_mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
6137117f1b4Smrg{
614c1f859d4Smrg   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
6157117f1b4Smrg}
6167117f1b4Smrg
617af69d88dSmrgvoid GLAPIENTRY
6187117f1b4Smrg_mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
6197117f1b4Smrg{
620c1f859d4Smrg   rasterpos(x, y, z, w);
6217117f1b4Smrg}
6227117f1b4Smrg
623af69d88dSmrgvoid GLAPIENTRY
6247117f1b4Smrg_mesa_RasterPos2dv(const GLdouble *v)
6257117f1b4Smrg{
626c1f859d4Smrg   rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
6277117f1b4Smrg}
6287117f1b4Smrg
629af69d88dSmrgvoid GLAPIENTRY
6307117f1b4Smrg_mesa_RasterPos2fv(const GLfloat *v)
6317117f1b4Smrg{
632c1f859d4Smrg   rasterpos(v[0], v[1], 0.0F, 1.0F);
6337117f1b4Smrg}
6347117f1b4Smrg
635af69d88dSmrgvoid GLAPIENTRY
6367117f1b4Smrg_mesa_RasterPos2iv(const GLint *v)
6377117f1b4Smrg{
638c1f859d4Smrg   rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
6397117f1b4Smrg}
6407117f1b4Smrg
641af69d88dSmrgvoid GLAPIENTRY
6427117f1b4Smrg_mesa_RasterPos2sv(const GLshort *v)
6437117f1b4Smrg{
644c1f859d4Smrg   rasterpos(v[0], v[1], 0.0F, 1.0F);
6457117f1b4Smrg}
6467117f1b4Smrg
647af69d88dSmrgvoid GLAPIENTRY
6487117f1b4Smrg_mesa_RasterPos3dv(const GLdouble *v)
6497117f1b4Smrg{
650c1f859d4Smrg   rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
6517117f1b4Smrg}
6527117f1b4Smrg
653af69d88dSmrgvoid GLAPIENTRY
6547117f1b4Smrg_mesa_RasterPos3fv(const GLfloat *v)
6557117f1b4Smrg{
656c1f859d4Smrg   rasterpos(v[0], v[1], v[2], 1.0F);
6577117f1b4Smrg}
6587117f1b4Smrg
659af69d88dSmrgvoid GLAPIENTRY
6607117f1b4Smrg_mesa_RasterPos3iv(const GLint *v)
6617117f1b4Smrg{
662c1f859d4Smrg   rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
6637117f1b4Smrg}
6647117f1b4Smrg
665af69d88dSmrgvoid GLAPIENTRY
6667117f1b4Smrg_mesa_RasterPos3sv(const GLshort *v)
6677117f1b4Smrg{
668c1f859d4Smrg   rasterpos(v[0], v[1], v[2], 1.0F);
6697117f1b4Smrg}
6707117f1b4Smrg
671af69d88dSmrgvoid GLAPIENTRY
6727117f1b4Smrg_mesa_RasterPos4dv(const GLdouble *v)
6737117f1b4Smrg{
674c1f859d4Smrg   rasterpos((GLfloat) v[0], (GLfloat) v[1],
6757117f1b4Smrg		     (GLfloat) v[2], (GLfloat) v[3]);
6767117f1b4Smrg}
6777117f1b4Smrg
678af69d88dSmrgvoid GLAPIENTRY
6797117f1b4Smrg_mesa_RasterPos4fv(const GLfloat *v)
6807117f1b4Smrg{
681c1f859d4Smrg   rasterpos(v[0], v[1], v[2], v[3]);
6827117f1b4Smrg}
6837117f1b4Smrg
684af69d88dSmrgvoid GLAPIENTRY
6857117f1b4Smrg_mesa_RasterPos4iv(const GLint *v)
6867117f1b4Smrg{
687c1f859d4Smrg   rasterpos((GLfloat) v[0], (GLfloat) v[1],
6887117f1b4Smrg		     (GLfloat) v[2], (GLfloat) v[3]);
6897117f1b4Smrg}
6907117f1b4Smrg
691af69d88dSmrgvoid GLAPIENTRY
6927117f1b4Smrg_mesa_RasterPos4sv(const GLshort *v)
6937117f1b4Smrg{
694c1f859d4Smrg   rasterpos(v[0], v[1], v[2], v[3]);
6957117f1b4Smrg}
6967117f1b4Smrg
6977117f1b4Smrg
6987117f1b4Smrg/**********************************************************************/
6997117f1b4Smrg/***           GL_ARB_window_pos / GL_MESA_window_pos               ***/
7007117f1b4Smrg/**********************************************************************/
7017117f1b4Smrg
7024a49301eSmrg
7037117f1b4Smrg/**
7047117f1b4Smrg * All glWindowPosMESA and glWindowPosARB commands call this function to
7057117f1b4Smrg * update the current raster position.
7067117f1b4Smrg */
7077117f1b4Smrgstatic void
7087117f1b4Smrgwindow_pos3f(GLfloat x, GLfloat y, GLfloat z)
7097117f1b4Smrg{
7107117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
7117117f1b4Smrg   GLfloat z2;
7127117f1b4Smrg
7137ec681f3Smrg   FLUSH_VERTICES(ctx, 0, GL_CURRENT_BIT);
7147117f1b4Smrg   FLUSH_CURRENT(ctx, 0);
7157117f1b4Smrg
716af69d88dSmrg   z2 = CLAMP(z, 0.0F, 1.0F)
717af69d88dSmrg      * (ctx->ViewportArray[0].Far - ctx->ViewportArray[0].Near)
718af69d88dSmrg      + ctx->ViewportArray[0].Near;
7197117f1b4Smrg
7207117f1b4Smrg   /* set raster position */
7217117f1b4Smrg   ctx->Current.RasterPos[0] = x;
7227117f1b4Smrg   ctx->Current.RasterPos[1] = y;
7237117f1b4Smrg   ctx->Current.RasterPos[2] = z2;
7247117f1b4Smrg   ctx->Current.RasterPos[3] = 1.0F;
7257117f1b4Smrg
7267117f1b4Smrg   ctx->Current.RasterPosValid = GL_TRUE;
7277117f1b4Smrg
7287117f1b4Smrg   if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
7297117f1b4Smrg      ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
7307117f1b4Smrg   else
7317117f1b4Smrg      ctx->Current.RasterDistance = 0.0;
7327117f1b4Smrg
7337117f1b4Smrg   /* raster color = current color or index */
734cdc920a0Smrg   ctx->Current.RasterColor[0]
735cdc920a0Smrg      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0], 0.0F, 1.0F);
736cdc920a0Smrg   ctx->Current.RasterColor[1]
737cdc920a0Smrg      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][1], 0.0F, 1.0F);
738cdc920a0Smrg   ctx->Current.RasterColor[2]
739cdc920a0Smrg      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][2], 0.0F, 1.0F);
740cdc920a0Smrg   ctx->Current.RasterColor[3]
741cdc920a0Smrg      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3], 0.0F, 1.0F);
742cdc920a0Smrg   ctx->Current.RasterSecondaryColor[0]
743cdc920a0Smrg      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0], 0.0F, 1.0F);
744cdc920a0Smrg   ctx->Current.RasterSecondaryColor[1]
745cdc920a0Smrg      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1], 0.0F, 1.0F);
746cdc920a0Smrg   ctx->Current.RasterSecondaryColor[2]
747cdc920a0Smrg      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][2], 0.0F, 1.0F);
748cdc920a0Smrg   ctx->Current.RasterSecondaryColor[3]
749cdc920a0Smrg      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][3], 0.0F, 1.0F);
7507117f1b4Smrg
7517117f1b4Smrg   /* raster texcoord = current texcoord */
7527117f1b4Smrg   {
7537117f1b4Smrg      GLuint texSet;
7547117f1b4Smrg      for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) {
75501e04c3fSmrg         assert(texSet < ARRAY_SIZE(ctx->Current.RasterTexCoords));
7567117f1b4Smrg         COPY_4FV( ctx->Current.RasterTexCoords[texSet],
7577117f1b4Smrg                  ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] );
7587117f1b4Smrg      }
7597117f1b4Smrg   }
7607117f1b4Smrg
7617117f1b4Smrg   if (ctx->RenderMode==GL_SELECT) {
7627117f1b4Smrg      _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
7637117f1b4Smrg   }
7647117f1b4Smrg}
7657117f1b4Smrg
7667117f1b4Smrg
7677117f1b4Smrg/* This is just to support the GL_MESA_window_pos version */
7687117f1b4Smrgstatic void
7697117f1b4Smrgwindow_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7707117f1b4Smrg{
7717117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
7727117f1b4Smrg   window_pos3f(x, y, z);
7737117f1b4Smrg   ctx->Current.RasterPos[3] = w;
7747117f1b4Smrg}
7757117f1b4Smrg
7767117f1b4Smrg
777af69d88dSmrgvoid GLAPIENTRY
778af69d88dSmrg_mesa_WindowPos2d(GLdouble x, GLdouble y)
7797117f1b4Smrg{
7807117f1b4Smrg   window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
7817117f1b4Smrg}
7827117f1b4Smrg
783af69d88dSmrgvoid GLAPIENTRY
784af69d88dSmrg_mesa_WindowPos2f(GLfloat x, GLfloat y)
7857117f1b4Smrg{
7867117f1b4Smrg   window_pos4f(x, y, 0.0F, 1.0F);
7877117f1b4Smrg}
7887117f1b4Smrg
789af69d88dSmrgvoid GLAPIENTRY
790af69d88dSmrg_mesa_WindowPos2i(GLint x, GLint y)
7917117f1b4Smrg{
7927117f1b4Smrg   window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
7937117f1b4Smrg}
7947117f1b4Smrg
795af69d88dSmrgvoid GLAPIENTRY
796af69d88dSmrg_mesa_WindowPos2s(GLshort x, GLshort y)
7977117f1b4Smrg{
7987117f1b4Smrg   window_pos4f(x, y, 0.0F, 1.0F);
7997117f1b4Smrg}
8007117f1b4Smrg
801af69d88dSmrgvoid GLAPIENTRY
802af69d88dSmrg_mesa_WindowPos3d(GLdouble x, GLdouble y, GLdouble z)
8037117f1b4Smrg{
8047117f1b4Smrg   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
8057117f1b4Smrg}
8067117f1b4Smrg
807af69d88dSmrgvoid GLAPIENTRY
808af69d88dSmrg_mesa_WindowPos3f(GLfloat x, GLfloat y, GLfloat z)
8097117f1b4Smrg{
8107117f1b4Smrg   window_pos4f(x, y, z, 1.0F);
8117117f1b4Smrg}
8127117f1b4Smrg
813af69d88dSmrgvoid GLAPIENTRY
814af69d88dSmrg_mesa_WindowPos3i(GLint x, GLint y, GLint z)
8157117f1b4Smrg{
8167117f1b4Smrg   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
8177117f1b4Smrg}
8187117f1b4Smrg
819af69d88dSmrgvoid GLAPIENTRY
820af69d88dSmrg_mesa_WindowPos3s(GLshort x, GLshort y, GLshort z)
8217117f1b4Smrg{
8227117f1b4Smrg   window_pos4f(x, y, z, 1.0F);
8237117f1b4Smrg}
8247117f1b4Smrg
825af69d88dSmrgvoid GLAPIENTRY
8267117f1b4Smrg_mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
8277117f1b4Smrg{
8287117f1b4Smrg   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
8297117f1b4Smrg}
8307117f1b4Smrg
831af69d88dSmrgvoid GLAPIENTRY
8327117f1b4Smrg_mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8337117f1b4Smrg{
8347117f1b4Smrg   window_pos4f(x, y, z, w);
8357117f1b4Smrg}
8367117f1b4Smrg
837af69d88dSmrgvoid GLAPIENTRY
8387117f1b4Smrg_mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
8397117f1b4Smrg{
8407117f1b4Smrg   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
8417117f1b4Smrg}
8427117f1b4Smrg
843af69d88dSmrgvoid GLAPIENTRY
8447117f1b4Smrg_mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
8457117f1b4Smrg{
8467117f1b4Smrg   window_pos4f(x, y, z, w);
8477117f1b4Smrg}
8487117f1b4Smrg
849af69d88dSmrgvoid GLAPIENTRY
850af69d88dSmrg_mesa_WindowPos2dv(const GLdouble *v)
8517117f1b4Smrg{
8527117f1b4Smrg   window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
8537117f1b4Smrg}
8547117f1b4Smrg
855af69d88dSmrgvoid GLAPIENTRY
856af69d88dSmrg_mesa_WindowPos2fv(const GLfloat *v)
8577117f1b4Smrg{
8587117f1b4Smrg   window_pos4f(v[0], v[1], 0.0F, 1.0F);
8597117f1b4Smrg}
8607117f1b4Smrg
861af69d88dSmrgvoid GLAPIENTRY
862af69d88dSmrg_mesa_WindowPos2iv(const GLint *v)
8637117f1b4Smrg{
8647117f1b4Smrg   window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
8657117f1b4Smrg}
8667117f1b4Smrg
867af69d88dSmrgvoid GLAPIENTRY
868af69d88dSmrg_mesa_WindowPos2sv(const GLshort *v)
8697117f1b4Smrg{
8707117f1b4Smrg   window_pos4f(v[0], v[1], 0.0F, 1.0F);
8717117f1b4Smrg}
8727117f1b4Smrg
873af69d88dSmrgvoid GLAPIENTRY
874af69d88dSmrg_mesa_WindowPos3dv(const GLdouble *v)
8757117f1b4Smrg{
8767117f1b4Smrg   window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
8777117f1b4Smrg}
8787117f1b4Smrg
879af69d88dSmrgvoid GLAPIENTRY
880af69d88dSmrg_mesa_WindowPos3fv(const GLfloat *v)
8817117f1b4Smrg{
8827117f1b4Smrg   window_pos4f(v[0], v[1], v[2], 1.0);
8837117f1b4Smrg}
8847117f1b4Smrg
885af69d88dSmrgvoid GLAPIENTRY
886af69d88dSmrg_mesa_WindowPos3iv(const GLint *v)
8877117f1b4Smrg{
8887117f1b4Smrg   window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
8897117f1b4Smrg}
8907117f1b4Smrg
891af69d88dSmrgvoid GLAPIENTRY
892af69d88dSmrg_mesa_WindowPos3sv(const GLshort *v)
8937117f1b4Smrg{
8947117f1b4Smrg   window_pos4f(v[0], v[1], v[2], 1.0F);
8957117f1b4Smrg}
8967117f1b4Smrg
897af69d88dSmrgvoid GLAPIENTRY
8987117f1b4Smrg_mesa_WindowPos4dvMESA(const GLdouble *v)
8997117f1b4Smrg{
9007117f1b4Smrg   window_pos4f((GLfloat) v[0], (GLfloat) v[1],
9017117f1b4Smrg			 (GLfloat) v[2], (GLfloat) v[3]);
9027117f1b4Smrg}
9037117f1b4Smrg
904af69d88dSmrgvoid GLAPIENTRY
9057117f1b4Smrg_mesa_WindowPos4fvMESA(const GLfloat *v)
9067117f1b4Smrg{
9077117f1b4Smrg   window_pos4f(v[0], v[1], v[2], v[3]);
9087117f1b4Smrg}
9097117f1b4Smrg
910af69d88dSmrgvoid GLAPIENTRY
9117117f1b4Smrg_mesa_WindowPos4ivMESA(const GLint *v)
9127117f1b4Smrg{
9137117f1b4Smrg   window_pos4f((GLfloat) v[0], (GLfloat) v[1],
9147117f1b4Smrg			 (GLfloat) v[2], (GLfloat) v[3]);
9157117f1b4Smrg}
9167117f1b4Smrg
917af69d88dSmrgvoid GLAPIENTRY
9187117f1b4Smrg_mesa_WindowPos4svMESA(const GLshort *v)
9197117f1b4Smrg{
9207117f1b4Smrg   window_pos4f(v[0], v[1], v[2], v[3]);
9217117f1b4Smrg}
9227117f1b4Smrg
9237117f1b4Smrg
9247117f1b4Smrg#if 0
9257117f1b4Smrg
9267117f1b4Smrg/*
9277117f1b4Smrg * OpenGL implementation of glWindowPos*MESA()
9287117f1b4Smrg */
9297117f1b4Smrgvoid glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
9307117f1b4Smrg{
9317117f1b4Smrg   GLfloat fx, fy;
9327117f1b4Smrg
9337117f1b4Smrg   /* Push current matrix mode and viewport attributes */
9347117f1b4Smrg   glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
9357117f1b4Smrg
9367117f1b4Smrg   /* Setup projection parameters */
9377117f1b4Smrg   glMatrixMode( GL_PROJECTION );
9387117f1b4Smrg   glPushMatrix();
9397117f1b4Smrg   glLoadIdentity();
9407117f1b4Smrg   glMatrixMode( GL_MODELVIEW );
9417117f1b4Smrg   glPushMatrix();
9427117f1b4Smrg   glLoadIdentity();
9437117f1b4Smrg
9447117f1b4Smrg   glDepthRange( z, z );
9457117f1b4Smrg   glViewport( (int) x - 1, (int) y - 1, 2, 2 );
9467117f1b4Smrg
9477117f1b4Smrg   /* set the raster (window) position */
9487117f1b4Smrg   fx = x - (int) x;
9497117f1b4Smrg   fy = y - (int) y;
9507117f1b4Smrg   glRasterPos4f( fx, fy, 0.0, w );
9517117f1b4Smrg
9527117f1b4Smrg   /* restore matrices, viewport and matrix mode */
9537117f1b4Smrg   glPopMatrix();
9547117f1b4Smrg   glMatrixMode( GL_PROJECTION );
9557117f1b4Smrg   glPopMatrix();
9567117f1b4Smrg
9577117f1b4Smrg   glPopAttrib();
9587117f1b4Smrg}
9597117f1b4Smrg
9607117f1b4Smrg#endif
9617117f1b4Smrg
9627117f1b4Smrg
9637117f1b4Smrg/**********************************************************************/
9647117f1b4Smrg/** \name Initialization                                              */
9657117f1b4Smrg/**********************************************************************/
9667117f1b4Smrg/*@{*/
9677117f1b4Smrg
9687117f1b4Smrg/**
9697117f1b4Smrg * Initialize the context current raster position information.
9707117f1b4Smrg *
9717117f1b4Smrg * \param ctx GL context.
9727117f1b4Smrg *
9737117f1b4Smrg * Initialize the current raster position information in
9743464ebd5Sriastradh * __struct gl_contextRec::Current, and adds the extension entry points to the
9757117f1b4Smrg * dispatcher.
9767117f1b4Smrg */
9773464ebd5Sriastradhvoid _mesa_init_rastpos( struct gl_context * ctx )
9787117f1b4Smrg{
97901e04c3fSmrg   unsigned i;
9807117f1b4Smrg
9817117f1b4Smrg   ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
9827117f1b4Smrg   ctx->Current.RasterDistance = 0.0;
9837117f1b4Smrg   ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
9847117f1b4Smrg   ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 );
98501e04c3fSmrg   for (i = 0; i < ARRAY_SIZE(ctx->Current.RasterTexCoords); i++)
9867117f1b4Smrg      ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
9877117f1b4Smrg   ctx->Current.RasterPosValid = GL_TRUE;
9887117f1b4Smrg}
9897117f1b4Smrg
9907117f1b4Smrg/*@}*/
991