2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
28 * Raster position operations.
38 #include "main/viewport.h"
39 #include "util/bitscan.h"
44 * Clip a point against the view volume.
46 * \param v vertex vector describing the point to clip.
48 * \return zero if outside view volume, or one if inside.
51 viewclip_point_xy( const GLfloat v
[] )
53 if ( v
[0] > v
[3] || v
[0] < -v
[3]
54 || v
[1] > v
[3] || v
[1] < -v
[3] ) {
64 * Clip a point against the near Z clipping planes.
66 * \param v vertex vector describing the point to clip.
68 * \return zero if outside view volume, or one if inside.
71 viewclip_point_near_z( const GLfloat v
[] )
83 * Clip a point against the far Z clipping planes.
85 * \param v vertex vector describing the point to clip.
87 * \return zero if outside view volume, or one if inside.
90 viewclip_point_far_z( const GLfloat v
[] )
102 * Clip a point against the user clipping planes.
104 * \param ctx GL context.
105 * \param v vertex vector describing the point to clip.
107 * \return zero if the point was clipped, or one otherwise.
110 userclip_point( struct gl_context
*ctx
, const GLfloat v
[] )
112 GLbitfield mask
= ctx
->Transform
.ClipPlanesEnabled
;
114 const int p
= u_bit_scan(&mask
);
115 GLfloat dot
= v
[0] * ctx
->Transform
._ClipUserPlane
[p
][0]
116 + v
[1] * ctx
->Transform
._ClipUserPlane
[p
][1]
117 + v
[2] * ctx
->Transform
._ClipUserPlane
[p
][2]
118 + v
[3] * ctx
->Transform
._ClipUserPlane
[p
][3];
130 * Compute lighting for the raster position. RGB modes computed.
131 * \param ctx the context
132 * \param vertex vertex location
133 * \param normal normal vector
134 * \param Rcolor returned color
135 * \param Rspec returned specular color (if separate specular enabled)
138 shade_rastpos(struct gl_context
*ctx
,
139 const GLfloat vertex
[4],
140 const GLfloat normal
[3],
144 /*const*/ GLfloat (*base
)[3] = ctx
->Light
._BaseColor
;
146 GLfloat diffuseColor
[4], specularColor
[4]; /* for RGB mode only */
148 COPY_3V(diffuseColor
, base
[0]);
149 diffuseColor
[3] = CLAMP(
150 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
][3], 0.0F
, 1.0F
);
151 ASSIGN_4V(specularColor
, 0.0, 0.0, 0.0, 1.0);
153 mask
= ctx
->Light
._EnabledLights
;
155 const int i
= u_bit_scan(&mask
);
156 struct gl_light
*light
= &ctx
->Light
.Light
[i
];
157 GLfloat attenuation
= 1.0;
158 GLfloat VP
[3]; /* vector from vertex to light pos */
160 GLfloat diffuseContrib
[3], specularContrib
[3];
162 if (!(light
->_Flags
& LIGHT_POSITIONAL
)) {
163 /* light at infinity */
164 COPY_3V(VP
, light
->_VP_inf_norm
);
165 attenuation
= light
->_VP_inf_spot_attenuation
;
168 /* local/positional light */
171 /* VP = vector from vertex pos to light[i].pos */
172 SUB_3V(VP
, light
->_Position
, vertex
);
174 d
= (GLfloat
) LEN_3FV( VP
);
177 GLfloat invd
= 1.0F
/ d
;
178 SELF_SCALE_SCALAR_3V(VP
, invd
);
182 attenuation
= 1.0F
/ (light
->ConstantAttenuation
+ d
*
183 (light
->LinearAttenuation
+ d
*
184 light
->QuadraticAttenuation
));
186 if (light
->_Flags
& LIGHT_SPOT
) {
187 GLfloat PV_dot_dir
= - DOT3(VP
, light
->_NormSpotDirection
);
189 if (PV_dot_dir
<light
->_CosCutoff
) {
193 GLfloat spot
= powf(PV_dot_dir
, light
->SpotExponent
);
199 if (attenuation
< 1e-3F
)
202 n_dot_VP
= DOT3( normal
, VP
);
204 if (n_dot_VP
< 0.0F
) {
205 ACC_SCALE_SCALAR_3V(diffuseColor
, attenuation
, light
->_MatAmbient
[0]);
209 /* Ambient + diffuse */
210 COPY_3V(diffuseContrib
, light
->_MatAmbient
[0]);
211 ACC_SCALE_SCALAR_3V(diffuseContrib
, n_dot_VP
, light
->_MatDiffuse
[0]);
218 ASSIGN_3V(specularContrib
, 0.0, 0.0, 0.0);
220 if (ctx
->Light
.Model
.LocalViewer
) {
228 else if (light
->_Flags
& LIGHT_POSITIONAL
) {
229 ACC_3V(VP
, ctx
->_EyeZDir
);
234 h
= light
->_h_inf_norm
;
237 n_dot_h
= DOT3(normal
, h
);
239 if (n_dot_h
> 0.0F
) {
243 shine
= ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_SHININESS
][0];
244 spec_coef
= powf(n_dot_h
, shine
);
246 if (spec_coef
> 1.0e-10F
) {
247 if (ctx
->Light
.Model
.ColorControl
==GL_SEPARATE_SPECULAR_COLOR
) {
248 ACC_SCALE_SCALAR_3V( specularContrib
, spec_coef
,
249 light
->_MatSpecular
[0]);
252 ACC_SCALE_SCALAR_3V( diffuseContrib
, spec_coef
,
253 light
->_MatSpecular
[0]);
259 ACC_SCALE_SCALAR_3V( diffuseColor
, attenuation
, diffuseContrib
);
260 ACC_SCALE_SCALAR_3V( specularColor
, attenuation
, specularContrib
);
263 Rcolor
[0] = CLAMP(diffuseColor
[0], 0.0F
, 1.0F
);
264 Rcolor
[1] = CLAMP(diffuseColor
[1], 0.0F
, 1.0F
);
265 Rcolor
[2] = CLAMP(diffuseColor
[2], 0.0F
, 1.0F
);
266 Rcolor
[3] = CLAMP(diffuseColor
[3], 0.0F
, 1.0F
);
267 Rspec
[0] = CLAMP(specularColor
[0], 0.0F
, 1.0F
);
268 Rspec
[1] = CLAMP(specularColor
[1], 0.0F
, 1.0F
);
269 Rspec
[2] = CLAMP(specularColor
[2], 0.0F
, 1.0F
);
270 Rspec
[3] = CLAMP(specularColor
[3], 0.0F
, 1.0F
);
275 * Do texgen needed for glRasterPos.
276 * \param ctx rendering context
277 * \param vObj object-space vertex coordinate
278 * \param vEye eye-space vertex coordinate
279 * \param normal vertex normal
280 * \param unit texture unit number
281 * \param texcoord incoming texcoord and resulting texcoord
284 compute_texgen(struct gl_context
*ctx
, const GLfloat vObj
[4], const GLfloat vEye
[4],
285 const GLfloat normal
[3], GLuint unit
, GLfloat texcoord
[4])
287 const struct gl_fixedfunc_texture_unit
*texUnit
=
288 &ctx
->Texture
.FixedFuncUnit
[unit
];
290 /* always compute sphere map terms, just in case */
291 GLfloat u
[3], two_nu
, rx
, ry
, rz
, m
, mInv
;
294 two_nu
= 2.0F
* DOT3(normal
, u
);
295 rx
= u
[0] - normal
[0] * two_nu
;
296 ry
= u
[1] - normal
[1] * two_nu
;
297 rz
= u
[2] - normal
[2] * two_nu
;
298 m
= rx
* rx
+ ry
* ry
+ (rz
+ 1.0F
) * (rz
+ 1.0F
);
300 mInv
= 0.5F
* (1.0f
/ sqrtf(m
));
304 if (texUnit
->TexGenEnabled
& S_BIT
) {
305 switch (texUnit
->GenS
.Mode
) {
306 case GL_OBJECT_LINEAR
:
307 texcoord
[0] = DOT4(vObj
, texUnit
->GenS
.ObjectPlane
);
310 texcoord
[0] = DOT4(vEye
, texUnit
->GenS
.EyePlane
);
313 texcoord
[0] = rx
* mInv
+ 0.5F
;
315 case GL_REFLECTION_MAP
:
319 texcoord
[0] = normal
[0];
322 _mesa_problem(ctx
, "Bad S texgen in compute_texgen()");
327 if (texUnit
->TexGenEnabled
& T_BIT
) {
328 switch (texUnit
->GenT
.Mode
) {
329 case GL_OBJECT_LINEAR
:
330 texcoord
[1] = DOT4(vObj
, texUnit
->GenT
.ObjectPlane
);
333 texcoord
[1] = DOT4(vEye
, texUnit
->GenT
.EyePlane
);
336 texcoord
[1] = ry
* mInv
+ 0.5F
;
338 case GL_REFLECTION_MAP
:
342 texcoord
[1] = normal
[1];
345 _mesa_problem(ctx
, "Bad T texgen in compute_texgen()");
350 if (texUnit
->TexGenEnabled
& R_BIT
) {
351 switch (texUnit
->GenR
.Mode
) {
352 case GL_OBJECT_LINEAR
:
353 texcoord
[2] = DOT4(vObj
, texUnit
->GenR
.ObjectPlane
);
356 texcoord
[2] = DOT4(vEye
, texUnit
->GenR
.EyePlane
);
358 case GL_REFLECTION_MAP
:
362 texcoord
[2] = normal
[2];
365 _mesa_problem(ctx
, "Bad R texgen in compute_texgen()");
370 if (texUnit
->TexGenEnabled
& Q_BIT
) {
371 switch (texUnit
->GenQ
.Mode
) {
372 case GL_OBJECT_LINEAR
:
373 texcoord
[3] = DOT4(vObj
, texUnit
->GenQ
.ObjectPlane
);
376 texcoord
[3] = DOT4(vEye
, texUnit
->GenQ
.EyePlane
);
379 _mesa_problem(ctx
, "Bad Q texgen in compute_texgen()");
387 * glRasterPos transformation. Typically called via ctx->Driver.RasterPos().
389 * \param vObj vertex position in object space
392 _mesa_RasterPos(struct gl_context
*ctx
, const GLfloat vObj
[4])
394 if (_mesa_arb_vertex_program_enabled(ctx
)) {
395 /* XXX implement this */
396 _mesa_problem(ctx
, "Vertex programs not implemented for glRasterPos");
400 GLfloat eye
[4], clip
[4], ndc
[3], d
;
401 GLfloat
*norm
, eyenorm
[3];
402 GLfloat
*objnorm
= ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
];
403 float scale
[3], translate
[3];
405 /* apply modelview matrix: eye = MV * obj */
406 TRANSFORM_POINT( eye
, ctx
->ModelviewMatrixStack
.Top
->m
, vObj
);
407 /* apply projection matrix: clip = Proj * eye */
408 TRANSFORM_POINT( clip
, ctx
->ProjectionMatrixStack
.Top
->m
, eye
);
410 /* clip to view volume. */
411 if (!ctx
->Transform
.DepthClampNear
) {
412 if (viewclip_point_near_z(clip
) == 0) {
413 ctx
->Current
.RasterPosValid
= GL_FALSE
;
417 if (!ctx
->Transform
.DepthClampFar
) {
418 if (viewclip_point_far_z(clip
) == 0) {
419 ctx
->Current
.RasterPosValid
= GL_FALSE
;
423 if (!ctx
->Transform
.RasterPositionUnclipped
) {
424 if (viewclip_point_xy(clip
) == 0) {
425 ctx
->Current
.RasterPosValid
= GL_FALSE
;
430 /* clip to user clipping planes */
431 if (ctx
->Transform
.ClipPlanesEnabled
&& !userclip_point(ctx
, clip
)) {
432 ctx
->Current
.RasterPosValid
= GL_FALSE
;
437 d
= (clip
[3] == 0.0F
) ? 1.0F
: 1.0F
/ clip
[3];
438 ndc
[0] = clip
[0] * d
;
439 ndc
[1] = clip
[1] * d
;
440 ndc
[2] = clip
[2] * d
;
441 /* wincoord = viewport_mapping(ndc) */
442 _mesa_get_viewport_xform(ctx
, 0, scale
, translate
);
443 ctx
->Current
.RasterPos
[0] = ndc
[0] * scale
[0] + translate
[0];
444 ctx
->Current
.RasterPos
[1] = ndc
[1] * scale
[1] + translate
[1];
445 ctx
->Current
.RasterPos
[2] = ndc
[2] * scale
[2] + translate
[2];
446 ctx
->Current
.RasterPos
[3] = clip
[3];
448 if (ctx
->Transform
.DepthClampNear
&&
449 ctx
->Transform
.DepthClampFar
) {
450 ctx
->Current
.RasterPos
[3] = CLAMP(ctx
->Current
.RasterPos
[3],
451 ctx
->ViewportArray
[0].Near
,
452 ctx
->ViewportArray
[0].Far
);
454 /* Clamp against near and far plane separately */
455 if (ctx
->Transform
.DepthClampNear
) {
456 ctx
->Current
.RasterPos
[3] = MAX2(ctx
->Current
.RasterPos
[3],
457 ctx
->ViewportArray
[0].Near
);
460 if (ctx
->Transform
.DepthClampFar
) {
461 ctx
->Current
.RasterPos
[3] = MIN2(ctx
->Current
.RasterPos
[3],
462 ctx
->ViewportArray
[0].Far
);
466 /* compute raster distance */
467 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
)
468 ctx
->Current
.RasterDistance
= ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0];
470 ctx
->Current
.RasterDistance
=
471 sqrtf( eye
[0]*eye
[0] + eye
[1]*eye
[1] + eye
[2]*eye
[2] );
473 /* compute transformed normal vector (for lighting or texgen) */
474 if (ctx
->_NeedEyeCoords
) {
475 const GLfloat
*inv
= ctx
->ModelviewMatrixStack
.Top
->inv
;
476 TRANSFORM_NORMAL( eyenorm
, objnorm
, inv
);
483 /* update raster color */
484 if (ctx
->Light
.Enabled
) {
486 shade_rastpos( ctx
, vObj
, norm
,
487 ctx
->Current
.RasterColor
,
488 ctx
->Current
.RasterSecondaryColor
);
491 /* use current color */
492 COPY_4FV(ctx
->Current
.RasterColor
,
493 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
494 COPY_4FV(ctx
->Current
.RasterSecondaryColor
,
495 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
]);
501 for (u
= 0; u
< ctx
->Const
.MaxTextureCoordUnits
; u
++) {
503 COPY_4V(tc
, ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ u
]);
504 if (ctx
->Texture
.FixedFuncUnit
[u
].TexGenEnabled
) {
505 compute_texgen(ctx
, vObj
, eye
, norm
, u
, tc
);
507 TRANSFORM_POINT(ctx
->Current
.RasterTexCoords
[u
],
508 ctx
->TextureMatrixStack
[u
].Top
->m
, tc
);
512 ctx
->Current
.RasterPosValid
= GL_TRUE
;
515 if (ctx
->RenderMode
== GL_SELECT
) {
516 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
522 * Helper function for all the RasterPos functions.
525 rasterpos(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
527 GET_CURRENT_CONTEXT(ctx
);
535 FLUSH_VERTICES(ctx
, 0);
536 FLUSH_CURRENT(ctx
, 0);
539 _mesa_update_state( ctx
);
541 ctx
->Driver
.RasterPos(ctx
, p
);
546 _mesa_RasterPos2d(GLdouble x
, GLdouble y
)
548 rasterpos((GLfloat
)x
, (GLfloat
)y
, (GLfloat
)0.0, (GLfloat
)1.0);
552 _mesa_RasterPos2f(GLfloat x
, GLfloat y
)
554 rasterpos(x
, y
, 0.0F
, 1.0F
);
558 _mesa_RasterPos2i(GLint x
, GLint y
)
560 rasterpos((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
564 _mesa_RasterPos2s(GLshort x
, GLshort y
)
566 rasterpos(x
, y
, 0.0F
, 1.0F
);
570 _mesa_RasterPos3d(GLdouble x
, GLdouble y
, GLdouble z
)
572 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
576 _mesa_RasterPos3f(GLfloat x
, GLfloat y
, GLfloat z
)
578 rasterpos(x
, y
, z
, 1.0F
);
582 _mesa_RasterPos3i(GLint x
, GLint y
, GLint z
)
584 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
588 _mesa_RasterPos3s(GLshort x
, GLshort y
, GLshort z
)
590 rasterpos(x
, y
, z
, 1.0F
);
594 _mesa_RasterPos4d(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
596 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
600 _mesa_RasterPos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
602 rasterpos(x
, y
, z
, w
);
606 _mesa_RasterPos4i(GLint x
, GLint y
, GLint z
, GLint w
)
608 rasterpos((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
612 _mesa_RasterPos4s(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
614 rasterpos(x
, y
, z
, w
);
618 _mesa_RasterPos2dv(const GLdouble
*v
)
620 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
624 _mesa_RasterPos2fv(const GLfloat
*v
)
626 rasterpos(v
[0], v
[1], 0.0F
, 1.0F
);
630 _mesa_RasterPos2iv(const GLint
*v
)
632 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
636 _mesa_RasterPos2sv(const GLshort
*v
)
638 rasterpos(v
[0], v
[1], 0.0F
, 1.0F
);
642 _mesa_RasterPos3dv(const GLdouble
*v
)
644 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
648 _mesa_RasterPos3fv(const GLfloat
*v
)
650 rasterpos(v
[0], v
[1], v
[2], 1.0F
);
654 _mesa_RasterPos3iv(const GLint
*v
)
656 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
660 _mesa_RasterPos3sv(const GLshort
*v
)
662 rasterpos(v
[0], v
[1], v
[2], 1.0F
);
666 _mesa_RasterPos4dv(const GLdouble
*v
)
668 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1],
669 (GLfloat
) v
[2], (GLfloat
) v
[3]);
673 _mesa_RasterPos4fv(const GLfloat
*v
)
675 rasterpos(v
[0], v
[1], v
[2], v
[3]);
679 _mesa_RasterPos4iv(const GLint
*v
)
681 rasterpos((GLfloat
) v
[0], (GLfloat
) v
[1],
682 (GLfloat
) v
[2], (GLfloat
) v
[3]);
686 _mesa_RasterPos4sv(const GLshort
*v
)
688 rasterpos(v
[0], v
[1], v
[2], v
[3]);
692 /**********************************************************************/
693 /*** GL_ARB_window_pos / GL_MESA_window_pos ***/
694 /**********************************************************************/
698 * All glWindowPosMESA and glWindowPosARB commands call this function to
699 * update the current raster position.
702 window_pos3f(GLfloat x
, GLfloat y
, GLfloat z
)
704 GET_CURRENT_CONTEXT(ctx
);
707 FLUSH_VERTICES(ctx
, 0);
708 FLUSH_CURRENT(ctx
, 0);
710 z2
= CLAMP(z
, 0.0F
, 1.0F
)
711 * (ctx
->ViewportArray
[0].Far
- ctx
->ViewportArray
[0].Near
)
712 + ctx
->ViewportArray
[0].Near
;
714 /* set raster position */
715 ctx
->Current
.RasterPos
[0] = x
;
716 ctx
->Current
.RasterPos
[1] = y
;
717 ctx
->Current
.RasterPos
[2] = z2
;
718 ctx
->Current
.RasterPos
[3] = 1.0F
;
720 ctx
->Current
.RasterPosValid
= GL_TRUE
;
722 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
)
723 ctx
->Current
.RasterDistance
= ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0];
725 ctx
->Current
.RasterDistance
= 0.0;
727 /* raster color = current color or index */
728 ctx
->Current
.RasterColor
[0]
729 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][0], 0.0F
, 1.0F
);
730 ctx
->Current
.RasterColor
[1]
731 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][1], 0.0F
, 1.0F
);
732 ctx
->Current
.RasterColor
[2]
733 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][2], 0.0F
, 1.0F
);
734 ctx
->Current
.RasterColor
[3]
735 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][3], 0.0F
, 1.0F
);
736 ctx
->Current
.RasterSecondaryColor
[0]
737 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][0], 0.0F
, 1.0F
);
738 ctx
->Current
.RasterSecondaryColor
[1]
739 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][1], 0.0F
, 1.0F
);
740 ctx
->Current
.RasterSecondaryColor
[2]
741 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][2], 0.0F
, 1.0F
);
742 ctx
->Current
.RasterSecondaryColor
[3]
743 = CLAMP(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
][3], 0.0F
, 1.0F
);
745 /* raster texcoord = current texcoord */
748 for (texSet
= 0; texSet
< ctx
->Const
.MaxTextureCoordUnits
; texSet
++) {
749 assert(texSet
< ARRAY_SIZE(ctx
->Current
.RasterTexCoords
));
750 COPY_4FV( ctx
->Current
.RasterTexCoords
[texSet
],
751 ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ texSet
] );
755 if (ctx
->RenderMode
==GL_SELECT
) {
756 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
761 /* This is just to support the GL_MESA_window_pos version */
763 window_pos4f(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
765 GET_CURRENT_CONTEXT(ctx
);
766 window_pos3f(x
, y
, z
);
767 ctx
->Current
.RasterPos
[3] = w
;
772 _mesa_WindowPos2d(GLdouble x
, GLdouble y
)
774 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
778 _mesa_WindowPos2f(GLfloat x
, GLfloat y
)
780 window_pos4f(x
, y
, 0.0F
, 1.0F
);
784 _mesa_WindowPos2i(GLint x
, GLint y
)
786 window_pos4f((GLfloat
) x
, (GLfloat
) y
, 0.0F
, 1.0F
);
790 _mesa_WindowPos2s(GLshort x
, GLshort y
)
792 window_pos4f(x
, y
, 0.0F
, 1.0F
);
796 _mesa_WindowPos3d(GLdouble x
, GLdouble y
, GLdouble z
)
798 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
802 _mesa_WindowPos3f(GLfloat x
, GLfloat y
, GLfloat z
)
804 window_pos4f(x
, y
, z
, 1.0F
);
808 _mesa_WindowPos3i(GLint x
, GLint y
, GLint z
)
810 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, 1.0F
);
814 _mesa_WindowPos3s(GLshort x
, GLshort y
, GLshort z
)
816 window_pos4f(x
, y
, z
, 1.0F
);
820 _mesa_WindowPos4dMESA(GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
822 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
826 _mesa_WindowPos4fMESA(GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
828 window_pos4f(x
, y
, z
, w
);
832 _mesa_WindowPos4iMESA(GLint x
, GLint y
, GLint z
, GLint w
)
834 window_pos4f((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
, (GLfloat
) w
);
838 _mesa_WindowPos4sMESA(GLshort x
, GLshort y
, GLshort z
, GLshort w
)
840 window_pos4f(x
, y
, z
, w
);
844 _mesa_WindowPos2dv(const GLdouble
*v
)
846 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
850 _mesa_WindowPos2fv(const GLfloat
*v
)
852 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
856 _mesa_WindowPos2iv(const GLint
*v
)
858 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], 0.0F
, 1.0F
);
862 _mesa_WindowPos2sv(const GLshort
*v
)
864 window_pos4f(v
[0], v
[1], 0.0F
, 1.0F
);
868 _mesa_WindowPos3dv(const GLdouble
*v
)
870 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
874 _mesa_WindowPos3fv(const GLfloat
*v
)
876 window_pos4f(v
[0], v
[1], v
[2], 1.0);
880 _mesa_WindowPos3iv(const GLint
*v
)
882 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1], (GLfloat
) v
[2], 1.0F
);
886 _mesa_WindowPos3sv(const GLshort
*v
)
888 window_pos4f(v
[0], v
[1], v
[2], 1.0F
);
892 _mesa_WindowPos4dvMESA(const GLdouble
*v
)
894 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
895 (GLfloat
) v
[2], (GLfloat
) v
[3]);
899 _mesa_WindowPos4fvMESA(const GLfloat
*v
)
901 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
905 _mesa_WindowPos4ivMESA(const GLint
*v
)
907 window_pos4f((GLfloat
) v
[0], (GLfloat
) v
[1],
908 (GLfloat
) v
[2], (GLfloat
) v
[3]);
912 _mesa_WindowPos4svMESA(const GLshort
*v
)
914 window_pos4f(v
[0], v
[1], v
[2], v
[3]);
921 * OpenGL implementation of glWindowPos*MESA()
923 void glWindowPos4fMESA( GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
927 /* Push current matrix mode and viewport attributes */
928 glPushAttrib( GL_TRANSFORM_BIT
| GL_VIEWPORT_BIT
);
930 /* Setup projection parameters */
931 glMatrixMode( GL_PROJECTION
);
934 glMatrixMode( GL_MODELVIEW
);
938 glDepthRange( z
, z
);
939 glViewport( (int) x
- 1, (int) y
- 1, 2, 2 );
941 /* set the raster (window) position */
944 glRasterPos4f( fx
, fy
, 0.0, w
);
946 /* restore matrices, viewport and matrix mode */
948 glMatrixMode( GL_PROJECTION
);
957 /**********************************************************************/
958 /** \name Initialization */
959 /**********************************************************************/
963 * Initialize the context current raster position information.
965 * \param ctx GL context.
967 * Initialize the current raster position information in
968 * __struct gl_contextRec::Current, and adds the extension entry points to the
971 void _mesa_init_rastpos( struct gl_context
* ctx
)
975 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
976 ctx
->Current
.RasterDistance
= 0.0;
977 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
978 ASSIGN_4V( ctx
->Current
.RasterSecondaryColor
, 0.0, 0.0, 0.0, 1.0 );
979 for (i
= 0; i
< ARRAY_SIZE(ctx
->Current
.RasterTexCoords
); i
++)
980 ASSIGN_4V( ctx
->Current
.RasterTexCoords
[i
], 0.0, 0.0, 0.0, 1.0 );
981 ctx
->Current
.RasterPosValid
= GL_TRUE
;