Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4358 Serge 1
/*
2
 * Mesa 3-D graphics library
3
 *
4
 * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included
14
 * in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
 * OTHER DEALINGS IN THE SOFTWARE.
23
 */
24
 
25
 
26
/**
27
 * \file rastpos.c
28
 * Raster position operations.
29
 */
30
 
31
#include "glheader.h"
32
#include "context.h"
33
#include "feedback.h"
34
#include "macros.h"
35
#include "mtypes.h"
36
#include "rastpos.h"
37
#include "state.h"
38
#include "main/dispatch.h"
39
 
40
 
41
/**
42
 * Helper function for all the RasterPos functions.
43
 */
44
static void
45
rasterpos(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
46
{
47
   GET_CURRENT_CONTEXT(ctx);
48
   GLfloat p[4];
49
 
50
   p[0] = x;
51
   p[1] = y;
52
   p[2] = z;
53
   p[3] = w;
54
 
55
   FLUSH_VERTICES(ctx, 0);
56
   FLUSH_CURRENT(ctx, 0);
57
 
58
   if (ctx->NewState)
59
      _mesa_update_state( ctx );
60
 
61
   ctx->Driver.RasterPos(ctx, p);
62
}
63
 
64
 
65
void GLAPIENTRY
66
_mesa_RasterPos2d(GLdouble x, GLdouble y)
67
{
68
   rasterpos((GLfloat)x, (GLfloat)y, (GLfloat)0.0, (GLfloat)1.0);
69
}
70
 
71
void GLAPIENTRY
72
_mesa_RasterPos2f(GLfloat x, GLfloat y)
73
{
74
   rasterpos(x, y, 0.0F, 1.0F);
75
}
76
 
77
void GLAPIENTRY
78
_mesa_RasterPos2i(GLint x, GLint y)
79
{
80
   rasterpos((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
81
}
82
 
83
void GLAPIENTRY
84
_mesa_RasterPos2s(GLshort x, GLshort y)
85
{
86
   rasterpos(x, y, 0.0F, 1.0F);
87
}
88
 
89
void GLAPIENTRY
90
_mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
91
{
92
   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
93
}
94
 
95
void GLAPIENTRY
96
_mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
97
{
98
   rasterpos(x, y, z, 1.0F);
99
}
100
 
101
void GLAPIENTRY
102
_mesa_RasterPos3i(GLint x, GLint y, GLint z)
103
{
104
   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
105
}
106
 
107
void GLAPIENTRY
108
_mesa_RasterPos3s(GLshort x, GLshort y, GLshort z)
109
{
110
   rasterpos(x, y, z, 1.0F);
111
}
112
 
113
void GLAPIENTRY
114
_mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
115
{
116
   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
117
}
118
 
119
void GLAPIENTRY
120
_mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
121
{
122
   rasterpos(x, y, z, w);
123
}
124
 
125
void GLAPIENTRY
126
_mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
127
{
128
   rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
129
}
130
 
131
void GLAPIENTRY
132
_mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
133
{
134
   rasterpos(x, y, z, w);
135
}
136
 
137
void GLAPIENTRY
138
_mesa_RasterPos2dv(const GLdouble *v)
139
{
140
   rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
141
}
142
 
143
void GLAPIENTRY
144
_mesa_RasterPos2fv(const GLfloat *v)
145
{
146
   rasterpos(v[0], v[1], 0.0F, 1.0F);
147
}
148
 
149
void GLAPIENTRY
150
_mesa_RasterPos2iv(const GLint *v)
151
{
152
   rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
153
}
154
 
155
void GLAPIENTRY
156
_mesa_RasterPos2sv(const GLshort *v)
157
{
158
   rasterpos(v[0], v[1], 0.0F, 1.0F);
159
}
160
 
161
void GLAPIENTRY
162
_mesa_RasterPos3dv(const GLdouble *v)
163
{
164
   rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
165
}
166
 
167
void GLAPIENTRY
168
_mesa_RasterPos3fv(const GLfloat *v)
169
{
170
   rasterpos(v[0], v[1], v[2], 1.0F);
171
}
172
 
173
void GLAPIENTRY
174
_mesa_RasterPos3iv(const GLint *v)
175
{
176
   rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
177
}
178
 
179
void GLAPIENTRY
180
_mesa_RasterPos3sv(const GLshort *v)
181
{
182
   rasterpos(v[0], v[1], v[2], 1.0F);
183
}
184
 
185
void GLAPIENTRY
186
_mesa_RasterPos4dv(const GLdouble *v)
187
{
188
   rasterpos((GLfloat) v[0], (GLfloat) v[1],
189
		     (GLfloat) v[2], (GLfloat) v[3]);
190
}
191
 
192
void GLAPIENTRY
193
_mesa_RasterPos4fv(const GLfloat *v)
194
{
195
   rasterpos(v[0], v[1], v[2], v[3]);
196
}
197
 
198
void GLAPIENTRY
199
_mesa_RasterPos4iv(const GLint *v)
200
{
201
   rasterpos((GLfloat) v[0], (GLfloat) v[1],
202
		     (GLfloat) v[2], (GLfloat) v[3]);
203
}
204
 
205
void GLAPIENTRY
206
_mesa_RasterPos4sv(const GLshort *v)
207
{
208
   rasterpos(v[0], v[1], v[2], v[3]);
209
}
210
 
211
 
212
/**********************************************************************/
213
/***           GL_ARB_window_pos / GL_MESA_window_pos               ***/
214
/**********************************************************************/
215
 
216
 
217
/**
218
 * All glWindowPosMESA and glWindowPosARB commands call this function to
219
 * update the current raster position.
220
 */
221
static void
222
window_pos3f(GLfloat x, GLfloat y, GLfloat z)
223
{
224
   GET_CURRENT_CONTEXT(ctx);
225
   GLfloat z2;
226
 
227
   FLUSH_VERTICES(ctx, 0);
228
   FLUSH_CURRENT(ctx, 0);
229
 
230
   z2 = CLAMP(z, 0.0F, 1.0F) * (ctx->Viewport.Far - ctx->Viewport.Near)
231
      + ctx->Viewport.Near;
232
 
233
   /* set raster position */
234
   ctx->Current.RasterPos[0] = x;
235
   ctx->Current.RasterPos[1] = y;
236
   ctx->Current.RasterPos[2] = z2;
237
   ctx->Current.RasterPos[3] = 1.0F;
238
 
239
   ctx->Current.RasterPosValid = GL_TRUE;
240
 
241
   if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
242
      ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
243
   else
244
      ctx->Current.RasterDistance = 0.0;
245
 
246
   /* raster color = current color or index */
247
   ctx->Current.RasterColor[0]
248
      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0], 0.0F, 1.0F);
249
   ctx->Current.RasterColor[1]
250
      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][1], 0.0F, 1.0F);
