ReactOS 0.4.16-dev-329-g9223134
rastpos.c
Go to the documentation of this file.
1/* $Id: rastpos.c,v 1.5 1997/07/24 01:23:44 brianp Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 2.4
6 * Copyright (C) 1995-1997 Brian Paul
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23
24/*
25 * $Log: rastpos.c,v $
26 * Revision 1.5 1997/07/24 01:23:44 brianp
27 * changed precompiled header symbol from PCH to PC_HEADER
28 *
29 * Revision 1.4 1997/06/20 02:25:54 brianp
30 * replaced Current.IntColor with Current.ByteColor
31 *
32 * Revision 1.3 1997/05/28 03:26:18 brianp
33 * added precompiled header (PCH) support
34 *
35 * Revision 1.2 1997/05/01 01:39:59 brianp
36 * replaced sqrt() with GL_SQRT()
37 *
38 * Revision 1.1 1997/04/01 04:17:13 brianp
39 * Initial revision
40 *
41 */
42
43
44#ifdef PC_HEADER
45#include "all.h"
46#else
47#include "clip.h"
48#include "feedback.h"
49#include "light.h"
50#include "macros.h"
51#include "matrix.h"
52#include "mmath.h"
53#include "shade.h"
54#include "types.h"
55#include "xform.h"
56#endif
57
58
59/*
60 * Caller: context->API.RasterPos4f
61 */
64{
65 GLfloat v[4], eye[4], clip[4], ndc[3], d;
66
67 ASSIGN_4V( v, x, y, z, w );
68
69 if (ctx->NewModelViewMatrix) {
71 }
72 if (ctx->NewProjectionMatrix) {
74 }
75 if (ctx->NewTextureMatrix) {
77 }
78
79 /* transform v to eye coords: eye = ModelView * v */
80 TRANSFORM_POINT( eye, ctx->ModelViewMatrix, v );
81
82 /* raster color */
83 if (ctx->Light.Enabled) {
84 GLfloat eyenorm[3];
85 TRANSFORM_NORMAL( eyenorm[0], eyenorm[1], eyenorm[2], ctx->Current.Normal,
86 ctx->ModelViewInv );
87 if (ctx->Visual->RGBAflag) {
88 GLubyte color[4];
89 gl_color_shade_vertices( ctx, 0, 1, &eye, &eyenorm, &color );
90 ctx->Current.RasterColor[0] = color[0] * ctx->Visual->InvRedScale;
91 ctx->Current.RasterColor[1] = color[1] * ctx->Visual->InvGreenScale;
92 ctx->Current.RasterColor[2] = color[2] * ctx->Visual->InvBlueScale;
93 ctx->Current.RasterColor[3] = color[3] * ctx->Visual->InvAlphaScale;
94 }
95 else {
96 gl_index_shade_vertices( ctx, 0, 1, &eye, &eyenorm,
97 &ctx->Current.RasterIndex );
98 }
99 }
100 else {
101 /* use current color or index */
102 if (ctx->Visual->RGBAflag) {
103 GLfloat *rc = ctx->Current.RasterColor;
104 rc[0] = ctx->Current.ByteColor[0] * ctx->Visual->InvRedScale;
105 rc[1] = ctx->Current.ByteColor[1] * ctx->Visual->InvGreenScale;
106 rc[2] = ctx->Current.ByteColor[2] * ctx->Visual->InvBlueScale;
107 rc[3] = ctx->Current.ByteColor[3] * ctx->Visual->InvAlphaScale;
108 }
109 else {
110 ctx->Current.RasterIndex = ctx->Current.Index;
111 }
112 }
113
114 /* clip to user clipping planes */
115 if (gl_userclip_point(ctx, eye)==0) {
116 ctx->Current.RasterPosValid = GL_FALSE;
117 return;
118 }
119
120 /* compute raster distance */
121 ctx->Current.RasterDistance =
122 GL_SQRT( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
123
124 /* apply projection matrix: clip = Proj * eye */
125 TRANSFORM_POINT( clip, ctx->ProjectionMatrix, eye );
126
127 /* clip to view volume */
128 if (gl_viewclip_point( clip )==0) {
129 ctx->Current.RasterPosValid = GL_FALSE;
130 return;
131 }
132
133 /* ndc = clip / W */
134 ASSERT( clip[3]!=0.0 );
135 d = 1.0F / clip[3];
136 ndc[0] = clip[0] * d;
137 ndc[1] = clip[1] * d;
138 ndc[2] = clip[2] * d;
139
140 ctx->Current.RasterPos[0] = ndc[0] * ctx->Viewport.Sx + ctx->Viewport.Tx;
141 ctx->Current.RasterPos[1] = ndc[1] * ctx->Viewport.Sy + ctx->Viewport.Ty;
142 ctx->Current.RasterPos[2] = (ndc[2] * ctx->Viewport.Sz + ctx->Viewport.Tz)
143 / DEPTH_SCALE;
144 ctx->Current.RasterPos[3] = clip[3];
145 ctx->Current.RasterPosValid = GL_TRUE;
146
147 /* FOG??? */
148
149 if (ctx->Texture.Enabled) {
150 COPY_4V( ctx->Current.RasterTexCoord, ctx->Current.TexCoord );
151 }
152
153 if (ctx->RenderMode==GL_SELECT) {
154 gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
155 }
156
157}
158
159
160
161/*
162 * This is a MESA extension function. Pretty much just like glRasterPos
163 * except we don't apply the modelview or projection matrices; specify a
164 * window coordinate directly.
165 * Caller: context->API.WindowPos4fMESA pointer.
166 */
168{
169 /* set raster position */
170 ctx->Current.RasterPos[0] = x;
171 ctx->Current.RasterPos[1] = y;
172 ctx->Current.RasterPos[2] = CLAMP( z, 0.0F, 1.0F );
173 ctx->Current.RasterPos[3] = w;
174
175 ctx->Current.RasterPosValid = GL_TRUE;
176
177 /* raster color */
178 if (ctx->Light.Enabled) {
179 GLfloat eye[4];
180 GLfloat eyenorm[3];
181 COPY_4V( eye, ctx->Current.RasterPos );
182 if (ctx->NewModelViewMatrix) {
184 }
185 TRANSFORM_NORMAL( eyenorm[0], eyenorm[1], eyenorm[2],
186 ctx->Current.Normal,
187 ctx->ModelViewInv );
188 if (ctx->Visual->RGBAflag) {
189 GLubyte color[4];
190 gl_color_shade_vertices( ctx, 0, 1, &eye, &eyenorm, &color );
191 ASSIGN_4V( ctx->Current.RasterColor,
192 (GLfloat) color[0] * ctx->Visual->InvRedScale,
193 (GLfloat) color[1] * ctx->Visual->InvGreenScale,
194 (GLfloat) color[2] * ctx->Visual->InvBlueScale,
195 (GLfloat) color[3] * ctx->Visual->InvAlphaScale );
196 }
197 else {
198 gl_index_shade_vertices( ctx, 0, 1, &eye, &eyenorm,
199 &ctx->Current.RasterIndex );
200 }
201 }
202 else {
203 /* use current color or index */
204 if (ctx->Visual->RGBAflag) {
205 ASSIGN_4V( ctx->Current.RasterColor,
206 ctx->Current.ByteColor[0] * ctx->Visual->InvRedScale,
207 ctx->Current.ByteColor[1] * ctx->Visual->InvGreenScale,
208 ctx->Current.ByteColor[2] * ctx->Visual->InvBlueScale,
209 ctx->Current.ByteColor[3] * ctx->Visual->InvAlphaScale );
210 }
211 else {
212 ctx->Current.RasterIndex = ctx->Current.Index;
213 }
214 }
215
216 ctx->Current.RasterDistance = 0.0;
217
218 if (ctx->Texture.Enabled) {
219 COPY_4V( ctx->Current.RasterTexCoord, ctx->Current.TexCoord );
220 }
221
222 if (ctx->RenderMode==GL_SELECT) {
223 gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
224 }
225}
GLuint gl_userclip_point(GLcontext *ctx, const GLfloat v[])
Definition: clip.c:756
GLuint gl_viewclip_point(const GLfloat v[])
Definition: clip.c:262
#define DEPTH_SCALE
Definition: config.h:146
void gl_analyze_texture_matrix(GLcontext *ctx)
Definition: matrix.c:487
void gl_analyze_modelview_matrix(GLcontext *ctx)
Definition: matrix.c:420
void gl_analyze_projection_matrix(GLcontext *ctx)
Definition: matrix.c:455
void gl_update_hitflag(GLcontext *ctx, GLfloat z)
Definition: feedback.c:240
unsigned char GLubyte
Definition: gl.h:157
#define GL_TRUE
Definition: gl.h:174
float GLfloat
Definition: gl.h:161
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLdouble * v
Definition: gl.h:2040
#define GL_SELECT
Definition: gl.h:389
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define GL_FALSE
Definition: gl.h:173
GLuint color
Definition: glext.h:6243
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLdouble GLdouble z
Definition: glext.h:5874
#define d
Definition: ke_i.h:81
#define ASSIGN_4V(V, V0, V1, V2, V3)
Definition: macros.h:128
#define COPY_4V(DST, SRC)
Definition: macros.h:102
#define GL_SQRT(X)
Definition: mmath.h:63
#define ASSERT(a)
Definition: mode.c:44
void gl_windowpos(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Definition: rastpos.c:167
void gl_RasterPos4f(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Definition: rastpos.c:62
void gl_color_shade_vertices(GLcontext *ctx, GLuint side, GLuint n, GLfloat vertex[][4], GLfloat normal[][3], GLubyte color[][4])
Definition: shade.c:94
void gl_index_shade_vertices(GLcontext *ctx, GLuint side, GLuint n, GLfloat vertex[][4], GLfloat normal[][3], GLuint indexResult[])
Definition: shade.c:439
#define CLAMP(f, min, max)
Definition: tif_color.c:177
#define TRANSFORM_NORMAL(NX, NY, NZ, N, MAT)
Definition: xform.h:61
#define TRANSFORM_POINT(Q, M, P)
Definition: xform.h:51