2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Raster position operations.
39 #include "simple_list.h"
42 #include "math/m_matrix.h"
46 * Clip a point against the view volume.
48 * \param v vertex vector describing the point to clip.
50 * \return zero if outside view volume, or one if inside.
53 viewclip_point( const GLfloat v
[] )
55 if ( v
[0] > v
[3] || v
[0] < -v
[3]
56 || v
[1] > v
[3] || v
[1] < -v
[3]
57 || v
[2] > v
[3] || v
[2] < -v
[3] ) {
67 * Clip a point against the far/near Z clipping planes.
69 * \param v vertex vector describing the point to clip.
71 * \return zero if outside view volume, or one if inside.
74 viewclip_point_z( const GLfloat v
[] )
76 if (v
[2] > v
[3] || v
[2] < -v
[3] ) {
86 * Clip a point against the user clipping planes.
88 * \param ctx GL context.
89 * \param v vertex vector describing the point to clip.
91 * \return zero if the point was clipped, or one otherwise.
94 userclip_point( GLcontext
*ctx
, const GLfloat v
[] )
98 for (p
= 0; p
< ctx
->Const
.MaxClipPlanes
; p
++) {
99 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
100 GLfloat dot
= v
[0] * ctx
->Transform
._ClipUserPlane
[p
][0]
101 + v
[1] * ctx
->Transform
._ClipUserPlane
[p
][1]
102 + v
[2] * ctx
->Transform
._ClipUserPlane
[p
][2]
103 + v
[3] * ctx
->Transform
._ClipUserPlane
[p
][3];
115 * This has been split off to allow the normal shade routines to
116 * get a little closer to the vertex buffer, and to use the
117 * GLvector objects directly.
118 * \param ctx the context
119 * \param vertex vertex location
120 * \param normal normal vector
121 * \param Rcolor returned color
122 * \param Rspec returned specular color (if separate specular enabled)
123 * \param Rindex returned color index
126 shade_rastpos(GLcontext
*ctx
,
127 const GLfloat vertex
[4],
128 const GLfloat normal
[3],
133 GLfloat (*base
)[3] = ctx
->Light
._BaseColor
;
134 struct gl_light
*light
;
135 GLfloat diffuseColor
[4], specularColor
[4];
136 GLfloat diffuse
= 0, specular
= 0;
138 if (!ctx
->_ShineTable
[0] || !ctx
->_ShineTable
[1])
139 _mesa_validate_all_lighting_tables( ctx
);
141 COPY_3V(diffuseColor
, base
[0]);
142 diffuseColor
[3] = CLAMP(
143 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
][3], 0.0F
, 1.0F
);
144 ASSIGN_4V(specularColor
, 0.0, 0.0, 0.0, 0.0);
146 foreach (light
, &ctx
->Light
.EnabledList
) {
148 GLfloat attenuation
= 1.0;
152 GLfloat diffuseContrib
[3], specularContrib
[3];
153 GLboolean normalized
;
155 if (!(light
->_Flags
& LIGHT_POSITIONAL
)) {
156 COPY_3V(VP
, light
->_VP_inf_norm
);
157 attenuation
= light
->_VP_inf_spot_attenuation
;
162 SUB_3V(VP
, light
->_Position
, vertex
);
163 d
= (GLfloat
) LEN_3FV( VP
);
166 GLfloat invd
= 1.0F
/ d
;
167 SELF_SCALE_SCALAR_3V(VP
, invd
);
169 attenuation
= 1.0F
/ (light
->ConstantAttenuation
+ d
*
170 (light
->LinearAttenuation
+ d
*
171 light
->QuadraticAttenuation
));
173 if (light
->_Flags
& LIGHT_SPOT
) {
174 GLfloat PV_dot_dir
= - DOT3(VP
, light
->_NormDirection
);
176 if (PV_dot_dir
<light
->_CosCutoff
) {
180 double x
= PV_dot_dir
* (EXP_TABLE_SIZE
-1);
182 GLfloat spot
= (GLfloat
) (light
->_SpotExpTable
[k
][0]
183 + (x
-k
)*light
->_SpotExpTable
[k
][1]);
189 if (attenuation
< 1e-3)
192 n_dot_VP
= DOT3( normal
, VP
);
194 if (n_dot_VP
< 0.0F
) {
195 ACC_SCALE_SCALAR_3V(diffuseColor
, attenuation
, light
->_MatAmbient
[0]);
199 COPY_3V(diffuseContrib
, light
->_MatAmbient
[0]);
200 ACC_SCALE_SCALAR_3V(diffuseContrib
, n_dot_VP
, light
->_MatDiffuse
[0]);
201 diffuse
+= n_dot_VP
* light
->_dli
* attenuation
;
202 ASSIGN_3V(specularContrib
, 0.0, 0.0, 0.0);
205 if (ctx
->Light
.Model
.LocalViewer
) {
213 else if (light
->_Flags
& LIGHT_POSITIONAL
) {
215 ACC_3V(h
, ctx
->_EyeZDir
);
219 h
= light
->_h_inf_norm
;
223 n_dot_h
= DOT3(normal
, h
);
225 if (n_dot_h
> 0.0F
) {
226 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
228 GLfloat shininess
= mat
[MAT_ATTRIB_FRONT_SHININESS
][0];
232 n_dot_h
/= LEN_SQUARED_3FV( h
);
236 GET_SHINE_TAB_ENTRY( ctx
->_ShineTable
[0], n_dot_h
, spec_coef
);
238 if (spec_coef
> 1.0e-10) {
239 if (ctx
->Light
.Model
.ColorControl
==GL_SEPARATE_SPECULAR_COLOR
) {
240 ACC_SCALE_SCALAR_3V( specularContrib
, spec_coef
,
241 light
->_MatSpecular
[0]);
244 ACC_SCALE_SCALAR_3V( diffuseContrib
, spec_coef
,
245 light
->_MatSpecular
[0]);
247 specular
+= spec_coef
* light
->_sli
* attenuation
;
252 ACC_SCALE_SCALAR_3V( diffuseColor
, attenuation
, diffuseContrib
);
253 ACC_SCALE_SCALAR_3V( specularColor
, attenuation
, specularContrib
);
256 if (ctx
->Visual
.rgbMode
) {
257 Rcolor
[0] = CLAMP(diffuseColor
[0], 0.0F
, 1.0F
);
258 Rcolor
[1] = CLAMP(diffuseColor
[1], 0.0F
, 1.0F
);
259 Rcolor
[2] = CLAMP(diffuseColor
[2], 0.0F
, 1.0F
);
260 Rcolor
[3] = CLAMP(diffuseColor
[3], 0.0F
, 1.0F
);
261 Rspec
[0] = CLAMP(specularColor
[0], 0.0F
, 1.0F
);
262 Rspec
[1] = CLAMP(specularColor
[1], 0.0F
, 1.0F
);
263 Rspec
[2] = CLAMP(specularColor
[2], 0.0F
, 1.0F
);
264 Rspec
[3] = CLAMP(specularColor
[3], 0.0F
, 1.0F
);
267 GLfloat
*ind
= ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_INDEXES
];
268 GLfloat d_a
= ind
[MAT_INDEX_DIFFUSE
] - ind
[MAT_INDEX_AMBIENT
];
269 GLfloat s_a
= ind
[MAT_INDEX_SPECULAR
] - ind
[MAT_INDEX_AMBIENT
];
270 GLfloat i
= (ind
[MAT_INDEX_AMBIENT
]
271 + diffuse
* (1.0F
-specular
) * d_a
273 if (i
> ind
[MAT_INDEX_SPECULAR
]) {
274 i
= ind
[MAT_INDEX_SPECULAR
];
282 * Do texgen needed for glRasterPos.
283 * \param ctx rendering context
284 * \param vObj object-space vertex coordinate
285 * \param vEye eye-space vertex coordinate
286 * \param normal vertex normal
287 * \param unit texture unit number
288 * \param texcoord incoming texcoord and resulting texcoord
291 compute_texgen(GLcontext
*ctx
, const GLfloat vObj
[4], const GLfloat vEye
[4],
292 const GLfloat normal
[3], GLuint unit
, GLfloat texcoord
[4])
294 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
296 /* always compute sphere map terms, just in case */
297 GLfloat u
[3], two_nu
, rx
, ry
, rz
, m
, mInv
;
300 two_nu
= 2.0F
* DOT3(normal
, u
);
301 rx
= u
[0] - normal
[0] * two_nu
;
302 ry
= u
[1] - normal
[1] * two_nu
;
303 rz
= u
[2] - normal
[2] * two_nu
;
304 m
= rx
* rx
+ ry
* ry
+ (rz
+ 1.0F
) * (rz
+ 1.0F
);
306 mInv
= 0.5F
* _mesa_inv_sqrtf(m
);
310 if (texUnit
->TexGenEnabled
& S_BIT
) {
311 switch (texUnit
->GenModeS
) {
312 case GL_OBJECT_LINEAR
:
313 texcoord
[0] = DOT4(vObj
, texUnit
->ObjectPlaneS
);
316 texcoord
[0] = DOT4(vEye
, texUnit
->EyePlaneS
);
319 texcoord
[0] = rx
* mInv
+ 0.5F
;
321 case GL_REFLECTION_MAP
:
325 texcoord
[0] = normal
[0];
328 _mesa_problem(ctx
, "Bad S texgen in compute_texgen()");
333 if (texUnit
->TexGenEnabled
& T_BIT
) {
334 switch (texUnit
->GenModeT
) {
335 case GL_OBJECT_LINEAR
:
336 texcoord
[1] = DOT4(vObj
, texUnit
->ObjectPlaneT
);
339 texcoord
[1] = DOT4(vEye
, texUnit
->EyePlaneT
);
342 texcoord
[1] = ry
* mInv
+ 0.5F
;
344 case GL_REFLECTION_MAP
:
348 texcoord
[1] = normal
[1];
351 _mesa_problem(ctx
, "Bad T texgen in compute_texgen()");
356 if (texUnit
->TexGenEnabled
& R_BIT
) {
357 switch (texUnit
->GenModeR
) {
358 case GL_OBJECT_LINEAR
:
359 texcoord
[2] = DOT4(vObj
, texUnit
->ObjectPlaneR
);
362 texcoord
[2] = DOT4(vEye
, texUnit
->EyePlaneR
);
364 case GL_REFLECTION_MAP
:
368 texcoord
[2] = normal
[2];
371 _mesa_problem(ctx
, "Bad R texgen in compute_texgen()");
376 if (texUnit
->TexGenEnabled
& Q_BIT
) {
377 switch (texUnit
->GenModeQ
) {
378 case GL_OBJECT_LINEAR
:
379 texcoord
[3] = DOT4(vObj
, texUnit
->ObjectPlaneQ
);
382 texcoord
[3] = DOT4(vEye
, texUnit
->EyePlaneQ
);
385 _mesa_problem(ctx
, "Bad Q texgen in compute_texgen()");
394 * Set the raster position for pixel operations.
396 * All glRasterPos command call this function to update the current
399 * \param ctx GL context.
400 * \param x x coordinate for the raster position.
401 * \param y y coordinate for the raster position.
402 * \param z z coordinate for the raster position.
403 * \param w w coordinate for the raster position.
405 * \sa Called by _mesa_RasterPos4f().
407 * Flushes the vertices, transforms and clips the vertex coordinates, and
408 * finally sets the current raster position and associated data in
409 * __GLcontextRec::Current. When in selection mode calls
410 * _mesa_update_hitflag() with the current raster position.
413 raster_pos4f(GLcontext
*ctx
, GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
415 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
416 FLUSH_CURRENT(ctx
, 0);
419 _mesa_update_state( ctx
);
421 if (ctx
->VertexProgram
._Enabled
) {
422 /* XXX implement this */
423 _mesa_problem(ctx
, "Vertex programs not implemented for glRasterPos");
427 GLfloat obj
[4], eye
[4], clip
[4], ndc
[3], d
;
428 GLfloat
*norm
, eyenorm
[3];
429 GLfloat
*objnorm
= ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
];
431 ASSIGN_4V( obj
, x
, y
, z
, w
);
432 /* apply modelview matrix: eye = MV * obj */
433 TRANSFORM_POINT( eye
, ctx
->ModelviewMatrixStack
.Top
->m
, obj
);
434 /* apply projection matrix: clip = Proj * eye */
435 TRANSFORM_POINT( clip
, ctx
->ProjectionMatrixStack
.Top
->m
, eye
);
437 /* clip to view volume */
438 if (ctx
->Transform
.RasterPositionUnclipped
) {
439 /* GL_IBM_rasterpos_clip: only clip against Z */
440 if (viewclip_point_z(clip
) == 0) {
441 ctx
->Current
.RasterPosValid
= GL_FALSE
;
445 else if (viewclip_point(clip
) == 0) {
446 /* Normal OpenGL behaviour */
447 ctx
->Current
.RasterPosValid
= GL_FALSE
;
451 /* clip to user clipping planes */
452 if (ctx
->Transform
.ClipPlanesEnabled
&& !userclip_point(ctx
, clip
)) {
453 ctx
->Current
.RasterPosValid
= GL_FALSE
;
458 d
= (clip
[3] == 0.0F
) ? 1.0F
: 1.0F
/ clip
[3];
459 ndc
[0] = clip
[0] * d
;
460 ndc
[1] = clip
[1] * d
;
461 ndc
[2] = clip
[2] * d
;
462 /* wincoord = viewport_mapping(ndc) */
463 ctx
->Current
.RasterPos
[0] = (ndc
[0] * ctx
->Viewport
._WindowMap
.m
[MAT_SX
]
464 + ctx
->Viewport
._WindowMap
.m
[MAT_TX
]);
465 ctx
->Current
.RasterPos
[1] = (ndc
[1] * ctx
->Viewport
._WindowMap
.m
[MAT_SY
]
466 + ctx
->Viewport
._WindowMap
.m
[MAT_TY
]);
467 ctx
->Current
.RasterPos
[2] = (ndc
[2] * ctx
->Viewport
._WindowMap
.m
[MAT_SZ
]
468 + ctx
->Viewport
._WindowMap
.m
[MAT_TZ
])
469 / ctx
->DrawBuffer
->_DepthMaxF
;
470 ctx
->Current
.RasterPos
[3] = clip
[3];
472 /* compute raster distance */
473 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
)
474 ctx
->Current
.RasterDistance
= ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0];
476 ctx
->Current
.RasterDistance
=
477 SQRTF( eye
[0]*eye
[0] + eye
[1]*eye
[1] + eye
[2]*eye
[2] );
479 /* compute transformed normal vector (for lighting or texgen) */
480 if (ctx
->_NeedEyeCoords
) {
481 const GLfloat
*inv
= ctx
->ModelviewMatrixStack
.Top
->inv
;
482 TRANSFORM_NORMAL( eyenorm
, objnorm
, inv
);
489 /* update raster color */
490 if (ctx
->Light
.Enabled
) {
492 shade_rastpos( ctx
, obj
, norm
,
493 ctx
->Current
.RasterColor
,
494 ctx
->Current
.RasterSecondaryColor
,
495 &ctx
->Current
.RasterIndex
);
498 /* use current color or index */
499 if (ctx
->Visual
.rgbMode
) {
500 COPY_4FV(ctx
->Current
.RasterColor
,
501 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
502 COPY_4FV(ctx
->Current
.RasterSecondaryColor
,
503 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
]);
506 ctx
->Current
.RasterIndex
= ctx
->Current
.Index
;
513 for (u
= 0; u
< ctx
->Const
.MaxTextureCoordUnits
; u
++) {
515 COPY_4V(tc
, ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ u
]);
516 if (ctx
->Texture
.Unit
[u
].TexGenEnabled
) {
517 compute_texgen(ctx
, obj
, eye
, norm
, u
, tc
);
519 TRANSFORM_POINT(ctx
->Current
.RasterTexCoords
[u
],
520 ctx
->TextureMatrixStack
[u
].Top
->m
, tc
);
524 ctx
->Current
.RasterPosValid
= GL_TRUE
;
527 if (ctx
->RenderMode
== GL_SELECT
) {
528 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
533 /** Calls _mesa_RasterPos4f() */
535 _mesa_RasterPos2d(GLdouble x
, GLdouble y
)
537 _mesa_RasterPos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
540 /** Calls _mesa_RasterPos4f() */
542 _mesa_RasterPos2f(GLfloat x
, GLfloat y
)
544 _mesa_RasterPos4f(x
, y
, 0.0F
, 1.0F
);
547 /** Calls _mesa_RasterPos4f() */
549 _mesa_RasterPos2i(GLint x
, GLint y
)
551 _mesa_RasterPos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
554 /** Calls _mesa_RasterPos4f() */
556 _mesa_RasterPos2s(GLshort x
, GLshort y
)
558 _mesa_RasterPos4f(x
, y
, 0.0F
, 1.0F
);
561 /** Calls _mesa_RasterPos4f() */
563 _mesa_RasterPos3d(GLdouble x
, GLdouble y
, GLdouble z
)
565 _mesa_RasterPos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
568 /** Calls _mesa_RasterPos4f() */
570 _mesa_RasterPos3f(GLfloat x
, GLfloat y
, GLfloat z
)
572 _mesa_RasterPos4f(x
, y
, z
, 1.0F
);
575 /** Calls _mesa_RasterPos4f() */
577 _mesa_RasterPos3i(GLint x
, GLint y
, GLint z
)
579 _mesa_RasterPos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
582 /** Calls _mesa_RasterPos4f() */
584 _mesa_RasterPos3s(GLshort x
, GLshort y
, GLshort z
)
586 _mesa_RasterPos4f(x
, y
, z
, 1.0F
);
589 /** Calls _mesa_RasterPos4f() */
591 _mesa_RasterPos4d(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
593 _mesa_RasterPos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
596 /** Calls raster_pos4f() */
598 _mesa_RasterPos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
600 GET_CURRENT_CONTEXT(ctx
);
601 raster_pos4f(ctx
, x
, y
, z
, w
);
604 /** Calls _mesa_RasterPos4f() */
606 _mesa_RasterPos4i(GLint x
, GLint y
, GLint z
, GLint w
)
608 _mesa_RasterPos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
611 /** Calls _mesa_RasterPos4f() */
613 _mesa_RasterPos4s(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
615 _mesa_RasterPos4f(x
, y
, z
, w
);
618 /** Calls _mesa_RasterPos4f() */
620 _mesa_RasterPos2dv(const GLdouble
*v
)
622 _mesa_RasterPos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
625 /** Calls _mesa_RasterPos4f() */
627 _mesa_RasterPos2fv(const GLfloat
*v
)
629 _mesa_RasterPos4f(v
[0], v
[1], 0.0F
, 1.0F
);
632 /** Calls _mesa_RasterPos4f() */
634 _mesa_RasterPos2iv(const GLint
*v
)
636 _mesa_RasterPos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
639 /** Calls _mesa_RasterPos4f() */
641 _mesa_RasterPos2sv(const GLshort
*v
)
643 _mesa_RasterPos4f(v
[0], v
[1], 0.0F
, 1.0F
);
646 /** Calls _mesa_RasterPos4f() */
648 _mesa_RasterPos3dv(const GLdouble
*v
)
650 _mesa_RasterPos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
653 /** Calls _mesa_RasterPos4f() */
655 _mesa_RasterPos3fv(const GLfloat
*v
)
657 _mesa_RasterPos4f(v
[0], v
[1], v
[2], 1.0F
);
660 /** Calls _mesa_RasterPos4f() */
662 _mesa_RasterPos3iv(const GLint
*v
)
664 _mesa_RasterPos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
667 /** Calls _mesa_RasterPos4f() */
669 _mesa_RasterPos3sv(const GLshort
*v
)
671 _mesa_RasterPos4f(v
[0], v
[1], v
[2], 1.0F
);
674 /** Calls _mesa_RasterPos4f() */
676 _mesa_RasterPos4dv(const GLdouble
*v
)
678 _mesa_RasterPos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
679 (GLfloat
) v
[2], (GLfloat
) v
[3]);
682 /** Calls _mesa_RasterPos4f() */
684 _mesa_RasterPos4fv(const GLfloat
*v
)
686 _mesa_RasterPos4f(v
[0], v
[1], v
[2], v
[3]);
689 /** Calls _mesa_RasterPos4f() */
691 _mesa_RasterPos4iv(const GLint
*v
)
693 _mesa_RasterPos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
694 (GLfloat
) v
[2], (GLfloat
) v
[3]);
697 /** Calls _mesa_RasterPos4f() */
699 _mesa_RasterPos4sv(const GLshort
*v
)
701 _mesa_RasterPos4f(v
[0], v
[1], v
[2], v
[3]);
705 /**********************************************************************/
706 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
707 /**********************************************************************/
709 #if FEATURE_windowpos
711 * All glWindowPosMESA and glWindowPosARB commands call this function to
712 * update the current raster position.
715 window_pos3f(GLfloat x
, GLfloat y
, GLfloat z
)
717 GET_CURRENT_CONTEXT(ctx
);
720 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
721 FLUSH_CURRENT(ctx
, 0);
723 z2
= CLAMP(z
, 0.0F
, 1.0F
) * (ctx
->Viewport
.Far
- ctx
->Viewport
.Near
)
724 + ctx
->Viewport
.Near
;
726 /* set raster position */
727 ctx
->Current
.RasterPos
[0] = x
;
728 ctx
->Current
.RasterPos
[1] = y
;
729 ctx
->Current
.RasterPos
[2] = z2
;
730 ctx
->Current
.RasterPos
[3] = 1.0F
;
732 ctx
->Current
.RasterPosValid
= GL_TRUE
;
734 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
)
735 ctx
->Current
.RasterDistance
= ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0];
737 ctx
->Current
.RasterDistance
= 0.0;
739 /* raster color = current color or index */
740 if (ctx
->Visual
.rgbMode
) {
741 ctx
->Current
.RasterColor
[0]
742 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][0], 0.0F
, 1.0F
);
743 ctx
->Current
.RasterColor
[1]
744 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][1], 0.0F
, 1.0F
);
745 ctx
->Current
.RasterColor
[2]
746 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][2], 0.0F
, 1.0F
);
747 ctx
->Current
.RasterColor
[3]
748 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][3], 0.0F
, 1.0F
);
749 ctx
->Current
.RasterSecondaryColor
[0]
750 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][0], 0.0F
, 1.0F
);
751 ctx
->Current
.RasterSecondaryColor
[1]
752 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][1], 0.0F
, 1.0F
);
753 ctx
->Current
.RasterSecondaryColor
[2]
754 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][2], 0.0F
, 1.0F
);
755 ctx
->Current
.RasterSecondaryColor
[3]
756 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][3], 0.0F
, 1.0F
);
759 ctx
->Current
.RasterIndex
= ctx
->Current
.Index
;
762 /* raster texcoord = current texcoord */
765 for (texSet
= 0; texSet
< ctx
->Const
.MaxTextureCoordUnits
; texSet
++) {
766 COPY_4FV( ctx
->Current
.RasterTexCoords
[texSet
],
767 ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ texSet
] );
771 if (ctx
->RenderMode
==GL_SELECT
) {
772 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
777 /* This is just to support the GL_MESA_window_pos version */
779 window_pos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
781 GET_CURRENT_CONTEXT(ctx
);
782 window_pos3f(x
, y
, z
);
783 ctx
->Current
.RasterPos
[3] = w
;
788 _mesa_WindowPos2dMESA(GLdouble x
, GLdouble y
)
790 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
794 _mesa_WindowPos2fMESA(GLfloat x
, GLfloat y
)
796 window_pos4f(x
, y
, 0.0F
, 1.0F
);
800 _mesa_WindowPos2iMESA(GLint x
, GLint y
)
802 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
806 _mesa_WindowPos2sMESA(GLshort x
, GLshort y
)
808 window_pos4f(x
, y
, 0.0F
, 1.0F
);
812 _mesa_WindowPos3dMESA(GLdouble x
, GLdouble y
, GLdouble z
)
814 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
818 _mesa_WindowPos3fMESA(GLfloat x
, GLfloat y
, GLfloat z
)
820 window_pos4f(x
, y
, z
, 1.0F
);
824 _mesa_WindowPos3iMESA(GLint x
, GLint y
, GLint z
)
826 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
830 _mesa_WindowPos3sMESA(GLshort x
, GLshort y
, GLshort z
)
832 window_pos4f(x
, y
, z
, 1.0F
);
836 _mesa_WindowPos4dMESA(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
838 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
842 _mesa_WindowPos4fMESA(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
844 window_pos4f(x
, y
, z
, w
);
848 _mesa_WindowPos4iMESA(GLint x
, GLint y
, GLint z
, GLint w
)
850 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
854 _mesa_WindowPos4sMESA(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
856 window_pos4f(x
, y
, z
, w
);
860 _mesa_WindowPos2dvMESA(const GLdouble
*v
)
862 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
866 _mesa_WindowPos2fvMESA(const GLfloat
*v
)
868 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
872 _mesa_WindowPos2ivMESA(const GLint
*v
)
874 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
878 _mesa_WindowPos2svMESA(const GLshort
*v
)
880 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
884 _mesa_WindowPos3dvMESA(const GLdouble
*v
)
886 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
890 _mesa_WindowPos3fvMESA(const GLfloat
*v
)
892 window_pos4f(v
[0], v
[1], v
[2], 1.0);
896 _mesa_WindowPos3ivMESA(const GLint
*v
)
898 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
902 _mesa_WindowPos3svMESA(const GLshort
*v
)
904 window_pos4f(v
[0], v
[1], v
[2], 1.0F
);
908 _mesa_WindowPos4dvMESA(const GLdouble
*v
)
910 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
911 (GLfloat
) v
[2], (GLfloat
) v
[3]);
915 _mesa_WindowPos4fvMESA(const GLfloat
*v
)
917 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
921 _mesa_WindowPos4ivMESA(const GLint
*v
)
923 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
924 (GLfloat
) v
[2], (GLfloat
) v
[3]);
928 _mesa_WindowPos4svMESA(const GLshort
*v
)
930 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
938 * OpenGL implementation of glWindowPos*MESA()
940 void glWindowPos4fMESA( GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
944 /* Push current matrix mode and viewport attributes */
945 glPushAttrib( GL_TRANSFORM_BIT
| GL_VIEWPORT_BIT
);
947 /* Setup projection parameters */
948 glMatrixMode( GL_PROJECTION
);
951 glMatrixMode( GL_MODELVIEW
);
955 glDepthRange( z
, z
);
956 glViewport( (int) x
- 1, (int) y
- 1, 2, 2 );
958 /* set the raster (window) position */
961 glRasterPos4f( fx
, fy
, 0.0, w
);
963 /* restore matrices, viewport and matrix mode */
965 glMatrixMode( GL_PROJECTION
);
974 /**********************************************************************/
975 /** \name Initialization */
976 /**********************************************************************/
980 * Initialize the context current raster position information.
982 * \param ctx GL context.
984 * Initialize the current raster position information in
985 * __GLcontextRec::Current, and adds the extension entry points to the
988 void _mesa_init_rastpos( GLcontext
* ctx
)
992 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
993 ctx
->Current
.RasterDistance
= 0.0;
994 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
995 ctx
->Current
.RasterIndex
= 1.0;
996 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
997 ASSIGN_4V( ctx
->Current
.RasterTexCoords
[i
], 0.0, 0.0, 0.0, 1.0 );
998 ctx
->Current
.RasterPosValid
= GL_TRUE
;