replace _mesa_ prefix with _swrast_, remove s_histogram.[ch]
[mesa.git] / src / mesa / swrast / s_feedback.c
1 /* $Id: s_feedback.c,v 1.11 2003/03/25 02:23:46 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 5.1
6 *
7 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 #include "glheader.h"
28 #include "colormac.h"
29 #include "context.h"
30 #include "enums.h"
31 #include "feedback.h"
32 #include "macros.h"
33
34 #include "s_context.h"
35 #include "s_feedback.h"
36 #include "s_triangle.h"
37
38
39 #define FB_3D 0x01
40 #define FB_4D 0x02
41 #define FB_INDEX 0x04
42 #define FB_COLOR 0x08
43 #define FB_TEXTURE 0X10
44
45
46
47
48 static void feedback_vertex( GLcontext *ctx,
49 const SWvertex *v, const SWvertex *pv )
50 {
51 const GLuint texUnit = 0; /* See section 5.3 of 1.2.1 spec */
52 GLfloat win[4];
53 GLfloat color[4];
54 GLfloat tc[4];
55 GLuint index;
56
57 win[0] = v->win[0];
58 win[1] = v->win[1];
59 win[2] = v->win[2] / ctx->DepthMaxF;
60 win[3] = 1.0F / v->win[3];
61
62 color[0] = CHAN_TO_FLOAT(pv->color[0]);
63 color[1] = CHAN_TO_FLOAT(pv->color[1]);
64 color[2] = CHAN_TO_FLOAT(pv->color[2]);
65 color[3] = CHAN_TO_FLOAT(pv->color[3]);
66
67 if (v->texcoord[texUnit][3] != 1.0 &&
68 v->texcoord[texUnit][3] != 0.0) {
69 GLfloat invq = 1.0F / v->texcoord[texUnit][3];
70 tc[0] = v->texcoord[texUnit][0] * invq;
71 tc[1] = v->texcoord[texUnit][1] * invq;
72 tc[2] = v->texcoord[texUnit][2] * invq;
73 tc[3] = v->texcoord[texUnit][3];
74 }
75 else {
76 COPY_4V(tc, v->texcoord[texUnit]);
77 }
78
79 index = v->index;
80
81 _mesa_feedback_vertex( ctx, win, color, index, tc );
82 }
83
84
85 /*
86 * Put triangle in feedback buffer.
87 */
88 void _swrast_feedback_triangle( GLcontext *ctx,
89 const SWvertex *v0,
90 const SWvertex *v1,
91 const SWvertex *v2)
92 {
93 if (_swrast_culltriangle( ctx, v0, v1, v2 )) {
94 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POLYGON_TOKEN );
95 FEEDBACK_TOKEN( ctx, (GLfloat) 3 ); /* three vertices */
96
97 if (ctx->Light.ShadeModel == GL_SMOOTH) {
98 feedback_vertex( ctx, v0, v0 );
99 feedback_vertex( ctx, v1, v1 );
100 feedback_vertex( ctx, v2, v2 );
101 } else {
102 feedback_vertex( ctx, v0, v2 );
103 feedback_vertex( ctx, v1, v2 );
104 feedback_vertex( ctx, v2, v2 );
105 }
106 }
107 }
108
109
110 void _swrast_feedback_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
111 {
112 GLenum token = GL_LINE_TOKEN;
113 SWcontext *swrast = SWRAST_CONTEXT(ctx);
114
115 if (swrast->StippleCounter==0)
116 token = GL_LINE_RESET_TOKEN;
117
118 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) token );
119
120 if (ctx->Light.ShadeModel == GL_SMOOTH) {
121 feedback_vertex( ctx, v0, v0 );
122 feedback_vertex( ctx, v1, v1 );
123 } else {
124 feedback_vertex( ctx, v0, v1 );
125 feedback_vertex( ctx, v1, v1 );
126 }
127
128 swrast->StippleCounter++;
129 }
130
131
132 void _swrast_feedback_point( GLcontext *ctx, const SWvertex *v )
133 {
134 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POINT_TOKEN );
135 feedback_vertex( ctx, v, v );
136 }
137
138
139 void _swrast_select_triangle( GLcontext *ctx,
140 const SWvertex *v0,
141 const SWvertex *v1,
142 const SWvertex *v2)
143 {
144 if (_swrast_culltriangle( ctx, v0, v1, v2 )) {
145 const GLfloat zs = 1.0F / ctx->DepthMaxF;
146
147 _mesa_update_hitflag( ctx, v0->win[2] * zs );
148 _mesa_update_hitflag( ctx, v1->win[2] * zs );
149 _mesa_update_hitflag( ctx, v2->win[2] * zs );
150 }
151 }
152
153
154 void _swrast_select_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
155 {
156 const GLfloat zs = 1.0F / ctx->DepthMaxF;
157 _mesa_update_hitflag( ctx, v0->win[2] * zs );
158 _mesa_update_hitflag( ctx, v1->win[2] * zs );
159 }
160
161
162 void _swrast_select_point( GLcontext *ctx, const SWvertex *v )
163 {
164 const GLfloat zs = 1.0F / ctx->DepthMaxF;
165 _mesa_update_hitflag( ctx, v->win[2] * zs );
166 }