1 /* $Id: rastpos.c,v 1.1 1999/08/19 00:55:41 jtg 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.
46 #include "GL/xf86glx.h"
53 * Caller: context->API.RasterPos4f
55 void gl_RasterPos4f( GLcontext
*ctx
,
56 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
58 GLfloat v
[4], eye
[4], clip
[4], ndc
[3], d
;
60 /* KW: Added this test, which is in the spec. We can't do this
61 * outside begin/end any more because the ctx->Current values
62 * aren't uptodate during that period.
64 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx
, "glRasterPos" );
67 gl_update_state( ctx
);
69 ASSIGN_4V( v
, x
, y
, z
, w
);
70 TRANSFORM_POINT( eye
, ctx
->ModelView
.m
, v
);
73 if (ctx
->Light
.Enabled
)
76 GLfloat
*norm
, eyenorm
[3];
77 GLfloat
*objnorm
= ctx
->Current
.Normal
;
80 vert = (ctx->NeedEyeCoords ? eye : v);
83 if (ctx
->NeedEyeNormals
) {
84 GLfloat
*inv
= ctx
->ModelView
.inv
;
85 TRANSFORM_NORMAL( eyenorm
, objnorm
, inv
);
91 gl_shade_rastpos( ctx
, v
, norm
,
92 ctx
->Current
.RasterColor
,
93 &ctx
->Current
.RasterIndex
);
97 /* use current color or index */
98 if (ctx
->Visual
->RGBAflag
) {
99 UBYTE_RGBA_TO_FLOAT_RGBA(ctx
->Current
.RasterColor
,
100 ctx
->Current
.ByteColor
);
103 ctx
->Current
.RasterIndex
= ctx
->Current
.Index
;
107 /* compute raster distance */
108 ctx
->Current
.RasterDistance
=
109 GL_SQRT( eye
[0]*eye
[0] + eye
[1]*eye
[1] + eye
[2]*eye
[2] );
111 /* apply projection matrix: clip = Proj * eye */
112 TRANSFORM_POINT( clip
, ctx
->ProjectionMatrix
.m
, eye
);
114 /* clip to view volume */
115 if (gl_viewclip_point( clip
)==0) {
116 ctx
->Current
.RasterPosValid
= GL_FALSE
;
120 /* clip to user clipping planes */
121 if ( ctx
->Transform
.AnyClip
&&
122 gl_userclip_point(ctx
, clip
) == 0)
124 ctx
->Current
.RasterPosValid
= GL_FALSE
;
129 ASSERT( clip
[3]!=0.0 );
131 ndc
[0] = clip
[0] * d
;
132 ndc
[1] = clip
[1] * d
;
133 ndc
[2] = clip
[2] * d
;
135 ctx
->Current
.RasterPos
[0] = (ndc
[0] * ctx
->Viewport
.WindowMap
.m
[MAT_SX
] +
136 ctx
->Viewport
.WindowMap
.m
[MAT_TX
]);
137 ctx
->Current
.RasterPos
[1] = (ndc
[1] * ctx
->Viewport
.WindowMap
.m
[MAT_SY
] +
138 ctx
->Viewport
.WindowMap
.m
[MAT_TY
]);
139 ctx
->Current
.RasterPos
[2] = (ndc
[2] * ctx
->Viewport
.WindowMap
.m
[MAT_SZ
] +
140 ctx
->Viewport
.WindowMap
.m
[MAT_TZ
]) / DEPTH_SCALE
;
141 ctx
->Current
.RasterPos
[3] = clip
[3];
142 ctx
->Current
.RasterPosValid
= GL_TRUE
;
148 for (texSet
=0; texSet
<MAX_TEXTURE_UNITS
; texSet
++) {
149 COPY_4FV( ctx
->Current
.RasterMultiTexCoord
[texSet
],
150 ctx
->Current
.Texcoord
[texSet
] );
154 if (ctx
->RenderMode
==GL_SELECT
) {
155 gl_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
163 * This is a MESA extension function. Pretty much just like glRasterPos
164 * except we don't apply the modelview or projection matrices; specify a
165 * window coordinate directly.
166 * Caller: context->API.WindowPos4fMESA pointer.
168 void gl_windowpos( GLcontext
*ctx
, GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
170 /* KW: Assume that like rasterpos, this must be outside begin/end.
172 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx
, "glWindowPosMESA" );
174 /* set raster position */
175 ctx
->Current
.RasterPos
[0] = x
;
176 ctx
->Current
.RasterPos
[1] = y
;
177 ctx
->Current
.RasterPos
[2] = CLAMP( z
, 0.0F
, 1.0F
);
178 ctx
->Current
.RasterPos
[3] = w
;
180 ctx
->Current
.RasterPosValid
= GL_TRUE
;
183 if (0 && ctx
->Light
.Enabled
) {
185 /* KW: I don't see how this can work - would have to take the
186 * inverse of the projection matrix or the combined
187 * modelProjection matrix, transform point and normal, and
188 * do the lighting. Those inverses are not used for
189 * anything else. This is not an object-space lighting
190 * issue - what this is trying to do is something like
191 * clip-space or window-space lighting...
193 * Anyway, since the implementation was never correct, I'm
194 * not fixing it now - just use the unlit color.
197 /* KW: As a reprise, we now *do* keep the inverse of the projection
198 * matrix, so it is not infeasible to try to swim up stream
199 * in this manner. I still don't want to implement it,
204 /* use current color or index */
205 if (ctx
->Visual
->RGBAflag
) {
206 UBYTE_RGBA_TO_FLOAT_RGBA(ctx
->Current
.RasterColor
,
207 ctx
->Current
.ByteColor
);
210 ctx
->Current
.RasterIndex
= ctx
->Current
.Index
;
214 ctx
->Current
.RasterDistance
= 0.0;
218 for (texSet
=0; texSet
<MAX_TEXTURE_UNITS
; texSet
++) {
219 COPY_4FV( ctx
->Current
.RasterMultiTexCoord
[texSet
],
220 ctx
->Current
.Texcoord
[texSet
] );
224 if (ctx
->RenderMode
==GL_SELECT
) {
225 gl_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );