1 /* $Id: rastpos.c,v 1.2 1999/10/08 09:27:11 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
38 #include "GL/xf86glx.h"
55 * Caller: context->API.RasterPos4f
57 void gl_RasterPos4f( GLcontext
*ctx
,
58 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
60 GLfloat v
[4], eye
[4], clip
[4], ndc
[3], d
;
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.
66 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx
, "glRasterPos" );
69 gl_update_state( ctx
);
71 ASSIGN_4V( v
, x
, y
, z
, w
);
72 TRANSFORM_POINT( eye
, ctx
->ModelView
.m
, v
);
75 if (ctx
->Light
.Enabled
)
78 GLfloat
*norm
, eyenorm
[3];
79 GLfloat
*objnorm
= ctx
->Current
.Normal
;
82 vert = (ctx->NeedEyeCoords ? eye : v);
85 if (ctx
->NeedEyeNormals
) {
86 GLfloat
*inv
= ctx
->ModelView
.inv
;
87 TRANSFORM_NORMAL( eyenorm
, objnorm
, inv
);
93 gl_shade_rastpos( ctx
, v
, norm
,
94 ctx
->Current
.RasterColor
,
95 &ctx
->Current
.RasterIndex
);
99 /* use current color or index */
100 if (ctx
->Visual
->RGBAflag
) {
101 UBYTE_RGBA_TO_FLOAT_RGBA(ctx
->Current
.RasterColor
,
102 ctx
->Current
.ByteColor
);
105 ctx
->Current
.RasterIndex
= ctx
->Current
.Index
;
109 /* compute raster distance */
110 ctx
->Current
.RasterDistance
=
111 GL_SQRT( eye
[0]*eye
[0] + eye
[1]*eye
[1] + eye
[2]*eye
[2] );
113 /* apply projection matrix: clip = Proj * eye */
114 TRANSFORM_POINT( clip
, ctx
->ProjectionMatrix
.m
, eye
);
116 /* clip to view volume */
117 if (gl_viewclip_point( clip
)==0) {
118 ctx
->Current
.RasterPosValid
= GL_FALSE
;
122 /* clip to user clipping planes */
123 if ( ctx
->Transform
.AnyClip
&&
124 gl_userclip_point(ctx
, clip
) == 0)
126 ctx
->Current
.RasterPosValid
= GL_FALSE
;
131 ASSERT( clip
[3]!=0.0 );
133 ndc
[0] = clip
[0] * d
;
134 ndc
[1] = clip
[1] * d
;
135 ndc
[2] = clip
[2] * d
;
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
;
150 for (texSet
=0; texSet
<MAX_TEXTURE_UNITS
; texSet
++) {
151 COPY_4FV( ctx
->Current
.RasterMultiTexCoord
[texSet
],
152 ctx
->Current
.Texcoord
[texSet
] );
156 if (ctx
->RenderMode
==GL_SELECT
) {
157 gl_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
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.
170 void gl_windowpos( GLcontext
*ctx
, GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
172 /* KW: Assume that like rasterpos, this must be outside begin/end.
174 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx
, "glWindowPosMESA" );
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
;
182 ctx
->Current
.RasterPosValid
= GL_TRUE
;
185 if (0 && ctx
->Light
.Enabled
) {
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...
195 * Anyway, since the implementation was never correct, I'm
196 * not fixing it now - just use the unlit color.
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,
206 /* use current color or index */
207 if (ctx
->Visual
->RGBAflag
) {
208 UBYTE_RGBA_TO_FLOAT_RGBA(ctx
->Current
.RasterColor
,
209 ctx
->Current
.ByteColor
);
212 ctx
->Current
.RasterIndex
= ctx
->Current
.Index
;
216 ctx
->Current
.RasterDistance
= 0.0;
220 for (texSet
=0; texSet
<MAX_TEXTURE_UNITS
; texSet
++) {
221 COPY_4FV( ctx
->Current
.RasterMultiTexCoord
[texSet
],
222 ctx
->Current
.Texcoord
[texSet
] );
226 if (ctx
->RenderMode
==GL_SELECT
) {
227 gl_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );