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