3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "s_context.h"
34 #include "s_feedback.h"
35 #include "s_triangle.h"
42 #define FB_TEXTURE 0X10
47 static void feedback_vertex( GLcontext
*ctx
,
48 const SWvertex
*v
, const SWvertex
*pv
)
50 const GLuint texUnit
= 0; /* See section 5.3 of 1.2.1 spec */
58 win
[2] = v
->win
[2] / ctx
->DepthMaxF
;
59 win
[3] = 1.0F
/ v
->win
[3];
61 color
[0] = CHAN_TO_FLOAT(pv
->color
[0]);
62 color
[1] = CHAN_TO_FLOAT(pv
->color
[1]);
63 color
[2] = CHAN_TO_FLOAT(pv
->color
[2]);
64 color
[3] = CHAN_TO_FLOAT(pv
->color
[3]);
66 if (v
->texcoord
[texUnit
][3] != 1.0 &&
67 v
->texcoord
[texUnit
][3] != 0.0) {
68 GLfloat invq
= 1.0F
/ v
->texcoord
[texUnit
][3];
69 tc
[0] = v
->texcoord
[texUnit
][0] * invq
;
70 tc
[1] = v
->texcoord
[texUnit
][1] * invq
;
71 tc
[2] = v
->texcoord
[texUnit
][2] * invq
;
72 tc
[3] = v
->texcoord
[texUnit
][3];
75 COPY_4V(tc
, v
->texcoord
[texUnit
]);
80 _mesa_feedback_vertex( ctx
, win
, color
, (GLfloat
)index
, tc
);
85 * Put triangle in feedback buffer.
87 void _swrast_feedback_triangle( GLcontext
*ctx
,
92 if (_swrast_culltriangle( ctx
, v0
, v1
, v2
)) {
93 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_POLYGON_TOKEN
);
94 FEEDBACK_TOKEN( ctx
, (GLfloat
) 3 ); /* three vertices */
96 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
97 feedback_vertex( ctx
, v0
, v0
);
98 feedback_vertex( ctx
, v1
, v1
);
99 feedback_vertex( ctx
, v2
, v2
);
101 feedback_vertex( ctx
, v0
, v2
);
102 feedback_vertex( ctx
, v1
, v2
);
103 feedback_vertex( ctx
, v2
, v2
);
109 void _swrast_feedback_line( GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
)
111 GLenum token
= GL_LINE_TOKEN
;
112 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
114 if (swrast
->StippleCounter
==0)
115 token
= GL_LINE_RESET_TOKEN
;
117 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) token
);
119 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
120 feedback_vertex( ctx
, v0
, v0
);
121 feedback_vertex( ctx
, v1
, v1
);
123 feedback_vertex( ctx
, v0
, v1
);
124 feedback_vertex( ctx
, v1
, v1
);
127 swrast
->StippleCounter
++;
131 void _swrast_feedback_point( GLcontext
*ctx
, const SWvertex
*v
)
133 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_POINT_TOKEN
);
134 feedback_vertex( ctx
, v
, v
);
138 void _swrast_select_triangle( GLcontext
*ctx
,
143 if (_swrast_culltriangle( ctx
, v0
, v1
, v2
)) {
144 const GLfloat zs
= 1.0F
/ ctx
->DepthMaxF
;
146 _mesa_update_hitflag( ctx
, v0
->win
[2] * zs
);
147 _mesa_update_hitflag( ctx
, v1
->win
[2] * zs
);
148 _mesa_update_hitflag( ctx
, v2
->win
[2] * zs
);
153 void _swrast_select_line( GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
)
155 const GLfloat zs
= 1.0F
/ ctx
->DepthMaxF
;
156 _mesa_update_hitflag( ctx
, v0
->win
[2] * zs
);
157 _mesa_update_hitflag( ctx
, v1
->win
[2] * zs
);
161 void _swrast_select_point( GLcontext
*ctx
, const SWvertex
*v
)
163 const GLfloat zs
= 1.0F
/ ctx
->DepthMaxF
;
164 _mesa_update_hitflag( ctx
, v
->win
[2] * zs
);