Another round of fixing attribute interpolation for glDraw/CopyPixels.
[mesa.git] / src / mesa / swrast / s_points.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.1
4 *
5 * Copyright (C) 1999-2004 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
26 #include "glheader.h"
27 #include "colormac.h"
28 #include "context.h"
29 #include "macros.h"
30 #include "texstate.h"
31 #include "s_context.h"
32 #include "s_feedback.h"
33 #include "s_points.h"
34 #include "s_span.h"
35
36
37 #define RGBA 0x1
38 #define INDEX 0x2
39 #define SMOOTH 0x4
40 #define ATTRIBS 0x8
41 #define SPECULAR 0x10
42 #define LARGE 0x20
43 #define ATTENUATE 0x40
44 #define SPRITE 0x80
45
46
47 /*
48 * CI points with size == 1.0
49 */
50 #define FLAGS (INDEX)
51 #define NAME size1_ci_point
52 #include "s_pointtemp.h"
53
54
55 /*
56 * General CI points.
57 */
58 #define FLAGS (INDEX | LARGE)
59 #define NAME general_ci_point
60 #include "s_pointtemp.h"
61
62
63 /*
64 * Antialiased CI points.
65 */
66 #define FLAGS (INDEX | SMOOTH)
67 #define NAME antialiased_ci_point
68 #include "s_pointtemp.h"
69
70
71 /*
72 * Distance attenuated, general CI points.
73 */
74 #define FLAGS (INDEX | ATTENUATE)
75 #define NAME atten_general_ci_point
76 #include "s_pointtemp.h"
77
78
79 /*
80 * RGBA points with size == 1.0
81 */
82 #define FLAGS (RGBA)
83 #define NAME size1_rgba_point
84 #include "s_pointtemp.h"
85
86
87 /*
88 * General RGBA points.
89 */
90 #define FLAGS (RGBA | LARGE)
91 #define NAME general_rgba_point
92 #include "s_pointtemp.h"
93
94
95 /*
96 * Antialiased RGBA points.
97 */
98 #define FLAGS (RGBA | SMOOTH)
99 #define NAME antialiased_rgba_point
100 #include "s_pointtemp.h"
101
102
103 /*
104 * Textured RGBA points.
105 */
106 #define FLAGS (RGBA | LARGE | ATTRIBS | SPECULAR)
107 #define NAME textured_rgba_point
108 #include "s_pointtemp.h"
109
110
111 /*
112 * Antialiased points with texture mapping.
113 */
114 #define FLAGS (RGBA | SMOOTH | ATTRIBS | SPECULAR)
115 #define NAME antialiased_tex_rgba_point
116 #include "s_pointtemp.h"
117
118
119 /*
120 * Distance attenuated, general RGBA points.
121 */
122 #define FLAGS (RGBA | ATTENUATE)
123 #define NAME atten_general_rgba_point
124 #include "s_pointtemp.h"
125
126
127 /*
128 * Distance attenuated, textured RGBA points.
129 */
130 #define FLAGS (RGBA | ATTENUATE | ATTRIBS | SPECULAR)
131 #define NAME atten_textured_rgba_point
132 #include "s_pointtemp.h"
133
134
135 /*
136 * Distance attenuated, antialiased points with or without texture mapping.
137 */
138 #define FLAGS (RGBA | ATTENUATE | ATTRIBS | SMOOTH)
139 #define NAME atten_antialiased_rgba_point
140 #include "s_pointtemp.h"
141
142
143 /*
144 * Sprite (textured point)
145 */
146 #define FLAGS (RGBA | SPRITE | SPECULAR)
147 #define NAME sprite_point
148 #include "s_pointtemp.h"
149
150
151 #define FLAGS (RGBA | SPRITE | SPECULAR | ATTENUATE)
152 #define NAME atten_sprite_point
153 #include "s_pointtemp.h"
154
155
156 void
157 _swrast_add_spec_terms_point(GLcontext *ctx, const SWvertex *v0)
158 {
159 SWvertex *ncv0 = (SWvertex *) v0;
160 GLfloat rSum, gSum, bSum;
161 GLchan cSave[4];
162
163 /* save */
164 COPY_CHAN4( cSave, ncv0->color );
165 /* sum */
166 rSum = CHAN_TO_FLOAT(ncv0->color[0]) + ncv0->attrib[FRAG_ATTRIB_COL1][0];
167 gSum = CHAN_TO_FLOAT(ncv0->color[1]) + ncv0->attrib[FRAG_ATTRIB_COL1][1];
168 bSum = CHAN_TO_FLOAT(ncv0->color[2]) + ncv0->attrib[FRAG_ATTRIB_COL1][2];
169 UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[0], rSum);
170 UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[1], gSum);
171 UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[2], bSum);
172 /* draw */
173 SWRAST_CONTEXT(ctx)->SpecPoint(ctx, ncv0);
174 /* restore */
175 COPY_CHAN4(ncv0->color, cSave);
176 }
177
178
179
180 /* record the current point function name */
181 #ifdef DEBUG
182
183 static const char *pntFuncName = NULL;
184
185 #define USE(pntFunc) \
186 do { \
187 pntFuncName = #pntFunc; \
188 /*printf("%s\n", pntFuncName);*/ \
189 swrast->Point = pntFunc; \
190 } while (0)
191
192 #else
193
194 #define USE(pntFunc) swrast->Point = pntFunc
195
196 #endif
197
198
199 /*
200 * Examine the current context to determine which point drawing function
201 * should be used.
202 */
203 void
204 _swrast_choose_point( GLcontext *ctx )
205 {
206 SWcontext *swrast = SWRAST_CONTEXT(ctx);
207 GLboolean rgbMode = ctx->Visual.rgbMode;
208 GLboolean specular = (ctx->Fog.ColorSumEnabled ||
209 (ctx->Light.Enabled &&
210 ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR));
211
212 if (ctx->RenderMode==GL_RENDER) {
213 if (ctx->Point.PointSprite) {
214 /* GL_ARB_point_sprite / GL_NV_point_sprite */
215 /* XXX this might not be good enough */
216 if (ctx->Point._Attenuated)
217 USE(atten_sprite_point);
218 else
219 USE(sprite_point);
220 }
221 else if (ctx->Point.SmoothFlag) {
222 /* Smooth points */
223 if (rgbMode) {
224 if (ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled) {
225 USE(atten_antialiased_rgba_point);
226 }
227 else if (ctx->Texture._EnabledCoordUnits) {
228 USE(antialiased_tex_rgba_point);
229 }
230 else {
231 USE(antialiased_rgba_point);
232 }
233 }
234 else {
235 USE(antialiased_ci_point);
236 }
237 }
238 else if (ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled) {
239 if (rgbMode) {
240 if (ctx->Texture._EnabledCoordUnits) {
241 if (ctx->Point.SmoothFlag) {
242 USE(atten_antialiased_rgba_point);
243 }
244 else {
245 USE(atten_textured_rgba_point);
246 }
247 }
248 else {
249 USE(atten_general_rgba_point);
250 }
251 }
252 else {
253 /* ci, atten */
254 USE(atten_general_ci_point);
255 }
256 }
257 else if ((ctx->Texture._EnabledCoordUnits
258 || specular
259 || swrast->_FogEnabled) && rgbMode) {
260 /* textured, fogged */
261 USE(textured_rgba_point);
262 }
263 else if (ctx->Point._Size != 1.0) {
264 /* large points */
265 if (rgbMode) {
266 USE(general_rgba_point);
267 }
268 else {
269 USE(general_ci_point);
270 }
271 }
272 else {
273 /* single pixel points */
274 if (rgbMode) {
275 assert((swrast->_ActiveAttribMask & FRAG_BIT_COL1) == 0);
276 USE(size1_rgba_point);
277 }
278 else {
279 USE(size1_ci_point);
280 }
281 }
282 }
283 else if (ctx->RenderMode==GL_FEEDBACK) {
284 USE(_swrast_feedback_point);
285 }
286 else {
287 /* GL_SELECT mode */
288 USE(_swrast_select_point);
289 }
290 }