1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Mesa 3-D graphics library
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci/**
27bf215546Sopenharmony_ci * \file rastpos.c
28bf215546Sopenharmony_ci * Raster position operations.
29bf215546Sopenharmony_ci */
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "glheader.h"
32bf215546Sopenharmony_ci#include "context.h"
33bf215546Sopenharmony_ci#include "feedback.h"
34bf215546Sopenharmony_ci#include "macros.h"
35bf215546Sopenharmony_ci#include "mtypes.h"
36bf215546Sopenharmony_ci#include "rastpos.h"
37bf215546Sopenharmony_ci#include "state.h"
38bf215546Sopenharmony_ci#include "main/light.h"
39bf215546Sopenharmony_ci#include "main/viewport.h"
40bf215546Sopenharmony_ci#include "util/bitscan.h"
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci#include "state_tracker/st_cb_rasterpos.h"
43bf215546Sopenharmony_ci#include "api_exec_decl.h"
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci/**
47bf215546Sopenharmony_ci * Clip a point against the view volume.
48bf215546Sopenharmony_ci *
49bf215546Sopenharmony_ci * \param v vertex vector describing the point to clip.
50bf215546Sopenharmony_ci *
51bf215546Sopenharmony_ci * \return zero if outside view volume, or one if inside.
52bf215546Sopenharmony_ci */
53bf215546Sopenharmony_cistatic GLuint
54bf215546Sopenharmony_civiewclip_point_xy( const GLfloat v[] )
55bf215546Sopenharmony_ci{
56bf215546Sopenharmony_ci   if (   v[0] > v[3] || v[0] < -v[3]
57bf215546Sopenharmony_ci       || v[1] > v[3] || v[1] < -v[3] ) {
58bf215546Sopenharmony_ci      return 0;
59bf215546Sopenharmony_ci   }
60bf215546Sopenharmony_ci   else {
61bf215546Sopenharmony_ci      return 1;
62bf215546Sopenharmony_ci   }
63bf215546Sopenharmony_ci}
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci/**
67bf215546Sopenharmony_ci * Clip a point against the near Z clipping planes.
68bf215546Sopenharmony_ci *
69bf215546Sopenharmony_ci * \param v vertex vector describing the point to clip.
70bf215546Sopenharmony_ci *
71bf215546Sopenharmony_ci * \return zero if outside view volume, or one if inside.
72bf215546Sopenharmony_ci */
73bf215546Sopenharmony_cistatic GLuint
74bf215546Sopenharmony_civiewclip_point_near_z( const GLfloat v[] )
75bf215546Sopenharmony_ci{
76bf215546Sopenharmony_ci   if (v[2] < -v[3]) {
77bf215546Sopenharmony_ci      return 0;
78bf215546Sopenharmony_ci   }
79bf215546Sopenharmony_ci   else {
80bf215546Sopenharmony_ci      return 1;
81bf215546Sopenharmony_ci   }
82bf215546Sopenharmony_ci}
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci/**
86bf215546Sopenharmony_ci * Clip a point against the far Z clipping planes.
87bf215546Sopenharmony_ci *
88bf215546Sopenharmony_ci * \param v vertex vector describing the point to clip.
89bf215546Sopenharmony_ci *
90bf215546Sopenharmony_ci * \return zero if outside view volume, or one if inside.
91bf215546Sopenharmony_ci */
92bf215546Sopenharmony_cistatic GLuint
93bf215546Sopenharmony_civiewclip_point_far_z( const GLfloat v[] )
94bf215546Sopenharmony_ci{
95bf215546Sopenharmony_ci   if (v[2] > v[3]) {
96bf215546Sopenharmony_ci      return 0;
97bf215546Sopenharmony_ci   }
98bf215546Sopenharmony_ci   else {
99bf215546Sopenharmony_ci      return 1;
100bf215546Sopenharmony_ci   }
101bf215546Sopenharmony_ci}
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci/**
105bf215546Sopenharmony_ci * Clip a point against the user clipping planes.
106bf215546Sopenharmony_ci *
107bf215546Sopenharmony_ci * \param ctx GL context.
108bf215546Sopenharmony_ci * \param v vertex vector describing the point to clip.
109bf215546Sopenharmony_ci *
110bf215546Sopenharmony_ci * \return zero if the point was clipped, or one otherwise.
111bf215546Sopenharmony_ci */
112bf215546Sopenharmony_cistatic GLuint
113bf215546Sopenharmony_ciuserclip_point( struct gl_context *ctx, const GLfloat v[] )
114bf215546Sopenharmony_ci{
115bf215546Sopenharmony_ci   GLbitfield mask = ctx->Transform.ClipPlanesEnabled;
116bf215546Sopenharmony_ci   while (mask) {
117bf215546Sopenharmony_ci      const int p = u_bit_scan(&mask);
118bf215546Sopenharmony_ci      GLfloat dot = v[0] * ctx->Transform._ClipUserPlane[p][0]
119bf215546Sopenharmony_ci         + v[1] * ctx->Transform._ClipUserPlane[p][1]
120bf215546Sopenharmony_ci         + v[2] * ctx->Transform._ClipUserPlane[p][2]
121bf215546Sopenharmony_ci         + v[3] * ctx->Transform._ClipUserPlane[p][3];
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci      if (dot < 0.0F) {
124bf215546Sopenharmony_ci         return 0;
125bf215546Sopenharmony_ci      }
126bf215546Sopenharmony_ci   }
127bf215546Sopenharmony_ci
128bf215546Sopenharmony_ci   return 1;
129bf215546Sopenharmony_ci}
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci/**
133bf215546Sopenharmony_ci * Compute lighting for the raster position.  RGB modes computed.
134bf215546Sopenharmony_ci * \param ctx the context
135bf215546Sopenharmony_ci * \param vertex vertex location
136bf215546Sopenharmony_ci * \param normal normal vector
137bf215546Sopenharmony_ci * \param Rcolor returned color
138bf215546Sopenharmony_ci * \param Rspec returned specular color (if separate specular enabled)
139bf215546Sopenharmony_ci */
140bf215546Sopenharmony_cistatic void
141bf215546Sopenharmony_cishade_rastpos(struct gl_context *ctx,
142bf215546Sopenharmony_ci              const GLfloat vertex[4],
143bf215546Sopenharmony_ci              const GLfloat normal[3],
144bf215546Sopenharmony_ci              GLfloat Rcolor[4],
145bf215546Sopenharmony_ci              GLfloat Rspec[4])
146bf215546Sopenharmony_ci{
147bf215546Sopenharmony_ci   /*const*/ GLfloat (*base)[3] = ctx->Light._BaseColor;
148bf215546Sopenharmony_ci   GLbitfield mask;
149bf215546Sopenharmony_ci   GLfloat diffuseColor[4], specularColor[4];  /* for RGB mode only */
150bf215546Sopenharmony_ci
151bf215546Sopenharmony_ci   _mesa_update_light_materials(ctx);
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_ci   COPY_3V(diffuseColor, base[0]);
154bf215546Sopenharmony_ci   diffuseColor[3] = CLAMP(
155bf215546Sopenharmony_ci      ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3], 0.0F, 1.0F );
156bf215546Sopenharmony_ci   ASSIGN_4V(specularColor, 0.0, 0.0, 0.0, 1.0);
157bf215546Sopenharmony_ci
158bf215546Sopenharmony_ci   mask = ctx->Light._EnabledLights;
159bf215546Sopenharmony_ci   while (mask) {
160bf215546Sopenharmony_ci      const int i = u_bit_scan(&mask);
161bf215546Sopenharmony_ci      struct gl_light *light = &ctx->Light.Light[i];
162bf215546Sopenharmony_ci      struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
163bf215546Sopenharmony_ci      GLfloat attenuation = 1.0;
164bf215546Sopenharmony_ci      GLfloat VP[3]; /* vector from vertex to light pos */
165bf215546Sopenharmony_ci      GLfloat n_dot_VP;
166bf215546Sopenharmony_ci      GLfloat diffuseContrib[3], specularContrib[3];
167bf215546Sopenharmony_ci
168bf215546Sopenharmony_ci      if (!(light->_Flags & LIGHT_POSITIONAL)) {
169bf215546Sopenharmony_ci         /* light at infinity */
170bf215546Sopenharmony_ci	 COPY_3V(VP, light->_VP_inf_norm);
171bf215546Sopenharmony_ci	 attenuation = light->_VP_inf_spot_attenuation;
172bf215546Sopenharmony_ci      }
173bf215546Sopenharmony_ci      else {
174bf215546Sopenharmony_ci         /* local/positional light */
175bf215546Sopenharmony_ci	 GLfloat d;
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci         /* VP = vector from vertex pos to light[i].pos */
178bf215546Sopenharmony_ci	 SUB_3V(VP, light->_Position, vertex);
179bf215546Sopenharmony_ci         /* d = length(VP) */
180bf215546Sopenharmony_ci	 d = (GLfloat) LEN_3FV( VP );
181bf215546Sopenharmony_ci	 if (d > 1.0e-6F) {
182bf215546Sopenharmony_ci            /* normalize VP */
183bf215546Sopenharmony_ci	    GLfloat invd = 1.0F / d;
184bf215546Sopenharmony_ci	    SELF_SCALE_SCALAR_3V(VP, invd);
185bf215546Sopenharmony_ci	 }
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_ci         /* atti */
188bf215546Sopenharmony_ci	 attenuation = 1.0F / (lu->ConstantAttenuation + d *
189bf215546Sopenharmony_ci			       (lu->LinearAttenuation + d *
190bf215546Sopenharmony_ci				lu->QuadraticAttenuation));
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_ci	 if (light->_Flags & LIGHT_SPOT) {
193bf215546Sopenharmony_ci	    GLfloat PV_dot_dir = - DOT3(VP, light->_NormSpotDirection);
194bf215546Sopenharmony_ci
195bf215546Sopenharmony_ci	    if (PV_dot_dir<lu->_CosCutoff) {
196bf215546Sopenharmony_ci	       continue;
197bf215546Sopenharmony_ci	    }
198bf215546Sopenharmony_ci	    else {
199bf215546Sopenharmony_ci               GLfloat spot = powf(PV_dot_dir, lu->SpotExponent);
200bf215546Sopenharmony_ci	       attenuation *= spot;
201bf215546Sopenharmony_ci	    }
202bf215546Sopenharmony_ci	 }
203bf215546Sopenharmony_ci      }
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci      if (attenuation < 1e-3F)
206bf215546Sopenharmony_ci	 continue;
207bf215546Sopenharmony_ci
208bf215546Sopenharmony_ci      n_dot_VP = DOT3( normal, VP );
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_ci      if (n_dot_VP < 0.0F) {
211bf215546Sopenharmony_ci	 ACC_SCALE_SCALAR_3V(diffuseColor, attenuation, light->_MatAmbient[0]);
212bf215546Sopenharmony_ci	 continue;
213bf215546Sopenharmony_ci      }
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_ci      /* Ambient + diffuse */
216bf215546Sopenharmony_ci      COPY_3V(diffuseContrib, light->_MatAmbient[0]);
217bf215546Sopenharmony_ci      ACC_SCALE_SCALAR_3V(diffuseContrib, n_dot_VP, light->_MatDiffuse[0]);
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci      /* Specular */
220bf215546Sopenharmony_ci      {
221bf215546Sopenharmony_ci         const GLfloat *h;
222bf215546Sopenharmony_ci         GLfloat n_dot_h;
223bf215546Sopenharmony_ci
224bf215546Sopenharmony_ci         ASSIGN_3V(specularContrib, 0.0, 0.0, 0.0);
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_ci	 if (ctx->Light.Model.LocalViewer) {
227bf215546Sopenharmony_ci	    GLfloat v[3];
228bf215546Sopenharmony_ci	    COPY_3V(v, vertex);
229bf215546Sopenharmony_ci	    NORMALIZE_3FV(v);
230bf215546Sopenharmony_ci	    SUB_3V(VP, VP, v);
231bf215546Sopenharmony_ci            NORMALIZE_3FV(VP);
232bf215546Sopenharmony_ci	    h = VP;
233bf215546Sopenharmony_ci	 }
234bf215546Sopenharmony_ci	 else if (light->_Flags & LIGHT_POSITIONAL) {
235bf215546Sopenharmony_ci	    ACC_3V(VP, ctx->_EyeZDir);
236bf215546Sopenharmony_ci            NORMALIZE_3FV(VP);
237bf215546Sopenharmony_ci	    h = VP;
238bf215546Sopenharmony_ci	 }
239bf215546Sopenharmony_ci         else {
240bf215546Sopenharmony_ci	    h = light->_h_inf_norm;
241bf215546Sopenharmony_ci	 }
242bf215546Sopenharmony_ci
243bf215546Sopenharmony_ci	 n_dot_h = DOT3(normal, h);
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ci	 if (n_dot_h > 0.0F) {
246bf215546Sopenharmony_ci	    GLfloat shine;
247bf215546Sopenharmony_ci	    GLfloat spec_coef;
248bf215546Sopenharmony_ci
249bf215546Sopenharmony_ci	    shine = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0];
250bf215546Sopenharmony_ci	    spec_coef = powf(n_dot_h, shine);
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_ci	    if (spec_coef > 1.0e-10F) {
253bf215546Sopenharmony_ci               if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) {
254bf215546Sopenharmony_ci                  ACC_SCALE_SCALAR_3V( specularContrib, spec_coef,
255bf215546Sopenharmony_ci                                       light->_MatSpecular[0]);
256bf215546Sopenharmony_ci               }
257bf215546Sopenharmony_ci               else {
258bf215546Sopenharmony_ci                  ACC_SCALE_SCALAR_3V( diffuseContrib, spec_coef,
259bf215546Sopenharmony_ci                                       light->_MatSpecular[0]);
260bf215546Sopenharmony_ci               }
261bf215546Sopenharmony_ci	    }
262bf215546Sopenharmony_ci	 }
263bf215546Sopenharmony_ci      }
264bf215546Sopenharmony_ci
265bf215546Sopenharmony_ci      ACC_SCALE_SCALAR_3V( diffuseColor, attenuation, diffuseContrib );
266bf215546Sopenharmony_ci      ACC_SCALE_SCALAR_3V( specularColor, attenuation, specularContrib );
267bf215546Sopenharmony_ci   }
268bf215546Sopenharmony_ci
269bf215546Sopenharmony_ci   Rcolor[0] = CLAMP(diffuseColor[0], 0.0F, 1.0F);
270bf215546Sopenharmony_ci   Rcolor[1] = CLAMP(diffuseColor[1], 0.0F, 1.0F);
271bf215546Sopenharmony_ci   Rcolor[2] = CLAMP(diffuseColor[2], 0.0F, 1.0F);
272bf215546Sopenharmony_ci   Rcolor[3] = CLAMP(diffuseColor[3], 0.0F, 1.0F);
273bf215546Sopenharmony_ci   Rspec[0] = CLAMP(specularColor[0], 0.0F, 1.0F);
274bf215546Sopenharmony_ci   Rspec[1] = CLAMP(specularColor[1], 0.0F, 1.0F);
275bf215546Sopenharmony_ci   Rspec[2] = CLAMP(specularColor[2], 0.0F, 1.0F);
276bf215546Sopenharmony_ci   Rspec[3] = CLAMP(specularColor[3], 0.0F, 1.0F);
277bf215546Sopenharmony_ci}
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_ci/**
281bf215546Sopenharmony_ci * Do texgen needed for glRasterPos.
282bf215546Sopenharmony_ci * \param ctx  rendering context
283bf215546Sopenharmony_ci * \param vObj  object-space vertex coordinate
284bf215546Sopenharmony_ci * \param vEye  eye-space vertex coordinate
285bf215546Sopenharmony_ci * \param normal  vertex normal
286bf215546Sopenharmony_ci * \param unit  texture unit number
287bf215546Sopenharmony_ci * \param texcoord  incoming texcoord and resulting texcoord
288bf215546Sopenharmony_ci */
289bf215546Sopenharmony_cistatic void
290bf215546Sopenharmony_cicompute_texgen(struct gl_context *ctx, const GLfloat vObj[4], const GLfloat vEye[4],
291bf215546Sopenharmony_ci               const GLfloat normal[3], GLuint unit, GLfloat texcoord[4])
292bf215546Sopenharmony_ci{
293bf215546Sopenharmony_ci   const struct gl_fixedfunc_texture_unit *texUnit =
294bf215546Sopenharmony_ci      &ctx->Texture.FixedFuncUnit[unit];
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_ci   /* always compute sphere map terms, just in case */
297bf215546Sopenharmony_ci   GLfloat u[3], two_nu, rx, ry, rz, m, mInv;
298bf215546Sopenharmony_ci   COPY_3V(u, vEye);
299bf215546Sopenharmony_ci   NORMALIZE_3FV(u);
300bf215546Sopenharmony_ci   two_nu = 2.0F * DOT3(normal, u);
301bf215546Sopenharmony_ci   rx = u[0] - normal[0] * two_nu;
302bf215546Sopenharmony_ci   ry = u[1] - normal[1] * two_nu;
303bf215546Sopenharmony_ci   rz = u[2] - normal[2] * two_nu;
304bf215546Sopenharmony_ci   m = rx * rx + ry * ry + (rz + 1.0F) * (rz + 1.0F);
305bf215546Sopenharmony_ci   if (m > 0.0F)
306bf215546Sopenharmony_ci      mInv = 0.5F * (1.0f / sqrtf(m));
307bf215546Sopenharmony_ci   else
308bf215546Sopenharmony_ci      mInv = 0.0F;
309bf215546Sopenharmony_ci
310bf215546Sopenharmony_ci   if (texUnit->TexGenEnabled & S_BIT) {
311bf215546Sopenharmony_ci      switch (texUnit->GenS.Mode) {
312bf215546Sopenharmony_ci         case GL_OBJECT_LINEAR:
313bf215546Sopenharmony_ci            texcoord[0] = DOT4(vObj, texUnit->ObjectPlane[GEN_S]);
314bf215546Sopenharmony_ci            break;
315bf215546Sopenharmony_ci         case GL_EYE_LINEAR:
316bf215546Sopenharmony_ci            texcoord[0] = DOT4(vEye, texUnit->EyePlane[GEN_S]);
317bf215546Sopenharmony_ci            break;
318bf215546Sopenharmony_ci         case GL_SPHERE_MAP:
319bf215546Sopenharmony_ci            texcoord[0] = rx * mInv + 0.5F;
320bf215546Sopenharmony_ci            break;
321bf215546Sopenharmony_ci         case GL_REFLECTION_MAP:
322bf215546Sopenharmony_ci            texcoord[0] = rx;
323bf215546Sopenharmony_ci            break;
324bf215546Sopenharmony_ci         case GL_NORMAL_MAP:
325bf215546Sopenharmony_ci            texcoord[0] = normal[0];
326bf215546Sopenharmony_ci            break;
327bf215546Sopenharmony_ci         default:
328bf215546Sopenharmony_ci            _mesa_problem(ctx, "Bad S texgen in compute_texgen()");
329bf215546Sopenharmony_ci            return;
330bf215546Sopenharmony_ci      }
331bf215546Sopenharmony_ci   }
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci   if (texUnit->TexGenEnabled & T_BIT) {
334bf215546Sopenharmony_ci      switch (texUnit->GenT.Mode) {
335bf215546Sopenharmony_ci         case GL_OBJECT_LINEAR:
336bf215546Sopenharmony_ci            texcoord[1] = DOT4(vObj, texUnit->ObjectPlane[GEN_T]);
337bf215546Sopenharmony_ci            break;
338bf215546Sopenharmony_ci         case GL_EYE_LINEAR:
339bf215546Sopenharmony_ci            texcoord[1] = DOT4(vEye, texUnit->EyePlane[GEN_T]);
340bf215546Sopenharmony_ci            break;
341bf215546Sopenharmony_ci         case GL_SPHERE_MAP:
342bf215546Sopenharmony_ci            texcoord[1] = ry * mInv + 0.5F;
343bf215546Sopenharmony_ci            break;
344bf215546Sopenharmony_ci         case GL_REFLECTION_MAP:
345bf215546Sopenharmony_ci            texcoord[1] = ry;
346bf215546Sopenharmony_ci            break;
347bf215546Sopenharmony_ci         case GL_NORMAL_MAP:
348bf215546Sopenharmony_ci            texcoord[1] = normal[1];
349bf215546Sopenharmony_ci            break;
350bf215546Sopenharmony_ci         default:
351bf215546Sopenharmony_ci            _mesa_problem(ctx, "Bad T texgen in compute_texgen()");
352bf215546Sopenharmony_ci            return;
353bf215546Sopenharmony_ci      }
354bf215546Sopenharmony_ci   }
355bf215546Sopenharmony_ci
356bf215546Sopenharmony_ci   if (texUnit->TexGenEnabled & R_BIT) {
357bf215546Sopenharmony_ci      switch (texUnit->GenR.Mode) {
358bf215546Sopenharmony_ci         case GL_OBJECT_LINEAR:
359bf215546Sopenharmony_ci            texcoord[2] = DOT4(vObj, texUnit->ObjectPlane[GEN_R]);
360bf215546Sopenharmony_ci            break;
361bf215546Sopenharmony_ci         case GL_EYE_LINEAR:
362bf215546Sopenharmony_ci            texcoord[2] = DOT4(vEye, texUnit->EyePlane[GEN_R]);
363bf215546Sopenharmony_ci            break;
364bf215546Sopenharmony_ci         case GL_REFLECTION_MAP:
365bf215546Sopenharmony_ci            texcoord[2] = rz;
366bf215546Sopenharmony_ci            break;
367bf215546Sopenharmony_ci         case GL_NORMAL_MAP:
368bf215546Sopenharmony_ci            texcoord[2] = normal[2];
369bf215546Sopenharmony_ci            break;
370bf215546Sopenharmony_ci         default:
371bf215546Sopenharmony_ci            _mesa_problem(ctx, "Bad R texgen in compute_texgen()");
372bf215546Sopenharmony_ci            return;
373bf215546Sopenharmony_ci      }
374bf215546Sopenharmony_ci   }
375bf215546Sopenharmony_ci
376bf215546Sopenharmony_ci   if (texUnit->TexGenEnabled & Q_BIT) {
377bf215546Sopenharmony_ci      switch (texUnit->GenQ.Mode) {
378bf215546Sopenharmony_ci         case GL_OBJECT_LINEAR:
379bf215546Sopenharmony_ci            texcoord[3] = DOT4(vObj, texUnit->ObjectPlane[GEN_Q]);
380bf215546Sopenharmony_ci            break;
381bf215546Sopenharmony_ci         case GL_EYE_LINEAR:
382bf215546Sopenharmony_ci            texcoord[3] = DOT4(vEye, texUnit->EyePlane[GEN_Q]);
383bf215546Sopenharmony_ci            break;
384bf215546Sopenharmony_ci         default:
385bf215546Sopenharmony_ci            _mesa_problem(ctx, "Bad Q texgen in compute_texgen()");
386bf215546Sopenharmony_ci            return;
387bf215546Sopenharmony_ci      }
388bf215546Sopenharmony_ci   }
389bf215546Sopenharmony_ci}
390bf215546Sopenharmony_ci
391bf215546Sopenharmony_ci
392bf215546Sopenharmony_ci/**
393bf215546Sopenharmony_ci * glRasterPos transformation.
394bf215546Sopenharmony_ci *
395bf215546Sopenharmony_ci * \param vObj  vertex position in object space
396bf215546Sopenharmony_ci */
397bf215546Sopenharmony_civoid
398bf215546Sopenharmony_ci_mesa_RasterPos(struct gl_context *ctx, const GLfloat vObj[4])
399bf215546Sopenharmony_ci{
400bf215546Sopenharmony_ci   ctx->PopAttribState |= GL_CURRENT_BIT;
401bf215546Sopenharmony_ci
402bf215546Sopenharmony_ci   if (_mesa_arb_vertex_program_enabled(ctx)) {
403bf215546Sopenharmony_ci      /* XXX implement this */
404bf215546Sopenharmony_ci      _mesa_problem(ctx, "Vertex programs not implemented for glRasterPos");
405bf215546Sopenharmony_ci      return;
406bf215546Sopenharmony_ci   }
407bf215546Sopenharmony_ci   else {
408bf215546Sopenharmony_ci      GLfloat eye[4], clip[4], ndc[3], d;
409bf215546Sopenharmony_ci      GLfloat *norm, eyenorm[3];
410bf215546Sopenharmony_ci      GLfloat *objnorm = ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
411bf215546Sopenharmony_ci      float scale[3], translate[3];
412bf215546Sopenharmony_ci
413bf215546Sopenharmony_ci      /* apply modelview matrix:  eye = MV * obj */
414bf215546Sopenharmony_ci      TRANSFORM_POINT( eye, ctx->ModelviewMatrixStack.Top->m, vObj );
415bf215546Sopenharmony_ci      /* apply projection matrix:  clip = Proj * eye */
416bf215546Sopenharmony_ci      TRANSFORM_POINT( clip, ctx->ProjectionMatrixStack.Top->m, eye );
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_ci      /* clip to view volume. */
419bf215546Sopenharmony_ci      if (!ctx->Transform.DepthClampNear) {
420bf215546Sopenharmony_ci         if (viewclip_point_near_z(clip) == 0) {
421bf215546Sopenharmony_ci            ctx->Current.RasterPosValid = GL_FALSE;
422bf215546Sopenharmony_ci            return;
423bf215546Sopenharmony_ci         }
424bf215546Sopenharmony_ci      }
425bf215546Sopenharmony_ci      if (!ctx->Transform.DepthClampFar) {
426bf215546Sopenharmony_ci         if (viewclip_point_far_z(clip) == 0) {
427bf215546Sopenharmony_ci            ctx->Current.RasterPosValid = GL_FALSE;
428bf215546Sopenharmony_ci            return;
429bf215546Sopenharmony_ci         }
430bf215546Sopenharmony_ci      }
431bf215546Sopenharmony_ci      if (!ctx->Transform.RasterPositionUnclipped) {
432bf215546Sopenharmony_ci         if (viewclip_point_xy(clip) == 0) {
433bf215546Sopenharmony_ci            ctx->Current.RasterPosValid = GL_FALSE;
434bf215546Sopenharmony_ci            return;
435bf215546Sopenharmony_ci         }
436bf215546Sopenharmony_ci      }
437bf215546Sopenharmony_ci
438bf215546Sopenharmony_ci      /* clip to user clipping planes */
439bf215546Sopenharmony_ci      if (ctx->Transform.ClipPlanesEnabled && !userclip_point(ctx, clip)) {
440bf215546Sopenharmony_ci         ctx->Current.RasterPosValid = GL_FALSE;
441bf215546Sopenharmony_ci         return;
442bf215546Sopenharmony_ci      }
443bf215546Sopenharmony_ci
444bf215546Sopenharmony_ci      /* ndc = clip / W */
445bf215546Sopenharmony_ci      d = (clip[3] == 0.0F) ? 1.0F : 1.0F / clip[3];
446bf215546Sopenharmony_ci      ndc[0] = clip[0] * d;
447bf215546Sopenharmony_ci      ndc[1] = clip[1] * d;
448bf215546Sopenharmony_ci      ndc[2] = clip[2] * d;
449bf215546Sopenharmony_ci      /* wincoord = viewport_mapping(ndc) */
450bf215546Sopenharmony_ci      _mesa_get_viewport_xform(ctx, 0, scale, translate);
451bf215546Sopenharmony_ci      ctx->Current.RasterPos[0] = ndc[0] * scale[0] + translate[0];
452bf215546Sopenharmony_ci      ctx->Current.RasterPos[1] = ndc[1] * scale[1] + translate[1];
453bf215546Sopenharmony_ci      ctx->Current.RasterPos[2] = ndc[2] * scale[2] + translate[2];
454bf215546Sopenharmony_ci      ctx->Current.RasterPos[3] = clip[3];
455bf215546Sopenharmony_ci
456bf215546Sopenharmony_ci      if (ctx->Transform.DepthClampNear &&
457bf215546Sopenharmony_ci          ctx->Transform.DepthClampFar) {
458bf215546Sopenharmony_ci         ctx->Current.RasterPos[3] = CLAMP(ctx->Current.RasterPos[3],
459bf215546Sopenharmony_ci                                           ctx->ViewportArray[0].Near,
460bf215546Sopenharmony_ci                                           ctx->ViewportArray[0].Far);
461bf215546Sopenharmony_ci      } else {
462bf215546Sopenharmony_ci         /* Clamp against near and far plane separately */
463bf215546Sopenharmony_ci         if (ctx->Transform.DepthClampNear) {
464bf215546Sopenharmony_ci            ctx->Current.RasterPos[3] = MAX2(ctx->Current.RasterPos[3],
465bf215546Sopenharmony_ci                                             ctx->ViewportArray[0].Near);
466bf215546Sopenharmony_ci         }
467bf215546Sopenharmony_ci
468bf215546Sopenharmony_ci         if (ctx->Transform.DepthClampFar) {
469bf215546Sopenharmony_ci            ctx->Current.RasterPos[3] = MIN2(ctx->Current.RasterPos[3],
470bf215546Sopenharmony_ci                                             ctx->ViewportArray[0].Far);
471bf215546Sopenharmony_ci         }
472bf215546Sopenharmony_ci      }
473bf215546Sopenharmony_ci
474bf215546Sopenharmony_ci      /* compute raster distance */
475bf215546Sopenharmony_ci      if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
476bf215546Sopenharmony_ci         ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
477bf215546Sopenharmony_ci      else
478bf215546Sopenharmony_ci         ctx->Current.RasterDistance =
479bf215546Sopenharmony_ci                        sqrtf( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
480bf215546Sopenharmony_ci
481bf215546Sopenharmony_ci      /* compute transformed normal vector (for lighting or texgen) */
482bf215546Sopenharmony_ci      if (ctx->_NeedEyeCoords) {
483bf215546Sopenharmony_ci         const GLfloat *inv = ctx->ModelviewMatrixStack.Top->inv;
484bf215546Sopenharmony_ci         TRANSFORM_NORMAL( eyenorm, objnorm, inv );
485bf215546Sopenharmony_ci         norm = eyenorm;
486bf215546Sopenharmony_ci      }
487bf215546Sopenharmony_ci      else {
488bf215546Sopenharmony_ci         norm = objnorm;
489bf215546Sopenharmony_ci      }
490bf215546Sopenharmony_ci
491bf215546Sopenharmony_ci      /* update raster color */
492bf215546Sopenharmony_ci      if (ctx->Light.Enabled) {
493bf215546Sopenharmony_ci         /* lighting */
494bf215546Sopenharmony_ci         shade_rastpos( ctx, vObj, norm,
495bf215546Sopenharmony_ci                        ctx->Current.RasterColor,
496bf215546Sopenharmony_ci                        ctx->Current.RasterSecondaryColor );
497bf215546Sopenharmony_ci      }
498bf215546Sopenharmony_ci      else {
499bf215546Sopenharmony_ci         /* use current color */
500bf215546Sopenharmony_ci	 COPY_4FV(ctx->Current.RasterColor,
501bf215546Sopenharmony_ci		  ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
502bf215546Sopenharmony_ci	 COPY_4FV(ctx->Current.RasterSecondaryColor,
503bf215546Sopenharmony_ci		  ctx->Current.Attrib[VERT_ATTRIB_COLOR1]);
504bf215546Sopenharmony_ci      }
505bf215546Sopenharmony_ci
506bf215546Sopenharmony_ci      /* texture coords */
507bf215546Sopenharmony_ci      {
508bf215546Sopenharmony_ci         GLuint u;
509bf215546Sopenharmony_ci         for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) {
510bf215546Sopenharmony_ci            GLfloat tc[4];
511bf215546Sopenharmony_ci            COPY_4V(tc, ctx->Current.Attrib[VERT_ATTRIB_TEX0 + u]);
512bf215546Sopenharmony_ci            if (ctx->Texture.FixedFuncUnit[u].TexGenEnabled) {
513bf215546Sopenharmony_ci               compute_texgen(ctx, vObj, eye, norm, u, tc);
514bf215546Sopenharmony_ci            }
515bf215546Sopenharmony_ci            TRANSFORM_POINT(ctx->Current.RasterTexCoords[u],
516bf215546Sopenharmony_ci                            ctx->TextureMatrixStack[u].Top->m, tc);
517bf215546Sopenharmony_ci         }
518bf215546Sopenharmony_ci      }
519bf215546Sopenharmony_ci
520bf215546Sopenharmony_ci      ctx->Current.RasterPosValid = GL_TRUE;
521bf215546Sopenharmony_ci   }
522bf215546Sopenharmony_ci
523bf215546Sopenharmony_ci   if (ctx->RenderMode == GL_SELECT) {
524bf215546Sopenharmony_ci      _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
525bf215546Sopenharmony_ci   }
526bf215546Sopenharmony_ci}
527bf215546Sopenharmony_ci
528bf215546Sopenharmony_ci
529bf215546Sopenharmony_ci/**
530bf215546Sopenharmony_ci * Helper function for all the RasterPos functions.
531bf215546Sopenharmony_ci */
532bf215546Sopenharmony_cistatic void
533bf215546Sopenharmony_cirasterpos(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
534bf215546Sopenharmony_ci{
535bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
536bf215546Sopenharmony_ci   GLfloat p[4];
537bf215546Sopenharmony_ci
538bf215546Sopenharmony_ci   p[0] = x;
539bf215546Sopenharmony_ci   p[1] = y;
540bf215546Sopenharmony_ci   p[2] = z;
541bf215546Sopenharmony_ci   p[3] = w;
542bf215546Sopenharmony_ci
543bf215546Sopenharmony_ci   FLUSH_VERTICES(ctx, 0, 0);
544bf215546Sopenharmony_ci   FLUSH_CURRENT(ctx, 0);
545bf215546Sopenharmony_ci
546bf215546Sopenharmony_ci   if (ctx->NewState)
547bf215546Sopenharmony_ci      _mesa_update_state( ctx );
548bf215546Sopenharmony_ci
549bf215546Sopenharmony_ci   st_RasterPos(ctx, p);
550bf215546Sopenharmony_ci}
551bf215546Sopenharmony_ci
552bf215546Sopenharmony_ci
553bf215546Sopenharmony_civoid GLAPIENTRY
554bf215546Sopenharmony_ci_mesa_RasterPos2d(GLdouble x, GLdouble y)
555bf215546Sopenharmony_ci{
556bf215546Sopenharmony_ci   rasterpos((GLfloat)x, (GLfloat)y, (GLfloat)0.0, (GLfloat)1.0);
557bf215546Sopenharmony_ci}
558bf215546Sopenharmony_ci
559bf215546Sopenharmony_civoid GLAPIENTRY
560bf215546Sopenharmony_ci_mesa_RasterPos2f(GLfloat x, GLfloat y)
561bf215546Sopenharmony_ci{
562bf215546Sopenharmony_ci   rasterpos(x, y, 0.0F, 1.0F);
563bf215546Sopenharmony_ci}
564bf215546Sopenharmony_ci
565bf215546Sopenharmony_civoid GLAPIENTRY
566bf215546Sopenharmony_ci_mesa_RasterPos2i(GLint x, GLint y)
567bf215546Sopenharmony_ci{
568bf215546Sopenharmony_ci   rasterpos((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
569bf215546Sopenharmony_ci}
570bf215546Sopenharmony_ci
571bf215546Sopenharmony_civoid GLAPIENTRY
572bf215546Sopenharmony_ci_mesa_RasterPos2s(GLshort x, GLshort y)
573bf215546Sopenharmony_ci{
574bf215546Sopenharmony_ci   rasterpos(x, y, 0.0F, 1.0F);
575bf215546Sopenharmony_ci}
576bf215546Sopenharmony_ci
577bf215546Sopenharmony_civoid GLAPIENTRY
578bf215546Sopenharmony_ci_mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
579bf215546Sopenharmony_ci{
580bf215546Sopenharmony_ci   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
581bf215546Sopenharmony_ci}
582bf215546Sopenharmony_ci
583bf215546Sopenharmony_civoid GLAPIENTRY
584bf215546Sopenharmony_ci_mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
585bf215546Sopenharmony_ci{
586bf215546Sopenharmony_ci   rasterpos(x, y, z, 1.0F);
587bf215546Sopenharmony_ci}
588bf215546Sopenharmony_ci
589bf215546Sopenharmony_civoid GLAPIENTRY
590bf215546Sopenharmony_ci_mesa_RasterPos3i(GLint x, GLint y, GLint z)
591bf215546Sopenharmony_ci{
592bf215546Sopenharmony_ci   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
593bf215546Sopenharmony_ci}
594bf215546Sopenharmony_ci
595bf215546Sopenharmony_civoid GLAPIENTRY
596bf215546Sopenharmony_ci_mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
597bf215546Sopenharmony_ci{
598bf215546Sopenharmony_ci   rasterpos(x, y, z, 1.0F);
599bf215546Sopenharmony_ci}
600bf215546Sopenharmony_ci
601bf215546Sopenharmony_civoid GLAPIENTRY
602bf215546Sopenharmony_ci_mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
603bf215546Sopenharmony_ci{
604bf215546Sopenharmony_ci   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
605bf215546Sopenharmony_ci}
606bf215546Sopenharmony_ci
607bf215546Sopenharmony_civoid GLAPIENTRY
608bf215546Sopenharmony_ci_mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
609bf215546Sopenharmony_ci{
610bf215546Sopenharmony_ci   rasterpos(x, y, z, w);
611bf215546Sopenharmony_ci}
612bf215546Sopenharmony_ci
613bf215546Sopenharmony_civoid GLAPIENTRY
614bf215546Sopenharmony_ci_mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
615bf215546Sopenharmony_ci{
616bf215546Sopenharmony_ci   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
617bf215546Sopenharmony_ci}
618bf215546Sopenharmony_ci
619bf215546Sopenharmony_civoid GLAPIENTRY
620bf215546Sopenharmony_ci_mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
621bf215546Sopenharmony_ci{
622bf215546Sopenharmony_ci   rasterpos(x, y, z, w);
623bf215546Sopenharmony_ci}
624bf215546Sopenharmony_ci
625bf215546Sopenharmony_civoid GLAPIENTRY
626bf215546Sopenharmony_ci_mesa_RasterPos2dv(const GLdouble *v)
627bf215546Sopenharmony_ci{
628bf215546Sopenharmony_ci   rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
629bf215546Sopenharmony_ci}
630bf215546Sopenharmony_ci
631bf215546Sopenharmony_civoid GLAPIENTRY
632bf215546Sopenharmony_ci_mesa_RasterPos2fv(const GLfloat *v)
633bf215546Sopenharmony_ci{
634bf215546Sopenharmony_ci   rasterpos(v[0], v[1], 0.0F, 1.0F);
635bf215546Sopenharmony_ci}
636bf215546Sopenharmony_ci
637bf215546Sopenharmony_civoid GLAPIENTRY
638bf215546Sopenharmony_ci_mesa_RasterPos2iv(const GLint *v)
639bf215546Sopenharmony_ci{
640bf215546Sopenharmony_ci   rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
641bf215546Sopenharmony_ci}
642bf215546Sopenharmony_ci
643bf215546Sopenharmony_civoid GLAPIENTRY
644bf215546Sopenharmony_ci_mesa_RasterPos2sv(const GLshort *v)
645bf215546Sopenharmony_ci{
646bf215546Sopenharmony_ci   rasterpos(v[0], v[1], 0.0F, 1.0F);
647bf215546Sopenharmony_ci}
648bf215546Sopenharmony_ci
649bf215546Sopenharmony_civoid GLAPIENTRY
650bf215546Sopenharmony_ci_mesa_RasterPos3dv(const GLdouble *v)
651bf215546Sopenharmony_ci{
652bf215546Sopenharmony_ci   rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
653bf215546Sopenharmony_ci}
654bf215546Sopenharmony_ci
655bf215546Sopenharmony_civoid GLAPIENTRY
656bf215546Sopenharmony_ci_mesa_RasterPos3fv(const GLfloat *v)
657bf215546Sopenharmony_ci{
658bf215546Sopenharmony_ci   rasterpos(v[0], v[1], v[2], 1.0F);
659bf215546Sopenharmony_ci}
660bf215546Sopenharmony_ci
661bf215546Sopenharmony_civoid GLAPIENTRY
662bf215546Sopenharmony_ci_mesa_RasterPos3iv(const GLint *v)
663bf215546Sopenharmony_ci{
664bf215546Sopenharmony_ci   rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
665bf215546Sopenharmony_ci}
666bf215546Sopenharmony_ci
667bf215546Sopenharmony_civoid GLAPIENTRY
668bf215546Sopenharmony_ci_mesa_RasterPos3sv(const GLshort *v)
669bf215546Sopenharmony_ci{
670bf215546Sopenharmony_ci   rasterpos(v[0], v[1], v[2], 1.0F);
671bf215546Sopenharmony_ci}
672bf215546Sopenharmony_ci
673bf215546Sopenharmony_civoid GLAPIENTRY
674bf215546Sopenharmony_ci_mesa_RasterPos4dv(const GLdouble *v)
675bf215546Sopenharmony_ci{
676bf215546Sopenharmony_ci   rasterpos((GLfloat) v[0], (GLfloat) v[1],
677bf215546Sopenharmony_ci		     (GLfloat) v[2], (GLfloat) v[3]);
678bf215546Sopenharmony_ci}
679bf215546Sopenharmony_ci
680bf215546Sopenharmony_civoid GLAPIENTRY
681bf215546Sopenharmony_ci_mesa_RasterPos4fv(const GLfloat *v)
682bf215546Sopenharmony_ci{
683bf215546Sopenharmony_ci   rasterpos(v[0], v[1], v[2], v[3]);
684bf215546Sopenharmony_ci}
685bf215546Sopenharmony_ci
686bf215546Sopenharmony_civoid GLAPIENTRY
687bf215546Sopenharmony_ci_mesa_RasterPos4iv(const GLint *v)
688bf215546Sopenharmony_ci{
689bf215546Sopenharmony_ci   rasterpos((GLfloat) v[0], (GLfloat) v[1],
690bf215546Sopenharmony_ci		     (GLfloat) v[2], (GLfloat) v[3]);
691bf215546Sopenharmony_ci}
692bf215546Sopenharmony_ci
693bf215546Sopenharmony_civoid GLAPIENTRY
694bf215546Sopenharmony_ci_mesa_RasterPos4sv(const GLshort *v)
695bf215546Sopenharmony_ci{
696bf215546Sopenharmony_ci   rasterpos(v[0], v[1], v[2], v[3]);
697bf215546Sopenharmony_ci}
698bf215546Sopenharmony_ci
699bf215546Sopenharmony_ci
700bf215546Sopenharmony_ci/**********************************************************************/
701bf215546Sopenharmony_ci/***           GL_ARB_window_pos / GL_MESA_window_pos               ***/
702bf215546Sopenharmony_ci/**********************************************************************/
703bf215546Sopenharmony_ci
704bf215546Sopenharmony_ci
705bf215546Sopenharmony_ci/**
706bf215546Sopenharmony_ci * All glWindowPosMESA and glWindowPosARB commands call this function to
707bf215546Sopenharmony_ci * update the current raster position.
708bf215546Sopenharmony_ci */
709bf215546Sopenharmony_cistatic void
710bf215546Sopenharmony_ciwindow_pos3f(GLfloat x, GLfloat y, GLfloat z)
711bf215546Sopenharmony_ci{
712bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
713bf215546Sopenharmony_ci   GLfloat z2;
714bf215546Sopenharmony_ci
715bf215546Sopenharmony_ci   FLUSH_VERTICES(ctx, 0, GL_CURRENT_BIT);
716bf215546Sopenharmony_ci   FLUSH_CURRENT(ctx, 0);
717bf215546Sopenharmony_ci
718bf215546Sopenharmony_ci   z2 = CLAMP(z, 0.0F, 1.0F)
719bf215546Sopenharmony_ci      * (ctx->ViewportArray[0].Far - ctx->ViewportArray[0].Near)
720bf215546Sopenharmony_ci      + ctx->ViewportArray[0].Near;
721bf215546Sopenharmony_ci
722bf215546Sopenharmony_ci   /* set raster position */
723bf215546Sopenharmony_ci   ctx->Current.RasterPos[0] = x;
724bf215546Sopenharmony_ci   ctx->Current.RasterPos[1] = y;
725bf215546Sopenharmony_ci   ctx->Current.RasterPos[2] = z2;
726bf215546Sopenharmony_ci   ctx->Current.RasterPos[3] = 1.0F;
727bf215546Sopenharmony_ci
728bf215546Sopenharmony_ci   ctx->Current.RasterPosValid = GL_TRUE;
729bf215546Sopenharmony_ci
730bf215546Sopenharmony_ci   if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
731bf215546Sopenharmony_ci      ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
732bf215546Sopenharmony_ci   else
733bf215546Sopenharmony_ci      ctx->Current.RasterDistance = 0.0;
734bf215546Sopenharmony_ci
735bf215546Sopenharmony_ci   /* raster color = current color or index */
736bf215546Sopenharmony_ci   ctx->Current.RasterColor[0]
737bf215546Sopenharmony_ci      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0], 0.0F, 1.0F);
738bf215546Sopenharmony_ci   ctx->Current.RasterColor[1]
739bf215546Sopenharmony_ci      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][1], 0.0F, 1.0F);
740bf215546Sopenharmony_ci   ctx->Current.RasterColor[2]
741bf215546Sopenharmony_ci      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][2], 0.0F, 1.0F);
742bf215546Sopenharmony_ci   ctx->Current.RasterColor[3]
743bf215546Sopenharmony_ci      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3], 0.0F, 1.0F);
744bf215546Sopenharmony_ci   ctx->Current.RasterSecondaryColor[0]
745bf215546Sopenharmony_ci      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0], 0.0F, 1.0F);
746bf215546Sopenharmony_ci   ctx->Current.RasterSecondaryColor[1]
747bf215546Sopenharmony_ci      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1], 0.0F, 1.0F);
748bf215546Sopenharmony_ci   ctx->Current.RasterSecondaryColor[2]
749bf215546Sopenharmony_ci      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][2], 0.0F, 1.0F);
750bf215546Sopenharmony_ci   ctx->Current.RasterSecondaryColor[3]
751bf215546Sopenharmony_ci      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][3], 0.0F, 1.0F);
752bf215546Sopenharmony_ci
753bf215546Sopenharmony_ci   /* raster texcoord = current texcoord */
754bf215546Sopenharmony_ci   {
755bf215546Sopenharmony_ci      GLuint texSet;
756bf215546Sopenharmony_ci      for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) {
757bf215546Sopenharmony_ci         assert(texSet < ARRAY_SIZE(ctx->Current.RasterTexCoords));
758bf215546Sopenharmony_ci         COPY_4FV( ctx->Current.RasterTexCoords[texSet],
759bf215546Sopenharmony_ci                  ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] );
760bf215546Sopenharmony_ci      }
761bf215546Sopenharmony_ci   }
762bf215546Sopenharmony_ci
763bf215546Sopenharmony_ci   if (ctx->RenderMode==GL_SELECT) {
764bf215546Sopenharmony_ci      _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
765bf215546Sopenharmony_ci   }
766bf215546Sopenharmony_ci}
767bf215546Sopenharmony_ci
768bf215546Sopenharmony_ci
769bf215546Sopenharmony_ci/* This is just to support the GL_MESA_window_pos version */
770bf215546Sopenharmony_cistatic void
771bf215546Sopenharmony_ciwindow_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
772bf215546Sopenharmony_ci{
773bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
774bf215546Sopenharmony_ci   window_pos3f(x, y, z);
775bf215546Sopenharmony_ci   ctx->Current.RasterPos[3] = w;
776bf215546Sopenharmony_ci}
777bf215546Sopenharmony_ci
778bf215546Sopenharmony_ci
779bf215546Sopenharmony_civoid GLAPIENTRY
780bf215546Sopenharmony_ci_mesa_WindowPos2d(GLdouble x, GLdouble y)
781bf215546Sopenharmony_ci{
782bf215546Sopenharmony_ci   window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
783bf215546Sopenharmony_ci}
784bf215546Sopenharmony_ci
785bf215546Sopenharmony_civoid GLAPIENTRY
786bf215546Sopenharmony_ci_mesa_WindowPos2f(GLfloat x, GLfloat y)
787bf215546Sopenharmony_ci{
788bf215546Sopenharmony_ci   window_pos4f(x, y, 0.0F, 1.0F);
789bf215546Sopenharmony_ci}
790bf215546Sopenharmony_ci
791bf215546Sopenharmony_civoid GLAPIENTRY
792bf215546Sopenharmony_ci_mesa_WindowPos2i(GLint x, GLint y)
793bf215546Sopenharmony_ci{
794bf215546Sopenharmony_ci   window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
795bf215546Sopenharmony_ci}
796bf215546Sopenharmony_ci
797bf215546Sopenharmony_civoid GLAPIENTRY
798bf215546Sopenharmony_ci_mesa_WindowPos2s(GLshort x, GLshort y)
799bf215546Sopenharmony_ci{
800bf215546Sopenharmony_ci   window_pos4f(x, y, 0.0F, 1.0F);
801bf215546Sopenharmony_ci}
802bf215546Sopenharmony_ci
803bf215546Sopenharmony_civoid GLAPIENTRY
804bf215546Sopenharmony_ci_mesa_WindowPos3d(GLdouble x, GLdouble y, GLdouble z)
805bf215546Sopenharmony_ci{
806bf215546Sopenharmony_ci   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
807bf215546Sopenharmony_ci}
808bf215546Sopenharmony_ci
809bf215546Sopenharmony_civoid GLAPIENTRY
810bf215546Sopenharmony_ci_mesa_WindowPos3f(GLfloat x, GLfloat y, GLfloat z)
811bf215546Sopenharmony_ci{
812bf215546Sopenharmony_ci   window_pos4f(x, y, z, 1.0F);
813bf215546Sopenharmony_ci}
814bf215546Sopenharmony_ci
815bf215546Sopenharmony_civoid GLAPIENTRY
816bf215546Sopenharmony_ci_mesa_WindowPos3i(GLint x, GLint y, GLint z)
817bf215546Sopenharmony_ci{
818bf215546Sopenharmony_ci   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
819bf215546Sopenharmony_ci}
820bf215546Sopenharmony_ci
821bf215546Sopenharmony_civoid GLAPIENTRY
822bf215546Sopenharmony_ci_mesa_WindowPos3s(GLshort x, GLshort y, GLshort z)
823bf215546Sopenharmony_ci{
824bf215546Sopenharmony_ci   window_pos4f(x, y, z, 1.0F);
825bf215546Sopenharmony_ci}
826bf215546Sopenharmony_ci
827bf215546Sopenharmony_civoid GLAPIENTRY
828bf215546Sopenharmony_ci_mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
829bf215546Sopenharmony_ci{
830bf215546Sopenharmony_ci   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
831bf215546Sopenharmony_ci}
832bf215546Sopenharmony_ci
833bf215546Sopenharmony_civoid GLAPIENTRY
834bf215546Sopenharmony_ci_mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
835bf215546Sopenharmony_ci{
836bf215546Sopenharmony_ci   window_pos4f(x, y, z, w);
837bf215546Sopenharmony_ci}
838bf215546Sopenharmony_ci
839bf215546Sopenharmony_civoid GLAPIENTRY
840bf215546Sopenharmony_ci_mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
841bf215546Sopenharmony_ci{
842bf215546Sopenharmony_ci   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
843bf215546Sopenharmony_ci}
844bf215546Sopenharmony_ci
845bf215546Sopenharmony_civoid GLAPIENTRY
846bf215546Sopenharmony_ci_mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
847bf215546Sopenharmony_ci{
848bf215546Sopenharmony_ci   window_pos4f(x, y, z, w);
849bf215546Sopenharmony_ci}
850bf215546Sopenharmony_ci
851bf215546Sopenharmony_civoid GLAPIENTRY
852bf215546Sopenharmony_ci_mesa_WindowPos2dv(const GLdouble *v)
853bf215546Sopenharmony_ci{
854bf215546Sopenharmony_ci   window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
855bf215546Sopenharmony_ci}
856bf215546Sopenharmony_ci
857bf215546Sopenharmony_civoid GLAPIENTRY
858bf215546Sopenharmony_ci_mesa_WindowPos2fv(const GLfloat *v)
859bf215546Sopenharmony_ci{
860bf215546Sopenharmony_ci   window_pos4f(v[0], v[1], 0.0F, 1.0F);
861bf215546Sopenharmony_ci}
862bf215546Sopenharmony_ci
863bf215546Sopenharmony_civoid GLAPIENTRY
864bf215546Sopenharmony_ci_mesa_WindowPos2iv(const GLint *v)
865bf215546Sopenharmony_ci{
866bf215546Sopenharmony_ci   window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
867bf215546Sopenharmony_ci}
868bf215546Sopenharmony_ci
869bf215546Sopenharmony_civoid GLAPIENTRY
870bf215546Sopenharmony_ci_mesa_WindowPos2sv(const GLshort *v)
871bf215546Sopenharmony_ci{
872bf215546Sopenharmony_ci   window_pos4f(v[0], v[1], 0.0F, 1.0F);
873bf215546Sopenharmony_ci}
874bf215546Sopenharmony_ci
875bf215546Sopenharmony_civoid GLAPIENTRY
876bf215546Sopenharmony_ci_mesa_WindowPos3dv(const GLdouble *v)
877bf215546Sopenharmony_ci{
878bf215546Sopenharmony_ci   window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
879bf215546Sopenharmony_ci}
880bf215546Sopenharmony_ci
881bf215546Sopenharmony_civoid GLAPIENTRY
882bf215546Sopenharmony_ci_mesa_WindowPos3fv(const GLfloat *v)
883bf215546Sopenharmony_ci{
884bf215546Sopenharmony_ci   window_pos4f(v[0], v[1], v[2], 1.0);
885bf215546Sopenharmony_ci}
886bf215546Sopenharmony_ci
887bf215546Sopenharmony_civoid GLAPIENTRY
888bf215546Sopenharmony_ci_mesa_WindowPos3iv(const GLint *v)
889bf215546Sopenharmony_ci{
890bf215546Sopenharmony_ci   window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
891bf215546Sopenharmony_ci}
892bf215546Sopenharmony_ci
893bf215546Sopenharmony_civoid GLAPIENTRY
894bf215546Sopenharmony_ci_mesa_WindowPos3sv(const GLshort *v)
895bf215546Sopenharmony_ci{
896bf215546Sopenharmony_ci   window_pos4f(v[0], v[1], v[2], 1.0F);
897bf215546Sopenharmony_ci}
898bf215546Sopenharmony_ci
899bf215546Sopenharmony_civoid GLAPIENTRY
900bf215546Sopenharmony_ci_mesa_WindowPos4dvMESA(const GLdouble *v)
901bf215546Sopenharmony_ci{
902bf215546Sopenharmony_ci   window_pos4f((GLfloat) v[0], (GLfloat) v[1],
903bf215546Sopenharmony_ci			 (GLfloat) v[2], (GLfloat) v[3]);
904bf215546Sopenharmony_ci}
905bf215546Sopenharmony_ci
906bf215546Sopenharmony_civoid GLAPIENTRY
907bf215546Sopenharmony_ci_mesa_WindowPos4fvMESA(const GLfloat *v)
908bf215546Sopenharmony_ci{
909bf215546Sopenharmony_ci   window_pos4f(v[0], v[1], v[2], v[3]);
910bf215546Sopenharmony_ci}
911bf215546Sopenharmony_ci
912bf215546Sopenharmony_civoid GLAPIENTRY
913bf215546Sopenharmony_ci_mesa_WindowPos4ivMESA(const GLint *v)
914bf215546Sopenharmony_ci{
915bf215546Sopenharmony_ci   window_pos4f((GLfloat) v[0], (GLfloat) v[1],
916bf215546Sopenharmony_ci			 (GLfloat) v[2], (GLfloat) v[3]);
917bf215546Sopenharmony_ci}
918bf215546Sopenharmony_ci
919bf215546Sopenharmony_civoid GLAPIENTRY
920bf215546Sopenharmony_ci_mesa_WindowPos4svMESA(const GLshort *v)
921bf215546Sopenharmony_ci{
922bf215546Sopenharmony_ci   window_pos4f(v[0], v[1], v[2], v[3]);
923bf215546Sopenharmony_ci}
924bf215546Sopenharmony_ci
925bf215546Sopenharmony_ci
926bf215546Sopenharmony_ci#if 0
927bf215546Sopenharmony_ci
928bf215546Sopenharmony_ci/*
929bf215546Sopenharmony_ci * OpenGL implementation of glWindowPos*MESA()
930bf215546Sopenharmony_ci */
931bf215546Sopenharmony_civoid glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
932bf215546Sopenharmony_ci{
933bf215546Sopenharmony_ci   GLfloat fx, fy;
934bf215546Sopenharmony_ci
935bf215546Sopenharmony_ci   /* Push current matrix mode and viewport attributes */
936bf215546Sopenharmony_ci   glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
937bf215546Sopenharmony_ci
938bf215546Sopenharmony_ci   /* Setup projection parameters */
939bf215546Sopenharmony_ci   glMatrixMode( GL_PROJECTION );
940bf215546Sopenharmony_ci   glPushMatrix();
941bf215546Sopenharmony_ci   glLoadIdentity();
942bf215546Sopenharmony_ci   glMatrixMode( GL_MODELVIEW );
943bf215546Sopenharmony_ci   glPushMatrix();
944bf215546Sopenharmony_ci   glLoadIdentity();
945bf215546Sopenharmony_ci
946bf215546Sopenharmony_ci   glDepthRange( z, z );
947bf215546Sopenharmony_ci   glViewport( (int) x - 1, (int) y - 1, 2, 2 );
948bf215546Sopenharmony_ci
949bf215546Sopenharmony_ci   /* set the raster (window) position */
950bf215546Sopenharmony_ci   fx = x - (int) x;
951bf215546Sopenharmony_ci   fy = y - (int) y;
952bf215546Sopenharmony_ci   glRasterPos4f( fx, fy, 0.0, w );
953bf215546Sopenharmony_ci
954bf215546Sopenharmony_ci   /* restore matrices, viewport and matrix mode */
955bf215546Sopenharmony_ci   glPopMatrix();
956bf215546Sopenharmony_ci   glMatrixMode( GL_PROJECTION );
957bf215546Sopenharmony_ci   glPopMatrix();
958bf215546Sopenharmony_ci
959bf215546Sopenharmony_ci   glPopAttrib();
960bf215546Sopenharmony_ci}
961bf215546Sopenharmony_ci
962bf215546Sopenharmony_ci#endif
963bf215546Sopenharmony_ci
964bf215546Sopenharmony_ci
965bf215546Sopenharmony_ci/**********************************************************************/
966bf215546Sopenharmony_ci/** \name Initialization                                              */
967bf215546Sopenharmony_ci/**********************************************************************/
968bf215546Sopenharmony_ci/*@{*/
969bf215546Sopenharmony_ci
970bf215546Sopenharmony_ci/**
971bf215546Sopenharmony_ci * Initialize the context current raster position information.
972bf215546Sopenharmony_ci *
973bf215546Sopenharmony_ci * \param ctx GL context.
974bf215546Sopenharmony_ci *
975bf215546Sopenharmony_ci * Initialize the current raster position information in
976bf215546Sopenharmony_ci * __struct gl_contextRec::Current, and adds the extension entry points to the
977bf215546Sopenharmony_ci * dispatcher.
978bf215546Sopenharmony_ci */
979bf215546Sopenharmony_civoid _mesa_init_rastpos( struct gl_context * ctx )
980bf215546Sopenharmony_ci{
981bf215546Sopenharmony_ci   unsigned i;
982bf215546Sopenharmony_ci
983bf215546Sopenharmony_ci   ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
984bf215546Sopenharmony_ci   ctx->Current.RasterDistance = 0.0;
985bf215546Sopenharmony_ci   ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
986bf215546Sopenharmony_ci   ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 );
987bf215546Sopenharmony_ci   for (i = 0; i < ARRAY_SIZE(ctx->Current.RasterTexCoords); i++)
988bf215546Sopenharmony_ci      ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
989bf215546Sopenharmony_ci   ctx->Current.RasterPosValid = GL_TRUE;
990bf215546Sopenharmony_ci}
991bf215546Sopenharmony_ci
992bf215546Sopenharmony_ci/*@}*/
993