[3598] | 1 | /* $Id: rastpos.c,v 1.3 2000-05-23 20:40:52 jeroen Exp $ */
|
---|
[2938] | 2 |
|
---|
| 3 | /*
|
---|
| 4 | * Mesa 3-D graphics library
|
---|
[3598] | 5 | * Version: 3.3
|
---|
[2938] | 6 | *
|
---|
| 7 | * Copyright (C) 1999 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 |
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | #ifdef PC_HEADER
|
---|
| 32 | #include "all.h"
|
---|
| 33 | #else
|
---|
[3598] | 34 | #include "glheader.h"
|
---|
[2938] | 35 | #include "clip.h"
|
---|
[2962] | 36 | #include "types.h"
|
---|
[2938] | 37 | #include "context.h"
|
---|
| 38 | #include "feedback.h"
|
---|
| 39 | #include "light.h"
|
---|
| 40 | #include "macros.h"
|
---|
| 41 | #include "matrix.h"
|
---|
| 42 | #include "mmath.h"
|
---|
| 43 | #include "rastpos.h"
|
---|
| 44 | #include "shade.h"
|
---|
| 45 | #include "xform.h"
|
---|
[3598] | 46 | #include "state.h"
|
---|
[2938] | 47 | #endif
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | /*
|
---|
| 51 | * Caller: context->API.RasterPos4f
|
---|
| 52 | */
|
---|
[3598] | 53 | static void raster_pos4f( GLcontext *ctx,
|
---|
| 54 | GLfloat x, GLfloat y, GLfloat z, GLfloat w )
|
---|
[2938] | 55 | {
|
---|
| 56 | GLfloat v[4], eye[4], clip[4], ndc[3], d;
|
---|
| 57 |
|
---|
| 58 | /* KW: Added this test, which is in the spec. We can't do this
|
---|
| 59 | * outside begin/end any more because the ctx->Current values
|
---|
| 60 | * aren't uptodate during that period.
|
---|
| 61 | */
|
---|
| 62 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, "glRasterPos" );
|
---|
| 63 |
|
---|
| 64 | if (ctx->NewState)
|
---|
| 65 | gl_update_state( ctx );
|
---|
| 66 |
|
---|
| 67 | ASSIGN_4V( v, x, y, z, w );
|
---|
| 68 | TRANSFORM_POINT( eye, ctx->ModelView.m, v );
|
---|
| 69 |
|
---|
| 70 | /* raster color */
|
---|
| 71 | if (ctx->Light.Enabled)
|
---|
| 72 | {
|
---|
| 73 | /*GLfloat *vert;*/
|
---|
| 74 | GLfloat *norm, eyenorm[3];
|
---|
| 75 | GLfloat *objnorm = ctx->Current.Normal;
|
---|
| 76 |
|
---|
[3598] | 77 | /* Not needed???
|
---|
[2938] | 78 | vert = (ctx->NeedEyeCoords ? eye : v);
|
---|
[3598] | 79 | */
|
---|
[2938] | 80 |
|
---|
| 81 | if (ctx->NeedEyeNormals) {
|
---|
[3598] | 82 | GLfloat *inv = ctx->ModelView.inv;
|
---|
| 83 | TRANSFORM_NORMAL( eyenorm, objnorm, inv );
|
---|
| 84 | norm = eyenorm;
|
---|
[2938] | 85 | } else {
|
---|
[3598] | 86 | norm = objnorm;
|
---|
[2938] | 87 | }
|
---|
| 88 |
|
---|
| 89 | gl_shade_rastpos( ctx, v, norm,
|
---|
[3598] | 90 | ctx->Current.RasterColor,
|
---|
| 91 | &ctx->Current.RasterIndex );
|
---|
[2938] | 92 |
|
---|
| 93 | }
|
---|
| 94 | else {
|
---|
| 95 | /* use current color or index */
|
---|
| 96 | if (ctx->Visual->RGBAflag) {
|
---|
[3598] | 97 | UBYTE_RGBA_TO_FLOAT_RGBA(ctx->Current.RasterColor,
|
---|
| 98 | ctx->Current.ByteColor);
|
---|
[2938] | 99 | }
|
---|
| 100 | else {
|
---|
[3598] | 101 | ctx->Current.RasterIndex = ctx->Current.Index;
|
---|
[2938] | 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | /* compute raster distance */
|
---|
| 106 | ctx->Current.RasterDistance = (GLfloat)
|
---|
| 107 | GL_SQRT( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
|
---|
| 108 |
|
---|
| 109 | /* apply projection matrix: clip = Proj * eye */
|
---|
| 110 | TRANSFORM_POINT( clip, ctx->ProjectionMatrix.m, eye );
|
---|
| 111 |
|
---|
| 112 | /* clip to view volume */
|
---|
| 113 | if (gl_viewclip_point( clip )==0) {
|
---|
| 114 | ctx->Current.RasterPosValid = GL_FALSE;
|
---|
| 115 | return;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | /* clip to user clipping planes */
|
---|
| 119 | if ( ctx->Transform.AnyClip &&
|
---|
[3598] | 120 | gl_userclip_point(ctx, clip) == 0)
|
---|
[2938] | 121 | {
|
---|
| 122 | ctx->Current.RasterPosValid = GL_FALSE;
|
---|
| 123 | return;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | /* ndc = clip / W */
|
---|
| 127 | ASSERT( clip[3]!=0.0 );
|
---|
| 128 | d = 1.0F / clip[3];
|
---|
| 129 | ndc[0] = clip[0] * d;
|
---|
| 130 | ndc[1] = clip[1] * d;
|
---|
| 131 | ndc[2] = clip[2] * d;
|
---|
| 132 |
|
---|
| 133 | ctx->Current.RasterPos[0] = (ndc[0] * ctx->Viewport.WindowMap.m[MAT_SX] +
|
---|
[3598] | 134 | ctx->Viewport.WindowMap.m[MAT_TX]);
|
---|
[2938] | 135 | ctx->Current.RasterPos[1] = (ndc[1] * ctx->Viewport.WindowMap.m[MAT_SY] +
|
---|
[3598] | 136 | ctx->Viewport.WindowMap.m[MAT_TY]);
|
---|
[2938] | 137 | ctx->Current.RasterPos[2] = (ndc[2] * ctx->Viewport.WindowMap.m[MAT_SZ] +
|
---|
[3598] | 138 | ctx->Viewport.WindowMap.m[MAT_TZ]) / ctx->Visual->DepthMaxF;
|
---|
[2938] | 139 | ctx->Current.RasterPos[3] = clip[3];
|
---|
| 140 | ctx->Current.RasterPosValid = GL_TRUE;
|
---|
| 141 |
|
---|
| 142 | /* FOG??? */
|
---|
| 143 |
|
---|
| 144 | {
|
---|
| 145 | GLuint texSet;
|
---|
| 146 | for (texSet=0; texSet<MAX_TEXTURE_UNITS; texSet++) {
|
---|
| 147 | COPY_4FV( ctx->Current.RasterMultiTexCoord[texSet],
|
---|
| 148 | ctx->Current.Texcoord[texSet] );
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | if (ctx->RenderMode==GL_SELECT) {
|
---|
| 153 | gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 |
|
---|
[3598] | 160 | void
|
---|
| 161 | _mesa_RasterPos2d(GLdouble x, GLdouble y)
|
---|
[2938] | 162 | {
|
---|
[3598] | 163 | _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
|
---|
| 164 | }
|
---|
[2938] | 165 |
|
---|
[3598] | 166 | void
|
---|
| 167 | _mesa_RasterPos2f(GLfloat x, GLfloat y)
|
---|
| 168 | {
|
---|
| 169 | _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
|
---|
| 170 | }
|
---|
[2938] | 171 |
|
---|
[3598] | 172 | void
|
---|
| 173 | _mesa_RasterPos2i(GLint x, GLint y)
|
---|
| 174 | {
|
---|
| 175 | _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
|
---|
| 176 | }
|
---|
[2938] | 177 |
|
---|
[3598] | 178 | void
|
---|
| 179 | _mesa_RasterPos2s(GLshort x, GLshort y)
|
---|
| 180 | {
|
---|
| 181 | _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
|
---|
| 182 | }
|
---|
[2938] | 183 |
|
---|
[3598] | 184 | void
|
---|
| 185 | _mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
|
---|
| 186 | {
|
---|
| 187 | _mesa_RasterPos4f(x, y, z, 1.0F);
|
---|
| 188 | }
|
---|
[2938] | 189 |
|
---|
[3598] | 190 | void
|
---|
| 191 | _mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
|
---|
| 192 | {
|
---|
| 193 | _mesa_RasterPos4f(x, y, z, 1.0F);
|
---|
| 194 | }
|
---|
[2938] | 195 |
|
---|
[3598] | 196 | void
|
---|
| 197 | _mesa_RasterPos3i(GLint x, GLint y, GLint z)
|
---|
| 198 | {
|
---|
| 199 | _mesa_RasterPos4f(x, y, z, 1.0F);
|
---|
| 200 | }
|
---|
[2938] | 201 |
|
---|
[3598] | 202 | void
|
---|
| 203 | _mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
|
---|
| 204 | {
|
---|
| 205 | _mesa_RasterPos4f(x, y, z, 1.0F);
|
---|
| 206 | }
|
---|
[2938] | 207 |
|
---|
[3598] | 208 | void
|
---|
| 209 | _mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
|
---|
| 210 | {
|
---|
| 211 | _mesa_RasterPos4f(x, y, z, w);
|
---|
[2938] | 212 | }
|
---|
[3598] | 213 |
|
---|
| 214 | void
|
---|
| 215 | _mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
|
---|
| 216 | {
|
---|
| 217 | GET_CURRENT_CONTEXT(ctx);
|
---|
| 218 | raster_pos4f(ctx, x, y, z, w);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | void
|
---|
| 222 | _mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
|
---|
| 223 | {
|
---|
| 224 | _mesa_RasterPos4f(x, y, z, w);
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | void
|
---|
| 228 | _mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
|
---|
| 229 | {
|
---|
| 230 | _mesa_RasterPos4f(x, y, z, w);
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | void
|
---|
| 234 | _mesa_RasterPos2dv(const GLdouble *v)
|
---|
| 235 | {
|
---|
| 236 | _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | void
|
---|
| 240 | _mesa_RasterPos2fv(const GLfloat *v)
|
---|
| 241 | {
|
---|
| 242 | _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | void
|
---|
| 246 | _mesa_RasterPos2iv(const GLint *v)
|
---|
| 247 | {
|
---|
| 248 | _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | void
|
---|
| 252 | _mesa_RasterPos2sv(const GLshort *v)
|
---|
| 253 | {
|
---|
| 254 | _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | void
|
---|
| 258 | _mesa_RasterPos3dv(const GLdouble *v)
|
---|
| 259 | {
|
---|
| 260 | _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | void
|
---|
| 264 | _mesa_RasterPos3fv(const GLfloat *v)
|
---|
| 265 | {
|
---|
| 266 | _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | void
|
---|
| 270 | _mesa_RasterPos3iv(const GLint *v)
|
---|
| 271 | {
|
---|
| 272 | _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | void
|
---|
| 276 | _mesa_RasterPos3sv(const GLshort *v)
|
---|
| 277 | {
|
---|
| 278 | _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | void
|
---|
| 282 | _mesa_RasterPos4dv(const GLdouble *v)
|
---|
| 283 | {
|
---|
| 284 | _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | void
|
---|
| 288 | _mesa_RasterPos4fv(const GLfloat *v)
|
---|
| 289 | {
|
---|
| 290 | _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | void
|
---|
| 294 | _mesa_RasterPos4iv(const GLint *v)
|
---|
| 295 | {
|
---|
| 296 | _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | void
|
---|
| 300 | _mesa_RasterPos4sv(const GLshort *v)
|
---|
| 301 | {
|
---|
| 302 | _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
|
---|
| 303 | }
|
---|