251
   ctx->Current.RasterColor[2]
252
      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][2], 0.0F, 1.0F);
253
   ctx->Current.RasterColor[3]
254
      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3], 0.0F, 1.0F);
255
   ctx->Current.RasterSecondaryColor[0]
256
      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0], 0.0F, 1.0F);
257
   ctx->Current.RasterSecondaryColor[1]
258
      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1], 0.0F, 1.0F);
259
   ctx->Current.RasterSecondaryColor[2]
260
      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][2], 0.0F, 1.0F);
261
   ctx->Current.RasterSecondaryColor[3]
262
      = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][3], 0.0F, 1.0F);
263
 
264
   /* raster texcoord = current texcoord */
265
   {
266
      GLuint texSet;
267
      for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) {
268
         assert(texSet < Elements(ctx->Current.RasterTexCoords));
269
         COPY_4FV( ctx->Current.RasterTexCoords[texSet],
270
                  ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] );
271
      }
272
   }
273
 
274
   if (ctx->RenderMode==GL_SELECT) {
275
      _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
276
   }
277
}
278
 
279
 
280
/* This is just to support the GL_MESA_window_pos version */
281
static void
282
window_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
283
{
284
   GET_CURRENT_CONTEXT(ctx);
285
   window_pos3f(x, y, z);
286
   ctx->Current.RasterPos[3] = w;
287
}
288
 
289
 
290
void GLAPIENTRY
291
_mesa_WindowPos2d(GLdouble x, GLdouble y)
292
{
293
   window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
294
}
295
 
296
void GLAPIENTRY
297
_mesa_WindowPos2f(GLfloat x, GLfloat y)
298
{
299
   window_pos4f(x, y, 0.0F, 1.0F);
300
}
301
 
302
void GLAPIENTRY
303
_mesa_WindowPos2i(GLint x, GLint y)
304
{
305
   window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
306
}
307
 
308
void GLAPIENTRY
309
_mesa_WindowPos2s(GLshort x, GLshort y)
310
{
311
   window_pos4f(x, y, 0.0F, 1.0F);
312
}
313
 
314
void GLAPIENTRY
315
_mesa_WindowPos3d(GLdouble x, GLdouble y, GLdouble z)
316
{
317
   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
318
}
319
 
320
void GLAPIENTRY
321
_mesa_WindowPos3f(GLfloat x, GLfloat y, GLfloat z)
322
{
323
   window_pos4f(x, y, z, 1.0F);
324
}
325
 
326
void GLAPIENTRY
327
_mesa_WindowPos3i(GLint x, GLint y, GLint z)
328
{
329
   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
330
}
331
 
332
void GLAPIENTRY
333
_mesa_WindowPos3s(GLshort x, GLshort y, GLshort z)
334
{
335
   window_pos4f(x, y, z, 1.0F);
336
}
337
 
