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