check swrast->_FogEnabled instead of ctx->Fog.Enabled
[mesa.git] / src / mesa / swrast / s_context.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 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 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 * Brian Paul
27 */
28
29 #include "imports.h"
30 #include "bufferobj.h"
31 #include "context.h"
32 #include "colormac.h"
33 #include "mtypes.h"
34 #include "program.h"
35 #include "texobj.h"
36 #include "nvfragprog.h"
37
38 #include "swrast.h"
39 #include "s_blend.h"
40 #include "s_context.h"
41 #include "s_lines.h"
42 #include "s_points.h"
43 #include "s_span.h"
44 #include "s_triangle.h"
45 #include "s_texfilter.h"
46
47
48 /**
49 * Recompute the value of swrast->_RasterMask, etc. according to
50 * the current context. The _RasterMask field can be easily tested by
51 * drivers to determine certain basic GL state (does the primitive need
52 * stenciling, logic-op, fog, etc?).
53 */
54 static void
55 _swrast_update_rasterflags( GLcontext *ctx )
56 {
57 SWcontext *swrast = SWRAST_CONTEXT(ctx);
58 GLbitfield rasterMask = 0;
59
60 if (ctx->Color.AlphaEnabled) rasterMask |= ALPHATEST_BIT;
61 if (ctx->Color.BlendEnabled) rasterMask |= BLEND_BIT;
62 if (ctx->Depth.Test) rasterMask |= DEPTH_BIT;
63 if (swrast->_FogEnabled) rasterMask |= FOG_BIT;
64 if (ctx->Scissor.Enabled) rasterMask |= CLIP_BIT;
65 if (ctx->Stencil.Enabled) rasterMask |= STENCIL_BIT;
66 if (ctx->Visual.rgbMode) {
67 const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask);
68 if (colorMask != 0xffffffff) rasterMask |= MASKING_BIT;
69 if (ctx->Color._LogicOpEnabled) rasterMask |= LOGIC_OP_BIT;
70 if (ctx->Texture._EnabledUnits) rasterMask |= TEXTURE_BIT;
71 }
72 else {
73 if (ctx->Color.IndexMask != 0xffffffff) rasterMask |= MASKING_BIT;
74 if (ctx->Color.IndexLogicOpEnabled) rasterMask |= LOGIC_OP_BIT;
75 }
76
77 if ( ctx->Viewport.X < 0
78 || ctx->Viewport.X + ctx->Viewport.Width > (GLint) ctx->DrawBuffer->Width
79 || ctx->Viewport.Y < 0
80 || ctx->Viewport.Y + ctx->Viewport.Height > (GLint) ctx->DrawBuffer->Height) {
81 rasterMask |= CLIP_BIT;
82 }
83
84 if (ctx->Query.CurrentOcclusionObject)
85 rasterMask |= OCCLUSION_BIT;
86
87
88 /* If we're not drawing to exactly one color buffer set the
89 * MULTI_DRAW_BIT flag. Also set it if we're drawing to no
90 * buffers or the RGBA or CI mask disables all writes.
91 */
92 if (ctx->DrawBuffer->_NumColorDrawBuffers[0] != 1) {
93 /* more than one color buffer designated for writing (or zero buffers) */
94 rasterMask |= MULTI_DRAW_BIT;
95 }
96 else if (ctx->Visual.rgbMode && *((GLuint *) ctx->Color.ColorMask) == 0) {
97 rasterMask |= MULTI_DRAW_BIT; /* all RGBA channels disabled */
98 }
99 else if (!ctx->Visual.rgbMode && ctx->Color.IndexMask==0) {
100 rasterMask |= MULTI_DRAW_BIT; /* all color index bits disabled */
101 }
102
103 if (ctx->FragmentProgram._Active) {
104 rasterMask |= FRAGPROG_BIT;
105 }
106
107 if (ctx->ATIFragmentShader._Enabled) {
108 rasterMask |= ATIFRAGSHADER_BIT;
109 }
110
111 SWRAST_CONTEXT(ctx)->_RasterMask = rasterMask;
112 }
113
114
115 /**
116 * Examine polycon culls tate to compute the _BackfaceSign field.
117 * _BackfaceSign will be 0 if no culling, -1 if culling back-faces,
118 * and 1 if culling front-faces. The Polygon FrontFace state also
119 * factors in.
120 */
121 static void
122 _swrast_update_polygon( GLcontext *ctx )
123 {
124 GLfloat backface_sign = 1;
125
126 if (ctx->Polygon.CullFlag) {
127 backface_sign = 1;
128 switch(ctx->Polygon.CullFaceMode) {
129 case GL_BACK:
130 if(ctx->Polygon.FrontFace==GL_CCW)
131 backface_sign = -1;
132 break;
133 case GL_FRONT:
134 if(ctx->Polygon.FrontFace!=GL_CCW)
135 backface_sign = -1;
136 break;
137 default:
138 case GL_FRONT_AND_BACK:
139 backface_sign = 0;
140 break;
141 }
142 }
143 else {
144 backface_sign = 0;
145 }
146
147 SWRAST_CONTEXT(ctx)->_BackfaceSign = backface_sign;
148 }
149
150
151 /**
152 * Update the _PreferPixelFog field to indicate if we need to compute
153 * fog factors per-fragment.
154 */
155 static void
156 _swrast_update_fog_hint( GLcontext *ctx )
157 {
158 SWcontext *swrast = SWRAST_CONTEXT(ctx);
159 swrast->_PreferPixelFog = (!swrast->AllowVertexFog ||
160 ctx->FragmentProgram._Enabled || /* not _Active! */
161 (ctx->Hint.Fog == GL_NICEST &&
162 swrast->AllowPixelFog));
163 }
164
165
166
167 /**
168 * Update the swrast->_AnyTextureCombine flag.
169 */
170 static void
171 _swrast_update_texture_env( GLcontext *ctx )
172 {
173 SWcontext *swrast = SWRAST_CONTEXT(ctx);
174 GLuint i;
175 swrast->_AnyTextureCombine = GL_FALSE;
176 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
177 if (ctx->Texture.Unit[i].EnvMode == GL_COMBINE_EXT ||
178 ctx->Texture.Unit[i].EnvMode == GL_COMBINE4_NV) {
179 swrast->_AnyTextureCombine = GL_TRUE;
180 return;
181 }
182 }
183 }
184
185
186 /**
187 * Update swrast->_FogColor and swrast->_FogEnable values.
188 */
189 static void
190 _swrast_update_fog_state( GLcontext *ctx )
191 {
192 SWcontext *swrast = SWRAST_CONTEXT(ctx);
193
194 /* convert fog color to GLchan values */
195 CLAMPED_FLOAT_TO_CHAN(swrast->_FogColor[RCOMP], ctx->Fog.Color[RCOMP]);
196 CLAMPED_FLOAT_TO_CHAN(swrast->_FogColor[GCOMP], ctx->Fog.Color[GCOMP]);
197 CLAMPED_FLOAT_TO_CHAN(swrast->_FogColor[BCOMP], ctx->Fog.Color[BCOMP]);
198
199 /* determine if fog is needed, and if so, which fog mode */
200 swrast->_FogEnabled = GL_FALSE;
201 if (ctx->FragmentProgram._Active) {
202 if (ctx->FragmentProgram._Current->Base.Target==GL_FRAGMENT_PROGRAM_ARB) {
203 const struct fragment_program *p
204 = (struct fragment_program *) ctx->FragmentProgram._Current;
205 if (p->FogOption != GL_NONE) {
206 swrast->_FogEnabled = GL_TRUE;
207 swrast->_FogMode = p->FogOption;
208 }
209 }
210 }
211 else if (ctx->Fog.Enabled) {
212 swrast->_FogEnabled = GL_TRUE;
213 swrast->_FogMode = ctx->Fog.Mode;
214 }
215 }
216
217
218 /**
219 * Update state for running fragment programs. Basically, load the
220 * program parameters with current state values.
221 */
222 static void
223 _swrast_update_fragment_program( GLcontext *ctx )
224 {
225 if (ctx->FragmentProgram._Active) {
226 struct fragment_program *program = ctx->FragmentProgram._Current;
227 _mesa_load_state_parameters(ctx, program->Parameters);
228 }
229 }
230
231
232
233 #define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK | \
234 _NEW_TEXTURE | \
235 _NEW_HINT | \
236 _NEW_POLYGON )
237
238 /* State referenced by _swrast_choose_triangle, _swrast_choose_line.
239 */
240 #define _SWRAST_NEW_TRIANGLE (_SWRAST_NEW_DERIVED | \
241 _NEW_RENDERMODE| \
242 _NEW_POLYGON| \
243 _NEW_DEPTH| \
244 _NEW_STENCIL| \
245 _NEW_COLOR| \
246 _NEW_TEXTURE| \
247 _SWRAST_NEW_RASTERMASK| \
248 _NEW_LIGHT| \
249 _NEW_FOG | \
250 _DD_NEW_SEPARATE_SPECULAR)
251
252 #define _SWRAST_NEW_LINE (_SWRAST_NEW_DERIVED | \
253 _NEW_RENDERMODE| \
254 _NEW_LINE| \
255 _NEW_TEXTURE| \
256 _NEW_LIGHT| \
257 _NEW_FOG| \
258 _NEW_DEPTH | \
259 _DD_NEW_SEPARATE_SPECULAR)
260
261 #define _SWRAST_NEW_POINT (_SWRAST_NEW_DERIVED | \
262 _NEW_RENDERMODE | \
263 _NEW_POINT | \
264 _NEW_TEXTURE | \
265 _NEW_LIGHT | \
266 _NEW_FOG | \
267 _DD_NEW_SEPARATE_SPECULAR)
268
269 #define _SWRAST_NEW_TEXTURE_SAMPLE_FUNC _NEW_TEXTURE
270
271 #define _SWRAST_NEW_TEXTURE_ENV_MODE _NEW_TEXTURE
272
273 #define _SWRAST_NEW_BLEND_FUNC _NEW_COLOR
274
275
276
277 /**
278 * Stub for swrast->Triangle to select a true triangle function
279 * after a state change.
280 */
281 static void
282 _swrast_validate_triangle( GLcontext *ctx,
283 const SWvertex *v0,
284 const SWvertex *v1,
285 const SWvertex *v2 )
286 {
287 SWcontext *swrast = SWRAST_CONTEXT(ctx);
288
289 _swrast_validate_derived( ctx );
290 swrast->choose_triangle( ctx );
291
292 if (ctx->Texture._EnabledUnits == 0
293 && NEED_SECONDARY_COLOR(ctx)
294 && !ctx->FragmentProgram._Active) {
295 /* separate specular color, but no texture */
296 swrast->SpecTriangle = swrast->Triangle;
297 swrast->Triangle = _swrast_add_spec_terms_triangle;
298 }
299
300 swrast->Triangle( ctx, v0, v1, v2 );
301 }
302
303 /**
304 * Called via swrast->Line. Examine current GL state and choose a software
305 * line routine. Then call it.
306 */
307 static void
308 _swrast_validate_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
309 {
310 SWcontext *swrast = SWRAST_CONTEXT(ctx);
311
312 _swrast_validate_derived( ctx );
313 swrast->choose_line( ctx );
314
315 if (ctx->Texture._EnabledUnits == 0
316 && NEED_SECONDARY_COLOR(ctx)
317 && !ctx->FragmentProgram._Active) {
318 swrast->SpecLine = swrast->Line;
319 swrast->Line = _swrast_add_spec_terms_line;
320 }
321
322
323 swrast->Line( ctx, v0, v1 );
324 }
325
326 /**
327 * Called via swrast->Point. Examine current GL state and choose a software
328 * point routine. Then call it.
329 */
330 static void
331 _swrast_validate_point( GLcontext *ctx, const SWvertex *v0 )
332 {
333 SWcontext *swrast = SWRAST_CONTEXT(ctx);
334
335 _swrast_validate_derived( ctx );
336 swrast->choose_point( ctx );
337
338 if (ctx->Texture._EnabledUnits == 0
339 && NEED_SECONDARY_COLOR(ctx)
340 && !ctx->FragmentProgram._Active) {
341 swrast->SpecPoint = swrast->Point;
342 swrast->Point = _swrast_add_spec_terms_point;
343 }
344
345 swrast->Point( ctx, v0 );
346 }
347
348
349 /**
350 * Called via swrast->BlendFunc. Examine GL state to choose a blending
351 * function, then call it.
352 */
353 static void _ASMAPI
354 _swrast_validate_blend_func( GLcontext *ctx, GLuint n,
355 const GLubyte mask[],
356 GLchan src[][4],
357 CONST GLchan dst[][4] )
358 {
359 SWcontext *swrast = SWRAST_CONTEXT(ctx);
360
361 _swrast_validate_derived( ctx );
362 _swrast_choose_blend_func( ctx );
363
364 swrast->BlendFunc( ctx, n, mask, src, dst );
365 }
366
367
368 static void
369 _swrast_sleep( GLcontext *ctx, GLbitfield new_state )
370 {
371 (void) ctx; (void) new_state;
372 }
373
374
375 static void
376 _swrast_invalidate_state( GLcontext *ctx, GLbitfield new_state )
377 {
378 SWcontext *swrast = SWRAST_CONTEXT(ctx);
379 GLuint i;
380
381 swrast->NewState |= new_state;
382
383 /* After 10 statechanges without any swrast functions being called,
384 * put the module to sleep.
385 */
386 if (++swrast->StateChanges > 10) {
387 swrast->InvalidateState = _swrast_sleep;
388 swrast->NewState = ~0;
389 new_state = ~0;
390 }
391
392 if (new_state & swrast->invalidate_triangle)
393 swrast->Triangle = _swrast_validate_triangle;
394
395 if (new_state & swrast->invalidate_line)
396 swrast->Line = _swrast_validate_line;
397
398 if (new_state & swrast->invalidate_point)
399 swrast->Point = _swrast_validate_point;
400
401 if (new_state & _SWRAST_NEW_BLEND_FUNC)
402 swrast->BlendFunc = _swrast_validate_blend_func;
403
404 if (new_state & _SWRAST_NEW_TEXTURE_SAMPLE_FUNC)
405 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
406 swrast->TextureSample[i] = NULL;
407 }
408
409
410 static void
411 _swrast_update_texture_samplers(GLcontext *ctx)
412 {
413 SWcontext *swrast = SWRAST_CONTEXT(ctx);
414 GLuint u;
415
416 for (u = 0; u < ctx->Const.MaxTextureImageUnits; u++) {
417 const struct gl_texture_object *tObj = ctx->Texture.Unit[u]._Current;
418 if (tObj)
419 swrast->TextureSample[u] =
420 _swrast_choose_texture_sample_func(ctx, tObj);
421 }
422 }
423
424
425 void
426 _swrast_validate_derived( GLcontext *ctx )
427 {
428 SWcontext *swrast = SWRAST_CONTEXT(ctx);
429
430 if (swrast->NewState) {
431 if (swrast->NewState & _SWRAST_NEW_RASTERMASK)
432 _swrast_update_rasterflags( ctx );
433
434 if (swrast->NewState & _NEW_POLYGON)
435 _swrast_update_polygon( ctx );
436
437 if (swrast->NewState & (_NEW_HINT | _NEW_PROGRAM))
438 _swrast_update_fog_hint( ctx );
439
440 if (swrast->NewState & _SWRAST_NEW_TEXTURE_ENV_MODE)
441 _swrast_update_texture_env( ctx );
442
443 if (swrast->NewState & (_NEW_FOG | _NEW_PROGRAM))
444 _swrast_update_fog_state( ctx );
445
446 if (swrast->NewState & _NEW_PROGRAM)
447 _swrast_update_fragment_program( ctx );
448
449 if (swrast->NewState & _NEW_TEXTURE)
450 _swrast_update_texture_samplers( ctx );
451
452 swrast->NewState = 0;
453 swrast->StateChanges = 0;
454 swrast->InvalidateState = _swrast_invalidate_state;
455 }
456 }
457
458 #define SWRAST_DEBUG 0
459
460 /* Public entrypoints: See also s_accum.c, s_bitmap.c, etc.
461 */
462 void
463 _swrast_Quad( GLcontext *ctx,
464 const SWvertex *v0, const SWvertex *v1,
465 const SWvertex *v2, const SWvertex *v3 )
466 {
467 if (SWRAST_DEBUG) {
468 _mesa_debug(ctx, "_swrast_Quad\n");
469 _swrast_print_vertex( ctx, v0 );
470 _swrast_print_vertex( ctx, v1 );
471 _swrast_print_vertex( ctx, v2 );
472 _swrast_print_vertex( ctx, v3 );
473 }
474 SWRAST_CONTEXT(ctx)->Triangle( ctx, v0, v1, v3 );
475 SWRAST_CONTEXT(ctx)->Triangle( ctx, v1, v2, v3 );
476 }
477
478 void
479 _swrast_Triangle( GLcontext *ctx, const SWvertex *v0,
480 const SWvertex *v1, const SWvertex *v2 )
481 {
482 if (SWRAST_DEBUG) {
483 _mesa_debug(ctx, "_swrast_Triangle\n");
484 _swrast_print_vertex( ctx, v0 );
485 _swrast_print_vertex( ctx, v1 );
486 _swrast_print_vertex( ctx, v2 );
487 }
488 SWRAST_CONTEXT(ctx)->Triangle( ctx, v0, v1, v2 );
489 }
490
491 void
492 _swrast_Line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
493 {
494 if (SWRAST_DEBUG) {
495 _mesa_debug(ctx, "_swrast_Line\n");
496 _swrast_print_vertex( ctx, v0 );
497 _swrast_print_vertex( ctx, v1 );
498 }
499 SWRAST_CONTEXT(ctx)->Line( ctx, v0, v1 );
500 }
501
502 void
503 _swrast_Point( GLcontext *ctx, const SWvertex *v0 )
504 {
505 if (SWRAST_DEBUG) {
506 _mesa_debug(ctx, "_swrast_Point\n");
507 _swrast_print_vertex( ctx, v0 );
508 }
509 SWRAST_CONTEXT(ctx)->Point( ctx, v0 );
510 }
511
512 void
513 _swrast_InvalidateState( GLcontext *ctx, GLbitfield new_state )
514 {
515 if (SWRAST_DEBUG) {
516 _mesa_debug(ctx, "_swrast_InvalidateState\n");
517 }
518 SWRAST_CONTEXT(ctx)->InvalidateState( ctx, new_state );
519 }
520
521 void
522 _swrast_ResetLineStipple( GLcontext *ctx )
523 {
524 if (SWRAST_DEBUG) {
525 _mesa_debug(ctx, "_swrast_ResetLineStipple\n");
526 }
527 SWRAST_CONTEXT(ctx)->StippleCounter = 0;
528 }
529
530 void
531 _swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value )
532 {
533 if (SWRAST_DEBUG) {
534 _mesa_debug(ctx, "_swrast_allow_vertex_fog %d\n", value);
535 }
536 SWRAST_CONTEXT(ctx)->InvalidateState( ctx, _NEW_HINT );
537 SWRAST_CONTEXT(ctx)->AllowVertexFog = value;
538 }
539
540 void
541 _swrast_allow_pixel_fog( GLcontext *ctx, GLboolean value )
542 {
543 if (SWRAST_DEBUG) {
544 _mesa_debug(ctx, "_swrast_allow_pixel_fog %d\n", value);
545 }
546 SWRAST_CONTEXT(ctx)->InvalidateState( ctx, _NEW_HINT );
547 SWRAST_CONTEXT(ctx)->AllowPixelFog = value;
548 }
549
550
551 GLboolean
552 _swrast_CreateContext( GLcontext *ctx )
553 {
554 GLuint i;
555 SWcontext *swrast = (SWcontext *)CALLOC(sizeof(SWcontext));
556
557 if (SWRAST_DEBUG) {
558 _mesa_debug(ctx, "_swrast_CreateContext\n");
559 }
560
561 if (!swrast)
562 return GL_FALSE;
563
564 swrast->NewState = ~0;
565
566 swrast->choose_point = _swrast_choose_point;
567 swrast->choose_line = _swrast_choose_line;
568 swrast->choose_triangle = _swrast_choose_triangle;
569
570 swrast->invalidate_point = _SWRAST_NEW_POINT;
571 swrast->invalidate_line = _SWRAST_NEW_LINE;
572 swrast->invalidate_triangle = _SWRAST_NEW_TRIANGLE;
573
574 swrast->Point = _swrast_validate_point;
575 swrast->Line = _swrast_validate_line;
576 swrast->Triangle = _swrast_validate_triangle;
577 swrast->InvalidateState = _swrast_sleep;
578 swrast->BlendFunc = _swrast_validate_blend_func;
579
580 swrast->AllowVertexFog = GL_TRUE;
581 swrast->AllowPixelFog = GL_TRUE;
582
583 /* Optimized Accum buffer */
584 swrast->_IntegerAccumMode = GL_FALSE;
585 swrast->_IntegerAccumScaler = 0.0;
586
587 for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
588 swrast->TextureSample[i] = NULL;
589
590 swrast->SpanArrays = MALLOC_STRUCT(span_arrays);
591 if (!swrast->SpanArrays) {
592 FREE(swrast);
593 return GL_FALSE;
594 }
595
596 /* init point span buffer */
597 swrast->PointSpan.primitive = GL_POINT;
598 swrast->PointSpan.start = 0;
599 swrast->PointSpan.end = 0;
600 swrast->PointSpan.facing = 0;
601 swrast->PointSpan.array = swrast->SpanArrays;
602
603 assert(ctx->Const.MaxTextureUnits > 0);
604 assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_UNITS);
605
606 swrast->TexelBuffer = (GLchan *) MALLOC(ctx->Const.MaxTextureUnits *
607 MAX_WIDTH * 4 * sizeof(GLchan));
608 if (!swrast->TexelBuffer) {
609 FREE(swrast->SpanArrays);
610 FREE(swrast);
611 return GL_FALSE;
612 }
613
614 ctx->swrast_context = swrast;
615
616 return GL_TRUE;
617 }
618
619 void
620 _swrast_DestroyContext( GLcontext *ctx )
621 {
622 SWcontext *swrast = SWRAST_CONTEXT(ctx);
623
624 if (SWRAST_DEBUG) {
625 _mesa_debug(ctx, "_swrast_DestroyContext\n");
626 }
627
628 FREE( swrast->SpanArrays );
629 FREE( swrast->TexelBuffer );
630 FREE( swrast );
631
632 ctx->swrast_context = 0;
633 }
634
635
636 struct swrast_device_driver *
637 _swrast_GetDeviceDriverReference( GLcontext *ctx )
638 {
639 SWcontext *swrast = SWRAST_CONTEXT(ctx);
640 return &swrast->Driver;
641 }
642
643 void
644 _swrast_flush( GLcontext *ctx )
645 {
646 SWcontext *swrast = SWRAST_CONTEXT(ctx);
647 /* flush any pending fragments from rendering points */
648 if (swrast->PointSpan.end > 0) {
649 if (ctx->Visual.rgbMode) {
650 _swrast_write_rgba_span(ctx, &(swrast->PointSpan));
651 }
652 else {
653 _swrast_write_index_span(ctx, &(swrast->PointSpan));
654 }
655 swrast->PointSpan.end = 0;
656 }
657 }
658
659 void
660 _swrast_render_primitive( GLcontext *ctx, GLenum prim )
661 {
662 SWcontext *swrast = SWRAST_CONTEXT(ctx);
663 if (swrast->Primitive == GL_POINTS && prim != GL_POINTS) {
664 _swrast_flush(ctx);
665 }
666 swrast->Primitive = prim;
667 }
668
669
670 void
671 _swrast_render_start( GLcontext *ctx )
672 {
673 SWcontext *swrast = SWRAST_CONTEXT(ctx);
674 if (swrast->Driver.SpanRenderStart)
675 swrast->Driver.SpanRenderStart( ctx );
676 swrast->PointSpan.end = 0;
677 }
678
679 void
680 _swrast_render_finish( GLcontext *ctx )
681 {
682 SWcontext *swrast = SWRAST_CONTEXT(ctx);
683 if (swrast->Driver.SpanRenderFinish)
684 swrast->Driver.SpanRenderFinish( ctx );
685
686 _swrast_flush(ctx);
687 }
688
689
690 #define SWRAST_DEBUG_VERTICES 0
691
692 void
693 _swrast_print_vertex( GLcontext *ctx, const SWvertex *v )
694 {
695 GLuint i;
696
697 if (SWRAST_DEBUG_VERTICES) {
698 _mesa_debug(ctx, "win %f %f %f %f\n",
699 v->win[0], v->win[1], v->win[2], v->win[3]);
700
701 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
702 if (ctx->Texture.Unit[i]._ReallyEnabled)
703 _mesa_debug(ctx, "texcoord[%d] %f %f %f %f\n", i,
704 v->texcoord[i][0], v->texcoord[i][1],
705 v->texcoord[i][2], v->texcoord[i][3]);
706
707 #if CHAN_TYPE == GL_FLOAT
708 _mesa_debug(ctx, "color %f %f %f %f\n",
709 v->color[0], v->color[1], v->color[2], v->color[3]);
710 _mesa_debug(ctx, "spec %f %f %f %f\n",
711 v->specular[0], v->specular[1],
712 v->specular[2], v->specular[3]);
713 #else
714 _mesa_debug(ctx, "color %d %d %d %d\n",
715 v->color[0], v->color[1], v->color[2], v->color[3]);
716 _mesa_debug(ctx, "spec %d %d %d %d\n",
717 v->specular[0], v->specular[1],
718 v->specular[2], v->specular[3]);
719 #endif
720 _mesa_debug(ctx, "fog %f\n", v->fog);
721 _mesa_debug(ctx, "index %d\n", v->index);
722 _mesa_debug(ctx, "pointsize %f\n", v->pointSize);
723 _mesa_debug(ctx, "\n");
724 }
725 }