| 1 | /* $Id: rastpos.c,v 1.2 2000-03-01 18:49:35 jeroen Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Mesa 3-D graphics library
|
|---|
| 5 | * Version: 3.1
|
|---|
| 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
|
|---|
| 34 | #ifndef XFree86Server
|
|---|
| 35 | #include <assert.h>
|
|---|
| 36 | #include <math.h>
|
|---|
| 37 | #else
|
|---|
| 38 | #include "GL/xf86glx.h"
|
|---|
| 39 | #endif
|
|---|
| 40 | #include "clip.h"
|
|---|
| 41 | #include "types.h"
|
|---|
| 42 | #include "context.h"
|
|---|
| 43 | #include "feedback.h"
|
|---|
| 44 | #include "light.h"
|
|---|
| 45 | #include "macros.h"
|
|---|
| 46 | #include "matrix.h"
|
|---|
| 47 | #include "mmath.h"
|
|---|
| 48 | #include "rastpos.h"
|
|---|
| 49 | #include "shade.h"
|
|---|
| 50 | #include "xform.h"
|
|---|
| 51 | #endif
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 | /*
|
|---|
| 55 | * Caller: context->API.RasterPos4f
|
|---|
| 56 | */
|
|---|
| 57 | void gl_RasterPos4f( GLcontext *ctx,
|
|---|
| 58 | GLfloat x, GLfloat y, GLfloat z, GLfloat w )
|
|---|
| 59 | {
|
|---|
| 60 | GLfloat v[4], eye[4], clip[4], ndc[3], d;
|
|---|
| 61 |
|
|---|
| 62 | /* KW: Added this test, which is in the spec. We can't do this
|
|---|
| 63 | * outside begin/end any more because the ctx->Current values
|
|---|
| 64 | * aren't uptodate during that period.
|
|---|
| 65 | */
|
|---|
| 66 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, "glRasterPos" );
|
|---|
| 67 |
|
|---|
| 68 | if (ctx->NewState)
|
|---|
| 69 | gl_update_state( ctx );
|
|---|
| 70 |
|
|---|
| 71 | ASSIGN_4V( v, x, y, z, w );
|
|---|
| 72 | TRANSFORM_POINT( eye, ctx->ModelView.m, v );
|
|---|
| 73 |
|
|---|
| 74 | /* raster color */
|
|---|
| 75 | if (ctx->Light.Enabled)
|
|---|
| 76 | {
|
|---|
| 77 | /*GLfloat *vert;*/
|
|---|
| 78 | GLfloat *norm, eyenorm[3];
|
|---|
| 79 | GLfloat *objnorm = ctx->Current.Normal;
|
|---|
| 80 |
|
|---|
| 81 | /* Not needed???
|
|---|
| 82 | vert = (ctx->NeedEyeCoords ? eye : v);
|
|---|
| 83 | */
|
|---|
| 84 |
|
|---|
| 85 | if (ctx->NeedEyeNormals) {
|
|---|
| 86 | GLfloat *inv = ctx->ModelView.inv;
|
|---|
| 87 | TRANSFORM_NORMAL( eyenorm, objnorm, inv );
|
|---|
| 88 | norm = eyenorm;
|
|---|
| 89 | } else {
|
|---|
| 90 | norm = objnorm;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | gl_shade_rastpos( ctx, v, norm,
|
|---|
| 94 | ctx->Current.RasterColor,
|
|---|
| 95 | &ctx->Current.RasterIndex );
|
|---|
| 96 |
|
|---|
| 97 | }
|
|---|
| 98 | else {
|
|---|
| 99 | /* use current color or index */
|
|---|
| 100 | if (ctx->Visual->RGBAflag) {
|
|---|
| 101 | UBYTE_RGBA_TO_FLOAT_RGBA(ctx->Current.RasterColor,
|
|---|
| 102 | ctx->Current.ByteColor);
|
|---|
| 103 | }
|
|---|
| 104 | else {
|
|---|
| 105 | ctx->Current.RasterIndex = ctx->Current.Index;
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | /* compute raster distance */
|
|---|
| 110 | ctx->Current.RasterDistance = (GLfloat)
|
|---|
| 111 | GL_SQRT( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
|
|---|
| 112 |
|
|---|
| 113 | /* apply projection matrix: clip = Proj * eye */
|
|---|
| 114 | TRANSFORM_POINT( clip, ctx->ProjectionMatrix.m, eye );
|
|---|
| 115 |
|
|---|
| 116 | /* clip to view volume */
|
|---|
| 117 | if (gl_viewclip_point( clip )==0) {
|
|---|
| 118 | ctx->Current.RasterPosValid = GL_FALSE;
|
|---|
| 119 | return;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | /* clip to user clipping planes */
|
|---|
| 123 | if ( ctx->Transform.AnyClip &&
|
|---|
| 124 | gl_userclip_point(ctx, clip) == 0)
|
|---|
| 125 | {
|
|---|
| 126 | ctx->Current.RasterPosValid = GL_FALSE;
|
|---|
| 127 | return;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | /* ndc = clip / W */
|
|---|
| 131 | ASSERT( clip[3]!=0.0 );
|
|---|
| 132 | d = 1.0F / clip[3];
|
|---|
| 133 | ndc[0] = clip[0] * d;
|
|---|
| 134 | ndc[1] = clip[1] * d;
|
|---|
| 135 | ndc[2] = clip[2] * d;
|
|---|
| 136 |
|
|---|
| 137 | ctx->Current.RasterPos[0] = (ndc[0] * ctx->Viewport.WindowMap.m[MAT_SX] +
|
|---|
| 138 | ctx->Viewport.WindowMap.m[MAT_TX]);
|
|---|
| 139 | ctx->Current.RasterPos[1] = (ndc[1] * ctx->Viewport.WindowMap.m[MAT_SY] +
|
|---|
| 140 | ctx->Viewport.WindowMap.m[MAT_TY]);
|
|---|
| 141 | ctx->Current.RasterPos[2] = (ndc[2] * ctx->Viewport.WindowMap.m[MAT_SZ] +
|
|---|
| 142 | ctx->Viewport.WindowMap.m[MAT_TZ]) / DEPTH_SCALE;
|
|---|
| 143 | ctx->Current.RasterPos[3] = clip[3];
|
|---|
| 144 | ctx->Current.RasterPosValid = GL_TRUE;
|
|---|
| 145 |
|
|---|
| 146 | /* FOG??? */
|
|---|
| 147 |
|
|---|
| 148 | {
|
|---|
| 149 | GLuint texSet;
|
|---|
| 150 | for (texSet=0; texSet<MAX_TEXTURE_UNITS; texSet++) {
|
|---|
| 151 | COPY_4FV( ctx->Current.RasterMultiTexCoord[texSet],
|
|---|
| 152 | ctx->Current.Texcoord[texSet] );
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | if (ctx->RenderMode==GL_SELECT) {
|
|---|
| 157 | gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 | /*
|
|---|
| 165 | * This is a MESA extension function. Pretty much just like glRasterPos
|
|---|
| 166 | * except we don't apply the modelview or projection matrices; specify a
|
|---|
| 167 | * window coordinate directly.
|
|---|
| 168 | * Caller: context->API.WindowPos4fMESA pointer.
|
|---|
| 169 | */
|
|---|
| 170 | void gl_windowpos( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat w )
|
|---|
| 171 | {
|
|---|
| 172 | /* KW: Assume that like rasterpos, this must be outside begin/end.
|
|---|
| 173 | */
|
|---|
| 174 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, "glWindowPosMESA" );
|
|---|
| 175 |
|
|---|
| 176 | /* set raster position */
|
|---|
| 177 | ctx->Current.RasterPos[0] = x;
|
|---|
| 178 | ctx->Current.RasterPos[1] = y;
|
|---|
| 179 | ctx->Current.RasterPos[2] = CLAMP( z, 0.0F, 1.0F );
|
|---|
| 180 | ctx->Current.RasterPos[3] = w;
|
|---|
| 181 |
|
|---|
| 182 | ctx->Current.RasterPosValid = GL_TRUE;
|
|---|
| 183 |
|
|---|
| 184 | /* raster color */
|
|---|
| 185 | if (0 && ctx->Light.Enabled) {
|
|---|
| 186 |
|
|---|
| 187 | /* KW: I don't see how this can work - would have to take the
|
|---|
| 188 | * inverse of the projection matrix or the combined
|
|---|
| 189 | * modelProjection matrix, transform point and normal, and
|
|---|
| 190 | * do the lighting. Those inverses are not used for
|
|---|
| 191 | * anything else. This is not an object-space lighting
|
|---|
| 192 | * issue - what this is trying to do is something like
|
|---|
| 193 | * clip-space or window-space lighting...
|
|---|
| 194 | *
|
|---|
| 195 | * Anyway, since the implementation was never correct, I'm
|
|---|
| 196 | * not fixing it now - just use the unlit color.
|
|---|
| 197 | */
|
|---|
| 198 |
|
|---|
| 199 | /* KW: As a reprise, we now *do* keep the inverse of the projection
|
|---|
| 200 | * matrix, so it is not infeasible to try to swim up stream
|
|---|
| 201 | * in this manner. I still don't want to implement it,
|
|---|
| 202 | * however.
|
|---|
| 203 | */
|
|---|
| 204 | }
|
|---|
| 205 | else {
|
|---|
| 206 | /* use current color or index */
|
|---|
| 207 | if (ctx->Visual->RGBAflag) {
|
|---|
| 208 | UBYTE_RGBA_TO_FLOAT_RGBA(ctx->Current.RasterColor,
|
|---|
| 209 | ctx->Current.ByteColor);
|
|---|
| 210 | }
|
|---|
| 211 | else {
|
|---|
| 212 | ctx->Current.RasterIndex = ctx->Current.Index;
|
|---|
| 213 | }
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | ctx->Current.RasterDistance = 0.0;
|
|---|
| 217 |
|
|---|
| 218 | {
|
|---|
| 219 | GLuint texSet;
|
|---|
| 220 | for (texSet=0; texSet<MAX_TEXTURE_UNITS; texSet++) {
|
|---|
| 221 | COPY_4FV( ctx->Current.RasterMultiTexCoord[texSet],
|
|---|
| 222 | ctx->Current.Texcoord[texSet] );
|
|---|
| 223 | }
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | if (ctx->RenderMode==GL_SELECT) {
|
|---|
| 227 | gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
|
|---|
| 228 | }
|
|---|
| 229 | }
|
|---|