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