1 /* $Id: rastpos.c,v 1.4 1999/11/11 01:22:27 brianp 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.
47 * Caller: context->API.RasterPos4f
49 static void raster_pos4f( GLcontext
*ctx
,
50 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
52 GLfloat v
[4], eye
[4], clip
[4], ndc
[3], d
;
54 /* KW: Added this test, which is in the spec. We can't do this
55 * outside begin/end any more because the ctx->Current values
56 * aren't uptodate during that period.
58 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx
, "glRasterPos" );
61 gl_update_state( ctx
);
63 ASSIGN_4V( v
, x
, y
, z
, w
);
64 TRANSFORM_POINT( eye
, ctx
->ModelView
.m
, v
);
67 if (ctx
->Light
.Enabled
)
70 GLfloat
*norm
, eyenorm
[3];
71 GLfloat
*objnorm
= ctx
->Current
.Normal
;
74 vert = (ctx->NeedEyeCoords ? eye : v);
77 if (ctx
->NeedEyeNormals
) {
78 GLfloat
*inv
= ctx
->ModelView
.inv
;
79 TRANSFORM_NORMAL( eyenorm
, objnorm
, inv
);
85 gl_shade_rastpos( ctx
, v
, norm
,
86 ctx
->Current
.RasterColor
,
87 &ctx
->Current
.RasterIndex
);
91 /* use current color or index */
92 if (ctx
->Visual
->RGBAflag
) {
93 UBYTE_RGBA_TO_FLOAT_RGBA(ctx
->Current
.RasterColor
,
94 ctx
->Current
.ByteColor
);
97 ctx
->Current
.RasterIndex
= ctx
->Current
.Index
;
101 /* compute raster distance */
102 ctx
->Current
.RasterDistance
= (GLfloat
)
103 GL_SQRT( eye
[0]*eye
[0] + eye
[1]*eye
[1] + eye
[2]*eye
[2] );
105 /* apply projection matrix: clip = Proj * eye */
106 TRANSFORM_POINT( clip
, ctx
->ProjectionMatrix
.m
, eye
);
108 /* clip to view volume */
109 if (gl_viewclip_point( clip
)==0) {
110 ctx
->Current
.RasterPosValid
= GL_FALSE
;
114 /* clip to user clipping planes */
115 if ( ctx
->Transform
.AnyClip
&&
116 gl_userclip_point(ctx
, clip
) == 0)
118 ctx
->Current
.RasterPosValid
= GL_FALSE
;
123 ASSERT( clip
[3]!=0.0 );
125 ndc
[0] = clip
[0] * d
;
126 ndc
[1] = clip
[1] * d
;
127 ndc
[2] = clip
[2] * d
;
129 ctx
->Current
.RasterPos
[0] = (ndc
[0] * ctx
->Viewport
.WindowMap
.m
[MAT_SX
] +
130 ctx
->Viewport
.WindowMap
.m
[MAT_TX
]);
131 ctx
->Current
.RasterPos
[1] = (ndc
[1] * ctx
->Viewport
.WindowMap
.m
[MAT_SY
] +
132 ctx
->Viewport
.WindowMap
.m
[MAT_TY
]);
133 ctx
->Current
.RasterPos
[2] = (ndc
[2] * ctx
->Viewport
.WindowMap
.m
[MAT_SZ
] +
134 ctx
->Viewport
.WindowMap
.m
[MAT_TZ
]) / DEPTH_SCALE
;
135 ctx
->Current
.RasterPos
[3] = clip
[3];
136 ctx
->Current
.RasterPosValid
= GL_TRUE
;
142 for (texSet
=0; texSet
<MAX_TEXTURE_UNITS
; texSet
++) {
143 COPY_4FV( ctx
->Current
.RasterMultiTexCoord
[texSet
],
144 ctx
->Current
.Texcoord
[texSet
] );
148 if (ctx
->RenderMode
==GL_SELECT
) {
149 gl_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
157 _mesa_RasterPos2d(GLdouble x
, GLdouble y
)
159 _mesa_RasterPos4f(x
, y
, 0.0F
, 1.0F
);
163 _mesa_RasterPos2f(GLfloat x
, GLfloat y
)
165 _mesa_RasterPos4f(x
, y
, 0.0F
, 1.0F
);
169 _mesa_RasterPos2i(GLint x
, GLint y
)
171 _mesa_RasterPos4f(x
, y
, 0.0F
, 1.0F
);
175 _mesa_RasterPos2s(GLshort x
, GLshort y
)
177 _mesa_RasterPos4f(x
, y
, 0.0F
, 1.0F
);
181 _mesa_RasterPos3d(GLdouble x
, GLdouble y
, GLdouble z
)
183 _mesa_RasterPos4f(x
, y
, z
, 1.0F
);
187 _mesa_RasterPos3f(GLfloat x
, GLfloat y
, GLfloat z
)
189 _mesa_RasterPos4f(x
, y
, z
, 1.0F
);
193 _mesa_RasterPos3i(GLint x
, GLint y
, GLint z
)
195 _mesa_RasterPos4f(x
, y
, z
, 1.0F
);
199 _mesa_RasterPos3s(GLshort x
, GLshort y
, GLshort z
)
201 _mesa_RasterPos4f(x
, y
, z
, 1.0F
);
205 _mesa_RasterPos4d(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
207 _mesa_RasterPos4f(x
, y
, z
, w
);
211 _mesa_RasterPos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
213 GET_CURRENT_CONTEXT(ctx
);
214 raster_pos4f(ctx
, x
, y
, z
, w
);
218 _mesa_RasterPos4i(GLint x
, GLint y
, GLint z
, GLint w
)
220 _mesa_RasterPos4f(x
, y
, z
, w
);
224 _mesa_RasterPos4s(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
226 _mesa_RasterPos4f(x
, y
, z
, w
);
230 _mesa_RasterPos2dv(const GLdouble
*v
)
232 _mesa_RasterPos4f(v
[0], v
[1], 0.0F
, 1.0F
);
236 _mesa_RasterPos2fv(const GLfloat
*v
)
238 _mesa_RasterPos4f(v
[0], v
[1], 0.0F
, 1.0F
);
242 _mesa_RasterPos2iv(const GLint
*v
)
244 _mesa_RasterPos4f(v
[0], v
[1], 0.0F
, 1.0F
);
248 _mesa_RasterPos2sv(const GLshort
*v
)
250 _mesa_RasterPos4f(v
[0], v
[1], 0.0F
, 1.0F
);
254 _mesa_RasterPos3dv(const GLdouble
*v
)
256 _mesa_RasterPos4f(v
[0], v
[1], v
[2], 1.0F
);
260 _mesa_RasterPos3fv(const GLfloat
*v
)
262 _mesa_RasterPos4f(v
[0], v
[1], v
[2], 1.0F
);
266 _mesa_RasterPos3iv(const GLint
*v
)
268 _mesa_RasterPos4f(v
[0], v
[1], v
[2], 1.0F
);
272 _mesa_RasterPos3sv(const GLshort
*v
)
274 _mesa_RasterPos4f(v
[0], v
[1], v
[2], 1.0F
);
278 _mesa_RasterPos4dv(const GLdouble
*v
)
280 _mesa_RasterPos4f(v
[0], v
[1], v
[2], v
[3]);
284 _mesa_RasterPos4fv(const GLfloat
*v
)
286 _mesa_RasterPos4f(v
[0], v
[1], v
[2], v
[3]);
290 _mesa_RasterPos4iv(const GLint
*v
)
292 _mesa_RasterPos4f(v
[0], v
[1], v
[2], v
[3]);
296 _mesa_RasterPos4sv(const GLshort
*v
)
298 _mesa_RasterPos4f(v
[0], v
[1], v
[2], v
[3]);