2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
28 * Raster position operations.
39 #include "simple_list.h"
42 #include "math/m_matrix.h"
46 * Clip a point against the view volume.
48 * \param v vertex vector describing the point to clip.
50 * \return zero if outside view volume, or one if inside.
53 viewclip_point( const GLfloat v[] )
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] ) {
67 * Clip a point against the far/near Z clipping planes.
69 * \param v vertex vector describing the point to clip.
71 * \return zero if outside view volume, or one if inside.
74 viewclip_point_z( const GLfloat v[] )
76 if (v[2] > v[3] || v[2] < -v[3] ) {
86 * Clip a point against the user clipping planes.
88 * \param ctx GL context.
89 * \param v vertex vector describing the point to clip.
91 * \return zero if the point was clipped, or one otherwise.
94 userclip_point( GLcontext *ctx, const GLfloat v[] )
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];
115 * Compute lighting for the raster position. Both RGB and CI modes computed.
116 * \param ctx the context
117 * \param vertex vertex location
118 * \param normal normal vector
119 * \param Rcolor returned color
120 * \param Rspec returned specular color (if separate specular enabled)
121 * \param Rindex returned color index
124 shade_rastpos(GLcontext *ctx,
125 const GLfloat vertex[4],
126 const GLfloat normal[3],
131 /*const*/ GLfloat (*base)[3] = ctx->Light._BaseColor;
132 const struct gl_light *light;
133 GLfloat diffuseColor[4], specularColor[4]; /* for RGB mode only */
134 GLfloat diffuseCI = 0.0, specularCI = 0.0; /* for CI mode only */
136 _mesa_validate_all_lighting_tables( ctx );
138 COPY_3V(diffuseColor, base[0]);
139 diffuseColor[3] = CLAMP(
140 ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3], 0.0F, 1.0F );
141 ASSIGN_4V(specularColor, 0.0, 0.0, 0.0, 1.0);
143 foreach (light, &ctx->Light.EnabledList) {
144 GLfloat attenuation = 1.0;
145 GLfloat VP[3]; /* vector from vertex to light pos */
147 GLfloat diffuseContrib[3], specularContrib[3];
149 if (!(light->_Flags & LIGHT_POSITIONAL)) {
150 /* light at infinity */
151 COPY_3V(VP, light->_VP_inf_norm);
152 attenuation = light->_VP_inf_spot_attenuation;
155 /* local/positional light */
158 /* VP = vector from vertex pos to light[i].pos */
159 SUB_3V(VP, light->_Position, vertex);
161 d = (GLfloat) LEN_3FV( VP );
164 GLfloat invd = 1.0F / d;
165 SELF_SCALE_SCALAR_3V(VP, invd);
169 attenuation = 1.0F / (light->ConstantAttenuation + d *
170 (light->LinearAttenuation + d *
171 light->QuadraticAttenuation));
173 if (light->_Flags & LIGHT_SPOT) {
174 GLfloat PV_dot_dir = - DOT3(VP, light->_NormDirection);
176 if (PV_dot_dir<light->_CosCutoff) {
180 double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
182 GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0]
183 + (x-k)*light->_SpotExpTable[k][1]);
189 if (attenuation < 1e-3)
192 n_dot_VP = DOT3( normal, VP );
194 if (n_dot_VP < 0.0F) {
195 ACC_SCALE_SCALAR_3V(diffuseColor, attenuation, light->_MatAmbient[0]);
199 /* Ambient + diffuse */
200 COPY_3V(diffuseContrib, light->_MatAmbient[0]);
201 ACC_SCALE_SCALAR_3V(diffuseContrib, n_dot_VP, light->_MatDiffuse[0]);
202 diffuseCI += n_dot_VP * light->_dli * attenuation;
209 ASSIGN_3V(specularContrib, 0.0, 0.0, 0.0);
211 if (ctx->Light.Model.LocalViewer) {
219 else if (light->_Flags & LIGHT_POSITIONAL) {
220 ACC_3V(VP, ctx->_EyeZDir);
225 h = light->_h_inf_norm;
228 n_dot_h = DOT3(normal, h);
230 if (n_dot_h > 0.0F) {
232 GET_SHINE_TAB_ENTRY( ctx->_ShineTable[0], n_dot_h, spec_coef );
234 if (spec_coef > 1.0e-10) {
235 if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) {
236 ACC_SCALE_SCALAR_3V( specularContrib, spec_coef,
237 light->_MatSpecular[0]);
240 ACC_SCALE_SCALAR_3V( diffuseContrib, spec_coef,
241 light->_MatSpecular[0]);
243 /*assert(light->_sli > 0.0);*/
244 specularCI += spec_coef * light->_sli * attenuation;
249 ACC_SCALE_SCALAR_3V( diffuseColor, attenuation, diffuseContrib );
250 ACC_SCALE_SCALAR_3V( specularColor, attenuation, specularContrib );
253 if (ctx->Visual.rgbMode) {
254 Rcolor[0] = CLAMP(diffuseColor[0], 0.0F, 1.0F);
255 Rcolor[1] = CLAMP(diffuseColor[1], 0.0F, 1.0F);
256 Rcolor[2] = CLAMP(diffuseColor[2], 0.0F, 1.0F);
257 Rcolor[3] = CLAMP(diffuseColor[3], 0.0F, 1.0F);
258 Rspec[0] = CLAMP(specularColor[0], 0.0F, 1.0F);
259 Rspec[1] = CLAMP(specularColor[1], 0.0F, 1.0F);
260 Rspec[2] = CLAMP(specularColor[2], 0.0F, 1.0F);
261 Rspec[3] = CLAMP(specularColor[3], 0.0F, 1.0F);
264 GLfloat *ind = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_INDEXES];
265 GLfloat d_a = ind[MAT_INDEX_DIFFUSE] - ind[MAT_INDEX_AMBIENT];
266 GLfloat s_a = ind[MAT_INDEX_SPECULAR] - ind[MAT_INDEX_AMBIENT];
267 GLfloat i = (ind[MAT_INDEX_AMBIENT]
268 + diffuseCI * (1.0F-specularCI) * d_a
270 if (i > ind[MAT_INDEX_SPECULAR]) {
271 i = ind[MAT_INDEX_SPECULAR];
279 * Do texgen needed for glRasterPos.
280 * \param ctx rendering context
281 * \param vObj object-space vertex coordinate
282 * \param vEye eye-space vertex coordinate
283 * \param normal vertex normal
284 * \param unit texture unit number
285 * \param texcoord incoming texcoord and resulting texcoord
288 compute_texgen(GLcontext *ctx, const GLfloat vObj[4], const GLfloat vEye[4],
289 const GLfloat normal[3], GLuint unit, GLfloat texcoord[4])
291 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
293 /* always compute sphere map terms, just in case */
294 GLfloat u[3], two_nu, rx, ry, rz, m, mInv;
297 two_nu = 2.0F * DOT3(normal, u);
298 rx = u[0] - normal[0] * two_nu;
299 ry = u[1] - normal[1] * two_nu;
300 rz = u[2] - normal[2] * two_nu;
301 m = rx * rx + ry * ry + (rz + 1.0F) * (rz + 1.0F);
303 mInv = 0.5F * _mesa_inv_sqrtf(m);
307 if (texUnit->TexGenEnabled & S_BIT) {
308 switch (texUnit->GenModeS) {
309 case GL_OBJECT_LINEAR:
310 texcoord[0] = DOT4(vObj, texUnit->ObjectPlaneS);
313 texcoord[0] = DOT4(vEye, texUnit->EyePlaneS);
316 texcoord[0] = rx * mInv + 0.5F;
318 case GL_REFLECTION_MAP:
322 texcoord[0] = normal[0];
325 _mesa_problem(ctx, "Bad S texgen in compute_texgen()");
330 if (texUnit->TexGenEnabled & T_BIT) {
331 switch (texUnit->GenModeT) {
332 case GL_OBJECT_LINEAR:
333 texcoord[1] = DOT4(vObj, texUnit->ObjectPlaneT);
336 texcoord[1] = DOT4(vEye, texUnit->EyePlaneT);
339 texcoord[1] = ry * mInv + 0.5F;
341 case GL_REFLECTION_MAP:
345 texcoord[1] = normal[1];
348 _mesa_problem(ctx, "Bad T texgen in compute_texgen()");
353 if (texUnit->TexGenEnabled & R_BIT) {
354 switch (texUnit->GenModeR) {
355 case GL_OBJECT_LINEAR:
356 texcoord[2] = DOT4(vObj, texUnit->ObjectPlaneR);
359 texcoord[2] = DOT4(vEye, texUnit->EyePlaneR);
361 case GL_REFLECTION_MAP:
365 texcoord[2] = normal[2];
368 _mesa_problem(ctx, "Bad R texgen in compute_texgen()");
373 if (texUnit->TexGenEnabled & Q_BIT) {
374 switch (texUnit->GenModeQ) {
375 case GL_OBJECT_LINEAR:
376 texcoord[3] = DOT4(vObj, texUnit->ObjectPlaneQ);
379 texcoord[3] = DOT4(vEye, texUnit->EyePlaneQ);
382 _mesa_problem(ctx, "Bad Q texgen in compute_texgen()");
391 * Set the raster position for pixel operations.
393 * All glRasterPos command call this function to update the current
396 * \param ctx GL context.
397 * \param x x coordinate for the raster position.
398 * \param y y coordinate for the raster position.
399 * \param z z coordinate for the raster position.
400 * \param w w coordinate for the raster position.
402 * \sa Called by _mesa_RasterPos4f().
404 * Flushes the vertices, transforms and clips the vertex coordinates, and
405 * finally sets the current raster position and associated data in
406 * __GLcontextRec::Current. When in selection mode calls
407 * _mesa_update_hitflag() with the current raster position.
410 raster_pos4f(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
412 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
413 FLUSH_CURRENT(ctx, 0);
416 _mesa_update_state( ctx );
418 if (ctx->VertexProgram._Enabled) {
419 /* XXX implement this */
420 _mesa_problem(ctx, "Vertex programs not implemented for glRasterPos");
424 GLfloat obj[4], eye[4], clip[4], ndc[3], d;
425 GLfloat *norm, eyenorm[3];
426 GLfloat *objnorm = ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
428 ASSIGN_4V( obj, x, y, z, w );
429 /* apply modelview matrix: eye = MV * obj */
430 TRANSFORM_POINT( eye, ctx->ModelviewMatrixStack.Top->m, obj );
431 /* apply projection matrix: clip = Proj * eye */
432 TRANSFORM_POINT( clip, ctx->ProjectionMatrixStack.Top->m, eye );
434 /* clip to view volume */
435 if (ctx->Transform.RasterPositionUnclipped) {
436 /* GL_IBM_rasterpos_clip: only clip against Z */
437 if (viewclip_point_z(clip) == 0) {
438 ctx->Current.RasterPosValid = GL_FALSE;
442 else if (viewclip_point(clip) == 0) {
443 /* Normal OpenGL behaviour */
444 ctx->Current.RasterPosValid = GL_FALSE;
448 /* clip to user clipping planes */
449 if (ctx->Transform.ClipPlanesEnabled && !userclip_point(ctx, clip)) {
450 ctx->Current.RasterPosValid = GL_FALSE;
455 d = (clip[3] == 0.0F) ? 1.0F : 1.0F / clip[3];
456 ndc[0] = clip[0] * d;
457 ndc[1] = clip[1] * d;
458 ndc[2] = clip[2] * d;
459 /* wincoord = viewport_mapping(ndc) */
460 ctx->Current.RasterPos[0] = (ndc[0] * ctx->Viewport._WindowMap.m[MAT_SX]
461 + ctx->Viewport._WindowMap.m[MAT_TX]);
462 ctx->Current.RasterPos[1] = (ndc[1] * ctx->Viewport._WindowMap.m[MAT_SY]
463 + ctx->Viewport._WindowMap.m[MAT_TY]);
464 ctx->Current.RasterPos[2] = (ndc[2] * ctx->Viewport._WindowMap.m[MAT_SZ]
465 + ctx->Viewport._WindowMap.m[MAT_TZ])
466 / ctx->DrawBuffer->_DepthMaxF;
467 ctx->Current.RasterPos[3] = clip[3];
469 /* compute raster distance */
470 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
471 ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
473 ctx->Current.RasterDistance =
474 SQRTF( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
476 /* compute transformed normal vector (for lighting or texgen) */
477 if (ctx->_NeedEyeCoords) {
478 const GLfloat *inv = ctx->ModelviewMatrixStack.Top->inv;
479 TRANSFORM_NORMAL( eyenorm, objnorm, inv );
486 /* update raster color */
487 if (ctx->Light.Enabled) {
489 shade_rastpos( ctx, obj, norm,
490 ctx->Current.RasterColor,
491 ctx->Current.RasterSecondaryColor,
492 &ctx->Current.RasterIndex );
495 /* use current color or index */
496 if (ctx->Visual.rgbMode) {
497 COPY_4FV(ctx->Current.RasterColor,
498 ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
499 COPY_4FV(ctx->Current.RasterSecondaryColor,
500 ctx->Current.Attrib[VERT_ATTRIB_COLOR1]);
503 ctx->Current.RasterIndex
504 = ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0];
511 for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) {
513 COPY_4V(tc, ctx->Current.Attrib[VERT_ATTRIB_TEX0 + u]);
514 if (ctx->Texture.Unit[u].TexGenEnabled) {
515 compute_texgen(ctx, obj, eye, norm, u, tc);
517 TRANSFORM_POINT(ctx->Current.RasterTexCoords[u],
518 ctx->TextureMatrixStack[u].Top->m, tc);
522 ctx->Current.RasterPosValid = GL_TRUE;
525 if (ctx->RenderMode == GL_SELECT) {
526 _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
531 /** Calls _mesa_RasterPos4f() */
533 _mesa_RasterPos2d(GLdouble x, GLdouble y)
535 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
538 /** Calls _mesa_RasterPos4f() */
540 _mesa_RasterPos2f(GLfloat x, GLfloat y)
542 _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
545 /** Calls _mesa_RasterPos4f() */
547 _mesa_RasterPos2i(GLint x, GLint y)
549 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
552 /** Calls _mesa_RasterPos4f() */
554 _mesa_RasterPos2s(GLshort x, GLshort y)
556 _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
559 /** Calls _mesa_RasterPos4f() */
561 _mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
563 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
566 /** Calls _mesa_RasterPos4f() */
568 _mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
570 _mesa_RasterPos4f(x, y, z, 1.0F);
573 /** Calls _mesa_RasterPos4f() */
575 _mesa_RasterPos3i(GLint x, GLint y, GLint z)
577 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
580 /** Calls _mesa_RasterPos4f() */
582 _mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
584 _mesa_RasterPos4f(x, y, z, 1.0F);
587 /** Calls _mesa_RasterPos4f() */
589 _mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
591 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
594 /** Calls raster_pos4f() */
596 _mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
598 GET_CURRENT_CONTEXT(ctx);
599 raster_pos4f(ctx, x, y, z, w);
602 /** Calls _mesa_RasterPos4f() */
604 _mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
606 _mesa_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
609 /** Calls _mesa_RasterPos4f() */
611 _mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
613 _mesa_RasterPos4f(x, y, z, w);
616 /** Calls _mesa_RasterPos4f() */
618 _mesa_RasterPos2dv(const GLdouble *v)
620 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
623 /** Calls _mesa_RasterPos4f() */
625 _mesa_RasterPos2fv(const GLfloat *v)
627 _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
630 /** Calls _mesa_RasterPos4f() */
632 _mesa_RasterPos2iv(const GLint *v)
634 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
637 /** Calls _mesa_RasterPos4f() */
639 _mesa_RasterPos2sv(const GLshort *v)
641 _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
644 /** Calls _mesa_RasterPos4f() */
646 _mesa_RasterPos3dv(const GLdouble *v)
648 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
651 /** Calls _mesa_RasterPos4f() */
653 _mesa_RasterPos3fv(const GLfloat *v)
655 _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
658 /** Calls _mesa_RasterPos4f() */
660 _mesa_RasterPos3iv(const GLint *v)
662 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
665 /** Calls _mesa_RasterPos4f() */
667 _mesa_RasterPos3sv(const GLshort *v)
669 _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
672 /** Calls _mesa_RasterPos4f() */
674 _mesa_RasterPos4dv(const GLdouble *v)
676 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
677 (GLfloat) v[2], (GLfloat) v[3]);
680 /** Calls _mesa_RasterPos4f() */
682 _mesa_RasterPos4fv(const GLfloat *v)
684 _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
687 /** Calls _mesa_RasterPos4f() */
689 _mesa_RasterPos4iv(const GLint *v)
691 _mesa_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
692 (GLfloat) v[2], (GLfloat) v[3]);
695 /** Calls _mesa_RasterPos4f() */
697 _mesa_RasterPos4sv(const GLshort *v)
699 _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
703 /**********************************************************************/
704 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
705 /**********************************************************************/
707 #if FEATURE_windowpos
709 * All glWindowPosMESA and glWindowPosARB commands call this function to
710 * update the current raster position.
713 window_pos3f(GLfloat x, GLfloat y, GLfloat z)
715 GET_CURRENT_CONTEXT(ctx);
718 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
719 FLUSH_CURRENT(ctx, 0);
721 z2 = CLAMP(z, 0.0F, 1.0F) * (ctx->Viewport.Far - ctx->Viewport.Near)
722 + ctx->Viewport.Near;
724 /* set raster position */
725 ctx->Current.RasterPos[0] = x;
726 ctx->Current.RasterPos[1] = y;
727 ctx->Current.RasterPos[2] = z2;
728 ctx->Current.RasterPos[3] = 1.0F;
730 ctx->Current.RasterPosValid = GL_TRUE;
732 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
733 ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
735 ctx->Current.RasterDistance = 0.0;
737 /* raster color = current color or index */
738 if (ctx->Visual.rgbMode) {
739 ctx->Current.RasterColor[0]
740 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0], 0.0F, 1.0F);
741 ctx->Current.RasterColor[1]
742 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][1], 0.0F, 1.0F);
743 ctx->Current.RasterColor[2]
744 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][2], 0.0F, 1.0F);
745 ctx->Current.RasterColor[3]
746 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3], 0.0F, 1.0F);
747 ctx->Current.RasterSecondaryColor[0]
748 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0], 0.0F, 1.0F);
749 ctx->Current.RasterSecondaryColor[1]
750 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1], 0.0F, 1.0F);
751 ctx->Current.RasterSecondaryColor[2]
752 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][2], 0.0F, 1.0F);
753 ctx->Current.RasterSecondaryColor[3]
754 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][3], 0.0F, 1.0F);
757 ctx->Current.RasterIndex
758 = ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0];
761 /* raster texcoord = current texcoord */
764 for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) {
765 COPY_4FV( ctx->Current.RasterTexCoords[texSet],
766 ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] );
770 if (ctx->RenderMode==GL_SELECT) {
771 _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
776 /* This is just to support the GL_MESA_window_pos version */
778 window_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
780 GET_CURRENT_CONTEXT(ctx);
781 window_pos3f(x, y, z);
782 ctx->Current.RasterPos[3] = w;
787 _mesa_WindowPos2dMESA(GLdouble x, GLdouble y)
789 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
793 _mesa_WindowPos2fMESA(GLfloat x, GLfloat y)
795 window_pos4f(x, y, 0.0F, 1.0F);
799 _mesa_WindowPos2iMESA(GLint x, GLint y)
801 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
805 _mesa_WindowPos2sMESA(GLshort x, GLshort y)
807 window_pos4f(x, y, 0.0F, 1.0F);
811 _mesa_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
813 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
817 _mesa_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
819 window_pos4f(x, y, z, 1.0F);
823 _mesa_WindowPos3iMESA(GLint x, GLint y, GLint z)
825 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
829 _mesa_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
831 window_pos4f(x, y, z, 1.0F);
835 _mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
837 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
841 _mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
843 window_pos4f(x, y, z, w);
847 _mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
849 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
853 _mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
855 window_pos4f(x, y, z, w);
859 _mesa_WindowPos2dvMESA(const GLdouble *v)
861 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
865 _mesa_WindowPos2fvMESA(const GLfloat *v)
867 window_pos4f(v[0], v[1], 0.0F, 1.0F);
871 _mesa_WindowPos2ivMESA(const GLint *v)
873 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
877 _mesa_WindowPos2svMESA(const GLshort *v)
879 window_pos4f(v[0], v[1], 0.0F, 1.0F);
883 _mesa_WindowPos3dvMESA(const GLdouble *v)
885 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
889 _mesa_WindowPos3fvMESA(const GLfloat *v)
891 window_pos4f(v[0], v[1], v[2], 1.0);
895 _mesa_WindowPos3ivMESA(const GLint *v)
897 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
901 _mesa_WindowPos3svMESA(const GLshort *v)
903 window_pos4f(v[0], v[1], v[2], 1.0F);
907 _mesa_WindowPos4dvMESA(const GLdouble *v)
909 window_pos4f((GLfloat) v[0], (GLfloat) v[1],
910 (GLfloat) v[2], (GLfloat) v[3]);
914 _mesa_WindowPos4fvMESA(const GLfloat *v)
916 window_pos4f(v[0], v[1], v[2], v[3]);
920 _mesa_WindowPos4ivMESA(const GLint *v)
922 window_pos4f((GLfloat) v[0], (GLfloat) v[1],
923 (GLfloat) v[2], (GLfloat) v[3]);
927 _mesa_WindowPos4svMESA(const GLshort *v)
929 window_pos4f(v[0], v[1], v[2], v[3]);
937 * OpenGL implementation of glWindowPos*MESA()
939 void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
943 /* Push current matrix mode and viewport attributes */
944 glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
946 /* Setup projection parameters */
947 glMatrixMode( GL_PROJECTION );
950 glMatrixMode( GL_MODELVIEW );
954 glDepthRange( z, z );
955 glViewport( (int) x - 1, (int) y - 1, 2, 2 );
957 /* set the raster (window) position */
960 glRasterPos4f( fx, fy, 0.0, w );
962 /* restore matrices, viewport and matrix mode */
964 glMatrixMode( GL_PROJECTION );
973 /**********************************************************************/
974 /** \name Initialization */
975 /**********************************************************************/
979 * Initialize the context current raster position information.
981 * \param ctx GL context.
983 * Initialize the current raster position information in
984 * __GLcontextRec::Current, and adds the extension entry points to the
987 void _mesa_init_rastpos( GLcontext * ctx )
991 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
992 ctx->Current.RasterDistance = 0.0;
993 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
994 ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 );
995 ctx->Current.RasterIndex = 1.0;
996 for (i=0; i<MAX_TEXTURE_UNITS; i++)
997 ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
998 ctx->Current.RasterPosValid = GL_TRUE;