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