1 /* $Id: rastpos.c,v 1.6 2000/03/03 17:47:39 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 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.
48 * Caller: context->API.RasterPos4f
50 static void raster_pos4f( GLcontext
*ctx
,
51 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
53 GLfloat v
[4], eye
[4], clip
[4], ndc
[3], d
;
55 /* KW: Added this test, which is in the spec. We can't do this
56 * outside begin/end any more because the ctx->Current values
57 * aren't uptodate during that period.
59 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx
, "glRasterPos" );
62 gl_update_state( ctx
);
64 ASSIGN_4V( v
, x
, y
, z
, w
);
65 TRANSFORM_POINT( eye
, ctx
->ModelView
.m
, v
);
68 if (ctx
->Light
.Enabled
)
71 GLfloat
*norm
, eyenorm
[3];
72 GLfloat
*objnorm
= ctx
->Current
.Normal
;
75 vert = (ctx->NeedEyeCoords ? eye : v);
78 if (ctx
->NeedEyeNormals
) {
79 GLfloat
*inv
= ctx
->ModelView
.inv
;
80 TRANSFORM_NORMAL( eyenorm
, objnorm
, inv
);
86 gl_shade_rastpos( ctx
, v
, norm
,
87 ctx
->Current
.RasterColor
,
88 &ctx
->Current
.RasterIndex
);
92 /* use current color or index */
93 if (ctx
->Visual
->RGBAflag
) {
94 UBYTE_RGBA_TO_FLOAT_RGBA(ctx
->Current
.RasterColor
,
95 ctx
->Current
.ByteColor
);
98 ctx
->Current
.RasterIndex
= ctx
->Current
.Index
;
102 /* compute raster distance */
103 ctx
->Current
.RasterDistance
= (GLfloat
)
104 GL_SQRT( eye
[0]*eye
[0] + eye
[1]*eye
[1] + eye
[2]*eye
[2] );
106 /* apply projection matrix: clip = Proj * eye */
107 TRANSFORM_POINT( clip
, ctx
->ProjectionMatrix
.m
, eye
);
109 /* clip to view volume */
110 if (gl_viewclip_point( clip
)==0) {
111 ctx
->Current
.RasterPosValid
= GL_FALSE
;
115 /* clip to user clipping planes */
116 if ( ctx
->Transform
.AnyClip
&&
117 gl_userclip_point(ctx
, clip
) == 0)
119 ctx
->Current
.RasterPosValid
= GL_FALSE
;
124 ASSERT( clip
[3]!=0.0 );
126 ndc
[0] = clip
[0] * d
;
127 ndc
[1] = clip
[1] * d
;
128 ndc
[2] = clip
[2] * d
;
130 ctx
->Current
.RasterPos
[0] = (ndc
[0] * ctx
->Viewport
.WindowMap
.m
[MAT_SX
] +
131 ctx
->Viewport
.WindowMap
.m
[MAT_TX
]);
132 ctx
->Current
.RasterPos
[1] = (ndc
[1] * ctx
->Viewport
.WindowMap
.m
[MAT_SY
] +
133 ctx
->Viewport
.WindowMap
.m
[MAT_TY
]);
134 ctx
->Current
.RasterPos
[2] = (ndc
[2] * ctx
->Viewport
.WindowMap
.m
[MAT_SZ
] +
135 ctx
->Viewport
.WindowMap
.m
[MAT_TZ
]) / ctx
->Visual
->DepthMaxF
;
136 ctx
->Current
.RasterPos
[3] = clip
[3];
137 ctx
->Current
.RasterPosValid
= GL_TRUE
;
143 for (texSet
=0; texSet
<MAX_TEXTURE_UNITS
; texSet
++) {
144 COPY_4FV( ctx
->Current
.RasterMultiTexCoord
[texSet
],
145 ctx
->Current
.Texcoord
[texSet
] );
149 if (ctx
->RenderMode
==GL_SELECT
) {
150 gl_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
158 _mesa_RasterPos2d(GLdouble x
, GLdouble y
)
160 _mesa_RasterPos4f(x
, y
, 0.0F
, 1.0F
);
164 _mesa_RasterPos2f(GLfloat x
, GLfloat y
)
166 _mesa_RasterPos4f(x
, y
, 0.0F
, 1.0F
);
170 _mesa_RasterPos2i(GLint x
, GLint y
)
172 _mesa_RasterPos4f(x
, y
, 0.0F
, 1.0F
);
176 _mesa_RasterPos2s(GLshort x
, GLshort y
)
178 _mesa_RasterPos4f(x
, y
, 0.0F
, 1.0F
);
182 _mesa_RasterPos3d(GLdouble x
, GLdouble y
, GLdouble z
)
184 _mesa_RasterPos4f(x
, y
, z
, 1.0F
);
188 _mesa_RasterPos3f(GLfloat x
, GLfloat y
, GLfloat z
)
190 _mesa_RasterPos4f(x
, y
, z
, 1.0F
);
194 _mesa_RasterPos3i(GLint x
, GLint y
, GLint z
)
196 _mesa_RasterPos4f(x
, y
, z
, 1.0F
);
200 _mesa_RasterPos3s(GLshort x
, GLshort y
, GLshort z
)
202 _mesa_RasterPos4f(x
, y
, z
, 1.0F
);
206 _mesa_RasterPos4d(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
208 _mesa_RasterPos4f(x
, y
, z
, w
);
212 _mesa_RasterPos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
214 GET_CURRENT_CONTEXT(ctx
);
215 raster_pos4f(ctx
, x
, y
, z
, w
);
219 _mesa_RasterPos4i(GLint x
, GLint y
, GLint z
, GLint w
)
221 _mesa_RasterPos4f(x
, y
, z
, w
);
225 _mesa_RasterPos4s(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
227 _mesa_RasterPos4f(x
, y
, z
, w
);
231 _mesa_RasterPos2dv(const GLdouble
*v
)
233 _mesa_RasterPos4f(v
[0], v
[1], 0.0F
, 1.0F
);
237 _mesa_RasterPos2fv(const GLfloat
*v
)
239 _mesa_RasterPos4f(v
[0], v
[1], 0.0F
, 1.0F
);
243 _mesa_RasterPos2iv(const GLint
*v
)
245 _mesa_RasterPos4f(v
[0], v
[1], 0.0F
, 1.0F
);
249 _mesa_RasterPos2sv(const GLshort
*v
)
251 _mesa_RasterPos4f(v
[0], v
[1], 0.0F
, 1.0F
);
255 _mesa_RasterPos3dv(const GLdouble
*v
)
257 _mesa_RasterPos4f(v
[0], v
[1], v
[2], 1.0F
);
261 _mesa_RasterPos3fv(const GLfloat
*v
)
263 _mesa_RasterPos4f(v
[0], v
[1], v
[2], 1.0F
);
267 _mesa_RasterPos3iv(const GLint
*v
)
269 _mesa_RasterPos4f(v
[0], v
[1], v
[2], 1.0F
);
273 _mesa_RasterPos3sv(const GLshort
*v
)
275 _mesa_RasterPos4f(v
[0], v
[1], v
[2], 1.0F
);
279 _mesa_RasterPos4dv(const GLdouble
*v
)
281 _mesa_RasterPos4f(v
[0], v
[1], v
[2], v
[3]);
285 _mesa_RasterPos4fv(const GLfloat
*v
)
287 _mesa_RasterPos4f(v
[0], v
[1], v
[2], v
[3]);
291 _mesa_RasterPos4iv(const GLint
*v
)
293 _mesa_RasterPos4f(v
[0], v
[1], v
[2], v
[3]);
297 _mesa_RasterPos4sv(const GLshort
*v
)
299 _mesa_RasterPos4f(v
[0], v
[1], v
[2], v
[3]);