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