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