changed a warning string
[mesa.git] / src / mesa / main / rastpos.c
1 /* $Id: rastpos.c,v 1.4 1999/11/11 01:22:27 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
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 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "clip.h"
33 #include "context.h"
34 #include "feedback.h"
35 #include "light.h"
36 #include "macros.h"
37 #include "matrix.h"
38 #include "mmath.h"
39 #include "rastpos.h"
40 #include "shade.h"
41 #include "types.h"
42 #include "xform.h"
43 #endif
44
45
46 /*
47 * Caller: context->API.RasterPos4f
48 */
49 static void raster_pos4f( GLcontext *ctx,
50 GLfloat x, GLfloat y, GLfloat z, GLfloat w )
51 {
52 GLfloat v[4], eye[4], clip[4], ndc[3], d;
53
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.
57 */
58 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, "glRasterPos" );
59
60 if (ctx->NewState)
61 gl_update_state( ctx );
62
63 ASSIGN_4V( v, x, y, z, w );
64 TRANSFORM_POINT( eye, ctx->ModelView.m, v );
65
66 /* raster color */
67 if (ctx->Light.Enabled)
68 {
69 /*GLfloat *vert;*/
70 GLfloat *norm, eyenorm[3];
71 GLfloat *objnorm = ctx->Current.Normal;
72
73 /* Not needed???
74 vert = (ctx->NeedEyeCoords ? eye : v);
75 */
76
77 if (ctx->NeedEyeNormals) {
78 GLfloat *inv = ctx->ModelView.inv;
79 TRANSFORM_NORMAL( eyenorm, objnorm, inv );
80 norm = eyenorm;
81 } else {
82 norm = objnorm;
83 }
84
85 gl_shade_rastpos( ctx, v, norm,
86 ctx->Current.RasterColor,
87 &ctx->Current.RasterIndex );
88
89 }
90 else {
91 /* use current color or index */
92 if (ctx->Visual->RGBAflag) {
93 UBYTE_RGBA_TO_FLOAT_RGBA(ctx->Current.RasterColor,
94 ctx->Current.ByteColor);
95 }
96 else {
97 ctx->Current.RasterIndex = ctx->Current.Index;
98 }
99 }
100
101 /* compute raster distance */
102 ctx->Current.RasterDistance = (GLfloat)
103 GL_SQRT( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
104
105 /* apply projection matrix: clip = Proj * eye */
106 TRANSFORM_POINT( clip, ctx->ProjectionMatrix.m, eye );
107
108 /* clip to view volume */
109 if (gl_viewclip_point( clip )==0) {
110 ctx->Current.RasterPosValid = GL_FALSE;
111 return;
112 }
113
114 /* clip to user clipping planes */
115 if ( ctx->Transform.AnyClip &&
116 gl_userclip_point(ctx, clip) == 0)
117 {
118 ctx->Current.RasterPosValid = GL_FALSE;
119 return;
120 }
121
122 /* ndc = clip / W */
123 ASSERT( clip[3]!=0.0 );
124 d = 1.0F / clip[3];
125 ndc[0] = clip[0] * d;
126 ndc[1] = clip[1] * d;
127 ndc[2] = clip[2] * d;
128
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;
137
138 /* FOG??? */
139
140 {
141 GLuint texSet;
142 for (texSet=0; texSet<MAX_TEXTURE_UNITS; texSet++) {
143 COPY_4FV( ctx->Current.RasterMultiTexCoord[texSet],
144 ctx->Current.Texcoord[texSet] );
145 }
146 }
147
148 if (ctx->RenderMode==GL_SELECT) {
149 gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
150 }
151
152 }
153
154
155
156 void
157 _mesa_RasterPos2d(GLdouble x, GLdouble y)
158 {
159 _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
160 }
161
162 void
163 _mesa_RasterPos2f(GLfloat x, GLfloat y)
164 {
165 _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
166 }
167
168 void
169 _mesa_RasterPos2i(GLint x, GLint y)
170 {
171 _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
172 }
173
174 void
175 _mesa_RasterPos2s(GLshort x, GLshort y)
176 {
177 _mesa_RasterPos4f(x, y, 0.0F, 1.0F);
178 }
179
180 void
181 _mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
182 {
183 _mesa_RasterPos4f(x, y, z, 1.0F);
184 }
185
186 void
187 _mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
188 {
189 _mesa_RasterPos4f(x, y, z, 1.0F);
190 }
191
192 void
193 _mesa_RasterPos3i(GLint x, GLint y, GLint z)
194 {
195 _mesa_RasterPos4f(x, y, z, 1.0F);
196 }
197
198 void
199 _mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
200 {
201 _mesa_RasterPos4f(x, y, z, 1.0F);
202 }
203
204 void
205 _mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
206 {
207 _mesa_RasterPos4f(x, y, z, w);
208 }
209
210 void
211 _mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
212 {
213 GET_CURRENT_CONTEXT(ctx);
214 raster_pos4f(ctx, x, y, z, w);
215 }
216
217 void
218 _mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
219 {
220 _mesa_RasterPos4f(x, y, z, w);
221 }
222
223 void
224 _mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
225 {
226 _mesa_RasterPos4f(x, y, z, w);
227 }
228
229 void
230 _mesa_RasterPos2dv(const GLdouble *v)
231 {
232 _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
233 }
234
235 void
236 _mesa_RasterPos2fv(const GLfloat *v)
237 {
238 _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
239 }
240
241 void
242 _mesa_RasterPos2iv(const GLint *v)
243 {
244 _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
245 }
246
247 void
248 _mesa_RasterPos2sv(const GLshort *v)
249 {
250 _mesa_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
251 }
252
253 void
254 _mesa_RasterPos3dv(const GLdouble *v)
255 {
256 _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
257 }
258
259 void
260 _mesa_RasterPos3fv(const GLfloat *v)
261 {
262 _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
263 }
264
265 void
266 _mesa_RasterPos3iv(const GLint *v)
267 {
268 _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
269 }
270
271 void
272 _mesa_RasterPos3sv(const GLshort *v)
273 {
274 _mesa_RasterPos4f(v[0], v[1], v[2], 1.0F);
275 }
276
277 void
278 _mesa_RasterPos4dv(const GLdouble *v)
279 {
280 _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
281 }
282
283 void
284 _mesa_RasterPos4fv(const GLfloat *v)
285 {
286 _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
287 }
288
289 void
290 _mesa_RasterPos4iv(const GLint *v)
291 {
292 _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
293 }
294
295 void
296 _mesa_RasterPos4sv(const GLshort *v)
297 {
298 _mesa_RasterPos4f(v[0], v[1], v[2], v[3]);
299 }