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