home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / MesaDLL / rastpos.cpp < prev    next >
C/C++ Source or Header  |  2002-10-24  |  20KB  |  789 lines

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