Merge branch 'master' into i915-unification
[mesa.git] / src / mesa / swrast / s_feedback.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.0
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 #include "glheader.h"
26 #include "colormac.h"
27 #include "context.h"
28 #include "enums.h"
29 #include "feedback.h"
30 #include "macros.h"
31
32 #include "s_context.h"
33 #include "s_feedback.h"
34 #include "s_triangle.h"
35
36
37
38 static void
39 feedback_vertex(GLcontext * ctx, const SWvertex * v, const SWvertex * pv)
40 {
41 GLfloat win[4];
42 GLfloat color[4];
43 const GLfloat *vtc = v->attrib[FRAG_ATTRIB_TEX0];
44
45 win[0] = v->attrib[FRAG_ATTRIB_WPOS][0];
46 win[1] = v->attrib[FRAG_ATTRIB_WPOS][1];
47 win[2] = v->attrib[FRAG_ATTRIB_WPOS][2] / ctx->DrawBuffer->_DepthMaxF;
48 win[3] = 1.0F / v->attrib[FRAG_ATTRIB_WPOS][3];
49
50 color[0] = CHAN_TO_FLOAT(pv->color[0]);
51 color[1] = CHAN_TO_FLOAT(pv->color[1]);
52 color[2] = CHAN_TO_FLOAT(pv->color[2]);
53 color[3] = CHAN_TO_FLOAT(pv->color[3]);
54
55 _mesa_feedback_vertex(ctx, win, color, v->attrib[FRAG_ATTRIB_CI][0], vtc);
56 }
57
58
59 /*
60 * Put triangle in feedback buffer.
61 */
62 void
63 _swrast_feedback_triangle(GLcontext *ctx, const SWvertex *v0,
64 const SWvertex *v1, const SWvertex *v2)
65 {
66 if (_swrast_culltriangle(ctx, v0, v1, v2)) {
67 FEEDBACK_TOKEN(ctx, (GLfloat) (GLint) GL_POLYGON_TOKEN);
68 FEEDBACK_TOKEN(ctx, (GLfloat) 3); /* three vertices */
69
70 if (ctx->Light.ShadeModel == GL_SMOOTH) {
71 feedback_vertex(ctx, v0, v0);
72 feedback_vertex(ctx, v1, v1);
73 feedback_vertex(ctx, v2, v2);
74 }
75 else {
76 feedback_vertex(ctx, v0, v2);
77 feedback_vertex(ctx, v1, v2);
78 feedback_vertex(ctx, v2, v2);
79 }
80 }
81 }
82
83
84 void
85 _swrast_feedback_line(GLcontext *ctx, const SWvertex *v0,
86 const SWvertex *v1)
87 {
88 GLenum token = GL_LINE_TOKEN;
89 SWcontext *swrast = SWRAST_CONTEXT(ctx);
90
91 if (swrast->StippleCounter == 0)
92 token = GL_LINE_RESET_TOKEN;
93
94 FEEDBACK_TOKEN(ctx, (GLfloat) (GLint) token);
95
96 if (ctx->Light.ShadeModel == GL_SMOOTH) {
97 feedback_vertex(ctx, v0, v0);
98 feedback_vertex(ctx, v1, v1);
99 }
100 else {
101 feedback_vertex(ctx, v0, v1);
102 feedback_vertex(ctx, v1, v1);
103 }
104
105 swrast->StippleCounter++;
106 }
107
108
109 void
110 _swrast_feedback_point(GLcontext *ctx, const SWvertex *v)
111 {
112 FEEDBACK_TOKEN(ctx, (GLfloat) (GLint) GL_POINT_TOKEN);
113 feedback_vertex(ctx, v, v);
114 }
115
116
117 void
118 _swrast_select_triangle(GLcontext *ctx, const SWvertex *v0,
119 const SWvertex *v1, const SWvertex *v2)
120 {
121 if (_swrast_culltriangle(ctx, v0, v1, v2)) {
122 const GLfloat zs = 1.0F / ctx->DrawBuffer->_DepthMaxF;
123
124 _mesa_update_hitflag( ctx, v0->attrib[FRAG_ATTRIB_WPOS][2] * zs );
125 _mesa_update_hitflag( ctx, v1->attrib[FRAG_ATTRIB_WPOS][2] * zs );
126 _mesa_update_hitflag( ctx, v2->attrib[FRAG_ATTRIB_WPOS][2] * zs );
127 }
128 }
129
130
131 void
132 _swrast_select_line(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1)
133 {
134 const GLfloat zs = 1.0F / ctx->DrawBuffer->_DepthMaxF;
135 _mesa_update_hitflag( ctx, v0->attrib[FRAG_ATTRIB_WPOS][2] * zs );
136 _mesa_update_hitflag( ctx, v1->attrib[FRAG_ATTRIB_WPOS][2] * zs );
137 }
138
139
140 void
141 _swrast_select_point(GLcontext *ctx, const SWvertex *v)
142 {
143 const GLfloat zs = 1.0F / ctx->DrawBuffer->_DepthMaxF;
144 _mesa_update_hitflag( ctx, v->attrib[FRAG_ATTRIB_WPOS][2] * zs );
145 }