1 | /* $Id: winpos.c,v 1.3 2000-05-23 20:41:04 jeroen 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 | /* $XFree86: xc/lib/GL/mesa/src/winpos.c,v 1.2 1999/04/04 00:20:36 dawes Exp $ */
|
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 | /*
|
---|
33 | * GL_MESA_window_pos extension
|
---|
34 | *
|
---|
35 | * This extension offers a set of functions named glWindowPos*MESA() which
|
---|
36 | * directly set the current raster position to the given window coordinate.
|
---|
37 | * glWindowPos*MESA() are similar to glRasterPos*() but bypass the
|
---|
38 | * modelview, projection and viewport transformations.
|
---|
39 | *
|
---|
40 | * These functions should be very handy in conjunction with glDrawPixels()
|
---|
41 | * and glCopyPixels().
|
---|
42 | *
|
---|
43 | * If your application uses glWindowPos*MESA() and may be compiled with
|
---|
44 | * a real OpenGL instead of Mesa you can simply copy the winpos.[ch] files
|
---|
45 | * into your source tree and compile them with the rest of your code
|
---|
46 | * since glWindowPos*MESA() can, and is, implemented in terms of standard
|
---|
47 | * OpenGL commands when not using Mesa. In your source files which use
|
---|
48 | * glWindowPos*MESA() just #include "winpos.h".
|
---|
49 | */
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 | #ifdef PC_HEADER
|
---|
54 | #include "all.h"
|
---|
55 | #else
|
---|
56 | #include "glheader.h"
|
---|
57 | #include "context.h"
|
---|
58 | #include "rastpos.h"
|
---|
59 | #include "winpos.h"
|
---|
60 | #include "mmath.h"
|
---|
61 | #include "feedback.h"
|
---|
62 | #endif
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 | /*
|
---|
67 | * This is a MESA extension function. Pretty much just like glRasterPos
|
---|
68 | * except we don't apply the modelview or projection matrices; specify a
|
---|
69 | * window coordinate directly.
|
---|
70 | * Caller: context->API.WindowPos4fMESA pointer.
|
---|
71 | */
|
---|
72 | void
|
---|
73 | _mesa_WindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
|
---|
74 | {
|
---|
75 | GET_CURRENT_CONTEXT(ctx);
|
---|
76 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, "glWindowPosMESA" );
|
---|
77 |
|
---|
78 | /* set raster position */
|
---|
79 | ctx->Current.RasterPos[0] = x;
|
---|
80 | ctx->Current.RasterPos[1] = y;
|
---|
81 | ctx->Current.RasterPos[2] = CLAMP( z, 0.0F, 1.0F );
|
---|
82 | ctx->Current.RasterPos[3] = w;
|
---|
83 |
|
---|
84 | ctx->Current.RasterPosValid = GL_TRUE;
|
---|
85 | ctx->Current.RasterDistance = 0.0F;
|
---|
86 |
|
---|
87 | /* raster color = current color or index */
|
---|
88 | if (ctx->Visual->RGBAflag) {
|
---|
89 | UBYTE_RGBA_TO_FLOAT_RGBA(ctx->Current.RasterColor,
|
---|
90 | ctx->Current.ByteColor);
|
---|
91 | }
|
---|
92 | else {
|
---|
93 | ctx->Current.RasterIndex = ctx->Current.Index;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /* raster texcoord = current texcoord */
|
---|
97 | {
|
---|
98 | GLuint texSet;
|
---|
99 | for (texSet=0; texSet<MAX_TEXTURE_UNITS; texSet++) {
|
---|
100 | COPY_4FV( ctx->Current.RasterMultiTexCoord[texSet],
|
---|
101 | ctx->Current.Texcoord[texSet] );
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | if (ctx->RenderMode==GL_SELECT) {
|
---|
106 | gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 |
|
---|
113 | void
|
---|
114 | _mesa_WindowPos2dMESA(GLdouble x, GLdouble y)
|
---|
115 | {
|
---|
116 | _mesa_WindowPos4fMESA(x, y, 0.0F, 1.0F);
|
---|
117 | }
|
---|
118 |
|
---|
119 | void
|
---|
120 | _mesa_WindowPos2fMESA(GLfloat x, GLfloat y)
|
---|
121 | {
|
---|
122 | _mesa_WindowPos4fMESA(x, y, 0.0F, 1.0F);
|
---|
123 | }
|
---|
124 |
|
---|
125 | void
|
---|
126 | _mesa_WindowPos2iMESA(GLint x, GLint y)
|
---|
127 | {
|
---|
128 | _mesa_WindowPos4fMESA(x, y, 0.0F, 1.0F);
|
---|
129 | }
|
---|
130 |
|
---|
131 | void
|
---|
132 | _mesa_WindowPos2sMESA(GLshort x, GLshort y)
|
---|
133 | {
|
---|
134 | _mesa_WindowPos4fMESA(x, y, 0.0F, 1.0F);
|
---|
135 | }
|
---|
136 |
|
---|
137 | void
|
---|
138 | _mesa_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
|
---|
139 | {
|
---|
140 | _mesa_WindowPos4fMESA(x, y, z, 1.0F);
|
---|
141 | }
|
---|
142 |
|
---|
143 | void
|
---|
144 | _mesa_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
|
---|
145 | {
|
---|
146 | _mesa_WindowPos4fMESA(x, y, z, 1.0F);
|
---|
147 | }
|
---|
148 |
|
---|
149 | void
|
---|
150 | _mesa_WindowPos3iMESA(GLint x, GLint y, GLint z)
|
---|
151 | {
|
---|
152 | _mesa_WindowPos4fMESA(x, y, z, 1.0F);
|
---|
153 | }
|
---|
154 |
|
---|
155 | void
|
---|
156 | _mesa_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
|
---|
157 | {
|
---|
158 | _mesa_WindowPos4fMESA(x, y, z, 1.0F);
|
---|
159 | }
|
---|
160 |
|
---|
161 | void
|
---|
162 | _mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
|
---|
163 | {
|
---|
164 | _mesa_WindowPos4fMESA(x, y, z, w);
|
---|
165 | }
|
---|
166 |
|
---|
167 | void
|
---|
168 | _mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
|
---|
169 | {
|
---|
170 | _mesa_WindowPos4fMESA(x, y, z, w);
|
---|
171 | }
|
---|
172 |
|
---|
173 | void
|
---|
174 | _mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
|
---|
175 | {
|
---|
176 | _mesa_WindowPos4fMESA(x, y, z, w);
|
---|
177 | }
|
---|
178 |
|
---|
179 | void
|
---|
180 | _mesa_WindowPos2dvMESA(const GLdouble *v)
|
---|
181 | {
|
---|
182 | _mesa_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
|
---|
183 | }
|
---|
184 |
|
---|
185 | void
|
---|
186 | _mesa_WindowPos2fvMESA(const GLfloat *v)
|
---|
187 | {
|
---|
188 | _mesa_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
|
---|
189 | }
|
---|
190 |
|
---|
191 | void
|
---|
192 | _mesa_WindowPos2ivMESA(const GLint *v)
|
---|
193 | {
|
---|
194 | _mesa_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
|
---|
195 | }
|
---|
196 |
|
---|
197 | void
|
---|
198 | _mesa_WindowPos2svMESA(const GLshort *v)
|
---|
199 | {
|
---|
200 | _mesa_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
|
---|
201 | }
|
---|
202 |
|
---|
203 | void
|
---|
204 | _mesa_WindowPos3dvMESA(const GLdouble *v)
|
---|
205 | {
|
---|
206 | _mesa_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
|
---|
207 | }
|
---|
208 |
|
---|
209 | void
|
---|
210 | _mesa_WindowPos3fvMESA(const GLfloat *v)
|
---|
211 | {
|
---|
212 | _mesa_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
|
---|
213 | }
|
---|
214 |
|
---|
215 | void
|
---|
216 | _mesa_WindowPos3ivMESA(const GLint *v)
|
---|
217 | {
|
---|
218 | _mesa_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
|
---|
219 | }
|
---|
220 |
|
---|
221 | void
|
---|
222 | _mesa_WindowPos3svMESA(const GLshort *v)
|
---|
223 | {
|
---|
224 | _mesa_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
|
---|
225 | }
|
---|
226 |
|
---|
227 | void
|
---|
228 | _mesa_WindowPos4dvMESA(const GLdouble *v)
|
---|
229 | {
|
---|
230 | _mesa_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
|
---|
231 | }
|
---|
232 |
|
---|
233 | void
|
---|
234 | _mesa_WindowPos4fvMESA(const GLfloat *v)
|
---|
235 | {
|
---|
236 | _mesa_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
|
---|
237 | }
|
---|
238 |
|
---|
239 | void
|
---|
240 | _mesa_WindowPos4ivMESA(const GLint *v)
|
---|
241 | {
|
---|
242 | _mesa_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
|
---|
243 | }
|
---|
244 |
|
---|
245 | void
|
---|
246 | _mesa_WindowPos4svMESA(const GLshort *v)
|
---|
247 | {
|
---|
248 | _mesa_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
|
---|
249 | }
|
---|
250 |
|
---|
251 |
|
---|
252 |
|
---|
253 | #if 0
|
---|
254 |
|
---|
255 | /*
|
---|
256 | * OpenGL implementation of glWindowPos*MESA()
|
---|
257 | */
|
---|
258 | void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
|
---|
259 | {
|
---|
260 | GLfloat fx, fy;
|
---|
261 |
|
---|
262 | /* Push current matrix mode and viewport attributes */
|
---|
263 | glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
|
---|
264 |
|
---|
265 | /* Setup projection parameters */
|
---|
266 | glMatrixMode( GL_PROJECTION );
|
---|
267 | glPushMatrix();
|
---|
268 | glLoadIdentity();
|
---|
269 | glMatrixMode( GL_MODELVIEW );
|
---|
270 | glPushMatrix();
|
---|
271 | glLoadIdentity();
|
---|
272 |
|
---|
273 | glDepthRange( z, z );
|
---|
274 | glViewport( (int) x - 1, (int) y - 1, 2, 2 );
|
---|
275 |
|
---|
276 | /* set the raster (window) position */
|
---|
277 | fx = x - (int) x;
|
---|
278 | fy = y - (int) y;
|
---|
279 | glRasterPos4f( fx, fy, 0.0, w );
|
---|
280 |
|
---|
281 | /* restore matrices, viewport and matrix mode */
|
---|
282 | glPopMatrix();
|
---|
283 | glMatrixMode( GL_PROJECTION );
|
---|
284 | glPopMatrix();
|
---|
285 |
|
---|
286 | glPopAttrib();
|
---|
287 | }
|
---|
288 |
|
---|
289 | #endif
|
---|