nouveau: unbreak nv40
[mesa.git] / src / mesa / main / rastpos.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file rastpos.c
28 * Raster position operations.
29 */
30
31 #include "glheader.h"
32 #include "colormac.h"
33 #include "context.h"
34 #include "feedback.h"
35 #include "light.h"
36 #include "macros.h"
37 #include "rastpos.h"
38 #include "state.h"
39 #include "simple_list.h"
40 #include "mtypes.h"
41
42 #include "math/m_matrix.h"
43
44
45 /**
46 * Clip a point against the view volume.
47 *
48 * \param v vertex vector describing the point to clip.
49 *
50 * \return zero if outside view volume, or one if inside.
51 */
52 static GLuint
53 viewclip_point( const GLfloat v[] )
54 {
55 if ( v[0] > v[3] || v[0] < -v[3]
56 || v[1] > v[3] || v[1] < -v[3]
57 || v[2] > v[3] || v[2] < -v[3] ) {
58 return 0;
59 }
60 else {
61 return 1;
62 }
63 }
64
65
66 /**
67 * Clip a point against the far/near Z clipping planes.
68 *
69 * \param v vertex vector describing the point to clip.
70 *
71 * \return zero if outside view volume, or one if inside.
72 */
73 static GLuint
74 viewclip_point_z( const GLfloat v[] )
75 {
76 if (v[2] > v[3] || v[2] < -v[3] ) {
77 return 0;
78 }
79 else {
80 return 1;
81 }
82 }
83
84
85 /**
86 * Clip a point against the user clipping planes.
87 *
88 * \param ctx GL context.
89 * \param v vertex vector describing the point to clip.
90 *
91 * \return zero if the point was clipped, or one otherwise.
92 */
93 static GLuint
94 userclip_point( GLcontext *ctx, const GLfloat v[] )
95 {
96 GLuint p;
97
98 for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
99 if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
100 GLfloat dot = v[0] * ctx->Transform._ClipUserPlane[p][0]
101 + v[1] * ctx->Transform._ClipUserPlane[p][1]
102 + v[2] * ctx->Transform._ClipUserPlane[p][2]
103 + v[3] * ctx->Transform._ClipUserPlane[p][3];
104 if (dot < 0.0F) {
105 return 0;
106 }
107 }
108 }
109
110 return 1;
111 }
112
113
114 /**
115 * This has been split off to allow the normal shade routines to
116 * get a little closer to the vertex buffer, and to use the
117 * GLvector objects directly.
118 * \param ctx the context
119 * \param vertex vertex location
120 * \param normal normal vector
121 * \param Rcolor returned color
122 * \param Rspec returned specular color (if separate specular enabled)
123 * \param Rindex returned color index
124 */
125 static void
126 shade_rastpos(GLcontext *ctx,
127 const GLfloat vertex[4],
128 const GLfloat normal[3],
129 GLfloat Rcolor[4],
130 GLfloat Rspec[4],
131 GLfloat *Rindex)
132 {
133 GLfloat (*base)[3] = ctx->Light._BaseColor;
134 struct gl_light *light;
135 GLfloat diffuseColor[4], specularColor[4];
136 GLfloat diffuse = 0, specular = 0;
137
138 if (!ctx->_ShineTable[0] || !ctx->_ShineTable[1])
139 _mesa_validate_all_lighting_tables( ctx );
140
141 COPY_3V(diffuseColor, base[0]);
142 diffuseColor[3] = CLAMP(
143 ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_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 GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
227 GLfloat spec_coef;
228 GLfloat shininess = mat[MAT_ATTRIB_FRONT_SHININESS][0];
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 GLfloat *ind = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_INDEXES];
268 GLfloat d_a = ind[MAT_INDEX_DIFFUSE] - ind[MAT_INDEX_AMBIENT];
269 GLfloat s_a = ind[MAT_INDEX_SPECULAR] - ind[MAT_INDEX_AMBIENT];
270 GLfloat i = (ind[MAT_INDEX_AMBIENT]
271 + diffuse * (1.0F-specular) * d_a
272 + specular * s_a);
273 if (i > ind[MAT_INDEX_SPECULAR]) {
274 i = ind[MAT_INDEX_SPECULAR];
275 }
276 *Rindex = i;
277 }
278 }
279
280
281 /**
282 * Do texgen needed for glRasterPos.
283 * \param ctx rendering context
284 * \param vObj object-space vertex coordinate
285 * \param vEye eye-space vertex coordinate
286 * \param normal vertex normal
287 * \param unit texture unit number
288 * \param texcoord incoming texcoord and resulting texcoord
289 */
290 static void
291 compute_texgen(GLcontext *ctx, const GLfloat vObj[4], const GLfloat vEye[4],
292 const GLfloat normal[3], GLuint unit, GLfloat texcoord[4])
293 {
294 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
295
296 /* always compute sphere map terms, just in case */
297 GLfloat u[3], two_nu, rx, ry, rz, m, mInv;
298 COPY_3V(u, vEye);
299 NORMALIZE_3FV(u);
300 two_nu = 2.0F * DOT3(normal, u);
301 rx = u[0] - normal[0] * two_nu;
302 ry = u[1] - normal[1] * two_nu;
303 rz = u[2] - normal[2] * two_nu;
304 m = rx * rx + ry * ry + (rz + 1.0F) * (rz + 1.0F);
305 if (m > 0.0F)
306 mInv = 0.5F * _mesa_inv_sqrtf(m);
307 else
308 mInv = 0.0F;
309
310 if (texUnit->TexGenEnabled & S_BIT) {
311 switch (texUnit->GenModeS) {
312 case GL_OBJECT_LINEAR:
313 texcoord[0] = DOT4(vObj, texUnit->ObjectPlaneS);
314 break;
315 case GL_EYE_LINEAR:
316 texcoord[0] = DOT4(vEye, texUnit->EyePlaneS);
317 break;
318 case GL_SPHERE_MAP:
319 texcoord[0] = rx * mInv + 0.5F;
320 break;
321 case GL_REFLECTION_MAP:
322 texcoord[0] = rx;
323 break;
324 case GL_NORMAL_MAP:
325 texcoord[0] = normal[0];
326 break;
327 default:
328 _mesa_problem(ctx, "Bad S texgen in compute_texgen()");
329 return;
330 }
331 }
332
333 if (texUnit->TexGenEnabled & T_BIT) {
334 switch (texUnit->GenModeT) {
335 case GL_OBJECT_LINEAR:
336 texcoord[1] = DOT4(vObj, texUnit->ObjectPlaneT);
337 break;
338 case GL_EYE_LINEAR:
339 texcoord[1] = DOT4(vEye, texUnit->EyePlaneT);
340 break;
341 case GL_SPHERE_MAP:
342 texcoord[1] = ry * mInv + 0.5F;
343 break;
344 case GL_REFLECTION_MAP:
345 texcoord[1] = ry;
346 break;
347 case GL_NORMAL_MAP:
348 texcoord[1] = normal[1];
349 break;
350 default:
351 _mesa_problem(ctx, "Bad T texgen in compute_texgen()");
352 return;
353 }
354 }
355
356 if (texUnit->TexGenEnabled & R_BIT) {
357 switch (texUnit->GenModeR) {
358 case GL_OBJECT_LINEAR:
359 texcoord[2] = DOT4(vObj, texUnit->ObjectPlaneR);
360 break;
361 case GL_EYE_LINEAR:
362 texcoord[2] = DOT4(vEye, texUnit->EyePlaneR);
363 break;
364 case GL_REFLECTION_MAP:
365 texcoord[2] = rz;
366 break;
367 case GL_NORMAL_MAP:
368 texcoord[2] = normal[2];
369 break;
370 default:
371 _mesa_problem(ctx, "Bad R texgen in compute_texgen()");
372 return;
373 }
374 }
375
376 if (texUnit->TexGenEnabled & Q_BIT) {
377 switch (texUnit->GenModeQ) {
378 case GL_OBJECT_LINEAR:
379 texcoord[3] = DOT4(vObj, texUnit->ObjectPlaneQ);
380 break;
381 case GL_EYE_LINEAR:
382 texcoord[3] = DOT4(vEye, texUnit->EyePlaneQ);
383 break;
384 default:
385 _mesa_problem(ctx, "Bad Q texgen in compute_texgen()");
386 return;
387 }
388 }
389 }
390
391
392
393 /**
394 * Set the raster position for pixel operations.
395 *
396 * All glRasterPos command call this function to update the current
397 * raster position.
398 *
399 * \param ctx GL context.
400 * \param x x coordinate for the raster position.
401 * \param y y coordinate for the raster position.
402 * \param z z coordinate for the raster position.
403 * \param w w coordinate for the raster position.
404 *
405 * \sa Called by _mesa_RasterPos4f().
406 *
407 * Flushes the vertices, transforms and clips the vertex coordinates, and
408 * finally sets the current raster position and associated data in
409 * __GLcontextRec::Current. When in selection mode calls
410 * _mesa_update_hitflag() with the current raster position.
411 */
412 static void
413 raster_pos4f(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
414 {
415 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
416 FLUSH_CURRENT(ctx, 0);
417
418 if (ctx->NewState)
419 _mesa_update_state( ctx );
420
421 if (ctx->VertexProgram._Enabled) {
422 /* XXX implement this */
423 _mesa_problem(ctx, "Vertex programs not implemented for glRasterPos");
424 return;
425 }
426 else {
427 GLfloat obj[4], eye[4], clip[4], ndc[3], d;
428 GLfloat *norm, eyenorm[3];
429 GLfloat *objnorm = ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
430
431 ASSIGN_4V( obj, x, y, z, w );
432 /* apply modelview matrix: eye = MV * obj */
433 TRANSFORM_POINT( eye, ctx->ModelviewMatrixStack.Top->m, obj );
434 /* apply projection matrix: clip = Proj * eye */
435 TRANSFORM_POINT( clip, ctx->ProjectionMatrixStack.Top->m, eye );
436
437 /* clip to view volume */
438 if (ctx->Transform.RasterPositionUnclipped) {
439 /* GL_IBM_rasterpos_clip: only clip against Z */
440 if (viewclip_point_z(clip) == 0) {
441 ctx->Current.RasterPosValid = GL_FALSE;
442 return;
443 }
444 }
445 else if (viewclip_point(clip) == 0) {
446 /* Normal OpenGL behaviour */
447 ctx->Current.RasterPosValid = GL_FALSE;
448 return;
449 }
450
451 /* clip to user clipping planes */
452 if (ctx->Transform.ClipPlanesEnabled && !userclip_point(ctx, clip)) {
453 ctx->Current.RasterPosValid = GL_FALSE;
454 return;
455 }
456
457 /* ndc = clip / W */
458 d = (clip[3] == 0.0F) ? 1.0F : 1.0F / clip[3];
459 ndc[0] = clip[0] * d;
460 ndc[1] = clip[1] * d;
461 ndc[2] = clip[2] * d;
462 /* wincoord = viewport_mapping(ndc) */
463 ctx->Current.RasterPos[0] = (ndc[0] * ctx->Viewport._WindowMap.m[MAT_SX]
464 + ctx->Viewport._WindowMap.m[MAT_TX]);
465 ctx->Current.RasterPos[1] = (ndc[1] * ctx->Viewport._WindowMap.m[MAT_SY]
466 + ctx->Viewport._WindowMap.m[MAT_TY]);
467 ctx->Current.RasterPos[2] = (ndc[2] * ctx->Viewport._WindowMap.m[MAT_SZ]
468 + ctx->Viewport._WindowMap.m[MAT_TZ])
469 / ctx->DrawBuffer->_DepthMaxF;
470 ctx->Current.RasterPos[3] = clip[3];
471
472 /* compute raster distance */
473 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
474 ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
475 else
476 ctx->Current.RasterDistance =
477 SQRTF( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
478
479 /* compute transformed normal vector (for lighting or texgen) */
480 if (ctx->_NeedEyeCoords) {
481 const GLfloat *inv = ctx->ModelviewMatrixStack.Top->inv;
482 TRANSFORM_NORMAL( eyenorm, objnorm, inv );
483 norm = eyenorm;
484 }
485 else {
486 norm = objnorm;
487 }
488
489 /* update raster color */
490 if (ctx->Light.Enabled) {
491 /* lighting */
492 shade_rastpos( ctx, obj, norm,
493 ctx->Current.RasterColor,
494 ctx->Current.RasterSecondaryColor,
495 &ctx->Current.RasterIndex );
496 }
497 else {
498 /* use current color or index */
499 if (ctx->Visual.rgbMode) {
500 COPY_4FV(ctx->Current.RasterColor,
501 ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
502 COPY_4FV(ctx->Current.RasterSecondaryColor,
503 ctx->Current.Attrib[VERT_ATTRIB_COLOR1]);
504 }
505 else {
506 ctx->Current.RasterIndex
507 = ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0];
508 }
509 }
510
511 /* texture coords */
512 {
513 GLuint u;
514 for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) {
515 GLfloat tc[4];
516 COPY_4V(tc, ctx->Current.Attrib[VERT_ATTRIB_TEX0 + u]);
517 if (ctx->Texture.Unit[u].TexGenEnabled) {
518 compute_texgen(ctx, obj, eye, norm, u, tc);
519 }
520 TRANSFORM_POINT(ctx->Current.RasterTexCoords[u],
521 ctx->TextureMatrixStack[u].Top->m, tc);
522 }
523 }
524
525 ctx->Current.RasterPosValid = GL_TRUE;
526 }
527
528 if (ctx->RenderMode == GL_SELECT) {
529 _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
530 }
531 }
532
533
534 /** Calls _mesa_RasterPos4f() */
535 void GLAPIENTRY
536 _mesa_RasterPos2d(GLdouble x, GLdouble y)
537 {
538 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
539 }
540
541 /** Calls _mesa_RasterPos4f() */
542 void GLAPIENTRY
543 _mesa_RasterPos2f(GLfloat x, GLfloat y)
544 {
545 _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
546 }
547
548 /** Calls _mesa_RasterPos4f() */
549 void GLAPIENTRY
550 _mesa_RasterPos2i(GLint x, GLint y)
551 {
552 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
553 }
554
555 /** Calls _mesa_RasterPos4f() */
556 void GLAPIENTRY
557 _mesa_RasterPos2s(GLshort x, GLshort y)
558 {
559 _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
560 }
561
562 /** Calls _mesa_RasterPos4f() */
563 void GLAPIENTRY
564 _mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
565 {
566 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
567 }
568
569 /** Calls _mesa_RasterPos4f() */
570 void GLAPIENTRY
571 _mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
572 {
573 _mesa_RasterPos4f(x, y, z, 1.0F);
574 }
575
576 /** Calls _mesa_RasterPos4f() */
577 void GLAPIENTRY
578 _mesa_RasterPos3i(GLint x, GLint y, GLint z)
579 {
580 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
581 }
582
583 /** Calls _mesa_RasterPos4f() */
584 void GLAPIENTRY
585 _mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
586 {
587 _mesa_RasterPos4f(x, y, z, 1.0F);
588 }
589
590 /** Calls _mesa_RasterPos4f() */
591 void GLAPIENTRY
592 _mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
593 {
594 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
595 }
596
597 /** Calls raster_pos4f() */
598 void GLAPIENTRY
599 _mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
600 {
601 GET_CURRENT_CONTEXT(ctx);
602 raster_pos4f(ctx, x, y, z, w);
603 }
604
605 /** Calls _mesa_RasterPos4f() */
606 void GLAPIENTRY
607 _mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
608 {
609 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
610 }
611
612 /** Calls _mesa_RasterPos4f() */
613 void GLAPIENTRY
614 _mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
615 {
616 _mesa_RasterPos4f(x, y, z, w);
617 }
618
619 /** Calls _mesa_RasterPos4f() */
620 void GLAPIENTRY
621 _mesa_RasterPos2dv(const GLdouble *v)
622 {
623 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
624 }
625
626 /** Calls _mesa_RasterPos4f() */
627 void GLAPIENTRY
628 _mesa_RasterPos2fv(const GLfloat *v)
629 {
630 _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
631 }
632
633 /** Calls _mesa_RasterPos4f() */
634 void GLAPIENTRY
635 _mesa_RasterPos2iv(const GLint *v)
636 {
637 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
638 }
639
640 /** Calls _mesa_RasterPos4f() */
641 void GLAPIENTRY
642 _mesa_RasterPos2sv(const GLshort *v)
643 {
644 _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
645 }
646
647 /** Calls _mesa_RasterPos4f() */
648 void GLAPIENTRY
649 _mesa_RasterPos3dv(const GLdouble *v)
650 {
651 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
652 }
653
654 /** Calls _mesa_RasterPos4f() */
655 void GLAPIENTRY
656 _mesa_RasterPos3fv(const GLfloat *v)
657 {
658 _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
659 }
660
661 /** Calls _mesa_RasterPos4f() */
662 void GLAPIENTRY
663 _mesa_RasterPos3iv(const GLint *v)
664 {
665 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
666 }
667
668 /** Calls _mesa_RasterPos4f() */
669 void GLAPIENTRY
670 _mesa_RasterPos3sv(const GLshort *v)
671 {
672 _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
673 }
674
675 /** Calls _mesa_RasterPos4f() */
676 void GLAPIENTRY
677 _mesa_RasterPos4dv(const GLdouble *v)
678 {
679 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
680 (GLfloat) v[2], (GLfloat) v[3]);
681 }
682
683 /** Calls _mesa_RasterPos4f() */
684 void GLAPIENTRY
685 _mesa_RasterPos4fv(const GLfloat *v)
686 {
687 _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
688 }
689
690 /** Calls _mesa_RasterPos4f() */
691 void GLAPIENTRY
692 _mesa_RasterPos4iv(const GLint *v)
693 {
694 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
695 (GLfloat) v[2], (GLfloat) v[3]);
696 }
697
698 /** Calls _mesa_RasterPos4f() */
699 void GLAPIENTRY
700 _mesa_RasterPos4sv(const GLshort *v)
701 {
702 _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
703 }
704
705
706 /**********************************************************************/
707 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
708 /**********************************************************************/
709
710 #if FEATURE_windowpos
711 /**
712 * All glWindowPosMESA and glWindowPosARB commands call this function to
713 * update the current raster position.
714 */
715 static void
716 window_pos3f(GLfloat x, GLfloat y, GLfloat z)
717 {
718 GET_CURRENT_CONTEXT(ctx);
719 GLfloat z2;
720
721 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
722 FLUSH_CURRENT(ctx, 0);
723
724 z2 = CLAMP(z, 0.0F, 1.0F) * (ctx->Viewport.Far - ctx->Viewport.Near)
725 + ctx->Viewport.Near;
726
727 /* set raster position */
728 ctx->Current.RasterPos[0] = x;
729 ctx->Current.RasterPos[1] = y;
730 ctx->Current.RasterPos[2] = z2;
731 ctx->Current.RasterPos[3] = 1.0F;
732
733 ctx->Current.RasterPosValid = GL_TRUE;
734
735 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
736 ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
737 else
738 ctx->Current.RasterDistance = 0.0;
739
740 /* raster color = current color or index */
741 if (ctx->Visual.rgbMode) {
742 ctx->Current.RasterColor[0]
743 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0], 0.0F, 1.0F);
744 ctx->Current.RasterColor[1]
745 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][1], 0.0F, 1.0F);
746 ctx->Current.RasterColor[2]
747 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][2], 0.0F, 1.0F);
748 ctx->Current.RasterColor[3]
749 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3], 0.0F, 1.0F);
750 ctx->Current.RasterSecondaryColor[0]
751 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0], 0.0F, 1.0F);
752 ctx->Current.RasterSecondaryColor[1]
753 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1], 0.0F, 1.0F);
754 ctx->Current.RasterSecondaryColor[2]
755 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][2], 0.0F, 1.0F);
756 ctx->Current.RasterSecondaryColor[3]
757 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][3], 0.0F, 1.0F);
758 }
759 else {
760 ctx->Current.RasterIndex
761 = ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0];
762 }
763
764 /* raster texcoord = current texcoord */
765 {
766 GLuint texSet;
767 for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) {
768 COPY_4FV( ctx->Current.RasterTexCoords[texSet],
769 ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] );
770 }
771 }
772
773 if (ctx->RenderMode==GL_SELECT) {
774 _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
775 }
776 }
777
778
779 /* This is just to support the GL_MESA_window_pos version */
780 static void
781 window_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
782 {
783 GET_CURRENT_CONTEXT(ctx);
784 window_pos3f(x, y, z);
785 ctx->Current.RasterPos[3] = w;
786 }
787
788
789 void GLAPIENTRY
790 _mesa_WindowPos2dMESA(GLdouble x, GLdouble y)
791 {
792 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
793 }
794
795 void GLAPIENTRY
796 _mesa_WindowPos2fMESA(GLfloat x, GLfloat y)
797 {
798 window_pos4f(x, y, 0.0F, 1.0F);
799 }
800
801 void GLAPIENTRY
802 _mesa_WindowPos2iMESA(GLint x, GLint y)
803 {
804 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
805 }
806
807 void GLAPIENTRY
808 _mesa_WindowPos2sMESA(GLshort x, GLshort y)
809 {
810 window_pos4f(x, y, 0.0F, 1.0F);
811 }
812
813 void GLAPIENTRY
814 _mesa_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
815 {
816 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
817 }
818
819 void GLAPIENTRY
820 _mesa_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
821 {
822 window_pos4f(x, y, z, 1.0F);
823 }
824
825 void GLAPIENTRY
826 _mesa_WindowPos3iMESA(GLint x, GLint y, GLint z)
827 {
828 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
829 }
830
831 void GLAPIENTRY
832 _mesa_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
833 {
834 window_pos4f(x, y, z, 1.0F);
835 }
836
837 void GLAPIENTRY
838 _mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
839 {
840 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
841 }
842
843 void GLAPIENTRY
844 _mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
845 {
846 window_pos4f(x, y, z, w);
847 }
848
849 void GLAPIENTRY
850 _mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
851 {
852 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
853 }
854
855 void GLAPIENTRY
856 _mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
857 {
858 window_pos4f(x, y, z, w);
859 }
860
861 void GLAPIENTRY
862 _mesa_WindowPos2dvMESA(const GLdouble *v)
863 {
864 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
865 }
866
867 void GLAPIENTRY
868 _mesa_WindowPos2fvMESA(const GLfloat *v)
869 {
870 window_pos4f(v[0], v[1], 0.0F, 1.0F);
871 }
872
873 void GLAPIENTRY
874 _mesa_WindowPos2ivMESA(const GLint *v)
875 {
876 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
877 }
878
879 void GLAPIENTRY
880 _mesa_WindowPos2svMESA(const GLshort *v)
881 {
882 window_pos4f(v[0], v[1], 0.0F, 1.0F);
883 }
884
885 void GLAPIENTRY
886 _mesa_WindowPos3dvMESA(const GLdouble *v)
887 {
888 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
889 }
890
891 void GLAPIENTRY
892 _mesa_WindowPos3fvMESA(const GLfloat *v)
893 {
894 window_pos4f(v[0], v[1], v[2], 1.0);
895 }
896
897 void GLAPIENTRY
898 _mesa_WindowPos3ivMESA(const GLint *v)
899 {
900 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
901 }
902
903 void GLAPIENTRY
904 _mesa_WindowPos3svMESA(const GLshort *v)
905 {
906 window_pos4f(v[0], v[1], v[2], 1.0F);
907 }
908
909 void GLAPIENTRY
910 _mesa_WindowPos4dvMESA(const GLdouble *v)
911 {
912 window_pos4f((GLfloat) v[0], (GLfloat) v[1],
913 (GLfloat) v[2], (GLfloat) v[3]);
914 }
915
916 void GLAPIENTRY
917 _mesa_WindowPos4fvMESA(const GLfloat *v)
918 {
919 window_pos4f(v[0], v[1], v[2], v[3]);
920 }
921
922 void GLAPIENTRY
923 _mesa_WindowPos4ivMESA(const GLint *v)
924 {
925 window_pos4f((GLfloat) v[0], (GLfloat) v[1],
926 (GLfloat) v[2], (GLfloat) v[3]);
927 }
928
929 void GLAPIENTRY
930 _mesa_WindowPos4svMESA(const GLshort *v)
931 {
932 window_pos4f(v[0], v[1], v[2], v[3]);
933 }
934
935 #endif
936
937 #if 0
938
939 /*
940 * OpenGL implementation of glWindowPos*MESA()
941 */
942 void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
943 {
944 GLfloat fx, fy;
945
946 /* Push current matrix mode and viewport attributes */
947 glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
948
949 /* Setup projection parameters */
950 glMatrixMode( GL_PROJECTION );
951 glPushMatrix();
952 glLoadIdentity();
953 glMatrixMode( GL_MODELVIEW );
954 glPushMatrix();
955 glLoadIdentity();
956
957 glDepthRange( z, z );
958 glViewport( (int) x - 1, (int) y - 1, 2, 2 );
959
960 /* set the raster (window) position */
961 fx = x - (int) x;
962 fy = y - (int) y;
963 glRasterPos4f( fx, fy, 0.0, w );
964
965 /* restore matrices, viewport and matrix mode */
966 glPopMatrix();
967 glMatrixMode( GL_PROJECTION );
968 glPopMatrix();
969
970 glPopAttrib();
971 }
972
973 #endif
974
975
976 /**********************************************************************/
977 /** \name Initialization */
978 /**********************************************************************/
979 /*@{*/
980
981 /**
982 * Initialize the context current raster position information.
983 *
984 * \param ctx GL context.
985 *
986 * Initialize the current raster position information in
987 * __GLcontextRec::Current, and adds the extension entry points to the
988 * dispatcher.
989 */
990 void _mesa_init_rastpos( GLcontext * ctx )
991 {
992 int i;
993
994 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
995 ctx->Current.RasterDistance = 0.0;
996 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
997 ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 );
998 ctx->Current.RasterIndex = 1.0;
999 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1000 ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
1001 ctx->Current.RasterPosValid = GL_TRUE;
1002 }
1003
1004 /*@}*/