338
void GLAPIENTRY
339
_mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
340
{
341
   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
342
}
343
 
344
void GLAPIENTRY
345
_mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
346
{
347
   window_pos4f(x, y, z, w);
348
}
349
 
350
void GLAPIENTRY
351
_mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
352
{
353
   window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
354
}
355
 
356
void GLAPIENTRY
357
_mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
358
{
359
   window_pos4f(x, y, z, w);
360
}
361
 
362
void GLAPIENTRY
363
_mesa_WindowPos2dv(const GLdouble *v)
364
{
365
   window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
366
}
367
 
368
void GLAPIENTRY
369
_mesa_WindowPos2fv(const GLfloat *v)
370
{
371
   window_pos4f(v[0], v[1], 0.0F, 1.0F);
372
}
373
 
374
void GLAPIENTRY
375
_mesa_WindowPos2iv(const GLint *v)
376
{
377
   window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
378
}
379
 
380
void GLAPIENTRY
381
_mesa_WindowPos2sv(const GLshort *v)
382
{
383
   window_pos4f(v[0], v[1], 0.0F, 1.0F);
384
}
385
 
386
void GLAPIENTRY
387
_mesa_WindowPos3dv(const GLdouble *v)
388
{
389
   window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
390
}
391
 
392
void GLAPIENTRY
393
_mesa_WindowPos3fv(const GLfloat *v)
394
{
395
   window_pos4f(v[0], v[1], v[2], 1.0);
396
}
397
 
398
void GLAPIENTRY
399
_mesa_WindowPos3iv(const GLint *v)
400
{
401
   window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
402
}
403
 
404
void GLAPIENTRY
405
_mesa_WindowPos3sv(const GLshort *v)
406
{
407
   window_pos4f(v[0], v[1], v[2], 1.0F);
408
}
409
 
410
void GLAPIENTRY
411
_mesa_WindowPos4dvMESA(const GLdouble *v)
412
{
413
   window_pos4f((GLfloat) v[0], (GLfloat) v[1],
414
			 (GLfloat) v[2], (GLfloat) v[3]);
415
}
416
 
417
void GLAPIENTRY
418
_mesa_WindowPos4fvMESA(const GLfloat *v)
419
{
420
   window_pos4f(v[0], v[1], v[2], v[3]);
421
}
422
 
423
void GLAPIENTRY
424
_mesa_WindowPos4ivMESA(const GLint *v)
425
{
426
   window_pos4f((GLfloat) v[0], (GLfloat) v[1],
427
			 (GLfloat) v[2], (GLfloat) v[3]);
428
}
429
 
430
void GLAPIENTRY
431
_mesa_WindowPos4svMESA(const GLshort *v)
432
{
433
   window_pos4f(v[0], v[1], v[2], v[3]);
434
}
435
 
436
 
437
#if 0
438
 
439
/*
440
 * OpenGL implementation of glWindowPos*MESA()
441
 */
442
void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
443
{
444
   GLfloat fx, fy;
445
 
446
   /* Push current matrix mode and viewport attributes */
447
   glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
448
 
449
   /* Setup projection parameters */
450
   glMatrixMode( GL_PROJECTION );
451
   glPushMatrix();
452
   glLoadIdentity();
453
   glMatrixMode( GL_MODELVIEW );
454
   glPushMatrix();
455
   glLoadIdentity();
456
 
457
   glDepthRange( z, z );
458
   glViewport( (int) x - 1, (int) y - 1, 2, 2 );
459
 
460
   /* set the raster (window) position */
461
   fx = x - (int) x;
462
   fy = y - (int) y;
463
   glRasterPos4f( fx, fy, 0.0, w );
464
 
465
   /* restore matrices, viewport and matrix mode */
466
   glPopMatrix();
467
   glMatrixMode( GL_PROJECTION );
468
   glPopMatrix();
469
 
470
   glPopAttrib();
471
}
472
 
473
#endif
474
 
475
 
476
/**********************************************************************/
477
/** \name Initialization                                              */
478
/**********************************************************************/
479
/*@{*/
480
 
481
/**
482
 * Initialize the context current raster position information.
483
 *
484
 * \param ctx GL context.
485
 *
486
 * Initialize the current raster position information in
487
 * __struct gl_contextRec::Current, and adds the extension entry points to the
488
 * dispatcher.
489
 */
490
void _mesa_init_rastpos( struct gl_context * ctx )
491
{
492
   int i;
493
 
494
   ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
495
   ctx->Current.RasterDistance = 0.0;
496
   ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
497
   ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 );
498
   for (i = 0; i < Elements(ctx->Current.RasterTexCoords); i++)
499
      ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
500
   ctx->Current.RasterPosValid = GL_TRUE;
501
}
502
 
503
/*@}*/