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